Bug 1313585 - Part 2: Removing the existing gamepads before scanning VR controllers; r?gw280
MozReview-Commit-ID: 24a4tRoYX8f
--- 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;