Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
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
 
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 ()
 
AndroidRenderingAPI RenderingApi () const
 
virtual bool IsValid () const
 
void SetMainSkiaContext (const sk_sp< GrDirectContext > &main_context)
 Setter for the Skia context to be used by subsequent AndroidSurfaces. More...
 
sk_sp< GrDirectContextGetMainSkiaContext () const
 Accessor for the Skia context associated with AndroidSurfaces and the raster thread. More...
 
std::shared_ptr< impeller::ContextGetImpellerContext () const
 Accessor for the Impeller context associated with AndroidSurfaces and the raster thread. More...
 

Additional Inherited Members

- Protected Member Functions inherited from flutter::AndroidContext
void SetImpellerContext (const std::shared_ptr< impeller::Context > &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 91 of file android_context_gl_impeller.cc.

95 reactor_worker_(std::shared_ptr<ReactorWorker>(new ReactorWorker())),
96 display_(std::move(display)) {
97 if (!display_ || !display_->IsValid()) {
98 FML_DLOG(ERROR) << "Could not create context with invalid EGL display.";
99 return;
100 }
101
108
110 std::unique_ptr<impeller::egl::Config> onscreen_config =
111 display_->ChooseConfig(desc);
112 if (!onscreen_config) {
113 // Fallback for Android emulator.
115 onscreen_config = display_->ChooseConfig(desc);
116 if (onscreen_config) {
117 FML_LOG(INFO) << "Warning: This device doesn't support MSAA for onscreen "
118 "framebuffers. Falling back to a single sample.";
119 } else {
120 FML_DLOG(ERROR) << "Could not choose onscreen config.";
121 return;
122 }
123 }
124
126 auto offscreen_config = display_->ChooseConfig(desc);
127 if (!offscreen_config) {
128 FML_DLOG(ERROR) << "Could not choose offscreen config.";
129 return;
130 }
131
132 auto onscreen_context = display_->CreateContext(*onscreen_config, nullptr);
133 if (!onscreen_context) {
134 FML_DLOG(ERROR) << "Could not create onscreen context.";
135 return;
136 }
137
138 auto offscreen_context =
139 display_->CreateContext(*offscreen_config, onscreen_context.get());
140 if (!offscreen_context) {
141 FML_DLOG(ERROR) << "Could not create offscreen context.";
142 return;
143 }
144
145 // Creating the impeller::Context requires a current context, which requires
146 // some surface.
147 auto offscreen_surface =
148 display_->CreatePixelBufferSurface(*offscreen_config, 1u, 1u);
149 if (!offscreen_context->MakeCurrent(*offscreen_surface)) {
150 FML_DLOG(ERROR) << "Could not make offscreen context current.";
151 return;
152 }
153
154 auto impeller_context =
155 CreateImpellerContext(reactor_worker_, enable_gpu_tracing);
156
157 if (!impeller_context) {
158 FML_DLOG(ERROR) << "Could not create Impeller context.";
159 return;
160 }
161
162 if (!offscreen_context->ClearCurrent()) {
163 FML_DLOG(ERROR) << "Could not clear offscreen context.";
164 return;
165 }
166 // Setup context listeners.
168 [worker =
169 reactor_worker_](impeller::egl ::Context::LifecycleEvent event) {
170 switch (event) {
172 worker->SetReactionsAllowedOnCurrentThread(true);
173 break;
175 worker->SetReactionsAllowedOnCurrentThread(false);
176 break;
177 }
178 };
179 if (!onscreen_context->AddLifecycleListener(listener).has_value() ||
180 !offscreen_context->AddLifecycleListener(listener).has_value()) {
181 FML_DLOG(ERROR) << "Could not add lifecycle listeners";
182 }
183
184 onscreen_config_ = std::move(onscreen_config);
185 offscreen_config_ = std::move(offscreen_config);
186 onscreen_context_ = std::move(onscreen_context);
187 offscreen_context_ = std::move(offscreen_context);
188 SetImpellerContext(impeller_context);
189
190 is_valid_ = true;
191}
AndroidContext(AndroidRenderingAPI rendering_api)
void SetImpellerContext(const std::shared_ptr< impeller::Context > &context)
std::function< void(LifecycleEvent)> LifecycleListener
Definition: context.h:75
FlKeyEvent * event
#define FML_DLOG(severity)
Definition: logging.h:102
#define FML_LOG(severity)
Definition: logging.h:82
static std::shared_ptr< impeller::Context > CreateImpellerContext(const std::shared_ptr< impeller::ReactorGLES::Worker > &worker, bool enable_gpu_tracing)
#define ERROR(message)
Definition: elf_loader.cc:260

◆ ~AndroidContextGLImpeller()

flutter::AndroidContextGLImpeller::~AndroidContextGLImpeller ( )
default

Member Function Documentation

◆ CreateOffscreenSurface()

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

Definition at line 217 of file android_context_gl_impeller.cc.

217 {
218 return display_->CreatePixelBufferSurface(*offscreen_config_, 1u, 1u);
219}

◆ CreateOnscreenSurface()

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

Definition at line 239 of file android_context_gl_impeller.cc.

239 {
240 return display_->CreateWindowSurface(*onscreen_config_, window);
241}
GLFWwindow * window
Definition: main.cc:45

◆ IsValid()

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

Reimplemented from flutter::AndroidContext.

Definition at line 195 of file android_context_gl_impeller.cc.

195 {
196 return is_valid_;
197}

◆ OnscreenContextClearCurrent()

bool flutter::AndroidContextGLImpeller::OnscreenContextClearCurrent ( )

Definition at line 230 of file android_context_gl_impeller.cc.

230 {
231 if (!onscreen_context_) {
232 return false;
233 }
234
235 return onscreen_context_->ClearCurrent();
236}

◆ OnscreenContextMakeCurrent()

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

Definition at line 221 of file android_context_gl_impeller.cc.

222 {
223 if (!onscreen_surface || !onscreen_context_) {
224 return false;
225 }
226
227 return onscreen_context_->MakeCurrent(*onscreen_surface);
228}

◆ ResourceContextClearCurrent()

bool flutter::AndroidContextGLImpeller::ResourceContextClearCurrent ( )

Definition at line 199 of file android_context_gl_impeller.cc.

199 {
200 if (!offscreen_context_) {
201 return false;
202 }
203
204 return offscreen_context_->ClearCurrent();
205}

◆ ResourceContextMakeCurrent()

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

Definition at line 207 of file android_context_gl_impeller.cc.

208 {
209 if (!offscreen_context_ || !offscreen_surface) {
210 return false;
211 }
212
213 return offscreen_context_->MakeCurrent(*offscreen_surface);
214}

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