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