Bug 1386664 - Add Knuckles string id for SteamVR Knuckles controllers; r?kip
MozReview-Commit-ID: H8fX21j0u6F
--- a/gfx/vr/gfxVROpenVR.cpp
+++ b/gfx/vr/gfxVROpenVR.cpp
@@ -373,39 +373,28 @@ VRDisplayOpenVR::NotifyVSync()
// Make sure we respond to OpenVR events even when not presenting
PollEvents();
VRDisplayHost::NotifyVSync();
}
VRControllerOpenVR::VRControllerOpenVR(dom::GamepadHand aHand, uint32_t aDisplayID,
uint32_t aNumButtons, uint32_t aNumTriggers,
- uint32_t aNumAxes, ::vr::ETrackedDeviceClass aDeviceType)
+ uint32_t aNumAxes, const nsCString& aId)
: VRControllerHost(VRDeviceType::OpenVR, aHand, aDisplayID)
, mTrigger(aNumTriggers)
, mAxisMove(aNumAxes)
, mVibrateThread(nullptr)
, mIsVibrateStopped(false)
{
MOZ_COUNT_CTOR_INHERITED(VRControllerOpenVR, VRControllerHost);
- switch (aDeviceType) {
- case ::vr::TrackedDeviceClass_Controller:
- mControllerInfo.mControllerName.AssignLiteral("OpenVR Gamepad");
- break;
- case ::vr::TrackedDeviceClass_GenericTracker:
- mControllerInfo.mControllerName.AssignLiteral("OpenVR Tracker");
- break;
- default:
- MOZ_ASSERT(false);
- break;
- }
-
mAxisMove.SetLengthAndRetainStorage(aNumAxes);
mTrigger.SetLengthAndRetainStorage(aNumTriggers);
+ mControllerInfo.mControllerName = aId;
mControllerInfo.mNumButtons = aNumButtons;
mControllerInfo.mNumAxes = aNumAxes;
mControllerInfo.mNumHaptics = kNumOpenVRHaptcs;
}
VRControllerOpenVR::~VRControllerOpenVR()
{
if (mVibrateThread) {
@@ -1074,19 +1063,21 @@ VRSystemManagerOpenVR::ScanForController
BTN_MASK_FROM_ID(k_EButton_DPad_Right)) {
++numButtons;
}
if (supportButtons &
BTN_MASK_FROM_ID(k_EButton_DPad_Down)) {
++numButtons;
}
+ nsCString deviceId;
+ GetControllerDeviceId(deviceType, trackedDevice, deviceId);
RefPtr<VRControllerOpenVR> openVRController =
new VRControllerOpenVR(hand, mOpenVRHMD->GetDisplayInfo().GetDisplayID(),
- numButtons, numTriggers, numAxes, deviceType);
+ numButtons, numTriggers, numAxes, deviceId);
openVRController->SetTrackedIndex(trackedDevice);
mOpenVRController.AppendElement(openVRController);
// Not already present, add it.
AddGamepad(openVRController->GetControllerInfo());
++mControllerCount;
}
}
@@ -1098,8 +1089,42 @@ VRSystemManagerOpenVR::RemoveControllers
// The controller count is changed, removing the existing gamepads first.
for (uint32_t i = 0; i < mOpenVRController.Length(); ++i) {
RemoveGamepad(i);
}
mOpenVRController.Clear();
mControllerCount = 0;
}
+void
+VRSystemManagerOpenVR::GetControllerDeviceId(::vr::ETrackedDeviceClass aDeviceType,
+ ::vr::TrackedDeviceIndex_t aDeviceIndex, nsCString& aId)
+{
+ switch (aDeviceType) {
+ case ::vr::TrackedDeviceClass_Controller:
+ {
+ ::vr::ETrackedPropertyError err;
+ uint32_t requiredBufferLen;
+ char charBuf[128];
+ requiredBufferLen = mVRSystem->GetStringTrackedDeviceProperty(aDeviceIndex,
+ ::vr::Prop_RenderModelName_String, charBuf, 128, &err);
+ if (requiredBufferLen > 128) {
+ MOZ_CRASH("Larger than the buffer size.");
+ }
+ MOZ_ASSERT(requiredBufferLen && err == ::vr::TrackedProp_Success);
+ nsCString deviceId(charBuf);
+ if (deviceId.Find("knuckles") != kNotFound) {
+ aId.AssignLiteral("OpenVR Knuckles");
+ } else {
+ aId.AssignLiteral("OpenVR Gamepad");
+ }
+ break;
+ }
+ case ::vr::TrackedDeviceClass_GenericTracker:
+ {
+ aId.AssignLiteral("OpenVR Tracker");
+ break;
+ }
+ default:
+ MOZ_ASSERT(false);
+ break;
+ }
+}
\ No newline at end of file
--- a/gfx/vr/gfxVROpenVR.h
+++ b/gfx/vr/gfxVROpenVR.h
@@ -74,17 +74,17 @@ protected:
const gfx::Rect& aRightEyeRect);
};
class VRControllerOpenVR : public VRControllerHost
{
public:
explicit VRControllerOpenVR(dom::GamepadHand aHand, uint32_t aDisplayID, uint32_t aNumButtons,
uint32_t aNumTriggers, uint32_t aNumAxes,
- ::vr::ETrackedDeviceClass aDeviceType);
+ const nsCString& aId);
void SetTrackedIndex(uint32_t aTrackedIndex);
uint32_t GetTrackedIndex();
float GetAxisMove(uint32_t aAxis);
void SetAxisMove(uint32_t aAxis, float aValue);
void SetTrigger(uint32_t aButton, float aValue);
float GetTrigger(uint32_t aButton);
void SetHand(dom::GamepadHand aHand);
void VibrateHaptic(::vr::IVRSystem* aVRSystem,
@@ -152,16 +152,19 @@ private:
float aValue);
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);
+ void GetControllerDeviceId(::vr::ETrackedDeviceClass aDeviceType,
+ ::vr::TrackedDeviceIndex_t aDeviceIndex,
+ nsCString& aId);
// there can only be one
RefPtr<impl::VRDisplayOpenVR> mOpenVRHMD;
nsTArray<RefPtr<impl::VRControllerOpenVR>> mOpenVRController;
::vr::IVRSystem *mVRSystem;
};
} // namespace gfx