1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "gfxPlatformWorker.h"
7 #include "mozilla/dom/WorkerCommon.h"
8 #include "mozilla/dom/WorkerRef.h"
9 #include "mozilla/gfx/2D.h"
10 #include "mozilla/ThreadLocal.h"
12 using namespace mozilla
;
13 using namespace mozilla::dom
;
14 using namespace mozilla::gfx
;
16 MOZ_THREAD_LOCAL(gfxPlatformWorker
*) gfxPlatformWorker::sInstance
;
18 /* static */ gfxPlatformWorker
* gfxPlatformWorker::Get() {
19 if (!sInstance
.init()) {
23 gfxPlatformWorker
* instance
= sInstance
.get();
28 WorkerPrivate
* workerPrivate
= GetCurrentThreadWorkerPrivate();
33 RefPtr
<WeakWorkerRef
> workerRef
= WeakWorkerRef::Create(
34 workerPrivate
, []() { gfxPlatformWorker::Shutdown(); });
39 instance
= new gfxPlatformWorker(std::move(workerRef
));
40 sInstance
.set(instance
);
44 /* static */ void gfxPlatformWorker::Shutdown() {
45 if (!sInstance
.init()) {
49 gfxPlatformWorker
* instance
= sInstance
.get();
54 sInstance
.set(nullptr);
58 gfxPlatformWorker::gfxPlatformWorker(RefPtr
<WeakWorkerRef
>&& aWorkerRef
)
59 : mWorkerRef(std::move(aWorkerRef
)) {}
61 gfxPlatformWorker::~gfxPlatformWorker() = default;
63 RefPtr
<mozilla::gfx::DrawTarget
>
64 gfxPlatformWorker::ScreenReferenceDrawTarget() {
65 if (!mScreenReferenceDrawTarget
) {
66 mScreenReferenceDrawTarget
= Factory::CreateDrawTarget(
67 BackendType::SKIA
, IntSize(1, 1), SurfaceFormat::B8G8R8A8
);
69 return mScreenReferenceDrawTarget
;