Monado OpenXR Runtime
Loading...
Searching...
No Matches
xrt_app_policy.h
Go to the documentation of this file.
1// Copyright 2026, Beyley Cardellio.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Header for application policy object.
6 * @author Beyley Cardellio <ep1cm1n10n123@gmail.com>
7 * @ingroup xrt_iface
8 */
9
10#pragma once
11
12#include "xrt/xrt_defines.h"
13#include "xrt/xrt_limits.h"
14
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20
21struct xrt_system;
22struct xrt_app_system;
23struct xrt_view_config;
24
25/*!
26 * @interface xrt_app_instance
27 *
28 * This interface acts as a way to store per-application policy for @ref xrt_instance.
29 *
30 * Only a single one of these should be created per application (aka XrInstance, in OpenXR terminology).
31 *
32 * @sa xrt_instance
33 * @sa xrt_instance_create_app_instance
34 */
36{
37 /*!
38 * @name Interface Methods
39 *
40 * All implementations of the xrt_app_instance interface must
41 * populate all these function pointers with their implementation
42 * methods. To use this interface, see the helper functions.
43 * @{
44 */
45
46 /*!
47 * Creates an application system from the passed system.
48 *
49 * All @ref xrt_app_system instances created by this function are expected to be destroyed before the
50 * xrt_app_instance is destroyed.
51 *
52 * @note Code consuming this interface should use xrt_app_instance_create_app_system()
53 *
54 * @param xainst Pointer to self
55 * @param xsys Pointer to system to wrap.
56 * @param[out] out_xasys Return of application system, required.
57 */
59 struct xrt_system *xsys,
60 struct xrt_app_system **out_xasys);
61
62 /*!
63 * Destroy the application instance and its owned objects.
64 *
65 * Code consuming this interface should use xrt_app_instance_destroy().
66 *
67 * @param xainst Pointer to self
68 */
69 void (*destroy)(struct xrt_app_instance *xainst);
70
71 /*!
72 * @}
73 */
74};
75
76/*!
77 * @copydoc xrt_app_instance::create_app_system
78 *
79 * Helper for calling through the function pointer.
80 *
81 * @public @memberof xrt_app_instance
82 */
83XRT_NONNULL_ALL static inline xrt_result_t
85 struct xrt_system *xsys,
86 struct xrt_app_system **out_xasys)
87{
88 return xainst->create_app_system(xainst, xsys, out_xasys);
89}
90
91/*!
92 * @copydoc xrt_app_instance::destroy
93 *
94 * Helper for calling through the function pointer.
95 *
96 * @public @memberof xrt_app_instance
97 */
98XRT_NONNULL_ALL static inline void
100{
101 struct xrt_app_instance *xainst = *xainst_ptr;
102 if (xainst == NULL) {
103 return;
104 }
105
106 xainst->destroy(xainst);
107 *xainst_ptr = NULL;
108}
109
110
111/*!
112 * Type of an @ref xrt_app_system event.
113 *
114 * @see xrt_app_system_event
115 * @ingroup xrt_iface
116 */
118{
119 //! This app system has no events.
121
122 //! The recommended view configuration of some view type has changed.
124};
125
126/*!
127 * Recommended view configuration changed event, type @ref XRT_APP_SYSTEM_EVENT_RECOMMENDED_VIEW_CONFIGURATION_CHANGED.
128 *
129 * @see xrt_app_system_event
130 * @ingroup xrt_iface
131 */
133{
134 //! The @ref xrt_view_type that has changed.
136};
137
138/*!
139 * Union of all app system events, used to return multiple events through one interface.
140 *
141 * @see xrt_app_system_event
142 * @ingroup xrt_iface
143 */
145{
147 union {
149 recommended_view_configuration_changed;
150 };
151};
152
153/*!
154 * A single view in a recommended view configuration
155 *
156 * @ingroup xrt_iface
157 */
159{
160 //! The width of the view.
161 uint32_t width_pixels;
162 //! The height of the view.
164 //! The amount of samples for the swapchain.
165 uint32_t sample_count;
166};
167
168/*!
169 * A recommended view configuration
170 *
171 * @ingroup xrt_iface
172 */
174{
175 //! Whether the recommendation is valid.
176 bool valid;
177 //! The number of views in the configuration, invariant.
178 uint32_t view_count;
179 //! The views in the configuration.
181};
182
183/*!
184 * @interface xrt_app_system
185 *
186 * This interface acts as a way to store per-application policy for @ref xrt_system.
187 *
188 * Only a single one of these should be created per @ref xrt_system per application
189 * (aka per XrInstance, in OpenXR terminology).
190 *
191 * @sa xrt_app_instance_create_app_system
192 */
194{
195 /*!
196 * @name Interface Methods
197 *
198 * All implementations of the xrt_app_system interface must
199 * populate all these function pointers with their implementation
200 * methods. To use this interface, see the helper functions.
201 * @{
202 */
203
204 /*!
205 * Poll a single event from this app system, if no event is available then
206 * the type of the event will be @ref XRT_APP_SYSTEM_EVENT_NONE.
207 *
208 * @param xasys Pointer to self
209 * @param[out] out_xasyse Event to be returned.
210 */
211 xrt_result_t (*poll_events)(struct xrt_app_system *xasys, struct xrt_app_system_event *out_xasyse);
212
213 /*!
214 * Gets the recommended view configuration for the given view type, if available and supported.
215 *
216 * @param xasys Pointer to self
217 * @param view_type The view type to get the recommended view configuration for.
218 * @param[out] out_recommended_view_config The recommendation for the client.
219 */
221 struct xrt_app_system *xasys,
222 enum xrt_view_type view_type,
223 struct xrt_recommended_view_config *out_recommended_view_config);
224
225 /*!
226 * Sets the recommended view configuration for this application, for the given view type.
227 *
228 * @note The xrt_app_system may not do verification on the passed configuration, it is up to the callee to not
229 * pass invalid data into here.
230 *
231 * @param xasys Pointer to self
232 * @param view_type The view type to set the recommended view configuration for.
233 * @param[in] recommended_view_config The recommended view configuration to set for the given view type.
234 */
236 struct xrt_app_system *xasys,
237 enum xrt_view_type view_type,
238 const struct xrt_recommended_view_config *recommended_view_config);
239
240 /*!
241 * Destroy the application system and its owned objects.
242 *
243 * @note Code consuming this interface should use xrt_app_system_destroy().
244 *
245 * @param xasys Pointer to self
246 */
247 void (*destroy)(struct xrt_app_system *xasys);
248
249 /*!
250 * @}
251 */
252};
253
254/*!
255 * @copydoc xrt_app_system::poll_events
256 *
257 * Helper for calling through the function pointer.
258 *
259 * @public @memberof xrt_app_system
260 */
261XRT_NONNULL_ALL static inline xrt_result_t
263{
264 return xasys->poll_events(xasys, out_xasyse);
265}
266
267/*!
268 * @copydoc xrt_app_system::get_recommended_view_configuration
269 *
270 * Helper for calling through the function pointer.
271 *
272 * @public @memberof xrt_app_system
273 */
274XRT_NONNULL_ALL static inline xrt_result_t
276 enum xrt_view_type view_type,
277 struct xrt_recommended_view_config *out_recommended_view_config)
278{
279 return xasys->get_recommended_view_configuration(xasys, view_type, out_recommended_view_config);
280}
281
282/*!
283 * @copydoc xrt_app_system::set_recommended_view_configuration
284 *
285 * Helper for calling through the function pointer.
286 *
287 * @public @memberof xrt_app_system
288 */
289XRT_NONNULL_ALL static inline xrt_result_t
291 enum xrt_view_type view_type,
292 const struct xrt_recommended_view_config *recommended_view_config)
293{
294 return xasys->set_recommended_view_configuration(xasys, view_type, recommended_view_config);
295}
296
297/*!
298 * @copydoc xrt_app_system::destroy
299 *
300 * Helper for calling through the function pointer.
301 *
302 * @public @memberof xrt_app_system
303 */
304XRT_NONNULL_ALL static inline void
306{
307 struct xrt_app_system *xasys = *xasys_ptr;
308 if (xasys == NULL) {
309 return;
310 }
311
312 xasys->destroy(xasys);
313 *xasys_ptr = NULL;
314}
315
316
317#ifdef __cplusplus
318};
319#endif
xrt_app_system_event_type
Type of an xrt_app_system event.
Definition xrt_app_policy.h:118
enum xrt_result xrt_result_t
Result type used across Monado.
@ XRT_APP_SYSTEM_EVENT_NONE
This app system has no events.
Definition xrt_app_policy.h:120
@ XRT_APP_SYSTEM_EVENT_RECOMMENDED_VIEW_CONFIGURATION_CHANGED
The recommended view configuration of some view type has changed.
Definition xrt_app_policy.h:123
This interface acts as a way to store per-application policy for xrt_instance.
Definition xrt_app_policy.h:36
void(* destroy)(struct xrt_app_instance *xainst)
Destroy the application instance and its owned objects.
Definition xrt_app_policy.h:69
static XRT_NONNULL_ALL xrt_result_t xrt_app_instance_create_app_system(struct xrt_app_instance *xainst, struct xrt_system *xsys, struct xrt_app_system **out_xasys)
Creates an application system from the passed system.
Definition xrt_app_policy.h:84
xrt_result_t(* create_app_system)(struct xrt_app_instance *xainst, struct xrt_system *xsys, struct xrt_app_system **out_xasys)
Creates an application system from the passed system.
Definition xrt_app_policy.h:58
static XRT_NONNULL_ALL void xrt_app_instance_destroy(struct xrt_app_instance **xainst_ptr)
Destroy the application instance and its owned objects.
Definition xrt_app_policy.h:99
Union of all app system events, used to return multiple events through one interface.
Definition xrt_app_policy.h:145
This interface acts as a way to store per-application policy for xrt_system.
Definition xrt_app_policy.h:194
xrt_result_t(* poll_events)(struct xrt_app_system *xasys, struct xrt_app_system_event *out_xasyse)
Poll a single event from this app system, if no event is available then the type of the event will be...
Definition xrt_app_policy.h:211
static XRT_NONNULL_ALL xrt_result_t xrt_app_system_poll_events(struct xrt_app_system *xasys, struct xrt_app_system_event *out_xasyse)
Poll a single event from this app system, if no event is available then the type of the event will be...
Definition xrt_app_policy.h:262
static XRT_NONNULL_ALL xrt_result_t xrt_app_system_get_recommended_view_configuration(struct xrt_app_system *xasys, enum xrt_view_type view_type, struct xrt_recommended_view_config *out_recommended_view_config)
Gets the recommended view configuration for the given view type, if available and supported.
Definition xrt_app_policy.h:275
xrt_result_t(* get_recommended_view_configuration)(struct xrt_app_system *xasys, enum xrt_view_type view_type, struct xrt_recommended_view_config *out_recommended_view_config)
Gets the recommended view configuration for the given view type, if available and supported.
Definition xrt_app_policy.h:220
static XRT_NONNULL_ALL void xrt_app_system_destroy(struct xrt_app_system **xasys_ptr)
Destroy the application system and its owned objects.
Definition xrt_app_policy.h:305
void(* destroy)(struct xrt_app_system *xasys)
Destroy the application system and its owned objects.
Definition xrt_app_policy.h:247
xrt_result_t(* set_recommended_view_configuration)(struct xrt_app_system *xasys, enum xrt_view_type view_type, const struct xrt_recommended_view_config *recommended_view_config)
Sets the recommended view configuration for this application, for the given view type.
Definition xrt_app_policy.h:235
static XRT_NONNULL_ALL xrt_result_t xrt_app_system_set_recommended_view_configuration(struct xrt_app_system *xasys, enum xrt_view_type view_type, const struct xrt_recommended_view_config *recommended_view_config)
Sets the recommended view configuration for this application, for the given view type.
Definition xrt_app_policy.h:290
A system is a collection of devices, policies and optionally a compositor that is organised into a ch...
Definition xrt_system.h:67
Definition xrt_compositor.h:2306
Common defines and enums for XRT.
xrt_view_type
View type to be rendered to by the compositor.
Definition xrt_defines.h:2444
Header for limits of the XRT interfaces.