From 64ca304e376a6193a19edfd93efb735363933144 Mon Sep 17 00:00:00 2001 From: Daosheng Mu Date: Fri, 21 Apr 2017 18:15:22 +0800 Subject: [PATCH] Bug 1355648 - Part 2: Handle GampadPose losing tracking situation; r=kip,qdot MozReview-Commit-ID: FAWnYBuDfFy --HG-- extra : rebase_source : 08437d75379acb5e4701cef0b39512ca482d52f3 --- dom/gamepad/GamepadPose.cpp | 30 ++++++++++++++++----------- dom/gamepad/GamepadPoseState.h | 6 +++++- dom/gamepad/ipc/GamepadMessageUtils.h | 6 +++++- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/dom/gamepad/GamepadPose.cpp b/dom/gamepad/GamepadPose.cpp index 25d157b8b38d..a2fa82396f84 100644 --- a/dom/gamepad/GamepadPose.cpp +++ b/dom/gamepad/GamepadPose.cpp @@ -55,8 +55,9 @@ GamepadPose::GetPosition(JSContext* aJSContext, JS::MutableHandle aRetval, ErrorResult& aRv) { - SetFloat32Array(aJSContext, aRetval, mPosition, mPoseState.position, 3, - bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Position), aRv); + SetFloat32Array(aJSContext, aRetval, mPosition, + mPoseState.isPositionValid ? mPoseState.position : nullptr, 3, + bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Position), aRv); } void @@ -64,8 +65,9 @@ GamepadPose::GetLinearVelocity(JSContext* aJSContext, JS::MutableHandle aRetval, ErrorResult& aRv) { - SetFloat32Array(aJSContext, aRetval, mLinearVelocity, mPoseState.linearVelocity, 3, - bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Position), aRv); + SetFloat32Array(aJSContext, aRetval, mLinearVelocity, + mPoseState.isPositionValid ? mPoseState.linearVelocity : nullptr, 3, + bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Position), aRv); } void @@ -73,8 +75,9 @@ GamepadPose::GetLinearAcceleration(JSContext* aJSContext, JS::MutableHandle aRetval, ErrorResult& aRv) { - SetFloat32Array(aJSContext, aRetval, mLinearAcceleration, mPoseState.linearAcceleration, 3, - bool(mPoseState.flags & GamepadCapabilityFlags::Cap_LinearAcceleration), aRv); + SetFloat32Array(aJSContext, aRetval, mLinearAcceleration, + mPoseState.isPositionValid ? mPoseState.linearAcceleration : nullptr, 3, + bool(mPoseState.flags & GamepadCapabilityFlags::Cap_LinearAcceleration), aRv); } void @@ -82,8 +85,9 @@ GamepadPose::GetOrientation(JSContext* aJSContext, JS::MutableHandle aRetval, ErrorResult& aRv) { - SetFloat32Array(aJSContext, aRetval, mOrientation, mPoseState.orientation, 4, - bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Orientation), aRv); + SetFloat32Array(aJSContext, aRetval, mOrientation, + mPoseState.isOrientationValid ? mPoseState.orientation : nullptr, 4, + bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Orientation), aRv); } void @@ -91,8 +95,9 @@ GamepadPose::GetAngularVelocity(JSContext* aJSContext, JS::MutableHandle aRetval, ErrorResult& aRv) { - SetFloat32Array(aJSContext, aRetval, mAngularVelocity, mPoseState.angularVelocity, 3, - bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Orientation), aRv); + SetFloat32Array(aJSContext, aRetval, mAngularVelocity, + mPoseState.isOrientationValid ? mPoseState.angularVelocity : nullptr, 3, + bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Orientation), aRv); } void @@ -100,8 +105,9 @@ GamepadPose::GetAngularAcceleration(JSContext* aJSContext, JS::MutableHandle aRetval, ErrorResult& aRv) { - SetFloat32Array(aJSContext, aRetval, mAngularAcceleration, mPoseState.angularAcceleration, 3, - bool(mPoseState.flags & GamepadCapabilityFlags::Cap_AngularAcceleration), aRv); + SetFloat32Array(aJSContext, aRetval, mAngularAcceleration, + mPoseState.isOrientationValid ? mPoseState.angularAcceleration : nullptr, 3, + bool(mPoseState.flags & GamepadCapabilityFlags::Cap_AngularAcceleration), aRv); } void diff --git a/dom/gamepad/GamepadPoseState.h b/dom/gamepad/GamepadPoseState.h index 958b26139fda..aa61562e5a3c 100644 --- a/dom/gamepad/GamepadPoseState.h +++ b/dom/gamepad/GamepadPoseState.h @@ -42,6 +42,8 @@ struct GamepadPoseState float angularAcceleration[3]; float linearVelocity[3]; float linearAcceleration[3]; + bool isPositionValid; + bool isOrientationValid; GamepadPoseState() { @@ -69,7 +71,9 @@ struct GamepadPoseState && linearVelocity[2] == aPose.linearVelocity[2] && linearAcceleration[0] == aPose.linearAcceleration[0] && linearAcceleration[1] == aPose.linearAcceleration[1] - && linearAcceleration[2] == aPose.linearAcceleration[2]; + && linearAcceleration[2] == aPose.linearAcceleration[2] + && isPositionValid == aPose.isPositionValid + && isOrientationValid == aPose.isOrientationValid; } bool operator!=(const GamepadPoseState& aPose) const diff --git a/dom/gamepad/ipc/GamepadMessageUtils.h b/dom/gamepad/ipc/GamepadMessageUtils.h index e7e209a98347..bbdfdf65d26c 100644 --- a/dom/gamepad/ipc/GamepadMessageUtils.h +++ b/dom/gamepad/ipc/GamepadMessageUtils.h @@ -62,6 +62,8 @@ struct ParamTraits WriteParam(aMsg, aParam.linearAcceleration[0]); WriteParam(aMsg, aParam.linearAcceleration[1]); WriteParam(aMsg, aParam.linearAcceleration[2]); + WriteParam(aMsg, aParam.isPositionValid); + WriteParam(aMsg, aParam.isOrientationValid); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) @@ -85,7 +87,9 @@ struct ParamTraits !ReadParam(aMsg, aIter, &(aResult->linearVelocity[2])) || !ReadParam(aMsg, aIter, &(aResult->linearAcceleration[0])) || !ReadParam(aMsg, aIter, &(aResult->linearAcceleration[1])) || - !ReadParam(aMsg, aIter, &(aResult->linearAcceleration[2]))) { + !ReadParam(aMsg, aIter, &(aResult->linearAcceleration[2])) || + !ReadParam(aMsg, aIter, &(aResult->isPositionValid)) || + !ReadParam(aMsg, aIter, &(aResult->isOrientationValid))) { return false; } return true;