Flutter Engine
 
Loading...
Searching...
No Matches
flutter::AndroidSurfaceGLSkia Class Referencefinal

#include <android_surface_gl_skia.h>

Inheritance diagram for flutter::AndroidSurfaceGLSkia:
flutter::GPUSurfaceGLDelegate flutter::AndroidSurface

Public Member Functions

 AndroidSurfaceGLSkia (const std::shared_ptr< AndroidContextGLSkia > &android_context)
 
 ~AndroidSurfaceGLSkia () override
 
bool IsValid () const override
 
std::unique_ptr< SurfaceCreateGPUSurface (GrDirectContext *gr_context) override
 
void TeardownOnScreenContext () override
 
bool OnScreenSurfaceResize (const DlISize &size) override
 
bool ResourceContextMakeCurrent () override
 
bool ResourceContextClearCurrent () override
 
bool SetNativeWindow (fml::RefPtr< AndroidNativeWindow > window, const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade) override
 
virtual std::unique_ptr< SurfaceCreateSnapshotSurface () override
 
std::unique_ptr< GLContextResultGLContextMakeCurrent () override
 
bool GLContextClearCurrent () override
 
SurfaceFrame::FramebufferInfo GLContextFramebufferInfo () const override
 
void GLContextSetDamageRegion (const std::optional< DlIRect > &region) override
 
bool GLContextPresent (const GLPresentInfo &present_info) override
 
GLFBOInfo GLContextFBO (GLFrameInfo frame_info) const override
 
sk_sp< const GrGLInterface > GetGLInterface () const override
 
AndroidEGLSurfaceGetOnscreenSurface () const
 
- Public Member Functions inherited from flutter::GPUSurfaceGLDelegate
 ~GPUSurfaceGLDelegate ()
 
virtual bool GLContextFBOResetAfterPresent () const
 
virtual DlMatrix GLContextSurfaceTransformation () const
 
virtual GLProcResolver GetGLProcResolver () const
 
virtual bool AllowsDrawingWhenGpuDisabled () const
 
- Public Member Functions inherited from flutter::AndroidSurface
virtual ~AndroidSurface ()
 
virtual std::shared_ptr< impeller::ContextGetImpellerContext ()
 
virtual void SetupImpellerSurface ()
 

Additional Inherited Members

- Public Types inherited from flutter::GPUSurfaceGLDelegate
using GLProcResolver = std::function< void *(const char *)>
 
- Static Public Member Functions inherited from flutter::GPUSurfaceGLDelegate
static sk_sp< const GrGLInterface > GetDefaultPlatformGLInterface ()
 
- Protected Member Functions inherited from flutter::AndroidSurface
 AndroidSurface ()
 

Detailed Description

Definition at line 21 of file android_surface_gl_skia.h.

Constructor & Destructor Documentation

◆ AndroidSurfaceGLSkia()

flutter::AndroidSurfaceGLSkia::AndroidSurfaceGLSkia ( const std::shared_ptr< AndroidContextGLSkia > &  android_context)
explicit

Definition at line 23 of file android_surface_gl_skia.cc.

25 : android_context_(android_context),
26 native_window_(nullptr),
27 onscreen_surface_(nullptr),
28 offscreen_surface_(nullptr) {
29 // Acquire the offscreen surface.
30 offscreen_surface_ = android_context_->CreateOffscreenSurface();
31 if (!offscreen_surface_->IsValid()) {
32 offscreen_surface_ = nullptr;
33 }
34}

◆ ~AndroidSurfaceGLSkia()

flutter::AndroidSurfaceGLSkia::~AndroidSurfaceGLSkia ( )
overridedefault

Member Function Documentation

◆ CreateGPUSurface()

std::unique_ptr< Surface > flutter::AndroidSurfaceGLSkia::CreateGPUSurface ( GrDirectContext *  gr_context)
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 50 of file android_surface_gl_skia.cc.

51 {
52 if (gr_context) {
53 return std::make_unique<GPUSurfaceGLSkia>(sk_ref_sp(gr_context), this,
54 true);
55 } else {
56 sk_sp<GrDirectContext> main_skia_context =
57 android_context_->GetMainSkiaContext();
58 if (!main_skia_context) {
59 main_skia_context = GPUSurfaceGLSkia::MakeGLContext(this);
60 android_context_->SetMainSkiaContext(main_skia_context);
61 }
62 return std::make_unique<GPUSurfaceGLSkia>(main_skia_context, this, true);
63 }
64}
static sk_sp< GrDirectContext > MakeGLContext(GPUSurfaceGLDelegate *delegate)

References flutter::GPUSurfaceGLSkia::MakeGLContext().

◆ CreateSnapshotSurface()

std::unique_ptr< Surface > flutter::AndroidSurfaceGLSkia::CreateSnapshotSurface ( )
overridevirtual

Reimplemented from flutter::AndroidSurface.

Definition at line 207 of file android_surface_gl_skia.cc.

207 {
208 if (!onscreen_surface_ || !onscreen_surface_->IsValid()) {
209 onscreen_surface_ = android_context_->CreatePbufferSurface();
210 }
211 sk_sp<GrDirectContext> main_skia_context =
212 android_context_->GetMainSkiaContext();
213 if (!main_skia_context) {
214 main_skia_context = GPUSurfaceGLSkia::MakeGLContext(this);
215 android_context_->SetMainSkiaContext(main_skia_context);
216 }
217
218 return std::make_unique<GPUSurfaceGLSkia>(main_skia_context, this, true);
219}

References flutter::GPUSurfaceGLSkia::MakeGLContext().

◆ GetGLInterface()

sk_sp< const GrGLInterface > flutter::AndroidSurfaceGLSkia::GetGLInterface ( ) const
overridevirtual

Reimplemented from flutter::GPUSurfaceGLDelegate.

Definition at line 175 of file android_surface_gl_skia.cc.

175 {
176 // This is a workaround for a bug in the Android emulator EGL/GLES
177 // implementation. Some versions of the emulator will not update the
178 // GL version string when the process switches to a new EGL context
179 // unless the EGL context is being made current for the first time.
180 // The inaccurate version string will be rejected by Skia when it
181 // tries to build the GrGLInterface. Flutter can work around this
182 // by creating a new context, making it current to force an update
183 // of the version, and then reverting to the previous context.
184 const char* gl_renderer =
185 reinterpret_cast<const char*>(glGetString(GL_RENDERER));
186 if (gl_renderer && strncmp(gl_renderer, kEmulatorRendererPrefix,
187 strlen(kEmulatorRendererPrefix)) == 0) {
188 EGLContext new_context = android_context_->CreateNewContext();
189 if (new_context != EGL_NO_CONTEXT) {
190 EGLContext old_context = eglGetCurrentContext();
191 EGLDisplay display = eglGetCurrentDisplay();
192 EGLSurface draw_surface = eglGetCurrentSurface(EGL_DRAW);
193 EGLSurface read_surface = eglGetCurrentSurface(EGL_READ);
194 [[maybe_unused]] EGLBoolean result =
195 eglMakeCurrent(display, draw_surface, read_surface, new_context);
196 FML_DCHECK(result == EGL_TRUE);
197 result = eglMakeCurrent(display, draw_surface, read_surface, old_context);
198 FML_DCHECK(result == EGL_TRUE);
199 result = eglDestroyContext(display, new_context);
200 FML_DCHECK(result == EGL_TRUE);
201 }
202 }
203
205}
virtual sk_sp< const GrGLInterface > GetGLInterface() const
#define FML_DCHECK(condition)
Definition logging.h:122

References FML_DCHECK, and flutter::GPUSurfaceGLDelegate::GetGLInterface().

◆ GetOnscreenSurface()

AndroidEGLSurface * flutter::AndroidSurfaceGLSkia::GetOnscreenSurface ( ) const
inline

Definition at line 81 of file android_surface_gl_skia.h.

81 {
82 return onscreen_surface_.get();
83 }

◆ GLContextClearCurrent()

bool flutter::AndroidSurfaceGLSkia::GLContextClearCurrent ( )
overridevirtual

Implements flutter::GPUSurfaceGLDelegate.

Definition at line 128 of file android_surface_gl_skia.cc.

128 {
130 return android_context_->ClearCurrent();
131}

References FML_DCHECK, and IsValid().

◆ GLContextFBO()

GLFBOInfo flutter::AndroidSurfaceGLSkia::GLContextFBO ( GLFrameInfo  frame_info) const
overridevirtual

Implements flutter::GPUSurfaceGLDelegate.

Definition at line 165 of file android_surface_gl_skia.cc.

165 {
167 // The default window bound framebuffer on Android.
168 return GLFBOInfo{
169 .fbo_id = 0,
170 .existing_damage = onscreen_surface_->InitialDamage(),
171 };
172}

References flutter::GLFBOInfo::fbo_id, FML_DCHECK, and IsValid().

◆ GLContextFramebufferInfo()

SurfaceFrame::FramebufferInfo flutter::AndroidSurfaceGLSkia::GLContextFramebufferInfo ( ) const
overridevirtual

Reimplemented from flutter::GPUSurfaceGLDelegate.

Definition at line 133 of file android_surface_gl_skia.cc.

134 {
136 SurfaceFrame::FramebufferInfo res;
137 res.supports_readback = true;
138 res.supports_partial_repaint = onscreen_surface_->SupportsPartialRepaint();
139 res.existing_damage = onscreen_surface_->InitialDamage();
140 // Some devices (Pixel2 XL) needs EGL_KHR_partial_update rect aligned to 4,
141 // otherwise there are glitches
142 // (https://github.com/flutter/flutter/issues/97482#)
143 // Larger alignment might also be beneficial for tile base renderers.
144 res.horizontal_clip_alignment = 32;
145 res.vertical_clip_alignment = 32;
146
147 return res;
148}

References flutter::SurfaceFrame::FramebufferInfo::existing_damage, FML_DCHECK, flutter::SurfaceFrame::FramebufferInfo::horizontal_clip_alignment, IsValid(), flutter::SurfaceFrame::FramebufferInfo::supports_partial_repaint, flutter::SurfaceFrame::FramebufferInfo::supports_readback, and flutter::SurfaceFrame::FramebufferInfo::vertical_clip_alignment.

◆ GLContextMakeCurrent()

std::unique_ptr< GLContextResult > flutter::AndroidSurfaceGLSkia::GLContextMakeCurrent ( )
overridevirtual

Implements flutter::GPUSurfaceGLDelegate.

Definition at line 119 of file android_surface_gl_skia.cc.

119 {
121 FML_DCHECK(onscreen_surface_);
122 auto status = onscreen_surface_->MakeCurrent();
123 auto default_context_result = std::make_unique<GLContextDefaultResult>(
125 return std::move(default_context_result);
126}
@ kFailure
Failed to make the egl context for the surface current.

References FML_DCHECK, IsValid(), and flutter::kFailure.

◆ GLContextPresent()

bool flutter::AndroidSurfaceGLSkia::GLContextPresent ( const GLPresentInfo present_info)
overridevirtual

Implements flutter::GPUSurfaceGLDelegate.

Definition at line 156 of file android_surface_gl_skia.cc.

156 {
158 FML_DCHECK(onscreen_surface_);
159 if (present_info.presentation_time) {
160 onscreen_surface_->SetPresentationTime(*present_info.presentation_time);
161 }
162 return onscreen_surface_->SwapBuffers(present_info.frame_damage);
163}

References FML_DCHECK, flutter::GLPresentInfo::frame_damage, IsValid(), and flutter::GLPresentInfo::presentation_time.

◆ GLContextSetDamageRegion()

void flutter::AndroidSurfaceGLSkia::GLContextSetDamageRegion ( const std::optional< DlIRect > &  region)
overridevirtual

Reimplemented from flutter::GPUSurfaceGLDelegate.

Definition at line 150 of file android_surface_gl_skia.cc.

151 {
153 onscreen_surface_->SetDamageRegion(region);
154}

References FML_DCHECK, and IsValid().

◆ IsValid()

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

◆ OnScreenSurfaceResize()

bool flutter::AndroidSurfaceGLSkia::OnScreenSurfaceResize ( const DlISize size)
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 66 of file android_surface_gl_skia.cc.

66 {
68 FML_DCHECK(onscreen_surface_);
69 FML_DCHECK(native_window_);
70
71 if (size == onscreen_surface_->GetSize()) {
72 return true;
73 }
74
75 android_context_->ClearCurrent();
76
77 // Ensure the destructor is called since it destroys the `EGLSurface` before
78 // creating a new onscreen surface.
79 onscreen_surface_ = nullptr;
80 onscreen_surface_ = android_context_->CreateOnscreenSurface(native_window_);
81 if (!onscreen_surface_->IsValid()) {
82 FML_LOG(ERROR) << "Unable to create EGL window surface on resize.";
83 return false;
84 }
85 onscreen_surface_->MakeCurrent();
86 return true;
87}
#define FML_LOG(severity)
Definition logging.h:101
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size

References FML_DCHECK, FML_LOG, IsValid(), and flutter::size.

◆ ResourceContextClearCurrent()

bool flutter::AndroidSurfaceGLSkia::ResourceContextClearCurrent ( )
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 95 of file android_surface_gl_skia.cc.

95 {
97 EGLBoolean result = eglMakeCurrent(eglGetCurrentDisplay(), EGL_NO_SURFACE,
98 EGL_NO_SURFACE, EGL_NO_CONTEXT);
99 return result == EGL_TRUE;
100}

References FML_DCHECK, and IsValid().

◆ ResourceContextMakeCurrent()

bool flutter::AndroidSurfaceGLSkia::ResourceContextMakeCurrent ( )
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 89 of file android_surface_gl_skia.cc.

89 {
91 auto status = offscreen_surface_->MakeCurrent();
93}

References FML_DCHECK, IsValid(), and flutter::kFailure.

◆ SetNativeWindow()

bool flutter::AndroidSurfaceGLSkia::SetNativeWindow ( fml::RefPtr< AndroidNativeWindow window,
const std::shared_ptr< PlatformViewAndroidJNI > &  jni_facade 
)
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 102 of file android_surface_gl_skia.cc.

104 {
107 native_window_ = window;
108 // Ensure the destructor is called since it destroys the `EGLSurface` before
109 // creating a new onscreen surface.
110 onscreen_surface_ = nullptr;
111 // Create the onscreen surface.
112 onscreen_surface_ = android_context_->CreateOnscreenSurface(window);
113 if (!onscreen_surface_->IsValid()) {
114 return false;
115 }
116 return true;
117}
GLFWwindow * window
Definition main.cc:60

References FML_DCHECK, IsValid(), and window.

◆ TeardownOnScreenContext()

void flutter::AndroidSurfaceGLSkia::TeardownOnScreenContext ( )
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 38 of file android_surface_gl_skia.cc.

38 {
39 // When the onscreen surface is destroyed, the context and the surface
40 // instance should be deleted. Issue:
41 // https://github.com/flutter/flutter/issues/64414
42 android_context_->ClearCurrent();
43 onscreen_surface_ = nullptr;
44}

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