Bug 1151937; [webvr] change deviceId/hardwareId to simple values; r=jrmuizel CLOSED TREE

This commit is contained in:
Vladimir Vukicevic 2015-04-07 13:26:44 -04:00
parent 117a8328e2
commit 38c2a45ba7
5 changed files with 48 additions and 23 deletions

View File

@ -213,22 +213,18 @@ 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;
}
@ -281,22 +277,19 @@ public:
, 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;
}

View File

@ -18,6 +18,7 @@
#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
@ -71,7 +72,18 @@ protected:
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()
@ -116,3 +128,9 @@ VRHMDManager::GetAllHMDs(nsTArray<nsRefPtr<VRHMDInfo>>& aHMDResult)
(*sManagers)[i]->GetHMDs(aHMDResult);
}
}
/* static */ uint32_t
VRHMDManager::AllocateDeviceIndex()
{
return ++sDeviceBase;
}

View File

@ -8,11 +8,13 @@
#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 {
@ -140,6 +142,8 @@ 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]; }
@ -179,11 +183,13 @@ public:
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;
@ -203,10 +209,12 @@ 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)

View File

@ -86,6 +86,10 @@ HMDInfoCardboard::HMDInfoCardboard()
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);

View File

@ -246,6 +246,8 @@ HMDInfoOculus::HMDInfoOculus(ovrHmd aHMD)
MOZ_COUNT_CTOR_INHERITED(HMDInfoOculus, VRHMDInfo);
mDeviceName.AssignLiteral("Oculus VR HMD");
mSupportedSensorBits = 0;
if (mHMD->TrackingCaps & ovrTrackingCap_Orientation)
mSupportedSensorBits |= State_Orientation;