Commit ec73e6ef authored by Anna Offenwanger's avatar Anna Offenwanger Committed by Commit Bot

Move runtime management logic out of XRDeviceImpl

Runtimes should only be handled by the XRRuntimeManager. Moving the
logic which handles getting current display info as well as checking for
session supports out of XRDeviceImpl is a step in that direction.

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: I95bd331a30c91deb665aa12853f8a80d79c0e51b
Reviewed-on: https://chromium-review.googlesource.com/1181535Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Commit-Queue: Anna Offenwanger <offenwanger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584550}
parent c0af3bf1
...@@ -37,7 +37,7 @@ void BrowserXRRuntime::OnDisplayInfoChanged( ...@@ -37,7 +37,7 @@ void BrowserXRRuntime::OnDisplayInfoChanged(
device::mojom::VRDisplayInfoPtr vr_device_info) { device::mojom::VRDisplayInfoPtr vr_device_info) {
display_info_ = std::move(vr_device_info); display_info_ = std::move(vr_device_info);
for (XRDeviceImpl* device : renderer_device_connections_) { for (XRDeviceImpl* device : renderer_device_connections_) {
device->OnChanged(); device->RuntimesChanged();
} }
} }
......
...@@ -99,7 +99,7 @@ void VRServiceImpl::ConnectRuntime(BrowserXRRuntime* runtime) { ...@@ -99,7 +99,7 @@ void VRServiceImpl::ConnectRuntime(BrowserXRRuntime* runtime) {
// We just need to notify device_ when new capabilities were added after // We just need to notify device_ when new capabilities were added after
// initialization. // initialization.
if (device_) { if (device_) {
device_->OnRuntimeAvailable(runtime); device_->RuntimesChanged();
} }
if (client_) { if (client_) {
...@@ -109,7 +109,7 @@ void VRServiceImpl::ConnectRuntime(BrowserXRRuntime* runtime) { ...@@ -109,7 +109,7 @@ void VRServiceImpl::ConnectRuntime(BrowserXRRuntime* runtime) {
void VRServiceImpl::RemoveRuntime(BrowserXRRuntime* runtime) { void VRServiceImpl::RemoveRuntime(BrowserXRRuntime* runtime) {
if (device_) { if (device_) {
device_->OnRuntimeRemoved(runtime); device_->RuntimesChanged();
} }
if (client_) { if (client_) {
......
...@@ -53,56 +53,6 @@ device::mojom::XRRuntimeSessionOptionsPtr GetRuntimeOptions( ...@@ -53,56 +53,6 @@ device::mojom::XRRuntimeSessionOptionsPtr GetRuntimeOptions(
} // namespace } // namespace
device::mojom::VRDisplayInfoPtr XRDeviceImpl::GetCurrentVRDisplayInfo() {
// Get an immersive_runtime_ device if there is one.
if (!immersive_runtime_) {
immersive_runtime_ = XRRuntimeManager::GetInstance()->GetImmersiveRuntime();
if (immersive_runtime_) {
// Listen to changes for this device.
immersive_runtime_->OnRendererDeviceAdded(this);
}
}
// Get an AR device if there is one.
if (!ar_runtime_) {
device::mojom::XRSessionOptions options = {};
options.provide_passthrough_camera = true;
ar_runtime_ =
XRRuntimeManager::GetInstance()->GetRuntimeForOptions(&options);
if (ar_runtime_) {
// Listen to changes for this device.
ar_runtime_->OnRendererDeviceAdded(this);
}
}
// If there is neither, use the generic non-immersive device.
if (!ar_runtime_ && !immersive_runtime_) {
if (!non_immersive_runtime_) {
device::mojom::XRSessionOptions options = {};
non_immersive_runtime_ =
XRRuntimeManager::GetInstance()->GetRuntimeForOptions(&options);
if (non_immersive_runtime_) {
// Listen to changes for this device.
non_immersive_runtime_->OnRendererDeviceAdded(this);
}
}
// If we don't have an AR or immersive device, return the generic non-
// immersive device's DisplayInfo if we have it.
return non_immersive_runtime_ ? non_immersive_runtime_->GetVRDisplayInfo()
: nullptr;
}
// Use the immersive or AR device. However, if we are using the immersive
// device's info, and AR is supported, reflect that in capabilities.
device::mojom::VRDisplayInfoPtr device_info =
immersive_runtime_ ? immersive_runtime_->GetVRDisplayInfo()
: ar_runtime_->GetVRDisplayInfo();
device_info->capabilities->can_provide_pass_through_images = !!ar_runtime_;
return device_info;
}
XRDeviceImpl::XRDeviceImpl(content::RenderFrameHost* render_frame_host, XRDeviceImpl::XRDeviceImpl(content::RenderFrameHost* render_frame_host,
device::mojom::XRDeviceRequest request) device::mojom::XRDeviceRequest request)
: // TODO(https://crbug.com/846392): render_frame_host can be null because : // TODO(https://crbug.com/846392): render_frame_host can be null because
...@@ -149,12 +99,7 @@ void XRDeviceImpl::OnSessionCreated( ...@@ -149,12 +99,7 @@ void XRDeviceImpl::OnSessionCreated(
} }
XRDeviceImpl::~XRDeviceImpl() { XRDeviceImpl::~XRDeviceImpl() {
if (immersive_runtime_) XRRuntimeManager::GetInstance()->OnRendererDeviceRemoved(this);
immersive_runtime_->OnRendererDeviceRemoved(this);
if (non_immersive_runtime_)
non_immersive_runtime_->OnRendererDeviceRemoved(this);
if (ar_runtime_)
ar_runtime_->OnRendererDeviceRemoved(this);
} }
void XRDeviceImpl::RequestSession( void XRDeviceImpl::RequestSession(
...@@ -220,11 +165,11 @@ void XRDeviceImpl::RequestSession( ...@@ -220,11 +165,11 @@ void XRDeviceImpl::RequestSession(
} }
} }
void XRDeviceImpl::SupportsSession(device::mojom::XRSessionOptionsPtr options, void XRDeviceImpl::SupportsSession(
SupportsSessionCallback callback) { device::mojom::XRSessionOptionsPtr options,
bool supports = XRRuntimeManager::GetInstance()->GetRuntimeForOptions( device::mojom::XRDevice::SupportsSessionCallback callback) {
options.get()) != nullptr; XRRuntimeManager::GetInstance()->SupportsSession(std::move(options),
std::move(callback).Run(supports); std::move(callback));
} }
void XRDeviceImpl::ReportRequestPresent() { void XRDeviceImpl::ReportRequestPresent() {
...@@ -242,20 +187,19 @@ void XRDeviceImpl::ReportRequestPresent() { ...@@ -242,20 +187,19 @@ void XRDeviceImpl::ReportRequestPresent() {
} }
void XRDeviceImpl::ExitPresent() { void XRDeviceImpl::ExitPresent() {
if (immersive_runtime_) BrowserXRRuntime* immersive_runtime =
immersive_runtime_->ExitPresent(this); XRRuntimeManager::GetInstance()->GetImmersiveRuntime();
if (immersive_runtime)
immersive_runtime->ExitPresent(this);
} }
void XRDeviceImpl::SetListeningForActivate( void XRDeviceImpl::SetListeningForActivate(
device::mojom::VRDisplayClientPtr client) { device::mojom::VRDisplayClientPtr client) {
client_ = std::move(client); client_ = std::move(client);
if (!immersive_runtime_) { BrowserXRRuntime* immersive_runtime =
// This function sets the runtimes. XRRuntimeManager::GetInstance()->GetImmersiveRuntime();
GetCurrentVRDisplayInfo(); if (immersive_runtime && client) {
} immersive_runtime->UpdateListeningForActivate(this);
if (immersive_runtime_ && client_) {
immersive_runtime_->UpdateListeningForActivate(this);
} }
} }
...@@ -270,10 +214,11 @@ void XRDeviceImpl::GetImmersiveVRDisplayInfo( ...@@ -270,10 +214,11 @@ void XRDeviceImpl::GetImmersiveVRDisplayInfo(
void XRDeviceImpl::SetInFocusedFrame(bool in_focused_frame) { void XRDeviceImpl::SetInFocusedFrame(bool in_focused_frame) {
in_focused_frame_ = in_focused_frame; in_focused_frame_ = in_focused_frame;
if (ListeningForActivate()) {
if (ListeningForActivate() && immersive_runtime_) { BrowserXRRuntime* immersive_runtime =
// No change, except focus. XRRuntimeManager::GetInstance()->GetImmersiveRuntime();
immersive_runtime_->UpdateListeningForActivate(this); if (immersive_runtime)
immersive_runtime->UpdateListeningForActivate(this);
} }
magic_window_controllers_.ForAllPtrs( magic_window_controllers_.ForAllPtrs(
...@@ -282,8 +227,9 @@ void XRDeviceImpl::SetInFocusedFrame(bool in_focused_frame) { ...@@ -282,8 +227,9 @@ void XRDeviceImpl::SetInFocusedFrame(bool in_focused_frame) {
}); });
} }
void XRDeviceImpl::OnChanged() { void XRDeviceImpl::RuntimesChanged() {
device::mojom::VRDisplayInfoPtr display_info = GetCurrentVRDisplayInfo(); device::mojom::VRDisplayInfoPtr display_info =
XRRuntimeManager::GetInstance()->GetCurrentVRDisplayInfo(this);
if (display_info) { if (display_info) {
session_clients_.ForAllPtrs( session_clients_.ForAllPtrs(
[&display_info](device::mojom::XRSessionClient* client) { [&display_info](device::mojom::XRSessionClient* client) {
...@@ -292,27 +238,6 @@ void XRDeviceImpl::OnChanged() { ...@@ -292,27 +238,6 @@ void XRDeviceImpl::OnChanged() {
} }
} }
void XRDeviceImpl::OnRuntimeRemoved(BrowserXRRuntime* runtime) {
if (runtime == immersive_runtime_) {
immersive_runtime_ = nullptr;
}
if (runtime == non_immersive_runtime_) {
non_immersive_runtime_ = nullptr;
}
if (runtime == ar_runtime_) {
ar_runtime_ = nullptr;
}
// Try to update our VRDisplayInfo.
OnChanged();
}
void XRDeviceImpl::OnRuntimeAvailable(BrowserXRRuntime* runtime) {
// Try to update our VRDisplayInfo. That may use the new device.
OnChanged();
}
void XRDeviceImpl::OnExitPresent() { void XRDeviceImpl::OnExitPresent() {
session_clients_.ForAllPtrs( session_clients_.ForAllPtrs(
......
...@@ -40,8 +40,9 @@ class XRDeviceImpl : public device::mojom::XRDevice { ...@@ -40,8 +40,9 @@ class XRDeviceImpl : public device::mojom::XRDevice {
device::mojom::XRSessionOptionsPtr options, device::mojom::XRSessionOptionsPtr options,
bool triggered_by_displayactive, bool triggered_by_displayactive,
device::mojom::XRDevice::RequestSessionCallback callback) override; device::mojom::XRDevice::RequestSessionCallback callback) override;
void SupportsSession(device::mojom::XRSessionOptionsPtr options, void SupportsSession(
SupportsSessionCallback callback) override; device::mojom::XRSessionOptionsPtr options,
device::mojom::XRDevice::SupportsSessionCallback callback) override;
void ExitPresent() override; void ExitPresent() override;
// device::mojom::XRDevice WebVR compatibility functions // device::mojom::XRDevice WebVR compatibility functions
void GetImmersiveVRDisplayInfo( void GetImmersiveVRDisplayInfo(
...@@ -52,12 +53,8 @@ class XRDeviceImpl : public device::mojom::XRDevice { ...@@ -52,12 +53,8 @@ class XRDeviceImpl : public device::mojom::XRDevice {
void SetInFocusedFrame(bool in_focused_frame); void SetInFocusedFrame(bool in_focused_frame);
// Notifications when devices are added/removed.
void OnRuntimeRemoved(BrowserXRRuntime* device);
void OnRuntimeAvailable(BrowserXRRuntime* device);
// Notifications/calls from BrowserXRRuntime: // Notifications/calls from BrowserXRRuntime:
void OnChanged(); void RuntimesChanged();
void OnExitPresent(); void OnExitPresent();
void OnBlur(); void OnBlur();
void OnFocus(); void OnFocus();
...@@ -88,8 +85,6 @@ class XRDeviceImpl : public device::mojom::XRDevice { ...@@ -88,8 +85,6 @@ class XRDeviceImpl : public device::mojom::XRDevice {
// object. // object.
bool IsSecureContextRequirementSatisfied(); bool IsSecureContextRequirementSatisfied();
device::mojom::VRDisplayInfoPtr GetCurrentVRDisplayInfo();
bool in_focused_frame_ = false; bool in_focused_frame_ = false;
content::RenderFrameHost* render_frame_host_; content::RenderFrameHost* render_frame_host_;
...@@ -102,12 +97,6 @@ class XRDeviceImpl : public device::mojom::XRDevice { ...@@ -102,12 +97,6 @@ class XRDeviceImpl : public device::mojom::XRDevice {
magic_window_controllers_; magic_window_controllers_;
int next_key_ = 0; int next_key_ = 0;
// If we start an immersive session, or are listening to immersive activation,
// notify this device if we are destroyed.
BrowserXRRuntime* immersive_runtime_ = nullptr;
BrowserXRRuntime* non_immersive_runtime_ = nullptr;
BrowserXRRuntime* ar_runtime_ = nullptr;
base::WeakPtrFactory<XRDeviceImpl> weak_ptr_factory_; base::WeakPtrFactory<XRDeviceImpl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(XRDeviceImpl); DISALLOW_COPY_AND_ASSIGN(XRDeviceImpl);
......
...@@ -152,6 +152,64 @@ BrowserXRRuntime* XRRuntimeManager::GetRuntimeForOptions( ...@@ -152,6 +152,64 @@ BrowserXRRuntime* XRRuntimeManager::GetRuntimeForOptions(
return nullptr; return nullptr;
} }
device::mojom::VRDisplayInfoPtr XRRuntimeManager::GetCurrentVRDisplayInfo(
XRDeviceImpl* device) {
// Get an immersive_runtime device if there is one.
auto* immersive_runtime = GetImmersiveRuntime();
if (immersive_runtime) {
// Listen to changes for this device.
immersive_runtime->OnRendererDeviceAdded(device);
}
// Get an AR device if there is one.
device::mojom::XRSessionOptions options = {};
options.provide_passthrough_camera = true;
auto* ar_runtime = GetRuntimeForOptions(&options);
if (ar_runtime) {
// Listen to changes for this device.
ar_runtime->OnRendererDeviceAdded(device);
}
// If there is neither, use the generic non-immersive device.
if (!ar_runtime && !immersive_runtime) {
device::mojom::XRSessionOptions options = {};
auto* non_immersive_runtime = GetRuntimeForOptions(&options);
if (non_immersive_runtime) {
// Listen to changes for this device.
non_immersive_runtime->OnRendererDeviceAdded(device);
}
// If we don't have an AR or immersive device, return the generic non-
// immersive device's DisplayInfo if we have it.
return non_immersive_runtime ? non_immersive_runtime->GetVRDisplayInfo()
: nullptr;
}
// Use the immersive or AR device. However, if we are using the immersive
// device's info, and AR is supported, reflect that in capabilities.
device::mojom::VRDisplayInfoPtr device_info =
immersive_runtime ? immersive_runtime->GetVRDisplayInfo()
: ar_runtime->GetVRDisplayInfo();
device_info->capabilities->can_provide_pass_through_images = !!ar_runtime;
return device_info;
}
void XRRuntimeManager::SupportsSession(
device::mojom::XRSessionOptionsPtr options,
device::mojom::XRDevice::SupportsSessionCallback callback) {
auto* runtime = GetRuntimeForOptions(options.get());
if (!runtime) {
std::move(callback).Run(false);
return;
}
// TODO(http://crbug.com/842025): Pass supports session on to the device
// runtimes.
std::move(callback).Run(true);
}
bool XRRuntimeManager::HasAnyRuntime() { bool XRRuntimeManager::HasAnyRuntime() {
return runtimes_.size() > 0; return runtimes_.size() > 0;
} }
...@@ -196,6 +254,12 @@ void XRRuntimeManager::RemoveService(VRServiceImpl* service) { ...@@ -196,6 +254,12 @@ void XRRuntimeManager::RemoveService(VRServiceImpl* service) {
} }
} }
void XRRuntimeManager::OnRendererDeviceRemoved(XRDeviceImpl* device) {
for (const auto& runtime : runtimes_) {
runtime.second->OnRendererDeviceRemoved(device);
}
}
void XRRuntimeManager::AddRuntime(device::mojom::XRDeviceId id, void XRRuntimeManager::AddRuntime(device::mojom::XRDeviceId id,
device::mojom::VRDisplayInfoPtr info, device::mojom::VRDisplayInfoPtr info,
device::mojom::XRRuntimePtr runtime) { device::mojom::XRRuntimePtr runtime) {
......
...@@ -49,9 +49,15 @@ class VR_EXPORT XRRuntimeManager { ...@@ -49,9 +49,15 @@ class VR_EXPORT XRRuntimeManager {
BrowserXRRuntime* GetRuntimeForOptions( BrowserXRRuntime* GetRuntimeForOptions(
device::mojom::XRSessionOptions* options); device::mojom::XRSessionOptions* options);
BrowserXRRuntime* GetImmersiveRuntime(); BrowserXRRuntime* GetImmersiveRuntime();
device::mojom::VRDisplayInfoPtr GetCurrentVRDisplayInfo(XRDeviceImpl* device);
void OnRendererDeviceRemoved(XRDeviceImpl* device);
bool HasAnyRuntime(); bool HasAnyRuntime();
void SupportsSession(
device::mojom::XRSessionOptionsPtr options,
device::mojom::XRDevice::SupportsSessionCallback callback);
protected: protected:
using ProviderList = std::vector<std::unique_ptr<device::VRDeviceProvider>>; using ProviderList = std::vector<std::unique_ptr<device::VRDeviceProvider>>;
......
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