tor-browser

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

XRSession.h (5488B)


      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_XRSession_h_
      8 #define mozilla_dom_XRSession_h_
      9 
     10 #include "gfxVR.h"
     11 #include "mozilla/DOMEventTargetHelper.h"
     12 #include "mozilla/dom/WebXRBinding.h"
     13 #include "nsRefreshObservers.h"
     14 
     15 class nsRefreshDriver;
     16 
     17 namespace mozilla {
     18 namespace gfx {
     19 class VRDisplayClient;
     20 class VRDisplayPresentation;
     21 }  // namespace gfx
     22 namespace dom {
     23 
     24 class XRSystem;
     25 enum class XREye : uint8_t;
     26 enum class XRReferenceSpaceType : uint8_t;
     27 enum class XRSessionMode : uint8_t;
     28 enum class XRVisibilityState : uint8_t;
     29 class XRFrame;
     30 class XRFrameRequestCallback;
     31 class XRInputSource;
     32 class XRInputSourceArray;
     33 class XRLayer;
     34 struct XRReferenceSpaceOptions;
     35 class XRRenderState;
     36 struct XRRenderStateInit;
     37 class XRSpace;
     38 class XRViewerPose;
     39 
     40 class XRSession final : public DOMEventTargetHelper, public nsARefreshObserver {
     41 public:
     42  NS_DECL_ISUPPORTS_INHERITED
     43  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XRSession, DOMEventTargetHelper)
     44 
     45 private:
     46  explicit XRSession(
     47      nsPIDOMWindowInner* aWindow, XRSystem* aXRSystem,
     48      nsRefreshDriver* aRefreshDriver, gfx::VRDisplayClient* aClient,
     49      uint32_t aPresentationGroup,
     50      const nsTArray<XRReferenceSpaceType>& aEnabledReferenceSpaceTypes);
     51 
     52 public:
     53  static already_AddRefed<XRSession> CreateInlineSession(
     54      nsPIDOMWindowInner* aWindow, XRSystem* aXRSystem,
     55      const nsTArray<XRReferenceSpaceType>& aEnabledReferenceSpaceTypes);
     56  static already_AddRefed<XRSession> CreateImmersiveSession(
     57      nsPIDOMWindowInner* aWindow, XRSystem* aXRSystem,
     58      gfx::VRDisplayClient* aClient, uint32_t aPresentationGroup,
     59      const nsTArray<XRReferenceSpaceType>& aEnabledReferenceSpaceTypes);
     60 
     61  // WebIDL Boilerplate
     62  JSObject* WrapObject(JSContext* aCx,
     63                       JS::Handle<JSObject*> aGivenProto) override;
     64 
     65  // WebIDL Attributes
     66  XRVisibilityState VisibilityState() const;
     67  XRRenderState* RenderState();
     68  XRInputSourceArray* InputSources();
     69  Nullable<float> GetFrameRate();
     70  void GetSupportedFrameRates(JSContext* aJSContext,
     71                              JS::MutableHandle<JSObject*> aRetval);
     72 
     73  // WebIDL Methods
     74  void UpdateRenderState(const XRRenderStateInit& aNewState, ErrorResult& aRv);
     75  already_AddRefed<Promise> RequestReferenceSpace(
     76      const XRReferenceSpaceType& aReferenceSpaceType, ErrorResult& aRv);
     77  int32_t RequestAnimationFrame(XRFrameRequestCallback& aCallback,
     78                                mozilla::ErrorResult& aError);
     79  void CancelAnimationFrame(int32_t aHandle, mozilla::ErrorResult& aError);
     80  already_AddRefed<Promise> End(ErrorResult& aRv);
     81  already_AddRefed<Promise> UpdateTargetFrameRate(float aRate,
     82                                                  ErrorResult& aRv);
     83 
     84  // WebIDL Events
     85  IMPL_EVENT_HANDLER(end);
     86  IMPL_EVENT_HANDLER(inputsourceschange);
     87  IMPL_EVENT_HANDLER(select);
     88  IMPL_EVENT_HANDLER(selectstart);
     89  IMPL_EVENT_HANDLER(selectend);
     90  IMPL_EVENT_HANDLER(squeeze);
     91  IMPL_EVENT_HANDLER(squeezestart);
     92  IMPL_EVENT_HANDLER(squeezeend);
     93  IMPL_EVENT_HANDLER(visibilitychange);
     94 
     95  // Non WebIDL Members
     96  gfx::VRDisplayClient* GetDisplayClient() const;
     97  XRRenderState* GetActiveRenderState() const;
     98  bool IsEnded() const;
     99  bool IsImmersive() const;
    100  MOZ_CAN_RUN_SCRIPT
    101  void StartFrame();
    102  void ExitPresent();
    103  RefPtr<XRViewerPose> PooledViewerPose(const gfx::Matrix4x4Double& aTransform,
    104                                        bool aEmulatedPosition);
    105  bool CanReportPoses() const;
    106 
    107  // nsARefreshObserver
    108  MOZ_CAN_RUN_SCRIPT
    109  void WillRefresh(mozilla::TimeStamp aTime) override;
    110 
    111 protected:
    112  virtual ~XRSession();
    113  void LastRelease() override;
    114  void DisconnectFromOwner() override;
    115  void Shutdown();
    116  void ExitPresentInternal();
    117  void ApplyPendingRenderState();
    118  RefPtr<XRFrame> PooledFrame();
    119  RefPtr<XRSystem> mXRSystem;
    120  bool mShutdown;
    121  bool mEnded;
    122  RefPtr<nsRefreshDriver> mRefreshDriver;
    123  RefPtr<gfx::VRDisplayClient> mDisplayClient;
    124  RefPtr<gfx::VRDisplayPresentation> mDisplayPresentation;
    125  RefPtr<XRRenderState> mActiveRenderState;
    126  RefPtr<XRRenderState> mPendingRenderState;
    127  RefPtr<XRInputSourceArray> mInputSources;
    128 
    129  struct XRFrameRequest {
    130    XRFrameRequest(mozilla::dom::XRFrameRequestCallback& aCallback,
    131                   int32_t aHandle)
    132        : mCallback(&aCallback), mHandle(aHandle) {}
    133    MOZ_CAN_RUN_SCRIPT
    134    void Call(const DOMHighResTimeStamp& aTimeStamp, XRFrame& aFrame);
    135 
    136    // Comparator operators to allow RemoveElementSorted with an
    137    // integer argument on arrays of XRFrameRequest
    138    bool operator==(int32_t aHandle) const { return mHandle == aHandle; }
    139    bool operator<(int32_t aHandle) const { return mHandle < aHandle; }
    140 
    141    RefPtr<mozilla::dom::XRFrameRequestCallback> mCallback;
    142    int32_t mHandle;
    143  };
    144 
    145  int32_t mFrameRequestCallbackCounter;
    146  nsTArray<XRFrameRequest> mFrameRequestCallbacks;
    147  mozilla::TimeStamp mStartTimeStamp;
    148  nsTArray<XRReferenceSpaceType> mEnabledReferenceSpaceTypes;
    149  nsTArray<RefPtr<XRViewerPose>> mViewerPosePool;
    150  uint32_t mViewerPosePoolIndex;
    151  nsTArray<RefPtr<XRFrame>> mFramePool;
    152  uint32_t mFramePoolIndex;
    153 };
    154 
    155 }  // namespace dom
    156 }  // namespace mozilla
    157 
    158 #endif  // mozilla_dom_XRSession_h_