Line data Source code
1 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef GFX_VR_PUPPET_H
7 : #define GFX_VR_PUPPET_H
8 :
9 : #include "nsTArray.h"
10 : #include "mozilla/RefPtr.h"
11 :
12 : #include "gfxVR.h"
13 :
14 : namespace mozilla {
15 : namespace gfx {
16 : namespace impl {
17 :
18 : class VRDisplayPuppet : public VRDisplayHost
19 : {
20 : public:
21 : void SetDisplayInfo(const VRDisplayInfo& aDisplayInfo);
22 : virtual void NotifyVSync() override;
23 : void SetSensorState(const VRHMDSensorState& aSensorState);
24 : void ZeroSensor() override;
25 :
26 : protected:
27 : virtual VRHMDSensorState GetSensorState() override;
28 : virtual void StartPresentation() override;
29 : virtual void StopPresentation() override;
30 : #if defined(XP_WIN)
31 : virtual bool SubmitFrame(mozilla::layers::TextureSourceD3D11* aSource,
32 : const IntSize& aSize,
33 : const gfx::Rect& aLeftEyeRect,
34 : const gfx::Rect& aRightEyeRect) override;
35 : #else
36 : virtual bool SubmitFrame(mozilla::layers::TextureSourceOGL* aSource,
37 : const IntSize& aSize,
38 : const gfx::Rect& aLeftEyeRect,
39 : const gfx::Rect& aRightEyeRect);
40 : #endif // XP_WIN
41 :
42 : public:
43 : explicit VRDisplayPuppet();
44 :
45 : protected:
46 : virtual ~VRDisplayPuppet();
47 : void Destroy();
48 :
49 : bool mIsPresenting;
50 :
51 : private:
52 : #if defined(XP_WIN)
53 : bool UpdateConstantBuffers();
54 :
55 : RefPtr<ID3D11Device> mDevice;
56 : RefPtr<ID3D11DeviceContext> mContext;
57 : ID3D11VertexShader* mQuadVS;
58 : ID3D11PixelShader* mQuadPS;
59 : RefPtr<ID3D11SamplerState> mLinearSamplerState;
60 : layers::VertexShaderConstants mVSConstants;
61 : layers::PixelShaderConstants mPSConstants;
62 : RefPtr<ID3D11Buffer> mVSConstantBuffer;
63 : RefPtr<ID3D11Buffer> mPSConstantBuffer;
64 : RefPtr<ID3D11Buffer> mVertexBuffer;
65 : RefPtr<ID3D11InputLayout> mInputLayout;
66 : #endif
67 :
68 : VRHMDSensorState mSensorState;
69 : };
70 :
71 : class VRControllerPuppet : public VRControllerHost
72 : {
73 : public:
74 : explicit VRControllerPuppet(dom::GamepadHand aHand);
75 : void SetButtonPressState(uint32_t aButton, bool aPressed);
76 : uint64_t GetButtonPressState();
77 : void SetButtonTouchState(uint32_t aButton, bool aTouched);
78 : uint64_t GetButtonTouchState();
79 : void SetAxisMoveState(uint32_t aAxis, double aValue);
80 : double GetAxisMoveState(uint32_t aAxis);
81 : void SetPoseMoveState(const dom::GamepadPoseState& aPose);
82 : const dom::GamepadPoseState& GetPoseMoveState();
83 : float GetAxisMove(uint32_t aAxis);
84 : void SetAxisMove(uint32_t aAxis, float aValue);
85 :
86 : protected:
87 : virtual ~VRControllerPuppet();
88 :
89 : private:
90 : uint64_t mButtonPressState;
91 : uint64_t mButtonTouchState;
92 : float mAxisMoveState[3];
93 : float mAxisMove[3];
94 : dom::GamepadPoseState mPoseState;
95 : };
96 :
97 : } // namespace impl
98 :
99 0 : class VRSystemManagerPuppet : public VRSystemManager
100 : {
101 : public:
102 : static already_AddRefed<VRSystemManagerPuppet> Create();
103 :
104 : virtual void Destroy() override;
105 : virtual void Shutdown() override;
106 : virtual bool GetHMDs(nsTArray<RefPtr<VRDisplayHost>>& aHMDResult) override;
107 : virtual bool GetIsPresenting() override;
108 : virtual void HandleInput() override;
109 : virtual void GetControllers(nsTArray<RefPtr<VRControllerHost>>&
110 : aControllerResult) override;
111 : virtual void ScanForControllers() override;
112 : virtual void RemoveControllers() override;
113 : virtual void VibrateHaptic(uint32_t aControllerIdx,
114 : uint32_t aHapticIndex,
115 : double aIntensity,
116 : double aDuration,
117 : uint32_t aPromiseID) override;
118 : virtual void StopVibrateHaptic(uint32_t aControllerIdx) override;
119 :
120 : protected:
121 : VRSystemManagerPuppet();
122 :
123 : private:
124 : void HandleButtonPress(uint32_t aControllerIdx,
125 : uint32_t aButton,
126 : uint64_t aButtonMask,
127 : uint64_t aButtonPressed,
128 : uint64_t aButtonTouched);
129 : void HandleAxisMove(uint32_t aControllerIndex, uint32_t aAxis,
130 : float aValue);
131 : void HandlePoseTracking(uint32_t aControllerIndex,
132 : const dom::GamepadPoseState& aPose,
133 : VRControllerHost* aController);
134 :
135 : // there can only be one
136 : RefPtr<impl::VRDisplayPuppet> mPuppetHMD;
137 : nsTArray<RefPtr<impl::VRControllerPuppet>> mPuppetController;
138 : };
139 :
140 : } // namespace gfx
141 : } // namespace mozilla
142 :
143 : #endif /* GFX_VR_PUPPET_H*/
|