Monado OpenXR Runtime
xrt_session.h
Go to the documentation of this file.
1// Copyright 2020-2023, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Header for session object.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @ingroup xrt_iface
8 */
9
10#pragma once
11
12#include "xrt/xrt_compiler.h"
13#include "xrt/xrt_defines.h"
14#include "xrt/xrt_space.h"
15
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
22
23
24/*
25 *
26 * Session events.
27 *
28 */
29
30/*!
31 * Type of a @ref xrt_session event.
32 *
33 * @see xrt_session_event
34 * @ingroup xrt_iface
35 */
37{
38 //! This session has no pending events.
40
41 //! The state of the session has changed.
43
44 //! The state of the primary session has changed.
46
47 //! The session is about to be lost.
49
50 //! The session has been lost.
52
53 //! The refresh rate of session (compositor) has changed.
55
56 //! A reference space for this session has a pending change.
58
59 //! The performance of the session has changed
61
62 //! The passthrough state of the session has changed
64
65 // ! The visibility mask of given view has changed
66 XRT_SESSION_EVENT_VISIBILITY_MASK_CHANGE = 9
67};
68
69/*!
70 * Session state changes event, type @ref XRT_SESSION_EVENT_STATE_CHANGE.
71 *
72 * @see xrt_session_event
73 * @ingroup xrt_iface
74 */
76{
77 enum xrt_session_event_type type;
78 bool visible;
79 bool focused;
80};
81
82/*!
83 * Primary session state changes event,
84 * type @ref XRT_SESSION_EVENT_OVERLAY_CHANGE.
85 *
86 * @see xrt_session_event
87 * @ingroup xrt_iface
88 */
90{
91 enum xrt_session_event_type type;
92 bool primary_focused;
93};
94
95/*!
96 * Loss pending event, @ref XRT_SESSION_EVENT_LOSS_PENDING.
97 *
98 * @see xrt_session_event
99 * @ingroup xrt_iface
100 */
102{
103 enum xrt_session_event_type type;
104 int64_t loss_time_ns;
105};
106
107/*!
108 * Session lost event, type @ref XRT_SESSION_EVENT_LOST.
109 *
110 * @see xrt_session_event
111 * @ingroup xrt_iface
112 */
114{
115 enum xrt_session_event_type type;
116};
117
118/*!
119 * Display refresh rate of compositor changed event,
120 * type @ref XRT_SESSION_EVENT_DISPLAY_REFRESH_RATE_CHANGE.
121 *
122 * @see xrt_session_event
123 * @ingroup xrt_iface
124 */
126{
127 enum xrt_session_event_type type;
128 float from_display_refresh_rate_hz;
129 float to_display_refresh_rate_hz;
130};
131
132/*!
133 * Event that tells the application that the reference space has a pending
134 * change to it, maps to @p XrEventDataReferenceSpaceChangePending,
135 * type @ref XRT_SESSION_EVENT_REFERENCE_SPACE_CHANGE_PENDING.
136 *
137 * @see xrt_session_event
138 * @ingroup xrt_iface
139 */
141{
142 enum xrt_session_event_type event_type;
143 enum xrt_reference_space_type ref_type;
144 int64_t timestamp_ns;
145 struct xrt_pose pose_in_previous_space;
146 bool pose_valid;
147};
148
149/*!
150 * Performance metrics change event.
151 */
153{
154 enum xrt_session_event_type type;
155 enum xrt_perf_domain domain;
156 enum xrt_perf_sub_domain sub_domain;
157 enum xrt_perf_notify_level from_level;
158 enum xrt_perf_notify_level to_level;
159};
160
161/*!
162 * Passthrough state change event.
163 */
165{
166 enum xrt_session_event_type type;
167 enum xrt_passthrough_state state;
168};
169
170/*!
171 * Visibility mask changed event
172 */
174{
175 enum xrt_session_event_type type;
176 uint32_t view_index;
177};
178
179/*!
180 * Union of all session events, used to return multiple events through one call.
181 * Each event struct must start with a @ref xrt_session_event_type field.
182 *
183 * @see xrt_session_event
184 * @ingroup xrt_iface
185 */
187 enum xrt_session_event_type type;
189 struct xrt_session_event_state_change overlay;
190 struct xrt_session_event_loss_pending loss_pending;
191 struct xrt_session_event_lost lost;
194 struct xrt_session_event_perf_change performance;
197};
198
199/*!
200 * Used internally from producers of events to push events into session, some
201 * sinks might multiplex events to multiple sessions.
202 *
203 * @ingroup xrt_iface
204 */
206{
207 /*!
208 * Push one event to this sink, data is copied so pointer only needs to
209 * be valid for the duration of the call.
210 *
211 * @param xses Self-pointer to event sink.
212 * @param xse A pre-filled out event.
213 */
215};
216
217/*!
218 * @copydoc xrt_session_event_sink::push_event
219 *
220 * Helper for calling through the function pointer.
221 *
222 * @public @memberof xrt_session_event_sink
223 */
224XRT_CHECK_RESULT static inline xrt_result_t
226{
227 return xses->push_event(xses, xse);
228}
229
230
231/*
232 *
233 * Session.
234 *
235 */
236
237/*!
238 * The XRT representation of `XrSession`, this object does not have all of the
239 * functionality of a session, most are partitioned to the session level
240 * compositor object. Often this is @ref xrt_compositor_native, note that
241 * interface may also be a system level object depending in implementer.
242 *
243 * @ingroup xrt_iface
244 */
246{
247 /*!
248 * Poll a single event from this session, if no event is available then
249 * the type of the event will be @ref XRT_SESSION_EVENT_NONE.
250 *
251 * @param xs Pointer to self
252 * @param[out] out_xse Event to be returned.
253 */
255
256 /*!
257 * Destroy the session, must be destroyed after the native compositor.
258 *
259 * Code consuming this interface should use @ref xrt_session_destroy.
260 *
261 * @param xs Pointer to self
262 */
263 void (*destroy)(struct xrt_session *xs);
264};
265
266/*!
267 * @copydoc xrt_session::poll_events
268 *
269 * Helper for calling through the function pointer.
270 *
271 * @public @memberof xrt_session
272 */
273XRT_CHECK_RESULT static inline xrt_result_t
275{
276 return xs->poll_events(xs, out_xse);
277}
278
279/*!
280 * Destroy an xrt_session - helper function.
281 *
282 * @param[in,out] xs_ptr A pointer to the xrt_session struct pointer.
283 *
284 * Will destroy the system if `*xs_ptr` is not NULL. Will then set `*xs_ptr` to
285 * NULL.
286 *
287 * @public @memberof xrt_session
288 */
289static inline void
291{
292 struct xrt_session *xs = *xs_ptr;
293 if (xs == NULL) {
294 return;
295 }
296
297 *xs_ptr = NULL;
298 xs->destroy(xs);
299}
300
301
302#ifdef __cplusplus
303}
304#endif
xrt_session_event_type
Type of a xrt_session event.
Definition: xrt_session.h:37
enum xrt_result xrt_result_t
Result type used across Monado.
xrt_reference_space_type
Type of a OpenXR mapped reference space, maps to the semantic spaces on the xrt_space_overseer struct...
Definition: xrt_defines.h:599
@ XRT_SESSION_EVENT_PASSTHRU_STATE_CHANGE
The passthrough state of the session has changed.
Definition: xrt_session.h:63
@ XRT_SESSION_EVENT_REFERENCE_SPACE_CHANGE_PENDING
A reference space for this session has a pending change.
Definition: xrt_session.h:57
@ XRT_SESSION_EVENT_LOSS_PENDING
The session is about to be lost.
Definition: xrt_session.h:48
@ XRT_SESSION_EVENT_LOST
The session has been lost.
Definition: xrt_session.h:51
@ XRT_SESSION_EVENT_DISPLAY_REFRESH_RATE_CHANGE
The refresh rate of session (compositor) has changed.
Definition: xrt_session.h:54
@ XRT_SESSION_EVENT_STATE_CHANGE
The state of the session has changed.
Definition: xrt_session.h:42
@ XRT_SESSION_EVENT_OVERLAY_CHANGE
The state of the primary session has changed.
Definition: xrt_session.h:45
@ XRT_SESSION_EVENT_NONE
This session has no pending events.
Definition: xrt_session.h:39
@ XRT_SESSION_EVENT_PERFORMANCE_CHANGE
The performance of the session has changed.
Definition: xrt_session.h:60
Main compositor server interface.
Definition: xrt_compositor.h:2224
A pose composed of a position and orientation.
Definition: xrt_defines.h:465
Display refresh rate of compositor changed event, type XRT_SESSION_EVENT_DISPLAY_REFRESH_RATE_CHANGE.
Definition: xrt_session.h:126
Loss pending event, XRT_SESSION_EVENT_LOSS_PENDING.
Definition: xrt_session.h:102
Session lost event, type XRT_SESSION_EVENT_LOST.
Definition: xrt_session.h:114
Primary session state changes event, type XRT_SESSION_EVENT_OVERLAY_CHANGE.
Definition: xrt_session.h:90
Passthrough state change event.
Definition: xrt_session.h:165
Performance metrics change event.
Definition: xrt_session.h:153
Event that tells the application that the reference space has a pending change to it,...
Definition: xrt_session.h:141
Used internally from producers of events to push events into session, some sinks might multiplex even...
Definition: xrt_session.h:206
static XRT_CHECK_RESULT xrt_result_t xrt_session_event_sink_push(struct xrt_session_event_sink *xses, const union xrt_session_event *xse)
Push one event to this sink, data is copied so pointer only needs to be valid for the duration of the...
Definition: xrt_session.h:225
xrt_result_t(* push_event)(struct xrt_session_event_sink *xses, const union xrt_session_event *xse)
Push one event to this sink, data is copied so pointer only needs to be valid for the duration of the...
Definition: xrt_session.h:214
Session state changes event, type XRT_SESSION_EVENT_STATE_CHANGE.
Definition: xrt_session.h:76
Visibility mask changed event.
Definition: xrt_session.h:174
The XRT representation of XrSession, this object does not have all of the functionality of a session,...
Definition: xrt_session.h:246
static void xrt_session_destroy(struct xrt_session **xs_ptr)
Destroy an xrt_session - helper function.
Definition: xrt_session.h:290
xrt_result_t(* poll_events)(struct xrt_session *xs, union xrt_session_event *out_xse)
Poll a single event from this session, if no event is available then the type of the event will be XR...
Definition: xrt_session.h:254
static XRT_CHECK_RESULT xrt_result_t xrt_session_poll_events(struct xrt_session *xs, union xrt_session_event *out_xse)
Poll a single event from this session, if no event is available then the type of the event will be XR...
Definition: xrt_session.h:274
void(* destroy)(struct xrt_session *xs)
Destroy the session, must be destroyed after the native compositor.
Definition: xrt_session.h:263
Union of all session events, used to return multiple events through one call.
Definition: xrt_session.h:186
Header holding common defines.
Common defines and enums for XRT.
xrt_perf_notify_level
Performance level.
Definition: xrt_defines.h:1956
xrt_perf_domain
Domain type.
Definition: xrt_defines.h:1929
xrt_passthrough_state
Specify additional state change behavior.
Definition: xrt_defines.h:133
Header defining xrt space and space overseer.