Commit 0bf5ea01 authored by Phu Le's avatar Phu Le Committed by Chromium LUCI CQ

Allow OpenXR device to reliably terminate XR sessions

Currently today OpenXR event pump does not have a callback to the render
loop and instead setting a state for session end and relies on the next
frame to check that state.  This is not reliable as most of the time,
the frame pump stops after sessions ends and the state logic has race
condition inside that changes as the code churns. This change add an
explicit callback to notify the end of a XR session so that the render
loop can reliably trigger the blink callback on session's end.

Bug: 1148648
Change-Id: I5447b0d053bbc1d575c9b509edc0ca5d6f76bca8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2535852
Commit-Queue: Phu Le <phle@microsoft.com>
Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833802}
parent 8389a73f
......@@ -684,6 +684,7 @@ XrResult OpenXrApiWrapper::ProcessEvents() {
session_running_ = false;
xr_result = xrEndSession(session_);
Uninitialize();
on_session_ended_callback_.Run();
return xr_result;
case XR_SESSION_STATE_SYNCHRONIZED:
visibility_changed_callback_.Run(
......@@ -858,6 +859,11 @@ void OpenXrApiWrapper::RegisterVisibilityChangeCallback(
visibility_changed_callback_ = std::move(visibility_changed_callback);
}
void OpenXrApiWrapper::RegisterOnSessionEndedCallback(
const base::RepeatingCallback<void()>& on_session_ended_callback) {
on_session_ended_callback_ = std::move(on_session_ended_callback);
}
VRTestHook* OpenXrApiWrapper::test_hook_ = nullptr;
ServiceTestHook* OpenXrApiWrapper::service_test_hook_ = nullptr;
void OpenXrApiWrapper::SetTestHook(VRTestHook* hook) {
......
......@@ -71,6 +71,8 @@ class OpenXrApiWrapper {
void RegisterVisibilityChangeCallback(
const base::RepeatingCallback<void(mojom::XRVisibilityState)>&
visibility_changed_callback);
void RegisterOnSessionEndedCallback(
const base::RepeatingCallback<void()>& on_session_ended_callback);
device::mojom::XREnvironmentBlendMode PickEnvironmentBlendModeForSession(
device::mojom::XRSessionMode session_mode);
......@@ -125,6 +127,7 @@ class OpenXrApiWrapper {
interaction_profile_changed_callback_;
base::RepeatingCallback<void(mojom::XRVisibilityState)>
visibility_changed_callback_;
base::RepeatingCallback<void()> on_session_ended_callback_;
// Testing objects
static VRTestHook* test_hook_;
......
......@@ -112,6 +112,8 @@ bool OpenXrRenderLoop::StartRuntime() {
input_helper_->GetWeakPtr()));
openxr_->RegisterVisibilityChangeCallback(base::BindRepeating(
&OpenXrRenderLoop::SetVisibilityState, weak_ptr_factory_.GetWeakPtr()));
openxr_->RegisterOnSessionEndedCallback(base::BindRepeating(
&OpenXrRenderLoop::ExitPresent, weak_ptr_factory_.GetWeakPtr()));
InitializeDisplayInfo();
return true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment