зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1455256 - Port more components to WorkerRef - part 6 - ImageCanvas, r=asuth
This commit is contained in:
Родитель
4ea7edd9be
Коммит
de57a3fc82
|
@ -12,6 +12,7 @@
|
|||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/StructuredCloneTags.h"
|
||||
#include "mozilla/dom/WorkerPrivate.h"
|
||||
#include "mozilla/dom/WorkerRef.h"
|
||||
#include "mozilla/dom/WorkerRunnable.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/gfx/Swizzle.h"
|
||||
|
@ -1219,7 +1220,6 @@ AsyncFulfillImageBitmapPromise(Promise* aPromise, ImageBitmap* aImageBitmap)
|
|||
}
|
||||
|
||||
class CreateImageBitmapFromBlobRunnable;
|
||||
class CreateImageBitmapFromBlobHolder;
|
||||
|
||||
class CreateImageBitmapFromBlob final : public CancelableRunnable
|
||||
, public imgIContainerCallback
|
||||
|
@ -1249,7 +1249,7 @@ public:
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// Called by the WorkerHolder.
|
||||
// Called by the WorkerRef.
|
||||
void WorkerShuttingDown();
|
||||
|
||||
private:
|
||||
|
@ -1301,7 +1301,7 @@ private:
|
|||
|
||||
// The access to this object is protected by mutex but is always nullified on
|
||||
// the owning thread.
|
||||
UniquePtr<CreateImageBitmapFromBlobHolder> mWorkerHolder;
|
||||
RefPtr<ThreadSafeWorkerRef> mWorkerRef;
|
||||
|
||||
// Touched only on the owning thread.
|
||||
RefPtr<Promise> mPromise;
|
||||
|
@ -1348,39 +1348,6 @@ private:
|
|||
nsresult mStatus;
|
||||
};
|
||||
|
||||
// This class keeps the worker alive and it informs CreateImageBitmapFromBlob
|
||||
// when it goes away.
|
||||
class CreateImageBitmapFromBlobHolder final : public WorkerHolder
|
||||
{
|
||||
public:
|
||||
CreateImageBitmapFromBlobHolder(WorkerPrivate* aWorkerPrivate,
|
||||
CreateImageBitmapFromBlob* aTask)
|
||||
: WorkerHolder("CreateImageBitmapFromBlobHolder")
|
||||
, mWorkerPrivate(aWorkerPrivate)
|
||||
, mTask(aTask)
|
||||
, mNotified(false)
|
||||
{}
|
||||
|
||||
bool Notify(WorkerStatus aStatus) override
|
||||
{
|
||||
if (!mNotified) {
|
||||
mNotified = true;
|
||||
mTask->WorkerShuttingDown();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
WorkerPrivate* GetWorkerPrivate() const
|
||||
{
|
||||
return mWorkerPrivate;
|
||||
}
|
||||
|
||||
private:
|
||||
WorkerPrivate* mWorkerPrivate;
|
||||
RefPtr<CreateImageBitmapFromBlob> mTask;
|
||||
bool mNotified;
|
||||
};
|
||||
|
||||
static void
|
||||
AsyncCreateImageBitmapFromBlob(Promise* aPromise, nsIGlobalObject* aGlobal,
|
||||
Blob& aBlob, const Maybe<IntRect>& aCropRect)
|
||||
|
@ -2204,19 +2171,21 @@ CreateImageBitmapFromBlob::Create(Promise* aPromise,
|
|||
return task.forget();
|
||||
}
|
||||
|
||||
// Let's use a WorkerHolder to keep the worker alive if this is not the
|
||||
// Let's use a WorkerRef to keep the worker alive if this is not the
|
||||
// main-thread.
|
||||
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
||||
MOZ_ASSERT(workerPrivate);
|
||||
|
||||
UniquePtr<CreateImageBitmapFromBlobHolder> holder(
|
||||
new CreateImageBitmapFromBlobHolder(workerPrivate, task));
|
||||
|
||||
if (!holder->HoldWorker(workerPrivate, Terminating)) {
|
||||
RefPtr<StrongWorkerRef> workerRef =
|
||||
StrongWorkerRef::Create(workerPrivate, "CreateImageBitmapFromBlob",
|
||||
[task]() {
|
||||
task->WorkerShuttingDown();
|
||||
});
|
||||
if (NS_WARN_IF(!workerRef)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
task->mWorkerHolder = std::move(holder);
|
||||
task->mWorkerRef = new ThreadSafeWorkerRef(workerRef);
|
||||
return task.forget();
|
||||
}
|
||||
|
||||
|
@ -2339,13 +2308,13 @@ CreateImageBitmapFromBlob::DecodeAndCropBlobCompletedMainThread(layers::Image* a
|
|||
if (!IsCurrentThread()) {
|
||||
MutexAutoLock lock(mMutex);
|
||||
|
||||
if (!mWorkerHolder) {
|
||||
if (!mWorkerRef) {
|
||||
// The worker is already gone.
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<CreateImageBitmapFromBlobRunnable> r =
|
||||
new CreateImageBitmapFromBlobRunnable(mWorkerHolder->GetWorkerPrivate(),
|
||||
new CreateImageBitmapFromBlobRunnable(mWorkerRef->Private(),
|
||||
this, aImage, aStatus);
|
||||
r->Dispatch();
|
||||
return;
|
||||
|
@ -2368,7 +2337,7 @@ CreateImageBitmapFromBlob::DecodeAndCropBlobCompletedOwningThread(layers::Image*
|
|||
// Let's release what has to be released on the owning thread.
|
||||
auto raii = MakeScopeExit([&] {
|
||||
// Doing this we also release the worker.
|
||||
mWorkerHolder = nullptr;
|
||||
mWorkerRef = nullptr;
|
||||
|
||||
mPromise = nullptr;
|
||||
mGlobalObject = nullptr;
|
||||
|
@ -2409,7 +2378,7 @@ CreateImageBitmapFromBlob::WorkerShuttingDown()
|
|||
MutexAutoLock lock(mMutex);
|
||||
|
||||
// Let's release all the non-thread-safe objects now.
|
||||
mWorkerHolder = nullptr;
|
||||
mWorkerRef = nullptr;
|
||||
mPromise = nullptr;
|
||||
mGlobalObject = nullptr;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче