53 const std::shared_ptr<impeller::ReactorGLES::Worker>& worker,
54 bool enable_gpu_tracing,
55 std::shared_ptr<fml::BasicTaskRunner> io_task_runner) {
56 auto proc_table = std::make_unique<impeller::ProcTableGLES>(
59 if (!proc_table->IsValid()) {
60 FML_LOG(ERROR) <<
"Could not create OpenGL proc table.";
63 std::vector<std::shared_ptr<fml::Mapping>> gles2_shader_mappings = {
64 std::make_shared<fml::NonOwnedMapping>(
65 impeller_entity_shaders_gles_data,
66 impeller_entity_shaders_gles_length),
67 std::make_shared<fml::NonOwnedMapping>(
68 impeller_framebuffer_blend_shaders_gles_data,
69 impeller_framebuffer_blend_shaders_gles_length),
74 bool is_gles3 = proc_table->GetDescription()->GetGlVersion().IsAtLeast(
77 std::vector<std::shared_ptr<fml::Mapping>> gles3_shader_mappings = {
78 std::make_shared<fml::NonOwnedMapping>(
79 impeller_entity_shaders_gles3_data,
80 impeller_entity_shaders_gles3_length),
81 std::make_shared<fml::NonOwnedMapping>(
82 impeller_framebuffer_blend_shaders_gles3_data,
83 impeller_framebuffer_blend_shaders_gles3_length),
88 is_gles3 ? gles3_shader_mappings : gles2_shader_mappings,
89 enable_gpu_tracing, std::move(io_task_runner));
93 enable_gpu_tracing, std::move(io_task_runner));
97 FML_LOG(ERROR) <<
"Could not create OpenGLES Impeller Context.";
101 if (!
context->AddReactorWorker(worker).has_value()) {
102 FML_LOG(ERROR) <<
"Could not add reactor worker.";
105 FML_LOG(IMPORTANT) <<
"Using the Impeller rendering backend (OpenGLES).";
110 std::unique_ptr<impeller::egl::Display> display,
111 bool enable_gpu_tracing,
112 std::shared_ptr<fml::BasicTaskRunner> io_task_runner)
116 io_task_runner_(
std::move(io_task_runner)) {
117 if (!display_ || !display_->IsValid()) {
118 FML_LOG(ERROR) <<
"Could not create context with invalid EGL display.";
130 std::unique_ptr<impeller::egl::Config> onscreen_config =
131 display_->ChooseConfig(desc);
133 if (!onscreen_config) {
135 onscreen_config = display_->ChooseConfig(desc);
138 if (!onscreen_config) {
141 onscreen_config = display_->ChooseConfig(desc);
142 if (onscreen_config) {
143 FML_LOG(INFO) <<
"Warning: This device doesn't support MSAA for onscreen "
144 "framebuffers. Falling back to a single sample.";
146 FML_LOG(ERROR) <<
"Could not choose onscreen config.";
152 auto offscreen_config = display_->ChooseConfig(desc);
153 if (!offscreen_config) {
154 FML_LOG(ERROR) <<
"Could not choose offscreen config.";
158 auto onscreen_context = display_->CreateContext(*onscreen_config,
nullptr);
159 if (!onscreen_context) {
160 FML_LOG(ERROR) <<
"Could not create onscreen context.";
164 auto offscreen_context =
165 display_->CreateContext(*offscreen_config, onscreen_context.get());
166 if (!offscreen_context) {
167 FML_LOG(ERROR) <<
"Could not create offscreen context.";
173 auto offscreen_surface =
174 display_->CreatePixelBufferSurface(*offscreen_config, 1u, 1u);
175 if (!offscreen_context->MakeCurrent(*offscreen_surface)) {
176 FML_LOG(ERROR) <<
"Could not make offscreen context current.";
181 reactor_worker_, enable_gpu_tracing, io_task_runner_);
183 if (!impeller_context) {
184 FML_LOG(ERROR) <<
"Could not create Impeller context.";
188 if (!offscreen_context->ClearCurrent()) {
189 FML_LOG(ERROR) <<
"Could not clear offscreen context.";
195 reactor_worker_](impeller::egl ::Context::LifecycleEvent event) {
198 worker->SetReactionsAllowedOnCurrentThread(
true);
201 worker->SetReactionsAllowedOnCurrentThread(
false);
205 if (!onscreen_context->AddLifecycleListener(listener).has_value() ||
206 !offscreen_context->AddLifecycleListener(listener).has_value()) {
207 FML_LOG(ERROR) <<
"Could not add lifecycle listeners";
210 onscreen_config_ = std::move(onscreen_config);
211 offscreen_config_ = std::move(offscreen_config);
212 onscreen_context_ = std::move(onscreen_context);
213 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)
AndroidContextGLImpeller(std::unique_ptr< impeller::egl::Display > display, bool enable_gpu_tracing, std::shared_ptr< fml::BasicTaskRunner > io_task_runner)
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()
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::shared_ptr< fml::BasicTaskRunner > io_task_runner=nullptr)
std::function< void(LifecycleEvent)> LifecycleListener