Monado OpenXR Runtime
xrt_system.h
Go to the documentation of this file.
1// Copyright 2020-2024, Collabora, Ltd.
2// Copyright 2023, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Header for system objects.
7 * @author Jakob Bornecrantz <jakob@collabora.com>
8 * @author Korcan Hussein <korcan.hussein@collabora.com>
9 * @ingroup xrt_iface
10 */
11
12#pragma once
13
14#include "xrt/xrt_compiler.h"
15#include "xrt/xrt_defines.h"
16#include "xrt/xrt_device.h"
17
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23struct xrt_instance;
25struct xrt_session;
27struct xrt_session_info;
28
29
30/*
31 *
32 * System.
33 *
34 */
35
36#define XRT_SYSTEM_ID 1
37
38#define XRT_MAX_SYSTEM_NAME_SIZE 256
39
40/*!
41 * Properties provided by the system.
42 */
44{
45 uint32_t vendor_id;
46 char name[XRT_MAX_SYSTEM_NAME_SIZE];
47};
48
49/*!
50 * A system is a collection of devices, policies and optionally a compositor
51 * that is organised into a chosive group that is usable by one user, most of
52 * the functionality of a system is exposed through other objects, this is the
53 * main object. It is from this you create sessions that is used to by apps to
54 * interact with the "system".
55 *
56 * Sibling objects: @ref xrt_system_devices, @ref xrt_system_compositor and
57 * @ref xrt_space_overseer.
58 *
59 * @ingroup xrt_iface
60 */
62{
63 /*!
64 * Create a @ref xrt_session and optionally a @ref xrt_compositor_native
65 * for this system.
66 *
67 * param[in] xsys Pointer to self.
68 * param[in] xsi Session info.
69 * param[out] out_xs Created session.
70 * param[out] out_xcn Native compositor for this session, optional.
71 */
73 const struct xrt_session_info *xsi,
74 struct xrt_session **out_xs,
75 struct xrt_compositor_native **out_xcn);
76
77 /*!
78 * Destroy the system, must be destroyed after system devices and system
79 * compositor has been destroyed.
80 *
81 * Code consuming this interface should use @ref xrt_system_destroy.
82 *
83 * @param xsys Pointer to self
84 */
85 void (*destroy)(struct xrt_system *xsys);
86
87 struct xrt_system_properties properties;
88};
89
90/*!
91 * @copydoc xrt_system::create_session
92 *
93 * Helper for calling through the function pointer.
94 *
95 * @public @memberof xrt_system
96 */
97static inline xrt_result_t
99 const struct xrt_session_info *xsi,
100 struct xrt_session **out_xs,
101 struct xrt_compositor_native **out_xcn)
102{
103 return xsys->create_session(xsys, xsi, out_xs, out_xcn);
104}
105
106/*!
107 * Destroy an xrt_system - helper function.
108 *
109 * @param[in,out] xsys_ptr A pointer to the xrt_system struct pointer.
110 *
111 * Will destroy the system if `*xsys_ptr` is not NULL. Will then set
112 * `*xsys_ptr` to NULL.
113 *
114 * @public @memberof xrt_system
115 */
116static inline void
118{
119 struct xrt_system *xsys = *xsys_ptr;
120 if (xsys == NULL) {
121 return;
122 }
123
124 *xsys_ptr = NULL;
125 xsys->destroy(xsys);
126}
127
128
129/*
130 *
131 * System devices.
132 *
133 */
134
135/*!
136 * Maximum number of devices simultaneously usable by an implementation of
137 * @ref xrt_system_devices
138 *
139 * @ingroup xrt_iface
140 */
141#define XRT_SYSTEM_MAX_DEVICES (32)
142
143/*!
144 * Data associating a device index (in @ref xrt_system_devices::xdevs) with a
145 * given "role" for dynamic role switching.
146 *
147 * For each of the named roles, a negative value means unpopulated/not available.
148 *
149 * Populated by a call from the @ref xrt_system_devices interface.
150 *
151 * When the caller of @ref xrt_system_devices_get_roles sees a change (based on
152 * comparing @ref generation_id) the caller must do the needed actions to handle
153 * device changes. For example, for the OpenXR state tracker this may include
154 * rebinding, queuing a change to the current interaction profile, and queuing
155 * the events associated with such a change.
156 *
157 * @see xrt_system_devices
158 * @ingroup xrt_iface
159 */
161{
162 /*!
163 * Monotonically increasing generation counter for the association
164 * between role and index.
165 *
166 * Increment whenever the roles are changed.
167 *
168 * All valid values are greater then zero; this is to
169 * make init easier where any cache can start at zero and be guaranteed
170 * to be replaced with a new @ref xrt_system_roles.
171 */
173
174 /*!
175 * Index in @ref xrt_system_devices::xdevs for the user's left
176 * controller/hand, or negative if none available.
177 */
178 int32_t left;
179
180 /*!
181 * Index in @ref xrt_system_devices::xdevs for the user's right
182 * controller/hand, or negative if none available.
183 */
184 int32_t right;
185
186 /*!
187 * Index in @ref xrt_system_devices::xdevs for the user's gamepad
188 * device, or negative if none available.
189 */
190 int32_t gamepad;
191
192 enum xrt_device_name left_profile;
193
194 enum xrt_device_name right_profile;
195
196 enum xrt_device_name gamepad_profile;
197};
198
199/*!
200 * Guaranteed invalid constant for @ref xrt_system_roles, not using designated
201 * initializers due to C++.
202 *
203 * @ingroup xrt_iface
204 * @relates xrt_system_roles
205 */
206#define XRT_SYSTEM_ROLES_INIT \
207 { \
208 0, -1, -1, -1, XRT_DEVICE_INVALID, XRT_DEVICE_INVALID, XRT_DEVICE_INVALID, \
209 }
210
211
212/*!
213 * A collection of @ref xrt_device, and an interface for identifying the roles
214 * they have been assigned.
215 *
216 * @see xrt_device, xrt_instance.
217 */
219{
220 /*!
221 * All devices known in the system.
222 *
223 * This is conventionally considered the "owning" reference to the devices.
224 * Valid entries are contiguous.
225 */
227
228 /*!
229 * The number of elements in @ref xdevs that are valid.
230 */
232
233 /*!
234 * Observing pointers for devices in some static (unchangeable) roles.
235 *
236 * All pointers in this struct must also exist in @ref xdevs. The
237 * association between a member of this struct and a given device
238 * cannot change during runtime.
239 */
240 struct
241 {
242 /*!
243 * An observing pointer to the device serving as the "head"
244 * (and HMD).
245 *
246 * Required.
247 */
249
250 /*!
251 * An observing pointer to the device providing eye tracking
252 * (optional).
253 */
255
256 /*!
257 * An observing pointer to the device providing face tracking
258 * (optional).
259 */
261
262 /*!
263 * An observing pointer to the device providing body tracking
264 * (optional).
265 */
267
268 /*!
269 * Devices providing optical (or otherwise more directly
270 * measured than from controller estimation) hand tracking.
271 */
272 struct
273 {
274
275 /*!
276 * An observing pointer to the device providing hand
277 * tracking for the left hand (optional).
278 *
279 * Currently this is used for both optical and
280 * controller driven hand-tracking.
281 */
283
284 /*!
285 * An observing pointer to the device providing hand
286 * tracking for the right hand (optional).
287 *
288 * Currently this is used for both optical and
289 * controller driven hand-tracking.
290 */
294
295
296 /*!
297 * Function to get the dynamic input device roles from this system
298 * devices, see @ref xrt_system_roles for more information.
299 *
300 * @param xsysd Pointer to self
301 * @param[out] out_roles Pointer to xrt_system_roles
302 */
303 xrt_result_t (*get_roles)(struct xrt_system_devices *xsysd, struct xrt_system_roles *out_roles);
304
305 /*!
306 * Increment the usage count of a feature.
307 * When the feature is used for the first time, then the feature will be begun.
308 *
309 * @param xsysd Pointer to self
310 * @param feature Which feature is being counted.
311 */
313
314 /*!
315 * Decrement the usage count of a feature.
316 * When the feature is not used by the current application any more, then the feature will be ended.
317 *
318 * @param xsysd Pointer to self
319 * @param feature Which feature is being counted.
320 */
322
323 /*!
324 * Destroy all the devices that are owned by this system devices.
325 *
326 * Code consuming this interface should use @ref xrt_system_devices_destroy.
327 *
328 * @param xsysd Pointer to self
329 */
330 void (*destroy)(struct xrt_system_devices *xsysd);
331};
332
333/*!
334 * @copydoc xrt_system_devices::get_roles
335 *
336 * Helper for calling through the function pointer.
337 *
338 * @public @memberof xrt_system_devices
339 */
340static inline xrt_result_t
342{
343 return xsysd->get_roles(xsysd, out_roles);
344}
345
346/*!
347 * @copydoc xrt_system_devices::feature_inc
348 *
349 * Helper for calling through the function pointer.
350 *
351 * @public @memberof xrt_system_devices
352 */
353static inline xrt_result_t
355{
356 return xsysd->feature_inc(xsysd, type);
357}
358
359/*!
360 * @copydoc xrt_system_devices::feature_dec
361 *
362 * Helper for calling through the function pointer.
363 *
364 * @public @memberof xrt_system_devices
365 */
366static inline xrt_result_t
368{
369 return xsysd->feature_dec(xsysd, type);
370}
371
372/*!
373 * Destroy an xrt_system_devices and owned devices - helper function.
374 *
375 * @param[in,out] xsysd_ptr A pointer to the xrt_system_devices struct pointer.
376 *
377 * Will destroy the system devices if `*xsysd_ptr` is not NULL. Will then set
378 * `*xsysd_ptr` to NULL.
379 *
380 * @public @memberof xrt_system_devices
381 */
382static inline void
384{
385 struct xrt_system_devices *xsysd = *xsysd_ptr;
386 if (xsysd == NULL) {
387 return;
388 }
389
390 *xsysd_ptr = NULL;
391 xsysd->destroy(xsysd);
392}
393
394
395#ifdef __cplusplus
396}
397#endif
#define XRT_SYSTEM_MAX_DEVICES
Maximum number of devices simultaneously usable by an implementation of xrt_system_devices.
Definition: xrt_system.h:141
enum xrt_result xrt_result_t
Result type used across Monado.
Main compositor server interface.
Definition: xrt_compositor.h:2224
A single HMD or input device.
Definition: xrt_device.h:241
This interface acts as a root object for Monado.
Definition: xrt_instance.h:114
Session information, mostly overlay extension data.
Definition: xrt_compositor.h:930
The XRT representation of XrSession, this object does not have all of the functionality of a session,...
Definition: xrt_session.h:246
A collection of xrt_device, and an interface for identifying the roles they have been assigned.
Definition: xrt_system.h:219
static xrt_result_t xrt_system_devices_feature_inc(struct xrt_system_devices *xsysd, enum xrt_device_feature_type type)
Increment the usage count of a feature.
Definition: xrt_system.h:354
xrt_result_t(* feature_inc)(struct xrt_system_devices *xsysd, enum xrt_device_feature_type type)
Increment the usage count of a feature.
Definition: xrt_system.h:312
size_t xdev_count
The number of elements in xdevs that are valid.
Definition: xrt_system.h:231
static xrt_result_t xrt_system_devices_get_roles(struct xrt_system_devices *xsysd, struct xrt_system_roles *out_roles)
Function to get the dynamic input device roles from this system devices, see xrt_system_roles for mor...
Definition: xrt_system.h:341
xrt_result_t(* get_roles)(struct xrt_system_devices *xsysd, struct xrt_system_roles *out_roles)
Function to get the dynamic input device roles from this system devices, see xrt_system_roles for mor...
Definition: xrt_system.h:303
static xrt_result_t xrt_system_devices_feature_dec(struct xrt_system_devices *xsysd, enum xrt_device_feature_type type)
Decrement the usage count of a feature.
Definition: xrt_system.h:367
void(* destroy)(struct xrt_system_devices *xsysd)
Destroy all the devices that are owned by this system devices.
Definition: xrt_system.h:330
struct xrt_device * head
An observing pointer to the device serving as the "head" (and HMD).
Definition: xrt_system.h:248
struct xrt_device * face
An observing pointer to the device providing face tracking (optional).
Definition: xrt_system.h:260
struct xrt_device * eyes
An observing pointer to the device providing eye tracking (optional).
Definition: xrt_system.h:254
struct xrt_device * xdevs[(32)]
All devices known in the system.
Definition: xrt_system.h:226
xrt_result_t(* feature_dec)(struct xrt_system_devices *xsysd, enum xrt_device_feature_type type)
Decrement the usage count of a feature.
Definition: xrt_system.h:321
struct xrt_device * left
An observing pointer to the device providing hand tracking for the left hand (optional).
Definition: xrt_system.h:282
struct xrt_system_devices::@239 static_roles
Observing pointers for devices in some static (unchangeable) roles.
struct xrt_system_devices::@239::@240 hand_tracking
Devices providing optical (or otherwise more directly measured than from controller estimation) hand ...
struct xrt_device * right
An observing pointer to the device providing hand tracking for the right hand (optional).
Definition: xrt_system.h:291
struct xrt_device * body
An observing pointer to the device providing body tracking (optional).
Definition: xrt_system.h:266
static void xrt_system_devices_destroy(struct xrt_system_devices **xsysd_ptr)
Destroy an xrt_system_devices and owned devices - helper function.
Definition: xrt_system.h:383
Properties provided by the system.
Definition: xrt_system.h:44
Data associating a device index (in xrt_system_devices::xdevs) with a given "role" for dynamic role s...
Definition: xrt_system.h:161
int32_t right
Index in xrt_system_devices::xdevs for the user's right controller/hand, or negative if none availabl...
Definition: xrt_system.h:184
uint64_t generation_id
Monotonically increasing generation counter for the association between role and index.
Definition: xrt_system.h:172
int32_t gamepad
Index in xrt_system_devices::xdevs for the user's gamepad device, or negative if none available.
Definition: xrt_system.h:190
int32_t left
Index in xrt_system_devices::xdevs for the user's left controller/hand, or negative if none available...
Definition: xrt_system.h:178
A system is a collection of devices, policies and optionally a compositor that is organised into a ch...
Definition: xrt_system.h:62
xrt_result_t(* create_session)(struct xrt_system *xsys, const struct xrt_session_info *xsi, struct xrt_session **out_xs, struct xrt_compositor_native **out_xcn)
Create a xrt_session and optionally a xrt_compositor_native for this system.
Definition: xrt_system.h:72
static xrt_result_t xrt_system_create_session(struct xrt_system *xsys, const struct xrt_session_info *xsi, struct xrt_session **out_xs, struct xrt_compositor_native **out_xcn)
Create a xrt_session and optionally a xrt_compositor_native for this system.
Definition: xrt_system.h:98
static void xrt_system_destroy(struct xrt_system **xsys_ptr)
Destroy an xrt_system - helper function.
Definition: xrt_system.h:117
void(* destroy)(struct xrt_system *xsys)
Destroy the system, must be destroyed after system devices and system compositor has been destroyed.
Definition: xrt_system.h:85
Header holding common defines.
Common defines and enums for XRT.
xrt_device_name
A enum that is used to name devices so that the state trackers can reason about the devices easier.
Definition: xrt_defines.h:712
Header defining an xrt display or controller device.
xrt_device_feature_type
Higher level features for devices.
Definition: xrt_device.h:226