Commit 4f541dad authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Make disabling magic window a cross-platform concept + add regression test.

Moves the concept of disabling magic window poses into VRDeviceBase.

Bug: 777868
Change-Id: I5ab317faf5ad04abb47558e041446cfc1a484da0
Reviewed-on: https://chromium-review.googlesource.com/776165
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarDavid Dorwin <ddorwin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#518369}
parent f9a91987
...@@ -79,9 +79,12 @@ VrShellDelegate* VrShellDelegate::GetNativeVrShellDelegate( ...@@ -79,9 +79,12 @@ VrShellDelegate* VrShellDelegate::GetNativeVrShellDelegate(
void VrShellDelegate::SetDelegate(VrShell* vr_shell, void VrShellDelegate::SetDelegate(VrShell* vr_shell,
gvr::ViewerType viewer_type) { gvr::ViewerType viewer_type) {
vr_shell_ = vr_shell; vr_shell_ = vr_shell;
device::GvrDevice* device = static_cast<device::GvrDevice*>(GetDevice()); device::VRDevice* device = GetDevice();
// When VrShell is created, we disable magic window mode as the user is inside
// the headset. As currently implemented, orientation-based magic window
// doesn't make sense when the window is fixed and the user is moving.
if (device) if (device)
device->SetInBrowsingMode(true); device->SetMagicWindowEnabled(false);
if (pending_successful_present_request_) { if (pending_successful_present_request_) {
CHECK(!present_callback_.is_null()); CHECK(!present_callback_.is_null());
...@@ -94,9 +97,9 @@ void VrShellDelegate::SetDelegate(VrShell* vr_shell, ...@@ -94,9 +97,9 @@ void VrShellDelegate::SetDelegate(VrShell* vr_shell,
void VrShellDelegate::RemoveDelegate() { void VrShellDelegate::RemoveDelegate() {
vr_shell_ = nullptr; vr_shell_ = nullptr;
device::GvrDevice* device = static_cast<device::GvrDevice*>(GetDevice()); device::VRDevice* device = GetDevice();
if (device) { if (device) {
device->SetInBrowsingMode(false); device->SetMagicWindowEnabled(true);
device->OnExitPresent(); device->OnExitPresent();
} }
} }
...@@ -177,9 +180,12 @@ void VrShellDelegate::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { ...@@ -177,9 +180,12 @@ void VrShellDelegate::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
void VrShellDelegate::SetDeviceId(unsigned int device_id) { void VrShellDelegate::SetDeviceId(unsigned int device_id) {
device_id_ = device_id; device_id_ = device_id;
if (vr_shell_) { if (vr_shell_) {
device::GvrDevice* device = static_cast<device::GvrDevice*>(GetDevice()); device::VRDevice* device = GetDevice();
// See comment in VrShellDelegate::SetDelegate. This handles the case where
// VrShell is created before the device/ code is initialized (like when
// entering VR browsing on a non-webVR page).
if (device) if (device)
device->SetInBrowsingMode(true); device->SetMagicWindowEnabled(false);
} }
} }
......
...@@ -180,12 +180,8 @@ void GvrDevice::ExitPresent() { ...@@ -180,12 +180,8 @@ void GvrDevice::ExitPresent() {
OnExitPresent(); OnExitPresent();
} }
void GvrDevice::GetPose( void GvrDevice::OnMagicWindowPoseRequest(
mojom::VRMagicWindowProvider::GetPoseCallback callback) { mojom::VRMagicWindowProvider::GetPoseCallback callback) {
if (in_browsing_mode_) {
std::move(callback).Run(nullptr);
return;
}
std::move(callback).Run( std::move(callback).Run(
GvrDelegate::GetVRPosePtrWithNeckModel(gvr_api_.get(), nullptr)); GvrDelegate::GetVRPosePtrWithNeckModel(gvr_api_.get(), nullptr));
} }
......
...@@ -32,7 +32,6 @@ class DEVICE_VR_EXPORT GvrDevice : public VRDeviceBase { ...@@ -32,7 +32,6 @@ class DEVICE_VR_EXPORT GvrDevice : public VRDeviceBase {
mojom::VRPresentationProviderRequest request, mojom::VRPresentationProviderRequest request,
mojom::VRDisplayHost::RequestPresentCallback callback) override; mojom::VRDisplayHost::RequestPresentCallback callback) override;
void ExitPresent() override; void ExitPresent() override;
void GetPose(mojom::VRMagicWindowProvider::GetPoseCallback callback) override;
void PauseTracking() override; void PauseTracking() override;
void ResumeTracking() override; void ResumeTracking() override;
...@@ -42,13 +41,12 @@ class DEVICE_VR_EXPORT GvrDevice : public VRDeviceBase { ...@@ -42,13 +41,12 @@ class DEVICE_VR_EXPORT GvrDevice : public VRDeviceBase {
void Activate(mojom::VRDisplayEventReason reason, void Activate(mojom::VRDisplayEventReason reason,
base::Callback<void(bool)> on_handled); base::Callback<void(bool)> on_handled);
// TODO(mthiesse): Make this functionality cross-platform.
void SetInBrowsingMode(bool in_browsing_mode) {
in_browsing_mode_ = in_browsing_mode;
}
private: private:
// VRDeviceBase
void OnListeningForActivate(bool listening) override; void OnListeningForActivate(bool listening) override;
void OnMagicWindowPoseRequest(
mojom::VRMagicWindowProvider::GetPoseCallback callback) override;
void OnRequestPresentResult( void OnRequestPresentResult(
mojom::VRDisplayHost::RequestPresentCallback callback, mojom::VRDisplayHost::RequestPresentCallback callback,
VRDisplayImpl* display, VRDisplayImpl* display,
...@@ -59,7 +57,6 @@ class DEVICE_VR_EXPORT GvrDevice : public VRDeviceBase { ...@@ -59,7 +57,6 @@ class DEVICE_VR_EXPORT GvrDevice : public VRDeviceBase {
base::android::ScopedJavaGlobalRef<jobject> non_presenting_context_; base::android::ScopedJavaGlobalRef<jobject> non_presenting_context_;
std::unique_ptr<gvr::GvrApi> gvr_api_; std::unique_ptr<gvr::GvrApi> gvr_api_;
bool in_browsing_mode_ = false;
base::WeakPtrFactory<GvrDevice> weak_ptr_factory_; base::WeakPtrFactory<GvrDevice> weak_ptr_factory_;
......
...@@ -189,7 +189,7 @@ void OpenVRDevice::ExitPresent() { ...@@ -189,7 +189,7 @@ void OpenVRDevice::ExitPresent() {
base::Bind(&OpenVRRenderLoop::ExitPresent, render_loop_->GetWeakPtr())); base::Bind(&OpenVRRenderLoop::ExitPresent, render_loop_->GetWeakPtr()));
} }
void OpenVRDevice::GetPose( void OpenVRDevice::OnMagicWindowPoseRequest(
mojom::VRMagicWindowProvider::GetPoseCallback callback) { mojom::VRMagicWindowProvider::GetPoseCallback callback) {
vr::TrackedDevicePose_t rendering_poses[vr::k_unMaxTrackedDeviceCount]; vr::TrackedDevicePose_t rendering_poses[vr::k_unMaxTrackedDeviceCount];
vr_system_->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseSeated, 0.03f, vr_system_->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseSeated, 0.03f,
......
...@@ -33,7 +33,6 @@ class OpenVRDevice : public VRDeviceBase { ...@@ -33,7 +33,6 @@ class OpenVRDevice : public VRDeviceBase {
mojom::VRPresentationProviderRequest request, mojom::VRPresentationProviderRequest request,
mojom::VRDisplayHost::RequestPresentCallback callback) override; mojom::VRDisplayHost::RequestPresentCallback callback) override;
void ExitPresent() override; void ExitPresent() override;
void GetPose(mojom::VRMagicWindowProvider::GetPoseCallback callback) override;
void OnPollingEvents(); void OnPollingEvents();
...@@ -42,6 +41,10 @@ class OpenVRDevice : public VRDeviceBase { ...@@ -42,6 +41,10 @@ class OpenVRDevice : public VRDeviceBase {
bool result); bool result);
private: private:
// VRDeviceBase
void OnMagicWindowPoseRequest(
mojom::VRMagicWindowProvider::GetPoseCallback callback) override;
// TODO (BillOrr): This should not be a unique_ptr because the render_loop_ // TODO (BillOrr): This should not be a unique_ptr because the render_loop_
// binds to VRVSyncProvider requests, so its lifetime should be tied to the // binds to VRVSyncProvider requests, so its lifetime should be tied to the
// lifetime of that binding. // lifetime of that binding.
......
...@@ -62,4 +62,9 @@ void FakeVRDevice::ExitPresent() { ...@@ -62,4 +62,9 @@ void FakeVRDevice::ExitPresent() {
OnExitPresent(); OnExitPresent();
} }
void FakeVRDevice::OnMagicWindowPoseRequest(
mojom::VRMagicWindowProvider::GetPoseCallback callback) {
std::move(callback).Run(pose_.Clone());
}
} // namespace device } // namespace device
...@@ -26,10 +26,17 @@ class DEVICE_VR_EXPORT FakeVRDevice : public VRDeviceBase { ...@@ -26,10 +26,17 @@ class DEVICE_VR_EXPORT FakeVRDevice : public VRDeviceBase {
mojom::VRDisplayHost::RequestPresentCallback callback) override; mojom::VRDisplayHost::RequestPresentCallback callback) override;
void ExitPresent() override; void ExitPresent() override;
void SetPose(mojom::VRPosePtr pose) { pose_ = std::move(pose); }
private: private:
void OnMagicWindowPoseRequest(
mojom::VRMagicWindowProvider::GetPoseCallback callback) override;
mojom::VRDisplayInfoPtr InitBasicDevice(); mojom::VRDisplayInfoPtr InitBasicDevice();
mojom::VREyeParametersPtr InitEye(float fov, float offset, uint32_t size); mojom::VREyeParametersPtr InitEye(float fov, float offset, uint32_t size);
mojom::VRPosePtr pose_;
DISALLOW_COPY_AND_ASSIGN(FakeVRDevice); DISALLOW_COPY_AND_ASSIGN(FakeVRDevice);
}; };
......
...@@ -27,6 +27,7 @@ class DEVICE_VR_EXPORT VRDevice { ...@@ -27,6 +27,7 @@ class DEVICE_VR_EXPORT VRDevice {
virtual void Blur() = 0; virtual void Blur() = 0;
virtual void Focus() = 0; virtual void Focus() = 0;
virtual mojom::VRDisplayInfoPtr GetVRDisplayInfo() = 0; virtual mojom::VRDisplayInfoPtr GetVRDisplayInfo() = 0;
virtual void SetMagicWindowEnabled(bool enabled) = 0;
// TODO(mthiesse): The browser should handle browser-side exiting of // TODO(mthiesse): The browser should handle browser-side exiting of
// presentation before device/ is even aware presentation is being exited. // presentation before device/ is even aware presentation is being exited.
......
...@@ -63,9 +63,18 @@ void VRDeviceBase::ExitPresent() { ...@@ -63,9 +63,18 @@ void VRDeviceBase::ExitPresent() {
NOTREACHED(); NOTREACHED();
} }
void VRDeviceBase::GetPose( void VRDeviceBase::SetMagicWindowEnabled(bool enabled) {
magic_window_enabled_ = enabled;
}
void VRDeviceBase::GetMagicWindowPose(
mojom::VRMagicWindowProvider::GetPoseCallback callback) { mojom::VRMagicWindowProvider::GetPoseCallback callback) {
if (!magic_window_enabled_) {
std::move(callback).Run(nullptr); std::move(callback).Run(nullptr);
return;
}
OnMagicWindowPoseRequest(std::move(callback));
} }
void VRDeviceBase::AddDisplay(VRDisplayImpl* display) { void VRDeviceBase::AddDisplay(VRDisplayImpl* display) {
...@@ -132,6 +141,11 @@ void VRDeviceBase::OnActivate(mojom::VRDisplayEventReason reason, ...@@ -132,6 +141,11 @@ void VRDeviceBase::OnActivate(mojom::VRDisplayEventReason reason,
void VRDeviceBase::OnListeningForActivate(bool listening) {} void VRDeviceBase::OnListeningForActivate(bool listening) {}
void VRDeviceBase::OnMagicWindowPoseRequest(
mojom::VRMagicWindowProvider::GetPoseCallback callback) {
std::move(callback).Run(nullptr);
}
void VRDeviceBase::UpdateListeningForActivate(VRDisplayImpl* display) { void VRDeviceBase::UpdateListeningForActivate(VRDisplayImpl* display) {
if (display->ListeningForActivate() && display->InFocusedFrame()) { if (display->ListeningForActivate() && display->InFocusedFrame()) {
bool was_listening = !!listening_for_activate_diplay_; bool was_listening = !!listening_for_activate_diplay_;
......
...@@ -31,6 +31,7 @@ class DEVICE_VR_EXPORT VRDeviceBase : public VRDevice { ...@@ -31,6 +31,7 @@ class DEVICE_VR_EXPORT VRDeviceBase : public VRDevice {
void Focus() override; void Focus() override;
void OnExitPresent() override; void OnExitPresent() override;
mojom::VRDisplayInfoPtr GetVRDisplayInfo() final; mojom::VRDisplayInfoPtr GetVRDisplayInfo() final;
void SetMagicWindowEnabled(bool enabled) final;
virtual void RequestPresent( virtual void RequestPresent(
VRDisplayImpl* display, VRDisplayImpl* display,
...@@ -38,7 +39,6 @@ class DEVICE_VR_EXPORT VRDeviceBase : public VRDevice { ...@@ -38,7 +39,6 @@ class DEVICE_VR_EXPORT VRDeviceBase : public VRDevice {
mojom::VRPresentationProviderRequest request, mojom::VRPresentationProviderRequest request,
mojom::VRDisplayHost::RequestPresentCallback callback); mojom::VRDisplayHost::RequestPresentCallback callback);
virtual void ExitPresent(); virtual void ExitPresent();
virtual void GetPose(mojom::VRMagicWindowProvider::GetPoseCallback callback);
void AddDisplay(VRDisplayImpl* display); void AddDisplay(VRDisplayImpl* display);
void RemoveDisplay(VRDisplayImpl* display); void RemoveDisplay(VRDisplayImpl* display);
...@@ -46,6 +46,8 @@ class DEVICE_VR_EXPORT VRDeviceBase : public VRDevice { ...@@ -46,6 +46,8 @@ class DEVICE_VR_EXPORT VRDeviceBase : public VRDevice {
bool CheckPresentingDisplay(VRDisplayImpl* display); bool CheckPresentingDisplay(VRDisplayImpl* display);
void OnListeningForActivateChanged(VRDisplayImpl* display); void OnListeningForActivateChanged(VRDisplayImpl* display);
void OnFrameFocusChanged(VRDisplayImpl* display); void OnFrameFocusChanged(VRDisplayImpl* display);
void GetMagicWindowPose(
mojom::VRMagicWindowProvider::GetPoseCallback callback);
VRDisplayImpl* GetPresentingDisplay() { return presenting_display_; } VRDisplayImpl* GetPresentingDisplay() { return presenting_display_; }
...@@ -55,10 +57,11 @@ class DEVICE_VR_EXPORT VRDeviceBase : public VRDevice { ...@@ -55,10 +57,11 @@ class DEVICE_VR_EXPORT VRDeviceBase : public VRDevice {
void OnActivate(mojom::VRDisplayEventReason reason, void OnActivate(mojom::VRDisplayEventReason reason,
base::Callback<void(bool)> on_handled); base::Callback<void(bool)> on_handled);
virtual void OnListeningForActivate(bool listening);
private: private:
void UpdateListeningForActivate(VRDisplayImpl* display); void UpdateListeningForActivate(VRDisplayImpl* display);
virtual void OnListeningForActivate(bool listening);
virtual void OnMagicWindowPoseRequest(
mojom::VRMagicWindowProvider::GetPoseCallback callback);
std::set<VRDisplayImpl*> displays_; std::set<VRDisplayImpl*> displays_;
...@@ -81,8 +84,8 @@ class DEVICE_VR_EXPORT VRDeviceBase : public VRDevice { ...@@ -81,8 +84,8 @@ class DEVICE_VR_EXPORT VRDeviceBase : public VRDevice {
mojom::VRDisplayInfoPtr display_info_; mojom::VRDisplayInfoPtr display_info_;
unsigned int id_; unsigned int id_;
static unsigned int next_id_; static unsigned int next_id_;
bool magic_window_enabled_ = true;
DISALLOW_COPY_AND_ASSIGN(VRDeviceBase); DISALLOW_COPY_AND_ASSIGN(VRDeviceBase);
}; };
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "device/vr/test/fake_vr_device.h"
#include "device/vr/test/fake_vr_service_client.h" #include "device/vr/test/fake_vr_service_client.h"
#include "device/vr/test/mock_vr_display_impl.h" #include "device/vr/test/mock_vr_display_impl.h"
#include "device/vr/vr_device_base.h" #include "device/vr/vr_device_base.h"
...@@ -155,4 +156,15 @@ TEST_F(VRDeviceTest, DisplayActivateRegsitered) { ...@@ -155,4 +156,15 @@ TEST_F(VRDeviceTest, DisplayActivateRegsitered) {
device->FireDisplayActivate(); device->FireDisplayActivate();
} }
TEST_F(VRDeviceTest, NoMagicWindowPosesWhileBrowsing) {
auto device = std::make_unique<FakeVRDevice>();
device->SetPose(mojom::VRPose::New());
device->GetMagicWindowPose(
base::BindOnce([](mojom::VRPosePtr pose) { EXPECT_TRUE(pose); }));
device->SetMagicWindowEnabled(false);
device->GetMagicWindowPose(
base::BindOnce([](mojom::VRPosePtr pose) { EXPECT_FALSE(pose); }));
}
} // namespace device } // namespace device
...@@ -74,12 +74,13 @@ void VRDisplayImpl::ExitPresent() { ...@@ -74,12 +74,13 @@ void VRDisplayImpl::ExitPresent() {
device_->ExitPresent(); device_->ExitPresent();
} }
// Gets a pose for magic window sessions.
void VRDisplayImpl::GetPose(GetPoseCallback callback) { void VRDisplayImpl::GetPose(GetPoseCallback callback) {
if (!device_->IsAccessAllowed(this)) { if (!device_->IsAccessAllowed(this)) {
std::move(callback).Run(nullptr); std::move(callback).Run(nullptr);
return; return;
} }
device_->GetPose(std::move(callback)); device_->GetMagicWindowPose(std::move(callback));
} }
void VRDisplayImpl::SetListeningForActivate(bool listening) { void VRDisplayImpl::SetListeningForActivate(bool listening) {
......
...@@ -52,6 +52,7 @@ class DEVICE_VR_EXPORT VRDisplayImpl : public mojom::VRMagicWindowProvider { ...@@ -52,6 +52,7 @@ class DEVICE_VR_EXPORT VRDisplayImpl : public mojom::VRMagicWindowProvider {
void ExitPresent(); void ExitPresent();
private: private:
// mojom::VRMagicWindowProvider
void GetPose(GetPoseCallback callback) override; void GetPose(GetPoseCallback callback) override;
mojo::Binding<mojom::VRMagicWindowProvider> binding_; mojo::Binding<mojom::VRMagicWindowProvider> binding_;
......
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