Monado OpenXR Runtime
xrt_session.h
Go to the documentation of this file.
1// Copyright 2020-2023, Collabora, Ltd.
2// Copyright 2025-2026, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Header for session object.
7 * @author Jakob Bornecrantz <jakob@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_results.h"
16#include "xrt/xrt_space.h"
17
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
24
25
26/*
27 *
28 * Session events.
29 *
30 */
31
32/*!
33 * Type of a @ref xrt_session event.
34 *
35 * @see xrt_session_event
36 * @ingroup xrt_iface
37 */
39{
40 //! This session has no pending events.
42
43 //! The state of the session has changed.
45
46 //! The state of the primary session has changed.
48
49 //! The session is about to be lost.
51
52 //! The session has been lost.
54
55 //! The refresh rate of session (compositor) has changed.
57
58 //! A reference space for this session has a pending change.
60
61 //! The performance of the session has changed
63
64 //! The passthrough state of the session has changed
66
67 // ! The visibility mask of given view has changed
68 XRT_SESSION_EVENT_VISIBILITY_MASK_CHANGE = 9,
69
70 //! User presence has changed (hmd may have been put on or removed)
72
73 //! Request the session to quit.
75};
76
77/*!
78 * Session state changes event, type @ref XRT_SESSION_EVENT_STATE_CHANGE.
79 *
80 * @see xrt_session_event
81 * @ingroup xrt_iface
82 */
84{
85 enum xrt_session_event_type type;
86 bool visible;
87 bool focused;
88 int64_t timestamp_ns;
89};
90
91/*!
92 * Primary session state changes event,
93 * type @ref XRT_SESSION_EVENT_OVERLAY_CHANGE.
94 *
95 * @see xrt_session_event
96 * @ingroup xrt_iface
97 */
99{
100 enum xrt_session_event_type type;
101 bool primary_focused;
102};
103
104/*!
105 * Loss pending event, @ref XRT_SESSION_EVENT_LOSS_PENDING.
106 *
107 * @see xrt_session_event
108 * @ingroup xrt_iface
109 */
111{
112 enum xrt_session_event_type type;
113 XRT_ALIGNAS(8) int64_t loss_time_ns;
114};
115
116/*!
117 * Session lost event, type @ref XRT_SESSION_EVENT_LOST.
118 *
119 * @see xrt_session_event
120 * @ingroup xrt_iface
121 */
123{
124 enum xrt_session_event_type type;
125};
126
127/*!
128 * Display refresh rate of compositor changed event,
129 * type @ref XRT_SESSION_EVENT_DISPLAY_REFRESH_RATE_CHANGE.
130 *
131 * @see xrt_session_event
132 * @ingroup xrt_iface
133 */
135{
136 enum xrt_session_event_type type;
137 float from_display_refresh_rate_hz;
138 float to_display_refresh_rate_hz;
139};
140
141/*!
142 * Event that tells the application that the reference space has a pending
143 * change to it, maps to @p XrEventDataReferenceSpaceChangePending,
144 * type @ref XRT_SESSION_EVENT_REFERENCE_SPACE_CHANGE_PENDING.
145 *
146 * @see xrt_session_event
147 * @ingroup xrt_iface
148 */
150{
151 enum xrt_session_event_type event_type;
152 enum xrt_reference_space_type ref_type;
153 int64_t timestamp_ns;
154 struct xrt_pose pose_in_previous_space;
155 bool pose_valid;
156};
157
158/*!
159 * Performance metrics change event.
160 */
162{
163 enum xrt_session_event_type type;
164 enum xrt_perf_domain domain;
165 enum xrt_perf_sub_domain sub_domain;
166 enum xrt_perf_notify_level from_level;
167 enum xrt_perf_notify_level to_level;
168};
169
170/*!
171 * Passthrough state change event.
172 */
174{
175 enum xrt_session_event_type type;
176 enum xrt_passthrough_state state;
177};
178
179/*!
180 * Visibility mask changed event
181 */
183{
184 enum xrt_session_event_type type;
185 uint32_t view_index;
186};
187
188/*!
189 * User presence changed event
190 */
192{
193 enum xrt_session_event_type type;
194 bool is_user_present;
195};
196
197/*!
198 * Session stop event, type @ref XRT_SESSION_EVENT_REQUEST_EXIT.
199 *
200 * @see xrt_session_event
201 * @ingroup xrt_iface
202 */
204{
205 enum xrt_session_event_type type;
206};
207
208/*!
209 * Union of all session events, used to return multiple events through one call.
210 * Each event struct must start with a @ref xrt_session_event_type field.
211 *
212 * @see xrt_session_event
213 * @ingroup xrt_iface
214 */
216 enum xrt_session_event_type type;
218 struct xrt_session_event_state_change overlay;
219 struct xrt_session_event_loss_pending loss_pending;
220 struct xrt_session_event_lost lost;
223 struct xrt_session_event_perf_change performance;
226 struct xrt_session_event_user_presence_change presence_change;
227 struct xrt_session_event_request_exit request_exit;
228};
229
230/*!
231 * Used internally from producers of events to push events into session, some
232 * sinks might multiplex events to multiple sessions.
233 *
234 * @ingroup xrt_iface
235 */
237{
238 /*!
239 * Push one event to this sink, data is copied so pointer only needs to
240 * be valid for the duration of the call.
241 *
242 * @param xses Self-pointer to event sink.
243 * @param xse A pre-filled out event.
244 */
246};
247
248/*!
249 * @copydoc xrt_session_event_sink::push_event
250 *
251 * Helper for calling through the function pointer.
252 *
253 * @public @memberof xrt_session_event_sink
254 */
255XRT_CHECK_RESULT XRT_NONNULL_ALL static inline xrt_result_t
257{
258 return xses->push_event(xses, xse);
259}
260
261
262/*
263 *
264 * Session.
265 *
266 */
267
268/*!
269 * The XRT representation of `XrSession`, this object does not have all of the
270 * functionality of a session, most are partitioned to the session level
271 * compositor object. Often this is @ref xrt_compositor_native, note that
272 * interface may also be a system level object depending in implementer.
273 *
274 * @ingroup xrt_iface
275 */
277{
278 /*!
279 * Poll a single event from this session, if no event is available then
280 * the type of the event will be @ref XRT_SESSION_EVENT_NONE.
281 *
282 * @param xs Pointer to self
283 * @param[out] out_xse Event to be returned.
284 */
286
287 /*!
288 * Request this session to exit.
289 *
290 * @param xs Pointer to self
291 */
293
294 /*!
295 * Destroy the session, must be destroyed after the native compositor.
296 *
297 * Code consuming this interface should use @ref xrt_session_destroy.
298 *
299 * @param xs Pointer to self
300 */
301 void (*destroy)(struct xrt_session *xs);
302};
303
304/*!
305 * @copydoc xrt_session::poll_events
306 *
307 * Helper for calling through the function pointer.
308 *
309 * @public @memberof xrt_session
310 */
311XRT_CHECK_RESULT XRT_NONNULL_ALL static inline xrt_result_t
313{
314 return xs->poll_events(xs, out_xse);
315}
316
317/*!
318 * @copydoc xrt_session::request_exit
319 *
320 * Helper for calling through the function pointer.
321 *
322 * @public @memberof xrt_session
323 */
324XRT_CHECK_RESULT static inline xrt_result_t
326{
327 return xs->request_exit(xs);
328}
329
330/*!
331 * Destroy an xrt_session - helper function.
332 *
333 * @param[in,out] xs_ptr A pointer to the xrt_session struct pointer.
334 *
335 * Will destroy the system if `*xs_ptr` is not NULL. Will then set `*xs_ptr` to
336 * NULL.
337 *
338 * @public @memberof xrt_session
339 */
340XRT_NONNULL_ALL static inline void
342{
343 struct xrt_session *xs = *xs_ptr;
344 if (xs == NULL) {
345 return;
346 }
347
348 *xs_ptr = NULL;
349 xs->destroy(xs);
350}
351
352
353#ifdef __cplusplus
354}
355#endif
xrt_session_event_type
Type of a xrt_session event.
Definition: xrt_session.h:39
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:612
@ XRT_SESSION_EVENT_PASSTHRU_STATE_CHANGE
The passthrough state of the session has changed.
Definition: xrt_session.h:65
@ XRT_SESSION_EVENT_REFERENCE_SPACE_CHANGE_PENDING
A reference space for this session has a pending change.
Definition: xrt_session.h:59
@ XRT_SESSION_EVENT_LOSS_PENDING
The session is about to be lost.
Definition: xrt_session.h:50
@ XRT_SESSION_EVENT_LOST
The session has been lost.
Definition: xrt_session.h:53
@ XRT_SESSION_EVENT_DISPLAY_REFRESH_RATE_CHANGE
The refresh rate of session (compositor) has changed.
Definition: xrt_session.h:56
@ XRT_SESSION_EVENT_USER_PRESENCE_CHANGE
User presence has changed (hmd may have been put on or removed)
Definition: xrt_session.h:71
@ XRT_SESSION_EVENT_REQUEST_EXIT
Request the session to quit.
Definition: xrt_session.h:74
@ XRT_SESSION_EVENT_STATE_CHANGE
The state of the session has changed.
Definition: xrt_session.h:44
@ XRT_SESSION_EVENT_OVERLAY_CHANGE
The state of the primary session has changed.
Definition: xrt_session.h:47
@ XRT_SESSION_EVENT_NONE
This session has no pending events.
Definition: xrt_session.h:41
@ XRT_SESSION_EVENT_PERFORMANCE_CHANGE
The performance of the session has changed.
Definition: xrt_session.h:62
Main compositor server interface.
Definition: xrt_compositor.h:2236
A pose composed of a position and orientation.
Definition: xrt_defines.h:479
Display refresh rate of compositor changed event, type XRT_SESSION_EVENT_DISPLAY_REFRESH_RATE_CHANGE.
Definition: xrt_session.h:135
Loss pending event, XRT_SESSION_EVENT_LOSS_PENDING.
Definition: xrt_session.h:111
Session lost event, type XRT_SESSION_EVENT_LOST.
Definition: xrt_session.h:123
Primary session state changes event, type XRT_SESSION_EVENT_OVERLAY_CHANGE.
Definition: xrt_session.h:99
Passthrough state change event.
Definition: xrt_session.h:174
Performance metrics change event.
Definition: xrt_session.h:162
Event that tells the application that the reference space has a pending change to it,...
Definition: xrt_session.h:150
Session stop event, type XRT_SESSION_EVENT_REQUEST_EXIT.
Definition: xrt_session.h:204
Used internally from producers of events to push events into session, some sinks might multiplex even...
Definition: xrt_session.h:237
XRT_CHECK_RESULT static XRT_NONNULL_ALL 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:256
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:245
Session state changes event, type XRT_SESSION_EVENT_STATE_CHANGE.
Definition: xrt_session.h:84
User presence changed event.
Definition: xrt_session.h:192
Visibility mask changed event.
Definition: xrt_session.h:183
The XRT representation of XrSession, this object does not have all of the functionality of a session,...
Definition: xrt_session.h:277
XRT_CHECK_RESULT static XRT_NONNULL_ALL 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:312
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:285
static XRT_NONNULL_ALL void xrt_session_destroy(struct xrt_session **xs_ptr)
Destroy an xrt_session - helper function.
Definition: xrt_session.h:341
xrt_result_t(* request_exit)(struct xrt_session *xs)
Request this session to exit.
Definition: xrt_session.h:292
static XRT_CHECK_RESULT xrt_result_t xrt_session_request_exit(struct xrt_session *xs)
Request this session to exit.
Definition: xrt_session.h:325
void(* destroy)(struct xrt_session *xs)
Destroy the session, must be destroyed after the native compositor.
Definition: xrt_session.h:301
Union of all session events, used to return multiple events through one call.
Definition: xrt_session.h:215
Header holding common defines.
Common defines and enums for XRT.
xrt_perf_notify_level
Performance level.
Definition: xrt_defines.h:2343
xrt_perf_domain
Domain type.
Definition: xrt_defines.h:2316
xrt_passthrough_state
Specify additional state change behavior.
Definition: xrt_defines.h:136
Internal result type for XRT.
Header defining xrt space and space overseer.