Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
flutter::GPUSurfaceGLImpeller Class Referencefinal

#include <gpu_surface_gl_impeller.h>

Inheritance diagram for flutter::GPUSurfaceGLImpeller:
flutter::Surface

Public Member Functions

 GPUSurfaceGLImpeller (GPUSurfaceGLDelegate *delegate, std::shared_ptr< impeller::Context > context, bool render_to_surface)
 
 ~GPUSurfaceGLImpeller () override
 
bool IsValid () override
 
- Public Member Functions inherited from flutter::Surface
 Surface ()
 
virtual ~Surface ()
 
virtual SurfaceData GetSurfaceData () const
 

Private Member Functions

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
 
bool EnableRasterCache () const override
 
std::shared_ptr< impeller::AiksContextGetAiksContext () const override
 

Detailed Description

Definition at line 18 of file gpu_surface_gl_impeller.h.

Constructor & Destructor Documentation

◆ GPUSurfaceGLImpeller()

flutter::GPUSurfaceGLImpeller::GPUSurfaceGLImpeller ( GPUSurfaceGLDelegate delegate,
std::shared_ptr< impeller::Context context,
bool  render_to_surface 
)
explicit

Definition at line 15 of file gpu_surface_gl_impeller.cc.

19 : weak_factory_(this) {
20 if (delegate == nullptr) {
21 return;
22 }
23
24 if (!context || !context->IsValid()) {
25 return;
26 }
27
28 auto renderer = std::make_shared<impeller::Renderer>(context);
29 if (!renderer->IsValid()) {
30 return;
31 }
32
33 auto aiks_context = std::make_shared<impeller::AiksContext>(
35
36 if (!aiks_context->IsValid()) {
37 return;
38 }
39
40 delegate_ = delegate;
41 impeller_context_ = std::move(context);
42 render_to_surface_ = render_to_surface;
43 impeller_renderer_ = std::move(renderer);
44 aiks_context_ = std::move(aiks_context);
45 is_valid_ = true;
46}
static std::shared_ptr< TypographerContext > Make()

◆ ~GPUSurfaceGLImpeller()

flutter::GPUSurfaceGLImpeller::~GPUSurfaceGLImpeller ( )
overridedefault

Member Function Documentation

◆ AcquireFrame()

std::unique_ptr< SurfaceFrame > flutter::GPUSurfaceGLImpeller::AcquireFrame ( const SkISize size)
overrideprivatevirtual

Implements flutter::Surface.

Definition at line 57 of file gpu_surface_gl_impeller.cc.

58 {
59 if (!IsValid()) {
60 FML_LOG(ERROR) << "OpenGL surface was invalid.";
61 return nullptr;
62 }
63
64 auto swap_callback = [weak = weak_factory_.GetWeakPtr(),
65 delegate = delegate_]() -> bool {
66 if (weak) {
67 GLPresentInfo present_info = {
68 .fbo_id = 0u,
69 .frame_damage = std::nullopt,
70 // TODO (https://github.com/flutter/flutter/issues/105597): wire-up
71 // presentation time to impeller backend.
72 .presentation_time = std::nullopt,
73 .buffer_damage = std::nullopt,
74 };
75 delegate->GLContextPresent(present_info);
76 }
77 return true;
78 };
79
80 auto context_switch = delegate_->GLContextMakeCurrent();
81 if (!context_switch->GetResult()) {
83 << "Could not make the context current to acquire the frame.";
84 return nullptr;
85 }
86
87 if (!render_to_surface_) {
88 return std::make_unique<SurfaceFrame>(
89 nullptr, SurfaceFrame::FramebufferInfo{.supports_readback = true},
90 [](const SurfaceFrame& surface_frame, DlCanvas* canvas) {
91 return true;
92 },
93 size);
94 }
95
96 GLFrameInfo frame_info = {static_cast<uint32_t>(size.width()),
97 static_cast<uint32_t>(size.height())};
98 const GLFBOInfo fbo_info = delegate_->GLContextFBO(frame_info);
100 impeller_context_, // context
101 swap_callback, // swap_callback
102 fbo_info.fbo_id, // fbo
104 impeller::ISize{size.width(), size.height()} // fbo_size
105 );
106
107 SurfaceFrame::SubmitCallback submit_callback =
108 fml::MakeCopyable([renderer = impeller_renderer_, //
109 aiks_context = aiks_context_, //
110 surface = std::move(surface) //
111 ](SurfaceFrame& surface_frame, DlCanvas* canvas) mutable -> bool {
112 if (!aiks_context) {
113 return false;
114 }
115
116 auto display_list = surface_frame.BuildDisplayList();
117 if (!display_list) {
118 FML_LOG(ERROR) << "Could not build display list for surface frame.";
119 return false;
120 }
121
122 auto cull_rect =
123 surface->GetTargetRenderPassDescriptor().GetRenderTargetSize();
124 impeller::Rect dl_cull_rect = impeller::Rect::MakeSize(cull_rect);
125 impeller::DlDispatcher impeller_dispatcher(dl_cull_rect);
126 display_list->Dispatch(
127 impeller_dispatcher,
128 SkIRect::MakeWH(cull_rect.width, cull_rect.height));
129 auto picture = impeller_dispatcher.EndRecordingAsPicture();
130
131 return renderer->Render(
132 std::move(surface),
134 [aiks_context, picture = std::move(picture)](
135 impeller::RenderTarget& render_target) -> bool {
136 return aiks_context->Render(picture, render_target,
137 /*reset_host_buffer=*/true);
138 }));
139 });
140
141 return std::make_unique<SurfaceFrame>(
142 nullptr, // surface
143 delegate_->GLContextFramebufferInfo(), // framebuffer info
144 submit_callback, // submit callback
145 size, // frame size
146 std::move(context_switch), // context result
147 true // display list fallback
148 );
149}
virtual std::unique_ptr< GLContextResult > GLContextMakeCurrent()=0
virtual SurfaceFrame::FramebufferInfo GLContextFramebufferInfo() const
virtual GLFBOInfo GLContextFBO(GLFrameInfo frame_info) const =0
std::function< bool(SurfaceFrame &surface_frame, DlCanvas *canvas)> SubmitCallback
static std::unique_ptr< Surface > WrapFBO(const std::shared_ptr< Context > &context, SwapCallback swap_callback, GLuint fbo, PixelFormat color_format, ISize fbo_size)
VkSurfaceKHR surface
Definition main.cc:49
#define FML_LOG(severity)
Definition logging.h:82
sk_sp< const SkPicture > picture
Definition SkRecords.h:299
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
internal::CopyableLambda< T > MakeCopyable(T lambda)
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:146
#define ERROR(message)

◆ AllowsDrawingWhenGpuDisabled()

bool flutter::GPUSurfaceGLImpeller::AllowsDrawingWhenGpuDisabled ( ) const
overrideprivatevirtual

Reimplemented from flutter::Surface.

Definition at line 175 of file gpu_surface_gl_impeller.cc.

175 {
176 return delegate_->AllowsDrawingWhenGpuDisabled();
177}
virtual bool AllowsDrawingWhenGpuDisabled() const

◆ ClearRenderContext()

bool flutter::GPUSurfaceGLImpeller::ClearRenderContext ( )
overrideprivatevirtual

Reimplemented from flutter::Surface.

Definition at line 171 of file gpu_surface_gl_impeller.cc.

171 {
172 return delegate_->GLContextClearCurrent();
173}
virtual bool GLContextClearCurrent()=0

◆ EnableRasterCache()

bool flutter::GPUSurfaceGLImpeller::EnableRasterCache ( ) const
overrideprivatevirtual

Reimplemented from flutter::Surface.

Definition at line 180 of file gpu_surface_gl_impeller.cc.

180 {
181 return false;
182}

◆ GetAiksContext()

std::shared_ptr< impeller::AiksContext > flutter::GPUSurfaceGLImpeller::GetAiksContext ( ) const
overrideprivatevirtual

Reimplemented from flutter::Surface.

Definition at line 185 of file gpu_surface_gl_impeller.cc.

186 {
187 return aiks_context_;
188}

◆ GetContext()

GrDirectContext * flutter::GPUSurfaceGLImpeller::GetContext ( )
overrideprivatevirtual

Implements flutter::Surface.

Definition at line 159 of file gpu_surface_gl_impeller.cc.

159 {
160 // Impeller != Skia.
161 return nullptr;
162}

◆ GetRootTransformation()

SkMatrix flutter::GPUSurfaceGLImpeller::GetRootTransformation ( ) const
overrideprivatevirtual

Implements flutter::Surface.

Definition at line 152 of file gpu_surface_gl_impeller.cc.

152 {
153 // This backend does not currently support root surface transformations. Just
154 // return identity.
155 return {};
156}

◆ IsValid()

bool flutter::GPUSurfaceGLImpeller::IsValid ( )
overridevirtual

Implements flutter::Surface.

Definition at line 52 of file gpu_surface_gl_impeller.cc.

52 {
53 return is_valid_;
54}

◆ MakeRenderContextCurrent()

std::unique_ptr< GLContextResult > flutter::GPUSurfaceGLImpeller::MakeRenderContextCurrent ( )
overrideprivatevirtual

Reimplemented from flutter::Surface.

Definition at line 166 of file gpu_surface_gl_impeller.cc.

166 {
167 return delegate_->GLContextMakeCurrent();
168}

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