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_DISPLAY_HOST_H
7 : #define GFX_VR_DISPLAY_HOST_H
8 :
9 : #include "gfxVR.h"
10 : #include "nsTArray.h"
11 : #include "nsString.h"
12 : #include "nsCOMPtr.h"
13 : #include "mozilla/RefPtr.h"
14 : #include "mozilla/gfx/2D.h"
15 : #include "mozilla/Atomics.h"
16 : #include "mozilla/EnumeratedArray.h"
17 : #include "mozilla/TimeStamp.h"
18 : #include "mozilla/TypedEnumBits.h"
19 : #include "mozilla/dom/GamepadPoseState.h"
20 :
21 : namespace mozilla {
22 : namespace layers {
23 : class PTextureParent;
24 : #if defined(XP_WIN)
25 : class TextureSourceD3D11;
26 : #endif
27 : } // namespace layers
28 : namespace gfx {
29 : class VRLayerParent;
30 :
31 : class VRDisplayHost {
32 : public:
33 0 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRDisplayHost)
34 :
35 0 : const VRDisplayInfo& GetDisplayInfo() const { return mDisplayInfo; }
36 :
37 : void AddLayer(VRLayerParent* aLayer);
38 : void RemoveLayer(VRLayerParent* aLayer);
39 :
40 : virtual void ZeroSensor() = 0;
41 : virtual void StartPresentation() = 0;
42 : virtual void StopPresentation() = 0;
43 : virtual void NotifyVSync();
44 :
45 : void StartFrame();
46 : void SubmitFrame(VRLayerParent* aLayer,
47 : mozilla::layers::PTextureParent* aTexture,
48 : const gfx::Rect& aLeftEyeRect,
49 : const gfx::Rect& aRightEyeRect);
50 :
51 : bool CheckClearDisplayInfoDirty();
52 : void SetGroupMask(uint32_t aGroupMask);
53 : bool GetIsConnected();
54 :
55 : protected:
56 : explicit VRDisplayHost(VRDeviceType aType);
57 : virtual ~VRDisplayHost();
58 :
59 : #if defined(XP_WIN)
60 : // Subclasses should override this SubmitFrame function.
61 : // Returns true if the SubmitFrame call will block as necessary
62 : // to control timing of the next frame and throttle the render loop
63 : // for the needed framerate.
64 : virtual bool SubmitFrame(mozilla::layers::TextureSourceD3D11* aSource,
65 : const IntSize& aSize,
66 : const gfx::Rect& aLeftEyeRect,
67 : const gfx::Rect& aRightEyeRect) = 0;
68 : #endif
69 :
70 : VRDisplayInfo mDisplayInfo;
71 :
72 : nsTArray<RefPtr<VRLayerParent>> mLayers;
73 : // Weak reference to mLayers entries are cleared in
74 : // VRLayerParent destructor
75 :
76 : protected:
77 : virtual VRHMDSensorState GetSensorState() = 0;
78 :
79 : private:
80 : VRDisplayInfo mLastUpdateDisplayInfo;
81 : TimeStamp mLastFrameStart;
82 : };
83 :
84 : class VRControllerHost {
85 : public:
86 0 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRControllerHost)
87 :
88 : const VRControllerInfo& GetControllerInfo() const;
89 : void SetButtonPressed(uint64_t aBit);
90 : uint64_t GetButtonPressed();
91 : void SetButtonTouched(uint64_t aBit);
92 : uint64_t GetButtonTouched();
93 : void SetPose(const dom::GamepadPoseState& aPose);
94 : const dom::GamepadPoseState& GetPose();
95 : dom::GamepadHand GetHand();
96 : void SetVibrateIndex(uint64_t aIndex);
97 : uint64_t GetVibrateIndex();
98 :
99 : protected:
100 : explicit VRControllerHost(VRDeviceType aType);
101 : virtual ~VRControllerHost();
102 :
103 : VRControllerInfo mControllerInfo;
104 : // The current button pressed bit of button mask.
105 : uint64_t mButtonPressed;
106 : // The current button touched bit of button mask.
107 : uint64_t mButtonTouched;
108 : uint64_t mVibrateIndex;
109 : dom::GamepadPoseState mPose;
110 : };
111 :
112 : } // namespace gfx
113 : } // namespace mozilla
114 :
115 : #endif /* GFX_VR_DISPLAY_HOST_H */
|