Bug 1341516 - Fix Oculus Touch ID and poseState; r=kip
authorDaosheng Mu <daoshengmu@gmail.com>
Wed, 22 Feb 2017 12:13:30 +0800
changeset 390772 004930dad76110abb1fe9536ea9d0c840f5c39b2
parent 390771 6132f6422a9dd00462cc738348d2364905c8c4c0
child 390773 412c2a1e69dae05d3fad19825e37a1f9dcb4c5bd
push id7198
push userjlorenzo@mozilla.com
push dateTue, 18 Apr 2017 12:07:49 +0000
treeherdermozilla-beta@d57aa49c3948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskip
bugs1341516
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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>>&