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 @@ ...@@ -24,6 +24,7 @@
#include "device/vr/windows_mixed_reality/wrappers/wmr_pointer_pose.h" #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_pointer_source_pose.h"
#include "device/vr/windows_mixed_reality/wrappers/wmr_timestamp.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.h"
#include "ui/gfx/transform_util.h" #include "ui/gfx/transform_util.h"
...@@ -368,7 +369,7 @@ bool MixedRealityInputHelper::EnsureSpatialInteractionManager() { ...@@ -368,7 +369,7 @@ bool MixedRealityInputHelper::EnsureSpatialInteractionManager() {
if (!hwnd_) if (!hwnd_)
return false; return false;
input_manager_ = WMRInputManager::GetForWindow(hwnd_); input_manager_ = WMRInputManagerFactory::GetForWindow(hwnd_);
if (!input_manager_) if (!input_manager_)
return false; return false;
......
...@@ -410,7 +410,8 @@ void MixedRealityRenderLoop::InitializeSpace() { ...@@ -410,7 +410,8 @@ void MixedRealityRenderLoop::InitializeSpace() {
// A small arbitrary size that keeps the window from being distracting. // A small arbitrary size that keeps the window from being distracting.
window_->Init(NULL, gfx::Rect(25, 10)); window_->Init(NULL, gfx::Rect(25, 10));
holographic_space_ = WMRHolographicSpace::CreateForWindow(window_->hwnd()); holographic_space_ =
WMRHolographicSpaceFactory::CreateForWindow(window_->hwnd());
} }
void MixedRealityRenderLoop::StartPresenting() { void MixedRealityRenderLoop::StartPresenting() {
......
...@@ -19,4 +19,16 @@ MockWMRInputManager::GetDetectedSourcesAtTimestamp( ...@@ -19,4 +19,16 @@ MockWMRInputManager::GetDetectedSourcesAtTimestamp(
return {}; 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 } // namespace device
...@@ -17,7 +17,15 @@ class MockWMRInputManager : public WMRInputManager { ...@@ -17,7 +17,15 @@ class MockWMRInputManager : public WMRInputManager {
Microsoft::WRL::ComPtr<ABI::Windows::Perception::IPerceptionTimestamp> Microsoft::WRL::ComPtr<ABI::Windows::Perception::IPerceptionTimestamp>
timestamp) const override; timestamp) const override;
std::unique_ptr<InputEventCallbackList::Subscription> AddPressedCallback(
const InputEventCallback& cb) override;
std::unique_ptr<InputEventCallbackList::Subscription> AddReleasedCallback(
const InputEventCallback& cb) override;
private: private:
InputEventCallbackList pressed_callback_list_;
InputEventCallbackList released_callback_list_;
DISALLOW_COPY_AND_ASSIGN(MockWMRInputManager); DISALLOW_COPY_AND_ASSIGN(MockWMRInputManager);
}; };
......
...@@ -18,11 +18,6 @@ bool MockWMRCoordinateSystem::TryGetTransformTo( ...@@ -18,11 +18,6 @@ bool MockWMRCoordinateSystem::TryGetTransformTo(
return true; return true;
} }
ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem*
MockWMRCoordinateSystem::GetRawPtr() const {
return nullptr;
}
// MockWMRStationaryOrigin // MockWMRStationaryOrigin
MockWMRStationaryOrigin::MockWMRStationaryOrigin() {} MockWMRStationaryOrigin::MockWMRStationaryOrigin() {}
......
...@@ -19,9 +19,6 @@ class MockWMRCoordinateSystem : public WMRCoordinateSystem { ...@@ -19,9 +19,6 @@ class MockWMRCoordinateSystem : public WMRCoordinateSystem {
const WMRCoordinateSystem* other, const WMRCoordinateSystem* other,
ABI::Windows::Foundation::Numerics::Matrix4x4* this_to_other) override; ABI::Windows::Foundation::Numerics::Matrix4x4* this_to_other) override;
ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem* GetRawPtr()
const override;
private: private:
DISALLOW_COPY_AND_ASSIGN(MockWMRCoordinateSystem); DISALLOW_COPY_AND_ASSIGN(MockWMRCoordinateSystem);
}; };
......
...@@ -31,17 +31,16 @@ using Microsoft::WRL::ComPtr; ...@@ -31,17 +31,16 @@ using Microsoft::WRL::ComPtr;
namespace device { namespace device {
// WMRHolographicFramePrediction // WMRHolographicFramePrediction
WMRHolographicFramePrediction::WMRHolographicFramePrediction( WMRHolographicFramePredictionImpl::WMRHolographicFramePredictionImpl(
ComPtr<IHolographicFramePrediction> prediction) ComPtr<IHolographicFramePrediction> prediction)
: prediction_(prediction) { : prediction_(prediction) {
DCHECK(prediction_); DCHECK(prediction_);
} }
WMRHolographicFramePrediction::WMRHolographicFramePrediction() {} WMRHolographicFramePredictionImpl::~WMRHolographicFramePredictionImpl() =
default;
WMRHolographicFramePrediction::~WMRHolographicFramePrediction() = default; std::unique_ptr<WMRTimestamp> WMRHolographicFramePredictionImpl::Timestamp() {
std::unique_ptr<WMRTimestamp> WMRHolographicFramePrediction::Timestamp() {
ComPtr<IPerceptionTimestamp> timestamp; ComPtr<IPerceptionTimestamp> timestamp;
HRESULT hr = prediction_->get_Timestamp(&timestamp); HRESULT hr = prediction_->get_Timestamp(&timestamp);
DCHECK(SUCCEEDED(hr)); DCHECK(SUCCEEDED(hr));
...@@ -49,7 +48,7 @@ std::unique_ptr<WMRTimestamp> WMRHolographicFramePrediction::Timestamp() { ...@@ -49,7 +48,7 @@ std::unique_ptr<WMRTimestamp> WMRHolographicFramePrediction::Timestamp() {
} }
std::vector<std::unique_ptr<WMRCameraPose>> std::vector<std::unique_ptr<WMRCameraPose>>
WMRHolographicFramePrediction::CameraPoses() { WMRHolographicFramePredictionImpl::CameraPoses() {
std::vector<std::unique_ptr<WMRCameraPose>> ret_val; std::vector<std::unique_ptr<WMRCameraPose>> ret_val;
ComPtr<IVectorView<HolographicCameraPose*>> poses; ComPtr<IVectorView<HolographicCameraPose*>> poses;
HRESULT hr = prediction_->get_CameraPoses(&poses); HRESULT hr = prediction_->get_CameraPoses(&poses);
...@@ -70,26 +69,24 @@ WMRHolographicFramePrediction::CameraPoses() { ...@@ -70,26 +69,24 @@ WMRHolographicFramePrediction::CameraPoses() {
} }
// WMRHolographicFrame // WMRHolographicFrame
WMRHolographicFrame::WMRHolographicFrame( WMRHolographicFrameImpl::WMRHolographicFrameImpl(
ComPtr<IHolographicFrame> holographic_frame) ComPtr<IHolographicFrame> holographic_frame)
: holographic_frame_(holographic_frame) { : holographic_frame_(holographic_frame) {
DCHECK(holographic_frame_); DCHECK(holographic_frame_);
} }
WMRHolographicFrame::WMRHolographicFrame() {} WMRHolographicFrameImpl::~WMRHolographicFrameImpl() = default;
WMRHolographicFrame::~WMRHolographicFrame() = default;
std::unique_ptr<WMRHolographicFramePrediction> std::unique_ptr<WMRHolographicFramePrediction>
WMRHolographicFrame::CurrentPrediction() { WMRHolographicFrameImpl::CurrentPrediction() {
ComPtr<IHolographicFramePrediction> prediction; ComPtr<IHolographicFramePrediction> prediction;
HRESULT hr = holographic_frame_->get_CurrentPrediction(&prediction); HRESULT hr = holographic_frame_->get_CurrentPrediction(&prediction);
DCHECK(SUCCEEDED(hr)); DCHECK(SUCCEEDED(hr));
return std::make_unique<WMRHolographicFramePrediction>(prediction); return std::make_unique<WMRHolographicFramePredictionImpl>(prediction);
} }
std::unique_ptr<WMRRenderingParameters> std::unique_ptr<WMRRenderingParameters>
WMRHolographicFrame::TryGetRenderingParameters(const WMRCameraPose* pose) { WMRHolographicFrameImpl::TryGetRenderingParameters(const WMRCameraPose* pose) {
ComPtr<IHolographicCameraRenderingParameters> rendering_params; ComPtr<IHolographicCameraRenderingParameters> rendering_params;
HRESULT hr = holographic_frame_->GetRenderingParameters(pose->GetRawPtr(), HRESULT hr = holographic_frame_->GetRenderingParameters(pose->GetRawPtr(),
&rendering_params); &rendering_params);
...@@ -98,7 +95,7 @@ WMRHolographicFrame::TryGetRenderingParameters(const WMRCameraPose* pose) { ...@@ -98,7 +95,7 @@ WMRHolographicFrame::TryGetRenderingParameters(const WMRCameraPose* pose) {
return std::make_unique<WMRRenderingParameters>(rendering_params); return std::make_unique<WMRRenderingParameters>(rendering_params);
} }
bool WMRHolographicFrame::TryPresentUsingCurrentPrediction() { bool WMRHolographicFrameImpl::TryPresentUsingCurrentPrediction() {
PresentResult result = PresentResult::HolographicFramePresentResult_Success; PresentResult result = PresentResult::HolographicFramePresentResult_Success;
HRESULT hr = holographic_frame_->PresentUsingCurrentPrediction(&result); HRESULT hr = holographic_frame_->PresentUsingCurrentPrediction(&result);
......
...@@ -19,49 +19,61 @@ class WMRTimestamp; ...@@ -19,49 +19,61 @@ class WMRTimestamp;
class WMRHolographicFramePrediction { class WMRHolographicFramePrediction {
public: 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< Microsoft::WRL::ComPtr<
ABI::Windows::Graphics::Holographic::IHolographicFramePrediction> ABI::Windows::Graphics::Holographic::IHolographicFramePrediction>
prediction); prediction);
virtual ~WMRHolographicFramePrediction(); ~WMRHolographicFramePredictionImpl() override;
virtual std::unique_ptr<WMRTimestamp> Timestamp(); std::unique_ptr<WMRTimestamp> Timestamp() override;
virtual std::vector<std::unique_ptr<WMRCameraPose>> CameraPoses(); std::vector<std::unique_ptr<WMRCameraPose>> CameraPoses() override;
protected:
// Necessary so subclasses don't call the explicit constructor.
WMRHolographicFramePrediction();
private: private:
Microsoft::WRL::ComPtr< Microsoft::WRL::ComPtr<
ABI::Windows::Graphics::Holographic::IHolographicFramePrediction> ABI::Windows::Graphics::Holographic::IHolographicFramePrediction>
prediction_; prediction_;
DISALLOW_COPY_AND_ASSIGN(WMRHolographicFramePrediction); DISALLOW_COPY_AND_ASSIGN(WMRHolographicFramePredictionImpl);
}; };
class WMRHolographicFrame { class WMRHolographicFrame {
public: 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< Microsoft::WRL::ComPtr<
ABI::Windows::Graphics::Holographic::IHolographicFrame> ABI::Windows::Graphics::Holographic::IHolographicFrame>
holographic_frame); holographic_frame);
virtual ~WMRHolographicFrame(); ~WMRHolographicFrameImpl() override;
virtual std::unique_ptr<WMRHolographicFramePrediction> CurrentPrediction(); std::unique_ptr<WMRHolographicFramePrediction> CurrentPrediction() override;
virtual std::unique_ptr<WMRRenderingParameters> TryGetRenderingParameters( std::unique_ptr<WMRRenderingParameters> TryGetRenderingParameters(
const WMRCameraPose* pose); const WMRCameraPose* pose) override;
virtual bool TryPresentUsingCurrentPrediction(); bool TryPresentUsingCurrentPrediction() override;
protected:
// Necessary so subclasses don't call the explicit constructor.
WMRHolographicFrame();
private: private:
Microsoft::WRL::ComPtr<ABI::Windows::Graphics::Holographic::IHolographicFrame> Microsoft::WRL::ComPtr<ABI::Windows::Graphics::Holographic::IHolographicFrame>
holographic_frame_; holographic_frame_;
DISALLOW_COPY_AND_ASSIGN(WMRHolographicFrame); DISALLOW_COPY_AND_ASSIGN(WMRHolographicFrameImpl);
}; };
} // namespace device } // namespace device
#endif // DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_WMR_HOLOGRAPHIC_FRAME_H_ #endif // DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_WMR_HOLOGRAPHIC_FRAME_H_
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "device/vr/windows_mixed_reality/wrappers/wmr_holographic_space.h" #include "device/vr/windows_mixed_reality/wrappers/wmr_holographic_space.h"
#include <HolographicSpaceInterop.h>
#include <Windows.Graphics.DirectX.Direct3D11.interop.h> #include <Windows.Graphics.DirectX.Direct3D11.interop.h>
#include <windows.graphics.holographic.h> #include <windows.graphics.holographic.h>
#include <wrl.h> #include <wrl.h>
...@@ -26,59 +25,32 @@ using ABI::Windows::Graphics::Holographic::IHolographicSpace; ...@@ -26,59 +25,32 @@ using ABI::Windows::Graphics::Holographic::IHolographicSpace;
using Microsoft::WRL::ComPtr; using Microsoft::WRL::ComPtr;
namespace device { 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)) WMRHolographicSpaceImpl::WMRHolographicSpaceImpl(
return nullptr; ComPtr<IHolographicSpace> space)
return std::make_unique<WMRHolographicSpace>(holographic_space);
}
WMRHolographicSpace::WMRHolographicSpace(ComPtr<IHolographicSpace> space)
: space_(space) { : space_(space) {
DCHECK(space_); DCHECK(space_);
} }
WMRHolographicSpace::WMRHolographicSpace() {} WMRHolographicSpaceImpl::~WMRHolographicSpaceImpl() = default;
WMRHolographicSpace::~WMRHolographicSpace() = default;
HolographicAdapterId WMRHolographicSpace::PrimaryAdapterId() { HolographicAdapterId WMRHolographicSpaceImpl::PrimaryAdapterId() {
HolographicAdapterId id; HolographicAdapterId id;
HRESULT hr = space_->get_PrimaryAdapterId(&id); HRESULT hr = space_->get_PrimaryAdapterId(&id);
DCHECK(SUCCEEDED(hr)); DCHECK(SUCCEEDED(hr));
return id; return id;
} }
std::unique_ptr<WMRHolographicFrame> WMRHolographicSpace::TryCreateNextFrame() { std::unique_ptr<WMRHolographicFrame>
WMRHolographicSpaceImpl::TryCreateNextFrame() {
ComPtr<IHolographicFrame> frame; ComPtr<IHolographicFrame> frame;
HRESULT hr = space_->CreateNextFrame(&frame); HRESULT hr = space_->CreateNextFrame(&frame);
if (FAILED(hr)) if (FAILED(hr))
return nullptr; return nullptr;
return std::make_unique<WMRHolographicFrame>(frame); return std::make_unique<WMRHolographicFrameImpl>(frame);
} }
bool WMRHolographicSpace::TrySetDirect3D11Device( bool WMRHolographicSpaceImpl::TrySetDirect3D11Device(
const ComPtr<IDirect3DDevice>& device) { const ComPtr<IDirect3DDevice>& device) {
HRESULT hr = space_->SetDirect3D11Device(device.Get()); HRESULT hr = space_->SetDirect3D11Device(device.Get());
return SUCCEEDED(hr); return SUCCEEDED(hr);
......
...@@ -15,30 +15,39 @@ namespace device { ...@@ -15,30 +15,39 @@ namespace device {
class WMRHolographicFrame; class WMRHolographicFrame;
class WMRHolographicSpace { class WMRHolographicSpace {
public: public:
static std::unique_ptr<WMRHolographicSpace> CreateForWindow(HWND hwnd); virtual ~WMRHolographicSpace() = default;
explicit WMRHolographicSpace(
Microsoft::WRL::ComPtr<
ABI::Windows::Graphics::Holographic::IHolographicSpace> space);
virtual ~WMRHolographicSpace();
virtual ABI::Windows::Graphics::Holographic::HolographicAdapterId virtual ABI::Windows::Graphics::Holographic::HolographicAdapterId
PrimaryAdapterId(); PrimaryAdapterId() = 0;
virtual std::unique_ptr<WMRHolographicFrame> TryCreateNextFrame(); virtual std::unique_ptr<WMRHolographicFrame> TryCreateNextFrame() = 0;
virtual bool TrySetDirect3D11Device( virtual bool TrySetDirect3D11Device(
const Microsoft::WRL::ComPtr< const Microsoft::WRL::ComPtr<
ABI::Windows::Graphics::DirectX::Direct3D11::IDirect3DDevice>& ABI::Windows::Graphics::DirectX::Direct3D11::IDirect3DDevice>&
device); device) = 0;
};
protected: class WMRHolographicSpaceImpl : public WMRHolographicSpace {
// Necessary so subclasses don't call the explicit constructor. public:
WMRHolographicSpace(); 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: private:
Microsoft::WRL::ComPtr<ABI::Windows::Graphics::Holographic::IHolographicSpace> Microsoft::WRL::ComPtr<ABI::Windows::Graphics::Holographic::IHolographicSpace>
space_; space_;
DISALLOW_COPY_AND_ASSIGN(WMRHolographicSpace); DISALLOW_COPY_AND_ASSIGN(WMRHolographicSpaceImpl);
}; };
} // namespace device } // namespace device
#endif // DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_WMR_HOLOGRAPHIC_SPACE_H_ #endif // DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_WMR_HOLOGRAPHIC_SPACE_H_
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "device/vr/windows_mixed_reality/wrappers/wmr_input_manager.h" #include "device/vr/windows_mixed_reality/wrappers/wmr_input_manager.h"
#include <SpatialInteractionManagerInterop.h>
#include <windows.perception.h> #include <windows.perception.h>
#include <windows.ui.input.spatial.h> #include <windows.ui.input.spatial.h>
#include <wrl.h> #include <wrl.h>
...@@ -65,32 +64,8 @@ WMRInputSourceState WMRInputSourceEventArgs::State() const { ...@@ -65,32 +64,8 @@ WMRInputSourceState WMRInputSourceEventArgs::State() const {
return WMRInputSourceState(wmr_state); return WMRInputSourceState(wmr_state);
} }
std::unique_ptr<WMRInputManager> WMRInputManager::GetForWindow(HWND hwnd) { WMRInputManagerImpl::WMRInputManagerImpl(
if (MixedRealityDeviceStatics::GetLockedTestHook().GetHook()) { ComPtr<ISpatialInteractionManager> manager)
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)
: manager_(manager) { : manager_(manager) {
DCHECK(manager_); DCHECK(manager_);
pressed_token_.value = 0; pressed_token_.value = 0;
...@@ -98,13 +73,12 @@ WMRInputManager::WMRInputManager(ComPtr<ISpatialInteractionManager> manager) ...@@ -98,13 +73,12 @@ WMRInputManager::WMRInputManager(ComPtr<ISpatialInteractionManager> manager)
SubscribeEvents(); SubscribeEvents();
} }
WMRInputManager::WMRInputManager() {} WMRInputManagerImpl::~WMRInputManagerImpl() {
WMRInputManager::~WMRInputManager() {
UnsubscribeEvents(); UnsubscribeEvents();
} }
std::vector<WMRInputSourceState> WMRInputManager::GetDetectedSourcesAtTimestamp( std::vector<WMRInputSourceState>
WMRInputManagerImpl::GetDetectedSourcesAtTimestamp(
ComPtr<IPerceptionTimestamp> timestamp) const { ComPtr<IPerceptionTimestamp> timestamp) const {
std::vector<WMRInputSourceState> input_states; std::vector<WMRInputSourceState> input_states;
ComPtr<IVectorView<SpatialInteractionSourceState*>> source_states; ComPtr<IVectorView<SpatialInteractionSourceState*>> source_states;
...@@ -127,16 +101,16 @@ std::vector<WMRInputSourceState> WMRInputManager::GetDetectedSourcesAtTimestamp( ...@@ -127,16 +101,16 @@ std::vector<WMRInputSourceState> WMRInputManager::GetDetectedSourcesAtTimestamp(
} }
std::unique_ptr<WMRInputManager::InputEventCallbackList::Subscription> std::unique_ptr<WMRInputManager::InputEventCallbackList::Subscription>
WMRInputManager::AddPressedCallback(const InputEventCallback& cb) { WMRInputManagerImpl::AddPressedCallback(const InputEventCallback& cb) {
return pressed_callback_list_.Add(cb); return pressed_callback_list_.Add(cb);
} }
std::unique_ptr<WMRInputManager::InputEventCallbackList::Subscription> std::unique_ptr<WMRInputManager::InputEventCallbackList::Subscription>
WMRInputManager::AddReleasedCallback(const InputEventCallback& cb) { WMRInputManagerImpl::AddReleasedCallback(const InputEventCallback& cb) {
return released_callback_list_.Add(cb); return released_callback_list_.Add(cb);
} }
HRESULT WMRInputManager::OnSourcePressed( HRESULT WMRInputManagerImpl::OnSourcePressed(
ISpatialInteractionManager* sender, ISpatialInteractionManager* sender,
ISpatialInteractionSourceEventArgs* raw_args) { ISpatialInteractionSourceEventArgs* raw_args) {
ComPtr<ISpatialInteractionSourceEventArgs> wmr_args(raw_args); ComPtr<ISpatialInteractionSourceEventArgs> wmr_args(raw_args);
...@@ -145,7 +119,7 @@ HRESULT WMRInputManager::OnSourcePressed( ...@@ -145,7 +119,7 @@ HRESULT WMRInputManager::OnSourcePressed(
return S_OK; return S_OK;
} }
HRESULT WMRInputManager::OnSourceReleased( HRESULT WMRInputManagerImpl::OnSourceReleased(
ISpatialInteractionManager* sender, ISpatialInteractionManager* sender,
ISpatialInteractionSourceEventArgs* raw_args) { ISpatialInteractionSourceEventArgs* raw_args) {
ComPtr<ISpatialInteractionSourceEventArgs> wmr_args(raw_args); ComPtr<ISpatialInteractionSourceEventArgs> wmr_args(raw_args);
...@@ -154,26 +128,26 @@ HRESULT WMRInputManager::OnSourceReleased( ...@@ -154,26 +128,26 @@ HRESULT WMRInputManager::OnSourceReleased(
return S_OK; return S_OK;
} }
void WMRInputManager::SubscribeEvents() { void WMRInputManagerImpl::SubscribeEvents() {
DCHECK(manager_); DCHECK(manager_);
DCHECK(pressed_token_.value == 0); DCHECK(pressed_token_.value == 0);
DCHECK(released_token_.value == 0); DCHECK(released_token_.value == 0);
// The destructor ensures that we're unsubscribed so raw this is fine. // The destructor ensures that we're unsubscribed so raw this is fine.
auto pressed_callback = Callback<SpatialInteractionSourceEventHandler>( auto pressed_callback = Callback<SpatialInteractionSourceEventHandler>(
this, &WMRInputManager::OnSourcePressed); this, &WMRInputManagerImpl::OnSourcePressed);
HRESULT hr = HRESULT hr =
manager_->add_SourcePressed(pressed_callback.Get(), &pressed_token_); manager_->add_SourcePressed(pressed_callback.Get(), &pressed_token_);
DCHECK(SUCCEEDED(hr)); DCHECK(SUCCEEDED(hr));
// The destructor ensures that we're unsubscribed so raw this is fine. // The destructor ensures that we're unsubscribed so raw this is fine.
auto released_callback = Callback<SpatialInteractionSourceEventHandler>( auto released_callback = Callback<SpatialInteractionSourceEventHandler>(
this, &WMRInputManager::OnSourceReleased); this, &WMRInputManagerImpl::OnSourceReleased);
hr = manager_->add_SourceReleased(released_callback.Get(), &released_token_); hr = manager_->add_SourceReleased(released_callback.Get(), &released_token_);
DCHECK(SUCCEEDED(hr)); DCHECK(SUCCEEDED(hr));
} }
void WMRInputManager::UnsubscribeEvents() { void WMRInputManagerImpl::UnsubscribeEvents() {
if (!manager_) if (!manager_)
return; return;
......
...@@ -44,27 +44,41 @@ class WMRInputManager { ...@@ -44,27 +44,41 @@ class WMRInputManager {
using InputEventCallback = using InputEventCallback =
base::RepeatingCallback<void(const WMRInputSourceEventArgs&)>; 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< Microsoft::WRL::ComPtr<
ABI::Windows::UI::Input::Spatial::ISpatialInteractionManager> ABI::Windows::UI::Input::Spatial::ISpatialInteractionManager>
manager); manager);
virtual ~WMRInputManager(); ~WMRInputManagerImpl() override;
virtual std::vector<WMRInputSourceState> GetDetectedSourcesAtTimestamp( std::vector<WMRInputSourceState> GetDetectedSourcesAtTimestamp(
Microsoft::WRL::ComPtr<ABI::Windows::Perception::IPerceptionTimestamp> Microsoft::WRL::ComPtr<ABI::Windows::Perception::IPerceptionTimestamp>
timestamp) const; timestamp) const override;
std::unique_ptr<InputEventCallbackList::Subscription> AddPressedCallback( std::unique_ptr<InputEventCallbackList::Subscription> AddPressedCallback(
const InputEventCallback& cb); const InputEventCallback& cb) override;
std::unique_ptr<InputEventCallbackList::Subscription> AddReleasedCallback( std::unique_ptr<InputEventCallbackList::Subscription> AddReleasedCallback(
const InputEventCallback& cb); const InputEventCallback& cb) override;
protected:
// Necessary so subclasses don't call the explicit constructor.
WMRInputManager();
private: private:
void SubscribeEvents(); void SubscribeEvents();
...@@ -88,7 +102,7 @@ class WMRInputManager { ...@@ -88,7 +102,7 @@ class WMRInputManager {
InputEventCallbackList pressed_callback_list_; InputEventCallbackList pressed_callback_list_;
InputEventCallbackList released_callback_list_; InputEventCallbackList released_callback_list_;
DISALLOW_COPY_AND_ASSIGN(WMRInputManager); DISALLOW_COPY_AND_ASSIGN(WMRInputManagerImpl);
}; };
} // namespace device } // namespace device
......
...@@ -39,6 +39,11 @@ using Microsoft::WRL::ComPtr; ...@@ -39,6 +39,11 @@ using Microsoft::WRL::ComPtr;
namespace device { namespace device {
// WMRCoordinateSystem // WMRCoordinateSystem
ISpatialCoordinateSystem* WMRCoordinateSystem::GetRawPtr() const {
NOTREACHED();
return nullptr;
}
WMRCoordinateSystemImpl::WMRCoordinateSystemImpl( WMRCoordinateSystemImpl::WMRCoordinateSystemImpl(
ComPtr<ISpatialCoordinateSystem> coordinates) ComPtr<ISpatialCoordinateSystem> coordinates)
: coordinates_(coordinates) { : coordinates_(coordinates) {
......
...@@ -23,8 +23,10 @@ class WMRCoordinateSystem { ...@@ -23,8 +23,10 @@ class WMRCoordinateSystem {
const WMRCoordinateSystem* other, const WMRCoordinateSystem* other,
ABI::Windows::Foundation::Numerics::Matrix4x4* this_to_other) = 0; 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* virtual ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem*
GetRawPtr() const = 0; GetRawPtr() const;
}; };
class WMRCoordinateSystemImpl : public WMRCoordinateSystem { class WMRCoordinateSystemImpl : public WMRCoordinateSystem {
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "device/vr/windows_mixed_reality/wrappers/wmr_wrapper_factories.h" #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 <windows.perception.spatial.h>
#include <wrl.h> #include <wrl.h>
...@@ -11,6 +14,8 @@ ...@@ -11,6 +14,8 @@
#include "base/win/core_winrt_util.h" #include "base/win/core_winrt_util.h"
#include "base/win/scoped_hstring.h" #include "base/win/scoped_hstring.h"
#include "device/vr/windows_mixed_reality/mixed_reality_statics.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/test/mock_wmr_origins.h"
#include "device/vr/windows_mixed_reality/wrappers/wmr_logging.h" #include "device/vr/windows_mixed_reality/wrappers/wmr_logging.h"
...@@ -19,6 +24,7 @@ using SpatialMovementRange = ...@@ -19,6 +24,7 @@ using SpatialMovementRange =
ABI::Windows::Perception::Spatial::SpatialMovementRange; ABI::Windows::Perception::Spatial::SpatialMovementRange;
using ABI::Windows::Foundation::IEventHandler; using ABI::Windows::Foundation::IEventHandler;
using ABI::Windows::Foundation::IReference; using ABI::Windows::Foundation::IReference;
using ABI::Windows::Graphics::Holographic::IHolographicSpace;
using ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem; using ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem;
using ABI::Windows::Perception::Spatial::ISpatialLocator; using ABI::Windows::Perception::Spatial::ISpatialLocator;
using ABI::Windows::Perception::Spatial:: using ABI::Windows::Perception::Spatial::
...@@ -27,6 +33,7 @@ using ABI::Windows::Perception::Spatial::ISpatialLocatorStatics; ...@@ -27,6 +33,7 @@ using ABI::Windows::Perception::Spatial::ISpatialLocatorStatics;
using ABI::Windows::Perception::Spatial::ISpatialStageFrameOfReference; using ABI::Windows::Perception::Spatial::ISpatialStageFrameOfReference;
using ABI::Windows::Perception::Spatial::ISpatialStageFrameOfReferenceStatics; using ABI::Windows::Perception::Spatial::ISpatialStageFrameOfReferenceStatics;
using ABI::Windows::Perception::Spatial::ISpatialStationaryFrameOfReference; using ABI::Windows::Perception::Spatial::ISpatialStationaryFrameOfReference;
using ABI::Windows::UI::Input::Spatial::ISpatialInteractionManager;
using Microsoft::WRL::ComPtr; using Microsoft::WRL::ComPtr;
namespace { namespace {
...@@ -115,4 +122,58 @@ std::unique_ptr<WMRStageStatics> WMRStageStaticsFactory::Create() { ...@@ -115,4 +122,58 @@ std::unique_ptr<WMRStageStatics> WMRStageStaticsFactory::Create() {
return std::make_unique<WMRStageStaticsImpl>(stage_statics); 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 } // namespace device
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#ifndef DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_WMR_WRAPPER_FACTORIES_H_ #ifndef DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_WMR_WRAPPER_FACTORIES_H_
#define 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" #include "device/vr/windows_mixed_reality/wrappers/wmr_origins.h"
namespace device { namespace device {
...@@ -23,6 +25,16 @@ class WMRStageStaticsFactory { ...@@ -23,6 +25,16 @@ class WMRStageStaticsFactory {
static std::unique_ptr<WMRStageStatics> Create(); 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 } // namespace device
#endif // DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_WMR_WRAPPER_FACTORIES_H_ #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