5#define FML_USED_ON_EMBEDDER
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"
14#include "gmock/gmock.h"
15#include "gtest/gtest.h"
23TaskRunners MakeTaskRunners(
const std::string& thread_label,
48 bool IsValid()
const override {
return true; }
103 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
104 std::string thread_label =
105 ::testing::UnitTest::GetInstance()->current_test_info()->name();
109 ThreadHost::Type::kIo));
110 TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
112 std::make_unique<AndroidContextGLSkia>(
environment, task_runners);
113 context->SetMainSkiaContext(main_context);
114 EXPECT_NE(context.get(),
nullptr);
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);
125 android_context.reset();
130TEST(AndroidContextGl, CreateSingleThread) {
134 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
135 std::string thread_label =
136 ::testing::UnitTest::GetInstance()->current_test_info()->name();
141 TaskRunners(thread_label, platform_runner, platform_runner,
142 platform_runner, platform_runner);
144 std::make_unique<AndroidContextGLSkia>(
environment, task_runners);
145 context->SetMainSkiaContext(main_context);
146 EXPECT_NE(context.get(),
nullptr);
151TEST(AndroidSurfaceGL, CreateSnapshopSurfaceWhenOnscreenSurfaceIsNotNull) {
155 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
156 std::string thread_label =
157 ::testing::UnitTest::GetInstance()->current_test_info()->name();
160 ThreadHost::Type::kIo));
161 TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
162 auto android_context =
163 std::make_shared<AndroidContextGLSkia>(
environment, task_runners);
164 auto android_surface =
165 std::make_unique<AndroidSurfaceGLSkia>(android_context);
166 auto window = fml::MakeRefCounted<AndroidNativeWindow>(
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());
175TEST(AndroidSurfaceGL, CreateSnapshopSurfaceWhenOnscreenSurfaceIsNull) {
179 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
180 std::string thread_label =
181 ::testing::UnitTest::GetInstance()->current_test_info()->name();
188 TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
189 auto android_context =
190 std::make_shared<AndroidContextGLSkia>(
environment, task_runners);
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);
198TEST(AndroidContextGl, EnsureMakeCurrentChecksCurrentContextStatus) {
202 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
203 std::string thread_label =
204 ::testing::UnitTest::GetInstance()->current_test_info()->name();
208 ThreadHost::Type::kIo));
209 TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
211 std::make_unique<AndroidContextGLSkia>(
environment, task_runners);
213 auto pbuffer_surface = context->CreatePbufferSurface();
214 auto status = pbuffer_surface->MakeCurrent();
218 status = pbuffer_surface->MakeCurrent();
static sk_sp< Effect > Create()
static sk_sp< GrDirectContext > MakeMock(const GrMockOptions *, const GrContextOptions &)
bool abandoned() override
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::string DescribeGpuModel() const override
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.
@ kRaster
Suitable for thread which raster data.
#define FML_UNREACHABLE()
static dart::SimpleHashMap * environment
TEST(AndroidContextGl, Create)
@ 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
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
The collection of all the threads used by the engine.
std::unique_ptr< fml::Thread > io_thread
std::unique_ptr< fml::Thread > raster_thread
std::unique_ptr< fml::Thread > ui_thread
#define EXPECT_TRUE(handle)