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