53 const std::shared_ptr<impeller::ReactorGLES::Worker>& worker,
54 bool enable_gpu_tracing) {
55 auto proc_table = std::make_unique<impeller::ProcTableGLES>(
58 if (!proc_table->IsValid()) {
59 FML_LOG(ERROR) <<
"Could not create OpenGL proc table.";
62 std::vector<std::shared_ptr<fml::Mapping>> gles2_shader_mappings = {
63 std::make_shared<fml::NonOwnedMapping>(
64 impeller_entity_shaders_gles_data,
65 impeller_entity_shaders_gles_length),
66 std::make_shared<fml::NonOwnedMapping>(
67 impeller_framebuffer_blend_shaders_gles_data,
68 impeller_framebuffer_blend_shaders_gles_length),
73 bool is_gles3 = proc_table->GetDescription()->GetGlVersion().IsAtLeast(
76 std::vector<std::shared_ptr<fml::Mapping>> gles3_shader_mappings = {
77 std::make_shared<fml::NonOwnedMapping>(
78 impeller_entity_shaders_gles3_data,
79 impeller_entity_shaders_gles3_length),
80 std::make_shared<fml::NonOwnedMapping>(
81 impeller_framebuffer_blend_shaders_gles3_data,
82 impeller_framebuffer_blend_shaders_gles3_length),
87 is_gles3 ? gles3_shader_mappings : gles2_shader_mappings,
92 gles2_shader_mappings, enable_gpu_tracing);
96 FML_LOG(ERROR) <<
"Could not create OpenGLES Impeller Context.";
100 if (!context->AddReactorWorker(worker).has_value()) {
101 FML_LOG(ERROR) <<
"Could not add reactor worker.";
104 FML_LOG(IMPORTANT) <<
"Using the Impeller rendering backend (OpenGLES).";
109 std::unique_ptr<impeller::egl::Display> display,
110 bool enable_gpu_tracing)
114 if (!display_ || !display_->IsValid()) {
115 FML_LOG(ERROR) <<
"Could not create context with invalid EGL display.";
127 std::unique_ptr<impeller::egl::Config> onscreen_config =
128 display_->ChooseConfig(desc);
130 if (!onscreen_config) {
132 onscreen_config = display_->ChooseConfig(desc);
135 if (!onscreen_config) {
138 onscreen_config = display_->ChooseConfig(desc);
139 if (onscreen_config) {
140 FML_LOG(INFO) <<
"Warning: This device doesn't support MSAA for onscreen "
141 "framebuffers. Falling back to a single sample.";
143 FML_LOG(ERROR) <<
"Could not choose onscreen config.";
149 auto offscreen_config = display_->ChooseConfig(desc);
150 if (!offscreen_config) {
151 FML_LOG(ERROR) <<
"Could not choose offscreen config.";
155 auto onscreen_context = display_->CreateContext(*onscreen_config,
nullptr);
156 if (!onscreen_context) {
157 FML_LOG(ERROR) <<
"Could not create onscreen context.";
161 auto offscreen_context =
162 display_->CreateContext(*offscreen_config, onscreen_context.get());
163 if (!offscreen_context) {
164 FML_LOG(ERROR) <<
"Could not create offscreen context.";
170 auto offscreen_surface =
171 display_->CreatePixelBufferSurface(*offscreen_config, 1u, 1u);
172 if (!offscreen_context->MakeCurrent(*offscreen_surface)) {
173 FML_LOG(ERROR) <<
"Could not make offscreen context current.";
177 auto impeller_context =
180 if (!impeller_context) {
181 FML_LOG(ERROR) <<
"Could not create Impeller context.";
185 if (!offscreen_context->ClearCurrent()) {
186 FML_LOG(ERROR) <<
"Could not clear offscreen context.";
192 reactor_worker_](impeller::egl ::Context::LifecycleEvent event) {
195 worker->SetReactionsAllowedOnCurrentThread(
true);
198 worker->SetReactionsAllowedOnCurrentThread(
false);
202 if (!onscreen_context->AddLifecycleListener(listener).has_value() ||
203 !offscreen_context->AddLifecycleListener(listener).has_value()) {
204 FML_LOG(ERROR) <<
"Could not add lifecycle listeners";
207 onscreen_config_ = std::move(onscreen_config);
208 offscreen_config_ = std::move(offscreen_config);
209 onscreen_context_ = std::move(onscreen_context);
210 offscreen_context_ = std::move(offscreen_context);
static std::shared_ptr< impeller::ContextMTL > CreateImpellerContext()
void SetReactionsAllowedOnCurrentThread(bool allowed)
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 ...
~ReactorWorker() override=default
std::unique_ptr< impeller::egl::Surface > CreateOnscreenSurface(EGLNativeWindowType window)
bool OnscreenContextMakeCurrent(impeller::egl::Surface *onscreen_surface)
bool OnscreenContextClearCurrent()
bool ResourceContextClearCurrent()
bool IsValid() const override
AndroidRenderingAPI RenderingApi() const override
bool ResourceContextMakeCurrent(impeller::egl::Surface *offscreen_surface)
~AndroidContextGLImpeller()
std::unique_ptr< impeller::egl::Surface > CreateOffscreenSurface()
AndroidContextGLImpeller(std::unique_ptr< impeller::egl::Display > display, bool enable_gpu_tracing)
Holds state that is shared across Android surfaces.
void SetImpellerContext(const std::shared_ptr< impeller::Context > &impeller_context)
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::function< void(LifecycleEvent)> LifecycleListener