[Impeller] call shutdown method in Android context. (flutter/engine#49992)
The Impeller context requires us to call Shutdown to ensure that all of its spawned worker threads are joined, ensuring that the raster thread retains the last reference. Without this, we may either destroy parts of the context to early, or attempt to join into a worker thread which will fail.
This commit is contained in:
@@ -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<const impeller::Capabilities>& GetCapabilities()
|
||||
const override {
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
bool UpdateOffscreenLayerPixelFormat(impeller::PixelFormat format) override {
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
std::shared_ptr<impeller::Allocator> GetResourceAllocator() const override {
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
std::shared_ptr<impeller::ShaderLibrary> GetShaderLibrary() const override {
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
std::shared_ptr<impeller::SamplerLibrary> GetSamplerLibrary() const override {
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
std::shared_ptr<impeller::PipelineLibrary> GetPipelineLibrary()
|
||||
const override {
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
std::shared_ptr<impeller::CommandBuffer> 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>& impeller_context,
|
||||
AndroidRenderingAPI rendering_api)
|
||||
: AndroidContext(rendering_api) {
|
||||
SetImpellerContext(impeller_context);
|
||||
}
|
||||
};
|
||||
|
||||
TEST(AndroidContextGl, Create) {
|
||||
GrMockOptions main_context_options;
|
||||
sk_sp<GrDirectContext> main_context =
|
||||
@@ -47,6 +108,17 @@ TEST(AndroidContextGl, Create) {
|
||||
EXPECT_TRUE(main_context->abandoned());
|
||||
}
|
||||
|
||||
TEST(AndroidContextGl, CreateImpeller) {
|
||||
auto impeller_context = std::make_shared<TestImpellerContext>();
|
||||
auto android_context = std::make_unique<TestAndroidContext>(
|
||||
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<GrDirectContext> main_context =
|
||||
|
||||
@@ -13,6 +13,9 @@ AndroidContext::~AndroidContext() {
|
||||
if (main_context_) {
|
||||
main_context_->releaseResourcesAndAbandonContext();
|
||||
}
|
||||
if (impeller_context_) {
|
||||
impeller_context_->Shutdown();
|
||||
}
|
||||
};
|
||||
|
||||
AndroidRenderingAPI AndroidContext::RenderingApi() const {
|
||||
|
||||
Reference in New Issue
Block a user