From 965fa60bff8e8354bd01aadeaf721d1f03d4bc2a Mon Sep 17 00:00:00 2001 From: Christoph Haag Date: Tue, 3 Nov 2020 23:11:09 +0100 Subject: [PATCH] xrt: Move synchronized state test into oxr session The compositor now moves immediately to visible/focused when polling. The state tracker will generate relevant openxr state changes once the session is synchronized. Properly working alternative to e03ee48dcea88427ac3272ccab70bb665b1618a4 (reverted in e7643de8dbb10884736107284c2fdad56c7a6c83) --- src/xrt/compositor/main/comp_compositor.c | 17 ++++------ src/xrt/compositor/main/comp_compositor.h | 6 ++-- src/xrt/state_trackers/oxr/oxr_objects.h | 3 ++ src/xrt/state_trackers/oxr/oxr_session.c | 39 ++++++++++------------- 4 files changed, 29 insertions(+), 36 deletions(-) diff --git a/src/xrt/compositor/main/comp_compositor.c b/src/xrt/compositor/main/comp_compositor.c index afd58c7b1..c8005771d 100644 --- a/src/xrt/compositor/main/comp_compositor.c +++ b/src/xrt/compositor/main/comp_compositor.c @@ -210,9 +210,6 @@ compositor_wait_frame(struct xrt_compositor *xc, *predicted_display_time = c->last_next_display_time; *out_frame_id = c->last_next_display_time; - if (c->state == COMP_STATE_PREPARED) { - c->state = COMP_STATE_WAITED; - } return XRT_SUCCESS; } @@ -246,9 +243,6 @@ compositor_wait_frame(struct xrt_compositor *xc, c->last_next_display_time = next_display_time; - if (c->state == COMP_STATE_PREPARED) { - c->state = COMP_STATE_WAITED; - } return XRT_SUCCESS; } } @@ -529,14 +523,15 @@ compositor_poll_events(struct xrt_compositor *xc, U_ZERO(out_xce); switch (c->state) { + case COMP_STATE_UNINITIALIZED: + COMP_ERROR(c, "Polled uninitialized compositor"); + out_xce->state.type = XRT_COMPOSITOR_EVENT_NONE; + break; case COMP_STATE_READY: out_xce->state.type = XRT_COMPOSITOR_EVENT_NONE; break; case COMP_STATE_PREPARED: - out_xce->state.type = XRT_COMPOSITOR_EVENT_NONE; - break; - case COMP_STATE_WAITED: - COMP_DEBUG(c, "WAITED -> VISIBLE"); + COMP_DEBUG(c, "PREPARED -> VISIBLE"); out_xce->state.type = XRT_COMPOSITOR_EVENT_STATE_CHANGE; out_xce->state.visible = true; c->state = COMP_STATE_VISIBLE; @@ -1373,6 +1368,8 @@ xrt_gfx_provider_create_native(struct xrt_device *xdev) c->compositor_frame_times.debug_var = ft; + c->state = COMP_STATE_READY; + return &c->base; } diff --git a/src/xrt/compositor/main/comp_compositor.h b/src/xrt/compositor/main/comp_compositor.h index 9448704be..94cf7dbcf 100644 --- a/src/xrt/compositor/main/comp_compositor.h +++ b/src/xrt/compositor/main/comp_compositor.h @@ -127,9 +127,9 @@ struct comp_layer_slot */ enum comp_state { - COMP_STATE_READY = 0, - COMP_STATE_PREPARED = 1, - COMP_STATE_WAITED = 2, + COMP_STATE_UNINITIALIZED = 0, + COMP_STATE_READY = 1, + COMP_STATE_PREPARED = 2, COMP_STATE_VISIBLE = 3, COMP_STATE_FOCUSED = 4, }; diff --git a/src/xrt/state_trackers/oxr/oxr_objects.h b/src/xrt/state_trackers/oxr/oxr_objects.h index 0478c176e..63e8bc722 100644 --- a/src/xrt/state_trackers/oxr/oxr_objects.h +++ b/src/xrt/state_trackers/oxr/oxr_objects.h @@ -1258,6 +1258,9 @@ struct oxr_session */ bool has_ended_once; + bool compositor_visible; + bool compositor_focused; + bool frame_started; bool exiting; diff --git a/src/xrt/state_trackers/oxr/oxr_session.c b/src/xrt/state_trackers/oxr/oxr_session.c index f9c872e2a..cdb5f5337 100644 --- a/src/xrt/state_trackers/oxr/oxr_session.c +++ b/src/xrt/state_trackers/oxr/oxr_session.c @@ -232,7 +232,8 @@ oxr_session_poll(struct oxr_logger *log, struct oxr_session *sess) return; } - while (true) { + bool read_more_events = true; + while (read_more_events) { union xrt_compositor_event xce = {0}; xc->poll_events(xc, &xce); @@ -240,29 +241,11 @@ oxr_session_poll(struct oxr_logger *log, struct oxr_session *sess) switch (xce.type) { case XRT_COMPOSITOR_EVENT_NONE: // No more events. - return; + read_more_events = false; + break; case XRT_COMPOSITOR_EVENT_STATE_CHANGE: - if (xce.state.visible && - sess->state == XR_SESSION_STATE_SYNCHRONIZED) { - oxr_session_change_state( - log, sess, XR_SESSION_STATE_VISIBLE); - } - if (xce.state.focused && - sess->state == XR_SESSION_STATE_VISIBLE) { - oxr_session_change_state( - log, sess, XR_SESSION_STATE_FOCUSED); - } - - if (!xce.state.focused && - sess->state == XR_SESSION_STATE_FOCUSED) { - oxr_session_change_state( - log, sess, XR_SESSION_STATE_VISIBLE); - } - if (!xce.state.visible && - sess->state == XR_SESSION_STATE_VISIBLE) { - oxr_session_change_state( - log, sess, XR_SESSION_STATE_SYNCHRONIZED); - } + sess->compositor_visible = xce.state.visible; + sess->compositor_focused = xce.state.focused; break; case XRT_COMPOSITOR_EVENT_OVERLAY_CHANGE: oxr_event_push_XrEventDataMainSessionVisibilityChangedEXTX( @@ -273,6 +256,16 @@ oxr_session_poll(struct oxr_logger *log, struct oxr_session *sess) break; } } + + if (sess->state == XR_SESSION_STATE_SYNCHRONIZED && + sess->compositor_visible) { + oxr_session_change_state(log, sess, XR_SESSION_STATE_VISIBLE); + } + + if (sess->state == XR_SESSION_STATE_VISIBLE && + sess->compositor_focused) { + oxr_session_change_state(log, sess, XR_SESSION_STATE_FOCUSED); + } } XrResult