зеркало из 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/Promise.h"
|
||||||
#include "mozilla/dom/StructuredCloneTags.h"
|
#include "mozilla/dom/StructuredCloneTags.h"
|
||||||
#include "mozilla/dom/WorkerPrivate.h"
|
#include "mozilla/dom/WorkerPrivate.h"
|
||||||
|
#include "mozilla/dom/WorkerRef.h"
|
||||||
#include "mozilla/dom/WorkerRunnable.h"
|
#include "mozilla/dom/WorkerRunnable.h"
|
||||||
#include "mozilla/gfx/2D.h"
|
#include "mozilla/gfx/2D.h"
|
||||||
#include "mozilla/gfx/Swizzle.h"
|
#include "mozilla/gfx/Swizzle.h"
|
||||||
|
@ -1219,7 +1220,6 @@ AsyncFulfillImageBitmapPromise(Promise* aPromise, ImageBitmap* aImageBitmap)
|
||||||
}
|
}
|
||||||
|
|
||||||
class CreateImageBitmapFromBlobRunnable;
|
class CreateImageBitmapFromBlobRunnable;
|
||||||
class CreateImageBitmapFromBlobHolder;
|
|
||||||
|
|
||||||
class CreateImageBitmapFromBlob final : public CancelableRunnable
|
class CreateImageBitmapFromBlob final : public CancelableRunnable
|
||||||
, public imgIContainerCallback
|
, public imgIContainerCallback
|
||||||
|
@ -1249,7 +1249,7 @@ public:
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called by the WorkerHolder.
|
// Called by the WorkerRef.
|
||||||
void WorkerShuttingDown();
|
void WorkerShuttingDown();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -1301,7 +1301,7 @@ private:
|
||||||
|
|
||||||
// The access to this object is protected by mutex but is always nullified on
|
// The access to this object is protected by mutex but is always nullified on
|
||||||
// the owning thread.
|
// the owning thread.
|
||||||
UniquePtr<CreateImageBitmapFromBlobHolder> mWorkerHolder;
|
RefPtr<ThreadSafeWorkerRef> mWorkerRef;
|
||||||
|
|
||||||
// Touched only on the owning thread.
|
// Touched only on the owning thread.
|
||||||
RefPtr<Promise> mPromise;
|
RefPtr<Promise> mPromise;
|
||||||
|
@ -1348,39 +1348,6 @@ private:
|
||||||
nsresult mStatus;
|
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
|
static void
|
||||||
AsyncCreateImageBitmapFromBlob(Promise* aPromise, nsIGlobalObject* aGlobal,
|
AsyncCreateImageBitmapFromBlob(Promise* aPromise, nsIGlobalObject* aGlobal,
|
||||||
Blob& aBlob, const Maybe<IntRect>& aCropRect)
|
Blob& aBlob, const Maybe<IntRect>& aCropRect)
|
||||||
|
@ -2204,19 +2171,21 @@ CreateImageBitmapFromBlob::Create(Promise* aPromise,
|
||||||
return task.forget();
|
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.
|
// main-thread.
|
||||||
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
||||||
MOZ_ASSERT(workerPrivate);
|
MOZ_ASSERT(workerPrivate);
|
||||||
|
|
||||||
UniquePtr<CreateImageBitmapFromBlobHolder> holder(
|
RefPtr<StrongWorkerRef> workerRef =
|
||||||
new CreateImageBitmapFromBlobHolder(workerPrivate, task));
|
StrongWorkerRef::Create(workerPrivate, "CreateImageBitmapFromBlob",
|
||||||
|
[task]() {
|
||||||
if (!holder->HoldWorker(workerPrivate, Terminating)) {
|
task->WorkerShuttingDown();
|
||||||
|
});
|
||||||
|
if (NS_WARN_IF(!workerRef)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
task->mWorkerHolder = std::move(holder);
|
task->mWorkerRef = new ThreadSafeWorkerRef(workerRef);
|
||||||
return task.forget();
|
return task.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2339,13 +2308,13 @@ CreateImageBitmapFromBlob::DecodeAndCropBlobCompletedMainThread(layers::Image* a
|
||||||
if (!IsCurrentThread()) {
|
if (!IsCurrentThread()) {
|
||||||
MutexAutoLock lock(mMutex);
|
MutexAutoLock lock(mMutex);
|
||||||
|
|
||||||
if (!mWorkerHolder) {
|
if (!mWorkerRef) {
|
||||||
// The worker is already gone.
|
// The worker is already gone.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<CreateImageBitmapFromBlobRunnable> r =
|
RefPtr<CreateImageBitmapFromBlobRunnable> r =
|
||||||
new CreateImageBitmapFromBlobRunnable(mWorkerHolder->GetWorkerPrivate(),
|
new CreateImageBitmapFromBlobRunnable(mWorkerRef->Private(),
|
||||||
this, aImage, aStatus);
|
this, aImage, aStatus);
|
||||||
r->Dispatch();
|
r->Dispatch();
|
||||||
return;
|
return;
|
||||||
|
@ -2368,7 +2337,7 @@ CreateImageBitmapFromBlob::DecodeAndCropBlobCompletedOwningThread(layers::Image*
|
||||||
// Let's release what has to be released on the owning thread.
|
// Let's release what has to be released on the owning thread.
|
||||||
auto raii = MakeScopeExit([&] {
|
auto raii = MakeScopeExit([&] {
|
||||||
// Doing this we also release the worker.
|
// Doing this we also release the worker.
|
||||||
mWorkerHolder = nullptr;
|
mWorkerRef = nullptr;
|
||||||
|
|
||||||
mPromise = nullptr;
|
mPromise = nullptr;
|
||||||
mGlobalObject = nullptr;
|
mGlobalObject = nullptr;
|
||||||
|
@ -2409,7 +2378,7 @@ CreateImageBitmapFromBlob::WorkerShuttingDown()
|
||||||
MutexAutoLock lock(mMutex);
|
MutexAutoLock lock(mMutex);
|
||||||
|
|
||||||
// Let's release all the non-thread-safe objects now.
|
// Let's release all the non-thread-safe objects now.
|
||||||
mWorkerHolder = nullptr;
|
mWorkerRef = nullptr;
|
||||||
mPromise = nullptr;
|
mPromise = nullptr;
|
||||||
mGlobalObject = nullptr;
|
mGlobalObject = nullptr;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче