Bug 1151937; [webvr] change deviceId/hardwareId to simple values; r=jrmuizel CLOSED TREE
authorVladimir Vukicevic <vladimir@pobox.com>
Tue, 07 Apr 2015 13:26:44 -0400
changeset 237992 deb77afd348fc8d5f3dcdaf629b5fd796992b2ed
parent 237991 29484df45d65cadb84a08ebbe8832f6504123e35
child 237993 3cdb12131f67245883d1de4d1e1ed415ef47740d
push id28554
push userryanvm@gmail.com
push dateWed, 08 Apr 2015 16:15:39 +0000
treeherdermozilla-central@256b307c35ce [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1151937
milestone40.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 1151937; [webvr] change deviceId/hardwareId to simple values; r=jrmuizel CLOSED TREE
dom/vr/VRDevice.cpp
gfx/vr/gfxVR.cpp
gfx/vr/gfxVR.h
gfx/vr/gfxVRCardboard.cpp
gfx/vr/gfxVROculus.cpp
--- a/dom/vr/VRDevice.cpp
+++ b/dom/vr/VRDevice.cpp
@@ -208,32 +208,28 @@ PositionSensorVRDevice::WrapObject(JSCon
 namespace {
 
 class HMDInfoVRDevice : public HMDVRDevice
 {
 public:
   HMDInfoVRDevice(nsISupports* aParent, gfx::VRHMDInfo* aHMD)
     : HMDVRDevice(aParent, aHMD)
   {
-    // XXX TODO use real names/IDs
-    uint64_t hmdid = reinterpret_cast<uint64_t>(aHMD);
+    uint64_t hmdid = aHMD->GetDeviceIndex() << 8;
+    uint64_t devid = hmdid | 0x00; // we generate a devid with low byte 0 for the HMD, 1 for the position sensor
 
     mHWID.Truncate();
-    mHWID.AppendPrintf("HMDInfo-0x%llx", hmdid);
+    mHWID.AppendPrintf("0x%llx", hmdid);
 
     mDeviceId.Truncate();
-    mDeviceId.AppendPrintf("HMDInfo-dev-0x%llx", hmdid);
+    mDeviceId.AppendPrintf("0x%llx", devid);
 
-    if (aHMD->GetType() == VRHMDType::Oculus) {
-      mDeviceName.AssignLiteral("VR HMD Device (oculus)");
-    } else if (aHMD->GetType() == VRHMDType::Cardboard) {
-      mDeviceName.AssignLiteral("VR HMD Device (cardboard)");
-    } else {
-      mDeviceName.AssignLiteral("VR HMD Device (unknown)");
-    }
+    mDeviceName.Truncate();
+    mDeviceName.Append(NS_ConvertASCIItoUTF16(aHMD->GetDeviceName()));
+    mDeviceName.AppendLiteral(" (HMD)");
 
     mValid = true;
   }
 
   virtual ~HMDInfoVRDevice() { }
 
   /* If a field of view that is set to all 0's is passed in,
    * the recommended field of view for that eye is used.
@@ -276,32 +272,29 @@ protected:
 class HMDPositionVRDevice : public PositionSensorVRDevice
 {
 public:
   HMDPositionVRDevice(nsISupports* aParent, gfx::VRHMDInfo* aHMD)
     : PositionSensorVRDevice(aParent)
     , mHMD(aHMD)
     , mTracking(false)
   {
-    // XXX TODO use real names/IDs
-    uint64_t hmdid = reinterpret_cast<uint64_t>(aHMD);
+
+    uint64_t hmdid = aHMD->GetDeviceIndex() << 8;
+    uint64_t devid = hmdid | 0x01; // we generate a devid with low byte 0 for the HMD, 1 for the position sensor
 
     mHWID.Truncate();
-    mHWID.AppendPrintf("HMDInfo-0x%llx", hmdid);
+    mHWID.AppendPrintf("0x%llx", hmdid);
 
     mDeviceId.Truncate();
-    mDeviceId.AppendPrintf("HMDInfo-dev-0x%llx", hmdid);
+    mDeviceId.AppendPrintf("0x%llx", devid);
 
-    if (aHMD->GetType() == VRHMDType::Oculus) {
-      mDeviceName.AssignLiteral("VR Position Device (oculus)");
-    } else if (aHMD->GetType() == VRHMDType::Cardboard) {
-      mDeviceName.AssignLiteral("VR Position Device (cardboard)");
-    } else {
-      mDeviceName.AssignLiteral("VR Position Device (unknown)");
-    }
+    mDeviceName.Truncate();
+    mDeviceName.Append(NS_ConvertASCIItoUTF16(aHMD->GetDeviceName()));
+    mDeviceName.AppendLiteral(" (Sensor)");
 
     mValid = true;
   }
 
   ~HMDPositionVRDevice()
   {
     if (mTracking) {
       mHMD->StopSensorTracking();
--- a/gfx/vr/gfxVR.cpp
+++ b/gfx/vr/gfxVR.cpp
@@ -13,16 +13,17 @@
 #include "gfxPrefs.h"
 #include "gfxVR.h"
 #include "gfxVROculus.h"
 #include "gfxVRCardboard.h"
 
 #include "nsServiceManagerUtils.h"
 #include "nsIScreenManager.h"
 
+using namespace mozilla;
 using namespace mozilla::gfx;
 
 // Dummy nsIScreen implementation, for when we just need to specify a size
 class FakeScreen : public nsIScreen
 {
 public:
   explicit FakeScreen(const IntRect& aScreenRect)
     : mScreenRect(aScreenRect)
@@ -66,17 +67,28 @@ public:
 protected:
   virtual ~FakeScreen() {}
 
   IntRect mScreenRect;
 };
 
 NS_IMPL_ISUPPORTS(FakeScreen, nsIScreen)
 
+VRHMDInfo::VRHMDInfo(VRHMDType aType)
+  : mType(aType)
+{
+  MOZ_COUNT_CTOR(VRHMDInfo);
+
+  mDeviceIndex = VRHMDManager::AllocateDeviceIndex();
+  mDeviceName.AssignLiteral("Unknown Device");
+}
+
+
 VRHMDManager::VRHMDManagerArray *VRHMDManager::sManagers = nullptr;
+Atomic<uint32_t> VRHMDManager::sDeviceBase(0);
 
 /* static */ void
 VRHMDManager::ManagerInit()
 {
   if (sManagers)
     return;
 
   sManagers = new VRHMDManagerArray();
@@ -111,8 +123,14 @@ VRHMDManager::GetAllHMDs(nsTArray<nsRefP
 {
   if (!sManagers)
     return;
 
   for (uint32_t i = 0; i < sManagers->Length(); ++i) {
     (*sManagers)[i]->GetHMDs(aHMDResult);
   }
 }
+
+/* static */ uint32_t
+VRHMDManager::AllocateDeviceIndex()
+{
+  return ++sDeviceBase;
+}
--- a/gfx/vr/gfxVR.h
+++ b/gfx/vr/gfxVR.h
@@ -3,21 +3,23 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_VR_H
 #define GFX_VR_H
 
 #include "nsTArray.h"
 #include "nsIScreen.h"
+#include "nsString.h"
 #include "nsCOMPtr.h"
 #include "nsRefPtr.h"
 
 #include "mozilla/gfx/2D.h"
 #include "mozilla/EnumeratedArray.h"
+#include "mozilla/Atomics.h"
 
 namespace mozilla {
 namespace gfx {
 
 enum class VRHMDType : uint16_t {
   Oculus,
   Cardboard,
   NumHMDTypes
@@ -135,16 +137,18 @@ public:
     State_Position = 1 << 1,
     State_Orientation = 1 << 2
   };
 
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRHMDInfo)
 
   VRHMDType GetType() const { return mType; }
+  uint32_t GetDeviceIndex() const { return mDeviceIndex; }
+  const nsCString& GetDeviceName() const { return mDeviceName; }
 
   virtual const VRFieldOfView& GetRecommendedEyeFOV(uint32_t whichEye) { return mRecommendedEyeFOV[whichEye]; }
   virtual const VRFieldOfView& GetMaximumEyeFOV(uint32_t whichEye) { return mMaximumEyeFOV[whichEye]; }
 
   const VRHMDConfiguration& GetConfiguration() const { return mConfiguration; }
 
   /* set the FOV for this HMD unit; this triggers a computation of all the remaining bits.  Returns false if it fails */
   virtual bool SetFOV(const VRFieldOfView& aFOVLeft, const VRFieldOfView& aFOVRight,
@@ -174,21 +178,23 @@ public:
                                        VRDistortionConstants& values) = 0;
 
   virtual const VRDistortionMesh& GetDistortionMesh(uint32_t whichEye) const { return mDistortionMesh[whichEye]; }
 
   // The nsIScreen that represents this device
   virtual nsIScreen* GetScreen() { return mScreen; }
 
 protected:
-  explicit VRHMDInfo(VRHMDType aType) : mType(aType) { MOZ_COUNT_CTOR(VRHMDInfo); }
+  explicit VRHMDInfo(VRHMDType aType);
   virtual ~VRHMDInfo() { MOZ_COUNT_DTOR(VRHMDInfo); }
 
   VRHMDType mType;
   VRHMDConfiguration mConfiguration;
+  uint32_t mDeviceIndex;
+  nsCString mDeviceName;
 
   VRFieldOfView mEyeFOV[NumEyes];
   IntSize mEyeResolution;
   Point3D mEyeTranslation[NumEyes];
   Matrix4x4 mEyeProjectionMatrix[NumEyes];
   VRDistortionMesh mDistortionMesh[NumEyes];
   uint32_t mSupportedSensorBits;
 
@@ -198,20 +204,22 @@ protected:
   nsCOMPtr<nsIScreen> mScreen;
 };
 
 class VRHMDManager {
 public:
   static void ManagerInit();
   static void ManagerDestroy();
   static void GetAllHMDs(nsTArray<nsRefPtr<VRHMDInfo>>& aHMDResult);
+  static uint32_t AllocateDeviceIndex();
 
 protected:
   typedef nsTArray<nsRefPtr<VRHMDManager>> VRHMDManagerArray;
   static VRHMDManagerArray *sManagers;
+  static Atomic<uint32_t> sDeviceBase;
 
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRHMDManager)
 
   virtual bool PlatformInit() = 0;
   virtual bool Init() = 0;
   virtual void Destroy() = 0;
   virtual void GetHMDs(nsTArray<nsRefPtr<VRHMDInfo>>& aHMDResult) = 0;
--- a/gfx/vr/gfxVRCardboard.cpp
+++ b/gfx/vr/gfxVRCardboard.cpp
@@ -81,16 +81,20 @@ RemapMatrixForOrientation(ScreenOrientat
 HMDInfoCardboard::HMDInfoCardboard()
   : VRHMDInfo(VRHMDType::Cardboard)
   , mStartCount(0)
   , mOrient(eScreenOrientation_PortraitPrimary)
 {
   MOZ_ASSERT(sizeof(HMDInfoCardboard::DistortionVertex) == sizeof(VRDistortionVertex),
              "HMDInfoCardboard::DistortionVertex must match the size of VRDistortionVertex");
 
+  MOZ_COUNT_CTOR_INHERITED(HMDInfoCardboard, VRHMDInfo);
+
+  mDeviceName.AssignLiteral("Phone Sensor (Cardboard) HMD");
+
   mSupportedSensorBits = State_Orientation;
 
   mRecommendedEyeFOV[Eye_Left] = VRFieldOfView(45.0, 45.0, 45.0, 45.0);
   mRecommendedEyeFOV[Eye_Right] = VRFieldOfView(45.0, 45.0, 45.0, 45.0);
 
   mMaximumEyeFOV[Eye_Left] = VRFieldOfView(45.0, 45.0, 45.0, 45.0);
   mMaximumEyeFOV[Eye_Right] = VRFieldOfView(45.0, 45.0, 45.0, 45.0);
 
--- a/gfx/vr/gfxVROculus.cpp
+++ b/gfx/vr/gfxVROculus.cpp
@@ -241,16 +241,18 @@ HMDInfoOculus::HMDInfoOculus(ovrHmd aHMD
   , mHMD(aHMD)
   , mStartCount(0)
 {
   MOZ_ASSERT(sizeof(HMDInfoOculus::DistortionVertex) == sizeof(VRDistortionVertex),
              "HMDInfoOculus::DistortionVertex must match the size of VRDistortionVertex");
 
   MOZ_COUNT_CTOR_INHERITED(HMDInfoOculus, VRHMDInfo);
 
+  mDeviceName.AssignLiteral("Oculus VR HMD");
+
   mSupportedSensorBits = 0;
   if (mHMD->TrackingCaps & ovrTrackingCap_Orientation)
     mSupportedSensorBits |= State_Orientation;
   if (mHMD->TrackingCaps & ovrTrackingCap_Position)
     mSupportedSensorBits |= State_Position;
 
   mRecommendedEyeFOV[Eye_Left] = FromFovPort(mHMD->DefaultEyeFov[ovrEye_Left]);
   mRecommendedEyeFOV[Eye_Right] = FromFovPort(mHMD->DefaultEyeFov[ovrEye_Right]);