Flutter Engine
 
Loading...
Searching...
No Matches
embedder_test_context_gl.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
7#include <memory>
8#include <utility>
9
11#include "flutter/fml/paths.h"
16#include "tests/embedder_test.h"
17#include "third_party/dart/runtime/bin/elf_loader.h"
18
19namespace flutter::testing {
20
22 : EmbedderTestContext(std::move(assets_path)),
23 egl_context_(std::make_shared<TestEGLContext>()) {
27 .make_current = [](void* context) -> bool {
28 return reinterpret_cast<EmbedderTestContextGL*>(context)
29 ->GLMakeCurrent();
30 },
31 .clear_current = [](void* context) -> bool {
32 return reinterpret_cast<EmbedderTestContextGL*>(context)
33 ->GLClearCurrent();
34 },
35 .make_resource_current = [](void* context) -> bool {
36 return reinterpret_cast<EmbedderTestContextGL*>(context)
37 ->GLMakeResourceCurrent();
38 },
39 .fbo_reset_after_present = true,
40 .surface_transformation = [](void* context) -> FlutterTransformation {
41 return reinterpret_cast<EmbedderTestContextGL*>(context)
43 },
44 .gl_proc_resolver = [](void* context, const char* name) -> void* {
45 return reinterpret_cast<EmbedderTestContextGL*>(context)
47 },
48 .fbo_with_frame_info_callback =
49 [](void* context, const FlutterFrameInfo* frame_info) -> uint32_t {
50 return reinterpret_cast<EmbedderTestContextGL*>(context)
51 ->GLGetFramebuffer(*frame_info);
52 },
53 .present_with_info = [](void* context,
54 const FlutterPresentInfo* present_info) -> bool {
55 return reinterpret_cast<EmbedderTestContextGL*>(context)->GLPresent(
56 *present_info);
57 },
58 .populate_existing_damage = nullptr,
59 };
60}
61
65
67 // SetOpenGLRendererConfig must be called before this.
69
70 renderer_config_.open_gl.fbo_callback = [](void* context) -> uint32_t {
71 FlutterFrameInfo frame_info = {};
72 // fbo_callback doesn't use the frame size information, only
73 // fbo_callback_with_frame_info does.
74 frame_info.struct_size = sizeof(FlutterFrameInfo);
75 frame_info.size.width = 0;
76 frame_info.size.height = 0;
77 return reinterpret_cast<EmbedderTestContextGL*>(context)->GLGetFramebuffer(
78 frame_info);
79 };
80}
81
83 // SetOpenGLRendererConfig must be called before this.
85
86 renderer_config_.open_gl.present = [](void* context) -> bool {
87 // passing a placeholder fbo_id.
88 return reinterpret_cast<EmbedderTestContextGL*>(context)->GLPresent(
90 .fbo_id = 0,
91 });
92 };
93}
94
95bool EmbedderTestContextGL::GLMakeCurrent() {
96 FML_CHECK(gl_surface_) << "GL surface must be initialized.";
97 return gl_surface_->MakeCurrent();
98}
99
100bool EmbedderTestContextGL::GLClearCurrent() {
101 FML_CHECK(gl_surface_) << "GL surface must be initialized.";
102 return gl_surface_->ClearCurrent();
103}
104
105bool EmbedderTestContextGL::GLPresent(FlutterPresentInfo present_info) {
106 FML_CHECK(gl_surface_) << "GL surface must be initialized.";
107 gl_surface_present_count_++;
108
110 {
111 std::scoped_lock lock(gl_callback_mutex_);
112 callback = gl_present_callback_;
113 }
114
115 if (callback) {
116 callback(present_info);
117 }
118
120 [&]() { return gl_surface_->GetRasterSurfaceSnapshot(); });
121
122 return gl_surface_->Present();
123}
124
126 const GLGetFBOCallback& callback) {
127 std::scoped_lock lock(gl_callback_mutex_);
128 gl_get_fbo_callback_ = callback;
129}
130
133 std::scoped_lock lock(gl_callback_mutex_);
134 gl_populate_existing_damage_callback_ = std::move(callback);
135}
136
138 std::scoped_lock lock(gl_callback_mutex_);
139 gl_present_callback_ = std::move(callback);
140}
141
142uint32_t EmbedderTestContextGL::GLGetFramebuffer(FlutterFrameInfo frame_info) {
143 FML_CHECK(gl_surface_) << "GL surface must be initialized.";
144
146 {
147 std::scoped_lock lock(gl_callback_mutex_);
148 callback = gl_get_fbo_callback_;
149 }
150
151 if (callback) {
152 callback(frame_info);
153 }
154
155 const auto size = frame_info.size;
156 return gl_surface_->GetFramebuffer(size.width, size.height);
157}
158
160 const intptr_t id,
161 FlutterDamage* existing_damage) {
162 FML_CHECK(gl_surface_) << "GL surface must be initialized.";
163
165 {
166 std::scoped_lock lock(gl_callback_mutex_);
167 callback = gl_populate_existing_damage_callback_;
168 }
169
170 if (callback) {
171 callback(id, existing_damage);
172 }
173}
174
175bool EmbedderTestContextGL::GLMakeResourceCurrent() {
176 FML_CHECK(gl_surface_) << "GL surface must be initialized.";
177 return gl_surface_->MakeResourceCurrent();
178}
179
181 FML_CHECK(gl_surface_) << "GL surface must be initialized.";
182 return gl_surface_->GetProcAddress(name);
183}
184
186 return gl_surface_present_count_;
187}
188
192
194 FML_CHECK(gl_surface_);
195 return gl_surface_->GetWindowFBOId();
196}
197
198void EmbedderTestContextGL::SetSurface(DlISize surface_size) {
199 FML_CHECK(!gl_surface_);
200 gl_surface_ = std::make_unique<TestGLSurface>(egl_context_, surface_size);
201}
202
203void EmbedderTestContextGL::SetupCompositor() {
204 FML_CHECK(!compositor_) << "Already set up a compositor in this context.";
205 FML_CHECK(gl_surface_)
206 << "Set up the GL surface before setting up a compositor.";
207 compositor_ = std::make_unique<EmbedderTestCompositorGL>(
208 egl_context_, gl_surface_->GetSurfaceSize(), gl_surface_->GetGrContext());
209 GLClearCurrent();
210}
211
212} // namespace flutter::testing
std::function< void(FlutterPresentInfo present_info)> GLPresentCallback
void GLPopulateExistingDamage(const intptr_t id, FlutterDamage *existing_damage)
EmbedderTestContextType GetContextType() const override
void SetGLPopulateExistingDamageCallback(GLPopulateExistingDamageCallback callback)
std::function< void(FlutterFrameInfo frame_info)> GLGetFBOCallback
void SetGLGetFBOCallback(const GLGetFBOCallback &callback)
Sets a callback that will be invoked (on the raster task runner) when the engine asks the embedder fo...
void SetGLPresentCallback(GLPresentCallback callback)
Sets a callback that will be invoked (on the raster task runner) when the engine presents an fbo that...
std::function< void(intptr_t id, FlutterDamage *existing_damage)> GLPopulateExistingDamageCallback
std::unique_ptr< EmbedderTestCompositor > compositor_
void FireRootSurfacePresentCallbackIfPresent(const std::function< sk_sp< SkImage >(void)> &image_callback)
@ kOpenGL
Definition embedder.h:80
FlutterDesktopBinaryReply callback
#define FML_CHECK(condition)
Definition logging.h:104
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
DEF_SWITCHES_START aot vmservice shared library name
Definition switch_defs.h:27
Definition ref_ptr.h:261
A structure to represent a damage region.
Definition embedder.h:664
size_t struct_size
The size of this struct. Must be sizeof(FlutterFrameInfo).
Definition embedder.h:681
FlutterUIntSize size
The size of the surface that will be backed by the fbo.
Definition embedder.h:683
size_t struct_size
The size of this struct. Must be sizeof(FlutterOpenGLRendererConfig).
Definition embedder.h:719
uint32_t fbo_id
Id of the fbo backing the surface that was presented.
Definition embedder.h:705
FlutterOpenGLRendererConfig open_gl
Definition embedder.h:1033
FlutterRendererType type
Definition embedder.h:1031
uint32_t height
Definition embedder.h:637
uint32_t width
Definition embedder.h:636