Flutter Engine
 
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)
 
 ~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 14 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 
)

Definition at line 108 of file android_context_gl_impeller.cc.

112 reactor_worker_(std::shared_ptr<ReactorWorker>(new ReactorWorker())),
113 display_(std::move(display)) {
114 if (!display_ || !display_->IsValid()) {
115 FML_LOG(ERROR) << "Could not create context with invalid EGL display.";
116 return;
117 }
118
125
127 std::unique_ptr<impeller::egl::Config> onscreen_config =
128 display_->ChooseConfig(desc);
129
130 if (!onscreen_config) {
132 onscreen_config = display_->ChooseConfig(desc);
133 }
134
135 if (!onscreen_config) {
136 // Fallback for Android emulator.
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.";
142 } else {
143 FML_LOG(ERROR) << "Could not choose onscreen config.";
144 return;
145 }
146 }
147
149 auto offscreen_config = display_->ChooseConfig(desc);
150 if (!offscreen_config) {
151 FML_LOG(ERROR) << "Could not choose offscreen config.";
152 return;
153 }
154
155 auto onscreen_context = display_->CreateContext(*onscreen_config, nullptr);
156 if (!onscreen_context) {
157 FML_LOG(ERROR) << "Could not create onscreen context.";
158 return;
159 }
160
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.";
165 return;
166 }
167
168 // Creating the impeller::Context requires a current context, which requires
169 // some surface.
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.";
174 return;
175 }
176
177 auto impeller_context =
178 CreateImpellerContext(reactor_worker_, enable_gpu_tracing);
179
180 if (!impeller_context) {
181 FML_LOG(ERROR) << "Could not create Impeller context.";
182 return;
183 }
184
185 if (!offscreen_context->ClearCurrent()) {
186 FML_LOG(ERROR) << "Could not clear offscreen context.";
187 return;
188 }
189 // Setup context listeners.
191 [worker =
192 reactor_worker_](impeller::egl ::Context::LifecycleEvent event) {
193 switch (event) {
195 worker->SetReactionsAllowedOnCurrentThread(true);
196 break;
198 worker->SetReactionsAllowedOnCurrentThread(false);
199 break;
200 }
201 };
202 if (!onscreen_context->AddLifecycleListener(listener).has_value() ||
203 !offscreen_context->AddLifecycleListener(listener).has_value()) {
204 FML_LOG(ERROR) << "Could not add lifecycle listeners";
205 }
206
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);
211 SetImpellerContext(impeller_context);
212
213 is_valid_ = true;
214}
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 240 of file android_context_gl_impeller.cc.

240 {
241 return display_->CreatePixelBufferSurface(*offscreen_config_, 1u, 1u);
242}

◆ CreateOnscreenSurface()

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

Definition at line 262 of file android_context_gl_impeller.cc.

262 {
263 return display_->CreateWindowSurface(*onscreen_config_, window);
264}
GLFWwindow * window
Definition main.cc:60

References window.

◆ IsValid()

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

Reimplemented from flutter::AndroidContext.

Definition at line 218 of file android_context_gl_impeller.cc.

218 {
219 return is_valid_;
220}

◆ OnscreenContextClearCurrent()

bool flutter::AndroidContextGLImpeller::OnscreenContextClearCurrent ( )

Definition at line 253 of file android_context_gl_impeller.cc.

253 {
254 if (!onscreen_context_) {
255 return false;
256 }
257
258 return onscreen_context_->ClearCurrent();
259}

◆ OnscreenContextMakeCurrent()

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

Definition at line 244 of file android_context_gl_impeller.cc.

245 {
246 if (!onscreen_surface || !onscreen_context_) {
247 return false;
248 }
249
250 return onscreen_context_->MakeCurrent(*onscreen_surface);
251}

◆ RenderingApi()

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

Reimplemented from flutter::AndroidContext.

Definition at line 266 of file android_context_gl_impeller.cc.

References flutter::kImpellerOpenGLES.

◆ ResourceContextClearCurrent()

bool flutter::AndroidContextGLImpeller::ResourceContextClearCurrent ( )

Definition at line 222 of file android_context_gl_impeller.cc.

222 {
223 if (!offscreen_context_) {
224 return false;
225 }
226
227 return offscreen_context_->ClearCurrent();
228}

◆ ResourceContextMakeCurrent()

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

Definition at line 230 of file android_context_gl_impeller.cc.

231 {
232 if (!offscreen_context_ || !offscreen_surface) {
233 return false;
234 }
235
236 return offscreen_context_->MakeCurrent(*offscreen_surface);
237}

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