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
112{
113 //! The width of the view.
114 uint32_t width_pixels;
115 //! The height of the view.
117 //! The amount of samples for the swapchain.
118 uint32_t sample_count;
119};
120
122{
123 //! Whether the recommendation is valid.
124 bool valid;
125 //! The number of views in the configuration, invariant.
126 uint32_t view_count;
127 //! The views in the configuration.
129};
130
131/*!
132 * @interface xrt_app_system
133 *
134 * This interface acts as a way to store per-application policy for @ref xrt_system.
135 *
136 * Only a single one of these should be created per @ref xrt_system per application
137 * (aka per XrInstance, in OpenXR terminology).
138 *
139 * @sa xrt_app_instance_create_app_system
140 */
142{
143 /*!
144 * @name Interface Methods
145 *
146 * All implementations of the xrt_app_system interface must
147 * populate all these function pointers with their implementation
148 * methods. To use this interface, see the helper functions.
149 * @{
150 */
151
152 /*!
153 * Gets the recommended view configuration for the given view type, if available and supported.
154 * Only the `recommended` field is guaranteed to be provided, and `max` may be left unspecified.
155 *
156 * This allows a policy to set a new recommended view configuration for the lifetime of this application.
157 *
158 * @param xasys Pointer to self
159 * @param view_type The view type to get the recommended view configuration for.
160 * @param[out] out_recommended_view_config The recommendation for the client.
161 */
163 struct xrt_app_system *xasys,
164 enum xrt_view_type view_type,
165 struct xrt_recommended_view_config *out_recommended_view_config);
166
167 /*!
168 * Sets the recommended view configuration for the given view type.
169 * Only the `recommended` field will be meaningfully read by the xrt_app_system.
170 *
171 * The callee should push a session event of type @ref XRT_SESSION_EVENT_RECOMMENDED_VIEW_CONFIGURATION_CHANGE
172 * when the recommended view configuration changes, so that sessions can react to this change if they want to.
173 *
174 * @note The xrt_app_system may not do verification on the passed configuration, it is up to the callee to not
175 * pass invalid data into here.
176 *
177 * @param xasys Pointer to self
178 * @param view_type The view type to set the recommended view configuration for.
179 * @param[in] recommended_view_config The recommended view configuration to set for the given view type.
180 */
182 struct xrt_app_system *xasys,
183 enum xrt_view_type view_type,
184 const struct xrt_recommended_view_config *recommended_view_config);
185
186 /*!
187 * Destroy the application system and its owned objects.
188 *
189 * @note Code consuming this interface should use xrt_app_system_destroy().
190 *
191 * @param xasys Pointer to self
192 */
193 void (*destroy)(struct xrt_app_system *xasys);
194
195 /*!
196 * @}
197 */
198};
199
200/*!
201 * @copydoc xrt_app_system::get_recommended_view_configuration
202 *
203 * Helper for calling through the function pointer.
204 *
205 * @public @memberof xrt_app_system
206 */
207XRT_NONNULL_ALL static inline xrt_result_t
209 enum xrt_view_type view_type,
210 struct xrt_recommended_view_config *out_recommended_view_config)
211{
212 return xasys->get_recommended_view_configuration(xasys, view_type, out_recommended_view_config);
213}
214
215/*!
216 * @copydoc xrt_app_system::set_recommended_view_configuration
217 *
218 * Helper for calling through the function pointer.
219 *
220 * @public @memberof xrt_app_system
221 */
222XRT_NONNULL_ALL static inline xrt_result_t
224 enum xrt_view_type view_type,
225 const struct xrt_recommended_view_config *recommended_view_config)
226{
227 return xasys->set_recommended_view_configuration(xasys, view_type, recommended_view_config);
228}
229
230/*!
231 * @copydoc xrt_app_system::destroy
232 *
233 * Helper for calling through the function pointer.
234 *
235 * @public @memberof xrt_app_system
236 */
237XRT_NONNULL_ALL static inline void
239{
240 struct xrt_app_system *xasys = *xasys_ptr;
241 if (xasys == NULL) {
242 return;
243 }
244
245 xasys->destroy(xasys);
246 *xasys_ptr = NULL;
247}
248
249
250#ifdef __cplusplus
251};
252#endif
enum xrt_result xrt_result_t
Result type used across Monado.
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
This interface acts as a way to store per-application policy for xrt_system.
Definition xrt_app_policy.h:142
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:208
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:162
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:238
void(* destroy)(struct xrt_app_system *xasys)
Destroy the application system and its owned objects.
Definition xrt_app_policy.h:193
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 the given view type.
Definition xrt_app_policy.h:181
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 the given view type.
Definition xrt_app_policy.h:223
A system is a collection of devices, policies and optionally a compositor that is organised into a ch...
Definition xrt_system.h:65
Definition xrt_compositor.h:2298
Common defines and enums for XRT.
xrt_view_type
View type to be rendered to by the compositor.
Definition xrt_defines.h:2438
Header for limits of the XRT interfaces.