Bug 1375816 - Part 3: VRController displayId attribute support; r=kip
authorDaosheng Mu <daoshengmu@gmail.com>
Fri, 14 Jul 2017 17:01:09 +0800
changeset 418208 8bebd50ee61baf7602a49712ed047deea8e2249c
parent 418207 a77053bac9a9c22662f84c692e7697f0b81a23ff
child 418209 61d6383a750a14d2f2e2b2381a06f2b9f5286caa
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskip
bugs1375816
milestone56.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 1375816 - Part 3: VRController displayId attribute support; r=kip MozReview-Commit-ID: CfWCYJuZaBK
gfx/vr/VRDisplayHost.cpp
gfx/vr/VRDisplayHost.h
gfx/vr/gfxVR.cpp
gfx/vr/gfxVR.h
gfx/vr/gfxVROculus.cpp
gfx/vr/gfxVROculus.h
gfx/vr/gfxVROpenVR.cpp
gfx/vr/gfxVROpenVR.h
--- a/gfx/vr/VRDisplayHost.cpp
+++ b/gfx/vr/VRDisplayHost.cpp
@@ -230,22 +230,26 @@ VRDisplayHost::CheckClearDisplayInfoDirt
 {
   if (mDisplayInfo == mLastUpdateDisplayInfo) {
     return false;
   }
   mLastUpdateDisplayInfo = mDisplayInfo;
   return true;
 }
 
-VRControllerHost::VRControllerHost(VRDeviceType aType)
+VRControllerHost::VRControllerHost(VRDeviceType aType, dom::GamepadHand aHand,
+                                   uint32_t aDisplayID)
  : mVibrateIndex(0)
 {
   MOZ_COUNT_CTOR(VRControllerHost);
   mControllerInfo.mType = aType;
-  mControllerInfo.mControllerID = VRSystemManager::AllocateDisplayID();
+  mControllerInfo.mHand = aHand;
+  mControllerInfo.mMappingType = dom::GamepadMappingType::_empty;
+  mControllerInfo.mDisplayID = aDisplayID;
+  mControllerInfo.mControllerID = VRSystemManager::AllocateControllerID();
 }
 
 VRControllerHost::~VRControllerHost()
 {
   MOZ_COUNT_DTOR(VRControllerHost);
 }
 
 const VRControllerInfo&
--- a/gfx/vr/VRDisplayHost.h
+++ b/gfx/vr/VRDisplayHost.h
@@ -93,17 +93,18 @@ public:
   uint64_t GetButtonTouched();
   void SetPose(const dom::GamepadPoseState& aPose);
   const dom::GamepadPoseState& GetPose();
   dom::GamepadHand GetHand();
   void SetVibrateIndex(uint64_t aIndex);
   uint64_t GetVibrateIndex();
 
 protected:
-  explicit VRControllerHost(VRDeviceType aType);
+  explicit VRControllerHost(VRDeviceType aType, dom::GamepadHand aHand,
+                            uint32_t aDisplayID);
   virtual ~VRControllerHost();
 
   VRControllerInfo mControllerInfo;
   // The current button pressed bit of button mask.
   uint64_t mButtonPressed;
   // The current button touched bit of button mask.
   uint64_t mButtonTouched;
   uint64_t mVibrateIndex;
--- a/gfx/vr/gfxVR.cpp
+++ b/gfx/vr/gfxVR.cpp
@@ -12,23 +12,30 @@
 #ifndef M_PI
 # define M_PI 3.14159265358979323846
 #endif
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 
 Atomic<uint32_t> VRSystemManager::sDisplayBase(0);
+Atomic<uint32_t> VRSystemManager::sControllerBase(0);
 
 /* static */ uint32_t
 VRSystemManager::AllocateDisplayID()
 {
   return ++sDisplayBase;
 }
 
+/* static */ uint32_t
+VRSystemManager::AllocateControllerID()
+{
+  return ++sControllerBase;
+}
+
 Matrix4x4
 VRFieldOfView::ConstructProjectionMatrix(float zNear, float zFar,
                                          bool rightHanded) const
 {
   float upTan = tan(upDegrees * M_PI / 180.0);
   float downTan = tan(downDegrees * M_PI / 180.0);
   float leftTan = tan(leftDegrees * M_PI / 180.0);
   float rightTan = tan(rightDegrees * M_PI / 180.0);
@@ -61,16 +68,17 @@ VRFieldOfView::ConstructProjectionMatrix
 void
 VRSystemManager::AddGamepad(const VRControllerInfo& controllerInfo)
 {
   dom::GamepadAdded a(NS_ConvertUTF8toUTF16(controllerInfo.GetControllerName()),
                       mControllerCount,
                       controllerInfo.GetMappingType(),
                       controllerInfo.GetHand(),
                       dom::GamepadServiceType::VR,
+                      controllerInfo.GetDisplayID(),
                       controllerInfo.GetNumButtons(),
                       controllerInfo.GetNumAxes(),
                       controllerInfo.GetNumHaptics());
 
   VRManager* vm = VRManager::Get();
   vm->NotifyGamepadChange<dom::GamepadAdded>(a);
 }
 
--- a/gfx/vr/gfxVR.h
+++ b/gfx/vr/gfxVR.h
@@ -273,52 +273,57 @@ struct VRSubmitFrameResultInfo
 };
 
 struct VRControllerInfo
 {
   VRDeviceType GetType() const { return mType; }
   uint32_t GetControllerID() const { return mControllerID; }
   const nsCString& GetControllerName() const { return mControllerName; }
   dom::GamepadMappingType GetMappingType() const { return mMappingType; }
+  uint32_t GetDisplayID() const { return mDisplayID; }
   dom::GamepadHand GetHand() const { return mHand; }
   uint32_t GetNumButtons() const { return mNumButtons; }
   uint32_t GetNumAxes() const { return mNumAxes; }
   uint32_t GetNumHaptics() const { return mNumHaptics; }
 
   uint32_t mControllerID;
   VRDeviceType mType;
   nsCString mControllerName;
   dom::GamepadMappingType mMappingType;
+  uint32_t mDisplayID;
   dom::GamepadHand mHand;
   uint32_t mNumButtons;
   uint32_t mNumAxes;
   uint32_t mNumHaptics;
 
   bool operator==(const VRControllerInfo& other) const {
     return mType == other.mType &&
            mControllerID == other.mControllerID &&
            mControllerName == other.mControllerName &&
            mMappingType == other.mMappingType &&
+           mDisplayID == other.mDisplayID &&
            mHand == other.mHand &&
            mNumButtons == other.mNumButtons &&
            mNumAxes == other.mNumAxes &&
            mNumHaptics == other.mNumHaptics;
   }
 
   bool operator!=(const VRControllerInfo& other) const {
     return !(*this == other);
   }
 };
 
 class VRSystemManager {
 public:
   static uint32_t AllocateDisplayID();
+  static uint32_t AllocateControllerID();
 
 protected:
   static Atomic<uint32_t> sDisplayBase;
+  static Atomic<uint32_t> sControllerBase;
 
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRSystemManager)
 
   virtual void Destroy() = 0;
   virtual void Shutdown() = 0;
   virtual bool GetHMDs(nsTArray<RefPtr<VRDisplayHost>>& aHMDResult) = 0;
   virtual bool GetIsPresenting() = 0;
--- a/gfx/vr/gfxVROculus.cpp
+++ b/gfx/vr/gfxVROculus.cpp
@@ -1175,18 +1175,18 @@ VRDisplayOculus::NotifyVSync()
     mDisplayInfo.mIsConnected = (ovr == ovrSuccess && sessionStatus.HmdPresent);
   } else {
     mDisplayInfo.mIsConnected = false;
   }
 
   VRDisplayHost::NotifyVSync();
 }
 
-VRControllerOculus::VRControllerOculus(dom::GamepadHand aHand)
-  : VRControllerHost(VRDeviceType::Oculus)
+VRControllerOculus::VRControllerOculus(dom::GamepadHand aHand, uint32_t aDisplayID)
+  : VRControllerHost(VRDeviceType::Oculus, aHand, aDisplayID)
   , mIndexTrigger(0.0f)
   , mHandTrigger(0.0f)
   , mVibrateThread(nullptr)
   , mIsVibrateStopped(false)
 {
   MOZ_COUNT_CTOR_INHERITED(VRControllerOculus, VRControllerHost);
 
   char* touchID = "";
@@ -1197,18 +1197,16 @@ VRControllerOculus::VRControllerOculus(d
     case dom::GamepadHand::Right:
       touchID = "Oculus Touch (Right)";
       break;
     default:
       MOZ_ASSERT(false);
       break;
   }
   mControllerInfo.mControllerName = touchID;
-  mControllerInfo.mMappingType = GamepadMappingType::_empty;
-  mControllerInfo.mHand = aHand;
 
   MOZ_ASSERT(kNumOculusButton ==
              static_cast<uint32_t>(OculusLeftControllerButtonType::NumButtonType)
              && kNumOculusButton ==
              static_cast<uint32_t>(OculusRightControllerButtonType::NumButtonType));
 
   mControllerInfo.mNumButtons = kNumOculusButton;
   mControllerInfo.mNumAxes = static_cast<uint32_t>(
@@ -1791,17 +1789,18 @@ VRSystemManagerOculus::ScanForController
       switch (activeControllerArray[i]) {
         case ovrControllerType::ovrControllerType_LTouch:
           hand = GamepadHand::Left;
           break;
         case ovrControllerType::ovrControllerType_RTouch:
           hand = GamepadHand::Right;
           break;
       }
-      RefPtr<VRControllerOculus> oculusController = new VRControllerOculus(hand);
+      RefPtr<VRControllerOculus> oculusController = new VRControllerOculus(hand,
+                                                      mDisplay->GetDisplayInfo().GetDisplayID());
       mOculusController.AppendElement(oculusController);
 
       // Not already present, add it.
       AddGamepad(oculusController->GetControllerInfo());
       ++mControllerCount;
     }
   }
 }
--- a/gfx/vr/gfxVROculus.h
+++ b/gfx/vr/gfxVROculus.h
@@ -126,17 +126,17 @@ protected:
   {
     float position[2];
   };
 };
 
 class VRControllerOculus : public VRControllerHost
 {
 public:
-  explicit VRControllerOculus(dom::GamepadHand aHand);
+  explicit VRControllerOculus(dom::GamepadHand aHand, uint32_t aDisplayID);
   float GetAxisMove(uint32_t aAxis);
   void SetAxisMove(uint32_t aAxis, float aValue);
   float GetIndexTrigger();
   void SetIndexTrigger(float aValue);
   float GetHandTrigger();
   void SetHandTrigger(float aValue);
   void VibrateHaptic(ovrSession aSession,
                      uint32_t aHapticIndex,
--- a/gfx/vr/gfxVROpenVR.cpp
+++ b/gfx/vr/gfxVROpenVR.cpp
@@ -333,19 +333,20 @@ VRDisplayOpenVR::NotifyVSync()
   mDisplayInfo.mIsConnected = ::vr::VR_IsHmdPresent();
 
   // Make sure we respond to OpenVR events even when not presenting
   PollEvents();
 
   VRDisplayHost::NotifyVSync();
 }
 
-VRControllerOpenVR::VRControllerOpenVR(dom::GamepadHand aHand, uint32_t aNumButtons,
-                                       uint32_t aNumAxes, ::vr::ETrackedDeviceClass aDeviceType)
-  : VRControllerHost(VRDeviceType::OpenVR)
+VRControllerOpenVR::VRControllerOpenVR(dom::GamepadHand aHand, uint32_t aDisplayID,
+                                       uint32_t aNumButtons, uint32_t aNumAxes,
+                                       ::vr::ETrackedDeviceClass aDeviceType)
+  : VRControllerHost(VRDeviceType::OpenVR, aHand, aDisplayID)
   , mTrigger(0)
   , mAxisMove(aNumAxes)
   , mVibrateThread(nullptr)
   , mIsVibrateStopped(false)
 {
   MOZ_COUNT_CTOR_INHERITED(VRControllerOpenVR, VRControllerHost);
 
   switch (aDeviceType) {
@@ -356,18 +357,16 @@ VRControllerOpenVR::VRControllerOpenVR(d
       mControllerInfo.mControllerName.AssignLiteral("OpenVR Tracker");
       break;
     default:
       MOZ_ASSERT(false);
       break;
   }
 
   mAxisMove.SetLengthAndRetainStorage(aNumAxes);
-  mControllerInfo.mMappingType = GamepadMappingType::_empty;
-  mControllerInfo.mHand = aHand;
   mControllerInfo.mNumButtons = aNumButtons;
   mControllerInfo.mNumAxes = aNumAxes;
   mControllerInfo.mNumHaptics = kNumOpenVRHaptcs;
 }
 
 VRControllerOpenVR::~VRControllerOpenVR()
 {
   if (mVibrateThread) {
@@ -1007,17 +1006,18 @@ VRSystemManagerOpenVR::ScanForController
         ++numButtons;
       }
       if (supportButtons &
           BTN_MASK_FROM_ID(k_EButton_DPad_Down)) {
         ++numButtons;
       }
 
       RefPtr<VRControllerOpenVR> openVRController =
-        new VRControllerOpenVR(hand, numButtons, numAxes, deviceType);
+        new VRControllerOpenVR(hand, mOpenVRHMD->GetDisplayInfo().GetDisplayID(),
+                               numButtons, numAxes, deviceType);
       openVRController->SetTrackedIndex(trackedDevice);
       mOpenVRController.AppendElement(openVRController);
 
       // Not already present, add it.
       AddGamepad(openVRController->GetControllerInfo());
       ++mControllerCount;
     }
   }
--- a/gfx/vr/gfxVROpenVR.h
+++ b/gfx/vr/gfxVROpenVR.h
@@ -58,18 +58,19 @@ protected:
 
   void UpdateStageParameters();
   void PollEvents();
 };
 
 class VRControllerOpenVR : public VRControllerHost
 {
 public:
-  explicit VRControllerOpenVR(dom::GamepadHand aHand, uint32_t aNumButtons,
-                              uint32_t aNumAxes, ::vr::ETrackedDeviceClass aDeviceType);
+  explicit VRControllerOpenVR(dom::GamepadHand aHand, uint32_t aDisplayID,
+                              uint32_t aNumButtons, uint32_t aNumAxes,
+                              ::vr::ETrackedDeviceClass aDeviceType);
   void SetTrackedIndex(uint32_t aTrackedIndex);
   uint32_t GetTrackedIndex();
   float GetAxisMove(uint32_t aAxis);
   void SetAxisMove(uint32_t aAxis, float aValue);
   void SetTrigger(float aValue);
   float GetTrigger();
   void SetHand(dom::GamepadHand aHand);
   void VibrateHaptic(::vr::IVRSystem* aVRSystem,