5#define FML_USED_ON_EMBEDDER
14#include "gmock/gmock.h"
15#include "gtest/gtest.h"
24TaskRunners MakeTaskRunners(
const std::string& thread_label,
49 bool IsValid()
const override {
return true; }
99 :
AndroidContext(rendering_api), impeller_context_(impeller_context) {
104 std::shared_ptr<impeller::Context> impeller_context_;
107TEST(AndroidContextGl, Create) {
108 GrMockOptions main_context_options;
109 sk_sp<GrDirectContext> main_context =
110 GrDirectContext::MakeMock(&main_context_options);
111 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
112 std::string thread_label =
113 ::testing::UnitTest::GetInstance()->current_test_info()->name();
118 TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
120 std::make_unique<AndroidContextGLSkia>(environment, task_runners);
121 context->SetMainSkiaContext(main_context);
122 EXPECT_NE(context.get(),
nullptr);
124 EXPECT_TRUE(main_context->abandoned());
127TEST(AndroidContextGl, CreateImpeller) {
128 auto impeller_context = std::make_shared<TestImpellerContext>();
129 auto android_context = std::make_unique<TestAndroidContext>(
131 EXPECT_FALSE(impeller_context->did_shutdown);
133 android_context.reset();
135 EXPECT_TRUE(impeller_context->did_shutdown);
138TEST(AndroidContextGl, CreateSingleThread) {
139 GrMockOptions main_context_options;
140 sk_sp<GrDirectContext> main_context =
141 GrDirectContext::MakeMock(&main_context_options);
142 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
143 std::string thread_label =
144 ::testing::UnitTest::GetInstance()->current_test_info()->name();
149 TaskRunners(thread_label, platform_runner, platform_runner,
150 platform_runner, platform_runner);
152 std::make_unique<AndroidContextGLSkia>(environment, task_runners);
153 context->SetMainSkiaContext(main_context);
154 EXPECT_NE(context.get(),
nullptr);
156 EXPECT_TRUE(main_context->abandoned());
159TEST(AndroidSurfaceGL, CreateSnapshopSurfaceWhenOnscreenSurfaceIsNotNull) {
160 GrMockOptions main_context_options;
161 sk_sp<GrDirectContext> main_context =
162 GrDirectContext::MakeMock(&main_context_options);
163 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
164 std::string thread_label =
165 ::testing::UnitTest::GetInstance()->current_test_info()->name();
169 TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
170 auto android_context =
171 std::make_shared<AndroidContextGLSkia>(environment, task_runners);
172 auto android_surface =
173 std::make_unique<AndroidSurfaceGLSkia>(android_context);
174 auto window = fml::MakeRefCounted<AndroidNativeWindow>(
176 android_surface->SetNativeWindow(
window,
nullptr);
177 auto onscreen_surface = android_surface->GetOnscreenSurface();
178 EXPECT_NE(onscreen_surface,
nullptr);
179 android_surface->CreateSnapshotSurface();
180 EXPECT_EQ(onscreen_surface, android_surface->GetOnscreenSurface());
183TEST(AndroidSurfaceGL, CreateSnapshopSurfaceWhenOnscreenSurfaceIsNull) {
184 GrMockOptions main_context_options;
185 sk_sp<GrDirectContext> main_context =
186 GrDirectContext::MakeMock(&main_context_options);
187 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
188 std::string thread_label =
189 ::testing::UnitTest::GetInstance()->current_test_info()->name();
196 TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
197 auto android_context =
198 std::make_shared<AndroidContextGLSkia>(environment, task_runners);
199 auto android_surface =
200 std::make_unique<AndroidSurfaceGLSkia>(android_context);
201 EXPECT_EQ(android_surface->GetOnscreenSurface(),
nullptr);
202 android_surface->CreateSnapshotSurface();
203 EXPECT_NE(android_surface->GetOnscreenSurface(),
nullptr);
206TEST(AndroidContextGl, EnsureMakeCurrentChecksCurrentContextStatus) {
207 GrMockOptions main_context_options;
208 sk_sp<GrDirectContext> main_context =
209 GrDirectContext::MakeMock(&main_context_options);
210 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
211 std::string thread_label =
212 ::testing::UnitTest::GetInstance()->current_test_info()->name();
217 TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
219 std::make_unique<AndroidContextGLSkia>(environment, task_runners);
221 auto pbuffer_surface = context->CreatePbufferSurface();
222 auto status = pbuffer_surface->MakeCurrent();
226 status = pbuffer_surface->MakeCurrent();
Holds state that is shared across Android surfaces.
void SetImpellerContext(const std::shared_ptr< impeller::Context > &impeller_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.
impeller::RuntimeStageBackend GetRuntimeStageBackend() const override
Retrieve the runtime stage for this context type.
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.
#define FML_UNREACHABLE()
TEST(AndroidContextGl, Create)
@ kSuccessMadeCurrent
Success, the egl context for the surface made current.
@ kSuccessAlreadyCurrent
Success, the egl context for the surface was already current.
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