/src/mozilla-central/gfx/vr/gfxVROSVR.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef GFX_VR_OSVR_H |
8 | | #define GFX_VR_OSVR_H |
9 | | |
10 | | #include "nsTArray.h" |
11 | | #include "mozilla/RefPtr.h" |
12 | | #include "nsThreadUtils.h" |
13 | | |
14 | | #include "mozilla/gfx/2D.h" |
15 | | #include "mozilla/EnumeratedArray.h" |
16 | | |
17 | | #include "VRDisplayLocal.h" |
18 | | |
19 | | #include <osvr/ClientKit/ClientKitC.h> |
20 | | #include <osvr/ClientKit/DisplayC.h> |
21 | | |
22 | | #if defined(XP_MACOSX) |
23 | | class MacIOSurface; |
24 | | #endif |
25 | | namespace mozilla { |
26 | | namespace gfx { |
27 | | namespace impl { |
28 | | |
29 | | class VRDisplayOSVR : public VRDisplayLocal |
30 | | { |
31 | | public: |
32 | | void ZeroSensor() override; |
33 | | |
34 | | protected: |
35 | | VRHMDSensorState GetSensorState() override; |
36 | | virtual void StartPresentation() override; |
37 | | virtual void StopPresentation() override; |
38 | | |
39 | | #if defined(XP_WIN) |
40 | | virtual bool SubmitFrame(ID3D11Texture2D* aSource, |
41 | | const IntSize& aSize, |
42 | | const gfx::Rect& aLeftEyeRect, |
43 | | const gfx::Rect& aRightEyeRect) override; |
44 | | #elif defined(XP_MACOSX) |
45 | | virtual bool SubmitFrame(MacIOSurface* aMacIOSurface, |
46 | | const IntSize& aSize, |
47 | | const gfx::Rect& aLeftEyeRect, |
48 | | const gfx::Rect& aRightEyeRect) override; |
49 | | #endif |
50 | | |
51 | | public: |
52 | | explicit VRDisplayOSVR(OSVR_ClientContext* context, |
53 | | OSVR_ClientInterface* iface, |
54 | | OSVR_DisplayConfig* display); |
55 | | |
56 | | protected: |
57 | | virtual ~VRDisplayOSVR() |
58 | 0 | { |
59 | 0 | Destroy(); |
60 | 0 | MOZ_COUNT_DTOR_INHERITED(VRDisplayOSVR, VRDisplayLocal); |
61 | 0 | } |
62 | | void Destroy(); |
63 | | |
64 | | OSVR_ClientContext* m_ctx; |
65 | | OSVR_ClientInterface* m_iface; |
66 | | OSVR_DisplayConfig* m_display; |
67 | | |
68 | | gfx::Matrix4x4 mHeadToEye[2]; |
69 | | }; |
70 | | |
71 | | } // namespace impl |
72 | | |
73 | | class VRSystemManagerOSVR : public VRSystemManager |
74 | | { |
75 | | public: |
76 | | static already_AddRefed<VRSystemManagerOSVR> Create(); |
77 | | virtual void Destroy() override; |
78 | | virtual void Shutdown() override; |
79 | | virtual void NotifyVSync() override; |
80 | | virtual void Enumerate() override; |
81 | | virtual bool ShouldInhibitEnumeration() override; |
82 | | virtual void GetHMDs(nsTArray<RefPtr<VRDisplayHost>>& aHMDResult) override; |
83 | | virtual bool GetIsPresenting() override; |
84 | | virtual void HandleInput() override; |
85 | | virtual void GetControllers(nsTArray<RefPtr<VRControllerHost>>& |
86 | | aControllerResult) override; |
87 | | virtual void ScanForControllers() override; |
88 | | virtual void RemoveControllers() override; |
89 | | virtual void VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex, |
90 | | double aIntensity, double aDuration, |
91 | | const VRManagerPromise& aPromise) override; |
92 | | virtual void StopVibrateHaptic(uint32_t aControllerIdx) override; |
93 | | |
94 | | protected: |
95 | | VRSystemManagerOSVR() |
96 | | : mOSVRInitialized(false) |
97 | | , mClientContextInitialized(false) |
98 | | , mDisplayConfigInitialized(false) |
99 | | , mInterfaceInitialized(false) |
100 | | , m_ctx(nullptr) |
101 | | , m_iface(nullptr) |
102 | | , m_display(nullptr) |
103 | 0 | { |
104 | 0 | } |
105 | | |
106 | | bool Init(); |
107 | | |
108 | | RefPtr<impl::VRDisplayOSVR> mHMDInfo; |
109 | | bool mOSVRInitialized; |
110 | | bool mClientContextInitialized; |
111 | | bool mDisplayConfigInitialized; |
112 | | bool mInterfaceInitialized; |
113 | | RefPtr<nsIThread> mOSVRThread; |
114 | | |
115 | | OSVR_ClientContext m_ctx; |
116 | | OSVR_ClientInterface m_iface; |
117 | | OSVR_DisplayConfig m_display; |
118 | | |
119 | | private: |
120 | | // check if all components are initialized |
121 | | // and if not, it will try to initialize them |
122 | | void CheckOSVRStatus(); |
123 | | void InitializeClientContext(); |
124 | | void InitializeDisplay(); |
125 | | void InitializeInterface(); |
126 | | }; |
127 | | |
128 | | } // namespace gfx |
129 | | } // namespace mozilla |
130 | | |
131 | | #endif /* GFX_VR_OSVR_H */ |