Commit 49786067 authored by Brian Sheedy's avatar Brian Sheedy Committed by Commit Bot

Cleanup WMR test TODOs

Cleans up all remaining TODOs pointing to 926048, which covers adding
WMR support to the XR browser tests. Specifically, this properly
implements controller and pointer poses using the data provided by
the test instead of using hard coded values.

Bug: 926048
Change-Id: I014781127e8d7e5151a1766ad2a8d28761140ecc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1642960Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666105}
parent 30815c7b
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define DEVICE_VR_TEST_TEST_HOOK_H_ #define DEVICE_VR_TEST_TEST_HOOK_H_
#include "base/logging.h" #include "base/logging.h"
#include "ui/gfx/transform.h"
#include <cstdint> #include <cstdint>
...@@ -120,6 +121,18 @@ struct ControllerFrameData { ...@@ -120,6 +121,18 @@ struct ControllerFrameData {
bool is_valid = false; bool is_valid = false;
}; };
inline gfx::Transform PoseFrameDataToTransform(PoseFrameData data) {
// The gfx::Transform constructor takes arguments in row-major order, but
// we're given data in column-major order. Construct in column-major order and
// transpose since it looks cleaner than manually transposing the arguments
// passed to the constructor.
float* t = data.device_to_origin;
gfx::Transform transform(t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8],
t[9], t[10], t[11], t[12], t[13], t[14], t[15]);
transform.Transpose();
return transform;
}
// Tests may implement this, and register it to control behavior of VR runtime. // Tests may implement this, and register it to control behavior of VR runtime.
class VRTestHook { class VRTestHook {
public: public:
......
...@@ -5,28 +5,40 @@ ...@@ -5,28 +5,40 @@
#include "device/vr/windows_mixed_reality/wrappers/test/mock_wmr_input_location.h" #include "device/vr/windows_mixed_reality/wrappers/test/mock_wmr_input_location.h"
#include "base/logging.h" #include "base/logging.h"
#include "device/vr/test/test_hook.h"
#include "ui/gfx/geometry/vector3d_f.h"
#include "ui/gfx/transform_util.h"
namespace device { namespace device {
MockWMRInputLocation::MockWMRInputLocation(ControllerFrameData data) MockWMRInputLocation::MockWMRInputLocation(ControllerFrameData data)
: data_(data) {} : data_(data) {
DecomposeTransform(&decomposed_device_to_origin_,
PoseFrameDataToTransform(data.pose_data));
}
MockWMRInputLocation::~MockWMRInputLocation() = default; MockWMRInputLocation::~MockWMRInputLocation() = default;
bool MockWMRInputLocation::TryGetPosition( bool MockWMRInputLocation::TryGetPosition(
ABI::Windows::Foundation::Numerics::Vector3* position) const { ABI::Windows::Foundation::Numerics::Vector3* position) const {
DCHECK(position); DCHECK(position);
// TODO(https://crbug.com/926048): Properly implement. if (!data_.pose_data.is_valid)
position->X = 0; return false;
position->Y = 0;
position->Z = 0; position->X = decomposed_device_to_origin_.translate[0];
position->Y = decomposed_device_to_origin_.translate[1];
position->Z = decomposed_device_to_origin_.translate[2];
return true; return true;
} }
bool MockWMRInputLocation::TryGetVelocity( bool MockWMRInputLocation::TryGetVelocity(
ABI::Windows::Foundation::Numerics::Vector3* velocity) const { ABI::Windows::Foundation::Numerics::Vector3* velocity) const {
DCHECK(velocity); DCHECK(velocity);
// TODO(https://crbug.com/926048): Properly implement. if (!data_.pose_data.is_valid)
return false;
// We could potentially store a history of poses and calculate the velocity,
// but that is more complicated and doesn't currently provide any benefit for
// tests. So, just report 0s.
velocity->X = 0; velocity->X = 0;
velocity->Y = 0; velocity->Y = 0;
velocity->Z = 0; velocity->Z = 0;
...@@ -36,18 +48,24 @@ bool MockWMRInputLocation::TryGetVelocity( ...@@ -36,18 +48,24 @@ bool MockWMRInputLocation::TryGetVelocity(
bool MockWMRInputLocation::TryGetOrientation( bool MockWMRInputLocation::TryGetOrientation(
ABI::Windows::Foundation::Numerics::Quaternion* orientation) const { ABI::Windows::Foundation::Numerics::Quaternion* orientation) const {
DCHECK(orientation); DCHECK(orientation);
// TODO(https://crbug.com/926048): Properly implement. if (!data_.pose_data.is_valid)
orientation->X = 0; return false;
orientation->Y = 0;
orientation->Z = 0; orientation->X = decomposed_device_to_origin_.quaternion.x();
orientation->W = 1; orientation->Y = decomposed_device_to_origin_.quaternion.y();
orientation->Z = decomposed_device_to_origin_.quaternion.z();
orientation->W = decomposed_device_to_origin_.quaternion.w();
return true; return true;
} }
bool MockWMRInputLocation::TryGetAngularVelocity( bool MockWMRInputLocation::TryGetAngularVelocity(
ABI::Windows::Foundation::Numerics::Vector3* angular_velocity) const { ABI::Windows::Foundation::Numerics::Vector3* angular_velocity) const {
DCHECK(angular_velocity); DCHECK(angular_velocity);
// TODO(https://crbug.com/926048): Properly implement. if (!data_.pose_data.is_valid)
return false;
// We could potentially store a history of poses and calculate the angular
// velocity, but that is more complicated and doesn't currently provide any
// benefit for tests. So, just report 0s.
angular_velocity->X = 0; angular_velocity->X = 0;
angular_velocity->Y = 0; angular_velocity->Y = 0;
angular_velocity->Z = 0; angular_velocity->Z = 0;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "device/vr/test/test_hook.h" #include "device/vr/test/test_hook.h"
#include "device/vr/windows_mixed_reality/wrappers/wmr_input_location.h" #include "device/vr/windows_mixed_reality/wrappers/wmr_input_location.h"
#include "ui/gfx/transform_util.h"
namespace device { namespace device {
...@@ -25,6 +26,7 @@ class MockWMRInputLocation : public WMRInputLocation { ...@@ -25,6 +26,7 @@ class MockWMRInputLocation : public WMRInputLocation {
private: private:
ControllerFrameData data_; ControllerFrameData data_;
gfx::DecomposedTransform decomposed_device_to_origin_;
}; };
} // namespace device } // namespace device
......
...@@ -19,7 +19,7 @@ MockWMRInputSourceState::~MockWMRInputSourceState() = default; ...@@ -19,7 +19,7 @@ MockWMRInputSourceState::~MockWMRInputSourceState() = default;
std::unique_ptr<WMRPointerPose> MockWMRInputSourceState::TryGetPointerPose( std::unique_ptr<WMRPointerPose> MockWMRInputSourceState::TryGetPointerPose(
const WMRCoordinateSystem* origin) const { const WMRCoordinateSystem* origin) const {
return std::make_unique<MockWMRPointerPose>(); return std::make_unique<MockWMRPointerPose>(data_);
} }
std::unique_ptr<WMRInputSource> MockWMRInputSourceState::GetSource() const { std::unique_ptr<WMRInputSource> MockWMRInputSourceState::GetSource() const {
......
...@@ -9,18 +9,19 @@ ...@@ -9,18 +9,19 @@
namespace device { namespace device {
MockWMRPointerPose::MockWMRPointerPose() {} MockWMRPointerPose::MockWMRPointerPose(ControllerFrameData data)
: data_(data) {}
MockWMRPointerPose::~MockWMRPointerPose() = default; MockWMRPointerPose::~MockWMRPointerPose() = default;
bool MockWMRPointerPose::IsValid() const { bool MockWMRPointerPose::IsValid() const {
return true; return data_.pose_data.is_valid;
} }
std::unique_ptr<WMRPointerSourcePose> std::unique_ptr<WMRPointerSourcePose>
MockWMRPointerPose::TryGetInteractionSourcePose( MockWMRPointerPose::TryGetInteractionSourcePose(
const WMRInputSource* source) const { const WMRInputSource* source) const {
return std::make_unique<MockWMRPointerSourcePose>(); return std::make_unique<MockWMRPointerSourcePose>(data_);
} }
ABI::Windows::Foundation::Numerics::Vector3 MockWMRPointerPose::HeadForward() ABI::Windows::Foundation::Numerics::Vector3 MockWMRPointerPose::HeadForward()
......
...@@ -4,13 +4,14 @@ ...@@ -4,13 +4,14 @@
#ifndef DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_TEST_MOCK_WMR_POINTER_POSE_H_ #ifndef DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_TEST_MOCK_WMR_POINTER_POSE_H_
#define DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_TEST_MOCK_WMR_POINTER_POSE_H_ #define DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_TEST_MOCK_WMR_POINTER_POSE_H_
#include "device/vr/test/test_hook.h"
#include "device/vr/windows_mixed_reality/wrappers/wmr_pointer_pose.h" #include "device/vr/windows_mixed_reality/wrappers/wmr_pointer_pose.h"
namespace device { namespace device {
class MockWMRPointerPose : public WMRPointerPose { class MockWMRPointerPose : public WMRPointerPose {
public: public:
MockWMRPointerPose(); MockWMRPointerPose(ControllerFrameData data);
~MockWMRPointerPose() override; ~MockWMRPointerPose() override;
bool IsValid() const override; bool IsValid() const override;
...@@ -19,6 +20,7 @@ class MockWMRPointerPose : public WMRPointerPose { ...@@ -19,6 +20,7 @@ class MockWMRPointerPose : public WMRPointerPose {
ABI::Windows::Foundation::Numerics::Vector3 HeadForward() const override; ABI::Windows::Foundation::Numerics::Vector3 HeadForward() const override;
private: private:
ControllerFrameData data_;
DISALLOW_COPY(MockWMRPointerPose); DISALLOW_COPY(MockWMRPointerPose);
}; };
......
...@@ -4,27 +4,36 @@ ...@@ -4,27 +4,36 @@
#include "device/vr/windows_mixed_reality/wrappers/test/mock_wmr_pointer_source_pose.h" #include "device/vr/windows_mixed_reality/wrappers/test/mock_wmr_pointer_source_pose.h"
#include "device/vr/windows_mixed_reality/wrappers/test/mock_wmr_input_location.h"
namespace device { namespace device {
MockWMRPointerSourcePose::MockWMRPointerSourcePose() {} MockWMRPointerSourcePose::MockWMRPointerSourcePose(ControllerFrameData data)
: data_(data) {}
MockWMRPointerSourcePose::~MockWMRPointerSourcePose() = default; MockWMRPointerSourcePose::~MockWMRPointerSourcePose() = default;
bool MockWMRPointerSourcePose::IsValid() const { bool MockWMRPointerSourcePose::IsValid() const {
return true; return data_.pose_data.is_valid;
} }
ABI::Windows::Foundation::Numerics::Vector3 MockWMRPointerSourcePose::Position() ABI::Windows::Foundation::Numerics::Vector3 MockWMRPointerSourcePose::Position()
const { const {
// TODO(https://crbug.com/926048): Actually implement. // Providing the same position and orientation as the controller should be
return {1, 1, 1}; // valid and make it easy to actually point at things in tests if ever
// necessary.
ABI::Windows::Foundation::Numerics::Vector3 ret;
MockWMRInputLocation loc(data_);
loc.TryGetPosition(&ret);
return ret;
} }
ABI::Windows::Foundation::Numerics::Quaternion ABI::Windows::Foundation::Numerics::Quaternion
MockWMRPointerSourcePose::Orientation() const { MockWMRPointerSourcePose::Orientation() const {
// TODO(https://crbug.com/926048): Actually implement. ABI::Windows::Foundation::Numerics::Quaternion ret;
// For whatever reason, W is first? MockWMRInputLocation loc(data_);
return {1, 0, 0, 0}; loc.TryGetOrientation(&ret);
return ret;
} }
} // namespace device } // namespace device
...@@ -4,13 +4,14 @@ ...@@ -4,13 +4,14 @@
#ifndef DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_TEST_MOCK_WMR_POINTER_SOURCE_POSE_H_ #ifndef DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_TEST_MOCK_WMR_POINTER_SOURCE_POSE_H_
#define DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_TEST_MOCK_WMR_POINTER_SOURCE_POSE_H_ #define DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_TEST_MOCK_WMR_POINTER_SOURCE_POSE_H_
#include "device/vr/test/test_hook.h"
#include "device/vr/windows_mixed_reality/wrappers/wmr_pointer_source_pose.h" #include "device/vr/windows_mixed_reality/wrappers/wmr_pointer_source_pose.h"
namespace device { namespace device {
class MockWMRPointerSourcePose : public WMRPointerSourcePose { class MockWMRPointerSourcePose : public WMRPointerSourcePose {
public: public:
MockWMRPointerSourcePose(); MockWMRPointerSourcePose(ControllerFrameData data);
~MockWMRPointerSourcePose() override; ~MockWMRPointerSourcePose() override;
bool IsValid() const override; bool IsValid() const override;
...@@ -18,6 +19,7 @@ class MockWMRPointerSourcePose : public WMRPointerSourcePose { ...@@ -18,6 +19,7 @@ class MockWMRPointerSourcePose : public WMRPointerSourcePose {
ABI::Windows::Foundation::Numerics::Quaternion Orientation() const override; ABI::Windows::Foundation::Numerics::Quaternion Orientation() const override;
private: private:
ControllerFrameData data_;
DISALLOW_COPY(MockWMRPointerSourcePose); DISALLOW_COPY(MockWMRPointerSourcePose);
}; };
......
...@@ -128,15 +128,7 @@ bool MockWMRCameraPose::TryGetViewTransform( ...@@ -128,15 +128,7 @@ bool MockWMRCameraPose::TryGetViewTransform(
// We need to get the inverse of the given transform, as it's the // We need to get the inverse of the given transform, as it's the
// device-to-origin transform and we need the origin-to-device transform. // device-to-origin transform and we need the origin-to-device transform.
float* t = pose_data.device_to_origin; gfx::Transform device_to_origin = PoseFrameDataToTransform(pose_data);
// The gfx::Transform constructor takes arguments in row-major order, but
// we're given data in column-major order. Construct in column-major order and
// transpose since it looks cleaner than manually transposing the arguments
// passed to the constructor.
gfx::Transform device_to_origin(t[0], t[1], t[2], t[3], t[4], t[5], t[6],
t[7], t[8], t[9], t[10], t[11], t[12], t[13],
t[14], t[15]);
device_to_origin.Transpose();
gfx::Transform origin_to_device = device_to_origin; gfx::Transform origin_to_device = device_to_origin;
auto success = origin_to_device.GetInverse(&origin_to_device); auto success = origin_to_device.GetInverse(&origin_to_device);
DCHECK(success); DCHECK(success);
......
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