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 e03ee48dce (reverted in e7643de8db)
This commit is contained in:
Christoph Haag 2020-11-03 23:11:09 +01:00
parent 4709744d0a
commit 965fa60bff
4 changed files with 29 additions and 36 deletions

View file

@ -210,9 +210,6 @@ compositor_wait_frame(struct xrt_compositor *xc,
*predicted_display_time = c->last_next_display_time; *predicted_display_time = c->last_next_display_time;
*out_frame_id = 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; return XRT_SUCCESS;
} }
@ -246,9 +243,6 @@ compositor_wait_frame(struct xrt_compositor *xc,
c->last_next_display_time = next_display_time; c->last_next_display_time = next_display_time;
if (c->state == COMP_STATE_PREPARED) {
c->state = COMP_STATE_WAITED;
}
return XRT_SUCCESS; return XRT_SUCCESS;
} }
} }
@ -529,14 +523,15 @@ compositor_poll_events(struct xrt_compositor *xc,
U_ZERO(out_xce); U_ZERO(out_xce);
switch (c->state) { 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: case COMP_STATE_READY:
out_xce->state.type = XRT_COMPOSITOR_EVENT_NONE; out_xce->state.type = XRT_COMPOSITOR_EVENT_NONE;
break; break;
case COMP_STATE_PREPARED: case COMP_STATE_PREPARED:
out_xce->state.type = XRT_COMPOSITOR_EVENT_NONE; COMP_DEBUG(c, "PREPARED -> VISIBLE");
break;
case COMP_STATE_WAITED:
COMP_DEBUG(c, "WAITED -> VISIBLE");
out_xce->state.type = XRT_COMPOSITOR_EVENT_STATE_CHANGE; out_xce->state.type = XRT_COMPOSITOR_EVENT_STATE_CHANGE;
out_xce->state.visible = true; out_xce->state.visible = true;
c->state = COMP_STATE_VISIBLE; 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->compositor_frame_times.debug_var = ft;
c->state = COMP_STATE_READY;
return &c->base; return &c->base;
} }

View file

@ -127,9 +127,9 @@ struct comp_layer_slot
*/ */
enum comp_state enum comp_state
{ {
COMP_STATE_READY = 0, COMP_STATE_UNINITIALIZED = 0,
COMP_STATE_PREPARED = 1, COMP_STATE_READY = 1,
COMP_STATE_WAITED = 2, COMP_STATE_PREPARED = 2,
COMP_STATE_VISIBLE = 3, COMP_STATE_VISIBLE = 3,
COMP_STATE_FOCUSED = 4, COMP_STATE_FOCUSED = 4,
}; };

View file

@ -1258,6 +1258,9 @@ struct oxr_session
*/ */
bool has_ended_once; bool has_ended_once;
bool compositor_visible;
bool compositor_focused;
bool frame_started; bool frame_started;
bool exiting; bool exiting;

View file

@ -232,7 +232,8 @@ oxr_session_poll(struct oxr_logger *log, struct oxr_session *sess)
return; return;
} }
while (true) { bool read_more_events = true;
while (read_more_events) {
union xrt_compositor_event xce = {0}; union xrt_compositor_event xce = {0};
xc->poll_events(xc, &xce); xc->poll_events(xc, &xce);
@ -240,29 +241,11 @@ oxr_session_poll(struct oxr_logger *log, struct oxr_session *sess)
switch (xce.type) { switch (xce.type) {
case XRT_COMPOSITOR_EVENT_NONE: case XRT_COMPOSITOR_EVENT_NONE:
// No more events. // No more events.
return; read_more_events = false;
break;
case XRT_COMPOSITOR_EVENT_STATE_CHANGE: case XRT_COMPOSITOR_EVENT_STATE_CHANGE:
if (xce.state.visible && sess->compositor_visible = xce.state.visible;
sess->state == XR_SESSION_STATE_SYNCHRONIZED) { sess->compositor_focused = xce.state.focused;
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);
}
break; break;
case XRT_COMPOSITOR_EVENT_OVERLAY_CHANGE: case XRT_COMPOSITOR_EVENT_OVERLAY_CHANGE:
oxr_event_push_XrEventDataMainSessionVisibilityChangedEXTX( oxr_event_push_XrEventDataMainSessionVisibilityChangedEXTX(
@ -273,6 +256,16 @@ oxr_session_poll(struct oxr_logger *log, struct oxr_session *sess)
break; 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 XrResult