Flutter Engine
 
Loading...
Searching...
No Matches
android_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
10
11namespace flutter {
12
14 const std::shared_ptr<AndroidContextGLImpeller>& android_context)
15 : android_context_(android_context) {
16 offscreen_surface_ = android_context_->CreateOffscreenSurface();
17
18 if (!offscreen_surface_) {
19 FML_DLOG(ERROR) << "Could not create offscreen surface.";
20 return;
21 }
22
23 // The onscreen surface will be acquired once the native window is set.
24
25 is_valid_ = true;
26}
27
29
30// |AndroidSurface|
32 return is_valid_;
33}
34
35// |AndroidSurface|
37 GrDirectContext* gr_context) {
38 auto surface = std::make_unique<GPUSurfaceGLImpeller>(
39 this, // delegate
40 android_context_->GetImpellerContext(), // context
41 true // render to surface
42 );
43 if (!surface->IsValid()) {
44 return nullptr;
45 }
46 return surface;
47}
48
49// |AndroidSurface|
52 onscreen_surface_.reset();
53}
54
55// |AndroidSurface|
57 // The size is unused. It was added only for iOS where the sizes were
58 // necessary to re-create auxiliary buffers (stencil, depth, etc.).
59 return RecreateOnscreenSurfaceAndMakeOnscreenContextCurrent();
60}
61
62// |AndroidSurface|
64 if (!offscreen_surface_) {
65 return false;
66 }
67 return android_context_->ResourceContextMakeCurrent(offscreen_surface_.get());
68}
69
70// |AndroidSurface|
72 return android_context_->ResourceContextClearCurrent();
73}
74
75// |AndroidSurface|
78 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade) {
79 native_window_ = std::move(window);
80 return RecreateOnscreenSurfaceAndMakeOnscreenContextCurrent();
81}
82
83// |AndroidSurface|
85 if (!onscreen_surface_ || !onscreen_surface_->IsValid()) {
86 onscreen_surface_ = android_context_->CreateOffscreenSurface();
87 if (!onscreen_surface_) {
88 FML_DLOG(ERROR) << "Could not create offscreen surface for snapshot.";
89 return nullptr;
90 }
91 }
92 // Make the snapshot surface current because constucting a
93 // GPUSurfaceGLImpeller and its AiksContext may invoke graphics APIs.
94 if (!android_context_->OnscreenContextMakeCurrent(onscreen_surface_.get())) {
95 FML_DLOG(ERROR) << "Could not make snapshot surface current.";
96 return nullptr;
97 }
98 return std::make_unique<GPUSurfaceGLImpeller>(
99 this, // delegate
100 android_context_->GetImpellerContext(), // context
101 true // render to surface
102 );
103}
104
105// |AndroidSurface|
106std::shared_ptr<impeller::Context>
108 return android_context_->GetImpellerContext();
109}
110
111// |GPUSurfaceGLDelegate|
112std::unique_ptr<GLContextResult>
114 return std::make_unique<GLContextDefaultResult>(OnGLContextMakeCurrent());
115}
116
117bool AndroidSurfaceGLImpeller::OnGLContextMakeCurrent() {
118 if (!onscreen_surface_) {
119 return false;
120 }
121
122 return android_context_->OnscreenContextMakeCurrent(onscreen_surface_.get());
123}
124
125// |GPUSurfaceGLDelegate|
127 if (!onscreen_surface_) {
128 return false;
129 }
130
131 return android_context_->OnscreenContextClearCurrent();
132}
133
134// |GPUSurfaceGLDelegate|
137 auto info = SurfaceFrame::FramebufferInfo{};
138 info.supports_readback = true;
139 info.supports_partial_repaint = false;
140 return info;
141}
142
143// |GPUSurfaceGLDelegate|
145 const std::optional<DlIRect>& region) {
146 // Not supported.
147}
148
149// |GPUSurfaceGLDelegate|
151 const GLPresentInfo& present_info) {
152 // The FBO ID is superfluous and was introduced for iOS where the default
153 // framebuffer was not FBO0.
154 if (!onscreen_surface_) {
155 return false;
156 }
157 return onscreen_surface_->Present();
158}
159
160// |GPUSurfaceGLDelegate|
162 // FBO0 is the default window bound framebuffer in EGL environments.
163 return GLFBOInfo{
164 .fbo_id = 0,
165 };
166}
167
168// |GPUSurfaceGLDelegate|
169sk_sp<const GrGLInterface> AndroidSurfaceGLImpeller::GetGLInterface() const {
170 return nullptr;
171}
172
173bool AndroidSurfaceGLImpeller::
174 RecreateOnscreenSurfaceAndMakeOnscreenContextCurrent() {
176 if (!native_window_) {
177 return false;
178 }
179 onscreen_surface_.reset();
180 auto onscreen_surface =
181 android_context_->CreateOnscreenSurface(native_window_->handle());
182 if (!onscreen_surface) {
183 FML_DLOG(ERROR) << "Could not create onscreen surface.";
184 return false;
185 }
186 onscreen_surface_ = std::move(onscreen_surface);
187 return OnGLContextMakeCurrent();
188}
189
190} // namespace flutter
SurfaceFrame::FramebufferInfo GLContextFramebufferInfo() const override
bool SetNativeWindow(fml::RefPtr< AndroidNativeWindow > window, const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade) override
sk_sp< const GrGLInterface > GetGLInterface() const override
bool GLContextPresent(const GLPresentInfo &present_info) override
AndroidSurfaceGLImpeller(const std::shared_ptr< AndroidContextGLImpeller > &android_context)
void GLContextSetDamageRegion(const std::optional< DlIRect > &region) override
GLFBOInfo GLContextFBO(GLFrameInfo frame_info) const override
std::shared_ptr< impeller::Context > GetImpellerContext() override
std::unique_ptr< GLContextResult > GLContextMakeCurrent() override
std::unique_ptr< Surface > CreateSnapshotSurface() override
std::unique_ptr< Surface > CreateGPUSurface(GrDirectContext *gr_context) override
bool OnScreenSurfaceResize(const DlISize &size) override
GLFWwindow * window
Definition main.cc:60
VkSurfaceKHR surface
Definition main.cc:65
#define FML_DLOG(severity)
Definition logging.h:121
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