Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
flutter::AndroidContextGLSkia Class Reference

#include <android_context_gl_skia.h>

Inheritance diagram for flutter::AndroidContextGLSkia:
flutter::AndroidContext

Public Member Functions

 AndroidContextGLSkia (fml::RefPtr< AndroidEnvironmentGL > environment, const TaskRunners &taskRunners, uint8_t msaa_samples)
 
 ~AndroidContextGLSkia ()
 
std::unique_ptr< AndroidEGLSurfaceCreateOnscreenSurface (const fml::RefPtr< AndroidNativeWindow > &window) const
 Allocates an new EGL window surface that is used for on-screen pixels.
 
std::unique_ptr< AndroidEGLSurfaceCreateOffscreenSurface () const
 Allocates an 1x1 pbuffer surface that is used for making the offscreen current for texture uploads.
 
std::unique_ptr< AndroidEGLSurfaceCreatePbufferSurface () const
 Allocates an 1x1 pbuffer surface that is used for making the onscreen context current for snapshotting.
 
fml::RefPtr< AndroidEnvironmentGLEnvironment () const
 
bool IsValid () const override
 
bool ClearCurrent () const
 
EGLContext GetEGLContext () const
 Returns the EGLContext.
 
EGLDisplay GetEGLDisplay () const
 Returns the EGLDisplay.
 
EGLContext CreateNewContext () const
 Create a new EGLContext using the same EGLConfig.
 
EGLConfig Config () const
 The EGLConfig for this context.
 
- Public Member Functions inherited from flutter::AndroidContext
 AndroidContext (AndroidRenderingAPI rendering_api)
 
virtual ~AndroidContext ()
 
AndroidRenderingAPI RenderingApi () const
 
void SetMainSkiaContext (const sk_sp< GrDirectContext > &main_context)
 Setter for the Skia context to be used by subsequent AndroidSurfaces.
 
sk_sp< GrDirectContextGetMainSkiaContext () const
 Accessor for the Skia context associated with AndroidSurfaces and the raster thread.
 
std::shared_ptr< impeller::ContextGetImpellerContext () const
 Accessor for the Impeller context associated with AndroidSurfaces and the raster thread.
 

Additional Inherited Members

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

Detailed Description

The Android context is used by AndroidSurfaceGL to create and manage EGL surfaces.

This context binds EGLContext to the current rendering thread and to the draw and read EGLSurfaces.

Definition at line 28 of file android_context_gl_skia.h.

Constructor & Destructor Documentation

◆ AndroidContextGLSkia()

flutter::AndroidContextGLSkia::AndroidContextGLSkia ( fml::RefPtr< AndroidEnvironmentGL environment,
const TaskRunners taskRunners,
uint8_t  msaa_samples 
)

Definition at line 67 of file android_context_gl_skia.cc.

72 environment_(std::move(environment)),
73 task_runners_(task_runners) {
74 if (!environment_->IsValid()) {
75 FML_LOG(ERROR) << "Could not create an Android GL environment.";
76 return;
77 }
78
79 bool success = false;
80
81 // Choose a valid configuration.
82 std::tie(success, config_) =
83 ChooseEGLConfiguration(environment_->Display(), msaa_samples);
84 if (!success) {
85 FML_LOG(ERROR) << "Could not choose an EGL configuration.";
87 return;
88 }
89
90 // Create a context for the configuration.
91 std::tie(success, context_) =
92 CreateContext(environment_->Display(), config_, EGL_NO_CONTEXT);
93 if (!success) {
94 FML_LOG(ERROR) << "Could not create an EGL context";
96 return;
97 }
98
99 std::tie(success, resource_context_) =
100 CreateContext(environment_->Display(), config_, context_);
101 if (!success) {
102 FML_LOG(ERROR) << "Could not create an EGL resource context";
104 return;
105 }
106
107 // All done!
108 valid_ = true;
109}
AndroidContext(AndroidRenderingAPI rendering_api)
#define FML_LOG(severity)
Definition logging.h:82
void LogLastEGLError()
static EGLResult< EGLConfig > ChooseEGLConfiguration(EGLDisplay display, uint8_t msaa_samples)
static EGLResult< EGLContext > CreateContext(EGLDisplay display, EGLConfig config, EGLContext share=EGL_NO_CONTEXT)
#define ERROR(message)

◆ ~AndroidContextGLSkia()

flutter::AndroidContextGLSkia::~AndroidContextGLSkia ( )

Definition at line 111 of file android_context_gl_skia.cc.

111 {
114 SetMainSkiaContext(nullptr);
116 // This context needs to be deallocated from the raster thread in order to
117 // keep a coherent usage of egl from a single thread.
119 if (main_context) {
120 std::unique_ptr<AndroidEGLSurface> pbuffer_surface =
121 CreatePbufferSurface();
122 auto status = pbuffer_surface->MakeCurrent();
123 if (status != AndroidEGLSurfaceMakeCurrentStatus::kFailure) {
124 main_context->releaseResourcesAndAbandonContext();
125 main_context.reset();
126 ClearCurrent();
127 }
128 }
129 latch.Signal();
130 });
131 latch.Wait();
132
133 if (!TeardownContext(environment_->Display(), context_)) {
135 << "Could not tear down the EGL context. Possible resource leak.";
137 }
138
139 if (!TeardownContext(environment_->Display(), resource_context_)) {
140 FML_LOG(ERROR) << "Could not tear down the EGL resource context. Possible "
141 "resource leak.";
143 }
144}
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.
fml::RefPtr< fml::TaskRunner > GetRasterTaskRunner() const
fml::RefPtr< fml::TaskRunner > GetPlatformTaskRunner() const
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
virtual bool RunsTasksOnCurrentThread()
#define FML_DCHECK(condition)
Definition logging.h:103
static bool TeardownContext(EGLDisplay display, EGLContext context)

Member Function Documentation

◆ ClearCurrent()

bool flutter::AndroidContextGLSkia::ClearCurrent ( ) const
Returns
Whether the current context was successfully clear.

Definition at line 193 of file android_context_gl_skia.cc.

193 {
194 if (eglGetCurrentContext() != context_) {
195 return true;
196 }
197 if (eglMakeCurrent(environment_->Display(), EGL_NO_SURFACE, EGL_NO_SURFACE,
198 EGL_NO_CONTEXT) != EGL_TRUE) {
199 FML_LOG(ERROR) << "Could not clear the current context";
201 return false;
202 }
203 return true;
204}

◆ Config()

EGLConfig flutter::AndroidContextGLSkia::Config ( ) const
inline

The EGLConfig for this context.

Definition at line 102 of file android_context_gl_skia.h.

102{ return config_; }

◆ CreateNewContext()

EGLContext flutter::AndroidContextGLSkia::CreateNewContext ( ) const

Create a new EGLContext using the same EGLConfig.

Returns
The EGLContext.

Definition at line 214 of file android_context_gl_skia.cc.

214 {
215 bool success;
216 EGLContext context;
217 std::tie(success, context) =
218 CreateContext(environment_->Display(), config_, EGL_NO_CONTEXT);
219 return success ? context : EGL_NO_CONTEXT;
220}

◆ CreateOffscreenSurface()

std::unique_ptr< AndroidEGLSurface > flutter::AndroidContextGLSkia::CreateOffscreenSurface ( ) const

Allocates an 1x1 pbuffer surface that is used for making the offscreen current for texture uploads.

Returns
The pbuffer surface.

Definition at line 163 of file android_context_gl_skia.cc.

163 {
164 // We only ever create pbuffer surfaces for background resource loading
165 // contexts. We never bind the pbuffer to anything.
166 EGLDisplay display = environment_->Display();
167
168 const EGLint attribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
169
170 EGLSurface surface = eglCreatePbufferSurface(display, config_, attribs);
171 return std::make_unique<AndroidEGLSurface>(surface, display,
172 resource_context_);
173}
VkSurfaceKHR surface
Definition main.cc:49

◆ CreateOnscreenSurface()

std::unique_ptr< AndroidEGLSurface > flutter::AndroidContextGLSkia::CreateOnscreenSurface ( const fml::RefPtr< AndroidNativeWindow > &  window) const

Allocates an new EGL window surface that is used for on-screen pixels.

Returns
The window surface.

Definition at line 146 of file android_context_gl_skia.cc.

147 {
148 if (window->IsFakeWindow()) {
149 return CreatePbufferSurface();
150 } else {
151 EGLDisplay display = environment_->Display();
152
153 const EGLint attribs[] = {EGL_NONE};
154
155 EGLSurface surface = eglCreateWindowSurface(
156 display, config_,
157 reinterpret_cast<EGLNativeWindowType>(window->handle()), attribs);
158 return std::make_unique<AndroidEGLSurface>(surface, display, context_);
159 }
160}
std::unique_ptr< AndroidEGLSurface > CreatePbufferSurface() const
Allocates an 1x1 pbuffer surface that is used for making the onscreen context current for snapshottin...
GLFWwindow * window
Definition main.cc:45

◆ CreatePbufferSurface()

std::unique_ptr< AndroidEGLSurface > flutter::AndroidContextGLSkia::CreatePbufferSurface ( ) const

Allocates an 1x1 pbuffer surface that is used for making the onscreen context current for snapshotting.

Returns
The pbuffer surface.

Definition at line 175 of file android_context_gl_skia.cc.

176 {
177 EGLDisplay display = environment_->Display();
178
179 const EGLint attribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
180
181 EGLSurface surface = eglCreatePbufferSurface(display, config_, attribs);
182 return std::make_unique<AndroidEGLSurface>(surface, display, context_);
183}

◆ Environment()

fml::RefPtr< AndroidEnvironmentGL > flutter::AndroidContextGLSkia::Environment ( ) const
Returns
The Android environment that contains a reference to the display.

Definition at line 185 of file android_context_gl_skia.cc.

185 {
186 return environment_;
187}

◆ GetEGLContext()

EGLContext flutter::AndroidContextGLSkia::GetEGLContext ( ) const

Returns the EGLContext.

Returns
EGLContext.

Definition at line 206 of file android_context_gl_skia.cc.

206 {
207 return context_;
208}

◆ GetEGLDisplay()

EGLDisplay flutter::AndroidContextGLSkia::GetEGLDisplay ( ) const

Returns the EGLDisplay.

Returns
EGLDisplay.

Definition at line 210 of file android_context_gl_skia.cc.

210 {
211 return environment_->Display();
212}

◆ IsValid()

bool flutter::AndroidContextGLSkia::IsValid ( ) const
overridevirtual
Returns
Whether the current context is valid. That is, if the EGL contexts were successfully created.

Reimplemented from flutter::AndroidContext.

Definition at line 189 of file android_context_gl_skia.cc.

189 {
190 return valid_;
191}

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