Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/vr/VRDisplayHost.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_DISPLAY_HOST_H
8
#define GFX_VR_DISPLAY_HOST_H
9
10
#include "gfxVR.h"
11
#include "nsTArray.h"
12
#include "nsString.h"
13
#include "nsCOMPtr.h"
14
#include "mozilla/RefPtr.h"
15
#include "mozilla/gfx/2D.h"
16
#include "mozilla/Atomics.h"
17
#include "mozilla/EnumeratedArray.h"
18
#include "mozilla/TimeStamp.h"
19
#include "mozilla/TypedEnumBits.h"
20
#include "mozilla/dom/GamepadPoseState.h"
21
#include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
22
23
#if defined(XP_WIN)
24
#include <d3d11_1.h>
25
#elif defined(XP_MACOSX)
26
class MacIOSurface;
27
#endif
28
namespace mozilla {
29
namespace gfx {
30
class VRThread;
31
class VRLayerParent;
32
33
class VRDisplayHost {
34
public:
35
  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRDisplayHost)
36
37
0
  const VRDisplayInfo& GetDisplayInfo() const { return mDisplayInfo; }
38
39
  void AddLayer(VRLayerParent* aLayer);
40
  void RemoveLayer(VRLayerParent* aLayer);
41
42
  virtual void ZeroSensor() = 0;
43
  virtual void StartPresentation() = 0;
44
  virtual void StopPresentation() = 0;
45
  virtual void StartVRNavigation();
46
  virtual void StopVRNavigation(const TimeDuration& aTimeout);
47
  void NotifyVSync();
48
49
  void StartFrame();
50
  void SubmitFrame(VRLayerParent* aLayer,
51
                   const layers::SurfaceDescriptor& aTexture,
52
                   uint64_t aFrameId,
53
                   const gfx::Rect& aLeftEyeRect,
54
                   const gfx::Rect& aRightEyeRect);
55
56
  bool CheckClearDisplayInfoDirty();
57
  void SetGroupMask(uint32_t aGroupMask);
58
  bool GetIsConnected();
59
60
  class AutoRestoreRenderState {
61
  public:
62
    explicit AutoRestoreRenderState(VRDisplayHost* aDisplay);
63
    ~AutoRestoreRenderState();
64
    bool IsSuccess();
65
  private:
66
    RefPtr<VRDisplayHost> mDisplay;
67
#if defined(XP_WIN)
68
    RefPtr<ID3DDeviceContextState> mPrevDeviceContextState;
69
#endif
70
    bool mSuccess;
71
  };
72
73
protected:
74
  explicit VRDisplayHost(VRDeviceType aType);
75
  virtual ~VRDisplayHost();
76
77
  // This SubmitFrame() must be overridden by children and block until
78
  // the next frame is ready to start and the resources in aTexture can
79
  // safely be released.
80
  virtual bool SubmitFrame(const layers::SurfaceDescriptor& aTexture,
81
                           uint64_t aFrameId,
82
                           const gfx::Rect& aLeftEyeRect,
83
                           const gfx::Rect& aRightEyeRect) = 0;
84
85
  VRDisplayInfo mDisplayInfo;
86
87
  nsTArray<VRLayerParent *> mLayers;
88
  // Weak reference to mLayers entries are cleared in
89
  // VRLayerParent destructor
90
91
protected:
92
  virtual VRHMDSensorState GetSensorState() = 0;
93
94
  RefPtr<VRThread> mSubmitThread;
95
private:
96
  void SubmitFrameInternal(const layers::SurfaceDescriptor& aTexture,
97
                           uint64_t aFrameId,
98
                           const gfx::Rect& aLeftEyeRect,
99
                           const gfx::Rect& aRightEyeRect);
100
101
  VRDisplayInfo mLastUpdateDisplayInfo;
102
  TimeStamp mLastFrameStart;
103
  bool mFrameStarted;
104
#if defined(MOZ_WIDGET_ANDROID)
105
protected:
106
  uint64_t mLastSubmittedFrameId;
107
  uint64_t mLastStartedFrame;
108
#endif // defined(MOZ_WIDGET_ANDROID)
109
110
#if defined(XP_WIN)
111
protected:
112
  bool CreateD3DObjects();
113
  RefPtr<ID3D11Device1> mDevice;
114
  RefPtr<ID3D11DeviceContext1> mContext;
115
  ID3D11Device1* GetD3DDevice();
116
  ID3D11DeviceContext1* GetD3DDeviceContext();
117
  ID3DDeviceContextState* GetD3DDeviceContextState();
118
119
private:
120
  RefPtr<ID3DDeviceContextState> mDeviceContextState;
121
#endif
122
};
123
124
class VRControllerHost {
125
public:
126
  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRControllerHost)
127
128
  const VRControllerInfo& GetControllerInfo() const;
129
  void SetButtonPressed(uint64_t aBit);
130
  uint64_t GetButtonPressed();
131
  void SetButtonTouched(uint64_t aBit);
132
  uint64_t GetButtonTouched();
133
  void SetPose(const dom::GamepadPoseState& aPose);
134
  const dom::GamepadPoseState& GetPose();
135
  dom::GamepadHand GetHand();
136
  void SetVibrateIndex(uint64_t aIndex);
137
  uint64_t GetVibrateIndex();
138
139
protected:
140
  explicit VRControllerHost(VRDeviceType aType, dom::GamepadHand aHand,
141
                            uint32_t aDisplayID);
142
  virtual ~VRControllerHost();
143
144
  VRControllerInfo mControllerInfo;
145
  uint64_t mVibrateIndex;
146
  dom::GamepadPoseState mPose;
147
};
148
149
} // namespace gfx
150
} // namespace mozilla
151
152
#endif /* GFX_VR_DISPLAY_HOST_H */