summaryrefslogtreecommitdiffstats
path: root/gfx/ipc/CanvasManagerChild.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/ipc/CanvasManagerChild.cpp')
-rw-r--r--gfx/ipc/CanvasManagerChild.cpp65
1 files changed, 19 insertions, 46 deletions
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<uint32_t> 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<CanvasRenderingContext2D*> 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<CanvasManagerChild> 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<CanvasManagerChild>(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<StrongWorkerRef> 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<CanvasManagerChild>(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<layers::CanvasChild> CanvasManagerChild::GetCanvasChild() {
}
if (!mCanvasChild) {
- mCanvasChild = MakeAndAddRef<layers::CanvasChild>();
+ mCanvasChild = MakeAndAddRef<layers::CanvasChild>(mWorkerRef);
if (!SendPCanvasConstructor(mCanvasChild)) {
+ mCanvasChild->Destroy();
mCanvasChild = nullptr;
}
}