Flutter Engine
flutter::AndroidSurfaceGL Class Referencefinal

#include <android_surface_gl.h>

Inheritance diagram for flutter::AndroidSurfaceGL:
flutter::GPUSurfaceGLDelegate flutter::AndroidSurface

Public Member Functions

 AndroidSurfaceGL (const std::shared_ptr< AndroidContext > &android_context, std::shared_ptr< PlatformViewAndroidJNI > jni_facade)
 
 ~AndroidSurfaceGL () override
 
bool IsValid () const override
 
std::unique_ptr< SurfaceCreateGPUSurface (GrDirectContext *gr_context) override
 
void TeardownOnScreenContext () override
 
bool OnScreenSurfaceResize (const SkISize &size) override
 
bool ResourceContextMakeCurrent () override
 
bool ResourceContextClearCurrent () override
 
bool SetNativeWindow (fml::RefPtr< AndroidNativeWindow > window) override
 
virtual std::unique_ptr< SurfaceCreatePbufferSurface () override
 
std::unique_ptr< GLContextResultGLContextMakeCurrent () override
 
bool GLContextClearCurrent () override
 
bool GLContextPresent (uint32_t fbo_id) override
 
intptr_t GLContextFBO (GLFrameInfo frame_info) const override
 
sk_sp< const GrGLInterface > GetGLInterface () const override
 
- Public Member Functions inherited from flutter::GPUSurfaceGLDelegate
 ~GPUSurfaceGLDelegate ()
 
virtual bool GLContextFBOResetAfterPresent () const
 
virtual bool SurfaceSupportsReadback () const
 
virtual SkMatrix GLContextSurfaceTransformation () const
 
virtual GLProcResolver GetGLProcResolver () const
 
virtual bool AllowsDrawingWhenGpuDisabled () const
 
- Public Member Functions inherited from flutter::AndroidSurface
virtual ~AndroidSurface ()
 

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 (const std::shared_ptr< AndroidContext > &android_context)
 
- Protected Attributes inherited from flutter::AndroidSurface
std::shared_ptr< AndroidContextandroid_context_
 

Detailed Description

Definition at line 21 of file android_surface_gl.h.

Constructor & Destructor Documentation

◆ AndroidSurfaceGL()

flutter::AndroidSurfaceGL::AndroidSurfaceGL ( const std::shared_ptr< AndroidContext > &  android_context,
std::shared_ptr< PlatformViewAndroidJNI jni_facade 
)

Definition at line 22 of file android_surface_gl.cc.

References flutter::AndroidContextGL::CreateOffscreenSurface(), and ~AndroidSurfaceGL().

25  : AndroidSurface(android_context),
26  native_window_(nullptr),
27  onscreen_surface_(nullptr),
28  offscreen_surface_(nullptr) {
29  // Acquire the offscreen surface.
30  offscreen_surface_ = GLContextPtr()->CreateOffscreenSurface();
31  if (!offscreen_surface_->IsValid()) {
32  offscreen_surface_ = nullptr;
33  }
34 }
AndroidSurface(const std::shared_ptr< AndroidContext > &android_context)
std::unique_ptr< AndroidEGLSurface > CreateOffscreenSurface() const
Allocates an 1x1 pbuffer surface that is used for making the offscreen current for texture uploads...

◆ ~AndroidSurfaceGL()

flutter::AndroidSurfaceGL::~AndroidSurfaceGL ( )
overridedefault

Referenced by AndroidSurfaceGL().

Member Function Documentation

◆ CreateGPUSurface()

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

Implements flutter::AndroidSurface.

Definition at line 50 of file android_surface_gl.cc.

51  {
52  if (gr_context) {
53  return std::make_unique<GPUSurfaceGL>(sk_ref_sp(gr_context), this, true);
54  } else {
55  return std::make_unique<GPUSurfaceGL>(this, true);
56  }
57 }

◆ CreatePbufferSurface()

std::unique_ptr< Surface > flutter::AndroidSurfaceGL::CreatePbufferSurface ( )
overridevirtual

Reimplemented from flutter::AndroidSurface.

Definition at line 172 of file android_surface_gl.cc.

References flutter::AndroidContextGL::CreatePbufferSurface().

172  {
173  onscreen_surface_ = GLContextPtr()->CreatePbufferSurface();
174  return std::make_unique<GPUSurfaceGL>(this, true);
175 }
std::unique_ptr< AndroidEGLSurface > CreatePbufferSurface() const
Allocates an 1x1 pbuffer surface that is used for making the onscreen context current for snapshottin...

◆ GetGLInterface()

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

Reimplemented from flutter::GPUSurfaceGLDelegate.

Definition at line 136 of file android_surface_gl.cc.

References flutter::AndroidSurface::android_context_, flutter::AndroidContextGL::CreateNewContext(), FML_DCHECK, flutter::GPUSurfaceGLDelegate::GetGLInterface(), and result.

136  {
137  // This is a workaround for a bug in the Android emulator EGL/GLES
138  // implementation. Some versions of the emulator will not update the
139  // GL version string when the process switches to a new EGL context
140  // unless the EGL context is being made current for the first time.
141  // The inaccurate version string will be rejected by Skia when it
142  // tries to build the GrGLInterface. Flutter can work around this
143  // by creating a new context, making it current to force an update
144  // of the version, and then reverting to the previous context.
145  const char* gl_renderer =
146  reinterpret_cast<const char*>(glGetString(GL_RENDERER));
147  if (gl_renderer && strncmp(gl_renderer, kEmulatorRendererPrefix,
148  strlen(kEmulatorRendererPrefix)) == 0) {
149  EGLContext new_context = GLContextPtr()->CreateNewContext();
150  if (new_context != EGL_NO_CONTEXT) {
151  EGLContext old_context = eglGetCurrentContext();
152  EGLDisplay display = eglGetCurrentDisplay();
153  EGLSurface draw_surface = eglGetCurrentSurface(EGL_DRAW);
154  EGLSurface read_surface = eglGetCurrentSurface(EGL_READ);
155  EGLBoolean result =
156  eglMakeCurrent(display, draw_surface, read_surface, new_context);
157  FML_DCHECK(result == EGL_TRUE);
158  result = eglMakeCurrent(display, draw_surface, read_surface, old_context);
159  FML_DCHECK(result == EGL_TRUE);
160  result = eglDestroyContext(display, new_context);
161  FML_DCHECK(result == EGL_TRUE);
162  }
163  }
164 
166 }
#define FML_DCHECK(condition)
Definition: logging.h:86
GAsyncResult * result
EGLContext CreateNewContext() const
Create a new EGLContext using the same EGLConfig.
virtual sk_sp< const GrGLInterface > GetGLInterface() const

◆ GLContextClearCurrent()

bool flutter::AndroidSurfaceGL::GLContextClearCurrent ( )
overridevirtual

Implements flutter::GPUSurfaceGLDelegate.

Definition at line 118 of file android_surface_gl.cc.

References flutter::AndroidContextGL::ClearCurrent(), FML_DCHECK, and IsValid().

118  {
119  FML_DCHECK(IsValid());
120  return GLContextPtr()->ClearCurrent();
121 }
#define FML_DCHECK(condition)
Definition: logging.h:86
bool IsValid() const override

◆ GLContextFBO()

intptr_t flutter::AndroidSurfaceGL::GLContextFBO ( GLFrameInfo  frame_info) const
overridevirtual

Implements flutter::GPUSurfaceGLDelegate.

Definition at line 129 of file android_surface_gl.cc.

References FML_DCHECK, and IsValid().

129  {
130  FML_DCHECK(IsValid());
131  // The default window bound framebuffer on Android.
132  return 0;
133 }
#define FML_DCHECK(condition)
Definition: logging.h:86
bool IsValid() const override

◆ GLContextMakeCurrent()

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

Implements flutter::GPUSurfaceGLDelegate.

Definition at line 110 of file android_surface_gl.cc.

References FML_DCHECK, and IsValid().

110  {
111  FML_DCHECK(IsValid());
112  FML_DCHECK(onscreen_surface_);
113  auto default_context_result = std::make_unique<GLContextDefaultResult>(
114  onscreen_surface_->MakeCurrent());
115  return std::move(default_context_result);
116 }
#define FML_DCHECK(condition)
Definition: logging.h:86
bool IsValid() const override

◆ GLContextPresent()

bool flutter::AndroidSurfaceGL::GLContextPresent ( uint32_t  fbo_id)
overridevirtual

Implements flutter::GPUSurfaceGLDelegate.

Definition at line 123 of file android_surface_gl.cc.

References FML_DCHECK, and IsValid().

123  {
124  FML_DCHECK(IsValid());
125  FML_DCHECK(onscreen_surface_);
126  return onscreen_surface_->SwapBuffers();
127 }
#define FML_DCHECK(condition)
Definition: logging.h:86
bool IsValid() const override

◆ IsValid()

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

◆ OnScreenSurfaceResize()

bool flutter::AndroidSurfaceGL::OnScreenSurfaceResize ( const SkISize &  size)
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 59 of file android_surface_gl.cc.

References flutter::AndroidContextGL::ClearCurrent(), flutter::AndroidContextGL::CreateOnscreenSurface(), FML_DCHECK, FML_LOG, and IsValid().

59  {
61  FML_DCHECK(onscreen_surface_);
62  FML_DCHECK(native_window_);
63 
64  if (size == onscreen_surface_->GetSize()) {
65  return true;
66  }
67 
68  GLContextPtr()->ClearCurrent();
69 
70  // Ensure the destructor is called since it destroys the `EGLSurface` before
71  // creating a new onscreen surface.
72  onscreen_surface_ = nullptr;
73  onscreen_surface_ = GLContextPtr()->CreateOnscreenSurface(native_window_);
74  if (!onscreen_surface_->IsValid()) {
75  FML_LOG(ERROR) << "Unable to create EGL window surface on resize.";
76  return false;
77  }
78  onscreen_surface_->MakeCurrent();
79  return true;
80 }
#define FML_DCHECK(condition)
Definition: logging.h:86
bool IsValid() const override
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
#define FML_LOG(severity)
Definition: logging.h:65
std::unique_ptr< AndroidEGLSurface > CreateOnscreenSurface(fml::RefPtr< AndroidNativeWindow > window) const
Allocates an new EGL window surface that is used for on-screen pixels.

◆ ResourceContextClearCurrent()

bool flutter::AndroidSurfaceGL::ResourceContextClearCurrent ( )
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 87 of file android_surface_gl.cc.

References FML_DCHECK, IsValid(), and result.

87  {
89  EGLBoolean result = eglMakeCurrent(eglGetCurrentDisplay(), EGL_NO_SURFACE,
90  EGL_NO_SURFACE, EGL_NO_CONTEXT);
91  return result == EGL_TRUE;
92 }
#define FML_DCHECK(condition)
Definition: logging.h:86
bool IsValid() const override
GAsyncResult * result

◆ ResourceContextMakeCurrent()

bool flutter::AndroidSurfaceGL::ResourceContextMakeCurrent ( )
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 82 of file android_surface_gl.cc.

References FML_DCHECK, and IsValid().

82  {
84  return offscreen_surface_->MakeCurrent();
85 }
#define FML_DCHECK(condition)
Definition: logging.h:86
bool IsValid() const override

◆ SetNativeWindow()

bool flutter::AndroidSurfaceGL::SetNativeWindow ( fml::RefPtr< AndroidNativeWindow window)
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 94 of file android_surface_gl.cc.

References flutter::AndroidContextGL::CreateOnscreenSurface(), FML_DCHECK, and IsValid().

95  {
97  FML_DCHECK(window);
98  native_window_ = window;
99  // Ensure the destructor is called since it destroys the `EGLSurface` before
100  // creating a new onscreen surface.
101  onscreen_surface_ = nullptr;
102  // Create the onscreen surface.
103  onscreen_surface_ = GLContextPtr()->CreateOnscreenSurface(window);
104  if (!onscreen_surface_->IsValid()) {
105  return false;
106  }
107  return true;
108 }
#define FML_DCHECK(condition)
Definition: logging.h:86
bool IsValid() const override
std::unique_ptr< AndroidEGLSurface > CreateOnscreenSurface(fml::RefPtr< AndroidNativeWindow > window) const
Allocates an new EGL window surface that is used for on-screen pixels.

◆ TeardownOnScreenContext()

void flutter::AndroidSurfaceGL::TeardownOnScreenContext ( )
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 38 of file android_surface_gl.cc.

References flutter::AndroidContextGL::ClearCurrent().

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  GLContextPtr()->ClearCurrent();
43  onscreen_surface_ = nullptr;
44 }

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