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 //! User presence has changed (hmd may have been put on or removed)
70};
71
72/*!
73 * Session state changes event, type @ref XRT_SESSION_EVENT_STATE_CHANGE.
74 *
75 * @see xrt_session_event
76 * @ingroup xrt_iface
77 */
79{
80 enum xrt_session_event_type type;
81 bool visible;
82 bool focused;
83 int64_t timestamp_ns;
84};
85
86/*!
87 * Primary session state changes event,
88 * type @ref XRT_SESSION_EVENT_OVERLAY_CHANGE.
89 *
90 * @see xrt_session_event
91 * @ingroup xrt_iface
92 */
94{
95 enum xrt_session_event_type type;
96 bool primary_focused;
97};
98
99/*!
100 * Loss pending event, @ref XRT_SESSION_EVENT_LOSS_PENDING.
101 *
102 * @see xrt_session_event
103 * @ingroup xrt_iface
104 */
106{
107 enum xrt_session_event_type type;
108 XRT_ALIGNAS(8) int64_t loss_time_ns;
109};
110
111/*!
112 * Session lost event, type @ref XRT_SESSION_EVENT_LOST.
113 *
114 * @see xrt_session_event
115 * @ingroup xrt_iface
116 */
118{
119 enum xrt_session_event_type type;
120};
121
122/*!
123 * Display refresh rate of compositor changed event,
124 * type @ref XRT_SESSION_EVENT_DISPLAY_REFRESH_RATE_CHANGE.
125 *
126 * @see xrt_session_event
127 * @ingroup xrt_iface
128 */
130{
131 enum xrt_session_event_type type;
132 float from_display_refresh_rate_hz;
133 float to_display_refresh_rate_hz;
134};
135
136/*!
137 * Event that tells the application that the reference space has a pending
138 * change to it, maps to @p XrEventDataReferenceSpaceChangePending,
139 * type @ref XRT_SESSION_EVENT_REFERENCE_SPACE_CHANGE_PENDING.
140 *
141 * @see xrt_session_event
142 * @ingroup xrt_iface
143 */
145{
146 enum xrt_session_event_type event_type;
147 enum xrt_reference_space_type ref_type;
148 int64_t timestamp_ns;
149 struct xrt_pose pose_in_previous_space;
150 bool pose_valid;
151};
152
153/*!
154 * Performance metrics change event.
155 */
157{
158 enum xrt_session_event_type type;
159 enum xrt_perf_domain domain;
160 enum xrt_perf_sub_domain sub_domain;
161 enum xrt_perf_notify_level from_level;
162 enum xrt_perf_notify_level to_level;
163};
164
165/*!
166 * Passthrough state change event.
167 */
169{
170 enum xrt_session_event_type type;
171 enum xrt_passthrough_state state;
172};
173
174/*!
175 * Visibility mask changed event
176 */
178{
179 enum xrt_session_event_type type;
180 uint32_t view_index;
181};
182
183/*!
184 * User presence changed event
185 */
187{
188 enum xrt_session_event_type type;
189 bool is_user_present;
190};
191
192/*!
193 * Union of all session events, used to return multiple events through one call.
194 * Each event struct must start with a @ref xrt_session_event_type field.
195 *
196 * @see xrt_session_event
197 * @ingroup xrt_iface
198 */
200 enum xrt_session_event_type type;
202 struct xrt_session_event_state_change overlay;
203 struct xrt_session_event_loss_pending loss_pending;
204 struct xrt_session_event_lost lost;
207 struct xrt_session_event_perf_change performance;
210 struct xrt_session_event_user_presence_change presence_change;
211};
212
213/*!
214 * Used internally from producers of events to push events into session, some
215 * sinks might multiplex events to multiple sessions.
216 *
217 * @ingroup xrt_iface
218 */
220{
221 /*!
222 * Push one event to this sink, data is copied so pointer only needs to
223 * be valid for the duration of the call.
224 *
225 * @param xses Self-pointer to event sink.
226 * @param xse A pre-filled out event.
227 */
229};
230
231/*!
232 * @copydoc xrt_session_event_sink::push_event
233 *
234 * Helper for calling through the function pointer.
235 *
236 * @public @memberof xrt_session_event_sink
237 */
238XRT_CHECK_RESULT static inline xrt_result_t
240{
241 return xses->push_event(xses, xse);
242}
243
244
245/*
246 *
247 * Session.
248 *
249 */
250
251/*!
252 * The XRT representation of `XrSession`, this object does not have all of the
253 * functionality of a session, most are partitioned to the session level
254 * compositor object. Often this is @ref xrt_compositor_native, note that
255 * interface may also be a system level object depending in implementer.
256 *
257 * @ingroup xrt_iface
258 */
260{
261 /*!
262 * Poll a single event from this session, if no event is available then
263 * the type of the event will be @ref XRT_SESSION_EVENT_NONE.
264 *
265 * @param xs Pointer to self
266 * @param[out] out_xse Event to be returned.
267 */
269
270 /*!
271 * Destroy the session, must be destroyed after the native compositor.
272 *
273 * Code consuming this interface should use @ref xrt_session_destroy.
274 *
275 * @param xs Pointer to self
276 */
277 void (*destroy)(struct xrt_session *xs);
278};
279
280/*!
281 * @copydoc xrt_session::poll_events
282 *
283 * Helper for calling through the function pointer.
284 *
285 * @public @memberof xrt_session
286 */
287XRT_CHECK_RESULT static inline xrt_result_t
289{
290 return xs->poll_events(xs, out_xse);
291}
292
293/*!
294 * Destroy an xrt_session - helper function.
295 *
296 * @param[in,out] xs_ptr A pointer to the xrt_session struct pointer.
297 *
298 * Will destroy the system if `*xs_ptr` is not NULL. Will then set `*xs_ptr` to
299 * NULL.
300 *
301 * @public @memberof xrt_session
302 */
303static inline void
305{
306 struct xrt_session *xs = *xs_ptr;
307 if (xs == NULL) {
308 return;
309 }
310
311 *xs_ptr = NULL;
312 xs->destroy(xs);
313}
314
315
316#ifdef __cplusplus
317}
318#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:612
@ 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_USER_PRESENCE_CHANGE
User presence has changed (hmd may have been put on or removed)
Definition: xrt_session.h:69
@ 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:2235
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:130
Loss pending event, XRT_SESSION_EVENT_LOSS_PENDING.
Definition: xrt_session.h:106
Session lost event, type XRT_SESSION_EVENT_LOST.
Definition: xrt_session.h:118
Primary session state changes event, type XRT_SESSION_EVENT_OVERLAY_CHANGE.
Definition: xrt_session.h:94
Passthrough state change event.
Definition: xrt_session.h:169
Performance metrics change event.
Definition: xrt_session.h:157
Event that tells the application that the reference space has a pending change to it,...
Definition: xrt_session.h:145
Used internally from producers of events to push events into session, some sinks might multiplex even...
Definition: xrt_session.h:220
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:239
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:228
Session state changes event, type XRT_SESSION_EVENT_STATE_CHANGE.
Definition: xrt_session.h:79
User presence changed event.
Definition: xrt_session.h:187
Visibility mask changed event.
Definition: xrt_session.h:178
The XRT representation of XrSession, this object does not have all of the functionality of a session,...
Definition: xrt_session.h:260
static void xrt_session_destroy(struct xrt_session **xs_ptr)
Destroy an xrt_session - helper function.
Definition: xrt_session.h:304
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:268
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:288
void(* destroy)(struct xrt_session *xs)
Destroy the session, must be destroyed after the native compositor.
Definition: xrt_session.h:277
Union of all session events, used to return multiple events through one call.
Definition: xrt_session.h:199
Header holding common defines.
Common defines and enums for XRT.
xrt_perf_notify_level
Performance level.
Definition: xrt_defines.h:2320
xrt_perf_domain
Domain type.
Definition: xrt_defines.h:2293
xrt_passthrough_state
Specify additional state change behavior.
Definition: xrt_defines.h:136
Header defining xrt space and space overseer.