Flutter Engine
flutter::GPUSurfaceGL Class Reference

#include <gpu_surface_gl.h>

Inheritance diagram for flutter::GPUSurfaceGL:
flutter::Surface

Public Member Functions

 GPUSurfaceGL (GPUSurfaceGLDelegate *delegate, bool render_to_surface)
 
 GPUSurfaceGL (sk_sp< GrDirectContext > gr_context, GPUSurfaceGLDelegate *delegate, bool render_to_surface)
 
 ~GPUSurfaceGL () override
 
bool IsValid () override
 
std::unique_ptr< SurfaceFrameAcquireFrame (const SkISize &size) override
 
SkMatrix GetRootTransformation () const override
 
GrDirectContext * GetContext () override
 
std::unique_ptr< GLContextResultMakeRenderContextCurrent () override
 
bool ClearRenderContext () override
 
bool AllowsDrawingWhenGpuDisabled () const override
 
- Public Member Functions inherited from flutter::Surface
 Surface ()
 
virtual ~Surface ()
 

Static Public Member Functions

static sk_sp< GrDirectContext > MakeGLContext (GPUSurfaceGLDelegate *delegate)
 

Detailed Description

Definition at line 21 of file gpu_surface_gl.h.

Constructor & Destructor Documentation

◆ GPUSurfaceGL() [1/2]

flutter::GPUSurfaceGL::GPUSurfaceGL ( GPUSurfaceGLDelegate delegate,
bool  render_to_surface 
)

Definition at line 64 of file gpu_surface_gl.cc.

66  : GPUSurfaceGL(MakeGLContext(delegate), delegate, render_to_surface) {
67  context_owner_ = true;
68 }
static sk_sp< GrDirectContext > MakeGLContext(GPUSurfaceGLDelegate *delegate)
GPUSurfaceGL(GPUSurfaceGLDelegate *delegate, bool render_to_surface)

◆ GPUSurfaceGL() [2/2]

flutter::GPUSurfaceGL::GPUSurfaceGL ( sk_sp< GrDirectContext >  gr_context,
GPUSurfaceGLDelegate delegate,
bool  render_to_surface 
)

Definition at line 70 of file gpu_surface_gl.cc.

References FML_LOG, flutter::GPUSurfaceGLDelegate::GLContextClearCurrent(), and flutter::GPUSurfaceGLDelegate::GLContextMakeCurrent().

73  : delegate_(delegate),
74  context_(gr_context),
75  context_owner_(false),
76  render_to_surface_(render_to_surface),
77  weak_factory_(this) {
78  auto context_switch = delegate_->GLContextMakeCurrent();
79  if (!context_switch->GetResult()) {
80  FML_LOG(ERROR)
81  << "Could not make the context current to set up the Gr context.";
82  return;
83  }
84 
85  delegate_->GLContextClearCurrent();
86 
87  valid_ = gr_context != nullptr;
88 }
MockDelegate delegate_
#define FML_LOG(severity)
Definition: logging.h:65

◆ ~GPUSurfaceGL()

flutter::GPUSurfaceGL::~GPUSurfaceGL ( )
override

Definition at line 90 of file gpu_surface_gl.cc.

References FML_LOG, flutter::GPUSurfaceGLDelegate::GLContextClearCurrent(), and flutter::GPUSurfaceGLDelegate::GLContextMakeCurrent().

90  {
91  if (!valid_) {
92  return;
93  }
94  auto context_switch = delegate_->GLContextMakeCurrent();
95  if (!context_switch->GetResult()) {
96  FML_LOG(ERROR) << "Could not make the context current to destroy the "
97  "GrDirectContext resources.";
98  return;
99  }
100 
101  onscreen_surface_ = nullptr;
102  fbo_id_ = 0;
103  if (context_owner_) {
104  context_->releaseResourcesAndAbandonContext();
105  }
106  context_ = nullptr;
107 
108  delegate_->GLContextClearCurrent();
109 }
MockDelegate delegate_
#define FML_LOG(severity)
Definition: logging.h:65

Member Function Documentation

◆ AcquireFrame()

std::unique_ptr< SurfaceFrame > flutter::GPUSurfaceGL::AcquireFrame ( const SkISize &  size)
overridevirtual

Implements flutter::Surface.

Definition at line 208 of file gpu_surface_gl.cc.

References FML_LOG, GetRootTransformation(), flutter::GPUSurfaceGLDelegate::GLContextFBO(), flutter::GPUSurfaceGLDelegate::GLContextFBOResetAfterPresent(), flutter::GPUSurfaceGLDelegate::GLContextMakeCurrent(), flutter::GPUSurfaceGLDelegate::GLContextPresent(), flutter::GPUSurfaceGLDelegate::SurfaceSupportsReadback(), TRACE_EVENT0, and flutter::WrapOnscreenSurface().

208  {
209  if (delegate_ == nullptr) {
210  return nullptr;
211  }
212  auto context_switch = delegate_->GLContextMakeCurrent();
213  if (!context_switch->GetResult()) {
214  FML_LOG(ERROR)
215  << "Could not make the context current to acquire the frame.";
216  return nullptr;
217  }
218 
219  // TODO(38466): Refactor GPU surface APIs take into account the fact that an
220  // external view embedder may want to render to the root surface.
221  if (!render_to_surface_) {
222  return std::make_unique<SurfaceFrame>(
223  nullptr, true, [](const SurfaceFrame& surface_frame, SkCanvas* canvas) {
224  return true;
225  });
226  }
227 
228  const auto root_surface_transformation = GetRootTransformation();
229 
230  sk_sp<SkSurface> surface =
231  AcquireRenderSurface(size, root_surface_transformation);
232 
233  if (surface == nullptr) {
234  return nullptr;
235  }
236 
237  surface->getCanvas()->setMatrix(root_surface_transformation);
238  SurfaceFrame::SubmitCallback submit_callback =
239  [weak = weak_factory_.GetWeakPtr()](const SurfaceFrame& surface_frame,
240  SkCanvas* canvas) {
241  return weak ? weak->PresentSurface(canvas) : false;
242  };
243 
244  return std::make_unique<SurfaceFrame>(
245  surface, delegate_->SurfaceSupportsReadback(), submit_callback,
246  std::move(context_switch));
247 }
std::function< bool(const SurfaceFrame &surface_frame, SkCanvas *canvas)> SubmitCallback
Definition: surface_frame.h:22
MockDelegate delegate_
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
#define FML_LOG(severity)
Definition: logging.h:65
SkMatrix GetRootTransformation() const override

◆ AllowsDrawingWhenGpuDisabled()

bool flutter::GPUSurfaceGL::AllowsDrawingWhenGpuDisabled ( ) const
overridevirtual

Reimplemented from flutter::Surface.

Definition at line 322 of file gpu_surface_gl.cc.

References flutter::GPUSurfaceGLDelegate::AllowsDrawingWhenGpuDisabled().

322  {
323  return delegate_->AllowsDrawingWhenGpuDisabled();
324 }
MockDelegate delegate_

◆ ClearRenderContext()

bool flutter::GPUSurfaceGL::ClearRenderContext ( )
overridevirtual

Reimplemented from flutter::Surface.

Definition at line 317 of file gpu_surface_gl.cc.

References flutter::GPUSurfaceGLDelegate::GLContextClearCurrent().

317  {
318  return delegate_->GLContextClearCurrent();
319 }
MockDelegate delegate_

◆ GetContext()

GrDirectContext * flutter::GPUSurfaceGL::GetContext ( )
overridevirtual

Implements flutter::Surface.

Definition at line 307 of file gpu_surface_gl.cc.

307  {
308  return context_.get();
309 }

◆ GetRootTransformation()

SkMatrix flutter::GPUSurfaceGL::GetRootTransformation ( ) const
overridevirtual

Implements flutter::Surface.

Definition at line 203 of file gpu_surface_gl.cc.

References flutter::GPUSurfaceGLDelegate::GLContextSurfaceTransformation().

Referenced by AcquireFrame().

203  {
204  return delegate_->GLContextSurfaceTransformation();
205 }
MockDelegate delegate_

◆ IsValid()

bool flutter::GPUSurfaceGL::IsValid ( )
overridevirtual

Implements flutter::Surface.

Definition at line 112 of file gpu_surface_gl.cc.

112  {
113  return valid_;
114 }

◆ MakeGLContext()

sk_sp< GrDirectContext > flutter::GPUSurfaceGL::MakeGLContext ( GPUSurfaceGLDelegate delegate)
static

Definition at line 38 of file gpu_surface_gl.cc.

References FML_LOG, flutter::PersistentCache::GetCacheForProcess(), flutter::GPUSurfaceGLDelegate::GetGLInterface(), flutter::GPUSurfaceGLDelegate::GLContextMakeCurrent(), kOpenGL, flutter::kRender, flutter::MakeDefaultContextOptions(), and flutter::PersistentCache::PrecompileKnownSkSLs().

Referenced by flutter::IOSSurfaceGL::CreateGPUSurface().

39  {
40  auto context_switch = delegate->GLContextMakeCurrent();
41  if (!context_switch->GetResult()) {
42  FML_LOG(ERROR)
43  << "Could not make the context current to set up the Gr context.";
44  return nullptr;
45  }
46 
47  const auto options =
49 
50  auto context = GrDirectContext::MakeGL(delegate->GetGLInterface(), options);
51 
52  if (!context) {
53  FML_LOG(ERROR) << "Failed to set up Skia Gr context.";
54  return nullptr;
55  }
56 
57  context->setResourceCacheLimits(kGrCacheMaxCount, kGrCacheMaxByteSize);
58 
60 
61  return context;
62 }
static const size_t kGrCacheMaxByteSize
size_t PrecompileKnownSkSLs(GrDirectContext *context) const
Precompile SkSLs packaged with the application and gathered during previous runs in the given context...
#define FML_LOG(severity)
Definition: logging.h:65
static const int kGrCacheMaxCount
static PersistentCache * GetCacheForProcess()
The context is used to render to a texture or renderbuffer.
GrContextOptions MakeDefaultContextOptions(ContextType type, std::optional< GrBackendApi > api)
Initializes GrContextOptions with values suitable for Flutter. The options can be further tweaked bef...

◆ MakeRenderContextCurrent()

std::unique_ptr< GLContextResult > flutter::GPUSurfaceGL::MakeRenderContextCurrent ( )
overridevirtual

Reimplemented from flutter::Surface.

Definition at line 312 of file gpu_surface_gl.cc.

References flutter::GPUSurfaceGLDelegate::GLContextMakeCurrent().

312  {
313  return delegate_->GLContextMakeCurrent();
314 }
MockDelegate delegate_

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