/work/obj-fuzz/dist/include/mozilla/dom/VRDisplay.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 file, |
5 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_dom_VRDisplay_h_ |
8 | | #define mozilla_dom_VRDisplay_h_ |
9 | | |
10 | | #include <stdint.h> |
11 | | |
12 | | #include "mozilla/ErrorResult.h" |
13 | | #include "mozilla/dom/TypedArray.h" |
14 | | #include "mozilla/dom/VRDisplayBinding.h" |
15 | | #include "mozilla/DOMEventTargetHelper.h" |
16 | | #include "mozilla/dom/DOMPoint.h" |
17 | | #include "mozilla/dom/DOMRect.h" |
18 | | #include "mozilla/dom/Pose.h" |
19 | | #include "mozilla/TimeStamp.h" |
20 | | |
21 | | #include "nsCOMPtr.h" |
22 | | #include "nsString.h" |
23 | | #include "nsTArray.h" |
24 | | |
25 | | #include "gfxVR.h" |
26 | | |
27 | | namespace mozilla { |
28 | | namespace gfx { |
29 | | class VRDisplayClient; |
30 | | class VRDisplayPresentation; |
31 | | struct VRFieldOfView; |
32 | | enum class VRDisplayCapabilityFlags : uint16_t; |
33 | | struct VRHMDSensorState; |
34 | | } |
35 | | namespace dom { |
36 | | class Navigator; |
37 | | |
38 | | class VRFieldOfView final : public nsWrapperCache |
39 | | { |
40 | | public: |
41 | | VRFieldOfView(nsISupports* aParent, |
42 | | double aUpDegrees, double aRightDegrees, |
43 | | double aDownDegrees, double aLeftDegrees); |
44 | | VRFieldOfView(nsISupports* aParent, const gfx::VRFieldOfView& aSrc); |
45 | | |
46 | | NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VRFieldOfView) |
47 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VRFieldOfView) |
48 | | |
49 | 0 | double UpDegrees() const { return mUpDegrees; } |
50 | 0 | double RightDegrees() const { return mRightDegrees; } |
51 | 0 | double DownDegrees() const { return mDownDegrees; } |
52 | 0 | double LeftDegrees() const { return mLeftDegrees; } |
53 | | |
54 | 0 | nsISupports* GetParentObject() const { return mParent; } |
55 | | virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
56 | | |
57 | | protected: |
58 | 0 | virtual ~VRFieldOfView() {} |
59 | | |
60 | | nsCOMPtr<nsISupports> mParent; |
61 | | |
62 | | double mUpDegrees; |
63 | | double mRightDegrees; |
64 | | double mDownDegrees; |
65 | | double mLeftDegrees; |
66 | | }; |
67 | | |
68 | | class VRDisplayCapabilities final : public nsWrapperCache |
69 | | { |
70 | | public: |
71 | | VRDisplayCapabilities(nsISupports* aParent, const gfx::VRDisplayCapabilityFlags& aFlags) |
72 | | : mParent(aParent) |
73 | | , mFlags(aFlags) |
74 | 0 | { |
75 | 0 | } |
76 | | |
77 | | NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VRDisplayCapabilities) |
78 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VRDisplayCapabilities) |
79 | | |
80 | | nsISupports* GetParentObject() const |
81 | 0 | { |
82 | 0 | return mParent; |
83 | 0 | } |
84 | | |
85 | | virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
86 | | |
87 | | bool HasPosition() const; |
88 | | bool HasOrientation() const; |
89 | | bool HasExternalDisplay() const; |
90 | | bool CanPresent() const; |
91 | | uint32_t MaxLayers() const; |
92 | | |
93 | | protected: |
94 | 0 | ~VRDisplayCapabilities() {} |
95 | | nsCOMPtr<nsISupports> mParent; |
96 | | gfx::VRDisplayCapabilityFlags mFlags; |
97 | | }; |
98 | | |
99 | | class VRPose final : public Pose |
100 | | { |
101 | | |
102 | | public: |
103 | | VRPose(nsISupports* aParent, const gfx::VRHMDSensorState& aState); |
104 | | explicit VRPose(nsISupports* aParent); |
105 | | |
106 | | virtual void GetPosition(JSContext* aCx, |
107 | | JS::MutableHandle<JSObject*> aRetval, |
108 | | ErrorResult& aRv) override; |
109 | | virtual void GetLinearVelocity(JSContext* aCx, |
110 | | JS::MutableHandle<JSObject*> aRetval, |
111 | | ErrorResult& aRv) override; |
112 | | virtual void GetLinearAcceleration(JSContext* aCx, |
113 | | JS::MutableHandle<JSObject*> aRetval, |
114 | | ErrorResult& aRv) override; |
115 | | virtual void GetOrientation(JSContext* aCx, |
116 | | JS::MutableHandle<JSObject*> aRetval, |
117 | | ErrorResult& aRv) override; |
118 | | virtual void GetAngularVelocity(JSContext* aCx, |
119 | | JS::MutableHandle<JSObject*> aRetval, |
120 | | ErrorResult& aRv) override; |
121 | | virtual void GetAngularAcceleration(JSContext* aCx, |
122 | | JS::MutableHandle<JSObject*> aRetval, |
123 | | ErrorResult& aRv) override; |
124 | | |
125 | | virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
126 | | |
127 | | protected: |
128 | | ~VRPose(); |
129 | | |
130 | | gfx::VRHMDSensorState mVRState; |
131 | | }; |
132 | | |
133 | | struct VRFrameInfo |
134 | | { |
135 | | VRFrameInfo(); |
136 | | |
137 | | void Update(const gfx::VRDisplayInfo& aInfo, |
138 | | const gfx::VRHMDSensorState& aState, |
139 | | float aDepthNear, |
140 | | float aDepthFar); |
141 | | |
142 | | void Clear(); |
143 | | bool IsDirty(); |
144 | | |
145 | | gfx::VRHMDSensorState mVRState; |
146 | | gfx::Matrix4x4 mLeftProjection; |
147 | | gfx::Matrix4x4 mLeftView; |
148 | | gfx::Matrix4x4 mRightProjection; |
149 | | gfx::Matrix4x4 mRightView; |
150 | | |
151 | | /** |
152 | | * In order to avoid leaking information related to the duration of |
153 | | * the user's VR session, we re-base timestamps. |
154 | | * mTimeStampOffset is added to the actual timestamp returned by the |
155 | | * underlying VR platform API when returned through WebVR API's. |
156 | | */ |
157 | | double mTimeStampOffset; |
158 | | }; |
159 | | |
160 | | class VRFrameData final : public nsWrapperCache |
161 | | { |
162 | | public: |
163 | | NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VRFrameData) |
164 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VRFrameData) |
165 | | |
166 | | explicit VRFrameData(nsISupports* aParent); |
167 | | static already_AddRefed<VRFrameData> Constructor(const GlobalObject& aGlobal, |
168 | | ErrorResult& aRv); |
169 | | |
170 | | void Update(const VRFrameInfo& aFrameInfo); |
171 | | |
172 | | // WebIDL Members |
173 | | double Timestamp() const; |
174 | | void GetLeftProjectionMatrix(JSContext* aCx, |
175 | | JS::MutableHandle<JSObject*> aRetval, |
176 | | ErrorResult& aRv); |
177 | | void GetLeftViewMatrix(JSContext* aCx, |
178 | | JS::MutableHandle<JSObject*> aRetval, |
179 | | ErrorResult& aRv); |
180 | | void GetRightProjectionMatrix(JSContext* aCx, |
181 | | JS::MutableHandle<JSObject*> aRetval, |
182 | | ErrorResult& aRv); |
183 | | void GetRightViewMatrix(JSContext* aCx, |
184 | | JS::MutableHandle<JSObject*> aRetval, |
185 | | ErrorResult& aRv); |
186 | | |
187 | | VRPose* Pose(); |
188 | | |
189 | | // WebIDL Boilerplate |
190 | 0 | nsISupports* GetParentObject() const { return mParent; } |
191 | | virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
192 | | |
193 | | protected: |
194 | | ~VRFrameData(); |
195 | | nsCOMPtr<nsISupports> mParent; |
196 | | |
197 | | VRFrameInfo mFrameInfo; |
198 | | RefPtr<VRPose> mPose; |
199 | | JS::Heap<JSObject*> mLeftProjectionMatrix; |
200 | | JS::Heap<JSObject*> mLeftViewMatrix; |
201 | | JS::Heap<JSObject*> mRightProjectionMatrix; |
202 | | JS::Heap<JSObject*> mRightViewMatrix; |
203 | | |
204 | | void LazyCreateMatrix(JS::Heap<JSObject*>& aArray, gfx::Matrix4x4& aMat, |
205 | | JSContext* aCx, JS::MutableHandle<JSObject*> aRetval, |
206 | | ErrorResult& aRv); |
207 | | }; |
208 | | |
209 | | class VRStageParameters final : public nsWrapperCache |
210 | | { |
211 | | public: |
212 | | VRStageParameters(nsISupports* aParent, |
213 | | const gfx::Matrix4x4& aSittingToStandingTransform, |
214 | | const gfx::Size& aSize); |
215 | | |
216 | | NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VRStageParameters) |
217 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VRStageParameters) |
218 | | |
219 | | void GetSittingToStandingTransform(JSContext* aCx, |
220 | | JS::MutableHandle<JSObject*> aRetval, |
221 | | ErrorResult& aRv); |
222 | 0 | float SizeX() const { return mSize.width; } |
223 | 0 | float SizeZ() const { return mSize.height; } |
224 | | |
225 | 0 | nsISupports* GetParentObject() const { return mParent; } |
226 | | virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
227 | | |
228 | | protected: |
229 | | ~VRStageParameters(); |
230 | | |
231 | | nsCOMPtr<nsISupports> mParent; |
232 | | |
233 | | gfx::Matrix4x4 mSittingToStandingTransform; |
234 | | JS::Heap<JSObject*> mSittingToStandingTransformArray; |
235 | | gfx::Size mSize; |
236 | | }; |
237 | | |
238 | | class VREyeParameters final : public nsWrapperCache |
239 | | { |
240 | | public: |
241 | | VREyeParameters(nsISupports* aParent, |
242 | | const gfx::Point3D& aEyeTranslation, |
243 | | const gfx::VRFieldOfView& aFOV, |
244 | | const gfx::IntSize& aRenderSize); |
245 | | |
246 | | NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VREyeParameters) |
247 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VREyeParameters) |
248 | | |
249 | | void GetOffset(JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal, |
250 | | ErrorResult& aRv); |
251 | | |
252 | | VRFieldOfView* FieldOfView(); |
253 | | |
254 | 0 | uint32_t RenderWidth() const { return mRenderSize.width; } |
255 | 0 | uint32_t RenderHeight() const { return mRenderSize.height; } |
256 | | |
257 | 0 | nsISupports* GetParentObject() const { return mParent; } |
258 | | virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
259 | | protected: |
260 | | ~VREyeParameters(); |
261 | | |
262 | | nsCOMPtr<nsISupports> mParent; |
263 | | |
264 | | |
265 | | gfx::Point3D mEyeTranslation; |
266 | | gfx::IntSize mRenderSize; |
267 | | JS::Heap<JSObject*> mOffset; |
268 | | RefPtr<VRFieldOfView> mFOV; |
269 | | }; |
270 | | |
271 | | class VRSubmitFrameResult final : public nsWrapperCache |
272 | | { |
273 | | public: |
274 | | NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VRSubmitFrameResult) |
275 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VRSubmitFrameResult) |
276 | | |
277 | | explicit VRSubmitFrameResult(nsISupports* aParent); |
278 | | static already_AddRefed<VRSubmitFrameResult> Constructor(const GlobalObject& aGlobal, |
279 | | ErrorResult& aRv); |
280 | | |
281 | | void Update(uint64_t aFrameNum, const nsACString& aBase64Image); |
282 | | // WebIDL Members |
283 | | double FrameNum() const; |
284 | | void GetBase64Image(nsAString& aImage) const; |
285 | | |
286 | | // WebIDL Boilerplate |
287 | 0 | nsISupports* GetParentObject() const { return mParent; } |
288 | | virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
289 | | |
290 | | protected: |
291 | | ~VRSubmitFrameResult(); |
292 | | |
293 | | nsCOMPtr<nsISupports> mParent; |
294 | | nsString mBase64Image; |
295 | | uint64_t mFrameNum; |
296 | | }; |
297 | | |
298 | | class VRDisplay final : public DOMEventTargetHelper |
299 | | , public nsIObserver |
300 | | { |
301 | | public: |
302 | | NS_DECL_ISUPPORTS_INHERITED |
303 | | NS_DECL_NSIOBSERVER |
304 | | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(VRDisplay, DOMEventTargetHelper) |
305 | | |
306 | | virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
307 | | |
308 | | uint32_t PresentingGroups() const; |
309 | | uint32_t GroupMask() const; |
310 | | void SetGroupMask(const uint32_t& aGroupMask); |
311 | | bool IsAnyPresenting(uint32_t aGroupMask) const; |
312 | | bool IsPresenting() const; |
313 | | bool IsConnected() const; |
314 | | |
315 | | VRDisplayCapabilities* Capabilities(); |
316 | | VRStageParameters* GetStageParameters(); |
317 | | |
318 | 0 | uint32_t DisplayId() const { return mDisplayId; } |
319 | 0 | void GetDisplayName(nsAString& aDisplayName) const { aDisplayName = mDisplayName; } |
320 | | |
321 | | static bool RefreshVRDisplays(uint64_t aWindowId); |
322 | | static void UpdateVRDisplays(nsTArray<RefPtr<VRDisplay> >& aDisplays, |
323 | | nsPIDOMWindowInner* aWindow); |
324 | | |
325 | 0 | gfx::VRDisplayClient *GetClient() { |
326 | 0 | return mClient; |
327 | 0 | } |
328 | | |
329 | | virtual already_AddRefed<VREyeParameters> GetEyeParameters(VREye aEye); |
330 | | |
331 | | bool GetFrameData(VRFrameData& aFrameData); |
332 | | bool GetSubmitFrameResult(VRSubmitFrameResult& aResult); |
333 | | already_AddRefed<VRPose> GetPose(); |
334 | | void ResetPose(); |
335 | | |
336 | 0 | double DepthNear() { |
337 | 0 | return mDepthNear; |
338 | 0 | } |
339 | | |
340 | 0 | double DepthFar() { |
341 | 0 | return mDepthFar; |
342 | 0 | } |
343 | | |
344 | 0 | void SetDepthNear(double aDepthNear) { |
345 | 0 | // XXX When we start sending depth buffers to VRLayer's we will want |
346 | 0 | // to communicate this with the VRDisplayHost |
347 | 0 | mDepthNear = aDepthNear; |
348 | 0 | } |
349 | | |
350 | 0 | void SetDepthFar(double aDepthFar) { |
351 | 0 | // XXX When we start sending depth buffers to VRLayer's we will want |
352 | 0 | // to communicate this with the VRDisplayHost |
353 | 0 | mDepthFar = aDepthFar; |
354 | 0 | } |
355 | | |
356 | | already_AddRefed<Promise> RequestPresent(const nsTArray<VRLayer>& aLayers, |
357 | | CallerType aCallerType, |
358 | | ErrorResult& aRv); |
359 | | already_AddRefed<Promise> ExitPresent(ErrorResult& aRv); |
360 | | void GetLayers(nsTArray<VRLayer>& result); |
361 | | void SubmitFrame(); |
362 | | |
363 | | int32_t RequestAnimationFrame(mozilla::dom::FrameRequestCallback& aCallback, |
364 | | mozilla::ErrorResult& aError); |
365 | | void CancelAnimationFrame(int32_t aHandle, mozilla::ErrorResult& aError); |
366 | | void StartVRNavigation(); |
367 | | void StartHandlingVRNavigationEvent(); |
368 | | void StopHandlingVRNavigationEvent(); |
369 | | bool IsHandlingVRNavigationEvent(); |
370 | | void OnPresentationGenerationChanged(); |
371 | | |
372 | | protected: |
373 | | VRDisplay(nsPIDOMWindowInner* aWindow, gfx::VRDisplayClient* aClient); |
374 | | virtual ~VRDisplay(); |
375 | | virtual void LastRelease() override; |
376 | | |
377 | | void ExitPresentInternal(); |
378 | | void Shutdown(); |
379 | | void UpdateFrameInfo(); |
380 | | |
381 | | RefPtr<gfx::VRDisplayClient> mClient; |
382 | | |
383 | | uint32_t mDisplayId; |
384 | | nsString mDisplayName; |
385 | | |
386 | | RefPtr<VRDisplayCapabilities> mCapabilities; |
387 | | RefPtr<VRStageParameters> mStageParameters; |
388 | | |
389 | | double mDepthNear; |
390 | | double mDepthFar; |
391 | | |
392 | | RefPtr<gfx::VRDisplayPresentation> mPresentation; |
393 | | |
394 | | /** |
395 | | * The WebVR 1.1 spec Requires that VRDisplay.getPose and VRDisplay.getFrameData |
396 | | * must return the same values until the next VRDisplay.submitFrame. |
397 | | * mFrameInfo is updated only on the first call to either function within one |
398 | | * frame. Subsequent calls before the next SubmitFrame or ExitPresent call |
399 | | * will use these cached values. |
400 | | */ |
401 | | VRFrameInfo mFrameInfo; |
402 | | |
403 | | // Time at which we began expecting VR navigation. |
404 | | TimeStamp mHandlingVRNavigationEventStart; |
405 | | int32_t mVRNavigationEventDepth; |
406 | | bool mShutdown; |
407 | | }; |
408 | | |
409 | | } // namespace dom |
410 | | } // namespace mozilla |
411 | | |
412 | | #endif |