Flutter Engine
 
Loading...
Searching...
No Matches
gpu_surface_gl_impeller.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
12
13namespace flutter {
14
16 GPUSurfaceGLDelegate* delegate,
17 std::shared_ptr<impeller::Context> context,
18 bool render_to_surface)
19 : weak_factory_(this) {
20 if (delegate == nullptr) {
21 return;
22 }
23
24 if (!context || !context->IsValid()) {
25 return;
26 }
27
28 auto aiks_context = std::make_shared<impeller::AiksContext>(
30
31 if (!aiks_context->IsValid()) {
32 return;
33 }
34
35 delegate_ = delegate;
36 impeller_context_ = std::move(context);
37 render_to_surface_ = render_to_surface;
38 aiks_context_ = std::move(aiks_context);
39 is_valid_ = true;
40}
41
42// |Surface|
44
45// |Surface|
47 return is_valid_;
48}
49
50// |Surface|
51std::unique_ptr<SurfaceFrame> GPUSurfaceGLImpeller::AcquireFrame(
52 const DlISize& size) {
53 if (!IsValid()) {
54 FML_LOG(ERROR) << "OpenGL surface was invalid.";
55 return nullptr;
56 }
57
58 auto swap_callback = [weak = weak_factory_.GetWeakPtr(),
59 delegate = delegate_]() -> bool {
60 if (weak) {
61 GLPresentInfo present_info = {
62 .fbo_id = 0u,
63 .frame_damage = std::nullopt,
64 // TODO (https://github.com/flutter/flutter/issues/105597): wire-up
65 // presentation time to impeller backend.
66 .presentation_time = std::nullopt,
67 .buffer_damage = std::nullopt,
68 };
69 delegate->GLContextPresent(present_info);
70 }
71 return true;
72 };
73
74 auto context_switch = delegate_->GLContextMakeCurrent();
75 if (!context_switch->GetResult()) {
76 FML_LOG(ERROR)
77 << "Could not make the context current to acquire the frame.";
78 return nullptr;
79 }
80
81 if (!render_to_surface_) {
82 return std::make_unique<SurfaceFrame>(
83 nullptr, SurfaceFrame::FramebufferInfo{.supports_readback = true},
84 [](const SurfaceFrame& surface_frame, DlCanvas* canvas) {
85 return true;
86 },
87 [](const SurfaceFrame& surface_frame) { return true; }, size);
88 }
89
90 GLFrameInfo frame_info = {static_cast<uint32_t>(size.width),
91 static_cast<uint32_t>(size.height)};
92 const GLFBOInfo fbo_info = delegate_->GLContextFBO(frame_info);
94 impeller_context_, // context
95 swap_callback, // swap_callback
96 fbo_info.fbo_id, // fbo
98 impeller::ISize{size.width, size.height} // fbo_size
99 );
100
101 impeller::RenderTarget render_target = surface->GetRenderTarget();
102
103 SurfaceFrame::EncodeCallback encode_callback =
104 [aiks_context = aiks_context_, //
105 render_target](SurfaceFrame& surface_frame,
106 DlCanvas* canvas) mutable -> bool {
107 if (!aiks_context) {
108 return false;
109 }
110
111 auto display_list = surface_frame.BuildDisplayList();
112 if (!display_list) {
113 FML_LOG(ERROR) << "Could not build display list for surface frame.";
114 return false;
115 }
116
117 auto cull_rect =
119 return impeller::RenderToTarget(aiks_context->GetContentContext(), //
120 render_target, //
121 display_list, //
122 cull_rect, //
123 /*reset_host_buffer=*/true //
124 );
125 return true;
126 };
127
128 return std::make_unique<SurfaceFrame>(
129 nullptr, // surface
130 delegate_->GLContextFramebufferInfo(), // framebuffer info
131 encode_callback, // encode callback
132 fml::MakeCopyable([surface = std::move(surface)](const SurfaceFrame&) {
133 return surface->Present();
134 }), // submit callback
135 size, // frame size
136 std::move(context_switch), // context result
137 true // display list fallback
138 );
139}
140
141// |Surface|
142DlMatrix GPUSurfaceGLImpeller::GetRootTransformation() const {
143 // This backend does not currently support root surface transformations. Just
144 // return identity.
145 return {};
146}
147
148// |Surface|
149GrDirectContext* GPUSurfaceGLImpeller::GetContext() {
150 // Impeller != Skia.
151 return nullptr;
152}
153
154// |Surface|
155std::unique_ptr<GLContextResult>
156GPUSurfaceGLImpeller::MakeRenderContextCurrent() {
157 return delegate_->GLContextMakeCurrent();
158}
159
160// |Surface|
161bool GPUSurfaceGLImpeller::ClearRenderContext() {
162 return delegate_->GLContextClearCurrent();
163}
164
165bool GPUSurfaceGLImpeller::AllowsDrawingWhenGpuDisabled() const {
166 return delegate_->AllowsDrawingWhenGpuDisabled();
167}
168
169// |Surface|
170bool GPUSurfaceGLImpeller::EnableRasterCache() const {
171 return false;
172}
173
174// |Surface|
175std::shared_ptr<impeller::AiksContext> GPUSurfaceGLImpeller::GetAiksContext()
176 const {
177 return aiks_context_;
178}
179
180} // namespace flutter
virtual bool AllowsDrawingWhenGpuDisabled() const
virtual std::unique_ptr< GLContextResult > GLContextMakeCurrent()=0
virtual bool GLContextClearCurrent()=0
virtual SurfaceFrame::FramebufferInfo GLContextFramebufferInfo() const
virtual GLFBOInfo GLContextFBO(GLFrameInfo frame_info) const =0
GPUSurfaceGLImpeller(GPUSurfaceGLDelegate *delegate, std::shared_ptr< impeller::Context > context, bool render_to_surface)
std::function< bool(SurfaceFrame &surface_frame, DlCanvas *canvas)> EncodeCallback
ISize GetRenderTargetSize() const
static std::unique_ptr< Surface > WrapFBO(const std::shared_ptr< Context > &context, SwapCallback swap_callback, GLuint fbo, PixelFormat color_format, ISize fbo_size)
static std::shared_ptr< TypographerContext > Make()
VkSurfaceKHR surface
Definition main.cc:65
#define FML_LOG(severity)
Definition logging.h:101
impeller::Matrix DlMatrix
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
internal::CopyableLambda< T > MakeCopyable(T lambda)
bool RenderToTarget(ContentContext &context, RenderTarget render_target, const sk_sp< flutter::DisplayList > &display_list, Rect cull_rect, bool reset_host_buffer, bool is_onscreen)
Render the provided display list to the render target.
flutter::DlCanvas DlCanvas
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:150