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