tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

VRDisplayClient.h (3149B)


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