Bug 1341516 - Fix Oculus Touch ID and poseState; r?kip draft
authorDaosheng Mu <daoshengmu@gmail.com>
Wed, 22 Feb 2017 12:13:30 +0800
changeset 487804 44383dcfde398fa6546a9503bbb594ff31749309
parent 487775 9f871c40b36f164a3413c5aea5c4434f080a7bf0
child 546554 82cd7dac4c894761b8992295ec09cd36afa665dd
push id46336
push userbmo:dmu@mozilla.com
push dateWed, 22 Feb 2017 05:54:56 +0000
reviewerskip
bugs1341516
milestone54.0a1
Bug 1341516 - Fix Oculus Touch ID and poseState; r?kip MozReview-Commit-ID: 9FoLcQmgxjg
gfx/vr/gfxVROculus.cpp
--- a/gfx/vr/gfxVROculus.cpp
+++ b/gfx/vr/gfxVROculus.cpp
@@ -831,20 +831,30 @@ VRDisplayOculus::NotifyVSync()
   ovrResult ovr = ovr_GetSessionStatus(mSession, &sessionStatus);
   mDisplayInfo.mIsConnected = (ovr == ovrSuccess && sessionStatus.HmdPresent);
 }
 
 VRControllerOculus::VRControllerOculus(dom::GamepadHand aHand)
   : VRControllerHost(VRDeviceType::Oculus)
 {
   MOZ_COUNT_CTOR_INHERITED(VRControllerOculus, VRControllerHost);
-  mControllerInfo.mControllerName.AssignLiteral("Oculus Touch (");
-  mControllerInfo.mControllerName.AppendPrintf("%s%s",
-                                               GamepadHandValues::strings[uint32_t(aHand)].value,
-                                               ")");
+
+  char* touchID = "";
+  switch (aHand) {
+    case dom::GamepadHand::Left:
+      touchID = "Oculus Touch (Left)";
+      break;
+    case dom::GamepadHand::Right:
+      touchID = "Oculus Touch (Right)";
+      break;
+    default:
+      MOZ_ASSERT(false);
+      break;
+  }
+  mControllerInfo.mControllerName = touchID;
   mControllerInfo.mMappingType = GamepadMappingType::_empty;
   mControllerInfo.mHand = aHand;
   mControllerInfo.mNumButtons = kNumOculusButton;
   mControllerInfo.mNumAxes = static_cast<uint32_t>(
                              OculusControllerAxisType::NumVRControllerAxisType);;
 }
 
 float
@@ -983,35 +993,38 @@ VRSystemManagerOculus::HandleInput()
     axis = static_cast<uint32_t>(OculusControllerAxisType::ThumbstickXAxis);
     HandleAxisMove(i, axis, inputState.Thumbstick[i].x);
 
     axis = static_cast<uint32_t>(OculusControllerAxisType::ThumbstickYAxis);
     HandleAxisMove(i, axis, -inputState.Thumbstick[i].y);
 
     // Start to process pose
     ovrTrackingState state = ovr_GetTrackingState(mSession, 0.0, false);
-    ovrPoseStatef& pose(state.HandPoses[i]);
+    // HandPoses is ordered by ovrControllerType_LTouch and ovrControllerType_RTouch,
+    // therefore, we can't get its state by the index of mOculusController.
+    const uint32_t handIdx = static_cast<uint32_t>(controller->GetHand()) - 1;
+    ovrPoseStatef& pose(state.HandPoses[handIdx]);
     GamepadPoseState poseState;
 
-    if (state.HandStatusFlags[i] & ovrStatus_OrientationTracked) {
+    if (state.HandStatusFlags[handIdx] & ovrStatus_OrientationTracked) {
       poseState.flags |= GamepadCapabilityFlags::Cap_Orientation;
       poseState.orientation[0] = pose.ThePose.Orientation.x;
       poseState.orientation[1] = pose.ThePose.Orientation.y;
       poseState.orientation[2] = pose.ThePose.Orientation.z;
       poseState.orientation[3] = pose.ThePose.Orientation.w;
       poseState.angularVelocity[0] = pose.AngularVelocity.x;
       poseState.angularVelocity[1] = pose.AngularVelocity.y;
       poseState.angularVelocity[2] = pose.AngularVelocity.z;
 
       poseState.flags |= GamepadCapabilityFlags::Cap_AngularAcceleration;
       poseState.angularAcceleration[0] = pose.AngularAcceleration.x;
       poseState.angularAcceleration[1] = pose.AngularAcceleration.y;
       poseState.angularAcceleration[2] = pose.AngularAcceleration.z;
     }
-    if (state.HandStatusFlags[i] & ovrStatus_PositionTracked) {
+    if (state.HandStatusFlags[handIdx] & ovrStatus_PositionTracked) {
       poseState.flags |= GamepadCapabilityFlags::Cap_Position;
       poseState.position[0] = pose.ThePose.Position.x;
       poseState.position[1] = pose.ThePose.Position.y;
       poseState.position[2] = pose.ThePose.Position.z;
       poseState.linearVelocity[0] = pose.LinearVelocity.x;
       poseState.linearVelocity[1] = pose.LinearVelocity.y;
       poseState.linearVelocity[2] = pose.LinearVelocity.z;
 
@@ -1034,20 +1047,20 @@ VRSystemManagerOculus::HandleButtonPress
   RefPtr<impl::VRControllerOculus> controller(mOculusController[aControllerIdx]);
   MOZ_ASSERT(controller);
   GamepadHand hand = controller->GetHand();
   uint64_t diff = (controller->GetButtonPressed() ^ aButtonPressed);
   uint32_t buttonMask = 0;
 
   for (uint32_t i = 0; i < kNumOculusButton; ++i) {
     switch (hand) {
-      case mozilla::dom::GamepadHand::Left:
+      case dom::GamepadHand::Left:
         buttonMask = kOculusTouchLButton[i];
         break;
-      case mozilla::dom::GamepadHand::Right:
+      case dom::GamepadHand::Right:
         buttonMask = kOculusTouchRButton[i];
         break;
       default:
         MOZ_ASSERT(false);
         break;
     }
     if (diff & buttonMask) {
       NewButtonEvent(aControllerIdx, i, diff & aButtonPressed);
@@ -1075,16 +1088,17 @@ VRSystemManagerOculus::HandleAxisMove(ui
   }
 }
 
 void
 VRSystemManagerOculus::HandlePoseTracking(uint32_t aControllerIdx,
                                           const GamepadPoseState& aPose,
                                           VRControllerHost* aController)
 {
+  MOZ_ASSERT(aController);
   if (aPose != aController->GetPose()) {
     aController->SetPose(aPose);
     NewPoseState(aControllerIdx, aPose);
   }
 }
 
 void
 VRSystemManagerOculus::GetControllers(nsTArray<RefPtr<VRControllerHost>>&