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