tor-browser

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

OpenVRSession.h (3919B)


      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_SERVICE_OPENVRSESSION_H
      8 #define GFX_VR_SERVICE_OPENVRSESSION_H
      9 
     10 #include "VRSession.h"
     11 
     12 #include "openvr.h"
     13 #include "mozilla/TimeStamp.h"
     14 #include "moz_external_vr.h"
     15 #include "OpenVRControllerMapper.h"
     16 
     17 #if defined(XP_WIN)
     18 #  include <d3d11_1.h>
     19 #endif
     20 class nsITimer;
     21 
     22 namespace mozilla {
     23 namespace gfx {
     24 class VRThread;
     25 class OpenVRControllerMapper;
     26 
     27 static const int kNumOpenVRHaptics = 1;
     28 
     29 enum OpenVRHand : int8_t {
     30  Left = 0,
     31  Right = 1,
     32  Total = 2,
     33 
     34  None = -1
     35 };
     36 
     37 class OpenVRSession : public VRSession {
     38 public:
     39  OpenVRSession();
     40  virtual ~OpenVRSession();
     41 
     42  bool Initialize(mozilla::gfx::VRSystemState& aSystemState,
     43                  bool aDetectRuntimesOnly) override;
     44  void Shutdown() override;
     45  void ProcessEvents(mozilla::gfx::VRSystemState& aSystemState) override;
     46  void StartFrame(mozilla::gfx::VRSystemState& aSystemState) override;
     47  bool StartPresentation() override;
     48  void StopPresentation() override;
     49  void VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex,
     50                     float aIntensity, float aDuration) override;
     51  void StopVibrateHaptic(uint32_t aControllerIdx) override;
     52  void StopAllHaptics() override;
     53 
     54 protected:
     55 #if defined(XP_WIN)
     56  bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
     57                   ID3D11Texture2D* aTexture) override;
     58 #elif defined(XP_MACOSX)
     59  bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
     60                   const VRLayerTextureHandle& aTexture) override;
     61 #endif
     62 
     63 private:
     64  // OpenVR State
     65  ::vr::IVRSystem* mVRSystem = nullptr;
     66  ::vr::IVRChaperone* mVRChaperone = nullptr;
     67  ::vr::IVRCompositor* mVRCompositor = nullptr;
     68  ::vr::VRActionSetHandle_t mActionsetFirefox = vr::k_ulInvalidActionSetHandle;
     69  OpenVRHand mControllerDeviceIndex[kVRControllerMaxCount];
     70  ControllerInfo mControllerHand[OpenVRHand::Total];
     71  float mHapticPulseRemaining[kVRControllerMaxCount][kNumOpenVRHaptics];
     72  float mHapticPulseIntensity[kVRControllerMaxCount][kNumOpenVRHaptics];
     73  bool mIsWindowsMR;
     74  TimeStamp mLastHapticUpdate;
     75 
     76  static void HapticTimerCallback(nsITimer* aTimer, void* aClosure);
     77  bool InitState(mozilla::gfx::VRSystemState& aSystemState);
     78  void UpdateStageParameters(mozilla::gfx::VRDisplayState& aState);
     79  void UpdateEyeParameters(mozilla::gfx::VRSystemState& aState);
     80  void UpdateHeadsetPose(mozilla::gfx::VRSystemState& aState);
     81  void EnumerateControllers(VRSystemState& aState);
     82  void UpdateControllerPoses(VRSystemState& aState);
     83  void UpdateControllerButtons(VRSystemState& aState);
     84  void UpdateTelemetry(VRSystemState& aSystemState);
     85  bool SetupContollerActions();
     86 
     87  bool SubmitFrame(const VRLayerTextureHandle& aTextureHandle,
     88                   ::vr::ETextureType aTextureType,
     89                   const VRLayerEyeRect& aLeftEyeRect,
     90                   const VRLayerEyeRect& aRightEyeRect);
     91 #if defined(XP_WIN)
     92  bool CreateD3DObjects();
     93 #endif
     94  void GetControllerDeviceId(::vr::ETrackedDeviceClass aDeviceType,
     95                             ::vr::TrackedDeviceIndex_t aDeviceIndex,
     96                             nsCString& aId,
     97                             mozilla::gfx::VRControllerType& aControllerType);
     98  void UpdateHaptics();
     99  void StartHapticThread();
    100  void StopHapticThread();
    101  void StartHapticTimer();
    102  void StopHapticTimer();
    103  RefPtr<nsITimer> mHapticTimer;
    104  RefPtr<VRThread> mHapticThread;
    105  mozilla::Mutex mControllerHapticStateMutex MOZ_UNANNOTATED;
    106  UniquePtr<OpenVRControllerMapper> mControllerMapper;
    107 };
    108 
    109 }  // namespace gfx
    110 }  // namespace mozilla
    111 
    112 #endif  // GFX_VR_SERVICE_OPENVRSESSION_H