Bug 1874684 - Part 28: Return DateDuration from DifferenceISODateTime. r=mgaudet
[gecko.git] / gfx / thebes / gfxPlatformWorker.cpp
blob1a6183236eece19e1057b9eba12db69124c8cdeb
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()) {
20 return nullptr;
23 gfxPlatformWorker* instance = sInstance.get();
24 if (instance) {
25 return instance;
28 WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
29 if (!workerPrivate) {
30 return nullptr;
33 RefPtr<WeakWorkerRef> workerRef = WeakWorkerRef::Create(
34 workerPrivate, []() { gfxPlatformWorker::Shutdown(); });
35 if (!workerRef) {
36 return nullptr;
39 instance = new gfxPlatformWorker(std::move(workerRef));
40 sInstance.set(instance);
41 return instance;
44 /* static */ void gfxPlatformWorker::Shutdown() {
45 if (!sInstance.init()) {
46 return;
49 gfxPlatformWorker* instance = sInstance.get();
50 if (!instance) {
51 return;
54 sInstance.set(nullptr);
55 delete instance;
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;