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 
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 
22 struct xrt_prober;
23 struct xrt_device;
24 struct xrt_space_overseer;
25 struct xrt_system;
26 struct xrt_system_devices;
28 
29 
30 /*!
31  * @addtogroup xrt_iface
32  * @{
33  */
34 
35 #define XRT_MAX_APPLICATION_NAME_SIZE 128
36 
37 /*!
38  * Information provided by the application at instance create time.
39  */
41 {
42  char application_name[XRT_MAX_APPLICATION_NAME_SIZE];
43  bool ext_hand_tracking_enabled;
44  bool ext_eye_gaze_interaction_enabled;
45  bool ext_hand_interaction_enabled;
46  bool htc_facial_tracking_enabled;
47 };
48 
49 /*!
50  * @interface xrt_instance
51  *
52  * This interface acts as a root object for Monado.
53  * It typically either wraps an @ref xrt_prober or forms a connection to an
54  * out-of-process XR service.
55  *
56  * This is as close to a singleton object as there is in Monado: you should not
57  * create more than one xrt_instance implementation per process.
58  *
59  * Each "target" will provide its own (private) implementation of this
60  * interface, which is exposed by implementing xrt_instance_create().
61  *
62  * Additional information can be found in @ref understanding-targets.
63  *
64  * @sa ipc_instance_create
65  */
67 {
68  /*!
69  * @name Interface Methods
70  *
71  * All implementations of the xrt_instance implementation must
72  * populate all these function pointers with their implementation
73  * methods. To use this interface, see the helper functions.
74  * @{
75  */
76 
77  /*!
78  * Creates all of the system resources like the devices and system
79  * compositor. The system compositor is optional.
80  *
81  * Should only be called once.
82  *
83  * @note Code consuming this interface should use xrt_instance_create_system()
84  *
85  * @param xinst Pointer to self
86  * @param[out] out_xsys Return of system, required.
87  * @param[out] out_xsysd Return of devices, required.
88  * @param[out] out_xsysc Return of system compositor, optional.
89  *
90  * @see xrt_prober::probe, xrt_prober::select, xrt_gfx_provider_create_native
91  */
93  struct xrt_system **out_xsys,
94  struct xrt_system_devices **out_xsysd,
95  struct xrt_space_overseer **out_xso,
96  struct xrt_system_compositor **out_xsysc);
97 
98  /*!
99  * Get the instance @ref xrt_prober, if any.
100  *
101  * If the instance is not using an @ref xrt_prober, it may return null.
102  *
103  * The instance retains ownership of the prober and is responsible for
104  * destroying it.
105  *
106  * Can be called multiple times. (The prober is usually created at
107  * instance construction time.)
108  *
109  * @note Code consuming this interface should use
110  * xrt_instance_get_prober().
111  *
112  * @param xinst Pointer to self
113  * @param[out] out_xp Pointer to xrt_prober pointer, will be populated
114  * or set to NULL.
115  *
116  * @return XRT_SUCCESS on success, other error code on error.
117  */
118  xrt_result_t (*get_prober)(struct xrt_instance *xinst, struct xrt_prober **out_xp);
119 
120  /*!
121  * Destroy the instance and its owned objects, including the prober (if
122  * any).
123  *
124  * Code consuming this interface should use xrt_instance_destroy().
125  *
126  * @param xinst Pointer to self
127  */
128  void (*destroy)(struct xrt_instance *xinst);
129  /*!
130  * @}
131  */
132  struct xrt_instance_info instance_info;
133 
134  uint64_t startup_timestamp;
135 };
136 
137 /*!
138  * @copydoc xrt_instance::create_system
139  *
140  * Helper for calling through the function pointer.
141  *
142  * @public @memberof xrt_instance
143  */
144 static inline xrt_result_t
146  struct xrt_system **out_xsys,
147  struct xrt_system_devices **out_xsysd,
148  struct xrt_space_overseer **out_xso,
149  struct xrt_system_compositor **out_xsysc)
150 {
151  return xinst->create_system(xinst, out_xsys, out_xsysd, out_xso, out_xsysc);
152 }
153 
154 /*!
155  * @copydoc xrt_instance::get_prober
156  *
157  * Helper for calling through the function pointer.
158  *
159  * @public @memberof xrt_instance
160  */
161 static inline xrt_result_t
162 xrt_instance_get_prober(struct xrt_instance *xinst, struct xrt_prober **out_xp)
163 {
164  return xinst->get_prober(xinst, out_xp);
165 }
166 
167 /*!
168  * Destroy an xrt_instance - helper function.
169  *
170  * @param[in,out] xinst_ptr A pointer to your instance implementation pointer.
171  *
172  * Will destroy the instance if *xinst_ptr is not NULL. Will then set *xinst_ptr
173  * to NULL.
174  *
175  * @public @memberof xrt_instance
176  */
177 static inline void
179 {
180  struct xrt_instance *xinst = *xinst_ptr;
181  if (xinst == NULL) {
182  return;
183  }
184 
185  xinst->destroy(xinst);
186  *xinst_ptr = NULL;
187 }
188 
189 /*!
190  * @name Factory
191  * Implemented in each target.
192  * @{
193  */
194 /*!
195  * Create an implementation of the xrt_instance interface.
196  *
197  * Creating more then one @ref xrt_instance is probably never the right thing
198  * to do, so avoid it.
199  *
200  * Each target must implement this function.
201  *
202  * @param[in] ii A pointer to a info struct containing information about the
203  * application.
204  * @param[out] out_xinst A pointer to an xrt_instance pointer. Will be
205  * populated.
206  *
207  * @return 0 on success
208  *
209  * @relates xrt_instance
210  */
212 xrt_instance_create(struct xrt_instance_info *ii, struct xrt_instance **out_xinst);
213 
214 /*!
215  * @}
216  */
217 
218 /*!
219  * @}
220  */
221 
222 
223 #ifdef __cplusplus
224 }
225 #endif
static void xrt_instance_destroy(struct xrt_instance **xinst_ptr)
Destroy an xrt_instance - helper function.
Definition: xrt_instance.h:178
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:151
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:145
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:162
A single HMD or input device.
Definition: xrt_device.h:230
Information provided by the application at instance create time.
Definition: xrt_instance.h:41
This interface acts as a root object for Monado.
Definition: xrt_instance.h:67
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:118
void(* destroy)(struct xrt_instance *xinst)
Destroy the instance and its owned objects, including the prober (if any).
Definition: xrt_instance.h:128
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:92
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:95
The system compositor handles composition for a system.
Definition: xrt_compositor.h:2386
A collection of xrt_device, and an interface for identifying the roles they have been assigned.
Definition: xrt_system.h:218
A system is a collection of devices, policies and optionally a compositor that is organised into a ch...
Definition: xrt_system.h:61
Header holding common defines.
Common defines and enums for XRT.