/work/obj-fuzz/dist/include/moz_external_vr.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 GFX_VR_EXTERNAL_API_H |
8 | | #define GFX_VR_EXTERNAL_API_H |
9 | | |
10 | | #include <stddef.h> |
11 | | #include <stdint.h> |
12 | | #include <type_traits> |
13 | | |
14 | | #ifdef MOZILLA_INTERNAL_API |
15 | | #include "mozilla/TypedEnumBits.h" |
16 | | #include "mozilla/gfx/2D.h" |
17 | | #endif // MOZILLA_INTERNAL_API |
18 | | |
19 | | #if defined(__ANDROID__) |
20 | | #include <pthread.h> |
21 | | #endif // defined(__ANDROID__) |
22 | | |
23 | | namespace mozilla { |
24 | | #ifdef MOZILLA_INTERNAL_API |
25 | | namespace dom { |
26 | | enum class GamepadHand : uint8_t; |
27 | | enum class GamepadCapabilityFlags : uint16_t; |
28 | | } |
29 | | #endif // MOZILLA_INTERNAL_API |
30 | | namespace gfx { |
31 | | |
32 | | static const int32_t kVRExternalVersion = 2; |
33 | | |
34 | | // We assign VR presentations to groups with a bitmask. |
35 | | // Currently, we will only display either content or chrome. |
36 | | // Later, we will have more groups to support VR home spaces and |
37 | | // multitasking environments. |
38 | | // These values are not exposed to regular content and only affect |
39 | | // chrome-only API's. They may be changed at any time. |
40 | | static const uint32_t kVRGroupNone = 0; |
41 | | static const uint32_t kVRGroupContent = 1 << 0; |
42 | | static const uint32_t kVRGroupChrome = 1 << 1; |
43 | | static const uint32_t kVRGroupAll = 0xffffffff; |
44 | | |
45 | | static const int kVRDisplayNameMaxLen = 256; |
46 | | static const int kVRControllerNameMaxLen = 256; |
47 | | static const int kVRControllerMaxCount = 16; |
48 | | static const int kVRControllerMaxButtons = 64; |
49 | | static const int kVRControllerMaxAxis = 16; |
50 | | static const int kVRLayerMaxCount = 8; |
51 | | |
52 | | #if defined(__ANDROID__) |
53 | | typedef uint64_t VRLayerTextureHandle; |
54 | | #else |
55 | | typedef void* VRLayerTextureHandle; |
56 | | #endif |
57 | | |
58 | | struct Point3D_POD |
59 | | { |
60 | | float x; |
61 | | float y; |
62 | | float z; |
63 | | }; |
64 | | |
65 | | struct IntSize_POD |
66 | | { |
67 | | int32_t width; |
68 | | int32_t height; |
69 | | }; |
70 | | |
71 | | struct FloatSize_POD |
72 | | { |
73 | | float width; |
74 | | float height; |
75 | | }; |
76 | | |
77 | | #ifndef MOZILLA_INTERNAL_API |
78 | | |
79 | | enum class ControllerHand : uint8_t { |
80 | | _empty, |
81 | | Left, |
82 | | Right, |
83 | | EndGuard_ |
84 | | }; |
85 | | |
86 | | enum class ControllerCapabilityFlags : uint16_t { |
87 | | Cap_None = 0, |
88 | | /** |
89 | | * Cap_Position is set if the Gamepad is capable of tracking its position. |
90 | | */ |
91 | | Cap_Position = 1 << 1, |
92 | | /** |
93 | | * Cap_Orientation is set if the Gamepad is capable of tracking its orientation. |
94 | | */ |
95 | | Cap_Orientation = 1 << 2, |
96 | | /** |
97 | | * Cap_AngularAcceleration is set if the Gamepad is capable of tracking its |
98 | | * angular acceleration. |
99 | | */ |
100 | | Cap_AngularAcceleration = 1 << 3, |
101 | | /** |
102 | | * Cap_LinearAcceleration is set if the Gamepad is capable of tracking its |
103 | | * linear acceleration. |
104 | | */ |
105 | | Cap_LinearAcceleration = 1 << 4, |
106 | | /** |
107 | | * Cap_All used for validity checking during IPC serialization |
108 | | */ |
109 | | Cap_All = (1 << 5) - 1 |
110 | | }; |
111 | | |
112 | | #endif // ifndef MOZILLA_INTERNAL_API |
113 | | |
114 | | enum class VRDisplayCapabilityFlags : uint16_t { |
115 | | Cap_None = 0, |
116 | | /** |
117 | | * Cap_Position is set if the VRDisplay is capable of tracking its position. |
118 | | */ |
119 | | Cap_Position = 1 << 1, |
120 | | /** |
121 | | * Cap_Orientation is set if the VRDisplay is capable of tracking its orientation. |
122 | | */ |
123 | | Cap_Orientation = 1 << 2, |
124 | | /** |
125 | | * Cap_Present is set if the VRDisplay is capable of presenting content to an |
126 | | * HMD or similar device. Can be used to indicate "magic window" devices that |
127 | | * are capable of 6DoF tracking but for which requestPresent is not meaningful. |
128 | | * If false then calls to requestPresent should always fail, and |
129 | | * getEyeParameters should return null. |
130 | | */ |
131 | | Cap_Present = 1 << 3, |
132 | | /** |
133 | | * Cap_External is set if the VRDisplay is separate from the device's |
134 | | * primary display. If presenting VR content will obscure |
135 | | * other content on the device, this should be un-set. When |
136 | | * un-set, the application should not attempt to mirror VR content |
137 | | * or update non-VR UI because that content will not be visible. |
138 | | */ |
139 | | Cap_External = 1 << 4, |
140 | | /** |
141 | | * Cap_AngularAcceleration is set if the VRDisplay is capable of tracking its |
142 | | * angular acceleration. |
143 | | */ |
144 | | Cap_AngularAcceleration = 1 << 5, |
145 | | /** |
146 | | * Cap_LinearAcceleration is set if the VRDisplay is capable of tracking its |
147 | | * linear acceleration. |
148 | | */ |
149 | | Cap_LinearAcceleration = 1 << 6, |
150 | | /** |
151 | | * Cap_StageParameters is set if the VRDisplay is capable of room scale VR |
152 | | * and can report the StageParameters to describe the space. |
153 | | */ |
154 | | Cap_StageParameters = 1 << 7, |
155 | | /** |
156 | | * Cap_MountDetection is set if the VRDisplay is capable of sensing when the |
157 | | * user is wearing the device. |
158 | | */ |
159 | | Cap_MountDetection = 1 << 8, |
160 | | /** |
161 | | * Cap_All used for validity checking during IPC serialization |
162 | | */ |
163 | | Cap_All = (1 << 9) - 1 |
164 | | }; |
165 | | |
166 | | #ifdef MOZILLA_INTERNAL_API |
167 | | MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(VRDisplayCapabilityFlags) |
168 | | #endif // MOZILLA_INTERNAL_API |
169 | | |
170 | | struct VRPose |
171 | | { |
172 | | float orientation[4]; |
173 | | float position[3]; |
174 | | float angularVelocity[3]; |
175 | | float angularAcceleration[3]; |
176 | | float linearVelocity[3]; |
177 | | float linearAcceleration[3]; |
178 | | }; |
179 | | |
180 | | struct VRHMDSensorState { |
181 | | uint64_t inputFrameID; |
182 | | double timestamp; |
183 | | VRDisplayCapabilityFlags flags; |
184 | | |
185 | | // These members will only change with inputFrameID: |
186 | | VRPose pose; |
187 | | float leftViewMatrix[16]; |
188 | | float rightViewMatrix[16]; |
189 | | |
190 | | #ifdef MOZILLA_INTERNAL_API |
191 | | |
192 | 0 | void Clear() { |
193 | 0 | memset(this, 0, sizeof(VRHMDSensorState)); |
194 | 0 | } |
195 | | |
196 | 0 | bool operator==(const VRHMDSensorState& other) const { |
197 | 0 | return inputFrameID == other.inputFrameID && |
198 | 0 | timestamp == other.timestamp; |
199 | 0 | } |
200 | | |
201 | 0 | bool operator!=(const VRHMDSensorState& other) const { |
202 | 0 | return !(*this == other); |
203 | 0 | } |
204 | | |
205 | | void CalcViewMatrices(const gfx::Matrix4x4* aHeadToEyeTransforms); |
206 | | |
207 | | #endif // MOZILLA_INTERNAL_API |
208 | | }; |
209 | | |
210 | | struct VRFieldOfView { |
211 | | double upDegrees; |
212 | | double rightDegrees; |
213 | | double downDegrees; |
214 | | double leftDegrees; |
215 | | |
216 | | #ifdef MOZILLA_INTERNAL_API |
217 | | |
218 | | VRFieldOfView() = default; |
219 | | VRFieldOfView(double up, double right, double down, double left) |
220 | | : upDegrees(up), rightDegrees(right), downDegrees(down), leftDegrees(left) |
221 | 0 | {} |
222 | | |
223 | | void SetFromTanRadians(double up, double right, double down, double left) |
224 | 0 | { |
225 | 0 | upDegrees = atan(up) * 180.0 / M_PI; |
226 | 0 | rightDegrees = atan(right) * 180.0 / M_PI; |
227 | 0 | downDegrees = atan(down) * 180.0 / M_PI; |
228 | 0 | leftDegrees = atan(left) * 180.0 / M_PI; |
229 | 0 | } |
230 | | |
231 | 0 | bool operator==(const VRFieldOfView& other) const { |
232 | 0 | return other.upDegrees == upDegrees && |
233 | 0 | other.downDegrees == downDegrees && |
234 | 0 | other.rightDegrees == rightDegrees && |
235 | 0 | other.leftDegrees == leftDegrees; |
236 | 0 | } |
237 | | |
238 | 0 | bool operator!=(const VRFieldOfView& other) const { |
239 | 0 | return !(*this == other); |
240 | 0 | } |
241 | | |
242 | 0 | bool IsZero() const { |
243 | 0 | return upDegrees == 0.0 || |
244 | 0 | rightDegrees == 0.0 || |
245 | 0 | downDegrees == 0.0 || |
246 | 0 | leftDegrees == 0.0; |
247 | 0 | } |
248 | | |
249 | | Matrix4x4 ConstructProjectionMatrix(float zNear, float zFar, bool rightHanded) const; |
250 | | |
251 | | #endif // MOZILLA_INTERNAL_API |
252 | | |
253 | | }; |
254 | | |
255 | | struct VRDisplayState |
256 | | { |
257 | | enum Eye { |
258 | | Eye_Left, |
259 | | Eye_Right, |
260 | | NumEyes |
261 | | }; |
262 | | |
263 | | #if defined(__ANDROID__) |
264 | | bool shutdown; |
265 | | #endif // defined(__ANDROID__) |
266 | | char mDisplayName[kVRDisplayNameMaxLen]; |
267 | | VRDisplayCapabilityFlags mCapabilityFlags; |
268 | | VRFieldOfView mEyeFOV[VRDisplayState::NumEyes]; |
269 | | Point3D_POD mEyeTranslation[VRDisplayState::NumEyes]; |
270 | | IntSize_POD mEyeResolution; |
271 | | bool mSuppressFrames; |
272 | | bool mIsConnected; |
273 | | bool mIsMounted; |
274 | | FloatSize_POD mStageSize; |
275 | | // We can't use a Matrix4x4 here unless we ensure it's a POD type |
276 | | float mSittingToStandingTransform[16]; |
277 | | uint64_t mLastSubmittedFrameId; |
278 | | bool mLastSubmittedFrameSuccessful; |
279 | | uint32_t mPresentingGeneration; |
280 | | }; |
281 | | |
282 | | struct VRControllerState |
283 | | { |
284 | | char controllerName[kVRControllerNameMaxLen]; |
285 | | #ifdef MOZILLA_INTERNAL_API |
286 | | dom::GamepadHand hand; |
287 | | #else |
288 | | ControllerHand hand; |
289 | | #endif |
290 | | uint32_t numButtons; |
291 | | uint32_t numAxes; |
292 | | uint32_t numHaptics; |
293 | | // The current button pressed bit of button mask. |
294 | | uint64_t buttonPressed; |
295 | | // The current button touched bit of button mask. |
296 | | uint64_t buttonTouched; |
297 | | float triggerValue[kVRControllerMaxButtons]; |
298 | | float axisValue[kVRControllerMaxAxis]; |
299 | | |
300 | | #ifdef MOZILLA_INTERNAL_API |
301 | | dom::GamepadCapabilityFlags flags; |
302 | | #else |
303 | | ControllerCapabilityFlags flags; |
304 | | #endif |
305 | | VRPose pose; |
306 | | bool isPositionValid; |
307 | | bool isOrientationValid; |
308 | | }; |
309 | | |
310 | | struct VRLayerEyeRect |
311 | | { |
312 | | float x; |
313 | | float y; |
314 | | float width; |
315 | | float height; |
316 | | }; |
317 | | |
318 | | enum class VRLayerType : uint16_t { |
319 | | LayerType_None = 0, |
320 | | LayerType_2D_Content = 1, |
321 | | LayerType_Stereo_Immersive = 2 |
322 | | }; |
323 | | |
324 | | enum class VRLayerTextureType : uint16_t { |
325 | | LayerTextureType_None = 0, |
326 | | LayerTextureType_D3D10SurfaceDescriptor = 1, |
327 | | LayerTextureType_MacIOSurface = 2, |
328 | | LayerTextureType_GeckoSurfaceTexture = 3 |
329 | | }; |
330 | | |
331 | | struct VRLayer_2D_Content |
332 | | { |
333 | | VRLayerTextureHandle mTextureHandle; |
334 | | VRLayerTextureType mTextureType; |
335 | | uint64_t mFrameId; |
336 | | }; |
337 | | |
338 | | struct VRLayer_Stereo_Immersive |
339 | | { |
340 | | VRLayerTextureHandle mTextureHandle; |
341 | | VRLayerTextureType mTextureType; |
342 | | uint64_t mFrameId; |
343 | | uint64_t mInputFrameId; |
344 | | VRLayerEyeRect mLeftEyeRect; |
345 | | VRLayerEyeRect mRightEyeRect; |
346 | | }; |
347 | | |
348 | | struct VRLayerState |
349 | | { |
350 | | VRLayerType type; |
351 | | union { |
352 | | VRLayer_2D_Content layer_2d_content; |
353 | | VRLayer_Stereo_Immersive layer_stereo_immersive; |
354 | | }; |
355 | | }; |
356 | | |
357 | | struct VRBrowserState |
358 | | { |
359 | | #if defined(__ANDROID__) |
360 | | bool shutdown; |
361 | | #endif // defined(__ANDROID__) |
362 | | bool presentationActive; |
363 | | bool navigationTransitionActive; |
364 | | VRLayerState layerState[kVRLayerMaxCount]; |
365 | | }; |
366 | | |
367 | | struct VRSystemState |
368 | | { |
369 | | bool enumerationCompleted; |
370 | | VRDisplayState displayState; |
371 | | VRHMDSensorState sensorState; |
372 | | VRControllerState controllerState[kVRControllerMaxCount]; |
373 | | }; |
374 | | |
375 | | struct VRExternalShmem |
376 | | { |
377 | | int32_t version; |
378 | | int32_t size; |
379 | | #if defined(__ANDROID__) |
380 | | pthread_mutex_t systemMutex; |
381 | | pthread_mutex_t browserMutex; |
382 | | pthread_cond_t systemCond; |
383 | | pthread_cond_t browserCond; |
384 | | #else |
385 | | int64_t generationA; |
386 | | #endif // defined(__ANDROID__) |
387 | | VRSystemState state; |
388 | | #if !defined(__ANDROID__) |
389 | | int64_t generationB; |
390 | | int64_t browserGenerationA; |
391 | | #endif // !defined(__ANDROID__) |
392 | | VRBrowserState browserState; |
393 | | #if !defined(__ANDROID__) |
394 | | int64_t browserGenerationB; |
395 | | #endif // !defined(__ANDROID__) |
396 | | }; |
397 | | |
398 | | // As we are memcpy'ing VRExternalShmem and its members around, it must be a POD type |
399 | | static_assert(std::is_pod<VRExternalShmem>::value, "VRExternalShmem must be a POD type."); |
400 | | |
401 | | } // namespace gfx |
402 | | } // namespace mozilla |
403 | | |
404 | | #endif /* GFX_VR_EXTERNAL_API_H */ |