Monado OpenXR Runtime
u_device.h
Go to the documentation of this file.
1// Copyright 2019-2023, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Misc helpers for device drivers.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @author Rylie Pavlik <rylie.pavlik@collabora.com>
8 * @author Moses Turner <moses@collabora.com>
9 * @ingroup aux_util
10 */
11
12#pragma once
13
14#include "xrt/xrt_compiler.h"
15#include "xrt/xrt_device.h"
16#include "xrt/xrt_tracking.h"
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22
23extern const struct xrt_matrix_2x2 u_device_rotation_right;
24extern const struct xrt_matrix_2x2 u_device_rotation_left;
25extern const struct xrt_matrix_2x2 u_device_rotation_ident;
26extern const struct xrt_matrix_2x2 u_device_rotation_180;
27
28enum u_device_alloc_flags
29{
30 // clang-format off
31 U_DEVICE_ALLOC_NO_FLAGS = 0,
32 U_DEVICE_ALLOC_HMD = 1u << 0u,
33 U_DEVICE_ALLOC_TRACKING_NONE = 1u << 1u,
34 // clang-format on
35};
36
37/*!
38 *
39 * Info to describe 2D extents of a device's screen
40 *
41 */
43{
44 uint32_t w_pixels; // Width of entire screen in pixels
45 uint32_t h_pixels; // Height of entire screen
46};
47
48/*!
49 *
50 * Info to describe a very simple headset with diffractive lens optics.
51 *
52 */
54{
55 struct
56 {
57 uint32_t w_pixels;
58 uint32_t h_pixels;
59 float w_meters;
60 float h_meters;
61 } display;
62
63 float lens_horizontal_separation_meters;
64 float lens_vertical_position_meters;
65
66 float fov[XRT_MAX_VIEWS];
67};
68
69/*!
70 * Setup the device information given a very simple info struct.
71 *
72 * @return true on success.
73 * @ingroup aux_util
74 */
75bool
76u_device_setup_one_eye(struct xrt_device *xdev, const struct u_device_simple_info *info);
77
78/*!
79 * Setup the device information given a very simple info struct.
80 *
81 * @return true on success.
82 * @ingroup aux_util
83 */
84bool
86
87/*!
88 * Setup the device's display's 2D extents.
89 * Good for headsets without traditional VR optics.
90 *
91 * @return true on success.
92 * @ingroup aux_util
93 */
94bool
95u_extents_2d_split_side_by_side(struct xrt_device *xdev, const struct u_extents_2d *extents);
96
97
98/*!
99 * Dump the device config to stderr.
100 *
101 * @ingroup aux_util
102 */
103void
104u_device_dump_config(struct xrt_device *xdev, const char *prefix, const char *prod);
105
106#define U_DEVICE_ALLOCATE(type, flags, input_count, output_count) \
107 ((type *)u_device_allocate(flags, sizeof(type), input_count, output_count))
108
109
110/*!
111 * Helper function to allocate a device plus inputs in the same allocation
112 * placed after the device in memory.
113 *
114 * Will setup any pointers and num values.
115 *
116 * @ingroup aux_util
117 */
118void *
119u_device_allocate(enum u_device_alloc_flags flags, size_t size, size_t input_count, size_t output_count);
120
121/*!
122 * Helper function to free a device and any data hanging of it.
123 *
124 * @ingroup aux_util
125 */
126void
127u_device_free(struct xrt_device *xdev);
128
129
130#define XRT_DEVICE_ROLE_UNASSIGNED (-1)
131
132/*!
133 * Helper function to assign head, left hand and right hand roles.
134 *
135 * @ingroup aux_util
136 */
137void
138u_device_assign_xdev_roles(struct xrt_device **xdevs, size_t xdev_count, int *head, int *left, int *right);
139
140/*!
141 * Helper function for `get_view_pose` in an HMD driver.
142 *
143 * Takes in a translation from the left to right eye, and returns a center to left or right eye transform that assumes
144 * the eye relation is symmetrical around the tracked point ("center eye"). Knowing IPD is a subset of this: If you know
145 * IPD better than the overall Monado system, copy @p eye_relation and put your known IPD in @p real_eye_relation->x
146 *
147 * If you have rotation, apply it after calling this function.
148 *
149 * @param eye_relation 3D translation from left eye to right eye.
150 * @param view_index 0 for left, 1 for right.
151 * @param out_pose The output pose to populate. Will receive translation, with an identity rotation.
152 */
153void
154u_device_get_view_pose(const struct xrt_vec3 *eye_relation, uint32_t view_index, struct xrt_pose *out_pose);
155
156
157/*
158 *
159 * Default implementation of functions.
160 *
161 */
162
163/*!
164 * Helper function to implement @ref xrt_device::get_view_poses in a HMD driver.
165 *
166 * The field @ref xrt_device::hmd needs to be set and valid.
167 */
168void
170 const struct xrt_vec3 *default_eye_relation,
171 int64_t at_timestamp_ns,
172 uint32_t view_count,
173 struct xrt_space_relation *out_head_relation,
174 struct xrt_fov *out_fovs,
175 struct xrt_pose *out_poses);
176
177
178/*
179 *
180 * No-op implementation of functions.
181 *
182 */
183
184/*!
185 * Noop function for @ref xrt_device::update_inputs,
186 * should only be used from a device with any inputs.
187 *
188 * @ingroup aux_util
189 */
192
193
194/*
195 *
196 * Not implemented function helpers.
197 *
198 */
199
200/*!
201 * Not implemented function for @ref xrt_device::get_hand_tracking.
202 *
203 * @ingroup aux_util
204 */
205void
207 enum xrt_input_name name,
208 uint64_t desired_timestamp_ns,
209 struct xrt_hand_joint_set *out_value,
210 uint64_t *out_timestamp_ns);
211
212/*!
213 * Not implemented function for @ref xrt_device::set_output.
214 *
215 * @ingroup aux_util
216 */
217void
218u_device_ni_set_output(struct xrt_device *xdev, enum xrt_output_name name, const union xrt_output_value *value);
219
220/*!
221 * Not implemented function for @ref xrt_device::get_view_poses.
222 *
223 * @ingroup aux_util
224 */
225void
227 const struct xrt_vec3 *default_eye_relation,
228 int64_t at_timestamp_ns,
229 uint32_t view_count,
230 struct xrt_space_relation *out_head_relation,
231 struct xrt_fov *out_fovs,
232 struct xrt_pose *out_poses);
233
234/*!
235 * Not implemented function for @ref xrt_device::compute_distortion.
236 *
237 * @ingroup aux_util
238 */
239bool
241 struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *out_result);
242
243/*!
244 * Not implemented function for @ref xrt_device::get_visibility_mask.
245 *
246 * @ingroup aux_util
247 */
250 enum xrt_visibility_mask_type type,
251 uint32_t view_index,
252 struct xrt_visibility_mask **out_mask);
253
254/*!
255 * Not implemented function for @ref xrt_device::is_form_factor_available.
256 *
257 * @ingroup aux_util
258 */
259bool
261
262/*!
263 * Not implemented function for @ref xrt_device::get_battery_status.
264 *
265 * @ingroup aux_util
266 */
268u_device_ni_get_battery_status(struct xrt_device *xdev, bool *out_present, bool *out_charging, float *out_charge);
269
270
271#ifdef __cplusplus
272}
273#endif
void u_device_ni_get_view_poses(struct xrt_device *xdev, const struct xrt_vec3 *default_eye_relation, int64_t at_timestamp_ns, uint32_t view_count, struct xrt_space_relation *out_head_relation, struct xrt_fov *out_fovs, struct xrt_pose *out_poses)
Not implemented function for xrt_device::get_view_poses.
Definition: u_device.c:512
bool u_device_setup_split_side_by_side(struct xrt_device *xdev, const struct u_device_simple_info *info)
Setup the device information given a very simple info struct.
Definition: u_device.c:204
void u_device_assign_xdev_roles(struct xrt_device **xdevs, size_t xdev_count, int *head, int *left, int *right)
Helper function to assign head, left hand and right hand roles.
Definition: u_device.c:361
void u_device_free(struct xrt_device *xdev)
Helper function to free a device and any data hanging of it.
Definition: u_device.c:331
bool u_extents_2d_split_side_by_side(struct xrt_device *xdev, const struct u_extents_2d *extents)
Setup the device's display's 2D extents.
Definition: u_device.c:131
xrt_result_t u_device_ni_get_battery_status(struct xrt_device *xdev, bool *out_present, bool *out_charging, float *out_charge)
Not implemented function for xrt_device::get_battery_status.
Definition: u_device.c:549
void u_device_ni_set_output(struct xrt_device *xdev, enum xrt_output_name name, const union xrt_output_value *value)
Not implemented function for xrt_device::set_output.
Definition: u_device.c:506
void u_device_dump_config(struct xrt_device *xdev, const char *prefix, const char *prod)
Dump the device config to stderr.
Definition: u_device.c:87
bool u_device_setup_one_eye(struct xrt_device *xdev, const struct u_device_simple_info *info)
Setup the device information given a very simple info struct.
Definition: u_device.c:160
xrt_result_t u_device_ni_get_visibility_mask(struct xrt_device *xdev, enum xrt_visibility_mask_type type, uint32_t view_index, struct xrt_visibility_mask **out_mask)
Not implemented function for xrt_device::get_visibility_mask.
Definition: u_device.c:532
void u_device_ni_get_hand_tracking(struct xrt_device *xdev, enum xrt_input_name name, uint64_t desired_timestamp_ns, struct xrt_hand_joint_set *out_value, uint64_t *out_timestamp_ns)
Not implemented function for xrt_device::get_hand_tracking.
Definition: u_device.c:496
bool u_device_ni_is_form_factor_available(struct xrt_device *xdev, enum xrt_form_factor form_factor)
Not implemented function for xrt_device::is_form_factor_available.
Definition: u_device.c:542
void * u_device_allocate(enum u_device_alloc_flags flags, size_t size, size_t input_count, size_t output_count)
Helper function to allocate a device plus inputs in the same allocation placed after the device in me...
Definition: u_device.c:272
bool u_device_ni_compute_distortion(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *out_result)
Not implemented function for xrt_device::compute_distortion.
Definition: u_device.c:524
xrt_result_t u_device_noop_update_inputs(struct xrt_device *xdev)
Noop function for xrt_device::update_inputs, should only be used from a device with any inputs.
Definition: u_device.c:480
xrt_visibility_mask_type
Visibility mask, mirror of XrVisibilityMaskKHR.
Definition: xrt_defines.h:1965
xrt_form_factor
What form factor is this device, mostly maps onto OpenXR's XrFormFactor.
Definition: xrt_defines.h:1915
xrt_input_name
Every internal input source known to monado with a baked in type.
Definition: xrt_defines.h:1298
enum xrt_result xrt_result_t
Result type used across Monado.
xrt_output_name
Name of a output with a baked in type.
Definition: xrt_defines.h:1801
Definition: m_space.cpp:87
Info to describe a very simple headset with diffractive lens optics.
Definition: u_device.h:54
Info to describe 2D extents of a device's screen.
Definition: u_device.h:43
A single HMD or input device.
Definition: xrt_device.h:241
Describes a projection matrix fov.
Definition: xrt_defines.h:486
Joint set type used for hand tracking.
Definition: xrt_defines.h:1397
A tightly packed 2x2 matrix of floats.
Definition: xrt_defines.h:513
A pose composed of a position and orientation.
Definition: xrt_defines.h:465
A relation with two spaces, includes velocity and acceleration.
Definition: xrt_defines.h:657
Represents a uv triplet for distortion, basically just three xrt_vec2.
Definition: xrt_defines.h:261
A 3 element vector with single floats.
Definition: xrt_defines.h:271
Visibility mask helper, the indices and vertices are tightly packed after this struct.
Definition: xrt_visibility_mask.h:25
void u_device_get_view_poses(struct xrt_device *xdev, const struct xrt_vec3 *default_eye_relation, int64_t at_timestamp_ns, uint32_t view_count, struct xrt_space_relation *out_head_relation, struct xrt_fov *out_fovs, struct xrt_pose *out_poses)
Helper function to implement xrt_device::get_view_poses in a HMD driver.
Definition: u_device.c:453
void u_device_get_view_pose(const struct xrt_vec3 *eye_relation, uint32_t view_index, struct xrt_pose *out_pose)
Helper function for get_view_pose in an HMD driver.
Definition: u_device.c:422
A union of all output types.
Definition: xrt_defines.h:1887
Header holding common defines.
Header defining an xrt display or controller device.
Header defining the tracking system integration in Monado.