Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
flutter::GPUSurfaceGLSkia Class Reference

#include <gpu_surface_gl_skia.h>

Inheritance diagram for flutter::GPUSurfaceGLSkia:
flutter::Surface

Public Member Functions

 GPUSurfaceGLSkia (GPUSurfaceGLDelegate *delegate, bool render_to_surface)
 
 GPUSurfaceGLSkia (const sk_sp< GrDirectContext > &gr_context, GPUSurfaceGLDelegate *delegate, bool render_to_surface)
 
 ~GPUSurfaceGLSkia () override
 
bool IsValid () override
 
std::unique_ptr< SurfaceFrameAcquireFrame (const SkISize &size) override
 
SkMatrix GetRootTransformation () const override
 
GrDirectContextGetContext () override
 
std::unique_ptr< GLContextResultMakeRenderContextCurrent () override
 
bool ClearRenderContext () override
 
bool AllowsDrawingWhenGpuDisabled () const override
 
- Public Member Functions inherited from flutter::Surface
 Surface ()
 
virtual ~Surface ()
 
virtual bool IsValid ()=0
 
virtual std::unique_ptr< SurfaceFrameAcquireFrame (const SkISize &size)=0
 
virtual SkMatrix GetRootTransformation () const =0
 
virtual GrDirectContextGetContext ()=0
 
virtual std::unique_ptr< GLContextResultMakeRenderContextCurrent ()
 
virtual bool ClearRenderContext ()
 
virtual bool AllowsDrawingWhenGpuDisabled () const
 
virtual bool EnableRasterCache () const
 
virtual std::shared_ptr< impeller::AiksContextGetAiksContext () const
 
virtual SurfaceData GetSurfaceData () const
 

Static Public Member Functions

static sk_sp< GrDirectContextMakeGLContext (GPUSurfaceGLDelegate *delegate)
 

Detailed Description

Definition at line 23 of file gpu_surface_gl_skia.h.

Constructor & Destructor Documentation

◆ GPUSurfaceGLSkia() [1/2]

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

Definition at line 69 of file gpu_surface_gl_skia.cc.

71 : GPUSurfaceGLSkia(MakeGLContext(delegate), delegate, render_to_surface) {
72 context_owner_ = true;
73}
static sk_sp< GrDirectContext > MakeGLContext(GPUSurfaceGLDelegate *delegate)
GPUSurfaceGLSkia(GPUSurfaceGLDelegate *delegate, bool render_to_surface)

◆ GPUSurfaceGLSkia() [2/2]

flutter::GPUSurfaceGLSkia::GPUSurfaceGLSkia ( const sk_sp< GrDirectContext > &  gr_context,
GPUSurfaceGLDelegate delegate,
bool  render_to_surface 
)

Definition at line 75 of file gpu_surface_gl_skia.cc.

78 : delegate_(delegate),
79 context_(gr_context),
80
81 render_to_surface_(render_to_surface),
82 weak_factory_(this) {
83 auto context_switch = delegate_->GLContextMakeCurrent();
84 if (!context_switch->GetResult()) {
86 << "Could not make the context current to set up the Gr context.";
87 return;
88 }
89
90 delegate_->GLContextClearCurrent();
91
92 valid_ = gr_context != nullptr;
93}
virtual std::unique_ptr< GLContextResult > GLContextMakeCurrent()=0
virtual bool GLContextClearCurrent()=0
#define FML_LOG(severity)
Definition: logging.h:82
#define ERROR(message)
Definition: elf_loader.cc:260

◆ ~GPUSurfaceGLSkia()

flutter::GPUSurfaceGLSkia::~GPUSurfaceGLSkia ( )
override

Definition at line 95 of file gpu_surface_gl_skia.cc.

95 {
96 if (!valid_) {
97 return;
98 }
99 auto context_switch = delegate_->GLContextMakeCurrent();
100 if (!context_switch->GetResult()) {
101 FML_LOG(ERROR) << "Could not make the context current to destroy the "
102 "GrDirectContext resources.";
103 return;
104 }
105
106 onscreen_surface_ = nullptr;
107 fbo_id_ = 0;
108 if (context_owner_) {
110 }
111 context_ = nullptr;
112
113 delegate_->GLContextClearCurrent();
114}
void releaseResourcesAndAbandonContext()

Member Function Documentation

◆ AcquireFrame()

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

Implements flutter::Surface.

Definition at line 215 of file gpu_surface_gl_skia.cc.

216 {
217 if (delegate_ == nullptr) {
218 return nullptr;
219 }
220 auto context_switch = delegate_->GLContextMakeCurrent();
221 if (!context_switch->GetResult()) {
223 << "Could not make the context current to acquire the frame.";
224 return nullptr;
225 }
226
227 SurfaceFrame::FramebufferInfo framebuffer_info;
228
229 // TODO(38466): Refactor GPU surface APIs take into account the fact that an
230 // external view embedder may want to render to the root surface.
231 if (!render_to_surface_) {
232 framebuffer_info.supports_readback = true;
233 return std::make_unique<SurfaceFrame>(
234 nullptr, framebuffer_info,
235 [](const SurfaceFrame& surface_frame, DlCanvas* canvas) {
236 return true;
237 },
238 size);
239 }
240
241 const auto root_surface_transformation = GetRootTransformation();
242
244 AcquireRenderSurface(size, root_surface_transformation);
245
246 if (surface == nullptr) {
247 return nullptr;
248 }
249
250 surface->getCanvas()->setMatrix(root_surface_transformation);
251 SurfaceFrame::SubmitCallback submit_callback =
252 [weak = weak_factory_.GetWeakPtr()](const SurfaceFrame& surface_frame,
253 DlCanvas* canvas) {
254 return weak ? weak->PresentSurface(surface_frame, canvas) : false;
255 };
256
257 framebuffer_info = delegate_->GLContextFramebufferInfo();
258 if (!framebuffer_info.existing_damage.has_value()) {
259 framebuffer_info.existing_damage = existing_damage_;
260 }
261 return std::make_unique<SurfaceFrame>(surface, framebuffer_info,
262 submit_callback, size,
263 std::move(context_switch));
264}
virtual SurfaceFrame::FramebufferInfo GLContextFramebufferInfo() const
SkMatrix GetRootTransformation() const override
std::function< bool(SurfaceFrame &surface_frame, DlCanvas *canvas)> SubmitCallback
Definition: surface_frame.h:27
VkSurfaceKHR surface
Definition: main.cc:49
it will be possible to load the file into Perfetto s trace viewer 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
Definition: switches.h:259
flutter::DlCanvas DlCanvas
std::optional< SkIRect > existing_damage
Definition: surface_frame.h:56

◆ AllowsDrawingWhenGpuDisabled()

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

Reimplemented from flutter::Surface.

Definition at line 349 of file gpu_surface_gl_skia.cc.

349 {
350 return delegate_->AllowsDrawingWhenGpuDisabled();
351}
virtual bool AllowsDrawingWhenGpuDisabled() const

◆ ClearRenderContext()

bool flutter::GPUSurfaceGLSkia::ClearRenderContext ( )
overridevirtual

Reimplemented from flutter::Surface.

Definition at line 344 of file gpu_surface_gl_skia.cc.

344 {
345 return delegate_->GLContextClearCurrent();
346}

◆ GetContext()

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

Implements flutter::Surface.

Definition at line 334 of file gpu_surface_gl_skia.cc.

334 {
335 return context_.get();
336}
T * get() const
Definition: SkRefCnt.h:303

◆ GetRootTransformation()

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

Implements flutter::Surface.

Definition at line 210 of file gpu_surface_gl_skia.cc.

210 {
211 return delegate_->GLContextSurfaceTransformation();
212}
virtual SkMatrix GLContextSurfaceTransformation() const

◆ IsValid()

bool flutter::GPUSurfaceGLSkia::IsValid ( )
overridevirtual

Implements flutter::Surface.

Definition at line 117 of file gpu_surface_gl_skia.cc.

117 {
118 return valid_;
119}

◆ MakeGLContext()

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

Definition at line 43 of file gpu_surface_gl_skia.cc.

44 {
45 auto context_switch = delegate->GLContextMakeCurrent();
46 if (!context_switch->GetResult()) {
48 << "Could not make the context current to set up the Gr context.";
49 return nullptr;
50 }
51
52 const auto options =
54
55 auto context = GrDirectContexts::MakeGL(delegate->GetGLInterface(), options);
56
57 if (!context) {
58 FML_LOG(ERROR) << "Failed to set up Skia Gr context.";
59 return nullptr;
60 }
61
62 context->setResourceCacheLimit(kGrCacheMaxByteSize);
63
65
66 return context;
67}
const char * options
static PersistentCache * GetCacheForProcess()
size_t PrecompileKnownSkSLs(GrDirectContext *context) const
Precompile SkSLs packaged with the application and gathered during previous runs in the given context...
SK_API sk_sp< GrDirectContext > MakeGL(sk_sp< const GrGLInterface >, const GrContextOptions &)
GrContextOptions MakeDefaultContextOptions(ContextType type, std::optional< GrBackendApi > api)
Initializes GrContextOptions with values suitable for Flutter. The options can be further tweaked bef...
static const size_t kGrCacheMaxByteSize
@ kRender
The context is used to render to a texture or renderbuffer.

◆ MakeRenderContextCurrent()

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

Reimplemented from flutter::Surface.

Definition at line 339 of file gpu_surface_gl_skia.cc.

339 {
340 return delegate_->GLContextMakeCurrent();
341}

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