5#define FML_USED_ON_EMBEDDER
14#include "gmock/gmock.h"
15#include "gtest/gtest.h"
18#include "third_party/skia/include/gpu/ganesh/mock/GrMockTypes.h"
25TaskRunners MakeTaskRunners(
const std::string& thread_label,
50 bool IsValid()
const override {
return true; }
104 :
AndroidContext(rendering_api), impeller_context_(impeller_context) {
109 std::shared_ptr<impeller::Context> impeller_context_;
112TEST(AndroidContextGl, Create) {
113 GrMockOptions main_context_options;
114 sk_sp<GrDirectContext> main_context =
115 GrDirectContext::MakeMock(&main_context_options);
116 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
117 std::string thread_label =
118 ::testing::UnitTest::GetInstance()->current_test_info()->name();
123 TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
125 std::make_unique<AndroidContextGLSkia>(environment, task_runners);
126 context->SetMainSkiaContext(main_context);
127 EXPECT_NE(context.get(),
nullptr);
129 EXPECT_TRUE(main_context->abandoned());
132TEST(AndroidContextGl, CreateImpeller) {
133 auto impeller_context = std::make_shared<TestImpellerContext>();
134 auto android_context = std::make_unique<TestAndroidContext>(
136 EXPECT_FALSE(impeller_context->did_shutdown);
138 android_context.reset();
140 EXPECT_TRUE(impeller_context->did_shutdown);
143TEST(AndroidContextGl, CreateSingleThread) {
144 GrMockOptions main_context_options;
145 sk_sp<GrDirectContext> main_context =
146 GrDirectContext::MakeMock(&main_context_options);
147 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
148 std::string thread_label =
149 ::testing::UnitTest::GetInstance()->current_test_info()->name();
154 TaskRunners(thread_label, platform_runner, platform_runner,
155 platform_runner, platform_runner);
157 std::make_unique<AndroidContextGLSkia>(environment, task_runners);
158 context->SetMainSkiaContext(main_context);
159 EXPECT_NE(context.get(),
nullptr);
161 EXPECT_TRUE(main_context->abandoned());
164TEST(AndroidSurfaceGL, CreateSnapshopSurfaceWhenOnscreenSurfaceIsNotNull) {
165 GrMockOptions main_context_options;
166 sk_sp<GrDirectContext> main_context =
167 GrDirectContext::MakeMock(&main_context_options);
168 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
169 std::string thread_label =
170 ::testing::UnitTest::GetInstance()->current_test_info()->name();
174 TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
175 auto android_context =
176 std::make_shared<AndroidContextGLSkia>(environment, task_runners);
177 auto android_surface =
178 std::make_unique<AndroidSurfaceGLSkia>(android_context);
179 auto window = fml::MakeRefCounted<AndroidNativeWindow>(
181 android_surface->SetNativeWindow(
window,
nullptr);
182 auto onscreen_surface = android_surface->GetOnscreenSurface();
183 EXPECT_NE(onscreen_surface,
nullptr);
184 android_surface->CreateSnapshotSurface();
185 EXPECT_EQ(onscreen_surface, android_surface->GetOnscreenSurface());
188TEST(AndroidSurfaceGL, CreateSnapshopSurfaceWhenOnscreenSurfaceIsNull) {
189 GrMockOptions main_context_options;
190 sk_sp<GrDirectContext> main_context =
191 GrDirectContext::MakeMock(&main_context_options);
192 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
193 std::string thread_label =
194 ::testing::UnitTest::GetInstance()->current_test_info()->name();
201 TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
202 auto android_context =
203 std::make_shared<AndroidContextGLSkia>(environment, task_runners);
204 auto android_surface =
205 std::make_unique<AndroidSurfaceGLSkia>(android_context);
206 EXPECT_EQ(android_surface->GetOnscreenSurface(),
nullptr);
207 android_surface->CreateSnapshotSurface();
208 EXPECT_NE(android_surface->GetOnscreenSurface(),
nullptr);
211TEST(AndroidContextGl, EnsureMakeCurrentChecksCurrentContextStatus) {
212 GrMockOptions main_context_options;
213 sk_sp<GrDirectContext> main_context =
214 GrDirectContext::MakeMock(&main_context_options);
215 auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>();
216 std::string thread_label =
217 ::testing::UnitTest::GetInstance()->current_test_info()->name();
222 TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
224 std::make_unique<AndroidContextGLSkia>(environment, task_runners);
226 auto pbuffer_surface = context->CreatePbufferSurface();
227 auto status = pbuffer_surface->MakeCurrent();
231 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,...
bool FinishQueue() override
Wait until all previously submitted command buffers are processed and displayed by the GPU.
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