Bug 1299929 - Part 2: Add extra info for VRController; r?kip draft
authorDaosheng Mu <daoshengmu@gmail.com>
Thu, 13 Oct 2016 14:30:26 +0800
changeset 426796 2e26133635176e864dd4bd240475843c18ed4bbe
parent 426795 d2cca7254c39856d7b55d16714b1b13a075f7e94
child 426797 af28fe9f3a21eafbf46614cc8951c0bad7e53ef9
child 427301 96febc4f32503ee22d5778b34e637bdc69d261c2
push id32801
push userbmo:dmu@mozilla.com
push dateWed, 19 Oct 2016 03:35:34 +0000
reviewerskip
bugs1299929
milestone52.0a1
Bug 1299929 - Part 2: Add extra info for VRController; r?kip MozReview-Commit-ID: 5y8X5ZPnsHb
gfx/vr/VRDisplayHost.cpp
gfx/vr/VRDisplayHost.h
gfx/vr/gfxVROpenVR.cpp
gfx/vr/gfxVROpenVR.h
--- a/gfx/vr/VRDisplayHost.cpp
+++ b/gfx/vr/VRDisplayHost.cpp
@@ -150,9 +150,27 @@ VRControllerHost::VRControllerHost(VRDev
   MOZ_COUNT_CTOR(VRControllerHost);
   mControllerInfo.mType = aType;
   mControllerInfo.mControllerID = VRDisplayManager::AllocateDisplayID();
 }
 
 VRControllerHost::~VRControllerHost()
 {
   MOZ_COUNT_DTOR(VRControllerHost);
+}
+
+const VRControllerInfo&
+VRControllerHost::GetControllerInfo() const
+{
+  return mControllerInfo;
+}
+
+void
+VRControllerHost::SetIndex(uint32_t aIndex)
+{
+  mIndex = aIndex;
+}
+
+uint32_t
+VRControllerHost::GetIndex()
+{
+  return mIndex;
 }
\ No newline at end of file
--- a/gfx/vr/VRDisplayHost.h
+++ b/gfx/vr/VRDisplayHost.h
@@ -82,21 +82,25 @@ protected:
 private:
   VRDisplayInfo mLastUpdateDisplayInfo;
 };
 
 class VRControllerHost {
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRControllerHost)
 
-  const VRControllerInfo& GetControllerInfo() const { return mControllerInfo; }
+  const VRControllerInfo& GetControllerInfo() const;
+  void SetIndex(uint32_t aIndex);
+  uint32_t GetIndex();
 
 protected:
   explicit VRControllerHost(VRDeviceType aType);
   virtual ~VRControllerHost();
 
   VRControllerInfo mControllerInfo;
+  // The controller index in VRControllerManager.
+  uint32_t mIndex;
 };
 
 } // namespace gfx
 } // namespace mozilla
 
 #endif /* GFX_VR_DISPLAY_HOST_H */
--- a/gfx/vr/gfxVROpenVR.cpp
+++ b/gfx/vr/gfxVROpenVR.cpp
@@ -450,16 +450,28 @@ VRControllerOpenVR::VRControllerOpenVR()
   mControllerInfo.mControllerName.AssignLiteral("OpenVR HMD");
 }
 
 VRControllerOpenVR::~VRControllerOpenVR()
 {
   MOZ_COUNT_DTOR_INHERITED(VRControllerOpenVR, VRControllerHost);
 }
 
+void
+VRControllerOpenVR::SetTrackedIndex(uint32_t aTrackedIndex)
+{
+  mTrackedIndex = aTrackedIndex;
+}
+
+uint32_t
+VRControllerOpenVR::GetTrackedIndex()
+{
+  return mTrackedIndex;
+}
+
 VRControllerManagerOpenVR::VRControllerManagerOpenVR()
   : mOpenVRInstalled(false), mVRSystem(nullptr)
 {
 }
 
 VRControllerManagerOpenVR::~VRControllerManagerOpenVR()
 {
   Destroy();
@@ -568,16 +580,18 @@ VRControllerManagerOpenVR::ScanForDevice
       continue;
     }
 
     if (mVRSystem->GetTrackedDeviceClass(trackedDevice) != vr::TrackedDeviceClass_Controller) {
       continue;
     }
 
     RefPtr<VRControllerOpenVR> openVRController = new VRControllerOpenVR();
+    openVRController->SetIndex(mControllerCount);
+    openVRController->SetTrackedIndex(trackedDevice);
     mOpenVRController.AppendElement(openVRController);
 
     // Not already present, add it.
     AddGamepad("OpenVR Gamepad", GamepadMappingType::_empty,
                kOpenVRControllerAxes, kOpenVRControllerButtons);
     ++mControllerCount;
   }
 }
\ No newline at end of file
--- a/gfx/vr/gfxVROpenVR.h
+++ b/gfx/vr/gfxVROpenVR.h
@@ -87,19 +87,24 @@ protected:
 };
 
 namespace impl {
 
 class VRControllerOpenVR : public VRControllerHost
 {
 public:
   explicit VRControllerOpenVR();
+  void SetTrackedIndex(uint32_t aTrackedIndex);
+  uint32_t GetTrackedIndex();
 
 protected:
   virtual ~VRControllerOpenVR();
+
+  // The index of tracked devices from vr::IVRSystem.
+  uint32_t mTrackedIndex;
 };
 
 } // namespace impl
 
 class VRControllerManagerOpenVR : public VRControllerManager
 {
 public:
   static already_AddRefed<VRControllerManagerOpenVR> Create();