summaryrefslogtreecommitdiff
path: root/chromium/device/vr/public/mojom/vr_service.mojom
blob: 108c4291434e98f27bd664f0179721c1cdeb0e3a (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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module device.mojom;

import "mojo/public/mojom/base/time.mojom";
import "gpu/ipc/common/mailbox_holder.mojom";
import "gpu/ipc/common/sync_token.mojom";
import "ui/display/mojo/display.mojom";
import "ui/gfx/geometry/mojo/geometry.mojom";
import "ui/gfx/mojo/gpu_fence_handle.mojom";
import "ui/gfx/mojo/transform.mojom";

//
// WebXR interfaces
//

enum XRHandedness {
  NONE = 0,
  LEFT = 1,
  RIGHT = 2
};

enum XRTargetRayMode {
  GAZING = 1,
  POINTING = 2,
  TAPPING = 3
};

struct XRSessionOptions {
  bool immersive;
  bool provide_passthrough_camera;

  // A flag to indicate if there has been a user activation when the request
  // session is made.
  bool has_user_activation;

  // This flag ensures that render paths that are only supported in WebXR are
  // not used for WebVR 1.1.
  bool use_legacy_webvr_render_path;
};

// TODO(offenwanger) Rearrange these two interfaces to merge duplicate
// functionality.
struct XRSession {
  VRMagicWindowProvider? magic_window_provider;
  XRPresentationConnection? connection;
};

struct XRPresentationConnection {
  VRSubmitFrameClient& client_request;
  VRPresentationProvider provider;
  VRDisplayFrameTransportOptions transport_options;
};

struct XRInputSourceDescription {
  XRTargetRayMode target_ray_mode;
  XRHandedness handedness;
  bool emulated_position;

  // Transform from the grip matrix to the pointer's origin and orientation.
  gfx.mojom.Transform? pointer_offset;
};

struct XRInputSourceState {
  uint32 source_id;

  // Description of this input source's behavior. Should be mostly static, only
  // need periodic updates.
  XRInputSourceDescription? description;

  // Transform to the controllers grip (users palm) from start space origin.
  gfx.mojom.Transform? grip;

  // Describes the current state of the primary input.
  bool primary_input_pressed;

  // Indicates if the input's primary input has been released (clicked) since
  // the last report. May indicate that the button was pressed and released in
  // the space of a single frame, so it may not have been preceeded by a
  // primary_input_pressed = true;
  bool primary_input_clicked;
};

//
// WebVR/WebXR shared interfaces
//

// A field of view, given by 4 degrees describing the view from a center point.
struct VRFieldOfView {
  float upDegrees;
  float downDegrees;
  float leftDegrees;
  float rightDegrees;
};

// A display's position, orientation, velocity, and acceleration state at the
// given timestamp.
struct VRPose {
  array<float, 4>? orientation;
  array<float, 3>? position;
  array<float, 3>? angularVelocity;
  array<float, 3>? linearVelocity;
  array<float, 3>? angularAcceleration;
  array<float, 3>? linearAcceleration;

  // For WebXR sessions only, reports the state of all active input devices
  // synced with the head pose.
  array<XRInputSourceState>? input_state;

  // Indicates that a reset pose event was triggered, either by device specific
  // UI or by some other method, and handled on the browser side, and the
  // renderer should now bubble up an event to the WebXR Device API.
  bool pose_reset;
};

struct XRRay {
  // TODO(https://crbug.com/845293): use Point3F and Vector3F from
  // ui/gfx/geometry and inline directly in requestHitTest().
  array<float, 3> origin;
  array<float, 3> direction;
};

struct XRHitResult {
  // A 4x4 transformation matrix representing the position of the object hit
  // and the orientation of the normal of the object at the hit location.
  // TODO(https://crbug.com/845293): use gfx.mojom.Transform.
  array<float, 16> hit_matrix;
};

struct VRDisplayCapabilities {
  bool hasPosition;
  bool hasExternalDisplay;

  // Indicates whether the display can actively show imagery on a headset.
  bool canPresent;

  // If true, this is an AR display that can provide a background image along
  // with each pose. Clients who want them should send a frame image request
  // via getFrameData instead of getPose.
  // TODO(https://crbug.com/836349): this may need to change.
  bool can_provide_pass_through_images;
};

// Information about the optical properties for an eye in a VRDisplay.
struct VREyeParameters {
  VRFieldOfView fieldOfView;
  array<float, 3> offset;
  uint32 renderWidth;
  uint32 renderHeight;
};

struct VRStageParameters {
  array<float, 16> standingTransform;
  float sizeX;
  float sizeZ;
};

struct VRDisplayInfo {
  uint32 index;
  string displayName;
  VRDisplayCapabilities capabilities;
  VRStageParameters? stageParameters;
  // Parameters required to distort a scene for viewing in a VR headset. Only
  // required for devices which have the canPresent capability.
  VREyeParameters? leftEye;
  VREyeParameters? rightEye;
  float webvr_default_framebuffer_scale = 1.0;
  float webxr_default_framebuffer_scale = 1.0;
};

// Frame transport method from the Renderer's point of view.
enum VRDisplayFrameTransportMethod {
  NONE = 0,

  // Renderer should create a new texture handle (Windows) or
  // texture mailbox (Android Surface path) containing the
  // frame's image and supply that as a submitFrame argument.
  SUBMIT_AS_TEXTURE_HANDLE = 1,
  SUBMIT_AS_MAILBOX_HOLDER = 2,

  // Renderer should draw directly into a texture mailbox
  // provided for each frame in OnVSync.
  DRAW_INTO_TEXTURE_MAILBOX = 3,
};

struct VRDisplayFrameTransportOptions {
  VRDisplayFrameTransportMethod transport_method;

  // Booleans indicating which of the VRSubmitFrameClient callbacks
  // are in use. Default is false, the device implementation should set
  // the ones to true that it needs and can ignore the rest.
  bool wait_for_transfer_notification;
  bool wait_for_render_notification;
  bool wait_for_gpu_fence;
};

// The data needed for each animation frame of an XRSession.
struct XRFrameData {
  // General XRSession value

  // The pose may be null if the device lost tracking. The XRFrameData can still
  // have other data, such as pass through camera image.
  VRPose? pose;
  // TODO(https://crbug.com/838515): Is this delta since the last
  // frame? OR an unspecified origin? Something else?
  mojo_base.mojom.TimeDelta time_delta;
  // The buffer_holder is used for sending data imagery back and forth across
  // the process boundary. For application with pass through camera, it holds
  // the camera image to be passed to the renderer. For immersive sessions, it
  // is the place for the renderer to draw into to pass imagery to the device
  // for rendering.
  gpu.mojom.MailboxHolder? buffer_holder;

  // Exclusive session values

  // The frame_id maps frame data to a frame arriving from the compositor. IDs
  // will be reused after the frame arrives from the compositor. Negative IDs
  // imply no mapping.
  int16 frame_id;

  // Pass through camera values
  gfx.mojom.Size? buffer_size;
  array<float, 16>? projection_matrix;
};

enum VRDisplayEventReason {
  NONE = 0,
  NAVIGATION = 1,
  MOUNTED = 2,
  UNMOUNTED = 3
};

// TODO(shaobo.yan@intel.com) : Add comments to describe these interfaces about
// how to use and where they live.
interface VRService {
  // TODO(shaobo.yan@intel.com, https://crbug.com/701027): Use a factory
  // function which takes a VRServiceClient so we will never have a
  // half-initialized VRService.
  SetClient(VRServiceClient client) => ();
  // Inform the service that the page is listening for vrdisplayactivate events.
  // TODO(mthiesse): Move SetListeningForActivate onto VRDisplay.
  SetListeningForActivate(bool listening);
};

interface VRServiceClient {
  OnDisplayConnected(VRDisplayHost display, VRDisplayClient& request,
                     VRDisplayInfo display_info);
};

// After submitting a frame, the VRPresentationProvider will notify the client
// about several stages of the render pipeline.  This allows pipelining
// efficiency.  Following VRPresentationProvider::Submit*, the submitted frame
// will be transferred (read from, perhaps copied to another texture), and then
// rendered (submitted to the underlying VR API).
// The client lives in the render process, implemented by VRDisplay.
//
// See VRDisplayFrameTransportConfiguration which configures which of these
// callbacks are in use.
interface VRSubmitFrameClient {
  // The VRPresentationProvider calls this to indicate that the submitted frame
  // has been transferred, so the backing data (mailbox or GpuMemoryBuffer) can
  // be reused or discarded.  Note that this is a convenience/optimization
  // feature, not a security feature - if a site discards the data early we may
  // drop a frame, but nothing will otherwise misbehave.
  // When the frame wasn't successfully transferred, the client should create a
  // new mailbox/GpuMemoryBuffer rather than reusing an existing one to recover
  // for subsequent frames.
  OnSubmitFrameTransferred(bool success);

  // The VRPresentationProvider calls this after the frame was handed off to the
  // underlying VR API. This allows some pipelining of CPU/GPU work, while
  // delaying expensive tasks for a subsequent frame until the current frame has
  // completed.
  OnSubmitFrameRendered();

  // This callback provides a GpuFence corresponding to the previous frame's
  // rendering completion, intended for use with a server wait issued before
  // the following wait to prevent its rendering work from competing with
  // the previous frame.
  OnSubmitFrameGpuFence(gfx.mojom.GpuFenceHandle gpu_fence_handle);
};


// Provides a communication channel from the renderer to the browser-side host
// of a (device/) VrDisplayImpl.
interface VRDisplayHost {
  // Request to initialize a session in the browser process. The return value
  // indicates if the session was successfully initialized or not.
  // TODO(https://crbug.com/842025): Refactor VR device interfaces to better
  // reflect WebXR.
  RequestSession(
    XRSessionOptions options,
    bool triggered_by_displayactive) => (XRSession? session);
  SupportsSession(XRSessionOptions options) => (bool supports_session);

  ExitPresent();
};

// Provides the necessary functionality for a non-presenting WebXR session to
// draw magic window content.
// This interface is hosted in the Browser process, but will move to a sandboxed
// utility process on Windows.  The render process communicates with it.
// For AR displays (VRDisplayCapabilities.can_provide_pass_through_images
// is true), clients can use GetFrameData to get images.
// TODO(836478): rename VRMagicWindowProvider to NonImmersiveWindowProvider or
// similar.
interface VRMagicWindowProvider {
  // frame_data is optional and will not be set if and only if the call fails
  // for some reason, such as device disconnection.
  GetFrameData() => (XRFrameData? frame_data);

  // Different devices can have different native orientations - 0
  // is the native orientation, and then increments of 90 degrees
  // from there.
  UpdateSessionGeometry(
      gfx.mojom.Size frame_size,
      display.mojom.Rotation display_rotation);

  // Performs a raycast into the magic window scene and returns a list of
  // XRHitResults sorted from closest to furthest hit from the ray. Each
  // hit result contains a hit_matrix containing the transform of the hit
  // where the rotation represents the normal of the surface hit.
  // An empty result list means there were no hits. If a nullopt is returned,
  // there was an error.
  // TODO(https://crbug.com/842025): have one "session" type, merging
  // VRMagicWindowProvider and VRPresentationProvider because RequestHitTest
  // makes sense for both types of sessions.
  RequestHitTest(XRRay ray) => (array<XRHitResult>? results);
};

// Provides the necessary functionality for a presenting WebVR page to draw
// frames for a VrDisplay.
// This interface is hosted in the Browser process, but will move to a sandboxed
// utility process on Windows.  The render process communicates with it.
interface VRPresentationProvider {
  // frame_data is optional and will not be set if and only if the call fails
  // for some reason, such as device disconnection.
  GetFrameData() => (XRFrameData? frame_data);

  UpdateLayerBounds(int16 frame_id, gfx.mojom.RectF left_bounds,
                    gfx.mojom.RectF right_bounds, gfx.mojom.Size source_size);

  // Call this if the animation loop exited without submitting a frame to
  // ensure that every GetFrameData has a matching Submit call. This happens for
  // WebXR if there were no drawing operations to the opaque framebuffer, and
  // for WebVR 1.1 if the application didn't call SubmitFrame. Usable with any
  // VRDisplayFrameTransportMethod. This path does *not* call the
  // SubmitFrameClient methods such as OnSubmitFrameTransferred. This is
  // intended to help separate frames while presenting, it may or may not
  // be called for the last animating frame when presentation ends.
  SubmitFrameMissing(int16 frame_id, gpu.mojom.SyncToken sync_token);

  // VRDisplayFrameTransportMethod SUBMIT_AS_MAILBOX_HOLDER
  SubmitFrame(int16 frame_id, gpu.mojom.MailboxHolder mailbox_holder,
              mojo_base.mojom.TimeDelta time_waited);

  // VRDisplayFrameTransportMethod SUBMIT_AS_TEXTURE_HANDLE
  // TODO(https://crbug.com/676224): Support preprocessing of mojom files, since
  // this is Windows only.
  SubmitFrameWithTextureHandle(int16 frameId, handle texture);

  // VRDisplayFrameTransportMethod DRAW_INTO_TEXTURE_MAILBOX
  SubmitFrameDrawnIntoTexture(int16 frameId, gpu.mojom.SyncToken sync_token,
                              mojo_base.mojom.TimeDelta time_waited);
};

interface VRDisplayClient {
  OnChanged(VRDisplayInfo display);
  OnExitPresent();
  OnBlur();
  OnFocus();
  OnActivate(VRDisplayEventReason reason) => (bool will_not_present);
  OnDeactivate(VRDisplayEventReason reason);
};