Bug 1358725 - Return zero after OpenVR controllers' axis is released; r=kip
authorDaosheng Mu <daoshengmu@gmail.com>
Mon, 24 Apr 2017 18:52:06 +0800
changeset 354848 fbc3a33ce156a82d0125fc820e8d1654fbf5f2af
parent 354847 1a675abcc1f075d78cb737ad061b08b6fa126e5b
child 354849 0b7e38e69babd5f759715903ab7cf531535ce6a0
push id41491
push userdmu@mozilla.com
push dateWed, 26 Apr 2017 01:18:34 +0000
treeherderautoland@fbc3a33ce156 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskip
bugs1358725
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1358725 - Return zero after OpenVR controllers' axis is released; r=kip MozReview-Commit-ID: Le4en6pUUTQ
gfx/vr/gfxVROpenVR.cpp
gfx/vr/gfxVROpenVR.h
--- a/gfx/vr/gfxVROpenVR.cpp
+++ b/gfx/vr/gfxVROpenVR.cpp
@@ -340,16 +340,17 @@ VRDisplayOpenVR::NotifyVSync()
   // Make sure we respond to OpenVR events even when not presenting
   PollEvents();
 }
 
 VRControllerOpenVR::VRControllerOpenVR(dom::GamepadHand aHand, uint32_t aNumButtons,
                                        uint32_t aNumAxes, ::vr::ETrackedDeviceClass aDeviceType)
   : VRControllerHost(VRDeviceType::OpenVR)
   , mTrigger(0)
+  , mAxisMove(aNumAxes)
   , mVibrateThread(nullptr)
   , mIsVibrateStopped(false)
 {
   MOZ_COUNT_CTOR_INHERITED(VRControllerOpenVR, VRControllerHost);
 
   switch (aDeviceType) {
     case ::vr::TrackedDeviceClass_Controller:
       mControllerInfo.mControllerName.AssignLiteral("OpenVR Gamepad");
@@ -357,16 +358,17 @@ VRControllerOpenVR::VRControllerOpenVR(d
     case ::vr::TrackedDeviceClass_GenericTracker:
       mControllerInfo.mControllerName.AssignLiteral("OpenVR Tracker");
       break;
     default:
       MOZ_ASSERT(false);
       break;
   }
 
+  mAxisMove.SetLengthAndRetainStorage(aNumAxes);
   mControllerInfo.mMappingType = GamepadMappingType::_empty;
   mControllerInfo.mHand = aHand;
   mControllerInfo.mNumButtons = aNumButtons;
   mControllerInfo.mNumAxes = aNumAxes;
   mControllerInfo.mNumHaptics = kNumOpenVRHaptcs;
 }
 
 VRControllerOpenVR::~VRControllerOpenVR()
@@ -386,16 +388,28 @@ VRControllerOpenVR::SetTrackedIndex(uint
 }
 
 uint32_t
 VRControllerOpenVR::GetTrackedIndex()
 {
   return mTrackedIndex;
 }
 
+float
+VRControllerOpenVR::GetAxisMove(uint32_t aAxis)
+{
+  return mAxisMove[aAxis];
+}
+
+void
+VRControllerOpenVR::SetAxisMove(uint32_t aAxis, float aValue)
+{
+  mAxisMove[aAxis] = aValue;
+}
+
 void
 VRControllerOpenVR::SetTrigger(float aValue)
 {
   mTrigger = aValue;
 }
 
 float
 VRControllerOpenVR::GetTrigger()
@@ -806,18 +820,22 @@ VRSystemManagerOpenVR::HandleTriggerPres
     controller->SetTrigger(aValue);
   }
 }
 
 void
 VRSystemManagerOpenVR::HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
                                       float aValue)
 {
-  if (aValue != 0.0f) {
+  RefPtr<impl::VRControllerOpenVR> controller(mOpenVRController[aControllerIdx]);
+  MOZ_ASSERT(controller);
+
+  if (controller->GetAxisMove(aAxis) != aValue) {
     NewAxisMove(aControllerIdx, aAxis, aValue);
+    controller->SetAxisMove(aAxis, aValue);
   }
 }
 
 void
 VRSystemManagerOpenVR::HandlePoseTracking(uint32_t aControllerIdx,
                                           const GamepadPoseState& aPose,
                                           VRControllerHost* aController)
 {
--- a/gfx/vr/gfxVROpenVR.h
+++ b/gfx/vr/gfxVROpenVR.h
@@ -64,16 +64,18 @@ protected:
 
 class VRControllerOpenVR : public VRControllerHost
 {
 public:
   explicit VRControllerOpenVR(dom::GamepadHand aHand, uint32_t aNumButtons,
                               uint32_t aNumAxes, ::vr::ETrackedDeviceClass aDeviceType);
   void SetTrackedIndex(uint32_t aTrackedIndex);
   uint32_t GetTrackedIndex();
+  float GetAxisMove(uint32_t aAxis);
+  void SetAxisMove(uint32_t aAxis, float aValue);
   void SetTrigger(float aValue);
   float GetTrigger();
   void SetHand(dom::GamepadHand aHand);
   void VibrateHaptic(::vr::IVRSystem* aVRSystem,
                      uint32_t aHapticIndex,
                      double aIntensity,
                      double aDuration,
                      uint32_t aPromiseID);
@@ -89,16 +91,17 @@ private:
                            double aDuration,
                            uint64_t aVibrateIndex,
                            uint32_t aPromiseID);
   void VibrateHapticComplete(uint32_t aPromiseID);
 
   // The index of tracked devices from ::vr::IVRSystem.
   uint32_t mTrackedIndex;
   float mTrigger;
+  nsTArray<float> mAxisMove;
   nsCOMPtr<nsIThread> mVibrateThread;
   Atomic<bool> mIsVibrateStopped;
 };
 
 } // namespace impl
 
 class VRSystemManagerOpenVR : public VRSystemManager
 {