Bug 1356452 - Part 2: Replace vr:: namespace with ::vr:: in OpenVR; r=kip
authorDaosheng Mu <daoshengmu@gmail.com>
Tue, 18 Apr 2017 13:04:53 +0800
changeset 354035 b425dbaf939443c0c42a8eaf913299e38e0d396b
parent 354034 45597054d4e8fdbd83a0ea0b5edc21024f000de8
child 354036 fed55d5486d0c356f40d582447f811c223679f90
push id31685
push userkwierso@gmail.com
push dateThu, 20 Apr 2017 21:45:29 +0000
treeherdermozilla-central@5e3dc7e1288a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskip
bugs1356452
milestone55.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 1356452 - Part 2: Replace vr:: namespace with ::vr:: in OpenVR; r=kip MozReview-Commit-ID: uBvQ7hBI4z
gfx/vr/gfxVROpenVR.cpp
gfx/vr/gfxVROpenVR.h
--- a/gfx/vr/gfxVROpenVR.cpp
+++ b/gfx/vr/gfxVROpenVR.cpp
@@ -35,17 +35,17 @@
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 using namespace mozilla::gfx::impl;
 using namespace mozilla::layers;
 using namespace mozilla::dom;
 
 #define BTN_MASK_FROM_ID(_id) \
-  vr::ButtonMaskFromId(vr::EVRButtonId::_id)
+  ::vr::ButtonMaskFromId(vr::EVRButtonId::_id)
 
 static const uint32_t kNumOpenVRHaptcs = 1;
 
 VRDisplayOpenVR::VRDisplayOpenVR(::vr::IVRSystem *aVRSystem,
                                  ::vr::IVRChaperone *aVRChaperone,
                                  ::vr::IVRCompositor *aVRCompositor)
   : VRDisplayHost(VRDeviceType::OpenVR)
   , mVRSystem(aVRSystem)
@@ -337,29 +337,29 @@ VRDisplayOpenVR::NotifyVSync()
   // We update mIsConneced once per frame.
   mDisplayInfo.mIsConnected = ::vr::VR_IsHmdPresent();
 
   // Make sure we respond to OpenVR events even when not presenting
   PollEvents();
 }
 
 VRControllerOpenVR::VRControllerOpenVR(dom::GamepadHand aHand, uint32_t aNumButtons,
-                                       uint32_t aNumAxes, vr::ETrackedDeviceClass aDeviceType)
+                                       uint32_t aNumAxes, ::vr::ETrackedDeviceClass aDeviceType)
   : VRControllerHost(VRDeviceType::OpenVR)
   , mTrigger(0)
   , mVibrateThread(nullptr)
   , mIsVibrateStopped(false)
 {
   MOZ_COUNT_CTOR_INHERITED(VRControllerOpenVR, VRControllerHost);
 
   switch (aDeviceType) {
-    case vr::TrackedDeviceClass_Controller:
+    case ::vr::TrackedDeviceClass_Controller:
       mControllerInfo.mControllerName.AssignLiteral("OpenVR Gamepad");
       break;
-    case vr::TrackedDeviceClass_GenericTracker:
+    case ::vr::TrackedDeviceClass_GenericTracker:
       mControllerInfo.mControllerName.AssignLiteral("OpenVR Tracker");
       break;
     default:
       MOZ_ASSERT(false);
       break;
   }
 
   mControllerInfo.mMappingType = GamepadMappingType::_empty;
@@ -399,17 +399,18 @@ VRControllerOpenVR::SetTrigger(float aVa
 
 float
 VRControllerOpenVR::GetTrigger()
 {
   return mTrigger;
 }
 
 void
-VRControllerOpenVR::UpdateVibrateHaptic(vr::IVRSystem* aVRSystem,
+void
+VRControllerOpenVR::UpdateVibrateHaptic(::vr::IVRSystem* aVRSystem,
                                         uint32_t aHapticIndex,
                                         double aIntensity,
                                         double aDuration,
                                         uint64_t aVibrateIndex,
                                         uint32_t aPromiseID)
 {
   // UpdateVibrateHaptic() only can be called by mVibrateThread
   MOZ_ASSERT(mVibrateThread == NS_GetCurrentThread());
@@ -435,17 +436,17 @@ VRControllerOpenVR::UpdateVibrateHaptic(
 
   // In OpenVR spec, it mentions TriggerHapticPulse() may not trigger another haptic pulse
   // on this controller and axis combination for 5ms.
   const double kVibrateRate = 5.0;
   if (duration >= kVibrateRate) {
     MOZ_ASSERT(mVibrateThread);
 
     RefPtr<Runnable> runnable =
-      NewRunnableMethod<vr::IVRSystem*, uint32_t, double, double, uint64_t, uint32_t>
+      NewRunnableMethod<::vr::IVRSystem*, uint32_t, double, double, uint64_t, uint32_t>
         (this, &VRControllerOpenVR::UpdateVibrateHaptic, aVRSystem,
          aHapticIndex, aIntensity, duration - kVibrateRate, aVibrateIndex, aPromiseID);
     NS_DelayedDispatchToCurrentThread(runnable.forget(), kVibrateRate);
   } else {
     // The pulse has completed
     VibrateHapticComplete(aPromiseID);
   }
 }
@@ -456,17 +457,17 @@ VRControllerOpenVR::VibrateHapticComplet
   VRManager *vm = VRManager::Get();
   MOZ_ASSERT(vm);
 
   CompositorThreadHolder::Loop()->PostTask(NewRunnableMethod<uint32_t>
     (vm, &VRManager::NotifyVibrateHapticCompleted, aPromiseID));
 }
 
 void
-VRControllerOpenVR::VibrateHaptic(vr::IVRSystem* aVRSystem,
+VRControllerOpenVR::VibrateHaptic(::vr::IVRSystem* aVRSystem,
                                   uint32_t aHapticIndex,
                                   double aIntensity,
                                   double aDuration,
                                   uint32_t aPromiseID)
 {
   // Spinning up the haptics thread at the first haptics call.
   if (!mVibrateThread) {
     nsresult rv = NS_NewThread(getter_AddRefs(mVibrateThread));
@@ -475,17 +476,17 @@ VRControllerOpenVR::VibrateHaptic(vr::IV
     if (NS_FAILED(rv)) {
       MOZ_ASSERT(false, "Failed to create async thread.");
     }
   }
   ++mVibrateIndex;
   mIsVibrateStopped = false;
 
   RefPtr<Runnable> runnable =
-      NewRunnableMethod<vr::IVRSystem*, uint32_t, double, double, uint64_t, uint32_t>
+      NewRunnableMethod<::vr::IVRSystem*, uint32_t, double, double, uint64_t, uint32_t>
         (this, &VRControllerOpenVR::UpdateVibrateHaptic, aVRSystem,
          aHapticIndex, aIntensity, aDuration, mVibrateIndex, aPromiseID);
   mVibrateThread->Dispatch(runnable.forget(), NS_DISPATCH_NORMAL);
 }
 
 void
 VRControllerOpenVR::StopVibrateHaptic()
 {
@@ -586,67 +587,67 @@ VRSystemManagerOpenVR::HandleInput()
 {
   // mVRSystem is available after VRDisplay is created
   // at GetHMDs().
   if (!mVRSystem) {
     return;
   }
 
   RefPtr<impl::VRControllerOpenVR> controller;
-  vr::VRControllerState_t state;
-  vr::TrackedDevicePose_t poses[vr::k_unMaxTrackedDeviceCount];
-  mVRSystem->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseSeated, 0.0f,
-                                             poses, vr::k_unMaxTrackedDeviceCount);
+  ::vr::VRControllerState_t state;
+  ::vr::TrackedDevicePose_t poses[::vr::k_unMaxTrackedDeviceCount];
+  mVRSystem->GetDeviceToAbsoluteTrackingPose(::vr::TrackingUniverseSeated, 0.0f,
+                                             poses, ::vr::k_unMaxTrackedDeviceCount);
   // Process OpenVR controller state
   for (uint32_t i = 0; i < mOpenVRController.Length(); ++i) {
     uint32_t axisIdx = 0;
     uint32_t buttonIdx = 0;
     controller = mOpenVRController[i];
     const uint32_t trackedIndex = controller->GetTrackedIndex();
 
     MOZ_ASSERT(mVRSystem->GetTrackedDeviceClass(trackedIndex)
-               == vr::TrackedDeviceClass_Controller ||
+               == ::vr::TrackedDeviceClass_Controller ||
                mVRSystem->GetTrackedDeviceClass(trackedIndex)
-               == vr::TrackedDeviceClass_GenericTracker);
+               == ::vr::TrackedDeviceClass_GenericTracker);
 
     if (mVRSystem->GetControllerState(trackedIndex, &state, sizeof(state))) {
-      for (uint32_t j = 0; j < vr::k_unControllerStateAxisCount; ++j) {
+      for (uint32_t j = 0; j < ::vr::k_unControllerStateAxisCount; ++j) {
         const uint32_t axisType = mVRSystem->GetInt32TrackedDeviceProperty(
                                    trackedIndex,
-                                   static_cast<vr::TrackedDeviceProperty>(
-                                   vr::Prop_Axis0Type_Int32 + j));
+                                   static_cast<::vr::TrackedDeviceProperty>(
+                                   ::vr::Prop_Axis0Type_Int32 + j));
         switch (axisType) {
-          case vr::EVRControllerAxisType::k_eControllerAxis_Joystick:
-          case vr::EVRControllerAxisType::k_eControllerAxis_TrackPad:
+          case ::vr::EVRControllerAxisType::k_eControllerAxis_Joystick:
+          case ::vr::EVRControllerAxisType::k_eControllerAxis_TrackPad:
             HandleAxisMove(i, axisIdx,
                            state.rAxis[j].x);
             ++axisIdx;
             HandleAxisMove(i, axisIdx,
                            state.rAxis[j].y);
             ++axisIdx;
             HandleButtonPress(i, buttonIdx,
-                              vr::ButtonMaskFromId(
-                               static_cast<vr::EVRButtonId>(vr::k_EButton_Axis0 + j)),
-                              state.ulButtonPressed, state.ulButtonTouched);
+                              ::vr::ButtonMaskFromId(
+                                 static_cast<::vr::EVRButtonId>(::vr::k_EButton_Axis0 + j)),
+                                 state.ulButtonPressed, state.ulButtonTouched);
             ++buttonIdx;
             break;
-          case vr::EVRControllerAxisType::k_eControllerAxis_Trigger:
+          case ::vr::EVRControllerAxisType::k_eControllerAxis_Trigger:
             HandleTriggerPress(i, buttonIdx,
-                               vr::ButtonMaskFromId(
-                                static_cast<vr::EVRButtonId>(vr::k_EButton_Axis0 + j)),
-                               state.rAxis[j].x, state.ulButtonPressed, state.ulButtonTouched);
+                               ::vr::ButtonMaskFromId(
+                                static_cast<::vr::EVRButtonId>(::vr::k_EButton_Axis0 + j)),
+                                state.rAxis[j].x, state.ulButtonPressed, state.ulButtonTouched);
             ++buttonIdx;
             break;
         }
       }
       MOZ_ASSERT(axisIdx ==
                  controller->GetControllerInfo().GetNumAxes());
 
       const uint64_t supportedButtons = mVRSystem->GetUint64TrackedDeviceProperty(
-                                         trackedIndex, vr::Prop_SupportedButtons_Uint64);
+                                         trackedIndex, ::vr::Prop_SupportedButtons_Uint64);
       if (supportedButtons &
           BTN_MASK_FROM_ID(k_EButton_A)) {
         HandleButtonPress(i, buttonIdx,
                           BTN_MASK_FROM_ID(k_EButton_A),
                           state.ulButtonPressed, state.ulButtonTouched);
         ++buttonIdx;
       }
       if (supportedButtons &
@@ -695,17 +696,17 @@ VRSystemManagerOpenVR::HandleInput()
                  controller->GetControllerInfo().GetNumButtons());
       controller->SetButtonPressed(state.ulButtonPressed);
       controller->SetButtonTouched(state.ulButtonTouched);
 
       // Start to process pose
       const ::vr::TrackedDevicePose_t& pose = poses[trackedIndex];
 
       if (pose.bDeviceIsConnected && pose.bPoseIsValid &&
-        pose.eTrackingResult == vr::TrackingResult_Running_OK) {
+        pose.eTrackingResult == ::vr::TrackingResult_Running_OK) {
         gfx::Matrix4x4 m;
 
         // NOTE! mDeviceToAbsoluteTracking is a 3x4 matrix, not 4x4.  But
         // because of its arrangement, we can copy the 12 elements in and
         // then transpose them to the right place.  We do this so we can
         // pull out a Quaternion.
         memcpy(&m.components, &pose.mDeviceToAbsoluteTracking, sizeof(float) * 12);
         m.Transpose();
@@ -856,88 +857,77 @@ void
 VRSystemManagerOpenVR::ScanForControllers()
 {
   // mVRSystem is available after VRDisplay is created
   // at GetHMDs().
   if (!mVRSystem) {
     return;
   }
 
-  vr::TrackedDeviceIndex_t trackedIndexArray[vr::k_unMaxTrackedDeviceCount];
+  ::vr::TrackedDeviceIndex_t trackedIndexArray[::vr::k_unMaxTrackedDeviceCount];
   uint32_t newControllerCount = 0;
-  vr::ETrackedDeviceClass deviceType;
+  ::vr::ETrackedDeviceClass deviceType;
   // Basically, we would have HMDs in the tracked devices,
   // but we are just interested in the controllers.
-  for (vr::TrackedDeviceIndex_t trackedDevice = vr::k_unTrackedDeviceIndex_Hmd + 1;
-       trackedDevice < vr::k_unMaxTrackedDeviceCount; ++trackedDevice) {
+  for (::vr::TrackedDeviceIndex_t trackedDevice = ::vr::k_unTrackedDeviceIndex_Hmd + 1;
+       trackedDevice < ::vr::k_unMaxTrackedDeviceCount; ++trackedDevice) {
 
     if (!mVRSystem->IsTrackedDeviceConnected(trackedDevice)) {
       continue;
     }
 
     deviceType = mVRSystem->GetTrackedDeviceClass(trackedDevice);
-    if (deviceType != vr::TrackedDeviceClass_Controller
-        && deviceType != vr::TrackedDeviceClass_GenericTracker) {
+    if (deviceType != ::vr::TrackedDeviceClass_Controller
+        && deviceType != ::vr::TrackedDeviceClass_GenericTracker) {
       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();
 
     // Re-adding controllers to VRControllerManager.
-    for (vr::TrackedDeviceIndex_t i = 0; i < newControllerCount; ++i) {
-      const vr::TrackedDeviceIndex_t trackedDevice = trackedIndexArray[i];
-      const vr::ETrackedControllerRole role = mVRSystem->
+    for (::vr::TrackedDeviceIndex_t i = 0; i < newControllerCount; ++i) {
+      const ::vr::TrackedDeviceIndex_t trackedDevice = trackedIndexArray[i];
+      const ::vr::ETrackedControllerRole role = mVRSystem->
                                                GetControllerRoleForTrackedDeviceIndex(
                                                trackedDevice);
-      GamepadHand hand;
+
       uint32_t numButtons = 0;
       uint32_t numAxes = 0;
-
-      switch(role) {
-        case vr::ETrackedControllerRole::TrackedControllerRole_Invalid:
-          hand = GamepadHand::_empty;
-          break;
-        case vr::ETrackedControllerRole::TrackedControllerRole_LeftHand:
-          hand = GamepadHand::Left;
-          break;
-        case vr::ETrackedControllerRole::TrackedControllerRole_RightHand:
-          hand = GamepadHand::Right;
-          break;
-      }
+      const GamepadHand hand = GetGamepadHandFromControllerRole(role);
 
       // Scan the axes that the controllers support
-      for (uint32_t j = 0; j < vr::k_unControllerStateAxisCount; ++j) {
+      for (uint32_t j = 0; j < ::vr::k_unControllerStateAxisCount; ++j) {
         const uint32_t supportAxis = mVRSystem->GetInt32TrackedDeviceProperty(trackedDevice,
                                       static_cast<vr::TrackedDeviceProperty>(
-                                      vr::Prop_Axis0Type_Int32 + j));
+                                      ::vr::Prop_Axis0Type_Int32 + j));
         switch (supportAxis) {
-          case vr::EVRControllerAxisType::k_eControllerAxis_Joystick:
-          case vr::EVRControllerAxisType::k_eControllerAxis_TrackPad:
+          case ::vr::EVRControllerAxisType::k_eControllerAxis_Joystick:
+          case ::vr::EVRControllerAxisType::k_eControllerAxis_TrackPad:
             numAxes += 2; // It has x and y axes.
             ++numButtons;
             break;
-          case vr::k_eControllerAxis_Trigger:
+          case ::vr::k_eControllerAxis_Trigger:
             ++numButtons;
             break;
         }
       }
 
       // Scan the buttons that the controllers support
       const uint64_t supportButtons = mVRSystem->GetUint64TrackedDeviceProperty(
-                                       trackedDevice, vr::Prop_SupportedButtons_Uint64);
+                                       trackedDevice, ::vr::Prop_SupportedButtons_Uint64);
       if (supportButtons &
           BTN_MASK_FROM_ID(k_EButton_A)) {
         ++numButtons;
       }
       if (supportButtons &
           BTN_MASK_FROM_ID(k_EButton_Grip)) {
         ++numButtons;
       }
--- a/gfx/vr/gfxVROpenVR.h
+++ b/gfx/vr/gfxVROpenVR.h
@@ -61,41 +61,41 @@ protected:
   void UpdateStageParameters();
   void PollEvents();
 };
 
 class VRControllerOpenVR : public VRControllerHost
 {
 public:
   explicit VRControllerOpenVR(dom::GamepadHand aHand, uint32_t aNumButtons,
-                              uint32_t aNumAxes, vr::ETrackedDeviceClass aDeviceType);
+                              uint32_t aNumAxes, ::vr::ETrackedDeviceClass aDeviceType);
   void SetTrackedIndex(uint32_t aTrackedIndex);
   uint32_t GetTrackedIndex();
   void SetTrigger(float aValue);
   float GetTrigger();
-  void VibrateHaptic(vr::IVRSystem* aVRSystem,
+  void VibrateHaptic(::vr::IVRSystem* aVRSystem,
                      uint32_t aHapticIndex,
                      double aIntensity,
                      double aDuration,
                      uint32_t aPromiseID);
   void StopVibrateHaptic();
 
 protected:
   virtual ~VRControllerOpenVR();
 
 private:
-  void UpdateVibrateHaptic(vr::IVRSystem* aVRSystem,
+  void UpdateVibrateHaptic(::vr::IVRSystem* aVRSystem,
                            uint32_t aHapticIndex,
                            double aIntensity,
                            double aDuration,
                            uint64_t aVibrateIndex,
                            uint32_t aPromiseID);
   void VibrateHapticComplete(uint32_t aPromiseID);
 
-  // The index of tracked devices from vr::IVRSystem.
+  // The index of tracked devices from ::vr::IVRSystem.
   uint32_t mTrackedIndex;
   float mTrigger;
   nsCOMPtr<nsIThread> mVibrateThread;
   Atomic<bool> mIsVibrateStopped;
 };
 
 } // namespace impl
 
@@ -135,20 +135,22 @@ private:
                           float aValue,
                           uint64_t aButtonPressed,
                           uint64_t aButtonTouched);
   void HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
                       float aValue);
   void HandlePoseTracking(uint32_t aControllerIdx,
                           const dom::GamepadPoseState& aPose,
                           VRControllerHost* aController);
+  dom::GamepadHand GetGamepadHandFromControllerRole(
+                          ::vr::ETrackedControllerRole aRole);
 
   // there can only be one
   RefPtr<impl::VRDisplayOpenVR> mOpenVRHMD;
   nsTArray<RefPtr<impl::VRControllerOpenVR>> mOpenVRController;
-  vr::IVRSystem *mVRSystem;
+  ::vr::IVRSystem *mVRSystem;
 };
 
 } // namespace gfx
 } // namespace mozilla
 
 
 #endif /* GFX_VR_OPENVR_H */