Flutter Engine
flutter::AndroidSurfaceGL Class Referencefinal

#include <android_surface_gl.h>

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

Public Member Functions

 AndroidSurfaceGL (std::shared_ptr< AndroidContext > android_context, std::shared_ptr< PlatformViewAndroidJNI > jni_facade, std::shared_ptr< AndroidExternalViewEmbedder > external_view_embedder)
 
 ~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
 
std::unique_ptr< GLContextResultGLContextMakeCurrent () override
 
bool GLContextClearCurrent () override
 
bool GLContextPresent (uint32_t fbo_id) override
 
intptr_t GLContextFBO (GLFrameInfo frame_info) const override
 
ExternalViewEmbedderGetExternalViewEmbedder () override
 Gets the view embedder that controls how the Flutter layer hierarchy split into multiple chunks should be composited back on-screen. This field is optional and the Flutter rasterizer will render into a single on-screen surface if this call returns a null external view embedder. This happens on the GPU thread. More...
 
sk_sp< const GrGLInterface > GetGLInterface () const override
 
- Public Member Functions inherited from flutter::GPUSurfaceGLDelegate
 ~GPUSurfaceGLDelegate () override
 
virtual bool GLContextFBOResetAfterPresent () const
 
virtual bool SurfaceSupportsReadback () const
 
virtual SkMatrix GLContextSurfaceTransformation () const
 
virtual GLProcResolver GetGLProcResolver () const
 
- Public Member Functions inherited from flutter::GPUSurfaceDelegate
virtual ~GPUSurfaceDelegate ()
 
- 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 ()
 

Detailed Description

Definition at line 22 of file android_surface_gl.h.

Constructor & Destructor Documentation

◆ AndroidSurfaceGL()

flutter::AndroidSurfaceGL::AndroidSurfaceGL ( std::shared_ptr< AndroidContext android_context,
std::shared_ptr< PlatformViewAndroidJNI jni_facade,
std::shared_ptr< AndroidExternalViewEmbedder external_view_embedder 
)

Definition at line 22 of file android_surface_gl.cc.

References ~AndroidSurfaceGL().

26  : external_view_embedder_(external_view_embedder),
27  android_context_(
28  std::static_pointer_cast<AndroidContextGL>(android_context)),
29  native_window_(nullptr),
30  onscreen_surface_(nullptr),
31  offscreen_surface_(nullptr) {
32  // Acquire the offscreen surface.
33  offscreen_surface_ = android_context_->CreateOffscreenSurface();
34  if (!offscreen_surface_->IsValid()) {
35  offscreen_surface_ = nullptr;
36  }
37 }

◆ ~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 53 of file android_surface_gl.cc.

54  {
55  if (gr_context) {
56  return std::make_unique<GPUSurfaceGL>(sk_ref_sp(gr_context), this, true);
57  }
58  return std::make_unique<GPUSurfaceGL>(this, true);
59 }

◆ GetExternalViewEmbedder()

ExternalViewEmbedder * flutter::AndroidSurfaceGL::GetExternalViewEmbedder ( )
overridevirtual

Gets the view embedder that controls how the Flutter layer hierarchy split into multiple chunks should be composited back on-screen. This field is optional and the Flutter rasterizer will render into a single on-screen surface if this call returns a null external view embedder. This happens on the GPU thread.

Returns
The external view embedder, or, null if Flutter is rendering into a single on-screen surface.

Reimplemented from flutter::GPUSurfaceGLDelegate.

Definition at line 136 of file android_surface_gl.cc.

136  {
137  return external_view_embedder_.get();
138 }

◆ GetGLInterface()

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

Reimplemented from flutter::GPUSurfaceGLDelegate.

Definition at line 141 of file android_surface_gl.cc.

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

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

118  {
119  FML_DCHECK(IsValid());
120  return android_context_->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

Implements flutter::AndroidSurface.

Definition at line 49 of file android_surface_gl.cc.

Referenced by GLContextClearCurrent(), GLContextFBO(), GLContextMakeCurrent(), GLContextPresent(), OnScreenSurfaceResize(), ResourceContextClearCurrent(), ResourceContextMakeCurrent(), and SetNativeWindow().

49  {
50  return offscreen_surface_ && android_context_->IsValid();
51 }

◆ OnScreenSurfaceResize()

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

Implements flutter::AndroidSurface.

Definition at line 61 of file android_surface_gl.cc.

References FML_DCHECK, FML_LOG, and IsValid().

61  {
63  FML_DCHECK(onscreen_surface_);
64  FML_DCHECK(native_window_);
65 
66  if (size == onscreen_surface_->GetSize()) {
67  return true;
68  }
69 
70  android_context_->ClearCurrent();
71 
72  // Ensure the destructor is called since it destroys the `EGLSurface` before
73  // creating a new onscreen surface.
74  onscreen_surface_ = nullptr;
75  onscreen_surface_ = android_context_->CreateOnscreenSurface(native_window_);
76  if (!onscreen_surface_->IsValid()) {
77  FML_LOG(ERROR) << "Unable to create EGL window surface on resize.";
78  return false;
79  }
80  onscreen_surface_->MakeCurrent();
81  return true;
82 }
#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

◆ ResourceContextClearCurrent()

bool flutter::AndroidSurfaceGL::ResourceContextClearCurrent ( )
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 89 of file android_surface_gl.cc.

References FML_DCHECK, and IsValid().

89  {
91  return android_context_->ClearCurrent();
92 }
#define FML_DCHECK(condition)
Definition: logging.h:86
bool IsValid() const override

◆ ResourceContextMakeCurrent()

bool flutter::AndroidSurfaceGL::ResourceContextMakeCurrent ( )
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 84 of file android_surface_gl.cc.

References FML_DCHECK, and IsValid().

84  {
86  return offscreen_surface_->MakeCurrent();
87 }
#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 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_ = android_context_->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

◆ TeardownOnScreenContext()

void flutter::AndroidSurfaceGL::TeardownOnScreenContext ( )
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 41 of file android_surface_gl.cc.

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

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