Flutter Engine
 
Loading...
Searching...
No Matches
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 DlISize &size) override
 
DlMatrix 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 ()
 
virtual bool EnableRasterCache () const
 
virtual std::shared_ptr< impeller::AiksContextGetAiksContext () const
 
virtual SurfaceData GetSurfaceData () const
 

Static Public Member Functions

static sk_sp< GrDirectContext > MakeGLContext (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 68 of file gpu_surface_gl_skia.cc.

70 : GPUSurfaceGLSkia(MakeGLContext(delegate), delegate, render_to_surface) {
71 context_owner_ = true;
72}
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 74 of file gpu_surface_gl_skia.cc.

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

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

◆ ~GPUSurfaceGLSkia()

flutter::GPUSurfaceGLSkia::~GPUSurfaceGLSkia ( )
override

Definition at line 93 of file gpu_surface_gl_skia.cc.

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

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

Member Function Documentation

◆ AcquireFrame()

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

Implements flutter::Surface.

Definition at line 213 of file gpu_surface_gl_skia.cc.

214 {
215 if (delegate_ == nullptr) {
216 return nullptr;
217 }
218 auto context_switch = delegate_->GLContextMakeCurrent();
219 if (!context_switch->GetResult()) {
220 FML_LOG(ERROR)
221 << "Could not make the context current to acquire the frame.";
222 return nullptr;
223 }
224
225 SurfaceFrame::FramebufferInfo framebuffer_info;
226
227 // TODO(38466): Refactor GPU surface APIs take into account the fact that an
228 // external view embedder may want to render to the root surface.
229 if (!render_to_surface_) {
230 framebuffer_info.supports_readback = true;
231 return std::make_unique<SurfaceFrame>(
232 nullptr, framebuffer_info,
233 [](const SurfaceFrame& surface_frame, DlCanvas* canvas) {
234 return true;
235 },
236 [](const SurfaceFrame& surface_frame) { return true; }, size);
237 }
238
239 const auto root_surface_transformation = GetRootTransformation();
240
241 sk_sp<SkSurface> surface =
242 AcquireRenderSurface(size, root_surface_transformation);
243
244 if (surface == nullptr) {
245 return nullptr;
246 }
247
248 surface->getCanvas()->setMatrix(ToSkM44(root_surface_transformation));
249
250 SurfaceFrame::EncodeCallback encode_callback =
251 [weak = weak_factory_.GetWeakPtr()](const SurfaceFrame& surface_frame,
252 DlCanvas* canvas) {
253 TRACE_EVENT0("flutter", "GrDirectContext::flushAndSubmit");
254 if (weak) {
255 weak->context_->flushAndSubmit();
256 return true;
257 }
258 return false;
259 };
260 SurfaceFrame::SubmitCallback submit_callback =
261 [weak = weak_factory_.GetWeakPtr()](const SurfaceFrame& surface_frame) {
262 return weak ? weak->PresentSurface(surface_frame) : false;
263 };
264
265 framebuffer_info = delegate_->GLContextFramebufferInfo();
266 if (!framebuffer_info.existing_damage.has_value()) {
267 framebuffer_info.existing_damage = existing_damage_;
268 }
269 return std::make_unique<SurfaceFrame>(surface, framebuffer_info,
270 encode_callback, submit_callback, size,
271 std::move(context_switch));
272}
virtual SurfaceFrame::FramebufferInfo GLContextFramebufferInfo() const
DlMatrix GetRootTransformation() const override
std::function< bool(SurfaceFrame &surface_frame, DlCanvas *canvas)> EncodeCallback
std::function< bool(SurfaceFrame &surface_frame)> SubmitCallback
VkSurfaceKHR surface
Definition main.cc:65
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
SkM44 ToSkM44(const DlMatrix &matrix)
flutter::DlCanvas DlCanvas
std::optional< DlIRect > existing_damage
#define TRACE_EVENT0(category_group, name)

References flutter::SurfaceFrame::FramebufferInfo::existing_damage, FML_LOG, GetRootTransformation(), flutter::GPUSurfaceGLDelegate::GLContextFramebufferInfo(), flutter::GPUSurfaceGLDelegate::GLContextMakeCurrent(), flutter::size, flutter::SurfaceFrame::FramebufferInfo::supports_readback, surface, flutter::ToSkM44(), and TRACE_EVENT0.

◆ AllowsDrawingWhenGpuDisabled()

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

Reimplemented from flutter::Surface.

Definition at line 352 of file gpu_surface_gl_skia.cc.

352 {
353 return delegate_->AllowsDrawingWhenGpuDisabled();
354}
virtual bool AllowsDrawingWhenGpuDisabled() const

References flutter::GPUSurfaceGLDelegate::AllowsDrawingWhenGpuDisabled().

◆ ClearRenderContext()

bool flutter::GPUSurfaceGLSkia::ClearRenderContext ( )
overridevirtual

Reimplemented from flutter::Surface.

Definition at line 347 of file gpu_surface_gl_skia.cc.

347 {
348 return delegate_->GLContextClearCurrent();
349}

References flutter::GPUSurfaceGLDelegate::GLContextClearCurrent().

◆ GetContext()

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

Implements flutter::Surface.

Definition at line 337 of file gpu_surface_gl_skia.cc.

337 {
338 return context_.get();
339}

◆ GetRootTransformation()

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

Implements flutter::Surface.

Definition at line 208 of file gpu_surface_gl_skia.cc.

208 {
209 return delegate_->GLContextSurfaceTransformation();
210}
virtual DlMatrix GLContextSurfaceTransformation() const

References flutter::GPUSurfaceGLDelegate::GLContextSurfaceTransformation().

Referenced by AcquireFrame().

◆ IsValid()

bool flutter::GPUSurfaceGLSkia::IsValid ( )
overridevirtual

Implements flutter::Surface.

Definition at line 115 of file gpu_surface_gl_skia.cc.

115 {
116 return valid_;
117}

◆ MakeGLContext()

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

Definition at line 42 of file gpu_surface_gl_skia.cc.

43 {
44 auto context_switch = delegate->GLContextMakeCurrent();
45 if (!context_switch->GetResult()) {
46 FML_LOG(ERROR)
47 << "Could not make the context current to set up the Gr context.";
48 return nullptr;
49 }
50
51 const auto options =
52 MakeDefaultContextOptions(ContextType::kRender, GrBackendApi::kOpenGL);
53
54 auto context = GrDirectContexts::MakeGL(delegate->GetGLInterface(), options);
55
56 if (!context) {
57 FML_LOG(ERROR) << "Failed to set up Skia Gr context.";
58 return nullptr;
59 }
60
61 context->setResourceCacheLimit(kGrCacheMaxByteSize);
62
64
65 return context;
66}
static PersistentCache * GetCacheForProcess()
size_t PrecompileKnownSkSLs(GrDirectContext *context) const
Precompile SkSLs packaged with the application and gathered during previous runs in the given context...
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.

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

Referenced by flutter::AndroidSurfaceGLSkia::CreateGPUSurface(), and flutter::AndroidSurfaceGLSkia::CreateSnapshotSurface().

◆ MakeRenderContextCurrent()

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

Reimplemented from flutter::Surface.

Definition at line 342 of file gpu_surface_gl_skia.cc.

342 {
343 return delegate_->GLContextMakeCurrent();
344}

References flutter::GPUSurfaceGLDelegate::GLContextMakeCurrent().


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