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