Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions shell/common/platform_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions shell/common/platform_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 9 additions & 5 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 2 additions & 0 deletions shell/platform/android/android_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class AndroidSurface {

virtual bool ResourceContextMakeCurrent() = 0;

virtual bool ResourceContextClearCurrent() = 0;

virtual bool SetNativeWindow(fml::RefPtr<AndroidNativeWindow> window) = 0;
};

Expand Down
5 changes: 5 additions & 0 deletions shell/platform/android/android_surface_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions shell/platform/android/android_surface_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions shell/platform/android/android_surface_software.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ bool AndroidSurfaceSoftware::ResourceContextMakeCurrent() {
return false;
}

bool AndroidSurfaceSoftware::ResourceContextClearCurrent() {
return false;
}

std::unique_ptr<Surface> AndroidSurfaceSoftware::CreateGPUSurface() {
if (!IsValid()) {
return nullptr;
Expand Down
3 changes: 3 additions & 0 deletions shell/platform/android/android_surface_software.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions shell/platform/android/android_surface_vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ bool AndroidSurfaceVulkan::ResourceContextMakeCurrent() {
return false;
}

bool AndroidSurfaceVulkan::ResourceContextClearCurrent() {
return false;
}

// |shell::AndroidSurface|
bool AndroidSurfaceVulkan::SetNativeWindow(
fml::RefPtr<AndroidNativeWindow> window) {
Expand Down
7 changes: 7 additions & 0 deletions shell/platform/android/platform_view_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions shell/platform/android/platform_view_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down