// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module device.mojom;
import "skia/public/mojom/bitmap.mojom";
import "ui/gfx/geometry/mojom/geometry.mojom";
import "mojo/public/mojom/base/time.mojom";
// Used primarily in logging to indicate why a session was rejecting to aid
// developer debuggability. To this end, rather than re-using an existing enum
// value, if it doesn't match your error case, a new value should be added.
// Note that this is converted to a console log, and thus the numbers can still
// be re-arranged as needed (e.g. if a value should be removed).
enum RequestSessionError {
// Indicates that another session is already using the hardware that a new
// session would need exclusive control over.
EXISTING_IMMERSIVE_SESSION = 1,
// Used to indicate that something happened to the connection between either
// renderer and browser or browser and device processes, and thus a session
// could not be brokered.
INVALID_CLIENT = 2,
// The user denied consent for one or more required features in the session
// configuration (or the mode).
USER_DENIED_CONSENT = 3,
// No runtime was present which supported both the requested mode and all
// required features.
NO_RUNTIME_FOUND = 4,
// The runtime could not successfully create a session.
UNKNOWN_RUNTIME_ERROR = 5,
// The runtime requires additional installation which could not be completed.
RUNTIME_INSTALL_FAILURE = 6,
// While processing/creating a session the "best fit" runtime changed (either
// a better runtime was added or the only supported runtime was removed).
RUNTIMES_CHANGED = 7,
// Something prevented the session from entering fullscreen, which was
// required by part of the session configuration.
FULLSCREEN_ERROR = 8,
// We are unable to determine why the request failed. This should be used very
// sparingly, (e.g. Crashes, destructors, etc.)
UNKNOWN_FAILURE = 9,
};
// These correspond with the features from the WebXR Spec:
// https://immersive-web.github.io/webxr/#feature-descriptor
enum XRSessionFeature {
REF_SPACE_VIEWER = 1,
REF_SPACE_LOCAL = 2,
REF_SPACE_LOCAL_FLOOR = 3,
REF_SPACE_BOUNDED_FLOOR = 4,
REF_SPACE_UNBOUNDED = 5,
DOM_OVERLAY = 6,
HIT_TEST = 7,
LIGHT_ESTIMATION = 8,
ANCHORS = 9,
CAMERA_ACCESS = 10,
PLANE_DETECTION = 11,
DEPTH = 12,
IMAGE_TRACKING = 13,
HAND_INPUT = 14,
SECONDARY_VIEWS = 15,
LAYERS = 16,
FRONT_FACING = 17,
};
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
// These enum names come from the WebXR spec:
// https://immersive-web.github.io/webxr/#xrsessionmode-enum
enum XRSessionMode {
kInline = 1,
kImmersiveVr = 2,
kImmersiveAr = 3,
};
struct XRTrackedImage {
skia.mojom.BitmapN32 bitmap;
gfx.mojom.Size size_in_pixels;
float width_in_meters;
};
enum XRDepthUsage {
kCPUOptimized = 1,
kGPUOptimized = 2,
};
enum XRDepthDataFormat {
kLuminanceAlpha = 1,
kFloat32 = 2,
kUnsignedShort = 3,
};
// Structure used to configure depth sensing API at session creation.
// If the device is unable to create the session given the preferences expressed
// in the options, the session will not have depth sensing API enabled. In case
// it was a required feature, this means that session creation will fail.
struct XRDepthOptions {
// Ordered array of depth sensing usage preferences. At session creation,
// the device will pick the depth sensing usage value that it supports,
// starting from the lowest-indexed one. If the array is empty, then we are
// allowed to select the optimal XRDepthUsage ourselves (this will usually
// match whatever the backing device's APIs support by default).
array<XRDepthUsage> usage_preferences;
// Ordered array of depth sensing data format preferences. At session
// creation, the device will pick the depth sensing data format value that it
// supports, starting from the lowest-indexed one. If the array is empty, then
// we are allowed to select the optimal XRDepthDataFormat ourselves (this will
// usually match whatever the backing device's APIs support by default).
array<XRDepthDataFormat> data_format_preferences;
};
struct XRSessionOptions {
// Represents the type of session that is being requested.
XRSessionMode mode;
// Represents the set of requested features that have been marked "required",
// if any of these features are missing, a session will not be created.
array<XRSessionFeature> required_features;
// Represents the set of requested features that have been marked "optional",
// if any of these features are missing, a session will still be created, but
// the feature will not be added to the enabled_features set on the XRSession
// struct that is returned.
array<XRSessionFeature> optional_features;
array<XRTrackedImage> tracked_images;
// Must be present if either optional or required features contain
// depth sensing API.
XRDepthOptions? depth_options;
// ID of this request, used for tracing.
uint64 trace_id;
};
// WebXR logging frame that is sent periodically to measure the
// performance of the WebXR session.
struct XrFrameStatistics {
// The trace_id is used to correlate the frame statistics with the
// session creation request. Check same trace_id in XRSessionOptions.
uint64 trace_id;
// The time span for which these reported statistics are reported.
mojo_base.mojom.TimeDelta duration;
// The number of frames that were sent to the device in the
// specified duration.
uint64 num_frames;
// The number of frames that were dropped by the device.
uint64 dropped_frames;
// The duration between requesting a frame and receiving the frame
// data back from the device.
mojo_base.mojom.TimeDelta frame_data_time;
// The duration for animation frame callback execution.
mojo_base.mojom.TimeDelta page_animation_frame_time;
};
struct XrLogMessage {
// The trace_id is used to correlate the frame statistics with the
// session creation request. Check same trace_id in XRSessionOptions.
uint64 trace_id;
// The console message to be logged.
string message;
};