Commit 88484baf authored by bsheedy's avatar bsheedy Committed by Commit Bot

Refactor classes in wmr_origins.h

Refactors all the classes in
//device/vr/windows_mixed_reality/wrappers/wmr_origins.h to inherit
from an interface, and switches the mock versions to inherit from the
same interface instead of subclassing the real versions.

Also moves the static creation functions into factories in
//device/vr/windows_mixed_reality/wrappers/wmr_wrapper_factories.h,
which now guarantee that the mock and real classes can't be mixed
together.

Bug: 961020
Change-Id: I0928bcadc9d942bd6ea513c156c832ffcaf0433f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1603748Reviewed-by: default avatarBill Orr <billorr@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659124}
parent 871177d0
......@@ -177,6 +177,8 @@ if (enable_vr) {
"windows_mixed_reality/wrappers/wmr_rendering.h",
"windows_mixed_reality/wrappers/wmr_timestamp.cc",
"windows_mixed_reality/wrappers/wmr_timestamp.h",
"windows_mixed_reality/wrappers/wmr_wrapper_factories.cc",
"windows_mixed_reality/wrappers/wmr_wrapper_factories.h",
]
# Sources only meant to be actually used in tests, but need to be always
......
......@@ -29,6 +29,7 @@
#include "device/vr/windows_mixed_reality/wrappers/wmr_origins.h"
#include "device/vr/windows_mixed_reality/wrappers/wmr_rendering.h"
#include "device/vr/windows_mixed_reality/wrappers/wmr_timestamp.h"
#include "device/vr/windows_mixed_reality/wrappers/wmr_wrapper_factories.h"
#include "ui/gfx/geometry/angle_conversions.h"
#include "ui/gfx/geometry/vector3d_f.h"
#include "ui/gfx/transform.h"
......@@ -287,13 +288,13 @@ void MixedRealityRenderLoop::InitializeOrigin() {
// Try to get a stationary frame. We'll hand out all of our poses in this
// space.
if (!attached_) {
attached_ = WMRAttachedOrigin::CreateAtCurrentLocation();
attached_ = WMRAttachedOriginFactory::CreateAtCurrentLocation();
if (!attached_)
return;
}
std::unique_ptr<WMRStationaryOrigin> stationary_frame =
WMRStationaryOrigin::CreateAtCurrentLocation();
WMRStationaryOriginFactory::CreateAtCurrentLocation();
if (!stationary_frame)
return;
......@@ -328,7 +329,7 @@ bool MixedRealityRenderLoop::EnsureStageStatics() {
if (stage_statics_)
return true;
stage_statics_ = WMRStageStatics::Create();
stage_statics_ = WMRStageStaticsFactory::Create();
if (!stage_statics_)
return false;
......@@ -343,8 +344,6 @@ bool MixedRealityRenderLoop::EnsureStageStatics() {
void MixedRealityRenderLoop::ClearStageStatics() {
stage_changed_subscription_ = nullptr;
if (stage_statics_)
stage_statics_->Dispose();
stage_statics_ = nullptr;
}
......
......@@ -56,6 +56,12 @@ LockedVRTestHook MixedRealityDeviceStatics::GetLockedTestHook() {
return LockedVRTestHook(test_hook_);
}
bool MixedRealityDeviceStatics::ShouldUseMocks() {
auto locked_hook = GetLockedTestHook();
static bool should_use_mocks = (locked_hook.GetHook() != nullptr);
return should_use_mocks;
}
MixedRealityDeviceStatics::~MixedRealityDeviceStatics() {}
MixedRealityDeviceStaticsImpl::MixedRealityDeviceStaticsImpl() {
......
......@@ -19,6 +19,7 @@ class DEVICE_VR_EXPORT MixedRealityDeviceStatics {
static std::unique_ptr<MixedRealityDeviceStatics> CreateInstance();
static void SetTestHook(VRTestHook* hook);
static LockedVRTestHook GetLockedTestHook();
static bool ShouldUseMocks();
virtual ~MixedRealityDeviceStatics();
......
......@@ -18,6 +18,11 @@ bool MockWMRCoordinateSystem::TryGetTransformTo(
return true;
}
ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem*
MockWMRCoordinateSystem::GetRawPtr() const {
return nullptr;
}
// MockWMRStationaryOrigin
MockWMRStationaryOrigin::MockWMRStationaryOrigin() {}
......@@ -61,14 +66,16 @@ MockWMRStageOrigin::GetMovementBounds(const WMRCoordinateSystem* coordinates) {
// MockWMRStageStatics
MockWMRStageStatics::MockWMRStageStatics() {}
MockWMRStageStatics::~MockWMRStageStatics() {}
void MockWMRStageStatics::Dispose() {
dispose_called_ = true;
}
MockWMRStageStatics::~MockWMRStageStatics() = default;
std::unique_ptr<WMRStageOrigin> MockWMRStageStatics::CurrentStage() {
return std::make_unique<MockWMRStageOrigin>();
}
std::unique_ptr<base::CallbackList<void()>::Subscription>
MockWMRStageStatics::AddStageChangedCallback(
const base::RepeatingCallback<void()>& cb) {
return callback_list_.Add(cb);
}
} // namespace device
......@@ -19,6 +19,9 @@ class MockWMRCoordinateSystem : public WMRCoordinateSystem {
const WMRCoordinateSystem* other,
ABI::Windows::Foundation::Numerics::Matrix4x4* this_to_other) override;
ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem* GetRawPtr()
const override;
private:
DISALLOW_COPY_AND_ASSIGN(MockWMRCoordinateSystem);
};
......@@ -68,9 +71,12 @@ class MockWMRStageStatics : public WMRStageStatics {
std::unique_ptr<WMRStageOrigin> CurrentStage() override;
void Dispose() override;
std::unique_ptr<base::CallbackList<void()>::Subscription>
AddStageChangedCallback(const base::RepeatingCallback<void()>& cb) override;
private:
base::CallbackList<void()> callback_list_;
DISALLOW_COPY_AND_ASSIGN(MockWMRStageStatics);
};
......
......@@ -37,46 +37,19 @@ using ABI::Windows::Perception::Spatial::ISpatialStageFrameOfReferenceStatics;
using ABI::Windows::Perception::Spatial::ISpatialStationaryFrameOfReference;
using Microsoft::WRL::ComPtr;
namespace {
ComPtr<ISpatialLocator> GetSpatialLocator() {
ComPtr<ISpatialLocatorStatics> spatial_locator_statics;
base::win::ScopedHString spatial_locator_string =
base::win::ScopedHString::Create(
RuntimeClass_Windows_Perception_Spatial_SpatialLocator);
HRESULT hr = base::win::RoGetActivationFactory(
spatial_locator_string.get(), IID_PPV_ARGS(&spatial_locator_statics));
if (FAILED(hr)) {
device::WMRLogging::TraceError(device::WMRErrorLocation::kGetSpatialLocator,
hr);
return nullptr;
}
ComPtr<ISpatialLocator> locator;
hr = spatial_locator_statics->GetDefault(&locator);
if (FAILED(hr)) {
device::WMRLogging::TraceError(device::WMRErrorLocation::kGetSpatialLocator,
hr);
return nullptr;
}
return locator;
}
} // anonymous namespace
namespace device {
// WMRCoordinateSystem
WMRCoordinateSystem::WMRCoordinateSystem(
WMRCoordinateSystemImpl::WMRCoordinateSystemImpl(
ComPtr<ISpatialCoordinateSystem> coordinates)
: coordinates_(coordinates) {
DCHECK(coordinates_);
}
WMRCoordinateSystem::WMRCoordinateSystem() {}
WMRCoordinateSystemImpl::~WMRCoordinateSystemImpl() = default;
WMRCoordinateSystem::~WMRCoordinateSystem() = default;
bool WMRCoordinateSystem::TryGetTransformTo(const WMRCoordinateSystem* other,
WFN::Matrix4x4* this_to_other) {
bool WMRCoordinateSystemImpl::TryGetTransformTo(
const WMRCoordinateSystem* other,
WFN::Matrix4x4* this_to_other) {
DCHECK(this_to_other);
DCHECK(other);
ComPtr<IReference<WFN::Matrix4x4>> this_to_other_ref;
......@@ -92,109 +65,66 @@ bool WMRCoordinateSystem::TryGetTransformTo(const WMRCoordinateSystem* other,
return true;
}
ISpatialCoordinateSystem* WMRCoordinateSystem::GetRawPtr() const {
ISpatialCoordinateSystem* WMRCoordinateSystemImpl::GetRawPtr() const {
return coordinates_.Get();
}
// WMRStationaryOrigin
std::unique_ptr<WMRStationaryOrigin>
WMRStationaryOrigin::CreateAtCurrentLocation() {
if (MixedRealityDeviceStatics::GetLockedTestHook().GetHook()) {
return std::make_unique<MockWMRStationaryOrigin>();
}
ComPtr<ISpatialLocator> locator = GetSpatialLocator();
if (!locator)
return nullptr;
ComPtr<ISpatialStationaryFrameOfReference> origin;
HRESULT hr =
locator->CreateStationaryFrameOfReferenceAtCurrentLocation(&origin);
if (FAILED(hr)) {
WMRLogging::TraceError(WMRErrorLocation::kStationaryReferenceCreation, hr);
return nullptr;
}
return std::make_unique<WMRStationaryOrigin>(origin);
}
WMRStationaryOrigin::WMRStationaryOrigin(
WMRStationaryOriginImpl::WMRStationaryOriginImpl(
ComPtr<ISpatialStationaryFrameOfReference> stationary_origin)
: stationary_origin_(stationary_origin) {
DCHECK(stationary_origin_);
}
WMRStationaryOrigin::WMRStationaryOrigin() {}
WMRStationaryOrigin::~WMRStationaryOrigin() = default;
WMRStationaryOriginImpl::~WMRStationaryOriginImpl() = default;
std::unique_ptr<WMRCoordinateSystem> WMRStationaryOrigin::CoordinateSystem() {
std::unique_ptr<WMRCoordinateSystem>
WMRStationaryOriginImpl::CoordinateSystem() {
ComPtr<ISpatialCoordinateSystem> coordinates;
HRESULT hr = stationary_origin_->get_CoordinateSystem(&coordinates);
DCHECK(SUCCEEDED(hr));
return std::make_unique<WMRCoordinateSystem>(coordinates);
return std::make_unique<WMRCoordinateSystemImpl>(coordinates);
}
// WMRAttachedOrigin
std::unique_ptr<WMRAttachedOrigin>
WMRAttachedOrigin::CreateAtCurrentLocation() {
if (MixedRealityDeviceStatics::GetLockedTestHook().GetHook()) {
return std::make_unique<MockWMRAttachedOrigin>();
}
ComPtr<ISpatialLocator> locator = GetSpatialLocator();
if (!locator)
return nullptr;
ComPtr<ISpatialLocatorAttachedFrameOfReference> origin;
HRESULT hr = locator->CreateAttachedFrameOfReferenceAtCurrentHeading(&origin);
if (FAILED(hr)) {
WMRLogging::TraceError(WMRErrorLocation::kAttachedReferenceCreation, hr);
return nullptr;
}
return std::make_unique<WMRAttachedOrigin>(origin);
}
WMRAttachedOrigin::WMRAttachedOrigin(
WMRAttachedOriginImpl::WMRAttachedOriginImpl(
ComPtr<ISpatialLocatorAttachedFrameOfReference> attached_origin)
: attached_origin_(attached_origin) {
DCHECK(attached_origin_);
}
WMRAttachedOrigin::WMRAttachedOrigin() {}
WMRAttachedOrigin::~WMRAttachedOrigin() = default;
WMRAttachedOriginImpl::~WMRAttachedOriginImpl() = default;
std::unique_ptr<WMRCoordinateSystem>
WMRAttachedOrigin::TryGetCoordinatesAtTimestamp(const WMRTimestamp* timestamp) {
WMRAttachedOriginImpl::TryGetCoordinatesAtTimestamp(
const WMRTimestamp* timestamp) {
ComPtr<ISpatialCoordinateSystem> coordinates;
HRESULT hr = attached_origin_->GetStationaryCoordinateSystemAtTimestamp(
timestamp->GetRawPtr(), &coordinates);
if (FAILED(hr))
return nullptr;
return std::make_unique<WMRCoordinateSystem>(coordinates);
return std::make_unique<WMRCoordinateSystemImpl>(coordinates);
}
// WMRStageOrigin
WMRStageOrigin::WMRStageOrigin(
WMRStageOriginImpl::WMRStageOriginImpl(
ComPtr<ISpatialStageFrameOfReference> stage_origin)
: stage_origin_(stage_origin) {
DCHECK(stage_origin_);
}
WMRStageOrigin::WMRStageOrigin() {}
WMRStageOriginImpl::~WMRStageOriginImpl() = default;
WMRStageOrigin::~WMRStageOrigin() = default;
std::unique_ptr<WMRCoordinateSystem> WMRStageOrigin::CoordinateSystem() {
std::unique_ptr<WMRCoordinateSystem> WMRStageOriginImpl::CoordinateSystem() {
ComPtr<ISpatialCoordinateSystem> coordinates;
HRESULT hr = stage_origin_->get_CoordinateSystem(&coordinates);
DCHECK(SUCCEEDED(hr));
return std::make_unique<WMRCoordinateSystem>(coordinates);
return std::make_unique<WMRCoordinateSystemImpl>(coordinates);
}
SpatialMovementRange WMRStageOrigin::MovementRange() {
SpatialMovementRange WMRStageOriginImpl::MovementRange() {
SpatialMovementRange movement_range;
HRESULT hr = stage_origin_->get_MovementRange(&movement_range);
DCHECK(SUCCEEDED(hr));
......@@ -202,7 +132,7 @@ SpatialMovementRange WMRStageOrigin::MovementRange() {
return movement_range;
}
std::vector<WFN::Vector3> WMRStageOrigin::GetMovementBounds(
std::vector<WFN::Vector3> WMRStageOriginImpl::GetMovementBounds(
const WMRCoordinateSystem* coordinates) {
DCHECK(coordinates);
......@@ -222,48 +152,26 @@ std::vector<WFN::Vector3> WMRStageOrigin::GetMovementBounds(
}
// WMRStageStatics
std::unique_ptr<WMRStageStatics> WMRStageStatics::Create() {
if (MixedRealityDeviceStatics::GetLockedTestHook().GetHook())
return std::make_unique<MockWMRStageStatics>();
ComPtr<ISpatialStageFrameOfReferenceStatics> stage_statics;
base::win::ScopedHString spatial_stage_string =
base::win::ScopedHString::Create(
RuntimeClass_Windows_Perception_Spatial_SpatialStageFrameOfReference);
HRESULT hr = base::win::RoGetActivationFactory(spatial_stage_string.get(),
IID_PPV_ARGS(&stage_statics));
if (FAILED(hr))
return nullptr;
return std::make_unique<WMRStageStatics>(stage_statics);
}
WMRStageStatics::WMRStageStatics(
WMRStageStaticsImpl::WMRStageStaticsImpl(
ComPtr<ISpatialStageFrameOfReferenceStatics> stage_statics)
: stage_statics_(stage_statics) {
DCHECK(stage_statics_);
auto callback = Microsoft::WRL::Callback<IEventHandler<IInspectable*>>(
this, &WMRStageStatics::OnCurrentChanged);
this, &WMRStageStaticsImpl::OnCurrentChanged);
HRESULT hr =
stage_statics_->add_CurrentChanged(callback.Get(), &stage_changed_token_);
DCHECK(SUCCEEDED(hr));
}
WMRStageStatics::WMRStageStatics() {}
WMRStageStatics::~WMRStageStatics() {
DCHECK(dispose_called_);
}
void WMRStageStatics::Dispose() {
WMRStageStaticsImpl::~WMRStageStaticsImpl() {
if (stage_changed_token_.value != 0) {
HRESULT hr = stage_statics_->remove_CurrentChanged(stage_changed_token_);
stage_changed_token_.value = 0;
DCHECK(SUCCEEDED(hr));
}
dispose_called_ = true;
}
std::unique_ptr<WMRStageOrigin> WMRStageStatics::CurrentStage() {
std::unique_ptr<WMRStageOrigin> WMRStageStaticsImpl::CurrentStage() {
ComPtr<ISpatialStageFrameOfReference> stage_origin;
HRESULT hr = stage_statics_->get_Current(&stage_origin);
if (FAILED(hr) || !stage_origin) {
......@@ -271,16 +179,16 @@ std::unique_ptr<WMRStageOrigin> WMRStageStatics::CurrentStage() {
return nullptr;
}
return std::make_unique<WMRStageOrigin>(stage_origin);
return std::make_unique<WMRStageOriginImpl>(stage_origin);
}
std::unique_ptr<base::CallbackList<void()>::Subscription>
WMRStageStatics::AddStageChangedCallback(
WMRStageStaticsImpl::AddStageChangedCallback(
const base::RepeatingCallback<void()>& cb) {
return callback_list_.Add(cb);
}
HRESULT WMRStageStatics::OnCurrentChanged(IInspectable*, IInspectable*) {
HRESULT WMRStageStaticsImpl::OnCurrentChanged(IInspectable*, IInspectable*) {
callback_list_.Notify();
return S_OK;
}
......
......@@ -18,127 +18,147 @@ class WMRTimestamp;
class WMRCoordinateSystem {
public:
explicit WMRCoordinateSystem(
virtual ~WMRCoordinateSystem() = default;
virtual bool TryGetTransformTo(
const WMRCoordinateSystem* other,
ABI::Windows::Foundation::Numerics::Matrix4x4* this_to_other) = 0;
virtual ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem*
GetRawPtr() const = 0;
};
class WMRCoordinateSystemImpl : public WMRCoordinateSystem {
public:
explicit WMRCoordinateSystemImpl(
Microsoft::WRL::ComPtr<
ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem>
coordinates);
virtual ~WMRCoordinateSystem();
~WMRCoordinateSystemImpl() override;
virtual bool TryGetTransformTo(
bool TryGetTransformTo(
const WMRCoordinateSystem* other,
ABI::Windows::Foundation::Numerics::Matrix4x4* this_to_other);
ABI::Windows::Foundation::Numerics::Matrix4x4* this_to_other) override;
ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem* GetRawPtr()
const;
protected:
// Necessary so subclasses don't call the explicit constructor.
WMRCoordinateSystem();
const override;
private:
Microsoft::WRL::ComPtr<
ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem>
coordinates_;
DISALLOW_COPY_AND_ASSIGN(WMRCoordinateSystem);
DISALLOW_COPY_AND_ASSIGN(WMRCoordinateSystemImpl);
};
class WMRStationaryOrigin {
public:
static std::unique_ptr<WMRStationaryOrigin> CreateAtCurrentLocation();
explicit WMRStationaryOrigin(
virtual ~WMRStationaryOrigin() = default;
virtual std::unique_ptr<WMRCoordinateSystem> CoordinateSystem() = 0;
};
class WMRStationaryOriginImpl : public WMRStationaryOrigin {
public:
explicit WMRStationaryOriginImpl(
Microsoft::WRL::ComPtr<
ABI::Windows::Perception::Spatial::ISpatialStationaryFrameOfReference>
stationary_origin);
virtual ~WMRStationaryOrigin();
~WMRStationaryOriginImpl() override;
virtual std::unique_ptr<WMRCoordinateSystem> CoordinateSystem();
protected:
// Necessary so subclasses don't call the explicit constructor.
WMRStationaryOrigin();
std::unique_ptr<WMRCoordinateSystem> CoordinateSystem() override;
private:
Microsoft::WRL::ComPtr<
ABI::Windows::Perception::Spatial::ISpatialStationaryFrameOfReference>
stationary_origin_;
DISALLOW_COPY_AND_ASSIGN(WMRStationaryOrigin);
DISALLOW_COPY_AND_ASSIGN(WMRStationaryOriginImpl);
};
class WMRAttachedOrigin {
public:
static std::unique_ptr<WMRAttachedOrigin> CreateAtCurrentLocation();
explicit WMRAttachedOrigin(
virtual ~WMRAttachedOrigin() = default;
virtual std::unique_ptr<WMRCoordinateSystem> TryGetCoordinatesAtTimestamp(
const WMRTimestamp* timestamp) = 0;
};
class WMRAttachedOriginImpl : public WMRAttachedOrigin {
public:
explicit WMRAttachedOriginImpl(
Microsoft::WRL::ComPtr<ABI::Windows::Perception::Spatial::
ISpatialLocatorAttachedFrameOfReference>
attached_origin);
virtual ~WMRAttachedOrigin();
~WMRAttachedOriginImpl() override;
virtual std::unique_ptr<WMRCoordinateSystem> TryGetCoordinatesAtTimestamp(
const WMRTimestamp* timestamp);
protected:
// Necessary so subclasses don't call the explicit constructor.
WMRAttachedOrigin();
std::unique_ptr<WMRCoordinateSystem> TryGetCoordinatesAtTimestamp(
const WMRTimestamp* timestamp) override;
private:
Microsoft::WRL::ComPtr<ABI::Windows::Perception::Spatial::
ISpatialLocatorAttachedFrameOfReference>
attached_origin_;
DISALLOW_COPY_AND_ASSIGN(WMRAttachedOrigin);
DISALLOW_COPY_AND_ASSIGN(WMRAttachedOriginImpl);
};
class WMRStageOrigin {
public:
static std::unique_ptr<WMRStageOrigin> CreateAtCurrentLocation();
explicit WMRStageOrigin(
Microsoft::WRL::ComPtr<
ABI::Windows::Perception::Spatial::ISpatialStageFrameOfReference>
stage_origin);
virtual ~WMRStageOrigin();
virtual ~WMRStageOrigin() = default;
virtual std::unique_ptr<WMRCoordinateSystem> CoordinateSystem();
virtual std::unique_ptr<WMRCoordinateSystem> CoordinateSystem() = 0;
virtual ABI::Windows::Perception::Spatial::SpatialMovementRange
MovementRange();
MovementRange() = 0;
// This will return an empty array if no bounds are set.
virtual std::vector<ABI::Windows::Foundation::Numerics::Vector3>
GetMovementBounds(const WMRCoordinateSystem* coordinates);
GetMovementBounds(const WMRCoordinateSystem* coordinates) = 0;
};
class WMRStageOriginImpl : public WMRStageOrigin {
public:
explicit WMRStageOriginImpl(
Microsoft::WRL::ComPtr<
ABI::Windows::Perception::Spatial::ISpatialStageFrameOfReference>
stage_origin);
~WMRStageOriginImpl() override;
protected:
// Necessary so subclasses don't call the explicit constructor.
WMRStageOrigin();
std::unique_ptr<WMRCoordinateSystem> CoordinateSystem() override;
ABI::Windows::Perception::Spatial::SpatialMovementRange MovementRange()
override;
std::vector<ABI::Windows::Foundation::Numerics::Vector3> GetMovementBounds(
const WMRCoordinateSystem* coordinates) override;
private:
Microsoft::WRL::ComPtr<
ABI::Windows::Perception::Spatial::ISpatialStageFrameOfReference>
stage_origin_;
DISALLOW_COPY_AND_ASSIGN(WMRStageOrigin);
DISALLOW_COPY_AND_ASSIGN(WMRStageOriginImpl);
};
class WMRStageStatics {
public:
static std::unique_ptr<WMRStageStatics> Create();
explicit WMRStageStatics(
virtual ~WMRStageStatics() = default;
virtual std::unique_ptr<WMRStageOrigin> CurrentStage() = 0;
virtual std::unique_ptr<base::CallbackList<void()>::Subscription>
AddStageChangedCallback(const base::RepeatingCallback<void()>& cb) = 0;
};
class WMRStageStaticsImpl : public WMRStageStatics {
public:
explicit WMRStageStaticsImpl(
Microsoft::WRL::ComPtr<ABI::Windows::Perception::Spatial::
ISpatialStageFrameOfReferenceStatics>
stage_statics);
virtual ~WMRStageStatics();
~WMRStageStaticsImpl() override;
virtual std::unique_ptr<WMRStageOrigin> CurrentStage();
std::unique_ptr<WMRStageOrigin> CurrentStage() override;
std::unique_ptr<base::CallbackList<void()>::Subscription>
AddStageChangedCallback(const base::RepeatingCallback<void()>& cb);
virtual void Dispose();
protected:
// Necessary so subclasses don't call the explicit constructor.
WMRStageStatics();
bool dispose_called_ = false;
AddStageChangedCallback(const base::RepeatingCallback<void()>& cb) override;
private:
HRESULT OnCurrentChanged(IInspectable* sender, IInspectable* args);
......@@ -149,7 +169,7 @@ class WMRStageStatics {
EventRegistrationToken stage_changed_token_;
base::CallbackList<void()> callback_list_;
DISALLOW_COPY_AND_ASSIGN(WMRStageStatics);
DISALLOW_COPY_AND_ASSIGN(WMRStageStaticsImpl);
};
} // namespace device
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "device/vr/windows_mixed_reality/wrappers/wmr_wrapper_factories.h"
#include <windows.perception.spatial.h>
#include <wrl.h>
#include "base/strings/string_util.h"
#include "base/win/core_winrt_util.h"
#include "base/win/scoped_hstring.h"
#include "device/vr/windows_mixed_reality/mixed_reality_statics.h"
#include "device/vr/windows_mixed_reality/wrappers/test/mock_wmr_origins.h"
#include "device/vr/windows_mixed_reality/wrappers/wmr_logging.h"
namespace WFN = ABI::Windows::Foundation::Numerics;
using SpatialMovementRange =
ABI::Windows::Perception::Spatial::SpatialMovementRange;
using ABI::Windows::Foundation::IEventHandler;
using ABI::Windows::Foundation::IReference;
using ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem;
using ABI::Windows::Perception::Spatial::ISpatialLocator;
using ABI::Windows::Perception::Spatial::
ISpatialLocatorAttachedFrameOfReference;
using ABI::Windows::Perception::Spatial::ISpatialLocatorStatics;
using ABI::Windows::Perception::Spatial::ISpatialStageFrameOfReference;
using ABI::Windows::Perception::Spatial::ISpatialStageFrameOfReferenceStatics;
using ABI::Windows::Perception::Spatial::ISpatialStationaryFrameOfReference;
using Microsoft::WRL::ComPtr;
namespace {
ComPtr<ISpatialLocator> GetSpatialLocator() {
ComPtr<ISpatialLocatorStatics> spatial_locator_statics;
base::win::ScopedHString spatial_locator_string =
base::win::ScopedHString::Create(
RuntimeClass_Windows_Perception_Spatial_SpatialLocator);
HRESULT hr = base::win::RoGetActivationFactory(
spatial_locator_string.get(), IID_PPV_ARGS(&spatial_locator_statics));
if (FAILED(hr)) {
device::WMRLogging::TraceError(device::WMRErrorLocation::kGetSpatialLocator,
hr);
return nullptr;
}
ComPtr<ISpatialLocator> locator;
hr = spatial_locator_statics->GetDefault(&locator);
if (FAILED(hr)) {
device::WMRLogging::TraceError(device::WMRErrorLocation::kGetSpatialLocator,
hr);
return nullptr;
}
return locator;
}
} // anonymous namespace
namespace device {
std::unique_ptr<WMRStationaryOrigin>
WMRStationaryOriginFactory::CreateAtCurrentLocation() {
if (MixedRealityDeviceStatics::ShouldUseMocks()) {
return std::make_unique<MockWMRStationaryOrigin>();
}
ComPtr<ISpatialLocator> locator = GetSpatialLocator();
if (!locator)
return nullptr;
ComPtr<ISpatialStationaryFrameOfReference> origin;
HRESULT hr =
locator->CreateStationaryFrameOfReferenceAtCurrentLocation(&origin);
if (FAILED(hr)) {
WMRLogging::TraceError(WMRErrorLocation::kStationaryReferenceCreation, hr);
return nullptr;
}
return std::make_unique<WMRStationaryOriginImpl>(origin);
}
std::unique_ptr<WMRAttachedOrigin>
WMRAttachedOriginFactory::CreateAtCurrentLocation() {
if (MixedRealityDeviceStatics::ShouldUseMocks()) {
return std::make_unique<MockWMRAttachedOrigin>();
}
ComPtr<ISpatialLocator> locator = GetSpatialLocator();
if (!locator)
return nullptr;
ComPtr<ISpatialLocatorAttachedFrameOfReference> origin;
HRESULT hr = locator->CreateAttachedFrameOfReferenceAtCurrentHeading(&origin);
if (FAILED(hr)) {
WMRLogging::TraceError(WMRErrorLocation::kAttachedReferenceCreation, hr);
return nullptr;
}
return std::make_unique<WMRAttachedOriginImpl>(origin);
}
std::unique_ptr<WMRStageStatics> WMRStageStaticsFactory::Create() {
if (MixedRealityDeviceStatics::ShouldUseMocks()) {
return std::make_unique<MockWMRStageStatics>();
}
ComPtr<ISpatialStageFrameOfReferenceStatics> stage_statics;
base::win::ScopedHString spatial_stage_string =
base::win::ScopedHString::Create(
RuntimeClass_Windows_Perception_Spatial_SpatialStageFrameOfReference);
HRESULT hr = base::win::RoGetActivationFactory(spatial_stage_string.get(),
IID_PPV_ARGS(&stage_statics));
if (FAILED(hr))
return nullptr;
return std::make_unique<WMRStageStaticsImpl>(stage_statics);
}
} // namespace device
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_WMR_WRAPPER_FACTORIES_H_
#define DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_WMR_WRAPPER_FACTORIES_H_
#include "device/vr/windows_mixed_reality/wrappers/wmr_origins.h"
namespace device {
class WMRStationaryOriginFactory {
public:
static std::unique_ptr<WMRStationaryOrigin> CreateAtCurrentLocation();
};
class WMRAttachedOriginFactory {
public:
static std::unique_ptr<WMRAttachedOrigin> CreateAtCurrentLocation();
};
class WMRStageStaticsFactory {
public:
static std::unique_ptr<WMRStageStatics> Create();
};
} // namespace device
#endif // DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_WMR_WRAPPER_FACTORIES_H_
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