1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef MOZILLA_GFX_VR_VRMANAGERCHILD_H
#define MOZILLA_GFX_VR_VRMANAGERCHILD_H
#include "nsISupportsImpl.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/AnimationFrameProviderBinding.h"
#include "mozilla/dom/WebXRBinding.h"
#include "mozilla/dom/XRFrame.h"
#include "mozilla/gfx/PVRManagerChild.h"
#include "mozilla/ipc/SharedMemory.h" // for SharedMemory, etc
#include "mozilla/layers/ISurfaceAllocator.h" // for ISurfaceAllocator
#include "mozilla/layers/LayersTypes.h" // for LayersBackend
namespace mozilla {
namespace dom {
class Promise;
class GamepadManager;
class Navigator;
class VRDisplay;
class FrameRequestCallback;
} // namespace dom
namespace gfx {
class VRLayerChild;
class VRDisplayClient;
class VRManagerEventObserver {
public:
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
virtual void NotifyVRDisplayMounted(uint32_t aDisplayID) = 0;
virtual void NotifyVRDisplayUnmounted(uint32_t aDisplayID) = 0;
virtual void NotifyVRDisplayConnect(uint32_t aDisplayID) = 0;
virtual void NotifyVRDisplayDisconnect(uint32_t aDisplayID) = 0;
virtual void NotifyVRDisplayPresentChange(uint32_t aDisplayID) = 0;
virtual void NotifyPresentationGenerationChanged(uint32_t aDisplayID) = 0;
virtual bool GetStopActivityStatus() const = 0;
virtual void NotifyEnumerationCompleted() = 0;
virtual void NotifyDetectRuntimesCompleted() = 0;
protected:
virtual ~VRManagerEventObserver() = default;
};
class VRManagerChild : public PVRManagerChild {
friend class PVRManagerChild;
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRManagerChild, override);
static VRManagerChild* Get();
// Indicate that an observer wants to receive VR events.
void AddListener(VRManagerEventObserver* aObserver);
// Indicate that an observer should no longer receive VR events.
void RemoveListener(VRManagerEventObserver* aObserver);
void StartActivity();
void StopActivity();
bool RuntimeSupportsVR() const;
bool RuntimeSupportsAR() const;
bool RuntimeSupportsInline() const;
void GetVRDisplays(nsTArray<RefPtr<VRDisplayClient>>& aDisplays);
bool RefreshVRDisplaysWithCallback(uint64_t aWindowId);
bool EnumerateVRDisplays();
void DetectRuntimes();
void AddPromise(const uint32_t& aID, dom::Promise* aPromise);
gfx::VRAPIMode GetVRAPIMode(uint32_t aDisplayID) const;
static void InitSameProcess();
static void InitWithGPUProcess(Endpoint<PVRManagerChild>&& aEndpoint);
static bool InitForContent(Endpoint<PVRManagerChild>&& aEndpoint);
static void ShutDown();
static bool IsCreated();
static bool IsPresenting();
static TimeStamp GetIdleDeadlineHint(TimeStamp aDefault);
PVRLayerChild* CreateVRLayer(uint32_t aDisplayID, uint32_t aGroup);
static void IdentifyTextureHost(
const layers::TextureFactoryIdentifier& aIdentifier);
layers::LayersBackend GetBackendType() const;
nsresult ScheduleFrameRequestCallback(dom::FrameRequestCallback& aCallback,
int32_t* aHandle);
void CancelFrameRequestCallback(int32_t aHandle);
MOZ_CAN_RUN_SCRIPT
void RunFrameRequestCallbacks();
void NotifyPresentationGenerationChanged(uint32_t aDisplayID);
MOZ_CAN_RUN_SCRIPT
void UpdateDisplayInfo(const VRDisplayInfo& aDisplayInfo);
void FireDOMVRDisplayMountedEvent(uint32_t aDisplayID);
void FireDOMVRDisplayUnmountedEvent(uint32_t aDisplayID);
void FireDOMVRDisplayConnectEvent(uint32_t aDisplayID);
void FireDOMVRDisplayDisconnectEvent(uint32_t aDisplayID);
void FireDOMVRDisplayPresentChangeEvent(uint32_t aDisplayID);
void FireDOMVRDisplayConnectEventsForLoad(VRManagerEventObserver* aObserver);
void HandleFatalError(const char* aMsg) override;
void ActorDestroy(ActorDestroyReason aReason) override;
void RunPuppet(const nsTArray<uint64_t>& aBuffer, dom::Promise* aPromise,
ErrorResult& aRv);
void ResetPuppet(dom::Promise* aPromise, ErrorResult& aRv);
protected:
explicit VRManagerChild();
~VRManagerChild();
PVRLayerChild* AllocPVRLayerChild(const uint32_t& aDisplayID,
const uint32_t& aGroup);
bool DeallocPVRLayerChild(PVRLayerChild* actor);
// MOZ_CAN_RUN_SCRIPT_BOUNDARY until we can mark ipdl-generated things as
// MOZ_CAN_RUN_SCRIPT.
MOZ_CAN_RUN_SCRIPT_BOUNDARY
mozilla::ipc::IPCResult RecvUpdateDisplayInfo(
const VRDisplayInfo& aDisplayInfo);
mozilla::ipc::IPCResult RecvUpdateRuntimeCapabilities(
const VRDisplayCapabilityFlags& aCapabilities);
mozilla::ipc::IPCResult RecvReplyGamepadVibrateHaptic(
const uint32_t& aPromiseID);
MOZ_CAN_RUN_SCRIPT_BOUNDARY
mozilla::ipc::IPCResult RecvNotifyPuppetCommandBufferCompleted(bool aSuccess);
MOZ_CAN_RUN_SCRIPT_BOUNDARY
mozilla::ipc::IPCResult RecvNotifyPuppetResetComplete();
bool IsSameProcess() const { return OtherPid() == base::GetCurrentProcId(); }
private:
void FireDOMVRDisplayMountedEventInternal(uint32_t aDisplayID);
void FireDOMVRDisplayUnmountedEventInternal(uint32_t aDisplayID);
void FireDOMVRDisplayConnectEventInternal(uint32_t aDisplayID);
void FireDOMVRDisplayDisconnectEventInternal(uint32_t aDisplayID);
void FireDOMVRDisplayPresentChangeEventInternal(uint32_t aDisplayID);
void FireDOMVRDisplayConnectEventsForLoadInternal(
uint32_t aDisplayID, VRManagerEventObserver* aObserver);
void NotifyPresentationGenerationChangedInternal(uint32_t aDisplayID);
void NotifyEnumerationCompletedInternal();
void NotifyRuntimeCapabilitiesUpdatedInternal();
nsTArray<RefPtr<VRDisplayClient>> mDisplays;
VRDisplayCapabilityFlags mRuntimeCapabilities;
bool mDisplaysInitialized;
nsTArray<uint64_t> mNavigatorCallbacks;
struct XRFrameRequest {
XRFrameRequest(mozilla::dom::FrameRequestCallback& aCallback,
int32_t aHandle)
: mCallback(&aCallback), mHandle(aHandle) {}
XRFrameRequest(mozilla::dom::XRFrameRequestCallback& aCallback,
mozilla::dom::XRFrame& aFrame, int32_t aHandle)
: mXRCallback(&aCallback), mXRFrame(&aFrame), mHandle(aHandle) {}
MOZ_CAN_RUN_SCRIPT
void Call(const DOMHighResTimeStamp& aTimeStamp);
// Comparator operators to allow RemoveElementSorted with an
// integer argument on arrays of XRFrameRequest
bool operator==(int32_t aHandle) const { return mHandle == aHandle; }
bool operator<(int32_t aHandle) const { return mHandle < aHandle; }
RefPtr<mozilla::dom::FrameRequestCallback> mCallback;
RefPtr<mozilla::dom::XRFrameRequestCallback> mXRCallback;
RefPtr<mozilla::dom::XRFrame> mXRFrame;
int32_t mHandle;
};
nsTArray<XRFrameRequest> mFrameRequestCallbacks;
/**
* The current frame request callback handle
*/
int32_t mFrameRequestCallbackCounter;
mozilla::TimeStamp mStartTimeStamp;
nsTArray<RefPtr<VRManagerEventObserver>> mListeners;
bool mWaitingForEnumeration;
layers::LayersBackend mBackend;
nsRefPtrHashtable<nsUint32HashKey, dom::Promise> mGamepadPromiseList;
RefPtr<dom::Promise> mRunPuppetPromise;
nsTArray<RefPtr<dom::Promise>> mResetPuppetPromises;
DISALLOW_COPY_AND_ASSIGN(VRManagerChild);
};
} // namespace gfx
} // namespace mozilla
#endif // MOZILLA_GFX_VR_VRMANAGERCHILD_H
|