Bug 1358725 - Return zero after OpenVR controllers' axis is released; r?kip draft
authorDaosheng Mu <daoshengmu@gmail.com>
Mon, 24 Apr 2017 18:52:06 +0800
changeset 567076 33f423ebce05d62346503977922f63616b43ebca
parent 566789 8e969cc9aff49f845678cba5b35d9dd8aa340f16
child 625512 18f3a38b6c80a53c7c67599094896c7b16c4717a
push id55430
push userbmo:dmu@mozilla.com
push dateMon, 24 Apr 2017 10:52:32 +0000
reviewerskip
bugs1358725
milestone55.0a1
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()
@@ -801,18 +815,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
 {