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() { ...@@ -93,21 +93,7 @@ void VRServiceImpl::MaybeReturnDevice() {
} }
} }
void VRServiceImpl::ConnectRuntime(BrowserXRRuntime* runtime) { void VRServiceImpl::RuntimesChanged() {
// 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) {
if (device_) { if (device_) {
device_->RuntimesChanged(); device_->RuntimesChanged();
} }
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
namespace vr { namespace vr {
class XRDeviceImpl; class XRDeviceImpl;
class BrowserXRRuntime;
// Browser process implementation of the VRService mojo interface. Instantiated // Browser process implementation of the VRService mojo interface. Instantiated
// through Mojo once the user loads a page containing WebXR. // through Mojo once the user loads a page containing WebXR.
...@@ -36,11 +35,8 @@ class VR_EXPORT VRServiceImpl : public device::mojom::VRService, ...@@ -36,11 +35,8 @@ class VR_EXPORT VRServiceImpl : public device::mojom::VRService,
void RequestDevice(RequestDeviceCallback callback) override; void RequestDevice(RequestDeviceCallback callback) override;
void SetClient(device::mojom::VRServiceClientPtr service_client) override; void SetClient(device::mojom::VRServiceClientPtr service_client) override;
// Tells the renderer that a new VR device is available. // Tells the renderer that the state of the physical devices changed.
void ConnectRuntime(BrowserXRRuntime* device); void RuntimesChanged();
// Tells the renderer that a VR device has gone away.
void RemoveRuntime(BrowserXRRuntime* device);
void InitializationComplete(); void InitializationComplete();
......
...@@ -120,11 +120,7 @@ void XRDeviceImpl::RequestSession( ...@@ -120,11 +120,7 @@ void XRDeviceImpl::RequestSession(
return; return;
} }
BrowserXRRuntime* presenting_runtime = if (XRRuntimeManager::GetInstance()->IsOtherDevicePresenting(this)) {
XRRuntimeManager::GetInstance()->GetImmersiveRuntime();
if (presenting_runtime &&
presenting_runtime->GetPresentingRendererDevice() != this &&
presenting_runtime->GetPresentingRendererDevice() != nullptr) {
// Can't create sessions while an immersive session exists. // Can't create sessions while an immersive session exists.
std::move(callback).Run(nullptr); std::move(callback).Run(nullptr);
return; return;
...@@ -238,7 +234,6 @@ void XRDeviceImpl::RuntimesChanged() { ...@@ -238,7 +234,6 @@ void XRDeviceImpl::RuntimesChanged() {
} }
} }
void XRDeviceImpl::OnExitPresent() { void XRDeviceImpl::OnExitPresent() {
session_clients_.ForAllPtrs( session_clients_.ForAllPtrs(
[](device::mojom::XRSessionClient* client) { client->OnExitPresent(); }); [](device::mojom::XRSessionClient* client) { client->OnExitPresent(); });
......
...@@ -152,6 +152,12 @@ BrowserXRRuntime* XRRuntimeManager::GetRuntimeForOptions( ...@@ -152,6 +152,12 @@ BrowserXRRuntime* XRRuntimeManager::GetRuntimeForOptions(
return nullptr; return nullptr;
} }
bool XRRuntimeManager::IsOtherDevicePresenting(XRDeviceImpl* device) {
auto* runtime = GetImmersiveRuntime();
return runtime && runtime->GetPresentingRendererDevice() &&
runtime->GetPresentingRendererDevice() != device;
}
device::mojom::VRDisplayInfoPtr XRRuntimeManager::GetCurrentVRDisplayInfo( device::mojom::VRDisplayInfoPtr XRRuntimeManager::GetCurrentVRDisplayInfo(
XRDeviceImpl* device) { XRDeviceImpl* device) {
// Get an immersive_runtime device if there is one. // Get an immersive_runtime device if there is one.
...@@ -269,7 +275,7 @@ void XRRuntimeManager::AddRuntime(device::mojom::XRDeviceId id, ...@@ -269,7 +275,7 @@ void XRRuntimeManager::AddRuntime(device::mojom::XRDeviceId id,
runtimes_[id] = runtimes_[id] =
std::make_unique<BrowserXRRuntime>(std::move(runtime), std::move(info)); std::make_unique<BrowserXRRuntime>(std::move(runtime), std::move(info));
for (VRServiceImpl* service : services_) for (VRServiceImpl* service : services_)
service->ConnectRuntime(runtimes_[id].get()); service->RuntimesChanged();
} }
void XRRuntimeManager::RemoveRuntime(device::mojom::XRDeviceId id) { void XRRuntimeManager::RemoveRuntime(device::mojom::XRDeviceId id) {
...@@ -283,7 +289,7 @@ void XRRuntimeManager::RemoveRuntime(device::mojom::XRDeviceId id) { ...@@ -283,7 +289,7 @@ void XRRuntimeManager::RemoveRuntime(device::mojom::XRDeviceId id) {
runtimes_.erase(it); runtimes_.erase(it);
for (VRServiceImpl* service : services_) for (VRServiceImpl* service : services_)
service->RemoveRuntime(removed_device.get()); service->RuntimesChanged();
} }
void XRRuntimeManager::RecordVrStartupHistograms() { void XRRuntimeManager::RecordVrStartupHistograms() {
......
...@@ -52,6 +52,9 @@ class VR_EXPORT XRRuntimeManager { ...@@ -52,6 +52,9 @@ class VR_EXPORT XRRuntimeManager {
device::mojom::VRDisplayInfoPtr GetCurrentVRDisplayInfo(XRDeviceImpl* device); device::mojom::VRDisplayInfoPtr GetCurrentVRDisplayInfo(XRDeviceImpl* device);
void OnRendererDeviceRemoved(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(); bool HasAnyRuntime();
void SupportsSession( 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