Bug 1305890 - Part 1: Oculus Touch button inputs support; r?kip
MozReview-Commit-ID: CJmSW00e8Ov
--- a/gfx/vr/VRManager.cpp
+++ b/gfx/vr/VRManager.cpp
@@ -187,17 +187,19 @@ VRManager::NotifyVsync(const TimeStamp&
}
mLastRefreshTime = TimeStamp::Now();
} else {
// We don't have to do this every frame, so check if we
// have refreshed recently.
TimeDuration duration = TimeStamp::Now() - mLastRefreshTime;
if (duration.ToMilliseconds() > kVRDisplayRefreshMaxDuration) {
RefreshVRDisplays();
- RefreshVRControllers();
+ if (bHaveControllerListener) {
+ RefreshVRControllers();
+ }
mLastRefreshTime = TimeStamp::Now();
}
}
}
}
void
VRManager::NotifyVRVsync(const uint32_t& aDisplayID)
--- a/gfx/vr/gfxVROculus.cpp
+++ b/gfx/vr/gfxVROculus.cpp
@@ -117,25 +117,25 @@ static pfn_ovr_GetMirrorTextureBufferGL
#define BUILD_BITS 32
#endif
#define OVR_PRODUCT_VERSION 1
#define OVR_MAJOR_VERSION 1
#define OVR_MINOR_VERSION 10
static const ovrButton kOculusTouchLButton[] = {
+ ovrButton_LThumb,
ovrButton_X,
- ovrButton_Y,
- ovrButton_LThumb
+ ovrButton_Y
};
static const ovrButton kOculusTouchRButton[] = {
+ ovrButton_RThumb,
ovrButton_A,
ovrButton_B,
- ovrButton_RThumb
};
static const uint32_t kNumOculusButton = sizeof(kOculusTouchLButton) /
sizeof(ovrButton);
static const uint32_t kNumOculusAxis = 2;
static const uint32_t kNumOculusHaptcs = 0; // TODO: Bug 1305892
static bool
@@ -934,17 +934,17 @@ VRSystemManagerOculus::GetHMDs(nsTArray<
if (mHMDInfo) {
aHMDResult.AppendElement(mHMDInfo);
}
}
void
VRSystemManagerOculus::HandleInput()
{
- // mSession is available after VRDisplay is created
+ // mSession is available after VRDisplay is created
// at GetHMDs().
if (!mSession) {
return;
}
RefPtr<impl::VRControllerOculus> controller;
ovrInputState inputState;
bool hasInputState = ovr_GetInputState(mSession, ovrControllerType_Touch,
@@ -959,17 +959,43 @@ VRSystemManagerOculus::HandleInput()
HandleButtonPress(controller->GetIndex(), inputState.Buttons);
}
}
void
VRSystemManagerOculus::HandleButtonPress(uint32_t aControllerIdx,
uint64_t aButtonPressed)
{
- // TODO: Bug 1305890
+ MOZ_ASSERT(sizeof(kOculusTouchLButton) / sizeof(ovrButton) ==
+ sizeof(kOculusTouchRButton) / sizeof(ovrButton));
+
+ RefPtr<impl::VRControllerOculus> controller(mOculusController[aControllerIdx]);
+ MOZ_ASSERT(controller);
+ GamepadHand hand = controller->GetHand();
+ uint64_t diff = (controller->GetButtonPressed() ^ aButtonPressed);
+ uint32_t buttonMask = 0;
+
+ for (uint32_t i = 0; i < kNumOculusButton; ++i) {
+ switch (hand) {
+ case mozilla::dom::GamepadHand::Left:
+ buttonMask = kOculusTouchLButton[i];
+ break;
+ case mozilla::dom::GamepadHand::Right:
+ buttonMask = kOculusTouchRButton[i];
+ break;
+ default:
+ MOZ_ASSERT(false);
+ break;
+ }
+ if (diff & buttonMask) {
+ NewButtonEvent(aControllerIdx, i, diff & aButtonPressed);
+ }
+ }
+
+ controller->SetButtonPressed(aButtonPressed);
}
void
VRSystemManagerOculus::HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
float aValue)
{
// TODO: Bug 1305890
}