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 file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_VRServiceTest_h_ 8 #define mozilla_dom_VRServiceTest_h_ 9 10 #include "mozilla/DOMEventTargetHelper.h" 11 #include "mozilla/dom/VRServiceTestBinding.h" 12 13 #include "gfxVR.h" 14 15 namespace mozilla { 16 namespace dom { 17 18 class VRMockDisplay final : public DOMEventTargetHelper { 19 public: 20 NS_DECL_ISUPPORTS_INHERITED 21 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(VRMockDisplay, DOMEventTargetHelper) 22 23 VRMockDisplay(const nsCString& aID, uint32_t aDeviceID); 24 void SetEyeParameter(VREye aEye, double aOffsetX, double aOffsetY, 25 double aOffsetZ, double aUpDegree, double aRightDegree, 26 double aDownDegree, double aLeftDegree); 27 void SetEyeResolution(unsigned long aRenderWidth, 28 unsigned long aRenderHeight); 29 void SetPose(const Nullable<Float32Array>& aPosition, 30 const Nullable<Float32Array>& aLinearVelocity, 31 const Nullable<Float32Array>& aLinearAcceleration, 32 const Nullable<Float32Array>& aOrientation, 33 const Nullable<Float32Array>& aAngularVelocity, 34 const Nullable<Float32Array>& aAngularAcceleration); SetMountState(bool aIsMounted)35 void SetMountState(bool aIsMounted) { mDisplayInfo.mIsMounted = aIsMounted; } 36 void Update(); 37 virtual JSObject* WrapObject(JSContext* aCx, 38 JS::Handle<JSObject*> aGivenProto) override; 39 40 private: 41 ~VRMockDisplay() = default; 42 43 uint32_t mDeviceID; 44 gfx::VRDisplayInfo mDisplayInfo; 45 gfx::VRHMDSensorState mSensorState; 46 TimeStamp mTimestamp; 47 }; 48 49 class VRMockController : public DOMEventTargetHelper { 50 public: 51 NS_DECL_ISUPPORTS_INHERITED 52 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(VRMockController, 53 DOMEventTargetHelper) 54 55 VRMockController(const nsCString& aID, uint32_t aDeviceID); 56 void NewButtonEvent(unsigned long aButton, bool aPressed); 57 void NewAxisMoveEvent(unsigned long aAxis, double aValue); 58 void NewPoseMove(const Nullable<Float32Array>& aPosition, 59 const Nullable<Float32Array>& aLinearVelocity, 60 const Nullable<Float32Array>& aLinearAcceleration, 61 const Nullable<Float32Array>& aOrientation, 62 const Nullable<Float32Array>& aAngularVelocity, 63 const Nullable<Float32Array>& aAngularAcceleration); 64 virtual JSObject* WrapObject(JSContext* aCx, 65 JS::Handle<JSObject*> aGivenProto) override; 66 67 private: 68 ~VRMockController() = default; 69 70 nsCString mID; 71 uint32_t mDeviceID; 72 }; 73 74 class VRServiceTest final : public DOMEventTargetHelper { 75 public: 76 NS_DECL_ISUPPORTS_INHERITED 77 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(VRServiceTest, DOMEventTargetHelper) 78 79 already_AddRefed<Promise> AttachVRDisplay(const nsAString& aID, 80 ErrorResult& aRv); 81 already_AddRefed<Promise> AttachVRController(const nsAString& aID, 82 ErrorResult& aRv); 83 void Shutdown(); 84 85 static already_AddRefed<VRServiceTest> CreateTestService( 86 nsPIDOMWindowInner* aWindow); 87 virtual JSObject* WrapObject(JSContext* aCx, 88 JS::Handle<JSObject*> aGivenProto) override; 89 90 private: 91 explicit VRServiceTest(nsPIDOMWindowInner* aWindow); 92 ~VRServiceTest() = default; 93 94 nsCOMPtr<nsPIDOMWindowInner> mWindow; 95 bool mShuttingDown; 96 }; 97 98 } // namespace dom 99 } // namespace mozilla 100 101 #endif // mozilla_dom_VRServiceTest_h_ 102