Flutter Engine
The Flutter Engine
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
5#include "flutter/shell/platform/android/android_surface_gl_impeller.h"
6
7#include "flutter/fml/logging.h"
8#include "flutter/impeller/toolkit/egl/surface.h"
9#include "flutter/shell/gpu/gpu_surface_gl_impeller.h"
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 native_window_ = std::move(window);
79 return RecreateOnscreenSurfaceAndMakeOnscreenContextCurrent();
80}
81
82// |AndroidSurface|
85}
86
87// |AndroidSurface|
88std::shared_ptr<impeller::Context>
90 return android_context_->GetImpellerContext();
91}
92
93// |GPUSurfaceGLDelegate|
94std::unique_ptr<GLContextResult>
96 return std::make_unique<GLContextDefaultResult>(OnGLContextMakeCurrent());
97}
98
99bool AndroidSurfaceGLImpeller::OnGLContextMakeCurrent() {
100 if (!onscreen_surface_) {
101 return false;
102 }
103
104 return android_context_->OnscreenContextMakeCurrent(onscreen_surface_.get());
105}
106
107// |GPUSurfaceGLDelegate|
109 if (!onscreen_surface_) {
110 return false;
111 }
112
113 return android_context_->OnscreenContextClearCurrent();
114}
115
116// |GPUSurfaceGLDelegate|
120 info.supports_readback = true;
121 info.supports_partial_repaint = false;
122 return info;
123}
124
125// |GPUSurfaceGLDelegate|
127 const std::optional<SkIRect>& region) {
128 // Not supported.
129}
130
131// |GPUSurfaceGLDelegate|
133 const GLPresentInfo& present_info) {
134 // The FBO ID is superfluous and was introduced for iOS where the default
135 // framebuffer was not FBO0.
136 if (!onscreen_surface_) {
137 return false;
138 }
139 return onscreen_surface_->Present();
140}
141
142// |GPUSurfaceGLDelegate|
144 // FBO0 is the default window bound framebuffer in EGL environments.
145 return GLFBOInfo{
146 .fbo_id = 0,
147 };
148}
149
150// |GPUSurfaceGLDelegate|
152 return nullptr;
153}
154
155bool AndroidSurfaceGLImpeller::
156 RecreateOnscreenSurfaceAndMakeOnscreenContextCurrent() {
158 if (!native_window_) {
159 return false;
160 }
161 onscreen_surface_.reset();
162 auto onscreen_surface =
163 android_context_->CreateOnscreenSurface(native_window_->handle());
164 if (!onscreen_surface) {
165 FML_DLOG(ERROR) << "Could not create onscreen surface.";
166 return false;
167 }
168 onscreen_surface_ = std::move(onscreen_surface);
169 return OnGLContextMakeCurrent();
170}
171
172} // namespace flutter
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
SurfaceFrame::FramebufferInfo GLContextFramebufferInfo() const override
void GLContextSetDamageRegion(const std::optional< SkIRect > &region) override
bool SetNativeWindow(fml::RefPtr< AndroidNativeWindow > window) override
sk_sp< const GrGLInterface > GetGLInterface() const override
bool GLContextPresent(const GLPresentInfo &present_info) override
bool OnScreenSurfaceResize(const SkISize &size) override
AndroidSurfaceGLImpeller(const std::shared_ptr< AndroidContextGLImpeller > &android_context)
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
GLFWwindow * window
Definition: main.cc:45
VkSurfaceKHR surface
Definition: main.cc:49
#define FML_DLOG(severity)
Definition: logging.h:102
#define FML_UNREACHABLE()
Definition: logging.h:109
ClipOpAndAA opAA SkRegion region
Definition: SkRecords.h:238
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
Definition: SkSize.h:16
#define ERROR(message)
Definition: elf_loader.cc:260