summaryrefslogtreecommitdiffstats
path: root/dom/webidl/VRDisplay.webidl
blob: d1ce4b949e46fb332ffaea9f9dfa6d23cea6f088 (plain)
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
 *
 * The origin of this IDL file is
 * https://immersive-web.github.io/webvr/spec/1.1/
 */

enum VREye {
  "left",
  "right"
};

[Pref="dom.vr.enabled",
 HeaderFile="mozilla/dom/VRDisplay.h",
 SecureContext,
 Exposed=Window]
interface VRFieldOfView {
  readonly attribute double upDegrees;
  readonly attribute double rightDegrees;
  readonly attribute double downDegrees;
  readonly attribute double leftDegrees;
};

typedef (HTMLCanvasElement or OffscreenCanvas) VRSource;

dictionary VRLayer {
  /**
   * XXX - When WebVR in WebWorkers is implemented, HTMLCanvasElement below
   *       should be replaced with VRSource.
   */
  HTMLCanvasElement? source = null;

  /**
   * The left and right viewports contain 4 values defining the viewport
   * rectangles within the canvas to present to the eye in UV space.
   * [0] left offset of the viewport (0.0 - 1.0)
   * [1] top offset of the viewport (0.0 - 1.0)
   * [2] width of the viewport (0.0 - 1.0)
   * [3] height of the viewport (0.0 - 1.0)
   *
   * When no values are passed, they will be processed as though the left
   * and right sides of the viewport were passed:
   *
   * leftBounds: [0.0, 0.0, 0.5, 1.0]
   * rightBounds: [0.5, 0.0, 0.5, 1.0]
   */
  sequence<float> leftBounds = [];
  sequence<float> rightBounds = [];
};

/**
 * Values describing the capabilities of a VRDisplay.
 * These are expected to be static per-device/per-user.
 */
[Pref="dom.vr.enabled",
 HeaderFile="mozilla/dom/VRDisplay.h",
 SecureContext,
 Exposed=Window]
interface VRDisplayCapabilities {
  /**
   * hasPosition is true if the VRDisplay is capable of tracking its position.
   */
  readonly attribute boolean hasPosition;

  /**
   * hasOrientation is true if the VRDisplay is capable of tracking its orientation.
   */
  readonly attribute boolean hasOrientation;

  /**
   * Whether the VRDisplay is separate from the device’s
   * primary display. If presenting VR content will obscure
   * other content on the device, this should be false. When
   * false, the application should not attempt to mirror VR content
   * or update non-VR UI because that content will not be visible.
   */
  readonly attribute boolean hasExternalDisplay;

  /**
   * Whether the VRDisplay is capable of presenting content to an HMD or similar device.
   * Can be used to indicate “magic window” devices that are capable of 6DoF tracking but for
   * which requestPresent is not meaningful. If false then calls to requestPresent should
   * always fail, and getEyeParameters should return null.
   */
  readonly attribute boolean canPresent;

  /**
   * Indicates the maximum length of the array that requestPresent() will accept. MUST be 1 if
     canPresent is true, 0 otherwise.
   */
  readonly attribute unsigned long maxLayers;
};

/**
 * Values describing the the stage / play area for devices
 * that support room-scale experiences.
 */
[Pref="dom.vr.enabled",
 HeaderFile="mozilla/dom/VRDisplay.h",
 SecureContext,
 Exposed=Window]
interface VRStageParameters {
  /**
   * A 16-element array containing the components of a column-major 4x4
   * affine transform matrix. This matrix transforms the sitting-space position
   * returned by get{Immediate}Pose() to a standing-space position.
   */
  [Throws] readonly attribute Float32Array sittingToStandingTransform;

  /**
   * Dimensions of the play-area bounds. The bounds are defined
   * as an axis-aligned rectangle on the floor.
   * The center of the rectangle is at (0,0,0) in standing-space
   * coordinates.
   * These bounds are defined for safety purposes.
   * Content should not require the user to move beyond these
   * bounds; however, it is possible for the user to ignore
   * the bounds resulting in position values outside of
   * this rectangle.
   */
  readonly attribute float sizeX;
  readonly attribute float sizeZ;
};

[Pref="dom.vr.enabled",
 HeaderFile="mozilla/dom/VRDisplay.h",
 SecureContext,
 Exposed=Window]
interface VRPose
{
  /**
   * position, linearVelocity, and linearAcceleration are 3-component vectors.
   * position is relative to a sitting space. Transforming this point with
   * VRStageParameters.sittingToStandingTransform converts this to standing space.
   */
  [Constant, Throws] readonly attribute Float32Array? position;
  [Constant, Throws] readonly attribute Float32Array? linearVelocity;
  [Constant, Throws] readonly attribute Float32Array? linearAcceleration;

  /* orientation is a 4-entry array representing the components of a quaternion. */
  [Constant, Throws] readonly attribute Float32Array? orientation;
  /* angularVelocity and angularAcceleration are the components of 3-dimensional vectors. */
  [Constant, Throws] readonly attribute Float32Array? angularVelocity;
  [Constant, Throws] readonly attribute Float32Array? angularAcceleration;
};

[Pref="dom.vr.enabled",
 HeaderFile="mozilla/dom/VRDisplay.h",
 SecureContext,
 Exposed=Window]
interface VRFrameData {
  constructor();

  readonly attribute DOMHighResTimeStamp timestamp;

  [Throws, Pure] readonly attribute Float32Array leftProjectionMatrix;
  [Throws, Pure] readonly attribute Float32Array leftViewMatrix;

  [Throws, Pure] readonly attribute Float32Array rightProjectionMatrix;
  [Throws, Pure] readonly attribute Float32Array rightViewMatrix;

  [Pure] readonly attribute VRPose pose;
};

[Pref="dom.vr.enabled",
 HeaderFile="mozilla/dom/VRDisplay.h",
 SecureContext,
 Exposed=Window]
interface VREyeParameters {
  /**
   * offset is a 3-component vector representing an offset to
   * translate the eye. This value may vary from frame
   * to frame if the user adjusts their headset ipd.
   */
  [Constant, Throws] readonly attribute Float32Array offset;

  /* These values may vary as the user adjusts their headset ipd. */
  [Constant] readonly attribute VRFieldOfView fieldOfView;

  /**
   * renderWidth and renderHeight specify the recommended render target
   * size of each eye viewport, in pixels. If multiple eyes are rendered
   * in a single render target, then the render target should be made large
   * enough to fit both viewports.
   */
  [Constant] readonly attribute unsigned long renderWidth;
  [Constant] readonly attribute unsigned long renderHeight;
};

[Pref="dom.vr.enabled",
 HeaderFile="mozilla/dom/VRDisplay.h",
 SecureContext,
 Exposed=Window]
interface VRDisplay : EventTarget {
  /**
   * presentingGroups is a bitmask indicating which VR session groups
   * have an active VR presentation.
   */
  [ChromeOnly] readonly attribute unsigned long presentingGroups;
  /**
   * Setting groupMask causes submitted frames by VR sessions that
   * aren't included in the bitmasked groups to be ignored.
   * Non-chrome content is not aware of the value of groupMask.
   * VRDisplay.RequestAnimationFrame will still fire for VR sessions
   * that are hidden by groupMask, enabling their performance to be
   * measured by chrome UI that is presented in other groups.
   * This is expected to be used in cases where chrome UI is presenting
   * information during link traversal or presenting options when content
   * performance is too low for comfort.
   * The VR refresh / VSync cycle is driven by the visible content
   * and the non-visible content may have a throttled refresh rate.
   */
  [ChromeOnly] attribute unsigned long groupMask;

  readonly attribute boolean isConnected;
  readonly attribute boolean isPresenting;

  /**
   * Dictionary of capabilities describing the VRDisplay.
   */
  [Constant] readonly attribute VRDisplayCapabilities capabilities;

  /**
   * If this VRDisplay supports room-scale experiences, the optional
   * stage attribute contains details on the room-scale parameters.
   */
  readonly attribute VRStageParameters? stageParameters;

  /* Return the current VREyeParameters for the given eye. */
  VREyeParameters getEyeParameters(VREye whichEye);

  /**
   * An identifier for this distinct VRDisplay. Used as an
   * association point in the Gamepad API.
   */
  [Constant] readonly attribute unsigned long displayId;

  /**
   * A display name, a user-readable name identifying it.
   */
  [Constant] readonly attribute DOMString displayName;

  /**
   * Populates the passed VRFrameData with the information required to render
   * the current frame.
   */
  boolean getFrameData(VRFrameData frameData);

  /**
   * Return a VRPose containing the future predicted pose of the VRDisplay
   * when the current frame will be presented. Subsequent calls to getPose()
   * MUST return a VRPose with the same values until the next call to
   * submitFrame().
   *
   * The VRPose will contain the position, orientation, velocity,
   * and acceleration of each of these properties.
   */
  [NewObject] VRPose getPose();

  /**
   * Reset the pose for this display, treating its current position and
   * orientation as the "origin/zero" values. VRPose.position,
   * VRPose.orientation, and VRStageParameters.sittingToStandingTransform may be
   * updated when calling resetPose(). This should be called in only
   * sitting-space experiences.
   */
  undefined resetPose();

  /**
   * z-depth defining the near plane of the eye view frustum
   * enables mapping of values in the render target depth
   * attachment to scene coordinates. Initially set to 0.01.
   */
  attribute double depthNear;

  /**
   * z-depth defining the far plane of the eye view frustum
   * enables mapping of values in the render target depth
   * attachment to scene coordinates. Initially set to 10000.0.
   */
  attribute double depthFar;

  /**
   * The callback passed to `requestAnimationFrame` will be called
   * any time a new frame should be rendered. When the VRDisplay is
   * presenting the callback will be called at the native refresh
   * rate of the HMD. When not presenting this function acts
   * identically to how window.requestAnimationFrame acts. Content should
   * make no assumptions of frame rate or vsync behavior as the HMD runs
   * asynchronously from other displays and at differing refresh rates.
   */
  [Throws] long requestAnimationFrame(FrameRequestCallback callback);

  /**
   * Passing the value returned by `requestAnimationFrame` to
   * `cancelAnimationFrame` will unregister the callback.
   */
  [Throws] undefined cancelAnimationFrame(long handle);

  /**
   * Begin presenting to the VRDisplay. Must be called in response to a user gesture.
   * Repeat calls while already presenting will update the VRLayers being displayed.
   */
  [NewObject, NeedsCallerType] Promise<undefined> requestPresent(sequence<VRLayer> layers);

  /**
   * Stops presenting to the VRDisplay.
   */
  [NewObject] Promise<undefined> exitPresent();

  /**
   * Get the layers currently being presented.
   */
  sequence<VRLayer> getLayers();

  /**
   * The VRLayer provided to the VRDisplay will be captured and presented
   * in the HMD. Calling this function has the same effect on the source
   * canvas as any other operation that uses its source image, and canvases
   * created without preserveDrawingBuffer set to true will be cleared.
   */
  undefined submitFrame();
};