Bug 1424378 - Switch off Windows MR mode when the amount of button or axes is less than our expectation; r?kip draft
authorDaosheng Mu <daoshengmu@gmail.com>
Tue, 12 Dec 2017 10:49:03 -0600
changeset 715235 be2b1a59b3e09efb110bcd71700bf38e91a01928
parent 715168 351c75ab74c9a83db5c0662ba271b49479adb1f1
child 744735 8ea6cf0a21eca80928dde6f0bac27e24777bad17
push id94099
push userbmo:dmu@mozilla.com
push dateWed, 03 Jan 2018 07:25:03 +0000
reviewerskip
bugs1424378
milestone59.0a1
Bug 1424378 - Switch off Windows MR mode when the amount of button or axes is less than our expectation; r?kip MozReview-Commit-ID: AONBdKV0Zqj
gfx/vr/gfxVROpenVR.cpp
--- a/gfx/vr/gfxVROpenVR.cpp
+++ b/gfx/vr/gfxVROpenVR.cpp
@@ -1183,16 +1183,23 @@ VRSystemManagerOpenVR::ScanForController
       nsCString deviceId;
       GetControllerDeviceId(deviceType, trackedDevice, deviceId);
       RefPtr<VRControllerOpenVR> openVRController =
         new VRControllerOpenVR(hand, mOpenVRHMD->GetDisplayInfo().GetDisplayID(),
                                numButtons, numTriggers, numAxes, deviceId);
       openVRController->SetTrackedIndex(trackedDevice);
       mOpenVRController.AppendElement(openVRController);
 
+      // If the Windows MR controller doesn't has the amount
+      // of buttons or axes as our expectation, switching off
+      // the workaround for Windows MR.
+      if (mIsWindowsMR && (numAxes < 4 || numButtons < 5)) {
+        mIsWindowsMR = false;
+        NS_WARNING("OpenVR - Switching off Windows MR mode.");
+      }
       // Not already present, add it.
       AddGamepad(openVRController->GetControllerInfo());
       ++mControllerCount;
     }
   }
 }
 
 void
@@ -1211,42 +1218,42 @@ void
 VRSystemManagerOpenVR::GetControllerDeviceId(::vr::ETrackedDeviceClass aDeviceType,
                                              ::vr::TrackedDeviceIndex_t aDeviceIndex, nsCString& aId)
 {
   switch (aDeviceType) {
     case ::vr::TrackedDeviceClass_Controller:
     {
       ::vr::ETrackedPropertyError err;
       uint32_t requiredBufferLen;
-      bool founded = false;
+      bool isFound = false;
       char charBuf[128];
       requiredBufferLen = mVRSystem->GetStringTrackedDeviceProperty(aDeviceIndex,
                           ::vr::Prop_RenderModelName_String, charBuf, 128, &err);
       if (requiredBufferLen > 128) {
         MOZ_CRASH("Larger than the buffer size.");
       }
       MOZ_ASSERT(requiredBufferLen && err == ::vr::TrackedProp_Success);
       nsCString deviceId(charBuf);
       if (deviceId.Find("knuckles") != kNotFound) {
         aId.AssignLiteral("OpenVR Knuckles");
-        founded = true;
+        isFound = true;
       }
       requiredBufferLen = mVRSystem->GetStringTrackedDeviceProperty(aDeviceIndex,
         ::vr::Prop_SerialNumber_String, charBuf, 128, &err);
       if (requiredBufferLen > 128) {
         MOZ_CRASH("Larger than the buffer size.");
       }
       MOZ_ASSERT(requiredBufferLen && err == ::vr::TrackedProp_Success);
       deviceId.Assign(charBuf);
       if (deviceId.Find("MRSOURCE") != kNotFound) {
         aId.AssignLiteral("Spatial Controller (Spatial Interaction Source) ");
         mIsWindowsMR = true;
-        founded = true;
+        isFound = true;
       }
-      if (!founded) {
+      if (!isFound) {
         aId.AssignLiteral("OpenVR Gamepad");
       }
       break;
     }
     case ::vr::TrackedDeviceClass_GenericTracker:
     {
       aId.AssignLiteral("OpenVR Tracker");
       break;