From fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:14:29 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- gfx/ipc/CanvasManagerChild.cpp | 65 ++++++++++++------------------------------ 1 file changed, 19 insertions(+), 46 deletions(-) (limited to 'gfx/ipc/CanvasManagerChild.cpp') diff --git a/gfx/ipc/CanvasManagerChild.cpp b/gfx/ipc/CanvasManagerChild.cpp index eca803bc4b..dee232b6b1 100644 --- a/gfx/ipc/CanvasManagerChild.cpp +++ b/gfx/ipc/CanvasManagerChild.cpp @@ -10,6 +10,7 @@ #include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerRef.h" #include "mozilla/gfx/2D.h" +#include "mozilla/gfx/CanvasShutdownManager.h" #include "mozilla/gfx/Swizzle.h" #include "mozilla/ipc/Endpoint.h" #include "mozilla/layers/ActiveResource.h" @@ -30,7 +31,10 @@ MOZ_THREAD_LOCAL(CanvasManagerChild*) CanvasManagerChild::sLocalManager; Atomic CanvasManagerChild::sNextId(1); -CanvasManagerChild::CanvasManagerChild(uint32_t aId) : mId(aId) {} +CanvasManagerChild::CanvasManagerChild(ThreadSafeWorkerRef* aWorkerRef, + uint32_t aId) + : mWorkerRef(aWorkerRef), mId(aId) {} + CanvasManagerChild::~CanvasManagerChild() = default; void CanvasManagerChild::ActorDestroy(ActorDestroyReason aReason) { @@ -42,11 +46,6 @@ void CanvasManagerChild::ActorDestroy(ActorDestroyReason aReason) { } void CanvasManagerChild::DestroyInternal() { - std::set activeCanvas = std::move(mActiveCanvas); - for (const auto& i : activeCanvas) { - i->OnShutdown(); - } - if (mActiveResourceTracker) { mActiveResourceTracker->AgeAllGenerations(); mActiveResourceTracker.reset(); @@ -56,6 +55,10 @@ void CanvasManagerChild::DestroyInternal() { mCanvasChild->Destroy(); mCanvasChild = nullptr; } + + if (auto* shutdownManager = CanvasShutdownManager::Get()) { + shutdownManager->OnRemoteCanvasLost(); + } } void CanvasManagerChild::Destroy() { @@ -67,12 +70,6 @@ void CanvasManagerChild::Destroy() { } /* static */ void CanvasManagerChild::Shutdown() { - MOZ_ASSERT(NS_IsMainThread()); - - // The worker threads should destroy their own CanvasManagerChild instances - // during their shutdown sequence. We just need to take care of the main - // thread. We need to init here because we may have never created a - // CanvasManagerChild for the main thread in the first place. if (sLocalManager.init()) { RefPtr manager = sLocalManager.get(); if (manager) { @@ -103,6 +100,11 @@ void CanvasManagerChild::Destroy() { return managerWeak; } + auto* shutdownManager = CanvasShutdownManager::Get(); + if (NS_WARN_IF(!shutdownManager)) { + return nullptr; + } + // We are only used on the main thread, or on worker threads. WorkerPrivate* worker = GetCurrentThreadWorkerPrivate(); MOZ_ASSERT_IF(!worker, NS_IsMainThread()); @@ -121,29 +123,8 @@ void CanvasManagerChild::Destroy() { return nullptr; } - auto manager = MakeRefPtr(sNextId++); - - if (worker) { - // The ThreadSafeWorkerRef will let us know when the worker is shutting - // down. This will let us clear our threadlocal reference and close the - // actor. We rely upon an explicit shutdown for the main thread. - RefPtr workerRef = StrongWorkerRef::Create( - worker, "CanvasManager", [manager]() { manager->Destroy(); }); - if (NS_WARN_IF(!workerRef)) { - return nullptr; - } - - manager->mWorkerRef = new ThreadSafeWorkerRef(workerRef); - } else if (NS_IsMainThread()) { - if (NS_WARN_IF( - AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed))) { - return nullptr; - } - } else { - MOZ_ASSERT_UNREACHABLE("Can only be used on main or DOM worker threads!"); - return nullptr; - } - + auto manager = MakeRefPtr(shutdownManager->GetWorkerRef(), + sNextId++); if (NS_WARN_IF(!childEndpoint.Bind(manager))) { return nullptr; } @@ -163,6 +144,7 @@ void CanvasManagerChild::Destroy() { } manager->SendInitialize(manager->Id()); + shutdownManager->OnRemoteCanvasRestored(); sLocalManager.set(manager); return manager; } @@ -175,16 +157,6 @@ void CanvasManagerChild::Destroy() { return sLocalManager.get(); } -void CanvasManagerChild::AddShutdownObserver( - dom::CanvasRenderingContext2D* aCanvas) { - mActiveCanvas.insert(aCanvas); -} - -void CanvasManagerChild::RemoveShutdownObserver( - dom::CanvasRenderingContext2D* aCanvas) { - mActiveCanvas.erase(aCanvas); -} - void CanvasManagerChild::EndCanvasTransaction() { if (!mCanvasChild) { return; @@ -224,8 +196,9 @@ RefPtr CanvasManagerChild::GetCanvasChild() { } if (!mCanvasChild) { - mCanvasChild = MakeAndAddRef(); + mCanvasChild = MakeAndAddRef(mWorkerRef); if (!SendPCanvasConstructor(mCanvasChild)) { + mCanvasChild->Destroy(); mCanvasChild = nullptr; } } -- cgit v1.2.3