VRManagerParent.h (4568B)
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/dom/ipc/IdType.h" 11 #include "mozilla/layers/CompositorThread.h" // for CompositorThreadHolder 12 #include "mozilla/layers/CompositableTransactionParent.h" // need? 13 #include "mozilla/gfx/PVRManagerParent.h" // for PVRManagerParent 14 #include "mozilla/gfx/PVRLayerParent.h" // for PVRLayerParent 15 #include "mozilla/ipc/ProtocolUtils.h" // for IToplevelProtocol 16 #include "mozilla/TimeStamp.h" // for TimeStamp 17 #include "gfxVR.h" // for VRFieldOfView 18 19 namespace mozilla { 20 using namespace layers; 21 namespace gfx { 22 23 class VRManager; 24 25 class VRManagerParent final : public PVRManagerParent { 26 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRManagerParent, final); 27 28 friend class PVRManagerParent; 29 30 public: 31 explicit VRManagerParent(ipc::EndpointProcInfo aChildProcess, 32 dom::ContentParentId aChildId, bool aIsContentChild); 33 34 static already_AddRefed<VRManagerParent> CreateSameProcess(); 35 static bool CreateForGPUProcess(Endpoint<PVRManagerParent>&& aEndpoint); 36 static bool CreateForContent(Endpoint<PVRManagerParent>&& aEndpoint, 37 dom::ContentParentId aChildId); 38 static void Shutdown(); 39 40 bool IsSameProcess() const; 41 bool HaveEventListener(); 42 bool HaveControllerListener(); 43 bool GetVRActiveStatus(); 44 bool SendReplyGamepadVibrateHaptic(const uint32_t& aPromiseID); 45 46 protected: 47 ~VRManagerParent(); 48 49 PVRLayerParent* AllocPVRLayerParent(const uint32_t& aDisplayID, 50 const uint32_t& aGroup); 51 bool DeallocPVRLayerParent(PVRLayerParent* actor); 52 53 virtual void ActorDestroy(ActorDestroyReason why) override; 54 55 mozilla::ipc::IPCResult RecvDetectRuntimes(); 56 mozilla::ipc::IPCResult RecvRefreshDisplays(); 57 mozilla::ipc::IPCResult RecvSetGroupMask(const uint32_t& aDisplayID, 58 const uint32_t& aGroupMask); 59 mozilla::ipc::IPCResult RecvSetHaveEventListener( 60 const bool& aHaveEventListener); 61 mozilla::ipc::IPCResult RecvControllerListenerAdded(); 62 mozilla::ipc::IPCResult RecvControllerListenerRemoved(); 63 mozilla::ipc::IPCResult RecvVibrateHaptic( 64 const mozilla::dom::GamepadHandle& aGamepadHandle, 65 const uint32_t& aHapticIndex, const double& aIntensity, 66 const double& aDuration, const uint32_t& aPromiseID); 67 mozilla::ipc::IPCResult RecvStopVibrateHaptic( 68 const mozilla::dom::GamepadHandle& aGamepadHandle); 69 mozilla::ipc::IPCResult RecvStartVRNavigation(const uint32_t& aDeviceID); 70 mozilla::ipc::IPCResult RecvStopVRNavigation(const uint32_t& aDeviceID, 71 const TimeDuration& aTimeout); 72 mozilla::ipc::IPCResult RecvStartActivity(); 73 mozilla::ipc::IPCResult RecvStopActivity(); 74 75 mozilla::ipc::IPCResult RecvRunPuppet(const nsTArray<uint64_t>& aBuffer); 76 mozilla::ipc::IPCResult RecvResetPuppet(); 77 78 private: 79 void RegisterWithManager(); 80 void UnregisterFromManager(); 81 82 void Bind(Endpoint<PVRManagerParent>&& aEndpoint); 83 84 static void RegisterVRManagerInCompositorThread(VRManagerParent* aVRManager); 85 86 // Keep the compositor thread alive, until we have destroyed ourselves. 87 RefPtr<CompositorThreadHolder> mCompositorThreadHolder; 88 89 // Keep the VRManager alive, until we have destroyed ourselves. 90 RefPtr<VRManager> mVRManagerHolder; 91 dom::ContentParentId mChildId; 92 bool mHaveEventListener; 93 bool mHaveControllerListener; 94 bool mIsContentChild; 95 96 // When VR tabs are switched the background, we won't need to 97 // initialize its session in VRService thread. 98 bool mVRActiveStatus; 99 }; 100 101 class VRManagerPromise final { 102 friend class VRManager; 103 104 public: 105 explicit VRManagerPromise(RefPtr<VRManagerParent> aParent, 106 uint32_t aPromiseID) 107 : mParent(aParent), mPromiseID(aPromiseID) {} 108 ~VRManagerPromise() { mParent = nullptr; } 109 bool operator==(const VRManagerPromise& aOther) const { 110 return mParent == aOther.mParent && mPromiseID == aOther.mPromiseID; 111 } 112 113 private: 114 RefPtr<VRManagerParent> mParent; 115 uint32_t mPromiseID; 116 }; 117 118 } // namespace gfx 119 } // namespace mozilla 120 121 #endif // MOZILLA_GFX_VR_VRMANAGERPARENT_H