Bug 1356421 - Part 2: Notify GamepadManager when controllers are removed in VR manager; r?kip
MozReview-Commit-ID: Hje9NTF4xxz
--- 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;
}