diff --git a/engine/src/flutter/shell/platform/android/android_context_gl_unittests.cc b/engine/src/flutter/shell/platform/android/android_context_gl_unittests.cc index e1ee5ec89e..859a1d3100 100644 --- a/engine/src/flutter/shell/platform/android/android_context_gl_unittests.cc +++ b/engine/src/flutter/shell/platform/android/android_context_gl_unittests.cc @@ -6,8 +6,10 @@ #include "flutter/shell/platform/android/android_egl_surface.h" #include "flutter/shell/platform/android/android_environment_gl.h" #include "flutter/shell/platform/android/android_surface_gl_skia.h" +#include "fml/logging.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "shell/platform/android/context/android_context.h" namespace flutter { namespace testing { @@ -27,6 +29,65 @@ TaskRunners MakeTaskRunners(const std::string& thread_label, } } // namespace +class TestImpellerContext : public impeller::Context { + public: + TestImpellerContext() {} + + ~TestImpellerContext() {} + + impeller::Context::BackendType GetBackendType() const override { + return impeller::Context::BackendType::kOpenGLES; + } + + std::string DescribeGpuModel() const override { return ""; } + + bool IsValid() const override { return true; } + + const std::shared_ptr& GetCapabilities() + const override { + FML_UNREACHABLE(); + } + + bool UpdateOffscreenLayerPixelFormat(impeller::PixelFormat format) override { + FML_UNREACHABLE(); + } + + std::shared_ptr GetResourceAllocator() const override { + FML_UNREACHABLE(); + } + + std::shared_ptr GetShaderLibrary() const override { + FML_UNREACHABLE(); + } + + std::shared_ptr GetSamplerLibrary() const override { + FML_UNREACHABLE(); + } + + std::shared_ptr GetPipelineLibrary() + const override { + FML_UNREACHABLE(); + } + + std::shared_ptr CreateCommandBuffer() + const override { + FML_UNREACHABLE(); + } + + void Shutdown() override { did_shutdown = true; } + + bool did_shutdown = false; +}; + +class TestAndroidContext : public AndroidContext { + public: + TestAndroidContext(const std::shared_ptr& impeller_context, + AndroidRenderingAPI rendering_api) + : AndroidContext(rendering_api) { + SetImpellerContext(impeller_context); + } +}; + TEST(AndroidContextGl, Create) { GrMockOptions main_context_options; sk_sp main_context = @@ -47,6 +108,17 @@ TEST(AndroidContextGl, Create) { EXPECT_TRUE(main_context->abandoned()); } +TEST(AndroidContextGl, CreateImpeller) { + auto impeller_context = std::make_shared(); + auto android_context = std::make_unique( + impeller_context, AndroidRenderingAPI::kOpenGLES); + EXPECT_FALSE(impeller_context->did_shutdown); + + android_context.reset(); + + EXPECT_TRUE(impeller_context->did_shutdown); +} + TEST(AndroidContextGl, CreateSingleThread) { GrMockOptions main_context_options; sk_sp main_context = diff --git a/engine/src/flutter/shell/platform/android/context/android_context.cc b/engine/src/flutter/shell/platform/android/context/android_context.cc index 3d7c4e619d..ed0970cb73 100644 --- a/engine/src/flutter/shell/platform/android/context/android_context.cc +++ b/engine/src/flutter/shell/platform/android/context/android_context.cc @@ -13,6 +13,9 @@ AndroidContext::~AndroidContext() { if (main_context_) { main_context_->releaseResourcesAndAbandonContext(); } + if (impeller_context_) { + impeller_context_->Shutdown(); + } }; AndroidRenderingAPI AndroidContext::RenderingApi() const {