diff options
Diffstat (limited to 'libs/ui')
-rw-r--r-- | libs/ui/Input.cpp | 46 | ||||
-rw-r--r-- | libs/ui/tests/InputEvent_test.cpp | 16 |
2 files changed, 17 insertions, 45 deletions
diff --git a/libs/ui/Input.cpp b/libs/ui/Input.cpp index 0af7f80..688b998 100644 --- a/libs/ui/Input.cpp +++ b/libs/ui/Input.cpp @@ -280,6 +280,9 @@ status_t PointerCoords::setAxisValue(int32_t axis, float value) { uint64_t axisBit = 1LL << axis; uint32_t index = __builtin_popcountll(bits & (axisBit - 1LL)); if (!(bits & axisBit)) { + if (value == 0) { + return OK; // axes with value 0 do not need to be stored + } uint32_t count = __builtin_popcountll(bits); if (count >= MAX_AXES) { tooManyAxes(axis); @@ -294,23 +297,10 @@ status_t PointerCoords::setAxisValue(int32_t axis, float value) { return OK; } -float* PointerCoords::editAxisValue(int32_t axis) { - if (axis < 0 || axis > 63) { - return NULL; - } - - uint64_t axisBit = 1LL << axis; - if (!(bits & axisBit)) { - return NULL; - } - uint32_t index = __builtin_popcountll(bits & (axisBit - 1LL)); - return &values[index]; -} - static inline void scaleAxisValue(PointerCoords& c, int axis, float scaleFactor) { - float* value = c.editAxisValue(axis); - if (value) { - *value *= scaleFactor; + float value = c.getAxisValue(axis); + if (value != 0) { + c.setAxisValue(axis, value * scaleFactor); } } @@ -574,20 +564,14 @@ void MotionEvent::transform(const SkMatrix* matrix) { size_t numSamples = mSamplePointerCoords.size(); for (size_t i = 0; i < numSamples; i++) { PointerCoords& c = mSamplePointerCoords.editItemAt(i); - float* xPtr = c.editAxisValue(AMOTION_EVENT_AXIS_X); - float* yPtr = c.editAxisValue(AMOTION_EVENT_AXIS_Y); - if (xPtr && yPtr) { - float x = *xPtr + oldXOffset; - float y = *yPtr + oldYOffset; - matrix->mapXY(SkFloatToScalar(x), SkFloatToScalar(y), & point); - *xPtr = SkScalarToFloat(point.fX) - newXOffset; - *yPtr = SkScalarToFloat(point.fY) - newYOffset; - } + float x = c.getAxisValue(AMOTION_EVENT_AXIS_X) + oldXOffset; + float y = c.getAxisValue(AMOTION_EVENT_AXIS_Y) + oldYOffset; + matrix->mapXY(SkFloatToScalar(x), SkFloatToScalar(y), &point); + c.setAxisValue(AMOTION_EVENT_AXIS_X, SkScalarToFloat(point.fX) - newXOffset); + c.setAxisValue(AMOTION_EVENT_AXIS_Y, SkScalarToFloat(point.fY) - newYOffset); - float* orientationPtr = c.editAxisValue(AMOTION_EVENT_AXIS_ORIENTATION); - if (orientationPtr) { - *orientationPtr = transformAngle(matrix, *orientationPtr); - } + float orientation = c.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION); + c.setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, transformAngle(matrix, orientation)); } } @@ -727,7 +711,7 @@ void VelocityTracker::addMovement(nsecs_t eventTime, BitSet32 idBits, const Posi } while (idBits.count() > MAX_POINTERS) { - idBits.clearBit(idBits.lastMarkedBit()); + idBits.clearLastMarkedBit(); } Movement& movement = mMovements[mIndex]; @@ -776,7 +760,7 @@ void VelocityTracker::addMovement(const MotionEvent* event) { // We do this on down instead of on up because the client may want to query the // final velocity for a pointer that just went up. BitSet32 downIdBits; - downIdBits.markBit(event->getActionIndex()); + downIdBits.markBit(event->getPointerId(event->getActionIndex())); clearPointers(downIdBits); break; } diff --git a/libs/ui/tests/InputEvent_test.cpp b/libs/ui/tests/InputEvent_test.cpp index e48d5b7..e21c464 100644 --- a/libs/ui/tests/InputEvent_test.cpp +++ b/libs/ui/tests/InputEvent_test.cpp @@ -52,9 +52,6 @@ TEST_F(PointerCoordsTest, AxisValues) { ASSERT_EQ(0, coords.getAxisValue(1)) << "getAxisValue should return zero because axis is not present"; - ASSERT_EQ(NULL, coords.editAxisValue(0)) - << "editAxisValue should return null because axis is not present"; - // Set first axis. ASSERT_EQ(OK, coords.setAxisValue(1, 5)); ASSERT_EQ(0x00000002ULL, coords.bits); @@ -96,26 +93,17 @@ TEST_F(PointerCoordsTest, AxisValues) { ASSERT_EQ(2, coords.getAxisValue(3)) << "getAxisValue should return value of axis"; - // Edit an existing axis value in place. - valuePtr = coords.editAxisValue(1); - ASSERT_EQ(5, *valuePtr) - << "editAxisValue should return pointer to axis value"; - - *valuePtr = 7; - ASSERT_EQ(7, coords.getAxisValue(1)) - << "getAxisValue should return value of axis"; - // Set an axis with an id between the others. (inserting value in the middle) ASSERT_EQ(OK, coords.setAxisValue(2, 1)); ASSERT_EQ(0x0000000fULL, coords.bits); ASSERT_EQ(4, coords.values[0]); - ASSERT_EQ(7, coords.values[1]); + ASSERT_EQ(5, coords.values[1]); ASSERT_EQ(1, coords.values[2]); ASSERT_EQ(2, coords.values[3]); ASSERT_EQ(4, coords.getAxisValue(0)) << "getAxisValue should return value of axis"; - ASSERT_EQ(7, coords.getAxisValue(1)) + ASSERT_EQ(5, coords.getAxisValue(1)) << "getAxisValue should return value of axis"; ASSERT_EQ(1, coords.getAxisValue(2)) << "getAxisValue should return value of axis"; |