/src/mozilla-central/gfx/vr/ipc/VRManagerChild.h
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 | | #ifndef MOZILLA_GFX_VR_VRMANAGERCHILD_H |
8 | | #define MOZILLA_GFX_VR_VRMANAGERCHILD_H |
9 | | |
10 | | #include "mozilla/dom/WindowBinding.h" // For FrameRequestCallback |
11 | | #include "mozilla/gfx/PVRManagerChild.h" |
12 | | #include "mozilla/ipc/SharedMemory.h" // for SharedMemory, etc |
13 | | #include "ThreadSafeRefcountingWithMainThreadDestruction.h" |
14 | | #include "mozilla/layers/ISurfaceAllocator.h" // for ISurfaceAllocator |
15 | | #include "mozilla/layers/LayersTypes.h" // for LayersBackend |
16 | | #include "mozilla/layers/TextureForwarder.h" |
17 | | |
18 | | namespace mozilla { |
19 | | namespace dom { |
20 | | class Promise; |
21 | | class GamepadManager; |
22 | | class Navigator; |
23 | | class VRDisplay; |
24 | | class VREventObserver; |
25 | | class VRMockDisplay; |
26 | | } // namespace dom |
27 | | namespace layers { |
28 | | class SyncObjectClient; |
29 | | } |
30 | | namespace gfx { |
31 | | class VRLayerChild; |
32 | | class VRDisplayClient; |
33 | | |
34 | | class VRManagerChild : public PVRManagerChild |
35 | | { |
36 | | public: |
37 | | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRManagerChild); |
38 | | |
39 | | static VRManagerChild* Get(); |
40 | | |
41 | | // Indicate that an observer wants to receive VR events. |
42 | | void AddListener(dom::VREventObserver* aObserver); |
43 | | // Indicate that an observer should no longer receive VR events. |
44 | | void RemoveListener(dom::VREventObserver* aObserver); |
45 | | |
46 | | bool GetVRDisplays(nsTArray<RefPtr<VRDisplayClient> >& aDisplays); |
47 | | bool RefreshVRDisplaysWithCallback(uint64_t aWindowId); |
48 | | void AddPromise(const uint32_t& aID, dom::Promise* aPromise); |
49 | | |
50 | | void CreateVRServiceTestDisplay(const nsCString& aID, dom::Promise* aPromise); |
51 | | void CreateVRServiceTestController(const nsCString& aID, dom::Promise* aPromise); |
52 | | |
53 | | static void InitSameProcess(); |
54 | | static void InitWithGPUProcess(Endpoint<PVRManagerChild>&& aEndpoint); |
55 | | static bool InitForContent(Endpoint<PVRManagerChild>&& aEndpoint); |
56 | | static bool ReinitForContent(Endpoint<PVRManagerChild>&& aEndpoint); |
57 | | static void ShutDown(); |
58 | | |
59 | | static bool IsCreated(); |
60 | | |
61 | | PVRLayerChild* CreateVRLayer(uint32_t aDisplayID, |
62 | | nsIEventTarget* aTarget, |
63 | | uint32_t aGroup); |
64 | | |
65 | | static void IdentifyTextureHost(const layers::TextureFactoryIdentifier& aIdentifier); |
66 | | layers::LayersBackend GetBackendType() const; |
67 | 0 | layers::SyncObjectClient* GetSyncObject() { return mSyncObject; } |
68 | | |
69 | | nsresult ScheduleFrameRequestCallback(mozilla::dom::FrameRequestCallback& aCallback, |
70 | | int32_t *aHandle); |
71 | | void CancelFrameRequestCallback(int32_t aHandle); |
72 | | void RunFrameRequestCallbacks(); |
73 | | void NotifyPresentationGenerationChanged(uint32_t aDisplayID); |
74 | | |
75 | | void UpdateDisplayInfo(nsTArray<VRDisplayInfo>& aDisplayUpdates); |
76 | | void FireDOMVRDisplayMountedEvent(uint32_t aDisplayID); |
77 | | void FireDOMVRDisplayUnmountedEvent(uint32_t aDisplayID); |
78 | | void FireDOMVRDisplayConnectEvent(uint32_t aDisplayID); |
79 | | void FireDOMVRDisplayDisconnectEvent(uint32_t aDisplayID); |
80 | | void FireDOMVRDisplayPresentChangeEvent(uint32_t aDisplayID); |
81 | | void FireDOMVRDisplayConnectEventsForLoad(dom::VREventObserver* aObserver); |
82 | | |
83 | | virtual void HandleFatalError(const char* aMsg) const override; |
84 | | |
85 | | protected: |
86 | | explicit VRManagerChild(); |
87 | | ~VRManagerChild(); |
88 | | void Destroy(); |
89 | | static void DeferredDestroy(RefPtr<VRManagerChild> aVRManagerChild); |
90 | | |
91 | | virtual PVRLayerChild* AllocPVRLayerChild(const uint32_t& aDisplayID, |
92 | | const uint32_t& aGroup) override; |
93 | | virtual bool DeallocPVRLayerChild(PVRLayerChild* actor) override; |
94 | | |
95 | | virtual mozilla::ipc::IPCResult RecvUpdateDisplayInfo(nsTArray<VRDisplayInfo>&& aDisplayUpdates) override; |
96 | | |
97 | | virtual mozilla::ipc::IPCResult RecvDispatchSubmitFrameResult(const uint32_t& aDisplayID, const VRSubmitFrameResultInfo& aResult) override; |
98 | | virtual mozilla::ipc::IPCResult RecvGamepadUpdate(const GamepadChangeEvent& aGamepadEvent) override; |
99 | | virtual mozilla::ipc::IPCResult RecvReplyGamepadVibrateHaptic(const uint32_t& aPromiseID) override; |
100 | | |
101 | | virtual mozilla::ipc::IPCResult RecvReplyCreateVRServiceTestDisplay(const nsCString& aID, |
102 | | const uint32_t& aPromiseID, |
103 | | const uint32_t& aDeviceID) override; |
104 | | virtual mozilla::ipc::IPCResult RecvReplyCreateVRServiceTestController(const nsCString& aID, |
105 | | const uint32_t& aPromiseID, |
106 | | const uint32_t& aDeviceID) override; |
107 | | bool IsSameProcess() const |
108 | | { |
109 | | return OtherPid() == base::GetCurrentProcId(); |
110 | | } |
111 | | private: |
112 | | |
113 | | void FireDOMVRDisplayMountedEventInternal(uint32_t aDisplayID); |
114 | | void FireDOMVRDisplayUnmountedEventInternal(uint32_t aDisplayID); |
115 | | void FireDOMVRDisplayConnectEventInternal(uint32_t aDisplayID); |
116 | | void FireDOMVRDisplayDisconnectEventInternal(uint32_t aDisplayID); |
117 | | void FireDOMVRDisplayPresentChangeEventInternal(uint32_t aDisplayID); |
118 | | void FireDOMVRDisplayConnectEventsForLoadInternal(uint32_t aDisplayID, |
119 | | dom::VREventObserver* aObserver); |
120 | | void NotifyPresentationGenerationChangedInternal(uint32_t aDisplayID); |
121 | | |
122 | | nsTArray<RefPtr<VRDisplayClient> > mDisplays; |
123 | | bool mDisplaysInitialized; |
124 | | nsTArray<uint64_t> mNavigatorCallbacks; |
125 | | |
126 | | MessageLoop* mMessageLoop; |
127 | | |
128 | | struct FrameRequest; |
129 | | |
130 | | nsTArray<FrameRequest> mFrameRequestCallbacks; |
131 | | /** |
132 | | * The current frame request callback handle |
133 | | */ |
134 | | int32_t mFrameRequestCallbackCounter; |
135 | | mozilla::TimeStamp mStartTimeStamp; |
136 | | |
137 | | nsTArray<RefPtr<dom::VREventObserver>> mListeners; |
138 | | |
139 | | layers::LayersBackend mBackend; |
140 | | RefPtr<layers::SyncObjectClient> mSyncObject; |
141 | | nsRefPtrHashtable<nsUint32HashKey, dom::Promise> mGamepadPromiseList; |
142 | | uint32_t mPromiseID; |
143 | | nsRefPtrHashtable<nsUint32HashKey, dom::Promise> mPromiseList; |
144 | | RefPtr<dom::VRMockDisplay> mVRMockDisplay; |
145 | | VRControllerState mLastControllerState[kVRControllerMaxCount]; |
146 | | |
147 | | DISALLOW_COPY_AND_ASSIGN(VRManagerChild); |
148 | | }; |
149 | | |
150 | | } // namespace mozilla |
151 | | } // namespace gfx |
152 | | |
153 | | #endif // MOZILLA_GFX_VR_VRMANAGERCHILD_H |