Bug 1336002 - Part 3: Support button touched in OpenVR and Puppet; r?kip
MozReview-Commit-ID: CMacSyuK3mv
--- a/gfx/vr/VRDisplayHost.cpp
+++ b/gfx/vr/VRDisplayHost.cpp
@@ -172,16 +172,28 @@ VRControllerHost::SetButtonPressed(uint6
uint64_t
VRControllerHost::GetButtonPressed()
{
return mButtonPressed;
}
void
+VRControllerHost::SetButtonTouched(uint64_t aBit)
+{
+ mButtonTouched = aBit;
+}
+
+uint64_t
+VRControllerHost::GetButtonTouched()
+{
+ return mButtonTouched;
+}
+
+void
VRControllerHost::SetPose(const dom::GamepadPoseState& aPose)
{
mPose = aPose;
}
const dom::GamepadPoseState&
VRControllerHost::GetPose()
{
--- a/gfx/vr/VRDisplayHost.h
+++ b/gfx/vr/VRDisplayHost.h
@@ -85,29 +85,33 @@ private:
class VRControllerHost {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRControllerHost)
const VRControllerInfo& GetControllerInfo() const;
void SetButtonPressed(uint64_t aBit);
uint64_t GetButtonPressed();
+ void SetButtonTouched(uint64_t aBit);
+ 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);
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;
dom::GamepadPoseState mPose;
};
} // namespace gfx
} // namespace mozilla
#endif /* GFX_VR_DISPLAY_HOST_H */
--- a/gfx/vr/gfxVR.cpp
+++ b/gfx/vr/gfxVR.cpp
@@ -82,20 +82,20 @@ VRSystemManager::RemoveGamepad(uint32_t
VRManager* vm = VRManager::Get();
MOZ_ASSERT(vm);
vm->NotifyGamepadChange<dom::GamepadRemoved>(a);
}
void
VRSystemManager::NewButtonEvent(uint32_t aIndex, uint32_t aButton,
- bool aPressed, double aValue)
+ bool aPressed, bool aTouched, double aValue)
{
dom::GamepadButtonInformation a(aIndex, dom::GamepadServiceType::VR,
- aButton, aPressed, aValue);
+ aButton, aValue, aPressed, aTouched);
VRManager* vm = VRManager::Get();
MOZ_ASSERT(vm);
vm->NotifyGamepadChange<dom::GamepadButtonInformation>(a);
}
void
VRSystemManager::NewAxisMove(uint32_t aIndex, uint32_t aAxis,
--- a/gfx/vr/gfxVR.h
+++ b/gfx/vr/gfxVR.h
@@ -257,17 +257,18 @@ public:
virtual bool GetIsPresenting() = 0;
virtual void HandleInput() = 0;
virtual void GetControllers(nsTArray<RefPtr<VRControllerHost>>& aControllerResult) = 0;
virtual void ScanForControllers() = 0;
virtual void RemoveControllers() = 0;
virtual void VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex,
double aIntensity, double aDuration, uint32_t aPromiseID) = 0;
virtual void StopVibrateHaptic(uint32_t aControllerIdx) = 0;
- void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed, double aValue);
+ void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed, bool aTouched,
+ double aValue);
void NewAxisMove(uint32_t aIndex, uint32_t aAxis, double aValue);
void NewPoseState(uint32_t aIndex, const dom::GamepadPoseState& aPose);
void AddGamepad(const VRControllerInfo& controllerInfo);
void RemoveGamepad(uint32_t aIndex);
protected:
VRSystemManager() : mControllerCount(0) { }
virtual ~VRSystemManager() { }
--- a/gfx/vr/gfxVROculus.cpp
+++ b/gfx/vr/gfxVROculus.cpp
@@ -1317,17 +1317,19 @@ VRSystemManagerOculus::HandleButtonPress
uint64_t aButtonMask,
uint64_t aButtonPressed)
{
RefPtr<impl::VRControllerOculus> controller(mOculusController[aControllerIdx]);
MOZ_ASSERT(controller);
const uint64_t diff = (controller->GetButtonPressed() ^ aButtonPressed);
if (diff & aButtonMask) {
+ // TODO: Bug 1336003 for button touched support.
NewButtonEvent(aControllerIdx, aButton, aButtonMask & aButtonPressed,
+ aButtonMask & aButtonPressed,
(aButtonMask & aButtonPressed) ? 1.0L : 0.0L);
}
}
void
VRSystemManagerOculus::HandleTriggerPress(uint32_t aControllerIdx, uint32_t aButton,
float aValue)
{
@@ -1351,17 +1353,18 @@ VRSystemManagerOculus::HandleTriggerPres
if (oldValue == aValue) {
return;
}
controller->SetHandTrigger(aValue);
} else {
MOZ_ASSERT(false, "We only support indexTrigger and handTrigger in Oculus.");
}
- NewButtonEvent(aControllerIdx, aButton, aValue > 0.1f, aValue);
+ // TODO: Bug 1336003 for button touched support.
+ NewButtonEvent(aControllerIdx, aButton, aValue > 0.1f, aValue > 0.1f, aValue);
}
void
VRSystemManagerOculus::HandleTouchEvent(uint32_t aControllerIdx, uint32_t aButton,
uint64_t aTouchMask, uint64_t aTouched)
{
// TODO: Bug 1336003
}
--- a/gfx/vr/gfxVROpenVR.cpp
+++ b/gfx/vr/gfxVROpenVR.cpp
@@ -681,85 +681,86 @@ VRSystemManagerOpenVR::HandleInput()
state.rAxis[j].x);
++axisIdx;
HandleAxisMove(i, axisIdx,
state.rAxis[j].y);
++axisIdx;
HandleButtonPress(i, buttonIdx,
vr::ButtonMaskFromId(
static_cast<vr::EVRButtonId>(vr::k_EButton_Axis0 + j)),
- state.ulButtonPressed);
+ state.ulButtonPressed, state.ulButtonTouched);
++buttonIdx;
break;
case vr::EVRControllerAxisType::k_eControllerAxis_Trigger:
HandleTriggerPress(i, buttonIdx,
vr::ButtonMaskFromId(
static_cast<vr::EVRButtonId>(vr::k_EButton_Axis0 + j)),
- state.rAxis[j].x, state.ulButtonPressed);
+ state.rAxis[j].x, state.ulButtonPressed, state.ulButtonTouched);
++buttonIdx;
break;
}
}
MOZ_ASSERT(axisIdx ==
controller->GetControllerInfo().GetNumAxes());
const uint64_t supportedButtons = mVRSystem->GetUint64TrackedDeviceProperty(
trackedIndex, vr::Prop_SupportedButtons_Uint64);
if (supportedButtons &
BTN_MASK_FROM_ID(k_EButton_A)) {
HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_A),
- state.ulButtonPressed);
+ state.ulButtonPressed, state.ulButtonTouched);
++buttonIdx;
}
if (supportedButtons &
BTN_MASK_FROM_ID(k_EButton_Grip)) {
HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_Grip),
- state.ulButtonPressed);
+ state.ulButtonPressed, state.ulButtonTouched);
++buttonIdx;
}
if (supportedButtons &
BTN_MASK_FROM_ID(k_EButton_ApplicationMenu)) {
HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_ApplicationMenu),
- state.ulButtonPressed);
+ state.ulButtonPressed, state.ulButtonTouched);
++buttonIdx;
}
if (supportedButtons &
BTN_MASK_FROM_ID(k_EButton_DPad_Left)) {
HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_DPad_Left),
- state.ulButtonPressed);
+ state.ulButtonPressed, state.ulButtonTouched);
++buttonIdx;
}
if (supportedButtons &
BTN_MASK_FROM_ID(k_EButton_DPad_Up)) {
HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_DPad_Up),
- state.ulButtonPressed);
+ state.ulButtonPressed, state.ulButtonTouched);
++buttonIdx;
}
if (supportedButtons &
BTN_MASK_FROM_ID(k_EButton_DPad_Right)) {
HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_DPad_Right),
- state.ulButtonPressed);
+ state.ulButtonPressed, state.ulButtonTouched);
++buttonIdx;
}
if (supportedButtons &
BTN_MASK_FROM_ID(k_EButton_DPad_Down)) {
HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_DPad_Down),
- state.ulButtonPressed);
+ state.ulButtonPressed, state.ulButtonTouched);
++buttonIdx;
}
MOZ_ASSERT(buttonIdx ==
controller->GetControllerInfo().GetNumButtons());
controller->SetButtonPressed(state.ulButtonPressed);
+ controller->SetButtonTouched(state.ulButtonTouched);
// Start to process pose
const ::vr::TrackedDevicePose_t& pose = poses[trackedIndex];
if (pose.bDeviceIsConnected && pose.bPoseIsValid &&
pose.eTrackingResult == vr::TrackingResult_Running_OK) {
gfx::Matrix4x4 m;
@@ -796,51 +797,59 @@ VRSystemManagerOpenVR::HandleInput()
}
}
}
void
VRSystemManagerOpenVR::HandleButtonPress(uint32_t aControllerIdx,
uint32_t aButton,
uint64_t aButtonMask,
- uint64_t aButtonPressed)
+ uint64_t aButtonPressed,
+ uint64_t aButtonTouched)
{
RefPtr<impl::VRControllerOpenVR> controller(mOpenVRController[aControllerIdx]);
MOZ_ASSERT(controller);
- const uint64_t diff = (controller->GetButtonPressed() ^ aButtonPressed);
+ const uint64_t pressedDiff = (controller->GetButtonPressed() ^ aButtonPressed);
+ const uint64_t touchedDiff = (controller->GetButtonTouched() ^ aButtonTouched);
- if (!diff) {
+ if (!pressedDiff && !touchedDiff) {
return;
}
- if (diff & aButtonMask) {
- // diff & aButtonPressed would be true while a new button press
- // event, otherwise it is an old press event and needs to notify
+ if (pressedDiff & aButtonMask ||
+ touchedDiff & aButtonMask) {
+ // diff & (aButtonPressed, aButtonTouched) would be true while a new button pressed or
+ // touched event, otherwise it is an old event and needs to notify
// the button has been released.
NewButtonEvent(aControllerIdx, aButton, aButtonMask & aButtonPressed,
+ aButtonMask & aButtonTouched,
(aButtonMask & aButtonPressed) ? 1.0L : 0.0L);
}
}
void
VRSystemManagerOpenVR::HandleTriggerPress(uint32_t aControllerIdx,
uint32_t aButton,
uint64_t aButtonMask,
float aValue,
- uint64_t aButtonPressed)
+ uint64_t aButtonPressed,
+ uint64_t aButtonTouched)
{
RefPtr<impl::VRControllerOpenVR> controller(mOpenVRController[aControllerIdx]);
MOZ_ASSERT(controller);
- const uint64_t diff = (controller->GetButtonPressed() ^ aButtonPressed);
+ const uint64_t pressedDiff = (controller->GetButtonPressed() ^ aButtonPressed);
+ const uint64_t touchedDiff = (controller->GetButtonTouched() ^ aButtonTouched);
const float oldValue = controller->GetTrigger();
// Avoid sending duplicated events in IPC channels.
if ((oldValue != aValue) ||
- (diff & aButtonMask)) {
- NewButtonEvent(aControllerIdx, aButton, aButtonMask & aButtonPressed, aValue);
+ (pressedDiff & aButtonMask) ||
+ (touchedDiff & aButtonMask)) {
+ NewButtonEvent(aControllerIdx, aButton, aButtonMask & aButtonPressed,
+ aButtonMask & aButtonTouched, aValue);
controller->SetTrigger(aValue);
}
}
void
VRSystemManagerOpenVR::HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
float aValue)
{
--- a/gfx/vr/gfxVROpenVR.h
+++ b/gfx/vr/gfxVROpenVR.h
@@ -129,22 +129,24 @@ public:
protected:
VRSystemManagerOpenVR();
private:
void HandleButtonPress(uint32_t aControllerIdx,
uint32_t aButton,
uint64_t aButtonMask,
- uint64_t aButtonPressed);
+ uint64_t aButtonPressed,
+ uint64_t aButtonTouched);
void HandleTriggerPress(uint32_t aControllerIdx,
uint32_t aButton,
uint64_t aButtonMask,
float aValue,
- uint64_t aButtonPressed);
+ uint64_t aButtonPressed,
+ uint64_t aButtonTouched);
void HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
float aValue);
void HandlePoseTracking(uint32_t aControllerIdx,
const dom::GamepadPoseState& aPose,
VRControllerHost* aController);
// there can only be one
RefPtr<impl::VRDisplayOpenVR> mOpenVRHMD;
--- a/gfx/vr/gfxVRPuppet.cpp
+++ b/gfx/vr/gfxVRPuppet.cpp
@@ -265,16 +265,39 @@ VRControllerPuppet::SetButtonPressState(
uint64_t
VRControllerPuppet::GetButtonPressState()
{
return mButtonPressState;
}
void
+VRControllerPuppet::SetButtonTouchState(uint32_t aButton, bool aTouched)
+{
+ const uint64_t buttonMask = kPuppetButtonMask[aButton];
+ uint64_t touchedBit = GetButtonTouched();
+
+ if (aTouched) {
+ touchedBit |= kPuppetButtonMask[aButton];
+ } else if (touchedBit & buttonMask) {
+ // this button was touched but is released now.
+ uint64_t mask = 0xff ^ buttonMask;
+ touchedBit &= mask;
+ }
+
+ mButtonTouchState = touchedBit;
+}
+
+uint64_t
+VRControllerPuppet::GetButtonTouchState()
+{
+ return mButtonTouchState;
+}
+
+void
VRControllerPuppet::SetAxisMoveState(uint32_t aAxis, double aValue)
{
MOZ_ASSERT((sizeof(mAxisMoveState) / sizeof(float)) == kNumPuppetAxis);
MOZ_ASSERT(aAxis <= kNumPuppetAxis);
mAxisMoveState[aAxis] = aValue;
}
@@ -357,46 +380,51 @@ VRSystemManagerPuppet::GetIsPresenting()
void
VRSystemManagerPuppet::HandleInput()
{
RefPtr<impl::VRControllerPuppet> controller;
for (uint32_t i = 0; i < mPuppetController.Length(); ++i) {
controller = mPuppetController[i];
for (uint32_t j = 0; j < kNumPuppetButtonMask; ++j) {
- HandleButtonPress(i, j, kPuppetButtonMask[i], controller->GetButtonPressState());
+ HandleButtonPress(i, j, kPuppetButtonMask[i], controller->GetButtonPressState(),
+ controller->GetButtonTouchState());
}
controller->SetButtonPressed(controller->GetButtonPressState());
for (uint32_t j = 0; j < kNumPuppetAxis; ++j) {
HandleAxisMove(i, j, controller->GetAxisMoveState(j));
}
HandlePoseTracking(i, controller->GetPoseMoveState(), controller);
}
}
void
VRSystemManagerPuppet::HandleButtonPress(uint32_t aControllerIdx,
uint32_t aButton,
uint64_t aButtonMask,
- uint64_t aButtonPressed)
+ uint64_t aButtonPressed,
+ uint64_t aButtonTouched)
{
RefPtr<impl::VRControllerPuppet> controller(mPuppetController[aControllerIdx]);
MOZ_ASSERT(controller);
- const uint64_t diff = (controller->GetButtonPressed() ^ aButtonPressed);
+ const uint64_t pressedDiff = (controller->GetButtonPressed() ^ aButtonPressed);
+ const uint64_t touchedDiff = (controller->GetButtonTouched() ^ aButtonTouched);
- if (!diff) {
+ if (!pressedDiff && !touchedDiff) {
return;
}
- if (diff & aButtonMask) {
- // diff & aButtonPressed would be true while a new button press
- // event, otherwise it is an old press event and needs to notify
+ if (pressedDiff & aButtonMask
+ || touchedDiff & aButtonMask) {
+ // diff & (aButtonPressed, aButtonTouched) would be true while a new button pressed or
+ // touched event, otherwise it is an old event and needs to notify
// the button has been released.
NewButtonEvent(aControllerIdx, aButton, aButtonMask & aButtonPressed,
+ aButtonMask & aButtonPressed,
(aButtonMask & aButtonPressed) ? 1.0L : 0.0L);
}
}
void
VRSystemManagerPuppet::HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
float aValue)
{
--- a/gfx/vr/gfxVRPuppet.h
+++ b/gfx/vr/gfxVRPuppet.h
@@ -57,28 +57,31 @@ private:
};
class VRControllerPuppet : public VRControllerHost
{
public:
explicit VRControllerPuppet(dom::GamepadHand aHand);
void SetButtonPressState(uint32_t aButton, bool aPressed);
uint64_t GetButtonPressState();
+ void SetButtonTouchState(uint32_t aButton, bool aTouched);
+ uint64_t GetButtonTouchState();
void SetAxisMoveState(uint32_t aAxis, double aValue);
double GetAxisMoveState(uint32_t aAxis);
void SetPoseMoveState(const dom::GamepadPoseState& aPose);
const dom::GamepadPoseState& GetPoseMoveState();
float GetAxisMove(uint32_t aAxis);
void SetAxisMove(uint32_t aAxis, float aValue);
protected:
virtual ~VRControllerPuppet();
private:
uint64_t mButtonPressState;
+ uint64_t mButtonTouchState;
float mAxisMoveState[3];
float mAxisMove[3];
dom::GamepadPoseState mPoseState;
};
} // namespace impl
class VRSystemManagerPuppet : public VRSystemManager
@@ -104,17 +107,18 @@ public:
protected:
VRSystemManagerPuppet();
private:
void HandleButtonPress(uint32_t aControllerIdx,
uint32_t aButton,
uint64_t aButtonMask,
- uint64_t aButtonPressed);
+ uint64_t aButtonPressed,
+ uint64_t aButtonTouched);
void HandleAxisMove(uint32_t aControllerIndex, uint32_t aAxis,
float aValue);
void HandlePoseTracking(uint32_t aControllerIndex,
const dom::GamepadPoseState& aPose,
VRControllerHost* aController);
// there can only be one
RefPtr<impl::VRDisplayPuppet> mPuppetHMD;