Bug 1356421 - Part 2: Notify GamepadManager when controllers are removed in VR manager; r?kip draft
authorDaosheng Mu <daoshengmu@gmail.com>
Mon, 24 Apr 2017 13:42:59 +0800
changeset 566934 94f653cdd9d7f2b7af2d8b488f5568f4cc27cf6a
parent 566933 855a04e0b47e4a632c9e45c78840b9cb1f939488
child 625465 ca42df9b20f21c2fd1a8149ed296b471282e277c
push id55381
push userbmo:dmu@mozilla.com
push dateMon, 24 Apr 2017 06:17:45 +0000
reviewerskip
bugs1356421
milestone55.0a1
Bug 1356421 - Part 2: Notify GamepadManager when controllers are removed in VR manager; r?kip MozReview-Commit-ID: Hje9NTF4xxz
gfx/vr/gfxVROculus.cpp
gfx/vr/gfxVROpenVR.cpp
--- a/gfx/vr/gfxVROculus.cpp
+++ b/gfx/vr/gfxVROculus.cpp
@@ -1463,23 +1463,17 @@ VRSystemManagerOculus::ScanForController
   }
 
   if (inputState.ControllerType & ovrControllerType_RTouch) {
     activeControllerArray[newControllerCount] = ovrControllerType_RTouch;
     ++newControllerCount;
   }
 
   if (newControllerCount != mControllerCount) {
-    // controller count is changed, removing the existing gamepads first.
-    for (uint32_t i = 0; i < mOculusController.Length(); ++i) {
-      RemoveGamepad(i);
-    }
-
-    mControllerCount = 0;
-    mOculusController.Clear();
+    RemoveControllers();
 
     // Re-adding controllers to VRControllerManager.
     for (uint32_t i = 0; i < newControllerCount; ++i) {
       GamepadHand hand;
 
       switch (activeControllerArray[i]) {
         case ovrControllerType::ovrControllerType_LTouch:
           hand = GamepadHand::Left;
@@ -1496,11 +1490,16 @@ VRSystemManagerOculus::ScanForController
       ++mControllerCount;
     }
   }
 }
 
 void
 VRSystemManagerOculus::RemoveControllers()
 {
+  // controller count is changed, removing the existing gamepads first.
+  for (uint32_t i = 0; i < mOculusController.Length(); ++i) {
+    RemoveGamepad(i);
+  }
+
   mOculusController.Clear();
   mControllerCount = 0;
 }
\ No newline at end of file
--- a/gfx/vr/gfxVROpenVR.cpp
+++ b/gfx/vr/gfxVROpenVR.cpp
@@ -917,22 +917,17 @@ VRSystemManagerOpenVR::ScanForController
       continue;
     }
 
     trackedIndexArray[newControllerCount] = trackedDevice;
     ++newControllerCount;
   }
 
   if (newControllerCount != mControllerCount) {
-    // The controller count is changed, removing the existing gamepads first.
-    for (uint32_t i = 0; i < mOpenVRController.Length(); ++i) {
-      RemoveGamepad(i);
-    }
-    mControllerCount = 0;
-    mOpenVRController.Clear();
+    RemoveControllers();
 
     // Re-adding controllers to VRControllerManager.
     for (::vr::TrackedDeviceIndex_t i = 0; i < newControllerCount; ++i) {
       const ::vr::TrackedDeviceIndex_t trackedDevice = trackedIndexArray[i];
       const ::vr::ETrackedDeviceClass deviceType = mVRSystem->
                                                    GetTrackedDeviceClass(trackedDevice);
       const ::vr::ETrackedControllerRole role = mVRSystem->
                                                 GetControllerRoleForTrackedDeviceIndex(
@@ -1000,12 +995,16 @@ VRSystemManagerOpenVR::ScanForController
       ++mControllerCount;
     }
   }
 }
 
 void
 VRSystemManagerOpenVR::RemoveControllers()
 {
+  // The controller count is changed, removing the existing gamepads first.
+  for (uint32_t i = 0; i < mOpenVRController.Length(); ++i) {
+    RemoveGamepad(i);
+  }
   mOpenVRController.Clear();
   mControllerCount = 0;
 }