Monado OpenXR Runtime
xrt_instance.h
Go to the documentation of this file.
1// Copyright 2020-2024, Collabora, Ltd.
2// Copyright 2025, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Header for @ref xrt_instance object.
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_config_os.h"
17
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23
24struct xrt_prober;
25struct xrt_device;
26struct xrt_instance_android;
28struct xrt_system;
31
32struct _JavaVM;
33
34/*!
35 * Platform-specific information for an instance.
36 *
37 * Does not get transported between processes.
38 *
39 * @addtogroup xrt_iface
40 */
42{
43#if defined(XRT_OS_ANDROID) || defined(XRT_DOXYGEN)
44 /*!
45 * @name Android members
46 * @{
47 */
48 struct _JavaVM *vm;
49 void *context;
50 /*! @} */
51#else
52 //! To avoid empty structs.
53 uint32_t _padding;
54#endif
55};
56
57
58/*!
59 * @addtogroup xrt_iface
60 * @{
61 */
62
63#define XRT_MAX_APPLICATION_NAME_SIZE 128
64
65/*!
66 * Non-process-specific information provided by the application at instance create time.
67 *
68 * This is transported between client and server over IPC.
69 *
70 * @see xrt_instance_info
71 */
73{
74 char application_name[XRT_MAX_APPLICATION_NAME_SIZE];
75 bool ext_hand_tracking_enabled;
76 bool ext_hand_tracking_data_source_enabled;
77 bool ext_eye_gaze_interaction_enabled;
78 bool ext_future_enabled;
79 bool ext_hand_interaction_enabled;
80 bool htc_facial_tracking_enabled;
81 bool fb_body_tracking_enabled;
82 bool fb_face_tracking2_enabled;
83 bool meta_body_tracking_full_body_enabled;
84 bool meta_body_tracking_calibration_enabled;
85 bool android_face_tracking_enabled;
86};
87
88/*!
89 * Information provided by the application at instance create time.
90 *
91 * Some information may be process-specific.
92 */
94{
95 //! Generic data from application.
97
98 //! Process-specific, platform-specific data.
100};
101
102/*!
103 * @interface xrt_instance
104 *
105 * This interface acts as a root object for Monado.
106 * It typically either wraps an @ref xrt_prober or forms a connection to an
107 * out-of-process XR service.
108 *
109 * This is as close to a singleton object as there is in Monado: you should not
110 * create more than one xrt_instance implementation per process.
111 *
112 * Each "target" will provide its own (private) implementation of this
113 * interface, which is exposed by implementing xrt_instance_create().
114 *
115 * Additional information can be found in @ref understanding-targets.
116 *
117 * @sa ipc_instance_create
118 */
120{
121 /*!
122 * @name Interface Methods
123 *
124 * All implementations of the xrt_instance interface must
125 * populate all these function pointers with their implementation
126 * methods. To use this interface, see the helper functions.
127 * @{
128 */
129
130 /*!
131 * Checks if the system can be created with create_system().
132 */
133 xrt_result_t (*is_system_available)(struct xrt_instance *xinst, bool *out_available);
134
135 /*!
136 * Creates all of the system resources like the devices and system
137 * compositor. The system compositor is optional.
138 *
139 * Should only be called once.
140 *
141 * @note Code consuming this interface should use xrt_instance_create_system()
142 *
143 * @param xinst Pointer to self
144 * @param[out] out_xsys Return of system, required.
145 * @param[out] out_xsysd Return of devices, required.
146 * @param[out] out_xsysc Return of system compositor, optional.
147 *
148 * @see xrt_prober::probe, xrt_prober::select, xrt_gfx_provider_create_native
149 */
151 struct xrt_system **out_xsys,
152 struct xrt_system_devices **out_xsysd,
153 struct xrt_space_overseer **out_xso,
154 struct xrt_system_compositor **out_xsysc);
155
156 /*!
157 * Get the instance @ref xrt_prober, if any.
158 *
159 * If the instance is not using an @ref xrt_prober, it may return null.
160 *
161 * The instance retains ownership of the prober and is responsible for
162 * destroying it.
163 *
164 * Can be called multiple times. (The prober is usually created at
165 * instance construction time.)
166 *
167 * @note Code consuming this interface should use
168 * xrt_instance_get_prober().
169 *
170 * @param xinst Pointer to self
171 * @param[out] out_xp Pointer to xrt_prober pointer, will be populated
172 * or set to NULL.
173 *
174 * @return XRT_SUCCESS on success, other error code on error.
175 */
176 xrt_result_t (*get_prober)(struct xrt_instance *xinst, struct xrt_prober **out_xp);
177
178 /*!
179 * Destroy the instance and its owned objects, including the prober (if
180 * any).
181 *
182 * Code consuming this interface should use xrt_instance_destroy().
183 *
184 * @param xinst Pointer to self
185 */
186 void (*destroy)(struct xrt_instance *xinst);
187 /*!
188 * @}
189 */
190
191 /*!
192 * Instance information structure, including both platform and application info.
193 */
195
196 /*!
197 * CLOCK_MONOTONIC timestamp of the instance startup.
198 */
200
201 /*!
202 * An "aspect" of the xrt_instance interface, used only on Android.
203 *
204 * @see xrt_instance_android
205 */
206 struct xrt_instance_android *android_instance;
207};
208
209
210/*!
211 * @copydoc xrt_instance::create_system
212 *
213 * Helper for calling through the function pointer.
214 *
215 * @public @memberof xrt_instance
216 */
217static inline xrt_result_t
218xrt_instance_is_system_available(struct xrt_instance *xinst, bool *out_available)
219{
220 return xinst->is_system_available(xinst, out_available);
221}
222
223/*!
224 * @copydoc xrt_instance::create_system
225 *
226 * Helper for calling through the function pointer.
227 *
228 * @public @memberof xrt_instance
229 */
230static inline xrt_result_t
232 struct xrt_system **out_xsys,
233 struct xrt_system_devices **out_xsysd,
234 struct xrt_space_overseer **out_xso,
235 struct xrt_system_compositor **out_xsysc)
236{
237 return xinst->create_system(xinst, out_xsys, out_xsysd, out_xso, out_xsysc);
238}
239
240/*!
241 * @copydoc xrt_instance::get_prober
242 *
243 * Helper for calling through the function pointer.
244 *
245 * @public @memberof xrt_instance
246 */
247static inline xrt_result_t
248xrt_instance_get_prober(struct xrt_instance *xinst, struct xrt_prober **out_xp)
249{
250 return xinst->get_prober(xinst, out_xp);
251}
252
253/*!
254 * Destroy an xrt_instance - helper function.
255 *
256 * @param[in,out] xinst_ptr A pointer to your instance implementation pointer.
257 *
258 * Will destroy the instance if *xinst_ptr is not NULL. Will then set *xinst_ptr
259 * to NULL.
260 *
261 * @public @memberof xrt_instance
262 */
263static inline void
265{
266 struct xrt_instance *xinst = *xinst_ptr;
267 if (xinst == NULL) {
268 return;
269 }
270
271 xinst->destroy(xinst);
272 *xinst_ptr = NULL;
273}
274
275/*!
276 * @name Factory
277 * Implemented in each target.
278 * @{
279 */
280/*!
281 * Create an implementation of the xrt_instance interface.
282 *
283 * Creating more then one @ref xrt_instance is probably never the right thing
284 * to do, so avoid it.
285 *
286 * Each target must implement this function.
287 *
288 * @param[in] ii A pointer to a info struct containing information about the
289 * application.
290 * @param[out] out_xinst A pointer to an xrt_instance pointer. Will be
291 * populated.
292 *
293 * @return 0 on success
294 *
295 * @relates xrt_instance
296 */
298xrt_instance_create(struct xrt_instance_info *ii, struct xrt_instance **out_xinst);
299
300/*!
301 * @}
302 */
303
304/*!
305 * @}
306 */
307
308
309#ifdef __cplusplus
310}
311#endif
static void xrt_instance_destroy(struct xrt_instance **xinst_ptr)
Destroy an xrt_instance - helper function.
Definition: xrt_instance.h:264
xrt_result_t xrt_instance_create(struct xrt_instance_info *ii, struct xrt_instance **out_xinst)
Create an implementation of the xrt_instance interface.
Definition: target_instance.c:170
static xrt_result_t xrt_instance_create_system(struct xrt_instance *xinst, struct xrt_system **out_xsys, struct xrt_system_devices **out_xsysd, struct xrt_space_overseer **out_xso, struct xrt_system_compositor **out_xsysc)
Creates all of the system resources like the devices and system compositor.
Definition: xrt_instance.h:231
enum xrt_result xrt_result_t
Result type used across Monado.
static xrt_result_t xrt_instance_is_system_available(struct xrt_instance *xinst, bool *out_available)
Creates all of the system resources like the devices and system compositor.
Definition: xrt_instance.h:218
static xrt_result_t xrt_instance_get_prober(struct xrt_instance *xinst, struct xrt_prober **out_xp)
Get the instance xrt_prober, if any.
Definition: xrt_instance.h:248
Non-process-specific information provided by the application at instance create time.
Definition: xrt_instance.h:73
A single HMD or input device.
Definition: xrt_device.h:284
Information provided by the application at instance create time.
Definition: xrt_instance.h:94
struct xrt_platform_info platform_info
Process-specific, platform-specific data.
Definition: xrt_instance.h:99
struct xrt_application_info app_info
Generic data from application.
Definition: xrt_instance.h:96
This interface acts as a root object for Monado.
Definition: xrt_instance.h:120
struct xrt_instance_android * android_instance
An "aspect" of the xrt_instance interface, used only on Android.
Definition: xrt_instance.h:206
struct xrt_instance_info instance_info
Instance information structure, including both platform and application info.
Definition: xrt_instance.h:194
xrt_result_t(* get_prober)(struct xrt_instance *xinst, struct xrt_prober **out_xp)
Get the instance xrt_prober, if any.
Definition: xrt_instance.h:176
void(* destroy)(struct xrt_instance *xinst)
Destroy the instance and its owned objects, including the prober (if any).
Definition: xrt_instance.h:186
xrt_result_t(* create_system)(struct xrt_instance *xinst, struct xrt_system **out_xsys, struct xrt_system_devices **out_xsysd, struct xrt_space_overseer **out_xso, struct xrt_system_compositor **out_xsysc)
Creates all of the system resources like the devices and system compositor.
Definition: xrt_instance.h:150
int64_t startup_timestamp
CLOCK_MONOTONIC timestamp of the instance startup.
Definition: xrt_instance.h:199
xrt_result_t(* is_system_available)(struct xrt_instance *xinst, bool *out_available)
Checks if the system can be created with create_system().
Definition: xrt_instance.h:133
Definition: xrt_instance.h:42
The main prober that probes and manages found but not opened HMD devices that are connected to the sy...
Definition: xrt_prober.h:132
Object that oversees and manages spaces, one created for each XR system.
Definition: xrt_space.h:97
The system compositor handles composition for a system.
Definition: xrt_compositor.h:2447
A collection of xrt_device, and an interface for identifying the roles they have been assigned.
Definition: xrt_system.h:221
A system is a collection of devices, policies and optionally a compositor that is organised into a ch...
Definition: xrt_system.h:62
Header holding common defines.
Auto detect OS and certain features.
Common defines and enums for XRT.