Bug 1423866 - Shutdown the vibrate thread when VR controllers are removed; r?kip
MozReview-Commit-ID: IWvokDVH0x3
--- a/gfx/vr/gfxVROculus.cpp
+++ b/gfx/vr/gfxVROculus.cpp
@@ -1369,16 +1369,17 @@ VRControllerOculus::GetHandTrigger()
void
VRControllerOculus::SetHandTrigger(float aValue)
{
mHandTrigger = aValue;
}
VRControllerOculus::~VRControllerOculus()
{
+ ShutdownVibrateHapticThread();
MOZ_COUNT_DTOR_INHERITED(VRControllerOculus, VRControllerHost);
}
void
VRControllerOculus::UpdateVibrateHaptic(ovrSession aSession,
uint32_t aHapticIndex,
double aIntensity,
double aDuration,
@@ -1511,16 +1512,26 @@ VRControllerOculus::VibrateHaptic(ovrSes
}
void
VRControllerOculus::StopVibrateHaptic()
{
mIsVibrateStopped = true;
}
+void
+VRControllerOculus::ShutdownVibrateHapticThread()
+{
+ StopVibrateHaptic();
+ if (mVibrateThread) {
+ mVibrateThread->Shutdown();
+ mVibrateThread = nullptr;
+ }
+}
+
/*static*/ already_AddRefed<VRSystemManagerOculus>
VRSystemManagerOculus::Create()
{
MOZ_ASSERT(NS_IsMainThread());
if (!gfxPrefs::VREnabled() || !gfxPrefs::VROculusEnabled())
{
return nullptr;
@@ -1978,14 +1989,15 @@ VRSystemManagerOculus::ScanForController
}
}
void
VRSystemManagerOculus::RemoveControllers()
{
// controller count is changed, removing the existing gamepads first.
for (uint32_t i = 0; i < mOculusController.Length(); ++i) {
+ mOculusController[i]->ShutdownVibrateHapticThread();
RemoveGamepad(i);
}
mOculusController.Clear();
mControllerCount = 0;
}
--- a/gfx/vr/gfxVROculus.h
+++ b/gfx/vr/gfxVROculus.h
@@ -151,16 +151,17 @@ public:
float GetHandTrigger();
void SetHandTrigger(float aValue);
void VibrateHaptic(ovrSession aSession,
uint32_t aHapticIndex,
double aIntensity,
double aDuration,
const VRManagerPromise& aPromise);
void StopVibrateHaptic();
+ void ShutdownVibrateHapticThread();
protected:
virtual ~VRControllerOculus();
private:
void UpdateVibrateHaptic(ovrSession aSession,
uint32_t aHapticIndex,
double aIntensity,
--- a/gfx/vr/gfxVROpenVR.cpp
+++ b/gfx/vr/gfxVROpenVR.cpp
@@ -440,21 +440,17 @@ VRControllerOpenVR::VRControllerOpenVR(d
mControllerInfo.mControllerName = aId;
mControllerInfo.mNumButtons = aNumButtons;
mControllerInfo.mNumAxes = aNumAxes;
mControllerInfo.mNumHaptics = kNumOpenVRHaptcs;
}
VRControllerOpenVR::~VRControllerOpenVR()
{
- if (mVibrateThread) {
- mVibrateThread->Shutdown();
- mVibrateThread = nullptr;
- }
-
+ ShutdownVibrateHapticThread();
MOZ_COUNT_DTOR_INHERITED(VRControllerOpenVR, VRControllerHost);
}
void
VRControllerOpenVR::SetTrackedIndex(uint32_t aTrackedIndex)
{
mTrackedIndex = aTrackedIndex;
}
@@ -580,16 +576,26 @@ VRControllerOpenVR::VibrateHaptic(::vr::
}
void
VRControllerOpenVR::StopVibrateHaptic()
{
mIsVibrateStopped = true;
}
+void
+VRControllerOpenVR::ShutdownVibrateHapticThread()
+{
+ StopVibrateHaptic();
+ if (mVibrateThread) {
+ mVibrateThread->Shutdown();
+ mVibrateThread = nullptr;
+ }
+}
+
VRSystemManagerOpenVR::VRSystemManagerOpenVR()
: mVRSystem(nullptr)
, mIsWindowsMR(false)
{
}
/*static*/ already_AddRefed<VRSystemManagerOpenVR>
VRSystemManagerOpenVR::Create()
@@ -1189,16 +1195,17 @@ VRSystemManagerOpenVR::ScanForController
}
}
void
VRSystemManagerOpenVR::RemoveControllers()
{
// The controller count is changed, removing the existing gamepads first.
for (uint32_t i = 0; i < mOpenVRController.Length(); ++i) {
+ mOpenVRController[i]->ShutdownVibrateHapticThread();
RemoveGamepad(i);
}
mOpenVRController.Clear();
mControllerCount = 0;
}
void
VRSystemManagerOpenVR::GetControllerDeviceId(::vr::ETrackedDeviceClass aDeviceType,
--- a/gfx/vr/gfxVROpenVR.h
+++ b/gfx/vr/gfxVROpenVR.h
@@ -91,16 +91,17 @@ public:
float GetTrigger(uint32_t aButton);
void SetHand(dom::GamepadHand aHand);
void VibrateHaptic(::vr::IVRSystem* aVRSystem,
uint32_t aHapticIndex,
double aIntensity,
double aDuration,
const VRManagerPromise& aPromise);
void StopVibrateHaptic();
+ void ShutdownVibrateHapticThread();
protected:
virtual ~VRControllerOpenVR();
private:
void UpdateVibrateHaptic(::vr::IVRSystem* aVRSystem,
uint32_t aHapticIndex,
double aIntensity,