Detach the resource context before shutting down the IO thread (flutter/engine#6009)

This commit is contained in:
Jason Simmons
2018-08-14 13:15:42 -07:00
committed by GitHub
parent ec9e81e29d
commit c761e6e2a0
11 changed files with 46 additions and 5 deletions

View File

@@ -73,6 +73,8 @@ sk_sp<GrContext> PlatformView::CreateResourceContext() const {
return nullptr;
}
void PlatformView::ReleaseResourceContext() const {}
fml::WeakPtr<PlatformView> PlatformView::GetWeakPtr() const {
return weak_factory_.GetWeakPtr();
}

View File

@@ -88,6 +88,10 @@ class PlatformView {
// non-platform task runner.
virtual sk_sp<GrContext> CreateResourceContext() const;
// Unlike all other methods on the platform view, this one may be called on a
// non-platform task runner.
virtual void ReleaseResourceContext() const;
fml::WeakPtr<PlatformView> GetWeakPtr() const;
virtual void UpdateSemantics(blink::SemanticsNodeUpdates updates,

View File

@@ -314,11 +314,15 @@ Shell::~Shell() {
fml::TaskRunner::RunNowOrPostTask(
task_runners_.GetIOTaskRunner(),
fml::MakeCopyable(
[io_manager = std::move(io_manager_), &io_latch]() mutable {
io_manager.reset();
io_latch.Signal();
}));
fml::MakeCopyable([io_manager = std::move(io_manager_),
platform_view = platform_view_.get(),
&io_latch]() mutable {
io_manager.reset();
if (platform_view) {
platform_view->ReleaseResourceContext();
}
io_latch.Signal();
}));
io_latch.Wait();

View File

@@ -33,6 +33,8 @@ class AndroidSurface {
virtual bool ResourceContextMakeCurrent() = 0;
virtual bool ResourceContextClearCurrent() = 0;
virtual bool SetNativeWindow(fml::RefPtr<AndroidNativeWindow> window) = 0;
};

View File

@@ -82,6 +82,11 @@ bool AndroidSurfaceGL::ResourceContextMakeCurrent() {
return offscreen_context_->MakeCurrent();
}
bool AndroidSurfaceGL::ResourceContextClearCurrent() {
FML_DCHECK(offscreen_context_ && offscreen_context_->IsValid());
return offscreen_context_->ClearCurrent();
}
bool AndroidSurfaceGL::SetNativeWindow(
fml::RefPtr<AndroidNativeWindow> window) {
// In any case, we want to get rid of our current onscreen context.

View File

@@ -40,6 +40,9 @@ class AndroidSurfaceGL final : public GPUSurfaceGLDelegate,
// |shell::AndroidSurface|
bool ResourceContextMakeCurrent() override;
// |shell::AndroidSurface|
bool ResourceContextClearCurrent() override;
// |shell::AndroidSurface|
bool SetNativeWindow(fml::RefPtr<AndroidNativeWindow> window) override;

View File

@@ -52,6 +52,10 @@ bool AndroidSurfaceSoftware::ResourceContextMakeCurrent() {
return false;
}
bool AndroidSurfaceSoftware::ResourceContextClearCurrent() {
return false;
}
std::unique_ptr<Surface> AndroidSurfaceSoftware::CreateGPUSurface() {
if (!IsValid()) {
return nullptr;

View File

@@ -26,6 +26,9 @@ class AndroidSurfaceSoftware final : public AndroidSurface,
// |shell::AndroidSurface|
bool ResourceContextMakeCurrent() override;
// |shell::AndroidSurface|
bool ResourceContextClearCurrent() override;
// |shell::AndroidSurface|
std::unique_ptr<Surface> CreateGPUSurface() override;

View File

@@ -65,6 +65,10 @@ bool AndroidSurfaceVulkan::ResourceContextMakeCurrent() {
return false;
}
bool AndroidSurfaceVulkan::ResourceContextClearCurrent() {
return false;
}
// |shell::AndroidSurface|
bool AndroidSurfaceVulkan::SetNativeWindow(
fml::RefPtr<AndroidNativeWindow> window) {

View File

@@ -385,6 +385,13 @@ sk_sp<GrContext> PlatformViewAndroid::CreateResourceContext() const {
return resource_context;
}
// |shell::PlatformView|
void PlatformViewAndroid::ReleaseResourceContext() const {
if (android_surface_) {
android_surface_->ResourceContextClearCurrent();
}
}
void PlatformViewAndroid::InstallFirstFrameCallback() {
// On Platform Task Runner.
SetNextFrameCallback(

View File

@@ -102,6 +102,9 @@ class PlatformViewAndroid final : public PlatformView {
// |shell::PlatformView|
sk_sp<GrContext> CreateResourceContext() const override;
// |shell::PlatformView|
void ReleaseResourceContext() const override;
void InstallFirstFrameCallback();
void FireFirstFrameCallback();