Commit 7ec20900 authored by Anna Offenwanger's avatar Anna Offenwanger Committed by Commit Bot

Move runtime management logic to XRRuntimeManager

Runtimes should only be handled by the XRRuntimeManager. VRServiceImpl
needs to know if capabilities have changed, but does not need to know if
runtimes were added or removed, so we can merge those functions into one
and remove XRRuntime from VRServiceImpl, which will forward this end.
Also moved logic to check in the runtimes if an XRDeviceImpl is
presenting to the manager.

Bug: 842025
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:linux_vr;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I4e155dbb4ff603572338a0d543ca030cd574ffb8
Reviewed-on: https://chromium-review.googlesource.com/1181685Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Commit-Queue: Anna Offenwanger <offenwanger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584808}
parent 70263d6d
......@@ -93,21 +93,7 @@ void VRServiceImpl::MaybeReturnDevice() {
}
}
void VRServiceImpl::ConnectRuntime(BrowserXRRuntime* runtime) {
// device_ is initialized on IntializationComplete. Devices may be added
// before that, but they'll be picked up during device_'s constructor.
// We just need to notify device_ when new capabilities were added after
// initialization.
if (device_) {
device_->RuntimesChanged();
}
if (client_) {
client_->OnDeviceChanged();
}
}
void VRServiceImpl::RemoveRuntime(BrowserXRRuntime* runtime) {
void VRServiceImpl::RuntimesChanged() {
if (device_) {
device_->RuntimesChanged();
}
......
......@@ -19,7 +19,6 @@
namespace vr {
class XRDeviceImpl;
class BrowserXRRuntime;
// Browser process implementation of the VRService mojo interface. Instantiated
// through Mojo once the user loads a page containing WebXR.
......@@ -36,11 +35,8 @@ class VR_EXPORT VRServiceImpl : public device::mojom::VRService,
void RequestDevice(RequestDeviceCallback callback) override;
void SetClient(device::mojom::VRServiceClientPtr service_client) override;
// Tells the renderer that a new VR device is available.
void ConnectRuntime(BrowserXRRuntime* device);
// Tells the renderer that a VR device has gone away.
void RemoveRuntime(BrowserXRRuntime* device);
// Tells the renderer that the state of the physical devices changed.
void RuntimesChanged();
void InitializationComplete();
......
......@@ -120,11 +120,7 @@ void XRDeviceImpl::RequestSession(
return;
}
BrowserXRRuntime* presenting_runtime =
XRRuntimeManager::GetInstance()->GetImmersiveRuntime();
if (presenting_runtime &&
presenting_runtime->GetPresentingRendererDevice() != this &&
presenting_runtime->GetPresentingRendererDevice() != nullptr) {
if (XRRuntimeManager::GetInstance()->IsOtherDevicePresenting(this)) {
// Can't create sessions while an immersive session exists.
std::move(callback).Run(nullptr);
return;
......@@ -238,7 +234,6 @@ void XRDeviceImpl::RuntimesChanged() {
}
}
void XRDeviceImpl::OnExitPresent() {
session_clients_.ForAllPtrs(
[](device::mojom::XRSessionClient* client) { client->OnExitPresent(); });
......
......@@ -152,6 +152,12 @@ BrowserXRRuntime* XRRuntimeManager::GetRuntimeForOptions(
return nullptr;
}
bool XRRuntimeManager::IsOtherDevicePresenting(XRDeviceImpl* device) {
auto* runtime = GetImmersiveRuntime();
return runtime && runtime->GetPresentingRendererDevice() &&
runtime->GetPresentingRendererDevice() != device;
}
device::mojom::VRDisplayInfoPtr XRRuntimeManager::GetCurrentVRDisplayInfo(
XRDeviceImpl* device) {
// Get an immersive_runtime device if there is one.
......@@ -269,7 +275,7 @@ void XRRuntimeManager::AddRuntime(device::mojom::XRDeviceId id,
runtimes_[id] =
std::make_unique<BrowserXRRuntime>(std::move(runtime), std::move(info));
for (VRServiceImpl* service : services_)
service->ConnectRuntime(runtimes_[id].get());
service->RuntimesChanged();
}
void XRRuntimeManager::RemoveRuntime(device::mojom::XRDeviceId id) {
......@@ -283,7 +289,7 @@ void XRRuntimeManager::RemoveRuntime(device::mojom::XRDeviceId id) {
runtimes_.erase(it);
for (VRServiceImpl* service : services_)
service->RemoveRuntime(removed_device.get());
service->RuntimesChanged();
}
void XRRuntimeManager::RecordVrStartupHistograms() {
......
......@@ -52,6 +52,9 @@ class VR_EXPORT XRRuntimeManager {
device::mojom::VRDisplayInfoPtr GetCurrentVRDisplayInfo(XRDeviceImpl* device);
void OnRendererDeviceRemoved(XRDeviceImpl* device);
// Returns true if another device is presenting. Returns false if this device
// is presenting, or if nobody is presenting.
bool IsOtherDevicePresenting(XRDeviceImpl* device);
bool HasAnyRuntime();
void SupportsSession(
......
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