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 GFX_VR_DISPLAY_CLIENT_H 8 #define GFX_VR_DISPLAY_CLIENT_H 9 10 #include "nsCOMPtr.h" 11 #include "mozilla/Attributes.h" 12 #include "mozilla/RefPtr.h" 13 #include "mozilla/dom/VRDisplayBinding.h" 14 15 #include "gfxVR.h" 16 17 namespace mozilla { 18 namespace dom { 19 enum class XRReferenceSpaceType : uint8_t; 20 class XRSession; 21 } // namespace dom 22 namespace gfx { 23 class VRDisplayPresentation; 24 class VRManagerChild; 25 26 class VRDisplayClient { 27 public: 28 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRDisplayClient) 29 30 explicit VRDisplayClient(const VRDisplayInfo& aDisplayInfo); 31 32 MOZ_CAN_RUN_SCRIPT void UpdateDisplayInfo(const VRDisplayInfo& aDisplayInfo); 33 void UpdateSubmitFrameResult(const VRSubmitFrameResultInfo& aResult); 34 GetDisplayInfo()35 const VRDisplayInfo& GetDisplayInfo() const { return mDisplayInfo; } 36 virtual const VRHMDSensorState& GetSensorState() const; 37 void GetSubmitFrameResult(VRSubmitFrameResultInfo& aResult); 38 39 already_AddRefed<VRDisplayPresentation> BeginPresentation( 40 const nsTArray<dom::VRLayer>& aLayers, uint32_t aGroup); 41 void PresentationCreated(); 42 void PresentationDestroyed(); 43 44 void SessionStarted(dom::XRSession* aSession); 45 void SessionEnded(dom::XRSession* aSession); 46 47 bool GetIsConnected() const; 48 49 void NotifyDisconnected(); 50 void SetGroupMask(uint32_t aGroupMask); 51 52 bool IsPresentationGenerationCurrent() const; 53 void MakePresentationGenerationCurrent(); 54 55 void StartVRNavigation(); 56 void StopVRNavigation(const TimeDuration& aTimeout); 57 58 bool IsPresenting(); 59 bool IsReferenceSpaceTypeSupported(dom::XRReferenceSpaceType aType) const; 60 gfx::VRAPIMode GetXRAPIMode() const; 61 void SetXRAPIMode(gfx::VRAPIMode aMode); 62 63 protected: 64 virtual ~VRDisplayClient(); 65 66 MOZ_CAN_RUN_SCRIPT void FireEvents(); 67 void FireGamepadEvents(); 68 MOZ_CAN_RUN_SCRIPT void StartFrame(); 69 70 VRDisplayInfo mDisplayInfo; 71 72 bool bLastEventWasMounted; 73 bool bLastEventWasPresenting; 74 75 int mPresentationCount; 76 uint64_t mLastEventFrameId; 77 uint32_t mLastPresentingGeneration; 78 79 // Difference between mDisplayInfo.mControllerState and 80 // mLastEventControllerState determines what gamepad events to fire when 81 // updated. 82 VRControllerState mLastEventControllerState[kVRControllerMaxCount]; 83 84 /** 85 * mSessions is cleared in VRDisplayClient::SessionEnded. 86 * SessionEnded is guaranteed to be called by every XRSession 87 * when it is shutdown explicitly with the WebXR XRSession.end 88 * call, when all JS references on the XRSession are released, or 89 * when the window is closed. 90 */ 91 nsTArray<RefPtr<dom::XRSession>> mSessions; 92 93 private: 94 void GamepadMappingForWebVR(VRControllerState& aControllerState); 95 96 VRSubmitFrameResultInfo mSubmitFrameResult; 97 gfx::VRAPIMode mAPIMode; 98 }; 99 100 } // namespace gfx 101 } // namespace mozilla 102 103 #endif /* GFX_VR_DISPLAY_CLIENT_H */ 104