Bug 1313585 - Part 2: Removing the existing gamepads before scanning VR controllers; r=gw280
authorDaosheng Mu <daoshengmu@gmail.com>
Fri, 28 Oct 2016 16:00:12 +0800
changeset 347666 bafacc3b707c7d10862dd766c2703fed640bcc22
parent 347665 b8502d4f4bb285a8c10d85a5dfc4382152546d8e
child 347667 a448b722c162abcd6aa7f946ce895743187c9802
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
bugs1313585
milestone52.0a1
Bug 1313585 - Part 2: Removing the existing gamepads before scanning VR controllers; r=gw280 MozReview-Commit-ID: 24a4tRoYX8f
gfx/vr/gfxVR.cpp
gfx/vr/gfxVR.h
gfx/vr/gfxVROpenVR.cpp
--- a/gfx/vr/gfxVR.cpp
+++ b/gfx/vr/gfxVR.cpp
@@ -74,16 +74,26 @@ VRControllerManager::AddGamepad(const ch
                      aNumAxes);
 
   VRManager* vm = VRManager::Get();
   MOZ_ASSERT(vm);
   vm->NotifyGamepadChange<dom::GamepadAdded>(a);
 }
 
 void
+VRControllerManager::RemoveGamepad(uint32_t aIndex)
+{
+  dom::GamepadRemoved a(aIndex, dom::GamepadServiceType::VR);
+
+  VRManager* vm = VRManager::Get();
+  MOZ_ASSERT(vm);
+  vm->NotifyGamepadChange<dom::GamepadRemoved>(a);
+}
+
+void
 VRControllerManager::NewButtonEvent(uint32_t aIndex, uint32_t aButton,
                                     bool aPressed)
 {
   dom::GamepadButtonInformation a(aIndex, dom::GamepadServiceType::VR,
                                   aButton, aPressed, aPressed ? 1.0L : 0.0L);
 
   VRManager* vm = VRManager::Get();
   MOZ_ASSERT(vm);
--- a/gfx/vr/gfxVR.h
+++ b/gfx/vr/gfxVR.h
@@ -250,16 +250,17 @@ public:
   virtual void Destroy() = 0;
   virtual void HandleInput() = 0;
   virtual void GetControllers(nsTArray<RefPtr<VRControllerHost>>& aControllerResult) = 0;
   virtual void ScanForDevices() = 0;
   void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed);
   void NewAxisMove(uint32_t aIndex, uint32_t aAxis, double aValue);
   void AddGamepad(const char* aID, dom::GamepadMappingType aMapping,
                   uint32_t aNumButtons, uint32_t aNumAxes);
+  void RemoveGamepad(uint32_t aIndex);
 
 protected:
   VRControllerManager() : mInstalled(false), mControllerCount(0) {}
   virtual ~VRControllerManager() {}
 
   bool mInstalled;
   uint32_t mControllerCount;
   static Atomic<uint32_t> sControllerBase;
--- a/gfx/vr/gfxVROpenVR.cpp
+++ b/gfx/vr/gfxVROpenVR.cpp
@@ -634,16 +634,20 @@ VRControllerManagerOpenVR::GetController
   for (uint32_t i = 0; i < mOpenVRController.Length(); ++i) {
     aControllerResult.AppendElement(mOpenVRController[i]);
   }
 }
 
 void
 VRControllerManagerOpenVR::ScanForDevices()
 {
+  // Remove the existing gamepads
+  for (uint32_t i = 0; i < mOpenVRController.Length(); ++i) {
+    RemoveGamepad(mOpenVRController[i]->GetIndex());
+  }
   mControllerCount = 0;
   mOpenVRController.Clear();
 
   if (!mVRSystem)
     return;
 
   // Basically, we would have HMDs in the tracked devices, but we are just interested in the controllers.
   for ( vr::TrackedDeviceIndex_t trackedDevice = vr::k_unTrackedDeviceIndex_Hmd + 1;