Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
flutter::AndroidContextGLImpeller Class Reference

#include <android_context_gl_impeller.h>

Inheritance diagram for flutter::AndroidContextGLImpeller:
flutter::AndroidContext

Classes

class  ReactorWorker
 

Public Member Functions

 AndroidContextGLImpeller (std::unique_ptr< impeller::egl::Display > display, bool enable_gpu_tracing, std::shared_ptr< fml::BasicTaskRunner > io_task_runner)
 
 ~AndroidContextGLImpeller ()
 
bool IsValid () const override
 
AndroidRenderingAPI RenderingApi () const override
 
bool ResourceContextMakeCurrent (impeller::egl::Surface *offscreen_surface)
 
bool ResourceContextClearCurrent ()
 
std::unique_ptr< impeller::egl::SurfaceCreateOffscreenSurface ()
 
bool OnscreenContextMakeCurrent (impeller::egl::Surface *onscreen_surface)
 
bool OnscreenContextClearCurrent ()
 
std::unique_ptr< impeller::egl::SurfaceCreateOnscreenSurface (EGLNativeWindowType window)
 
- Public Member Functions inherited from flutter::AndroidContext
 AndroidContext (AndroidRenderingAPI rendering_api)
 
virtual ~AndroidContext ()
 
virtual bool IsDynamicSelection () const
 
void SetMainSkiaContext (const sk_sp< GrDirectContext > &main_context)
 Setter for the Skia context to be used by subsequent AndroidSurfaces.
 
sk_sp< GrDirectContext > GetMainSkiaContext () const
 Accessor for the Skia context associated with AndroidSurfaces and the raster thread.
 
virtual std::shared_ptr< impeller::ContextGetImpellerContext () const
 Accessor for the Impeller context associated with AndroidSurfaces and the raster thread.
 
virtual void SetupImpellerContext ()
 Perform deferred setup for the impeller Context.
 

Additional Inherited Members

- Protected Member Functions inherited from flutter::AndroidContext
void SetImpellerContext (const std::shared_ptr< impeller::Context > &impeller_context)
 

Detailed Description

Definition at line 15 of file android_context_gl_impeller.h.

Constructor & Destructor Documentation

◆ AndroidContextGLImpeller()

flutter::AndroidContextGLImpeller::AndroidContextGLImpeller ( std::unique_ptr< impeller::egl::Display display,
bool  enable_gpu_tracing,
std::shared_ptr< fml::BasicTaskRunner io_task_runner 
)

Definition at line 109 of file android_context_gl_impeller.cc.

114 reactor_worker_(std::shared_ptr<ReactorWorker>(new ReactorWorker())),
115 display_(std::move(display)),
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.";
119 return;
120 }
121
128
130 std::unique_ptr<impeller::egl::Config> onscreen_config =
131 display_->ChooseConfig(desc);
132
133 if (!onscreen_config) {
135 onscreen_config = display_->ChooseConfig(desc);
136 }
137
138 if (!onscreen_config) {
139 // Fallback for Android emulator.
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.";
145 } else {
146 FML_LOG(ERROR) << "Could not choose onscreen config.";
147 return;
148 }
149 }
150
152 auto offscreen_config = display_->ChooseConfig(desc);
153 if (!offscreen_config) {
154 FML_LOG(ERROR) << "Could not choose offscreen config.";
155 return;
156 }
157
158 auto onscreen_context = display_->CreateContext(*onscreen_config, nullptr);
159 if (!onscreen_context) {
160 FML_LOG(ERROR) << "Could not create onscreen context.";
161 return;
162 }
163
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.";
168 return;
169 }
170
171 // Creating the impeller::Context requires a current context, which requires
172 // some surface.
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.";
177 return;
178 }
179
180 auto impeller_context = CreateImpellerContext(
181 reactor_worker_, enable_gpu_tracing, io_task_runner_);
182
183 if (!impeller_context) {
184 FML_LOG(ERROR) << "Could not create Impeller context.";
185 return;
186 }
187
188 if (!offscreen_context->ClearCurrent()) {
189 FML_LOG(ERROR) << "Could not clear offscreen context.";
190 return;
191 }
192 // Setup context listeners.
194 [worker =
195 reactor_worker_](impeller::egl ::Context::LifecycleEvent event) {
196 switch (event) {
198 worker->SetReactionsAllowedOnCurrentThread(true);
199 break;
201 worker->SetReactionsAllowedOnCurrentThread(false);
202 break;
203 }
204 };
205 if (!onscreen_context->AddLifecycleListener(listener).has_value() ||
206 !offscreen_context->AddLifecycleListener(listener).has_value()) {
207 FML_LOG(ERROR) << "Could not add lifecycle listeners";
208 }
209
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);
214 SetImpellerContext(impeller_context);
215
216 is_valid_ = true;
217}
static std::shared_ptr< impeller::ContextMTL > CreateImpellerContext()
AndroidContext(AndroidRenderingAPI rendering_api)
void SetImpellerContext(const std::shared_ptr< impeller::Context > &impeller_context)
std::function< void(LifecycleEvent)> LifecycleListener
Definition context.h:75
#define FML_LOG(severity)
Definition logging.h:101

References impeller::egl::ConfigDescriptor::api, impeller::egl::ConfigDescriptor::color_format, CreateImpellerContext(), impeller::egl::ConfigDescriptor::depth_bits, FML_LOG, impeller::egl::Context::kDidMakeCurrent, impeller::egl::kEight, impeller::egl::kFour, impeller::egl::kOne, impeller::egl::kOpenGLES2, impeller::egl::kOpenGLES3, impeller::egl::kPBuffer, impeller::egl::kRGBA8888, impeller::egl::kTwentyFour, impeller::egl::Context::kWillClearCurrent, impeller::egl::kWindow, impeller::egl::ConfigDescriptor::samples, flutter::AndroidContext::SetImpellerContext(), impeller::egl::ConfigDescriptor::stencil_bits, and impeller::egl::ConfigDescriptor::surface_type.

◆ ~AndroidContextGLImpeller()

flutter::AndroidContextGLImpeller::~AndroidContextGLImpeller ( )
default

Member Function Documentation

◆ CreateOffscreenSurface()

std::unique_ptr< impeller::egl::Surface > flutter::AndroidContextGLImpeller::CreateOffscreenSurface ( )

Definition at line 243 of file android_context_gl_impeller.cc.

243 {
244 return display_->CreatePixelBufferSurface(*offscreen_config_, 1u, 1u);
245}

◆ CreateOnscreenSurface()

std::unique_ptr< impeller::egl::Surface > flutter::AndroidContextGLImpeller::CreateOnscreenSurface ( EGLNativeWindowType  window)

Definition at line 265 of file android_context_gl_impeller.cc.

265 {
266 return display_->CreateWindowSurface(*onscreen_config_, window);
267}
GLFWwindow * window
Definition main.cc:60

References window.

◆ IsValid()

bool flutter::AndroidContextGLImpeller::IsValid ( ) const
overridevirtual

Reimplemented from flutter::AndroidContext.

Definition at line 221 of file android_context_gl_impeller.cc.

221 {
222 return is_valid_;
223}

◆ OnscreenContextClearCurrent()

bool flutter::AndroidContextGLImpeller::OnscreenContextClearCurrent ( )

Definition at line 256 of file android_context_gl_impeller.cc.

256 {
257 if (!onscreen_context_) {
258 return false;
259 }
260
261 return onscreen_context_->ClearCurrent();
262}

◆ OnscreenContextMakeCurrent()

bool flutter::AndroidContextGLImpeller::OnscreenContextMakeCurrent ( impeller::egl::Surface onscreen_surface)

Definition at line 247 of file android_context_gl_impeller.cc.

248 {
249 if (!onscreen_surface || !onscreen_context_) {
250 return false;
251 }
252
253 return onscreen_context_->MakeCurrent(*onscreen_surface);
254}

◆ RenderingApi()

AndroidRenderingAPI flutter::AndroidContextGLImpeller::RenderingApi ( ) const
overridevirtual

Reimplemented from flutter::AndroidContext.

Definition at line 269 of file android_context_gl_impeller.cc.

References flutter::kImpellerOpenGLES.

◆ ResourceContextClearCurrent()

bool flutter::AndroidContextGLImpeller::ResourceContextClearCurrent ( )

Definition at line 225 of file android_context_gl_impeller.cc.

225 {
226 if (!offscreen_context_) {
227 return false;
228 }
229
230 return offscreen_context_->ClearCurrent();
231}

◆ ResourceContextMakeCurrent()

bool flutter::AndroidContextGLImpeller::ResourceContextMakeCurrent ( impeller::egl::Surface offscreen_surface)

Definition at line 233 of file android_context_gl_impeller.cc.

234 {
235 if (!offscreen_context_ || !offscreen_surface) {
236 return false;
237 }
238
239 return offscreen_context_->MakeCurrent(*offscreen_surface);
240}

The documentation for this class was generated from the following files: