Bug 1315636 - Hanlde OpenVR controller button release; r=gw280
authorDaosheng Mu <daoshengmu@gmail.com>
Tue, 08 Nov 2016 08:15:01 +0800
changeset 348358 1633bd3dfd6ff73c795544da9518d16383cb18d8
parent 348357 b504bc4ede3c3ad80b5624476bf0601c97011043
child 348359 79a80a004aa8eb59d18489b6b8c99a532603faca
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgw280
bugs1315636
milestone52.0a1
Bug 1315636 - Hanlde OpenVR controller button release; r=gw280 MozReview-Commit-ID: 9ihcXugQn2r
gfx/vr/VRDisplayHost.cpp
gfx/vr/VRDisplayHost.h
gfx/vr/gfxVROpenVR.cpp
--- a/gfx/vr/VRDisplayHost.cpp
+++ b/gfx/vr/VRDisplayHost.cpp
@@ -168,9 +168,21 @@ VRControllerHost::SetIndex(uint32_t aInd
 {
   mIndex = aIndex;
 }
 
 uint32_t
 VRControllerHost::GetIndex()
 {
   return mIndex;
-}
\ No newline at end of file
+}
+
+void
+VRControllerHost::SetButtonPressed(uint64_t aBit)
+{
+  mButtonPressed = aBit;
+}
+
+uint64_t
+VRControllerHost::GetButtonPressed()
+{
+  return mButtonPressed;
+}
--- a/gfx/vr/VRDisplayHost.h
+++ b/gfx/vr/VRDisplayHost.h
@@ -85,22 +85,26 @@ private:
 
 class VRControllerHost {
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRControllerHost)
 
   const VRControllerInfo& GetControllerInfo() const;
   void SetIndex(uint32_t aIndex);
   uint32_t GetIndex();
+  void SetButtonPressed(uint64_t aBit);
+  uint64_t GetButtonPressed();
 
 protected:
   explicit VRControllerHost(VRDeviceType aType);
   virtual ~VRControllerHost();
 
   VRControllerInfo mControllerInfo;
   // The controller index in VRControllerManager.
   uint32_t mIndex;
+  // The current button pressed bit of button mask.
+  uint64_t mButtonPressed;
 };
 
 } // namespace gfx
 } // namespace mozilla
 
 #endif /* GFX_VR_DISPLAY_HOST_H */
--- a/gfx/vr/gfxVROpenVR.cpp
+++ b/gfx/vr/gfxVROpenVR.cpp
@@ -578,19 +578,17 @@ VRControllerManagerOpenVR::HandleInput()
   // Process OpenVR controller state
   for (uint32_t i = 0; i < mOpenVRController.Length(); ++i) {
     controller = mOpenVRController[i];
 
     MOZ_ASSERT(mVRSystem->GetTrackedDeviceClass(controller->GetTrackedIndex())
                == vr::TrackedDeviceClass_Controller);
 
     if (mVRSystem->GetControllerState(controller->GetTrackedIndex(), &state)) {
-      if (state.ulButtonPressed) {
-        HandleButtonPress(controller->GetIndex(), state.ulButtonPressed);
-      }
+      HandleButtonPress(controller->GetIndex(), state.ulButtonPressed);
 
       axis = static_cast<uint32_t>(VRControllerAxisType::TrackpadXAxis);
       HandleAxisMove(controller->GetIndex(), axis,
                      state.rAxis[gOpenVRAxes[axis]].x);
 
       axis = static_cast<uint32_t>(VRControllerAxisType::TrackpadYAxis);
       HandleAxisMove(controller->GetIndex(), axis,
                      state.rAxis[gOpenVRAxes[axis]].y);
@@ -602,21 +600,36 @@ VRControllerManagerOpenVR::HandleInput()
   }
 }
 
 void
 VRControllerManagerOpenVR::HandleButtonPress(uint32_t aControllerIdx,
                                              uint64_t aButtonPressed)
 {
   uint64_t buttonMask = 0;
+  RefPtr<impl::VRControllerOpenVR> controller;
+  controller = mOpenVRController[aControllerIdx];
+  uint64_t diff = (controller->GetButtonPressed() ^ aButtonPressed);
+
+  if (!diff) {
+    return;
+  }
 
   for (uint32_t i = 0; i < gNumOpenVRButtonMask; ++i) {
     buttonMask = gOpenVRButtonMask[i];
-    NewButtonEvent(aControllerIdx, i, aButtonPressed & buttonMask);
+
+    if (diff & buttonMask) {
+      // diff & aButtonPressed would be true while a new button press
+      // event, otherwise it is an old press event and needs to notify
+      // the button has been released.
+      NewButtonEvent(aControllerIdx, i, diff & aButtonPressed);
+    }
   }
+
+  controller->SetButtonPressed(aButtonPressed);
 }
 
 void
 VRControllerManagerOpenVR::HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
                                           float aValue)
 {
   if (aValue != 0.0f) {
     NewAxisMove(aControllerIdx, aAxis, aValue);