diff --git a/shell/common/platform_view.cc b/shell/common/platform_view.cc index 69c404bffb261..76c01dca9cef0 100644 --- a/shell/common/platform_view.cc +++ b/shell/common/platform_view.cc @@ -73,6 +73,8 @@ sk_sp PlatformView::CreateResourceContext() const { return nullptr; } +void PlatformView::ReleaseResourceContext() const {} + fml::WeakPtr PlatformView::GetWeakPtr() const { return weak_factory_.GetWeakPtr(); } diff --git a/shell/common/platform_view.h b/shell/common/platform_view.h index b727ad7179006..153cae71d53a0 100644 --- a/shell/common/platform_view.h +++ b/shell/common/platform_view.h @@ -88,6 +88,10 @@ class PlatformView { // non-platform task runner. virtual sk_sp 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 GetWeakPtr() const; virtual void UpdateSemantics(blink::SemanticsNodeUpdates updates, diff --git a/shell/common/shell.cc b/shell/common/shell.cc index fb6df3f6958bb..5017a2c6078fa 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -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(); diff --git a/shell/platform/android/android_surface.h b/shell/platform/android/android_surface.h index fc376971b984e..e0a413c1e0dc2 100644 --- a/shell/platform/android/android_surface.h +++ b/shell/platform/android/android_surface.h @@ -33,6 +33,8 @@ class AndroidSurface { virtual bool ResourceContextMakeCurrent() = 0; + virtual bool ResourceContextClearCurrent() = 0; + virtual bool SetNativeWindow(fml::RefPtr window) = 0; }; diff --git a/shell/platform/android/android_surface_gl.cc b/shell/platform/android/android_surface_gl.cc index 730a1e061b6ce..207d2631a0404 100644 --- a/shell/platform/android/android_surface_gl.cc +++ b/shell/platform/android/android_surface_gl.cc @@ -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 window) { // In any case, we want to get rid of our current onscreen context. diff --git a/shell/platform/android/android_surface_gl.h b/shell/platform/android/android_surface_gl.h index 02049146bf7ab..5562523799096 100644 --- a/shell/platform/android/android_surface_gl.h +++ b/shell/platform/android/android_surface_gl.h @@ -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 window) override; diff --git a/shell/platform/android/android_surface_software.cc b/shell/platform/android/android_surface_software.cc index 2335cca995bc8..a577ade5c91fb 100644 --- a/shell/platform/android/android_surface_software.cc +++ b/shell/platform/android/android_surface_software.cc @@ -52,6 +52,10 @@ bool AndroidSurfaceSoftware::ResourceContextMakeCurrent() { return false; } +bool AndroidSurfaceSoftware::ResourceContextClearCurrent() { + return false; +} + std::unique_ptr AndroidSurfaceSoftware::CreateGPUSurface() { if (!IsValid()) { return nullptr; diff --git a/shell/platform/android/android_surface_software.h b/shell/platform/android/android_surface_software.h index 2b14f65f5ae85..6301515ca4254 100644 --- a/shell/platform/android/android_surface_software.h +++ b/shell/platform/android/android_surface_software.h @@ -26,6 +26,9 @@ class AndroidSurfaceSoftware final : public AndroidSurface, // |shell::AndroidSurface| bool ResourceContextMakeCurrent() override; + // |shell::AndroidSurface| + bool ResourceContextClearCurrent() override; + // |shell::AndroidSurface| std::unique_ptr CreateGPUSurface() override; diff --git a/shell/platform/android/android_surface_vulkan.cc b/shell/platform/android/android_surface_vulkan.cc index 33bf9705b747d..f040f19d2ccfc 100644 --- a/shell/platform/android/android_surface_vulkan.cc +++ b/shell/platform/android/android_surface_vulkan.cc @@ -65,6 +65,10 @@ bool AndroidSurfaceVulkan::ResourceContextMakeCurrent() { return false; } +bool AndroidSurfaceVulkan::ResourceContextClearCurrent() { + return false; +} + // |shell::AndroidSurface| bool AndroidSurfaceVulkan::SetNativeWindow( fml::RefPtr window) { diff --git a/shell/platform/android/platform_view_android.cc b/shell/platform/android/platform_view_android.cc index ccd6ccb0cafbe..eea7593e06a18 100644 --- a/shell/platform/android/platform_view_android.cc +++ b/shell/platform/android/platform_view_android.cc @@ -385,6 +385,13 @@ sk_sp 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( diff --git a/shell/platform/android/platform_view_android.h b/shell/platform/android/platform_view_android.h index b82f4474d973c..0a73fed04d5d6 100644 --- a/shell/platform/android/platform_view_android.h +++ b/shell/platform/android/platform_view_android.h @@ -102,6 +102,9 @@ class PlatformViewAndroid final : public PlatformView { // |shell::PlatformView| sk_sp CreateResourceContext() const override; + // |shell::PlatformView| + void ReleaseResourceContext() const override; + void InstallFirstFrameCallback(); void FireFirstFrameCallback();