Bumping manifests a=b2g-bump
[gecko.git] / dom / vr / VRDevice.h
blobac1f8053501720c59bad6acd2a96635575ea57e0
1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
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 file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_VRDevice_h_
7 #define mozilla_dom_VRDevice_h_
9 #include <stdint.h>
11 #include "mozilla/ErrorResult.h"
12 #include "mozilla/dom/TypedArray.h"
13 #include "mozilla/dom/VRDeviceBinding.h"
14 #include "mozilla/dom/DOMPoint.h"
15 #include "mozilla/dom/DOMRect.h"
17 #include "nsCOMPtr.h"
18 #include "nsString.h"
19 #include "nsTArray.h"
20 #include "nsWrapperCache.h"
22 #include "gfxVR.h"
24 namespace mozilla {
25 namespace dom {
27 class Element;
29 class VRFieldOfViewReadOnly : public nsWrapperCache
31 public:
32 VRFieldOfViewReadOnly(nsISupports* aParent,
33 double aUpDegrees, double aRightDegrees,
34 double aDownDegrees, double aLeftDegrees)
35 : mParent(aParent)
36 , mUpDegrees(aUpDegrees)
37 , mRightDegrees(aRightDegrees)
38 , mDownDegrees(aDownDegrees)
39 , mLeftDegrees(aLeftDegrees)
43 double UpDegrees() const { return mUpDegrees; }
44 double RightDegrees() const { return mRightDegrees; }
45 double DownDegrees() const { return mDownDegrees; }
46 double LeftDegrees() const { return mLeftDegrees; }
48 protected:
49 nsCOMPtr<nsISupports> mParent;
50 double mUpDegrees;
51 double mRightDegrees;
52 double mDownDegrees;
53 double mLeftDegrees;
56 class VRFieldOfView MOZ_FINAL : public VRFieldOfViewReadOnly
58 ~VRFieldOfView() {}
59 public:
60 explicit VRFieldOfView(nsISupports* aParent,
61 double aUpDegrees = 0.0, double aRightDegrees = 0.0,
62 double aDownDegrees = 0.0, double aLeftDegrees = 0.0)
63 : VRFieldOfViewReadOnly(aParent, aUpDegrees, aRightDegrees, aDownDegrees, aLeftDegrees)
66 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VRFieldOfView)
67 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VRFieldOfView)
69 static already_AddRefed<VRFieldOfView>
70 Constructor(const GlobalObject& aGlobal, const VRFieldOfViewInit& aParams,
71 ErrorResult& aRv);
73 static already_AddRefed<VRFieldOfView>
74 Constructor(const GlobalObject& aGlobal,
75 double aUpDegrees, double aRightDegrees,
76 double aDownDegrees, double aLeftDegrees,
77 ErrorResult& aRv);
79 nsISupports* GetParentObject() const { return mParent; }
80 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
82 void SetUpDegrees(double aVal) { mUpDegrees = aVal; }
83 void SetRightDegrees(double aVal) { mRightDegrees = aVal; }
84 void SetDownDegrees(double aVal) { mDownDegrees = aVal; }
85 void SetLeftDegrees(double aVal) { mLeftDegrees = aVal; }
88 class VRPositionState MOZ_FINAL : public nsWrapperCache
90 ~VRPositionState() {}
91 public:
92 explicit VRPositionState(nsISupports* aParent, const gfx::VRHMDSensorState& aState);
94 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VRPositionState)
95 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VRPositionState)
97 double TimeStamp() const { return mTimeStamp; }
99 bool HasPosition() const { return mPosition != nullptr; }
100 DOMPoint* GetPosition() const { return mPosition; }
102 bool HasOrientation() const { return mOrientation != nullptr; }
103 DOMPoint* GetOrientation() const { return mOrientation; }
105 // these are created lazily
106 DOMPoint* GetLinearVelocity();
107 DOMPoint* GetLinearAcceleration();
108 DOMPoint* GetAngularVelocity();
109 DOMPoint* GetAngularAcceleration();
111 nsISupports* GetParentObject() const { return mParent; }
112 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
114 protected:
115 nsCOMPtr<nsISupports> mParent;
117 double mTimeStamp;
118 gfx::VRHMDSensorState mVRState;
120 nsRefPtr<DOMPoint> mPosition;
121 nsRefPtr<DOMPoint> mLinearVelocity;
122 nsRefPtr<DOMPoint> mLinearAcceleration;
124 nsRefPtr<DOMPoint> mOrientation;
125 nsRefPtr<DOMPoint> mAngularVelocity;
126 nsRefPtr<DOMPoint> mAngularAcceleration;
129 class VRDevice : public nsISupports,
130 public nsWrapperCache
132 public:
133 // create new VRDevice objects for all known underlying gfx::vr devices
134 static bool CreateAllKnownVRDevices(nsISupports *aParent, nsTArray<nsRefPtr<VRDevice>>& aDevices);
136 public:
137 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
138 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(VRDevice)
140 void GetHardwareUnitId(nsAString& aHWID) const { aHWID = mHWID; }
141 void GetDeviceId(nsAString& aDeviceId) const { aDeviceId = mDeviceId; }
142 void GetDeviceName(nsAString& aDeviceName) const { aDeviceName = mDeviceName; }
144 bool IsValid() { return mValid; }
146 virtual void Shutdown() { }
148 nsISupports* GetParentObject() const
150 return mParent;
153 enum VRDeviceType {
154 HMD,
155 PositionSensor
158 VRDeviceType GetType() const { return mType; }
160 protected:
161 VRDevice(nsISupports* aParent, VRDeviceType aType)
162 : mParent(aParent)
163 , mType(aType)
164 , mValid(false)
166 mHWID.AssignLiteral("uknown");
167 mDeviceId.AssignLiteral("unknown");
168 mDeviceName.AssignLiteral("unknown");
171 virtual ~VRDevice() {
172 Shutdown();
175 nsCOMPtr<nsISupports> mParent;
176 nsString mHWID;
177 nsString mDeviceId;
178 nsString mDeviceName;
180 VRDeviceType mType;
182 bool mValid;
185 class HMDVRDevice : public VRDevice
187 public:
188 virtual already_AddRefed<DOMPoint> GetEyeTranslation(VREye aEye) = 0;
190 virtual void SetFieldOfView(const VRFieldOfViewInit& aLeftFOV,
191 const VRFieldOfViewInit& aRightFOV,
192 double zNear, double zFar) = 0;
193 virtual already_AddRefed<VRFieldOfView> GetCurrentEyeFieldOfView(VREye aEye) = 0;
194 virtual already_AddRefed<VRFieldOfView> GetRecommendedEyeFieldOfView(VREye aEye) = 0;
195 virtual already_AddRefed<VRFieldOfView> GetMaximumEyeFieldOfView(VREye aEye) = 0;
196 virtual already_AddRefed<DOMRect> GetRecommendedEyeRenderRect(VREye aEye) = 0;
198 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
200 void XxxToggleElementVR(Element& aElement);
202 gfx::VRHMDInfo *GetHMD() { return mHMD.get(); }
204 protected:
205 HMDVRDevice(nsISupports* aParent, gfx::VRHMDInfo* aHMD)
206 : VRDevice(aParent, VRDevice::HMD)
207 , mHMD(aHMD)
210 virtual ~HMDVRDevice() { }
212 nsRefPtr<gfx::VRHMDInfo> mHMD;
215 class PositionSensorVRDevice : public VRDevice
217 public:
218 virtual already_AddRefed<VRPositionState> GetState(double timeOffset) = 0;
220 virtual void ZeroSensor() = 0;
222 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
224 protected:
225 explicit PositionSensorVRDevice(nsISupports* aParent)
226 : VRDevice(aParent, VRDevice::PositionSensor)
229 virtual ~PositionSensorVRDevice() { }
232 } // namespace dom
233 } // namespace mozilla
235 #endif