Line data Source code
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 : {
20 : public:
21 : NS_DECL_ISUPPORTS_INHERITED
22 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(VRMockDisplay, DOMEventTargetHelper)
23 :
24 : VRMockDisplay(const nsCString& aID, uint32_t aDeviceID);
25 : void SetEyeParameter(VREye aEye, double aOffsetX, double aOffsetY, double aOffsetZ,
26 : double aUpDegree, double aRightDegree,
27 : double aDownDegree, double aLeftDegree);
28 : void SetEyeResolution(unsigned long aRenderWidth, unsigned long aRenderHeight);
29 : void SetPose(const Nullable<Float32Array>& aPosition, const Nullable<Float32Array>& aLinearVelocity,
30 : const Nullable<Float32Array>& aLinearAcceleration, const Nullable<Float32Array>& aOrientation,
31 : const Nullable<Float32Array>& aAngularVelocity, const Nullable<Float32Array>& aAngularAcceleration);
32 0 : void SetMountState(bool aIsMounted) { mDisplayInfo.mIsMounted = aIsMounted; }
33 : void Update();
34 : virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
35 :
36 : private:
37 0 : ~VRMockDisplay() = default;
38 :
39 : uint32_t mDeviceID;
40 : gfx::VRDisplayInfo mDisplayInfo;
41 : gfx::VRHMDSensorState mSensorState;
42 : TimeStamp mTimestamp;
43 : };
44 :
45 : class VRMockController : public DOMEventTargetHelper
46 : {
47 : public:
48 : NS_DECL_ISUPPORTS_INHERITED
49 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(VRMockController, DOMEventTargetHelper)
50 :
51 : VRMockController(const nsCString& aID, uint32_t aDeviceID);
52 : void NewButtonEvent(unsigned long aButton, bool aPressed);
53 : void NewAxisMoveEvent(unsigned long aAxis, double aValue);
54 : void NewPoseMove(const Nullable<Float32Array>& aPosition, const Nullable<Float32Array>& aLinearVelocity,
55 : const Nullable<Float32Array>& aLinearAcceleration, const Nullable<Float32Array>& aOrientation,
56 : const Nullable<Float32Array>& aAngularVelocity, const Nullable<Float32Array>& aAngularAcceleration);
57 : virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
58 :
59 : private:
60 0 : ~VRMockController() = default;
61 :
62 : nsCString mID;
63 : uint32_t mDeviceID;
64 : };
65 :
66 : class VRServiceTest final : public DOMEventTargetHelper
67 : {
68 : public:
69 : NS_DECL_ISUPPORTS_INHERITED
70 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(VRServiceTest, DOMEventTargetHelper)
71 :
72 : already_AddRefed<Promise> AttachVRDisplay(const nsAString& aID, ErrorResult& aRv);
73 : already_AddRefed<Promise> AttachVRController(const nsAString& aID, ErrorResult& aRv);
74 : void Shutdown();
75 :
76 : static already_AddRefed<VRServiceTest> CreateTestService(nsPIDOMWindowInner* aWindow);
77 : virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
78 :
79 : private:
80 : explicit VRServiceTest(nsPIDOMWindowInner* aWindow);
81 : ~VRServiceTest();
82 :
83 : nsCOMPtr<nsPIDOMWindowInner> mWindow;
84 : bool mShuttingDown;
85 : };
86 :
87 : } // namespace dom
88 : } // namespace mozilla
89 :
90 : #endif // mozilla_dom_VRServiceTest_h_
|