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,
81 std::shared_ptr<fml::BasicTaskRunner> io_task_runner,
83 : gl_dispatch_table_(
std::move(gl_dispatch_table)),
84 fbo_reset_after_present_(fbo_reset_after_present),
85 external_view_embedder_(
std::move(external_view_embedder)),
100 auto gl = std::make_unique<impeller::ProcTableGLES>(
102 if (!gl->IsValid()) {
106 const auto is_gles3 =
108 const auto shader_mappings = GetShaderMappings(is_gles3);
111 impeller_flags, std::move(gl), shader_mappings,
112 false, std::move(io_task_runner));
114 if (!impeller_context_) {
115 FML_LOG(ERROR) <<
"Could not create Impeller context.";
119 auto worker_id = impeller_context_->AddReactorWorker(worker_);
120 if (!worker_id.has_value()) {
121 FML_LOG(ERROR) <<
"Could not add reactor worker.";
127 FML_LOG(IMPORTANT) <<
"Using the Impeller rendering backend (OpenGLESSDF).";
129 FML_LOG(IMPORTANT) <<
"Using the Impeller rendering backend (OpenGLES).";
137bool EmbedderSurfaceGLImpeller::IsValid()
const {
142std::unique_ptr<GLContextResult>
143EmbedderSurfaceGLImpeller::GLContextMakeCurrent() {
144 worker_->SetReactionsAllowedOnCurrentThread(
true);
145 return std::make_unique<GLContextDefaultResult>(
150bool EmbedderSurfaceGLImpeller::GLContextClearCurrent() {
151 worker_->SetReactionsAllowedOnCurrentThread(
false);
156bool EmbedderSurfaceGLImpeller::GLContextPresent(
157 const GLPresentInfo& present_info) {
163GLFBOInfo EmbedderSurfaceGLImpeller::GLContextFBO(
164 GLFrameInfo frame_info)
const {
172bool EmbedderSurfaceGLImpeller::GLContextFBOResetAfterPresent()
const {
173 return fbo_reset_after_present_;
177DlMatrix EmbedderSurfaceGLImpeller::GLContextSurfaceTransformation()
const {
187EmbedderSurfaceGLImpeller::GetGLProcResolver()
const {
192SurfaceFrame::FramebufferInfo
193EmbedderSurfaceGLImpeller::GLContextFramebufferInfo()
const {
195 auto info = SurfaceFrame::FramebufferInfo{};
196 info.supports_readback =
true;
197 info.supports_partial_repaint =
203std::unique_ptr<Surface> EmbedderSurfaceGLImpeller::CreateGPUSurface() {
207 GLContextMakeCurrent();
209 return std::make_unique<GPUSurfaceGLImpeller>(
212 !external_view_embedder_
217std::shared_ptr<impeller::Context>
218EmbedderSurfaceGLImpeller::CreateImpellerContext()
const {
219 return impeller_context_;
223sk_sp<GrDirectContext> EmbedderSurfaceGLImpeller::CreateResourceContext()
226 worker_->SetReactionsAllowedOnCurrentThread(
true);
228 FML_DLOG(ERROR) <<
"Could not make the resource context current.";
229 worker_->SetReactionsAllowedOnCurrentThread(
false);
235void EmbedderSurfaceGLImpeller::ReleaseResourceContext()
const {
236 worker_->SetReactionsAllowedOnCurrentThread(
false);
EmbedderSurfaceGLImpeller(EmbedderSurfaceGLSkia::GLDispatchTable gl_dispatch_table, bool fbo_reset_after_present, std::shared_ptr< EmbedderExternalViewEmbedder > external_view_embedder, std::shared_ptr< fml::BasicTaskRunner > io_task_runner, 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, std::shared_ptr< fml::BasicTaskRunner > io_task_runner=nullptr)
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::shared_ptr< ReactorGLES > reactor
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)