LCOV - code coverage report
Current view: top level - gfx/vr - gfxVROpenVR.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 1 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #ifndef GFX_VR_OPENVR_H
       7             : #define GFX_VR_OPENVR_H
       8             : 
       9             : #include "nsTArray.h"
      10             : #include "nsIScreen.h"
      11             : #include "nsIThread.h"
      12             : #include "nsCOMPtr.h"
      13             : #include "mozilla/RefPtr.h"
      14             : 
      15             : #include "mozilla/gfx/2D.h"
      16             : #include "mozilla/EnumeratedArray.h"
      17             : 
      18             : #include "openvr.h"
      19             : #include "gfxVR.h"
      20             : #include "VRDisplayHost.h"
      21             : 
      22             : namespace mozilla {
      23             : namespace gfx {
      24             : namespace impl {
      25             : 
      26             : class VRDisplayOpenVR : public VRDisplayHost
      27             : {
      28             : public:
      29             :   virtual void NotifyVSync() override;
      30             :   void ZeroSensor() override;
      31             : 
      32             : protected:
      33             :   virtual VRHMDSensorState GetSensorState() override;
      34             :   virtual void StartPresentation() override;
      35             :   virtual void StopPresentation() override;
      36             : #if defined(XP_WIN)
      37             :   virtual bool SubmitFrame(mozilla::layers::TextureSourceD3D11* aSource,
      38             :                            const IntSize& aSize,
      39             :                            const gfx::Rect& aLeftEyeRect,
      40             :                            const gfx::Rect& aRightEyeRect) override;
      41             : #endif
      42             : 
      43             : public:
      44             :   explicit VRDisplayOpenVR(::vr::IVRSystem *aVRSystem,
      45             :                            ::vr::IVRChaperone *aVRChaperone,
      46             :                            ::vr::IVRCompositor *aVRCompositor);
      47             : 
      48             : protected:
      49             :   virtual ~VRDisplayOpenVR();
      50             :   void Destroy();
      51             : 
      52             :   // not owned by us; global from OpenVR
      53             :   ::vr::IVRSystem *mVRSystem;
      54             :   ::vr::IVRChaperone *mVRChaperone;
      55             :   ::vr::IVRCompositor *mVRCompositor;
      56             : 
      57             :   bool mIsPresenting;
      58             : 
      59             :   void UpdateStageParameters();
      60             :   void PollEvents();
      61             : };
      62             : 
      63             : class VRControllerOpenVR : public VRControllerHost
      64             : {
      65             : public:
      66             :   explicit VRControllerOpenVR(dom::GamepadHand aHand, uint32_t aNumButtons,
      67             :                               uint32_t aNumAxes, ::vr::ETrackedDeviceClass aDeviceType);
      68             :   void SetTrackedIndex(uint32_t aTrackedIndex);
      69             :   uint32_t GetTrackedIndex();
      70             :   float GetAxisMove(uint32_t aAxis);
      71             :   void SetAxisMove(uint32_t aAxis, float aValue);
      72             :   void SetTrigger(float aValue);
      73             :   float GetTrigger();
      74             :   void SetHand(dom::GamepadHand aHand);
      75             :   void VibrateHaptic(::vr::IVRSystem* aVRSystem,
      76             :                      uint32_t aHapticIndex,
      77             :                      double aIntensity,
      78             :                      double aDuration,
      79             :                      uint32_t aPromiseID);
      80             :   void StopVibrateHaptic();
      81             : 
      82             : protected:
      83             :   virtual ~VRControllerOpenVR();
      84             : 
      85             : private:
      86             :   void UpdateVibrateHaptic(::vr::IVRSystem* aVRSystem,
      87             :                            uint32_t aHapticIndex,
      88             :                            double aIntensity,
      89             :                            double aDuration,
      90             :                            uint64_t aVibrateIndex,
      91             :                            uint32_t aPromiseID);
      92             :   void VibrateHapticComplete(uint32_t aPromiseID);
      93             : 
      94             :   // The index of tracked devices from ::vr::IVRSystem.
      95             :   uint32_t mTrackedIndex;
      96             :   float mTrigger;
      97             :   nsTArray<float> mAxisMove;
      98             :   nsCOMPtr<nsIThread> mVibrateThread;
      99             :   Atomic<bool> mIsVibrateStopped;
     100             : };
     101             : 
     102             : } // namespace impl
     103             : 
     104           0 : class VRSystemManagerOpenVR : public VRSystemManager
     105             : {
     106             : public:
     107             :   static already_AddRefed<VRSystemManagerOpenVR> Create();
     108             : 
     109             :   virtual void Destroy() override;
     110             :   virtual void Shutdown() override;
     111             :   virtual bool GetHMDs(nsTArray<RefPtr<VRDisplayHost> >& aHMDResult) override;
     112             :   virtual bool GetIsPresenting() override;
     113             :   virtual void HandleInput() override;
     114             :   virtual void GetControllers(nsTArray<RefPtr<VRControllerHost>>&
     115             :                               aControllerResult) override;
     116             :   virtual void ScanForControllers() override;
     117             :   virtual void RemoveControllers() override;
     118             :   virtual void VibrateHaptic(uint32_t aControllerIdx,
     119             :                              uint32_t aHapticIndex,
     120             :                              double aIntensity,
     121             :                              double aDuration,
     122             :                              uint32_t aPromiseID) override;
     123             :   virtual void StopVibrateHaptic(uint32_t aControllerIdx) override;
     124             : 
     125             : protected:
     126             :   VRSystemManagerOpenVR();
     127             : 
     128             : private:
     129             :   void HandleButtonPress(uint32_t aControllerIdx,
     130             :                          uint32_t aButton,
     131             :                          uint64_t aButtonMask,
     132             :                          uint64_t aButtonPressed,
     133             :                          uint64_t aButtonTouched);
     134             :   void HandleTriggerPress(uint32_t aControllerIdx,
     135             :                           uint32_t aButton,
     136             :                           float aValue);
     137             :   void HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
     138             :                       float aValue);
     139             :   void HandlePoseTracking(uint32_t aControllerIdx,
     140             :                           const dom::GamepadPoseState& aPose,
     141             :                           VRControllerHost* aController);
     142             :   dom::GamepadHand GetGamepadHandFromControllerRole(
     143             :                           ::vr::ETrackedControllerRole aRole);
     144             : 
     145             :   // there can only be one
     146             :   RefPtr<impl::VRDisplayOpenVR> mOpenVRHMD;
     147             :   nsTArray<RefPtr<impl::VRControllerOpenVR>> mOpenVRController;
     148             :   ::vr::IVRSystem *mVRSystem;
     149             : };
     150             : 
     151             : } // namespace gfx
     152             : } // namespace mozilla
     153             : 
     154             : 
     155             : #endif /* GFX_VR_OPENVR_H */

Generated by: LCOV version 1.13