Allow embedders to specify software renderer configs. (flutter/engine#6133)

This commit is contained in:
Chinmay Garde
2018-08-31 20:03:06 -07:00
committed by GitHub
parent 79d8614074
commit f2049c7687
12 changed files with 629 additions and 166 deletions

View File

@@ -609,6 +609,12 @@ FILE: ../../../flutter/shell/platform/android/platform_message_response_android.
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate_Internal.h
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.h
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.mm
FILE: ../../../flutter/shell/platform/embedder/embedder_surface.cc
FILE: ../../../flutter/shell/platform/embedder/embedder_surface.h
FILE: ../../../flutter/shell/platform/embedder/embedder_surface_gl.cc
FILE: ../../../flutter/shell/platform/embedder/embedder_surface_gl.h
FILE: ../../../flutter/shell/platform/embedder/embedder_surface_software.cc
FILE: ../../../flutter/shell/platform/embedder/embedder_surface_software.h
FILE: ../../../flutter/shell/version/version.cc
FILE: ../../../flutter/shell/version/version.h
----------------------------------------------------------------------------------------------------

View File

@@ -7,7 +7,7 @@ import("$flutter_root/shell/gpu/gpu.gni")
import("$flutter_root/shell/platform/embedder/embedder.gni")
shell_gpu_configuration("embedder_gpu_configuration") {
enable_software = false
enable_software = true
enable_vulkan = false
enable_gl = true
}
@@ -16,6 +16,12 @@ source_set("embedder") {
sources = [
"embedder.cc",
"embedder.h",
"embedder_surface.cc",
"embedder_surface.h",
"embedder_surface_gl.cc",
"embedder_surface_gl.h",
"embedder_surface_software.cc",
"embedder_surface_software.h",
"embedder_engine.cc",
"embedder_engine.h",
"embedder_include.c",

View File

@@ -39,8 +39,8 @@
return static_cast<decltype(pointer->member)>((default_value)); \
})()
bool IsRendererValid(const FlutterRendererConfig* config) {
if (config == nullptr || config->type != kOpenGL) {
static bool IsOpenGLRendererConfigValid(const FlutterRendererConfig* config) {
if (config->type != kOpenGL) {
return false;
}
@@ -56,6 +56,167 @@ bool IsRendererValid(const FlutterRendererConfig* config) {
return true;
}
static bool IsSoftwareRendererConfigValid(const FlutterRendererConfig* config) {
if (config->type != kSoftware) {
return false;
}
const FlutterSoftwareRendererConfig* software_config = &config->software;
if (SAFE_ACCESS(software_config, surface_present_callback, nullptr) ==
nullptr) {
return false;
}
return true;
}
static bool IsRendererValid(const FlutterRendererConfig* config) {
if (config == nullptr) {
return false;
}
switch (config->type) {
case kOpenGL:
return IsOpenGLRendererConfigValid(config);
case kSoftware:
return IsSoftwareRendererConfigValid(config);
default:
return false;
}
return false;
}
static shell::Shell::CreateCallback<shell::PlatformView>
InferOpenGLPlatformViewCreationCallback(
const FlutterRendererConfig* config,
void* user_data,
shell::PlatformViewEmbedder::PlatformDispatchTable
platform_dispatch_table) {
if (config->type != kOpenGL) {
return nullptr;
}
auto gl_make_current = [ptr = config->open_gl.make_current,
user_data]() -> bool { return ptr(user_data); };
auto gl_clear_current = [ptr = config->open_gl.clear_current,
user_data]() -> bool { return ptr(user_data); };
auto gl_present = [ptr = config->open_gl.present, user_data]() -> bool {
return ptr(user_data);
};
auto gl_fbo_callback = [ptr = config->open_gl.fbo_callback,
user_data]() -> intptr_t { return ptr(user_data); };
const FlutterOpenGLRendererConfig* open_gl_config = &config->open_gl;
std::function<bool()> gl_make_resource_current_callback = nullptr;
if (SAFE_ACCESS(open_gl_config, make_resource_current, nullptr) != nullptr) {
gl_make_resource_current_callback =
[ptr = config->open_gl.make_resource_current, user_data]() {
return ptr(user_data);
};
}
std::function<SkMatrix(void)> gl_surface_transformation_callback = nullptr;
if (SAFE_ACCESS(open_gl_config, surface_transformation, nullptr) != nullptr) {
gl_surface_transformation_callback =
[ptr = config->open_gl.surface_transformation, user_data]() {
FlutterTransformation transformation = ptr(user_data);
return SkMatrix::MakeAll(transformation.scaleX, //
transformation.skewX, //
transformation.transX, //
transformation.skewY, //
transformation.scaleY, //
transformation.transY, //
transformation.pers0, //
transformation.pers1, //
transformation.pers2 //
);
};
}
bool fbo_reset_after_present =
SAFE_ACCESS(open_gl_config, fbo_reset_after_present, false);
shell::EmbedderSurfaceGL::GLDispatchTable gl_dispatch_table = {
gl_make_current, // gl_make_current_callback
gl_clear_current, // gl_clear_current_callback
gl_present, // gl_present_callback
gl_fbo_callback, // gl_fbo_callback
gl_make_resource_current_callback, // gl_make_resource_current_callback
gl_surface_transformation_callback // gl_surface_transformation_callback
};
return [gl_dispatch_table, fbo_reset_after_present,
platform_dispatch_table](shell::Shell& shell) {
return std::make_unique<shell::PlatformViewEmbedder>(
shell, // delegate
shell.GetTaskRunners(), // task runners
gl_dispatch_table, // embedder GL dispatch table
fbo_reset_after_present, // fbo reset after present
platform_dispatch_table // embedder platform dispatch table
);
};
}
static shell::Shell::CreateCallback<shell::PlatformView>
InferSoftwarePlatformViewCreationCallback(
const FlutterRendererConfig* config,
void* user_data,
shell::PlatformViewEmbedder::PlatformDispatchTable
platform_dispatch_table) {
if (config->type != kSoftware) {
return nullptr;
}
auto software_present_backing_store =
[ptr = config->software.surface_present_callback, user_data](
const void* allocation, size_t row_bytes, size_t height) -> bool {
return ptr(user_data, allocation, row_bytes, height);
};
shell::EmbedderSurfaceSoftware::SoftwareDispatchTable
software_dispatch_table = {
software_present_backing_store, // required
};
return
[software_dispatch_table, platform_dispatch_table](shell::Shell& shell) {
return std::make_unique<shell::PlatformViewEmbedder>(
shell, // delegate
shell.GetTaskRunners(), // task runners
software_dispatch_table, // software dispatch table
platform_dispatch_table // platform dispatch table
);
};
}
static shell::Shell::CreateCallback<shell::PlatformView>
InferPlatformViewCreationCallback(
const FlutterRendererConfig* config,
void* user_data,
shell::PlatformViewEmbedder::PlatformDispatchTable
platform_dispatch_table) {
if (config == nullptr) {
return nullptr;
}
switch (config->type) {
case kOpenGL:
return InferOpenGLPlatformViewCreationCallback(config, user_data,
platform_dispatch_table);
case kSoftware:
return InferSoftwarePlatformViewCreationCallback(config, user_data,
platform_dispatch_table);
default:
return nullptr;
}
return nullptr;
}
struct _FlutterPlatformMessageResponseHandle {
fml::RefPtr<blink::PlatformMessage> message;
};
@@ -88,67 +249,6 @@ FlutterResult FlutterEngineRun(size_t version,
return kInvalidArguments;
}
auto make_current = [ptr = config->open_gl.make_current,
user_data]() -> bool { return ptr(user_data); };
auto clear_current = [ptr = config->open_gl.clear_current,
user_data]() -> bool { return ptr(user_data); };
auto present = [ptr = config->open_gl.present, user_data]() -> bool {
return ptr(user_data);
};
auto fbo_callback = [ptr = config->open_gl.fbo_callback,
user_data]() -> intptr_t { return ptr(user_data); };
shell::PlatformViewEmbedder::PlatformMessageResponseCallback
platform_message_response_callback = nullptr;
if (SAFE_ACCESS(args, platform_message_callback, nullptr) != nullptr) {
platform_message_response_callback =
[ptr = args->platform_message_callback,
user_data](fml::RefPtr<blink::PlatformMessage> message) {
auto handle = new FlutterPlatformMessageResponseHandle();
const FlutterPlatformMessage incoming_message = {
sizeof(FlutterPlatformMessage), // struct_size
message->channel().c_str(), // channel
message->data().data(), // message
message->data().size(), // message_size
handle, // response_handle
};
handle->message = std::move(message);
return ptr(&incoming_message, user_data);
};
}
const FlutterOpenGLRendererConfig* open_gl_config = &config->open_gl;
std::function<bool()> make_resource_current_callback = nullptr;
if (SAFE_ACCESS(open_gl_config, make_resource_current, nullptr) != nullptr) {
make_resource_current_callback = [ptr =
config->open_gl.make_resource_current,
user_data]() { return ptr(user_data); };
}
std::function<SkMatrix(void)> gl_surface_transformation_callback = nullptr;
if (SAFE_ACCESS(open_gl_config, surface_transformation, nullptr) != nullptr) {
gl_surface_transformation_callback =
[ptr = config->open_gl.surface_transformation, user_data]() {
FlutterTransformation transformation = ptr(user_data);
return SkMatrix::MakeAll(transformation.scaleX, //
transformation.skewX, //
transformation.transX, //
transformation.skewY, //
transformation.scaleY, //
transformation.transY, //
transformation.pers0, //
transformation.pers1, //
transformation.pers2 //
);
};
}
bool fbo_reset_after_present =
SAFE_ACCESS(open_gl_config, fbo_reset_after_present, false);
std::string icu_data_path;
if (SAFE_ACCESS(args, icu_data_path, nullptr) != nullptr) {
icu_data_path = SAFE_ACCESS(args, icu_data_path, nullptr);
@@ -205,25 +305,35 @@ FlutterResult FlutterEngineRun(size_t version,
thread_host.io_thread->GetTaskRunner() // io
);
shell::PlatformViewEmbedder::DispatchTable dispatch_table = {
make_current, // gl_make_current_callback
clear_current, // gl_clear_current_callback
present, // gl_present_callback
fbo_callback, // gl_fbo_callback
shell::PlatformViewEmbedder::PlatformMessageResponseCallback
platform_message_response_callback = nullptr;
if (SAFE_ACCESS(args, platform_message_callback, nullptr) != nullptr) {
platform_message_response_callback =
[ptr = args->platform_message_callback,
user_data](fml::RefPtr<blink::PlatformMessage> message) {
auto handle = new FlutterPlatformMessageResponseHandle();
const FlutterPlatformMessage incoming_message = {
sizeof(FlutterPlatformMessage), // struct_size
message->channel().c_str(), // channel
message->data().data(), // message
message->data().size(), // message_size
handle, // response_handle
};
handle->message = std::move(message);
return ptr(&incoming_message, user_data);
};
}
shell::PlatformViewEmbedder::PlatformDispatchTable platform_dispatch_table = {
platform_message_response_callback, // platform_message_response_callback
make_resource_current_callback, // gl_make_resource_current_callback
gl_surface_transformation_callback // gl_surface_transformation_callback
};
shell::Shell::CreateCallback<shell::PlatformView> on_create_platform_view =
[dispatch_table, fbo_reset_after_present](shell::Shell& shell) {
return std::make_unique<shell::PlatformViewEmbedder>(
shell, // delegate
shell.GetTaskRunners(), // task runners
dispatch_table, // embedder dispatch table
fbo_reset_after_present // fbo reset after present
);
};
auto on_create_platform_view = InferPlatformViewCreationCallback(
config, user_data, platform_dispatch_table);
if (!on_create_platform_view) {
return kInvalidArguments;
}
shell::Shell::CreateCallback<shell::Rasterizer> on_create_rasterizer =
[](shell::Shell& shell) {

View File

@@ -27,6 +27,7 @@ typedef enum {
typedef enum {
kOpenGL,
kSoftware,
} FlutterRendererType;
typedef struct _FlutterEngine* FlutterEngine;
@@ -55,6 +56,10 @@ typedef struct {
typedef bool (*BoolCallback)(void* /* user data */);
typedef FlutterTransformation (*TransformationCallback)(void* /* user data */);
typedef uint32_t (*UIntCallback)(void* /* user data */);
typedef bool (*SoftwareSurfacePresentCallback)(void* /* user data */,
const void* /* allocation */,
size_t /* row bytes */,
size_t /* height */);
typedef struct {
// The size of this struct. Must be sizeof(FlutterOpenGLRendererConfig).
@@ -74,10 +79,21 @@ typedef struct {
TransformationCallback surface_transformation;
} FlutterOpenGLRendererConfig;
typedef struct {
// The size of this struct. Must be sizeof(FlutterSoftwareRendererConfig).
size_t struct_size;
// The callback presented to the embedder to present a fully populated buffer
// to the user. The pixel format of the buffer is the native 32-bit RGBA
// format. The buffer is owned by the Flutter engine and must be copied in
// this callback if needed.
SoftwareSurfacePresentCallback surface_present_callback;
} FlutterSoftwareRendererConfig;
typedef struct {
FlutterRendererType type;
union {
FlutterOpenGLRendererConfig open_gl;
FlutterSoftwareRendererConfig software;
};
} FlutterRendererConfig;

View File

@@ -0,0 +1,13 @@
// Copyright 2018 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/embedder/embedder_surface.h"
namespace shell {
EmbedderSurface::EmbedderSurface() = default;
EmbedderSurface::~EmbedderSurface() = default;
} // namespace shell

View File

@@ -0,0 +1,31 @@
// Copyright 2018 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SURFACE_H_
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SURFACE_H_
#include "flutter/fml/macros.h"
#include "flutter/shell/common/surface.h"
namespace shell {
class EmbedderSurface {
public:
EmbedderSurface();
virtual ~EmbedderSurface();
virtual bool IsValid() const = 0;
virtual std::unique_ptr<Surface> CreateGPUSurface() = 0;
virtual sk_sp<GrContext> CreateResourceContext() const = 0;
private:
FML_DISALLOW_COPY_AND_ASSIGN(EmbedderSurface);
};
} // namespace shell
#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SURFACE_H_

View File

@@ -0,0 +1,84 @@
// Copyright 2018 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/embedder/embedder_surface_gl.h"
#include "flutter/shell/common/io_manager.h"
namespace shell {
EmbedderSurfaceGL::EmbedderSurfaceGL(GLDispatchTable gl_dispatch_table,
bool fbo_reset_after_present)
: gl_dispatch_table_(gl_dispatch_table),
fbo_reset_after_present_(fbo_reset_after_present) {
// Make sure all required members of the dispatch table are checked.
if (!gl_dispatch_table_.gl_make_current_callback ||
!gl_dispatch_table_.gl_clear_current_callback ||
!gl_dispatch_table_.gl_present_callback ||
!gl_dispatch_table_.gl_fbo_callback) {
return;
}
valid_ = true;
}
EmbedderSurfaceGL::~EmbedderSurfaceGL() = default;
// |shell::EmbedderSurface|
bool EmbedderSurfaceGL::IsValid() const {
return valid_;
}
// |shell::GPUSurfaceGLDelegate|
bool EmbedderSurfaceGL::GLContextMakeCurrent() {
return gl_dispatch_table_.gl_make_current_callback();
}
// |shell::GPUSurfaceGLDelegate|
bool EmbedderSurfaceGL::GLContextClearCurrent() {
return gl_dispatch_table_.gl_clear_current_callback();
}
// |shell::GPUSurfaceGLDelegate|
bool EmbedderSurfaceGL::GLContextPresent() {
return gl_dispatch_table_.gl_present_callback();
}
// |shell::GPUSurfaceGLDelegate|
intptr_t EmbedderSurfaceGL::GLContextFBO() const {
return gl_dispatch_table_.gl_fbo_callback();
}
// |shell::GPUSurfaceGLDelegate|
bool EmbedderSurfaceGL::GLContextFBOResetAfterPresent() const {
return fbo_reset_after_present_;
}
// |shell::GPUSurfaceGLDelegate|
SkMatrix EmbedderSurfaceGL::GLContextSurfaceTransformation() const {
auto callback = gl_dispatch_table_.gl_surface_transformation_callback;
if (!callback) {
SkMatrix matrix;
matrix.setIdentity();
return matrix;
}
return callback();
}
// |shell::EmbedderSurface|
std::unique_ptr<Surface> EmbedderSurfaceGL::CreateGPUSurface() {
return std::make_unique<GPUSurfaceGL>(this);
}
// |shell::EmbedderSurface|
sk_sp<GrContext> EmbedderSurfaceGL::CreateResourceContext() const {
auto callback = gl_dispatch_table_.gl_make_resource_current_callback;
if (callback && callback()) {
return IOManager::CreateCompatibleResourceLoadingContext(
GrBackend::kOpenGL_GrBackend);
}
return nullptr;
}
} // namespace shell

View File

@@ -0,0 +1,69 @@
// Copyright 2018 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SURFACE_GL_H_
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SURFACE_GL_H_
#include "flutter/fml/macros.h"
#include "flutter/shell/gpu/gpu_surface_gl.h"
#include "flutter/shell/platform/embedder/embedder_surface.h"
namespace shell {
class EmbedderSurfaceGL final : public EmbedderSurface,
public GPUSurfaceGLDelegate {
public:
struct GLDispatchTable {
std::function<bool(void)> gl_make_current_callback; // required
std::function<bool(void)> gl_clear_current_callback; // required
std::function<bool(void)> gl_present_callback; // required
std::function<intptr_t(void)> gl_fbo_callback; // required
std::function<bool(void)> gl_make_resource_current_callback; // optional
std::function<SkMatrix(void)>
gl_surface_transformation_callback; // optional
};
EmbedderSurfaceGL(GLDispatchTable gl_dispatch_table,
bool fbo_reset_after_present);
~EmbedderSurfaceGL() override;
private:
bool valid_ = false;
GLDispatchTable gl_dispatch_table_;
bool fbo_reset_after_present_;
// |shell::EmbedderSurface|
bool IsValid() const override;
// |shell::EmbedderSurface|
std::unique_ptr<Surface> CreateGPUSurface() override;
// |shell::EmbedderSurface|
sk_sp<GrContext> CreateResourceContext() const override;
// |shell::GPUSurfaceGLDelegate|
bool GLContextMakeCurrent() override;
// |shell::GPUSurfaceGLDelegate|
bool GLContextClearCurrent() override;
// |shell::GPUSurfaceGLDelegate|
bool GLContextPresent() override;
// |shell::GPUSurfaceGLDelegate|
intptr_t GLContextFBO() const override;
// |shell::GPUSurfaceGLDelegate|
bool GLContextFBOResetAfterPresent() const override;
// |shell::GPUSurfaceGLDelegate|
SkMatrix GLContextSurfaceTransformation() const override;
FML_DISALLOW_COPY_AND_ASSIGN(EmbedderSurfaceGL);
};
} // namespace shell
#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SURFACE_GL_H_

View File

@@ -0,0 +1,107 @@
// Copyright 2018 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/embedder/embedder_surface_software.h"
#include "flutter/fml/trace_event.h"
#include "third_party/skia/include/gpu/GrContext.h"
namespace shell {
EmbedderSurfaceSoftware::EmbedderSurfaceSoftware(
SoftwareDispatchTable software_dispatch_table)
: software_dispatch_table_(software_dispatch_table) {
if (!software_dispatch_table_.software_present_backing_store) {
return;
}
valid_ = true;
}
EmbedderSurfaceSoftware::~EmbedderSurfaceSoftware() = default;
// |shell::EmbedderSurface|
bool EmbedderSurfaceSoftware::IsValid() const {
return valid_;
}
// |shell::EmbedderSurface|
std::unique_ptr<Surface> EmbedderSurfaceSoftware::CreateGPUSurface() {
if (!IsValid()) {
return nullptr;
}
auto surface = std::make_unique<GPUSurfaceSoftware>(this);
if (!surface->IsValid()) {
return nullptr;
}
return surface;
}
// |shell::EmbedderSurface|
sk_sp<GrContext> EmbedderSurfaceSoftware::CreateResourceContext() const {
return nullptr;
}
// |shell::GPUSurfaceSoftwareDelegate|
sk_sp<SkSurface> EmbedderSurfaceSoftware::AcquireBackingStore(
const SkISize& size) {
TRACE_EVENT0("flutter", "EmbedderSurfaceSoftware::AcquireBackingStore");
if (!IsValid()) {
FML_LOG(ERROR)
<< "Could not acquire backing store for the software surface.";
return nullptr;
}
if (sk_surface_ != nullptr &&
SkISize::Make(sk_surface_->width(), sk_surface_->height()) == size) {
// The old and new surface sizes are the same. Nothing to do here.
return sk_surface_;
}
SkImageInfo info =
SkImageInfo::MakeN32(size.fWidth, size.fHeight, kPremul_SkAlphaType);
sk_surface_ = SkSurface::MakeRaster(info, nullptr);
if (sk_surface_ == nullptr) {
FML_LOG(ERROR) << "Could not create backing store for software rendering.";
return nullptr;
}
return sk_surface_;
}
// |shell::GPUSurfaceSoftwareDelegate|
bool EmbedderSurfaceSoftware::PresentBackingStore(
sk_sp<SkSurface> backing_store) {
if (!IsValid()) {
FML_LOG(ERROR) << "Tried to present an invalid software surface.";
return false;
}
SkPixmap pixmap;
if (!backing_store->peekPixels(&pixmap)) {
FML_LOG(ERROR) << "Could not peek the pixels of the backing store.";
return false;
}
// Some basic sanity checking.
uint64_t expected_pixmap_data_size = pixmap.width() * pixmap.height() * 4;
const size_t pixmap_size = pixmap.computeByteSize();
if (expected_pixmap_data_size != pixmap_size) {
FML_LOG(ERROR) << "Software backing store had unexpected size.";
return false;
}
return software_dispatch_table_.software_present_backing_store(
pixmap.addr(), //
pixmap.rowBytes(), //
pixmap.height() //
);
}
} // namespace shell

View File

@@ -0,0 +1,51 @@
// Copyright 2018 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SURFACE_SOFTWARE_H_
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SURFACE_SOFTWARE_H_
#include "flutter/fml/macros.h"
#include "flutter/shell/gpu/gpu_surface_software.h"
#include "flutter/shell/platform/embedder/embedder_surface.h"
namespace shell {
class EmbedderSurfaceSoftware final : public EmbedderSurface,
public GPUSurfaceSoftwareDelegate {
public:
struct SoftwareDispatchTable {
std::function<bool(const void* allocation, size_t row_bytes, size_t height)>
software_present_backing_store; // required
};
EmbedderSurfaceSoftware(SoftwareDispatchTable software_dispatch_table);
~EmbedderSurfaceSoftware() override;
private:
bool valid_ = false;
SoftwareDispatchTable software_dispatch_table_;
sk_sp<SkSurface> sk_surface_;
// |shell::EmbedderSurface|
bool IsValid() const override;
// |shell::EmbedderSurface|
std::unique_ptr<Surface> CreateGPUSurface() override;
// |shell::EmbedderSurface|
sk_sp<GrContext> CreateResourceContext() const override;
// |shell::GPUSurfaceSoftwareDelegate|
sk_sp<SkSurface> AcquireBackingStore(const SkISize& size) override;
// |shell::GPUSurfaceSoftwareDelegate|
bool PresentBackingStore(sk_sp<SkSurface> backing_store) override;
FML_DISALLOW_COPY_AND_ASSIGN(EmbedderSurfaceSoftware);
};
} // namespace shell
#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SURFACE_SOFTWARE_H_

View File

@@ -4,56 +4,32 @@
#include "flutter/shell/platform/embedder/platform_view_embedder.h"
#include "flutter/shell/common/io_manager.h"
namespace shell {
PlatformViewEmbedder::PlatformViewEmbedder(PlatformView::Delegate& delegate,
blink::TaskRunners task_runners,
DispatchTable dispatch_table,
bool fbo_reset_after_present)
PlatformViewEmbedder::PlatformViewEmbedder(
PlatformView::Delegate& delegate,
blink::TaskRunners task_runners,
EmbedderSurfaceGL::GLDispatchTable gl_dispatch_table,
bool fbo_reset_after_present,
PlatformDispatchTable platform_dispatch_table)
: PlatformView(delegate, std::move(task_runners)),
dispatch_table_(dispatch_table),
fbo_reset_after_present_(fbo_reset_after_present) {}
embedder_surface_(
std::make_unique<EmbedderSurfaceGL>(gl_dispatch_table,
fbo_reset_after_present)),
platform_dispatch_table_(platform_dispatch_table) {}
PlatformViewEmbedder::PlatformViewEmbedder(
PlatformView::Delegate& delegate,
blink::TaskRunners task_runners,
EmbedderSurfaceSoftware::SoftwareDispatchTable software_dispatch_table,
PlatformDispatchTable platform_dispatch_table)
: PlatformView(delegate, std::move(task_runners)),
embedder_surface_(
std::make_unique<EmbedderSurfaceSoftware>(software_dispatch_table)),
platform_dispatch_table_(platform_dispatch_table) {}
PlatformViewEmbedder::~PlatformViewEmbedder() = default;
// |shell::GPUSurfaceGLDelegate|
bool PlatformViewEmbedder::GLContextMakeCurrent() {
return dispatch_table_.gl_make_current_callback();
}
// |shell::GPUSurfaceGLDelegate|
bool PlatformViewEmbedder::GLContextClearCurrent() {
return dispatch_table_.gl_clear_current_callback();
}
// |shell::GPUSurfaceGLDelegate|
bool PlatformViewEmbedder::GLContextPresent() {
return dispatch_table_.gl_present_callback();
}
// |shell::GPUSurfaceGLDelegate|
intptr_t PlatformViewEmbedder::GLContextFBO() const {
return dispatch_table_.gl_fbo_callback();
}
// |shell::GPUSurfaceGLDelegate|
bool PlatformViewEmbedder::GLContextFBOResetAfterPresent() const {
return fbo_reset_after_present_;
}
// |shell::GPUSurfaceGLDelegate|
SkMatrix PlatformViewEmbedder::GLContextSurfaceTransformation() const {
auto callback = dispatch_table_.gl_surface_transformation_callback;
if (!callback) {
SkMatrix matrix;
matrix.setIdentity();
return matrix;
}
return callback();
}
void PlatformViewEmbedder::HandlePlatformMessage(
fml::RefPtr<blink::PlatformMessage> message) {
if (!message) {
@@ -64,25 +40,31 @@ void PlatformViewEmbedder::HandlePlatformMessage(
return;
}
if (dispatch_table_.platform_message_response_callback == nullptr) {
if (platform_dispatch_table_.platform_message_response_callback == nullptr) {
message->response()->CompleteEmpty();
return;
}
dispatch_table_.platform_message_response_callback(std::move(message));
platform_dispatch_table_.platform_message_response_callback(
std::move(message));
}
// |shell::PlatformView|
std::unique_ptr<Surface> PlatformViewEmbedder::CreateRenderingSurface() {
return std::make_unique<GPUSurfaceGL>(this);
if (embedder_surface_ == nullptr) {
FML_LOG(ERROR) << "Embedder surface was null.";
return nullptr;
}
return embedder_surface_->CreateGPUSurface();
}
// |shell::PlatformView|
sk_sp<GrContext> PlatformViewEmbedder::CreateResourceContext() const {
auto callback = dispatch_table_.gl_make_resource_current_callback;
if (callback && callback()) {
return IOManager::CreateCompatibleResourceLoadingContext(
GrBackend::kOpenGL_GrBackend);
if (embedder_surface_ == nullptr) {
FML_LOG(ERROR) << "Embedder surface was null.";
return nullptr;
}
return nullptr;
return embedder_surface_->CreateResourceContext();
}
} // namespace shell

View File

@@ -5,62 +5,50 @@
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_PLATFORM_VIEW_EMBEDDER_H_
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_PLATFORM_VIEW_EMBEDDER_H_
#include <functional>
#include "flutter/fml/macros.h"
#include "flutter/shell/common/platform_view.h"
#include "flutter/shell/gpu/gpu_surface_gl.h"
#include "flutter/shell/platform/embedder/embedder.h"
#include "flutter/shell/platform/embedder/embedder_surface.h"
#include "flutter/shell/platform/embedder/embedder_surface_gl.h"
#include "flutter/shell/platform/embedder/embedder_surface_software.h"
namespace shell {
class PlatformViewEmbedder final : public PlatformView,
public GPUSurfaceGLDelegate {
class PlatformViewEmbedder final : public PlatformView {
public:
using PlatformMessageResponseCallback =
std::function<void(fml::RefPtr<blink::PlatformMessage>)>;
struct DispatchTable {
std::function<bool(void)> gl_make_current_callback; // required
std::function<bool(void)> gl_clear_current_callback; // required
std::function<bool(void)> gl_present_callback; // required
std::function<intptr_t(void)> gl_fbo_callback; // required
struct PlatformDispatchTable {
PlatformMessageResponseCallback
platform_message_response_callback; // optional
std::function<bool(void)> gl_make_resource_current_callback; // optional
std::function<SkMatrix(void)>
gl_surface_transformation_callback; // optional
platform_message_response_callback; // optional
};
// Creates a platform view that sets up an OpenGL rasterizer.
PlatformViewEmbedder(PlatformView::Delegate& delegate,
blink::TaskRunners task_runners,
DispatchTable dispatch_table,
bool fbo_reset_after_present);
EmbedderSurfaceGL::GLDispatchTable gl_dispatch_table,
bool fbo_reset_after_present,
PlatformDispatchTable platform_dispatch_table);
// Create a platform view that sets up a software rasterizer.
PlatformViewEmbedder(
PlatformView::Delegate& delegate,
blink::TaskRunners task_runners,
EmbedderSurfaceSoftware::SoftwareDispatchTable software_dispatch_table,
PlatformDispatchTable platform_dispatch_table);
~PlatformViewEmbedder() override;
// |shell::GPUSurfaceGLDelegate|
bool GLContextMakeCurrent() override;
// |shell::GPUSurfaceGLDelegate|
bool GLContextClearCurrent() override;
// |shell::GPUSurfaceGLDelegate|
bool GLContextPresent() override;
// |shell::GPUSurfaceGLDelegate|
intptr_t GLContextFBO() const override;
// |shell::GPUSurfaceGLDelegate|
bool GLContextFBOResetAfterPresent() const override;
// |shell::GPUSurfaceGLDelegate|
SkMatrix GLContextSurfaceTransformation() const override;
// |shell::PlatformView|
void HandlePlatformMessage(
fml::RefPtr<blink::PlatformMessage> message) override;
private:
DispatchTable dispatch_table_;
bool fbo_reset_after_present_;
std::unique_ptr<EmbedderSurface> embedder_surface_;
PlatformDispatchTable platform_dispatch_table_;
// |shell::PlatformView|
std::unique_ptr<Surface> CreateRenderingSurface() override;