Flutter Engine
The Flutter Engine
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
5#include "flutter/shell/platform/embedder/tests/embedder_test_context_gl.h"
6
7#include <utility>
8
9#include "flutter/fml/make_copyable.h"
10#include "flutter/fml/paths.h"
11#include "flutter/runtime/dart_vm.h"
12#include "flutter/shell/platform/embedder/tests/embedder_assertions.h"
13#include "flutter/shell/platform/embedder/tests/embedder_test_compositor_gl.h"
14#include "flutter/testing/testing.h"
15#include "tests/embedder_test.h"
16#include "third_party/dart/runtime/bin/elf_loader.h"
18
19namespace flutter {
20namespace testing {
21
23 : EmbedderTestContext(std::move(assets_path)) {}
24
26 SetGLGetFBOCallback(nullptr);
27}
28
29void EmbedderTestContextGL::SetupSurface(SkISize surface_size) {
30 FML_CHECK(!gl_surface_);
31 gl_surface_ = std::make_unique<TestGLSurface>(surface_size);
32}
33
34bool EmbedderTestContextGL::GLMakeCurrent() {
35 FML_CHECK(gl_surface_) << "GL surface must be initialized.";
36 return gl_surface_->MakeCurrent();
37}
38
39bool EmbedderTestContextGL::GLClearCurrent() {
40 FML_CHECK(gl_surface_) << "GL surface must be initialized.";
41 return gl_surface_->ClearCurrent();
42}
43
44bool EmbedderTestContextGL::GLPresent(FlutterPresentInfo present_info) {
45 FML_CHECK(gl_surface_) << "GL surface must be initialized.";
46 gl_surface_present_count_++;
47
49 {
50 std::scoped_lock lock(gl_callback_mutex_);
51 callback = gl_present_callback_;
52 }
53
54 if (callback) {
55 callback(present_info);
56 }
57
59 [&]() { return gl_surface_->GetRasterSurfaceSnapshot(); });
60
61 return gl_surface_->Present();
62}
63
65 std::scoped_lock lock(gl_callback_mutex_);
66 gl_get_fbo_callback_ = std::move(callback);
67}
68
71 std::scoped_lock lock(gl_callback_mutex_);
72 gl_populate_existing_damage_callback_ = std::move(callback);
73}
74
76 std::scoped_lock lock(gl_callback_mutex_);
77 gl_present_callback_ = std::move(callback);
78}
79
80uint32_t EmbedderTestContextGL::GLGetFramebuffer(FlutterFrameInfo frame_info) {
81 FML_CHECK(gl_surface_) << "GL surface must be initialized.";
82
84 {
85 std::scoped_lock lock(gl_callback_mutex_);
86 callback = gl_get_fbo_callback_;
87 }
88
89 if (callback) {
90 callback(frame_info);
91 }
92
93 const auto size = frame_info.size;
94 return gl_surface_->GetFramebuffer(size.width, size.height);
95}
96
98 const intptr_t id,
99 FlutterDamage* existing_damage) {
100 FML_CHECK(gl_surface_) << "GL surface must be initialized.";
101
103 {
104 std::scoped_lock lock(gl_callback_mutex_);
105 callback = gl_populate_existing_damage_callback_;
106 }
107
108 if (callback) {
109 callback(id, existing_damage);
110 }
111}
112
113bool EmbedderTestContextGL::GLMakeResourceCurrent() {
114 FML_CHECK(gl_surface_) << "GL surface must be initialized.";
115 return gl_surface_->MakeResourceCurrent();
116}
117
119 FML_CHECK(gl_surface_) << "GL surface must be initialized.";
120 return gl_surface_->GetProcAddress(name);
121}
122
124 return gl_surface_present_count_;
125}
126
129}
130
132 FML_CHECK(gl_surface_);
133 return gl_surface_->GetWindowFBOId();
134}
135
137 FML_CHECK(!compositor_) << "Already set up a compositor in this context.";
138 FML_CHECK(gl_surface_)
139 << "Set up the GL surface before setting up a compositor.";
140 compositor_ = std::make_unique<EmbedderTestCompositorGL>(
141 gl_surface_->GetSurfaceSize(), gl_surface_->GetGrContext());
142 GLClearCurrent();
143}
144
145} // namespace testing
146} // namespace flutter
std::function< void(FlutterPresentInfo present_info)> GLPresentCallback
void SetGLGetFBOCallback(GLGetFBOCallback callback)
Sets a callback that will be invoked (on the raster task runner) when the engine asks the embedder fo...
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 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)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_CHECK(condition)
Definition: logging.h:85
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
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: ref_ptr.h:256
A structure to represent a damage region.
Definition: embedder.h:460
FlutterUIntSize size
The size of the surface that will be backed by the fbo.
Definition: embedder.h:479
Definition: SkSize.h:16