/src/mozilla-central/gfx/vr/ipc/VRGPUChild.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "VRGPUChild.h" |
8 | | |
9 | | |
10 | | namespace mozilla { |
11 | | namespace gfx { |
12 | | |
13 | | static StaticRefPtr<VRGPUChild> sVRGPUChildSingleton; |
14 | | |
15 | | /* static */ bool |
16 | | VRGPUChild::InitForGPUProcess(Endpoint<PVRGPUChild>&& aEndpoint) |
17 | 0 | { |
18 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
19 | 0 | MOZ_ASSERT(!sVRGPUChildSingleton); |
20 | 0 |
|
21 | 0 | RefPtr<VRGPUChild> child(new VRGPUChild()); |
22 | 0 | if (!aEndpoint.Bind(child)) { |
23 | 0 | return false; |
24 | 0 | } |
25 | 0 | sVRGPUChildSingleton = child; |
26 | 0 | return true; |
27 | 0 | } |
28 | | |
29 | | /* static */ bool |
30 | | VRGPUChild::IsCreated() |
31 | 0 | { |
32 | 0 | return !!sVRGPUChildSingleton; |
33 | 0 | } |
34 | | |
35 | | /* static */ VRGPUChild* |
36 | | VRGPUChild::Get() |
37 | 0 | { |
38 | 0 | MOZ_ASSERT(IsCreated(), "VRGPUChild haven't initialized yet."); |
39 | 0 | return sVRGPUChildSingleton; |
40 | 0 | } |
41 | | |
42 | | /*static*/ void |
43 | | VRGPUChild::ShutDown() |
44 | 0 | { |
45 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
46 | 0 | if (sVRGPUChildSingleton) { |
47 | 0 | sVRGPUChildSingleton->Destroy(); |
48 | 0 | sVRGPUChildSingleton = nullptr; |
49 | 0 | } |
50 | 0 | } |
51 | | |
52 | | class DeferredDeleteVRGPUChild : public Runnable |
53 | | { |
54 | | public: |
55 | | explicit DeferredDeleteVRGPUChild(RefPtr<VRGPUChild> aChild) |
56 | | : Runnable("gfx::DeferredDeleteVRGPUChild") |
57 | | , mChild(std::move(aChild)) |
58 | 0 | { |
59 | 0 | } |
60 | | |
61 | 0 | NS_IMETHODIMP Run() override { |
62 | 0 | mChild->Close(); |
63 | 0 | return NS_OK; |
64 | 0 | } |
65 | | |
66 | | private: |
67 | | RefPtr<VRGPUChild> mChild; |
68 | | }; |
69 | | |
70 | | void |
71 | | VRGPUChild::Destroy() |
72 | 0 | { |
73 | 0 | // Keep ourselves alive until everything has been shut down |
74 | 0 | RefPtr<VRGPUChild> selfRef = this; |
75 | 0 | NS_DispatchToMainThread(new DeferredDeleteVRGPUChild(this)); |
76 | 0 | } |
77 | | |
78 | | } // namespace gfx |
79 | | } // namespace mozilla |