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