Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
android_context_gl_unittests.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#define FML_USED_ON_EMBEDDER
6
7#include <memory>
8#include "flutter/shell/common/thread_host.h"
9#include "flutter/shell/platform/android/android_context_gl_skia.h"
10#include "flutter/shell/platform/android/android_egl_surface.h"
11#include "flutter/shell/platform/android/android_environment_gl.h"
12#include "flutter/shell/platform/android/android_surface_gl_skia.h"
13#include "fml/logging.h"
14#include "gmock/gmock.h"
15#include "gtest/gtest.h"
17
18namespace flutter {
19namespace testing {
20namespace android {
21namespace {
22
23TaskRunners MakeTaskRunners(const std::string& thread_label,
24 const ThreadHost& thread_host) {
26 fml::RefPtr<fml::TaskRunner> platform_runner =
28
29 return TaskRunners(thread_label, platform_runner,
30 thread_host.raster_thread->GetTaskRunner(),
31 thread_host.ui_thread->GetTaskRunner(),
32 thread_host.io_thread->GetTaskRunner());
33}
34} // namespace
35
37 public:
39
41
45
46 std::string DescribeGpuModel() const override { return ""; }
47
48 bool IsValid() const override { return true; }
49
50 const std::shared_ptr<const impeller::Capabilities>& GetCapabilities()
51 const override {
53 }
54
58
59 std::shared_ptr<impeller::Allocator> GetResourceAllocator() const override {
61 }
62
63 std::shared_ptr<impeller::ShaderLibrary> GetShaderLibrary() const override {
65 }
66
67 std::shared_ptr<impeller::SamplerLibrary> GetSamplerLibrary() const override {
69 }
70
71 std::shared_ptr<impeller::PipelineLibrary> GetPipelineLibrary()
72 const override {
74 }
75
76 std::shared_ptr<impeller::CommandBuffer> CreateCommandBuffer()
77 const override {
79 }
80
81 std::shared_ptr<impeller::CommandQueue> GetCommandQueue() const override {
83 }
84
85 void Shutdown() override { did_shutdown = true; }
86
87 bool did_shutdown = false;
88};
89
91 public:
92 TestAndroidContext(const std::shared_ptr<impeller::Context>& impeller_context,
93 AndroidRenderingAPI rendering_api)
94 : AndroidContext(rendering_api) {
95 SetImpellerContext(impeller_context);
96 }
97};
98
99TEST(AndroidContextGl, Create) {
100 GrMockOptions main_context_options;
101 sk_sp<GrDirectContext> main_context =
102 GrDirectContext::MakeMock(&main_context_options);
103 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
104 std::string thread_label =
105 ::testing::UnitTest::GetInstance()->current_test_info()->name();
106
110 TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
111 auto context =
112 std::make_unique<AndroidContextGLSkia>(environment, task_runners, 0);
113 context->SetMainSkiaContext(main_context);
114 EXPECT_NE(context.get(), nullptr);
115 context.reset();
116 EXPECT_TRUE(main_context->abandoned());
117}
118
119TEST(AndroidContextGl, CreateImpeller) {
120 auto impeller_context = std::make_shared<TestImpellerContext>();
121 auto android_context = std::make_unique<TestAndroidContext>(
123 EXPECT_FALSE(impeller_context->did_shutdown);
124
125 android_context.reset();
126
127 EXPECT_TRUE(impeller_context->did_shutdown);
128}
129
130TEST(AndroidContextGl, CreateSingleThread) {
131 GrMockOptions main_context_options;
132 sk_sp<GrDirectContext> main_context =
133 GrDirectContext::MakeMock(&main_context_options);
134 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
135 std::string thread_label =
136 ::testing::UnitTest::GetInstance()->current_test_info()->name();
138 fml::RefPtr<fml::TaskRunner> platform_runner =
140 TaskRunners task_runners =
141 TaskRunners(thread_label, platform_runner, platform_runner,
142 platform_runner, platform_runner);
143 auto context =
144 std::make_unique<AndroidContextGLSkia>(environment, task_runners, 0);
145 context->SetMainSkiaContext(main_context);
146 EXPECT_NE(context.get(), nullptr);
147 context.reset();
148 EXPECT_TRUE(main_context->abandoned());
149}
150
151TEST(AndroidSurfaceGL, CreateSnapshopSurfaceWhenOnscreenSurfaceIsNotNull) {
152 GrMockOptions main_context_options;
153 sk_sp<GrDirectContext> main_context =
154 GrDirectContext::MakeMock(&main_context_options);
155 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
156 std::string thread_label =
157 ::testing::UnitTest::GetInstance()->current_test_info()->name();
161 TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
162 auto android_context =
163 std::make_shared<AndroidContextGLSkia>(environment, task_runners, 0);
164 auto android_surface =
165 std::make_unique<AndroidSurfaceGLSkia>(android_context);
166 auto window = fml::MakeRefCounted<AndroidNativeWindow>(
167 nullptr, /*is_fake_window=*/true);
168 android_surface->SetNativeWindow(window);
169 auto onscreen_surface = android_surface->GetOnscreenSurface();
170 EXPECT_NE(onscreen_surface, nullptr);
171 android_surface->CreateSnapshotSurface();
172 EXPECT_EQ(onscreen_surface, android_surface->GetOnscreenSurface());
173}
174
175TEST(AndroidSurfaceGL, CreateSnapshopSurfaceWhenOnscreenSurfaceIsNull) {
176 GrMockOptions main_context_options;
177 sk_sp<GrDirectContext> main_context =
178 GrDirectContext::MakeMock(&main_context_options);
179 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
180 std::string thread_label =
181 ::testing::UnitTest::GetInstance()->current_test_info()->name();
182
183 auto mask =
186
187 ThreadHost thread_host(host_config);
188 TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
189 auto android_context =
190 std::make_shared<AndroidContextGLSkia>(environment, task_runners, 0);
191 auto android_surface =
192 std::make_unique<AndroidSurfaceGLSkia>(android_context);
193 EXPECT_EQ(android_surface->GetOnscreenSurface(), nullptr);
194 android_surface->CreateSnapshotSurface();
195 EXPECT_NE(android_surface->GetOnscreenSurface(), nullptr);
196}
197
198// TODO(https://github.com/flutter/flutter/issues/104463): Flaky test.
199TEST(AndroidContextGl, DISABLED_MSAAx4) {
200 GrMockOptions main_context_options;
201 sk_sp<GrDirectContext> main_context =
202 GrDirectContext::MakeMock(&main_context_options);
203 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
204 std::string thread_label =
205 ::testing::UnitTest::GetInstance()->current_test_info()->name();
206
210 TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
211 auto context =
212 std::make_unique<AndroidContextGLSkia>(environment, task_runners, 4);
213 context->SetMainSkiaContext(main_context);
214
215 EGLint sample_count;
216 eglGetConfigAttrib(environment->Display(), context->Config(), EGL_SAMPLES,
217 &sample_count);
218 EXPECT_EQ(sample_count, 4);
219}
220
221TEST(AndroidContextGl, EnsureMakeCurrentChecksCurrentContextStatus) {
222 GrMockOptions main_context_options;
223 sk_sp<GrDirectContext> main_context =
224 GrDirectContext::MakeMock(&main_context_options);
225 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
226 std::string thread_label =
227 ::testing::UnitTest::GetInstance()->current_test_info()->name();
228
232 TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
233 auto context =
234 std::make_unique<AndroidContextGLSkia>(environment, task_runners, 0);
235
236 auto pbuffer_surface = context->CreatePbufferSurface();
237 auto status = pbuffer_surface->MakeCurrent();
239
240 // context already current, so status must reflect that.
241 status = pbuffer_surface->MakeCurrent();
243}
244} // namespace android
245} // namespace testing
246} // namespace flutter
#define TEST(S, s, D, expected)
static sk_sp< Effect > Create()
static sk_sp< GrDirectContext > MakeMock(const GrMockOptions *, const GrContextOptions &)
Holds state that is shared across Android surfaces.
void SetImpellerContext(const std::shared_ptr< impeller::Context > &context)
TestAndroidContext(const std::shared_ptr< impeller::Context > &impeller_context, AndroidRenderingAPI rendering_api)
bool UpdateOffscreenLayerPixelFormat(impeller::PixelFormat format) override
std::shared_ptr< impeller::CommandBuffer > CreateCommandBuffer() const override
Create a new command buffer. Command buffers can be used to encode graphics, blit,...
const std::shared_ptr< const impeller::Capabilities > & GetCapabilities() const override
Get the capabilities of Impeller context. All optionally supported feature of the platform,...
impeller::Context::BackendType GetBackendType() const override
Get the graphics backend of an Impeller context.
std::shared_ptr< impeller::SamplerLibrary > GetSamplerLibrary() const override
Returns the library of combined image samplers used in shaders.
void Shutdown() override
Force all pending asynchronous work to finish. This is achieved by deleting all owned concurrent mess...
std::shared_ptr< impeller::ShaderLibrary > GetShaderLibrary() const override
Returns the library of shaders used to specify the programmable stages of a pipeline.
std::shared_ptr< impeller::PipelineLibrary > GetPipelineLibrary() const override
Returns the library of pipelines used by render or compute commands.
std::shared_ptr< impeller::CommandQueue > GetCommandQueue() const override
Return the graphics queue for submitting command buffers.
std::shared_ptr< impeller::Allocator > GetResourceAllocator() const override
Returns the allocator used to create textures and buffers on the device.
bool IsValid() const override
Determines if a context is valid. If the caller ever receives an invalid context, they must discard i...
static void EnsureInitializedForCurrentThread()
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
To do anything rendering related with Impeller, you need a context.
Definition context.h:46
GLFWwindow * window
Definition main.cc:45
#define FML_UNREACHABLE()
Definition logging.h:109
AndroidRenderingAPI
Definition settings.h:26
@ kSuccessMadeCurrent
Success, the egl context for the surface made current.
@ kSuccessAlreadyCurrent
Success, the egl context for the surface was already current.
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent Remove all existing persistent cache This is mainly for debugging purposes such as reproducing the shader compilation jank trace to Write the timeline trace to a file at the specified path The file will be in Perfetto s proto format
Definition switches.h:203
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition formats.h:100
The collection of all the threads used by the engine.
Definition thread_host.h:21
std::unique_ptr< fml::Thread > io_thread
Definition thread_host.h:86
std::unique_ptr< fml::Thread > raster_thread
Definition thread_host.h:85
std::unique_ptr< fml::Thread > ui_thread
Definition thread_host.h:84
#define EXPECT_TRUE(handle)
Definition unit_test.h:685