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 ext_hand_tracking_enabled;
77 bool ext_hand_tracking_data_source_enabled;
78 bool ext_eye_gaze_interaction_enabled;
79 bool ext_future_enabled;
80 bool ext_hand_interaction_enabled;
81 bool htc_facial_tracking_enabled;
82 bool fb_body_tracking_enabled;
83 bool fb_face_tracking2_enabled;
84 bool meta_body_tracking_full_body_enabled;
85 bool meta_body_tracking_calibration_enabled;
86 bool meta_body_tracking_fidelity_enabled;
87 bool android_face_tracking_enabled;
88};
89
90/*!
91 * Information provided by the application at instance create time.
92 *
93 * Some information may be process-specific.
94 */
96{
97 //! Generic data from application.
99
100 //! Process-specific, platform-specific data.
102};
103
104/*!
105 * @interface xrt_instance
106 *
107 * This interface acts as a root object for Monado.
108 * It typically either wraps an @ref xrt_prober or forms a connection to an
109 * out-of-process XR service.
110 *
111 * This is as close to a singleton object as there is in Monado: you should not
112 * create more than one xrt_instance implementation per process.
113 *
114 * Each "target" will provide its own (private) implementation of this
115 * interface, which is exposed by implementing xrt_instance_create().
116 *
117 * Additional information can be found in @ref understanding-targets.
118 *
119 * @sa ipc_instance_create
120 */
122{
123 /*!
124 * @name Interface Methods
125 *
126 * All implementations of the xrt_instance interface must
127 * populate all these function pointers with their implementation
128 * methods. To use this interface, see the helper functions.
129 * @{
130 */
131
132 /*!
133 * Checks if the system can be created with create_system().
134 */
135 xrt_result_t (*is_system_available)(struct xrt_instance *xinst, bool *out_available);
136
137 /*!
138 * Creates all of the system resources like the devices and system
139 * compositor. The system compositor is optional.
140 *
141 * Should only be called once.
142 *
143 * @note Code consuming this interface should use xrt_instance_create_system()
144 *
145 * @param xinst Pointer to self
146 * @param[out] out_xsys Return of system, required.
147 * @param[out] out_xsysd Return of devices, required.
148 * @param[out] out_xsysc Return of system compositor, optional.
149 *
150 * @see xrt_prober::probe, xrt_prober::select, xrt_gfx_provider_create_native
151 */
153 struct xrt_system **out_xsys,
154 struct xrt_system_devices **out_xsysd,
155 struct xrt_space_overseer **out_xso,
156 struct xrt_system_compositor **out_xsysc);
157
158 /*!
159 * Get the instance @ref xrt_prober, if any.
160 *
161 * If the instance is not using an @ref xrt_prober, it may return null.
162 *
163 * The instance retains ownership of the prober and is responsible for
164 * destroying it.
165 *
166 * Can be called multiple times. (The prober is usually created at
167 * instance construction time.)
168 *
169 * @note Code consuming this interface should use
170 * xrt_instance_get_prober().
171 *
172 * @param xinst Pointer to self
173 * @param[out] out_xp Pointer to xrt_prober pointer, will be populated
174 * or set to NULL.
175 *
176 * @return XRT_SUCCESS on success, other error code on error.
177 */
178 xrt_result_t (*get_prober)(struct xrt_instance *xinst, struct xrt_prober **out_xp);
179
180 /*!
181 * Creates an application instance, should only be called once per application.
182 *
183 * All @ref xrt_app_instance instances created by this function are expected to be destroyed before the
184 * xrt_instance is destroyed.
185 *
186 * @note Code consuming this interface should use xrt_instance_create_app_instance()
187 *
188 * @param xinst Pointer to self
189 * @param[out] out_xainst Return of application instance, required.
190 */
191 xrt_result_t (*create_app_instance)(struct xrt_instance *xinst, struct xrt_app_instance **out_xainst);
192
193 /*!
194 * Destroy the instance and its owned objects, including the prober (if
195 * any).
196 *
197 * Code consuming this interface should use xrt_instance_destroy().
198 *
199 * @param xinst Pointer to self
200 */
201 void (*destroy)(struct xrt_instance *xinst);
202 /*!
203 * @}
204 */
205
206 /*!
207 * Instance information structure, including both platform and application info.
208 */
210
211 /*!
212 * CLOCK_MONOTONIC timestamp of the instance startup.
213 */
215
216 /*!
217 * An "aspect" of the xrt_instance interface, used only on Android.
218 *
219 * @see xrt_instance_android
220 */
222};
223
224
225/*!
226 * @copydoc xrt_instance::create_system
227 *
228 * Helper for calling through the function pointer.
229 *
230 * @public @memberof xrt_instance
231 */
232XRT_NONNULL_ALL static inline xrt_result_t
233xrt_instance_is_system_available(struct xrt_instance *xinst, bool *out_available)
234{
235 return xinst->is_system_available(xinst, out_available);
236}
237
238/*!
239 * @copydoc xrt_instance::create_system
240 *
241 * Helper for calling through the function pointer.
242 *
243 * @public @memberof xrt_instance
244 */
245static inline xrt_result_t
247 struct xrt_system **out_xsys,
248 struct xrt_system_devices **out_xsysd,
249 struct xrt_space_overseer **out_xso,
250 struct xrt_system_compositor **out_xsysc)
251{
252 return xinst->create_system(xinst, out_xsys, out_xsysd, out_xso, out_xsysc);
253}
254
255/*!
256 * @copydoc xrt_instance::get_prober
257 *
258 * Helper for calling through the function pointer.
259 *
260 * @public @memberof xrt_instance
261 */
262XRT_NONNULL_ALL static inline xrt_result_t
263xrt_instance_get_prober(struct xrt_instance *xinst, struct xrt_prober **out_xp)
264{
265 return xinst->get_prober(xinst, out_xp);
266}
267
268/*!
269 * @copydoc xrt_instance::create_app_instance
270 *
271 * Helper for calling through the function pointer.
272 *
273 * @public @memberof xrt_instance
274 */
275XRT_NONNULL_ALL static inline xrt_result_t
277{
278 return xinst->create_app_instance(xinst, out_xainst);
279}
280
281/*!
282 * Destroy an xrt_instance - helper function.
283 *
284 * @param[in,out] xinst_ptr A pointer to your instance implementation pointer.
285 *
286 * Will destroy the instance if *xinst_ptr is not NULL. Will then set *xinst_ptr
287 * to NULL.
288 *
289 * @public @memberof xrt_instance
290 */
291XRT_NONNULL_ALL static inline void
293{
294 struct xrt_instance *xinst = *xinst_ptr;
295 if (xinst == NULL) {
296 return;
297 }
298
299 xinst->destroy(xinst);
300 *xinst_ptr = NULL;
301}
302
303/*!
304 * @name Factory
305 * Implemented in each target.
306 * @{
307 */
308/*!
309 * Create an implementation of the xrt_instance interface.
310 *
311 * Creating more then one @ref xrt_instance is probably never the right thing
312 * to do, so avoid it.
313 *
314 * Each target must implement this function.
315 *
316 * @param[in] ii A pointer to a info struct containing information about the
317 * application, optional can be null.
318 * @param[out] out_xinst A pointer to an xrt_instance pointer. Will be
319 * populated.
320 *
321 * @return 0 on success
322 *
323 * @relates xrt_instance
324 */
326xrt_instance_create(struct xrt_instance_info *ii, struct xrt_instance **out_xinst);
327
328/*!
329 * @}
330 */
331
332/*!
333 * @}
334 */
335
336
337#ifdef __cplusplus
338}
339#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:263
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:276
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:246
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:292
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:233
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:34
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:96
struct xrt_platform_info platform_info
Process-specific, platform-specific data.
Definition xrt_instance.h:101
struct xrt_application_info app_info
Generic data from application.
Definition xrt_instance.h:98
This interface acts as a root object for Monado.
Definition xrt_instance.h:122
struct xrt_instance_android * android_instance
An "aspect" of the xrt_instance interface, used only on Android.
Definition xrt_instance.h:221
struct xrt_instance_info instance_info
Instance information structure, including both platform and application info.
Definition xrt_instance.h:209
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:178
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:191
void(* destroy)(struct xrt_instance *xinst)
Destroy the instance and its owned objects, including the prober (if any).
Definition xrt_instance.h:201
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:152
int64_t startup_timestamp
CLOCK_MONOTONIC timestamp of the instance startup.
Definition xrt_instance.h:214
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:135
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:2459
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.