Commit b96cff8c authored by bsheedy's avatar bsheedy Committed by Commit Bot

Refactor more WMR wrapper classes

Refactors all the classes in wmr_input_manager.h,
wmr_holographic_frame.h, and wmr_holographic_space.h in the same way as
crrev.com/c/1603748.

Bug: 961020
Change-Id: Ie4dc432823cfdbe506d2616fb9005ce5392035e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1610592
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Auto-Submit: Brian Sheedy <bsheedy@chromium.org>
Reviewed-by: default avatarBill Orr <billorr@chromium.org>
Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659284}
parent 84e62dd3
......@@ -24,6 +24,7 @@
#include "device/vr/windows_mixed_reality/wrappers/wmr_pointer_pose.h"
#include "device/vr/windows_mixed_reality/wrappers/wmr_pointer_source_pose.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/transform.h"
#include "ui/gfx/transform_util.h"
......@@ -368,7 +369,7 @@ bool MixedRealityInputHelper::EnsureSpatialInteractionManager() {
if (!hwnd_)
return false;
input_manager_ = WMRInputManager::GetForWindow(hwnd_);
input_manager_ = WMRInputManagerFactory::GetForWindow(hwnd_);
if (!input_manager_)
return false;
......
......@@ -410,7 +410,8 @@ void MixedRealityRenderLoop::InitializeSpace() {
// A small arbitrary size that keeps the window from being distracting.
window_->Init(NULL, gfx::Rect(25, 10));
holographic_space_ = WMRHolographicSpace::CreateForWindow(window_->hwnd());
holographic_space_ =
WMRHolographicSpaceFactory::CreateForWindow(window_->hwnd());
}
void MixedRealityRenderLoop::StartPresenting() {
......
......@@ -19,4 +19,16 @@ MockWMRInputManager::GetDetectedSourcesAtTimestamp(
return {};
}
std::unique_ptr<WMRInputManager::InputEventCallbackList::Subscription>
MockWMRInputManager::AddPressedCallback(
const WMRInputManager::InputEventCallback& cb) {
return pressed_callback_list_.Add(cb);
}
std::unique_ptr<WMRInputManager::InputEventCallbackList::Subscription>
MockWMRInputManager::AddReleasedCallback(
const WMRInputManager::InputEventCallback& cb) {
return released_callback_list_.Add(cb);
}
} // namespace device
......@@ -17,7 +17,15 @@ class MockWMRInputManager : public WMRInputManager {
Microsoft::WRL::ComPtr<ABI::Windows::Perception::IPerceptionTimestamp>
timestamp) const override;
std::unique_ptr<InputEventCallbackList::Subscription> AddPressedCallback(
const InputEventCallback& cb) override;
std::unique_ptr<InputEventCallbackList::Subscription> AddReleasedCallback(
const InputEventCallback& cb) override;
private:
InputEventCallbackList pressed_callback_list_;
InputEventCallbackList released_callback_list_;
DISALLOW_COPY_AND_ASSIGN(MockWMRInputManager);
};
......
......@@ -18,11 +18,6 @@ bool MockWMRCoordinateSystem::TryGetTransformTo(
return true;
}
ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem*
MockWMRCoordinateSystem::GetRawPtr() const {
return nullptr;
}
// MockWMRStationaryOrigin
MockWMRStationaryOrigin::MockWMRStationaryOrigin() {}
......
......@@ -19,9 +19,6 @@ 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);
};
......
......@@ -31,17 +31,16 @@ using Microsoft::WRL::ComPtr;
namespace device {
// WMRHolographicFramePrediction
WMRHolographicFramePrediction::WMRHolographicFramePrediction(
WMRHolographicFramePredictionImpl::WMRHolographicFramePredictionImpl(
ComPtr<IHolographicFramePrediction> prediction)
: prediction_(prediction) {
DCHECK(prediction_);
}
WMRHolographicFramePrediction::WMRHolographicFramePrediction() {}
WMRHolographicFramePredictionImpl::~WMRHolographicFramePredictionImpl() =
default;
WMRHolographicFramePrediction::~WMRHolographicFramePrediction() = default;
std::unique_ptr<WMRTimestamp> WMRHolographicFramePrediction::Timestamp() {
std::unique_ptr<WMRTimestamp> WMRHolographicFramePredictionImpl::Timestamp() {
ComPtr<IPerceptionTimestamp> timestamp;
HRESULT hr = prediction_->get_Timestamp(&timestamp);
DCHECK(SUCCEEDED(hr));
......@@ -49,7 +48,7 @@ std::unique_ptr<WMRTimestamp> WMRHolographicFramePrediction::Timestamp() {
}
std::vector<std::unique_ptr<WMRCameraPose>>
WMRHolographicFramePrediction::CameraPoses() {
WMRHolographicFramePredictionImpl::CameraPoses() {
std::vector<std::unique_ptr<WMRCameraPose>> ret_val;
ComPtr<IVectorView<HolographicCameraPose*>> poses;
HRESULT hr = prediction_->get_CameraPoses(&poses);
......@@ -70,26 +69,24 @@ WMRHolographicFramePrediction::CameraPoses() {
}
// WMRHolographicFrame
WMRHolographicFrame::WMRHolographicFrame(
WMRHolographicFrameImpl::WMRHolographicFrameImpl(
ComPtr<IHolographicFrame> holographic_frame)
: holographic_frame_(holographic_frame) {
DCHECK(holographic_frame_);
}
WMRHolographicFrame::WMRHolographicFrame() {}
WMRHolographicFrame::~WMRHolographicFrame() = default;
WMRHolographicFrameImpl::~WMRHolographicFrameImpl() = default;
std::unique_ptr<WMRHolographicFramePrediction>
WMRHolographicFrame::CurrentPrediction() {
WMRHolographicFrameImpl::CurrentPrediction() {
ComPtr<IHolographicFramePrediction> prediction;
HRESULT hr = holographic_frame_->get_CurrentPrediction(&prediction);
DCHECK(SUCCEEDED(hr));
return std::make_unique<WMRHolographicFramePrediction>(prediction);
return std::make_unique<WMRHolographicFramePredictionImpl>(prediction);
}
std::unique_ptr<WMRRenderingParameters>
WMRHolographicFrame::TryGetRenderingParameters(const WMRCameraPose* pose) {
WMRHolographicFrameImpl::TryGetRenderingParameters(const WMRCameraPose* pose) {
ComPtr<IHolographicCameraRenderingParameters> rendering_params;
HRESULT hr = holographic_frame_->GetRenderingParameters(pose->GetRawPtr(),
&rendering_params);
......@@ -98,7 +95,7 @@ WMRHolographicFrame::TryGetRenderingParameters(const WMRCameraPose* pose) {
return std::make_unique<WMRRenderingParameters>(rendering_params);
}
bool WMRHolographicFrame::TryPresentUsingCurrentPrediction() {
bool WMRHolographicFrameImpl::TryPresentUsingCurrentPrediction() {
PresentResult result = PresentResult::HolographicFramePresentResult_Success;
HRESULT hr = holographic_frame_->PresentUsingCurrentPrediction(&result);
......
......@@ -19,49 +19,61 @@ class WMRTimestamp;
class WMRHolographicFramePrediction {
public:
explicit WMRHolographicFramePrediction(
virtual ~WMRHolographicFramePrediction() = default;
virtual std::unique_ptr<WMRTimestamp> Timestamp() = 0;
virtual std::vector<std::unique_ptr<WMRCameraPose>> CameraPoses() = 0;
};
class WMRHolographicFramePredictionImpl : public WMRHolographicFramePrediction {
public:
explicit WMRHolographicFramePredictionImpl(
Microsoft::WRL::ComPtr<
ABI::Windows::Graphics::Holographic::IHolographicFramePrediction>
prediction);
virtual ~WMRHolographicFramePrediction();
~WMRHolographicFramePredictionImpl() override;
virtual std::unique_ptr<WMRTimestamp> Timestamp();
virtual std::vector<std::unique_ptr<WMRCameraPose>> CameraPoses();
protected:
// Necessary so subclasses don't call the explicit constructor.
WMRHolographicFramePrediction();
std::unique_ptr<WMRTimestamp> Timestamp() override;
std::vector<std::unique_ptr<WMRCameraPose>> CameraPoses() override;
private:
Microsoft::WRL::ComPtr<
ABI::Windows::Graphics::Holographic::IHolographicFramePrediction>
prediction_;
DISALLOW_COPY_AND_ASSIGN(WMRHolographicFramePrediction);
DISALLOW_COPY_AND_ASSIGN(WMRHolographicFramePredictionImpl);
};
class WMRHolographicFrame {
public:
explicit WMRHolographicFrame(
virtual ~WMRHolographicFrame() = default;
virtual std::unique_ptr<WMRHolographicFramePrediction>
CurrentPrediction() = 0;
virtual std::unique_ptr<WMRRenderingParameters> TryGetRenderingParameters(
const WMRCameraPose* pose) = 0;
virtual bool TryPresentUsingCurrentPrediction() = 0;
};
class WMRHolographicFrameImpl : public WMRHolographicFrame {
public:
explicit WMRHolographicFrameImpl(
Microsoft::WRL::ComPtr<
ABI::Windows::Graphics::Holographic::IHolographicFrame>
holographic_frame);
virtual ~WMRHolographicFrame();
~WMRHolographicFrameImpl() override;
virtual std::unique_ptr<WMRHolographicFramePrediction> CurrentPrediction();
virtual std::unique_ptr<WMRRenderingParameters> TryGetRenderingParameters(
const WMRCameraPose* pose);
virtual bool TryPresentUsingCurrentPrediction();
protected:
// Necessary so subclasses don't call the explicit constructor.
WMRHolographicFrame();
std::unique_ptr<WMRHolographicFramePrediction> CurrentPrediction() override;
std::unique_ptr<WMRRenderingParameters> TryGetRenderingParameters(
const WMRCameraPose* pose) override;
bool TryPresentUsingCurrentPrediction() override;
private:
Microsoft::WRL::ComPtr<ABI::Windows::Graphics::Holographic::IHolographicFrame>
holographic_frame_;
DISALLOW_COPY_AND_ASSIGN(WMRHolographicFrame);
DISALLOW_COPY_AND_ASSIGN(WMRHolographicFrameImpl);
};
} // namespace device
#endif // DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_WMR_HOLOGRAPHIC_FRAME_H_
......@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "device/vr/windows_mixed_reality/wrappers/wmr_holographic_space.h"
#include <HolographicSpaceInterop.h>
#include <Windows.Graphics.DirectX.Direct3D11.interop.h>
#include <windows.graphics.holographic.h>
#include <wrl.h>
......@@ -26,59 +25,32 @@ using ABI::Windows::Graphics::Holographic::IHolographicSpace;
using Microsoft::WRL::ComPtr;
namespace device {
std::unique_ptr<WMRHolographicSpace> WMRHolographicSpace::CreateForWindow(
HWND hwnd) {
if (MixedRealityDeviceStatics::GetLockedTestHook().GetHook()) {
return std::make_unique<MockWMRHolographicSpace>();
}
if (!hwnd)
return nullptr;
ComPtr<IHolographicSpaceInterop> holographic_space_interop;
base::win::ScopedHString holographic_space_string =
base::win::ScopedHString::Create(
RuntimeClass_Windows_Graphics_Holographic_HolographicSpace);
HRESULT hr = base::win::RoGetActivationFactory(
holographic_space_string.get(), IID_PPV_ARGS(&holographic_space_interop));
if (FAILED(hr))
return nullptr;
ComPtr<IHolographicSpace> holographic_space;
hr = holographic_space_interop->CreateForWindow(
hwnd, IID_PPV_ARGS(&holographic_space));
if (FAILED(hr))
return nullptr;
return std::make_unique<WMRHolographicSpace>(holographic_space);
}
WMRHolographicSpace::WMRHolographicSpace(ComPtr<IHolographicSpace> space)
WMRHolographicSpaceImpl::WMRHolographicSpaceImpl(
ComPtr<IHolographicSpace> space)
: space_(space) {
DCHECK(space_);
}
WMRHolographicSpace::WMRHolographicSpace() {}
WMRHolographicSpace::~WMRHolographicSpace() = default;
WMRHolographicSpaceImpl::~WMRHolographicSpaceImpl() = default;
HolographicAdapterId WMRHolographicSpace::PrimaryAdapterId() {
HolographicAdapterId WMRHolographicSpaceImpl::PrimaryAdapterId() {
HolographicAdapterId id;
HRESULT hr = space_->get_PrimaryAdapterId(&id);
DCHECK(SUCCEEDED(hr));
return id;
}
std::unique_ptr<WMRHolographicFrame> WMRHolographicSpace::TryCreateNextFrame() {
std::unique_ptr<WMRHolographicFrame>
WMRHolographicSpaceImpl::TryCreateNextFrame() {
ComPtr<IHolographicFrame> frame;
HRESULT hr = space_->CreateNextFrame(&frame);
if (FAILED(hr))
return nullptr;
return std::make_unique<WMRHolographicFrame>(frame);
return std::make_unique<WMRHolographicFrameImpl>(frame);
}
bool WMRHolographicSpace::TrySetDirect3D11Device(
bool WMRHolographicSpaceImpl::TrySetDirect3D11Device(
const ComPtr<IDirect3DDevice>& device) {
HRESULT hr = space_->SetDirect3D11Device(device.Get());
return SUCCEEDED(hr);
......
......@@ -15,30 +15,39 @@ namespace device {
class WMRHolographicFrame;
class WMRHolographicSpace {
public:
static std::unique_ptr<WMRHolographicSpace> CreateForWindow(HWND hwnd);
explicit WMRHolographicSpace(
Microsoft::WRL::ComPtr<
ABI::Windows::Graphics::Holographic::IHolographicSpace> space);
virtual ~WMRHolographicSpace();
virtual ~WMRHolographicSpace() = default;
virtual ABI::Windows::Graphics::Holographic::HolographicAdapterId
PrimaryAdapterId();
virtual std::unique_ptr<WMRHolographicFrame> TryCreateNextFrame();
PrimaryAdapterId() = 0;
virtual std::unique_ptr<WMRHolographicFrame> TryCreateNextFrame() = 0;
virtual bool TrySetDirect3D11Device(
const Microsoft::WRL::ComPtr<
ABI::Windows::Graphics::DirectX::Direct3D11::IDirect3DDevice>&
device);
device) = 0;
};
protected:
// Necessary so subclasses don't call the explicit constructor.
WMRHolographicSpace();
class WMRHolographicSpaceImpl : public WMRHolographicSpace {
public:
explicit WMRHolographicSpaceImpl(
Microsoft::WRL::ComPtr<
ABI::Windows::Graphics::Holographic::IHolographicSpace> space);
~WMRHolographicSpaceImpl() override;
ABI::Windows::Graphics::Holographic::HolographicAdapterId PrimaryAdapterId()
override;
std::unique_ptr<WMRHolographicFrame> TryCreateNextFrame() override;
bool TrySetDirect3D11Device(
const Microsoft::WRL::ComPtr<
ABI::Windows::Graphics::DirectX::Direct3D11::IDirect3DDevice>& device)
override;
private:
Microsoft::WRL::ComPtr<ABI::Windows::Graphics::Holographic::IHolographicSpace>
space_;
DISALLOW_COPY_AND_ASSIGN(WMRHolographicSpace);
DISALLOW_COPY_AND_ASSIGN(WMRHolographicSpaceImpl);
};
} // namespace device
#endif // DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_WMR_HOLOGRAPHIC_SPACE_H_
......@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "device/vr/windows_mixed_reality/wrappers/wmr_input_manager.h"
#include <SpatialInteractionManagerInterop.h>
#include <windows.perception.h>
#include <windows.ui.input.spatial.h>
#include <wrl.h>
......@@ -65,32 +64,8 @@ WMRInputSourceState WMRInputSourceEventArgs::State() const {
return WMRInputSourceState(wmr_state);
}
std::unique_ptr<WMRInputManager> WMRInputManager::GetForWindow(HWND hwnd) {
if (MixedRealityDeviceStatics::GetLockedTestHook().GetHook()) {
return std::make_unique<MockWMRInputManager>();
}
if (!hwnd)
return nullptr;
ComPtr<ISpatialInteractionManagerInterop> spatial_interaction_interop;
base::win::ScopedHString spatial_interaction_interop_string =
base::win::ScopedHString::Create(
RuntimeClass_Windows_UI_Input_Spatial_SpatialInteractionManager);
HRESULT hr = base::win::RoGetActivationFactory(
spatial_interaction_interop_string.get(),
IID_PPV_ARGS(&spatial_interaction_interop));
if (FAILED(hr))
return nullptr;
ComPtr<ISpatialInteractionManager> manager;
hr = spatial_interaction_interop->GetForWindow(hwnd, IID_PPV_ARGS(&manager));
if (FAILED(hr))
return nullptr;
return std::make_unique<WMRInputManager>(manager);
}
WMRInputManager::WMRInputManager(ComPtr<ISpatialInteractionManager> manager)
WMRInputManagerImpl::WMRInputManagerImpl(
ComPtr<ISpatialInteractionManager> manager)
: manager_(manager) {
DCHECK(manager_);
pressed_token_.value = 0;
......@@ -98,13 +73,12 @@ WMRInputManager::WMRInputManager(ComPtr<ISpatialInteractionManager> manager)
SubscribeEvents();
}
WMRInputManager::WMRInputManager() {}
WMRInputManager::~WMRInputManager() {
WMRInputManagerImpl::~WMRInputManagerImpl() {
UnsubscribeEvents();
}
std::vector<WMRInputSourceState> WMRInputManager::GetDetectedSourcesAtTimestamp(
std::vector<WMRInputSourceState>
WMRInputManagerImpl::GetDetectedSourcesAtTimestamp(
ComPtr<IPerceptionTimestamp> timestamp) const {
std::vector<WMRInputSourceState> input_states;
ComPtr<IVectorView<SpatialInteractionSourceState*>> source_states;
......@@ -127,16 +101,16 @@ std::vector<WMRInputSourceState> WMRInputManager::GetDetectedSourcesAtTimestamp(
}
std::unique_ptr<WMRInputManager::InputEventCallbackList::Subscription>
WMRInputManager::AddPressedCallback(const InputEventCallback& cb) {
WMRInputManagerImpl::AddPressedCallback(const InputEventCallback& cb) {
return pressed_callback_list_.Add(cb);
}
std::unique_ptr<WMRInputManager::InputEventCallbackList::Subscription>
WMRInputManager::AddReleasedCallback(const InputEventCallback& cb) {
WMRInputManagerImpl::AddReleasedCallback(const InputEventCallback& cb) {
return released_callback_list_.Add(cb);
}
HRESULT WMRInputManager::OnSourcePressed(
HRESULT WMRInputManagerImpl::OnSourcePressed(
ISpatialInteractionManager* sender,
ISpatialInteractionSourceEventArgs* raw_args) {
ComPtr<ISpatialInteractionSourceEventArgs> wmr_args(raw_args);
......@@ -145,7 +119,7 @@ HRESULT WMRInputManager::OnSourcePressed(
return S_OK;
}
HRESULT WMRInputManager::OnSourceReleased(
HRESULT WMRInputManagerImpl::OnSourceReleased(
ISpatialInteractionManager* sender,
ISpatialInteractionSourceEventArgs* raw_args) {
ComPtr<ISpatialInteractionSourceEventArgs> wmr_args(raw_args);
......@@ -154,26 +128,26 @@ HRESULT WMRInputManager::OnSourceReleased(
return S_OK;
}
void WMRInputManager::SubscribeEvents() {
void WMRInputManagerImpl::SubscribeEvents() {
DCHECK(manager_);
DCHECK(pressed_token_.value == 0);
DCHECK(released_token_.value == 0);
// The destructor ensures that we're unsubscribed so raw this is fine.
auto pressed_callback = Callback<SpatialInteractionSourceEventHandler>(
this, &WMRInputManager::OnSourcePressed);
this, &WMRInputManagerImpl::OnSourcePressed);
HRESULT hr =
manager_->add_SourcePressed(pressed_callback.Get(), &pressed_token_);
DCHECK(SUCCEEDED(hr));
// The destructor ensures that we're unsubscribed so raw this is fine.
auto released_callback = Callback<SpatialInteractionSourceEventHandler>(
this, &WMRInputManager::OnSourceReleased);
this, &WMRInputManagerImpl::OnSourceReleased);
hr = manager_->add_SourceReleased(released_callback.Get(), &released_token_);
DCHECK(SUCCEEDED(hr));
}
void WMRInputManager::UnsubscribeEvents() {
void WMRInputManagerImpl::UnsubscribeEvents() {
if (!manager_)
return;
......
......@@ -44,27 +44,41 @@ class WMRInputManager {
using InputEventCallback =
base::RepeatingCallback<void(const WMRInputSourceEventArgs&)>;
static std::unique_ptr<WMRInputManager> GetForWindow(HWND hwnd);
virtual ~WMRInputManager() = default;
explicit WMRInputManager(
virtual std::vector<WMRInputSourceState> GetDetectedSourcesAtTimestamp(
Microsoft::WRL::ComPtr<ABI::Windows::Perception::IPerceptionTimestamp>
timestamp) const = 0;
virtual std::unique_ptr<InputEventCallbackList::Subscription>
AddPressedCallback(const InputEventCallback& cb) = 0;
virtual std::unique_ptr<InputEventCallbackList::Subscription>
AddReleasedCallback(const InputEventCallback& cb) = 0;
};
class WMRInputManagerImpl : public WMRInputManager {
public:
using InputEventCallbackList =
base::CallbackList<void(const WMRInputSourceEventArgs&)>;
using InputEventCallback =
base::RepeatingCallback<void(const WMRInputSourceEventArgs&)>;
explicit WMRInputManagerImpl(
Microsoft::WRL::ComPtr<
ABI::Windows::UI::Input::Spatial::ISpatialInteractionManager>
manager);
virtual ~WMRInputManager();
~WMRInputManagerImpl() override;
virtual std::vector<WMRInputSourceState> GetDetectedSourcesAtTimestamp(
std::vector<WMRInputSourceState> GetDetectedSourcesAtTimestamp(
Microsoft::WRL::ComPtr<ABI::Windows::Perception::IPerceptionTimestamp>
timestamp) const;
timestamp) const override;
std::unique_ptr<InputEventCallbackList::Subscription> AddPressedCallback(
const InputEventCallback& cb);
const InputEventCallback& cb) override;
std::unique_ptr<InputEventCallbackList::Subscription> AddReleasedCallback(
const InputEventCallback& cb);
protected:
// Necessary so subclasses don't call the explicit constructor.
WMRInputManager();
const InputEventCallback& cb) override;
private:
void SubscribeEvents();
......@@ -88,7 +102,7 @@ class WMRInputManager {
InputEventCallbackList pressed_callback_list_;
InputEventCallbackList released_callback_list_;
DISALLOW_COPY_AND_ASSIGN(WMRInputManager);
DISALLOW_COPY_AND_ASSIGN(WMRInputManagerImpl);
};
} // namespace device
......
......@@ -39,6 +39,11 @@ using Microsoft::WRL::ComPtr;
namespace device {
// WMRCoordinateSystem
ISpatialCoordinateSystem* WMRCoordinateSystem::GetRawPtr() const {
NOTREACHED();
return nullptr;
}
WMRCoordinateSystemImpl::WMRCoordinateSystemImpl(
ComPtr<ISpatialCoordinateSystem> coordinates)
: coordinates_(coordinates) {
......
......@@ -23,8 +23,10 @@ class WMRCoordinateSystem {
const WMRCoordinateSystem* other,
ABI::Windows::Foundation::Numerics::Matrix4x4* this_to_other) = 0;
// This should only ever be used by the real implementation, so by default
// make sure it's not called.
virtual ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem*
GetRawPtr() const = 0;
GetRawPtr() const;
};
class WMRCoordinateSystemImpl : public WMRCoordinateSystem {
......
......@@ -4,6 +4,9 @@
#include "device/vr/windows_mixed_reality/wrappers/wmr_wrapper_factories.h"
#include <HolographicSpaceInterop.h>
#include <SpatialInteractionManagerInterop.h>
#include <windows.perception.h>
#include <windows.perception.spatial.h>
#include <wrl.h>
......@@ -11,6 +14,8 @@
#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_holographic_space.h"
#include "device/vr/windows_mixed_reality/wrappers/test/mock_wmr_input_manager.h"
#include "device/vr/windows_mixed_reality/wrappers/test/mock_wmr_origins.h"
#include "device/vr/windows_mixed_reality/wrappers/wmr_logging.h"
......@@ -19,6 +24,7 @@ using SpatialMovementRange =
ABI::Windows::Perception::Spatial::SpatialMovementRange;
using ABI::Windows::Foundation::IEventHandler;
using ABI::Windows::Foundation::IReference;
using ABI::Windows::Graphics::Holographic::IHolographicSpace;
using ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem;
using ABI::Windows::Perception::Spatial::ISpatialLocator;
using ABI::Windows::Perception::Spatial::
......@@ -27,6 +33,7 @@ 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 ABI::Windows::UI::Input::Spatial::ISpatialInteractionManager;
using Microsoft::WRL::ComPtr;
namespace {
......@@ -115,4 +122,58 @@ std::unique_ptr<WMRStageStatics> WMRStageStaticsFactory::Create() {
return std::make_unique<WMRStageStaticsImpl>(stage_statics);
}
std::unique_ptr<WMRInputManager> WMRInputManagerFactory::GetForWindow(
HWND hwnd) {
if (MixedRealityDeviceStatics::ShouldUseMocks()) {
return std::make_unique<MockWMRInputManager>();
}
if (!hwnd)
return nullptr;
ComPtr<ISpatialInteractionManagerInterop> spatial_interaction_interop;
base::win::ScopedHString spatial_interaction_interop_string =
base::win::ScopedHString::Create(
RuntimeClass_Windows_UI_Input_Spatial_SpatialInteractionManager);
HRESULT hr = base::win::RoGetActivationFactory(
spatial_interaction_interop_string.get(),
IID_PPV_ARGS(&spatial_interaction_interop));
if (FAILED(hr))
return nullptr;
ComPtr<ISpatialInteractionManager> manager;
hr = spatial_interaction_interop->GetForWindow(hwnd, IID_PPV_ARGS(&manager));
if (FAILED(hr))
return nullptr;
return std::make_unique<WMRInputManagerImpl>(manager);
}
std::unique_ptr<WMRHolographicSpace>
WMRHolographicSpaceFactory::CreateForWindow(HWND hwnd) {
if (MixedRealityDeviceStatics::ShouldUseMocks()) {
return std::make_unique<MockWMRHolographicSpace>();
}
if (!hwnd)
return nullptr;
ComPtr<IHolographicSpaceInterop> holographic_space_interop;
base::win::ScopedHString holographic_space_string =
base::win::ScopedHString::Create(
RuntimeClass_Windows_Graphics_Holographic_HolographicSpace);
HRESULT hr = base::win::RoGetActivationFactory(
holographic_space_string.get(), IID_PPV_ARGS(&holographic_space_interop));
if (FAILED(hr))
return nullptr;
ComPtr<IHolographicSpace> holographic_space;
hr = holographic_space_interop->CreateForWindow(
hwnd, IID_PPV_ARGS(&holographic_space));
if (FAILED(hr))
return nullptr;
return std::make_unique<WMRHolographicSpaceImpl>(holographic_space);
}
} // namespace device
......@@ -4,6 +4,8 @@
#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_holographic_space.h"
#include "device/vr/windows_mixed_reality/wrappers/wmr_input_manager.h"
#include "device/vr/windows_mixed_reality/wrappers/wmr_origins.h"
namespace device {
......@@ -23,6 +25,16 @@ class WMRStageStaticsFactory {
static std::unique_ptr<WMRStageStatics> Create();
};
class WMRInputManagerFactory {
public:
static std::unique_ptr<WMRInputManager> GetForWindow(HWND hwnd);
};
class WMRHolographicSpaceFactory {
public:
static std::unique_ptr<WMRHolographicSpace> CreateForWindow(HWND hwnd);
};
} // 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