5#include "flutter/shell/platform/embedder/embedder_surface_gl_impeller.h"
9#include "impeller/entity/gles/entity_shaders_gles.h"
10#include "impeller/entity/gles/framebuffer_blend_shaders_gles.h"
11#include "impeller/entity/gles/modern_shaders_gles.h"
16#include "impeller/scene/shaders/gles/scene_shaders_gles.h"
29 auto found = reactions_allowed_.find(std::this_thread::get_id());
30 if (found == reactions_allowed_.end()) {
38 reactions_allowed_[std::this_thread::get_id()] = allowed;
42 mutable impeller::RWMutex mutex_;
43 std::map<std::thread::id, bool> reactions_allowed_ IPLR_GUARDED_BY(mutex_);
50 bool fbo_reset_after_present,
51 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
52 : gl_dispatch_table_(
std::move(gl_dispatch_table)),
53 fbo_reset_after_present_(fbo_reset_after_present),
54 external_view_embedder_(
std::move(external_view_embedder)),
69 std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
70 std::make_shared<fml::NonOwnedMapping>(
71 impeller_entity_shaders_gles_data,
72 impeller_entity_shaders_gles_length),
73 std::make_shared<fml::NonOwnedMapping>(
74 impeller_modern_shaders_gles_data,
75 impeller_modern_shaders_gles_length),
76 std::make_shared<fml::NonOwnedMapping>(
77 impeller_framebuffer_blend_shaders_gles_data,
78 impeller_framebuffer_blend_shaders_gles_length),
80 std::make_shared<fml::NonOwnedMapping>(
81 impeller_scene_shaders_gles_data, impeller_scene_shaders_gles_length),
84 auto gl = std::make_unique<impeller::ProcTableGLES>(
91 std::move(
gl), shader_mappings,
false);
93 if (!impeller_context_) {
98 auto worker_id = impeller_context_->AddReactorWorker(worker_);
99 if (!worker_id.has_value()) {
105 FML_LOG(IMPORTANT) <<
"Using the Impeller rendering backend (OpenGL).";
112bool EmbedderSurfaceGLImpeller::IsValid()
const {
117std::unique_ptr<GLContextResult>
118EmbedderSurfaceGLImpeller::GLContextMakeCurrent() {
119 worker_->SetReactionsAllowedOnCurrentThread(
true);
120 return std::make_unique<GLContextDefaultResult>(
125bool EmbedderSurfaceGLImpeller::GLContextClearCurrent() {
126 worker_->SetReactionsAllowedOnCurrentThread(
false);
131bool EmbedderSurfaceGLImpeller::GLContextPresent(
132 const GLPresentInfo& present_info) {
138GLFBOInfo EmbedderSurfaceGLImpeller::GLContextFBO(
139 GLFrameInfo frame_info)
const {
147bool EmbedderSurfaceGLImpeller::GLContextFBOResetAfterPresent()
const {
148 return fbo_reset_after_present_;
152SkMatrix EmbedderSurfaceGLImpeller::GLContextSurfaceTransformation()
const {
164EmbedderSurfaceGLImpeller::GetGLProcResolver()
const {
169SurfaceFrame::FramebufferInfo
170EmbedderSurfaceGLImpeller::GLContextFramebufferInfo()
const {
172 auto info = SurfaceFrame::FramebufferInfo{};
173 info.supports_readback =
true;
174 info.supports_partial_repaint =
180std::unique_ptr<Surface> EmbedderSurfaceGLImpeller::CreateGPUSurface() {
184 GLContextMakeCurrent();
186 return std::make_unique<GPUSurfaceGLImpeller>(
189 !external_view_embedder_
194std::shared_ptr<impeller::Context>
195EmbedderSurfaceGLImpeller::CreateImpellerContext()
const {
196 return impeller_context_;
203 worker_->SetReactionsAllowedOnCurrentThread(
true);
205 FML_DLOG(
ERROR) <<
"Could not make the resource context current.";
206 worker_->SetReactionsAllowedOnCurrentThread(
false);
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
EmbedderSurfaceGLImpeller(EmbedderSurfaceGLSkia::GLDispatchTable gl_dispatch_table, bool fbo_reset_after_present, std::shared_ptr< EmbedderExternalViewEmbedder > external_view_embedder)
~EmbedderSurfaceGLImpeller() override
std::function< void *(const char *)> GLProcResolver
bool CanReactorReactOnCurrentThreadNow(const impeller::ReactorGLES &reactor) const override
Determines the ability of the worker to service a reaction on the current thread. The OpenGL context ...
void SetReactionsAllowedOnCurrentThread(bool allowed)
static std::shared_ptr< ContextGLES > Create(std::unique_ptr< ProcTableGLES > gl, const std::vector< std::shared_ptr< fml::Mapping > > &shader_libraries, bool enable_gpu_tracing)
A delegate implemented by a thread on which an OpenGL context is current. There may be multiple worke...
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_DLOG(severity)
#define FML_LOG(severity)
unsigned useCenter Optional< SkMatrix > matrix
std::function< bool(void)> gl_clear_current_callback
std::function< GLFBOInfo(intptr_t)> gl_populate_existing_damage
std::function< bool(void)> gl_make_current_callback
std::function< intptr_t(GLFrameInfo)> gl_fbo_callback
std::function< bool(GLPresentInfo)> gl_present_callback
std::function< bool(void)> gl_make_resource_current_callback
std::function< void *(const char *)> gl_proc_resolver
std::function< SkMatrix(void)> gl_surface_transformation_callback