/src/mozilla-central/gfx/vr/ipc/VRManagerParent.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 MOZILLA_GFX_VR_VRMANAGERPARENT_H |
8 | | #define MOZILLA_GFX_VR_VRMANAGERPARENT_H |
9 | | |
10 | | #include "mozilla/layers/CompositableTransactionParent.h" // need? |
11 | | #include "mozilla/gfx/PVRManagerParent.h" // for PVRManagerParent |
12 | | #include "mozilla/gfx/PVRLayerParent.h" // for PVRLayerParent |
13 | | #include "mozilla/ipc/ProtocolUtils.h" // for IToplevelProtocol |
14 | | #include "mozilla/TimeStamp.h" // for TimeStamp |
15 | | #include "gfxVR.h" // for VRFieldOfView |
16 | | #include "VRThread.h" // for VRListenerThreadHolder |
17 | | |
18 | | namespace mozilla { |
19 | | using namespace layers; |
20 | | namespace gfx { |
21 | | |
22 | | class VRManager; |
23 | | |
24 | | namespace impl { |
25 | | class VRDisplayPuppet; |
26 | | class VRControllerPuppet; |
27 | | } // namespace impl |
28 | | |
29 | | class VRManagerParent final : public PVRManagerParent |
30 | | { |
31 | | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRManagerParent); |
32 | | public: |
33 | | explicit VRManagerParent(ProcessId aChildProcessId, bool aIsContentChild); |
34 | | |
35 | | static VRManagerParent* CreateSameProcess(); |
36 | | static bool CreateForGPUProcess(Endpoint<PVRManagerParent>&& aEndpoint); |
37 | | static bool CreateForContent(Endpoint<PVRManagerParent>&& aEndpoint); |
38 | | |
39 | | bool IsSameProcess() const; |
40 | | bool HaveEventListener(); |
41 | | bool HaveControllerListener(); |
42 | | bool SendGamepadUpdate(const GamepadChangeEvent& aGamepadEvent); |
43 | | bool SendReplyGamepadVibrateHaptic(const uint32_t& aPromiseID); |
44 | | |
45 | | protected: |
46 | | ~VRManagerParent(); |
47 | | |
48 | | virtual PVRLayerParent* AllocPVRLayerParent(const uint32_t& aDisplayID, |
49 | | const uint32_t& aGroup) override; |
50 | | virtual bool DeallocPVRLayerParent(PVRLayerParent* actor) override; |
51 | | |
52 | | virtual void ActorDestroy(ActorDestroyReason why) override; |
53 | | void OnChannelConnected(int32_t pid) override; |
54 | | |
55 | | virtual mozilla::ipc::IPCResult RecvRefreshDisplays() override; |
56 | | virtual mozilla::ipc::IPCResult RecvResetSensor(const uint32_t& aDisplayID) override; |
57 | | virtual mozilla::ipc::IPCResult RecvSetGroupMask(const uint32_t& aDisplayID, const uint32_t& aGroupMask) override; |
58 | | virtual mozilla::ipc::IPCResult RecvSetHaveEventListener(const bool& aHaveEventListener) override; |
59 | | virtual mozilla::ipc::IPCResult RecvControllerListenerAdded() override; |
60 | | virtual mozilla::ipc::IPCResult RecvControllerListenerRemoved() override; |
61 | | virtual mozilla::ipc::IPCResult RecvVibrateHaptic(const uint32_t& aControllerIdx, const uint32_t& aHapticIndex, |
62 | | const double& aIntensity, const double& aDuration, const uint32_t& aPromiseID) override; |
63 | | virtual mozilla::ipc::IPCResult RecvStopVibrateHaptic(const uint32_t& aControllerIdx) override; |
64 | | virtual mozilla::ipc::IPCResult RecvCreateVRTestSystem() override; |
65 | | virtual mozilla::ipc::IPCResult RecvCreateVRServiceTestDisplay(const nsCString& aID, const uint32_t& aPromiseID) override; |
66 | | virtual mozilla::ipc::IPCResult RecvCreateVRServiceTestController(const nsCString& aID, const uint32_t& aPromiseID) override; |
67 | | virtual mozilla::ipc::IPCResult RecvSetDisplayInfoToMockDisplay(const uint32_t& aDeviceID, |
68 | | const VRDisplayInfo& aDisplayInfo) override; |
69 | | virtual mozilla::ipc::IPCResult RecvSetSensorStateToMockDisplay(const uint32_t& aDeviceID, |
70 | | const VRHMDSensorState& aSensorState) override; |
71 | | virtual mozilla::ipc::IPCResult RecvNewButtonEventToMockController(const uint32_t& aDeviceID, const long& aButton, |
72 | | const bool& aPressed) override; |
73 | | virtual mozilla::ipc::IPCResult RecvNewAxisMoveEventToMockController(const uint32_t& aDeviceID, const long& aAxis, |
74 | | const double& aValue) override; |
75 | | virtual mozilla::ipc::IPCResult RecvNewPoseMoveToMockController(const uint32_t& aDeviceID, const GamepadPoseState& pose) override; |
76 | | virtual mozilla::ipc::IPCResult RecvStartVRNavigation(const uint32_t& aDeviceID) override; |
77 | | virtual mozilla::ipc::IPCResult RecvStopVRNavigation(const uint32_t& aDeviceID, const TimeDuration& aTimeout) override; |
78 | | private: |
79 | | void RegisterWithManager(); |
80 | | void UnregisterFromManager(); |
81 | | |
82 | | void Bind(Endpoint<PVRManagerParent>&& aEndpoint); |
83 | | |
84 | | static void RegisterVRManagerInVRListenerThread(VRManagerParent* aVRManager); |
85 | | |
86 | | void DeferredDestroy(); |
87 | | already_AddRefed<impl::VRControllerPuppet> GetControllerPuppet(uint32_t aDeviceID); |
88 | | |
89 | | // This keeps us alive until ActorDestroy(), at which point we do a |
90 | | // deferred destruction of ourselves. |
91 | | RefPtr<VRManagerParent> mSelfRef; |
92 | | RefPtr<VRListenerThreadHolder> mVRListenerThreadHolder; |
93 | | |
94 | | // Keep the VRManager alive, until we have destroyed ourselves. |
95 | | RefPtr<VRManager> mVRManagerHolder; |
96 | | nsRefPtrHashtable<nsUint32HashKey, impl::VRControllerPuppet> mVRControllerTests; |
97 | | uint32_t mControllerTestID; |
98 | | bool mHaveEventListener; |
99 | | bool mHaveControllerListener; |
100 | | bool mIsContentChild; |
101 | | }; |
102 | | |
103 | | class VRManagerPromise final |
104 | | { |
105 | | friend class VRManager; |
106 | | |
107 | | public: |
108 | | explicit VRManagerPromise(RefPtr<VRManagerParent> aParent, uint32_t aPromiseID) |
109 | | : mParent(aParent), mPromiseID(aPromiseID) |
110 | 0 | {} |
111 | | ~VRManagerPromise() { |
112 | | mParent = nullptr; |
113 | | } |
114 | | |
115 | | private: |
116 | | RefPtr<VRManagerParent> mParent; |
117 | | uint32_t mPromiseID; |
118 | | }; |
119 | | |
120 | | } // namespace mozilla |
121 | | } // namespace gfx |
122 | | |
123 | | #endif // MOZILLA_GFX_VR_VRMANAGERPARENT_H |