10#include "impeller/entity/gles/entity_shaders_gles.h"
11#include "impeller/entity/gles/framebuffer_blend_shaders_gles.h"
12#include "impeller/entity/gles/modern_shaders_gles.h"
13#include "impeller/entity/gles3/entity_shaders_gles.h"
14#include "impeller/entity/gles3/framebuffer_blend_shaders_gles.h"
15#include "impeller/entity/gles3/modern_shaders_gles.h"
22std::vector<std::shared_ptr<fml::Mapping>> GetShaderMappings(
bool is_gles3) {
25 std::make_shared<fml::NonOwnedMapping>(
26 impeller_entity_shaders_gles3_data,
27 impeller_entity_shaders_gles3_length),
28 std::make_shared<fml::NonOwnedMapping>(
29 impeller_modern_shaders_gles3_data,
30 impeller_modern_shaders_gles3_length),
31 std::make_shared<fml::NonOwnedMapping>(
32 impeller_framebuffer_blend_shaders_gles3_data,
33 impeller_framebuffer_blend_shaders_gles3_length),
37 std::make_shared<fml::NonOwnedMapping>(
38 impeller_entity_shaders_gles_data,
39 impeller_entity_shaders_gles_length),
40 std::make_shared<fml::NonOwnedMapping>(
41 impeller_modern_shaders_gles_data,
42 impeller_modern_shaders_gles_length),
43 std::make_shared<fml::NonOwnedMapping>(
44 impeller_framebuffer_blend_shaders_gles_data,
45 impeller_framebuffer_blend_shaders_gles_length),
58 auto found = reactions_allowed_.find(std::this_thread::get_id());
59 if (found == reactions_allowed_.end()) {
67 reactions_allowed_[std::this_thread::get_id()] = allowed;
71 mutable impeller::RWMutex mutex_;
72 std::map<std::thread::id, bool> reactions_allowed_
IPLR_GUARDED_BY(mutex_);
79 bool fbo_reset_after_present,
80 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder,
82 : gl_dispatch_table_(
std::move(gl_dispatch_table)),
83 fbo_reset_after_present_(fbo_reset_after_present),
84 external_view_embedder_(
std::move(external_view_embedder)),
99 auto gl = std::make_unique<impeller::ProcTableGLES>(
101 if (!gl->IsValid()) {
105 const auto is_gles3 =
107 const auto shader_mappings = GetShaderMappings(is_gles3);
110 impeller_flags, std::move(gl), shader_mappings,
113 if (!impeller_context_) {
114 FML_LOG(ERROR) <<
"Could not create Impeller context.";
118 auto worker_id = impeller_context_->AddReactorWorker(worker_);
119 if (!worker_id.has_value()) {
120 FML_LOG(ERROR) <<
"Could not add reactor worker.";
126 FML_LOG(IMPORTANT) <<
"Using the Impeller rendering backend (OpenGLESSDF).";
128 FML_LOG(IMPORTANT) <<
"Using the Impeller rendering backend (OpenGLES).";
136bool EmbedderSurfaceGLImpeller::IsValid()
const {
141std::unique_ptr<GLContextResult>
142EmbedderSurfaceGLImpeller::GLContextMakeCurrent() {
143 worker_->SetReactionsAllowedOnCurrentThread(
true);
144 return std::make_unique<GLContextDefaultResult>(
149bool EmbedderSurfaceGLImpeller::GLContextClearCurrent() {
150 worker_->SetReactionsAllowedOnCurrentThread(
false);
155bool EmbedderSurfaceGLImpeller::GLContextPresent(
156 const GLPresentInfo& present_info) {
162GLFBOInfo EmbedderSurfaceGLImpeller::GLContextFBO(
163 GLFrameInfo frame_info)
const {
171bool EmbedderSurfaceGLImpeller::GLContextFBOResetAfterPresent()
const {
172 return fbo_reset_after_present_;
176DlMatrix EmbedderSurfaceGLImpeller::GLContextSurfaceTransformation()
const {
186EmbedderSurfaceGLImpeller::GetGLProcResolver()
const {
191SurfaceFrame::FramebufferInfo
192EmbedderSurfaceGLImpeller::GLContextFramebufferInfo()
const {
194 auto info = SurfaceFrame::FramebufferInfo{};
195 info.supports_readback =
true;
196 info.supports_partial_repaint =
202std::unique_ptr<Surface> EmbedderSurfaceGLImpeller::CreateGPUSurface() {
206 GLContextMakeCurrent();
208 return std::make_unique<GPUSurfaceGLImpeller>(
211 !external_view_embedder_
216std::shared_ptr<impeller::Context>
217EmbedderSurfaceGLImpeller::CreateImpellerContext()
const {
218 return impeller_context_;
222sk_sp<GrDirectContext> EmbedderSurfaceGLImpeller::CreateResourceContext()
225 worker_->SetReactionsAllowedOnCurrentThread(
true);
227 FML_DLOG(ERROR) <<
"Could not make the resource context current.";
228 worker_->SetReactionsAllowedOnCurrentThread(
false);
EmbedderSurfaceGLImpeller(EmbedderSurfaceGLSkia::GLDispatchTable gl_dispatch_table, bool fbo_reset_after_present, std::shared_ptr< EmbedderExternalViewEmbedder > external_view_embedder, impeller::Flags impeller_flags={})
~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(const Flags &flags, 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.
FlutterDesktopBinaryReply callback
#define FML_DLOG(severity)
#define FML_LOG(severity)
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
impeller::Matrix DlMatrix
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< DlMatrix(void)> gl_surface_transformation_callback
bool use_sdfs
Use SDFs for rendering.
#define IPLR_GUARDED_BY(x)