1// Copyright 2018 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5module device_test.mojom; 6 7import "ui/gfx/geometry/mojom/geometry.mojom"; 8import "ui/gfx/mojom/transform.mojom"; 9 10struct Color { 11 uint8 r; 12 uint8 g; 13 uint8 b; 14 uint8 a; 15}; 16 17enum Eye { 18 LEFT = 1, 19 RIGHT = 2 20}; 21 22struct SubmittedFrameData { 23 Color color; 24 25 Eye eye; 26 27 gfx.mojom.Rect viewport; 28 gfx.mojom.Size image_size; 29}; 30 31struct PoseFrameData { 32 gfx.mojom.Transform? device_to_origin; 33}; 34 35// Each component is the tangent of the up/down/left/right view frustum. 36struct ProjectionRaw { 37 float left; 38 float right; 39 float top; 40 float bottom; 41}; 42 43struct DeviceConfig { 44 float interpupillary_distance; // Distance between the eyes. 45 46 ProjectionRaw projection_left; 47 ProjectionRaw projection_right; 48}; 49 50struct ControllerAxisData { 51 float x; 52 float y; 53 uint8 axis_type; // Corresponds to OpenVR's EVRControllerAxisType 54}; 55 56enum TrackedDeviceClass { 57 kTrackedDeviceInvalid, 58 kTrackedDeviceHmd, 59 kTrackedDeviceController, 60 kTrackedDeviceGenericTracker, 61 kTrackedDeviceTrackingReference, 62 kTrackedDeviceDisplayRedirect 63}; 64 65enum ControllerRole { 66 kControllerRoleInvalid, // Test hook should ignore this controller. 67 kControllerRoleLeft, 68 kControllerRoleRight, 69 kControllerRoleVoice // Simulates voice input such as saying "select" in WMR. 70}; 71 72struct ControllerFrameData { 73 uint32 packet_number; 74 uint64 buttons_pressed; 75 uint64 buttons_touched; 76 uint64 supported_buttons; 77 array<ControllerAxisData, 5> axis_data; 78 PoseFrameData pose_data; 79 ControllerRole role = kControllerRoleInvalid; 80 bool is_valid; 81}; 82 83// Event type is used by test to simulate runtime events. 84enum EventType { 85 kSessionLost, 86 kVisibilityVisibleBlurred, 87 kInstanceLost, 88 kInteractionProfileChanged, 89 kNoEvent 90}; 91 92// InteractionProfileType is used to indicate which interaction profile runtime 93// would like to change to 94enum InteractionProfileType { 95 // Windows Mixed Reality Motion Controller 96 kWMRMotion, 97 // Khronos Simple Controller 98 kKHRSimple, 99 kInvalid, 100}; 101 102// EventData is used by test to pass all event related data. 103struct EventData { 104 EventType type = kNoEvent; 105 InteractionProfileType interaction_profile = kInvalid; 106}; 107 108// Tests may implement this, and register it to control behavior of devices for 109// tests. The test interface lives in the browser process, and may be consumed 110// by the device utility process. 111// It is only implemented when running in browser tests. 112interface XRTestHook { 113 // Notifies the test anytime the XR runtime receives a frame with the data 114 // that was submitted. 115 [Sync] OnFrameSubmitted(SubmittedFrameData frame_data) => (); 116 117 // Called by the XR runtime to retrieve the XR device's configuration set by 118 // the test. 119 [Sync] WaitGetDeviceConfig() => (DeviceConfig config); 120 121 // Called by the XR runtime to retrieve the XR device's pose while in a 122 // presenting/exclusive session. 123 [Sync] WaitGetPresentingPose() => (PoseFrameData data); 124 125 // Called by the XR runtime to retrieve the XR device's pose while in a 126 // magic window/non-exclusive session. 127 [Sync] WaitGetMagicWindowPose() => (PoseFrameData data); 128 129 // Called by the XR runtime to retrieve the ControllerRole of the device 130 // that the test has registered at the given index, i.e. which hand the 131 // controller is mapped to. 132 [Sync] WaitGetControllerRoleForTrackedDeviceIndex(uint32 index) => 133 (ControllerRole role); 134 135 // Called by the XR runtime to retrieve the class of the device that the test 136 // has registered at the given index, e.g. whether it is a controller or 137 // headset. 138 [Sync] WaitGetTrackedDeviceClass(uint32 index) => 139 (TrackedDeviceClass device_class); 140 141 // Called by the XR runtime anytime it updates its controller data to retrieve 142 // the controller data of the device that the test has registered at the 143 // given index, e.g. its current position and pressed buttons. 144 [Sync] WaitGetControllerData(uint32 index) => (ControllerFrameData data); 145 146 // Called by the OpenXR test to simulate runtime events. 147 [Sync] WaitGetEventData() => (EventData data); 148}; 149 150// Interface exposed by IsolatedXRService to allow browser tests to hook VR APIs 151// It is always hosted in the XRDevice process, but only has effects while 152// running in browser tests with mock implementations of runtimes. 153interface XRServiceTestHook { 154 [Sync] SetTestHook(pending_remote<XRTestHook>? hook) => (); 155 156 // Called by tests to trigger a termination of the Device Service Process 157 // To test that the product can properly handle the service either crashing 158 // or (more expectedly) being terminated by some other running process. 159 [Sync] TerminateDeviceServiceProcessForTesting() => (); 160}; 161