Loading include/input/VelocityTracker.h +1 −2 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ public: INT2 = 8, LEGACY = 9, MAX = LEGACY, ftl_last = LEGACY, }; /* Loading Loading @@ -81,8 +82,6 @@ public: // TODO(b/32830165): support axis-specific strategies. VelocityTracker(const Strategy strategy = Strategy::DEFAULT); ~VelocityTracker(); /** Return true if the axis is supported for velocity tracking, false otherwise. */ static bool isAxisSupported(int32_t axis); Loading libs/input/VelocityTracker.cpp +13 −19 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #define LOG_TAG "VelocityTracker" #include <android-base/logging.h> #include <ftl/enum.h> #include <inttypes.h> #include <limits.h> #include <math.h> Loading Loading @@ -148,27 +149,19 @@ static std::string matrixToString(const float* a, uint32_t m, uint32_t n, bool r VelocityTracker::VelocityTracker(const Strategy strategy) : mLastEventTime(0), mCurrentPointerIdBits(0), mOverrideStrategy(strategy) {} VelocityTracker::~VelocityTracker() { } bool VelocityTracker::isAxisSupported(int32_t axis) { return DEFAULT_STRATEGY_BY_AXIS.find(axis) != DEFAULT_STRATEGY_BY_AXIS.end(); } void VelocityTracker::configureStrategy(int32_t axis) { const bool isDifferentialAxis = DIFFERENTIAL_AXES.find(axis) != DIFFERENTIAL_AXES.end(); std::unique_ptr<VelocityTrackerStrategy> createdStrategy; if (mOverrideStrategy != VelocityTracker::Strategy::DEFAULT) { createdStrategy = createStrategy(mOverrideStrategy, /*deltaValues=*/isDifferentialAxis); } else { createdStrategy = createStrategy(DEFAULT_STRATEGY_BY_AXIS.at(axis), if (isDifferentialAxis || mOverrideStrategy == VelocityTracker::Strategy::DEFAULT) { // Do not allow overrides of strategies for differential axes, for now. mConfiguredStrategies[axis] = createStrategy(DEFAULT_STRATEGY_BY_AXIS.at(axis), /*deltaValues=*/isDifferentialAxis); } else { mConfiguredStrategies[axis] = createStrategy(mOverrideStrategy, /*deltaValues=*/false); } LOG_ALWAYS_FATAL_IF(createdStrategy == nullptr, "Could not create velocity tracker strategy for axis '%" PRId32 "'!", axis); mConfiguredStrategies[axis] = std::move(createdStrategy); } std::unique_ptr<VelocityTrackerStrategy> VelocityTracker::createStrategy( Loading Loading @@ -216,6 +209,9 @@ std::unique_ptr<VelocityTrackerStrategy> VelocityTracker::createStrategy( default: break; } LOG(FATAL) << "Invalid strategy: " << ftl::enum_string(strategy) << ", deltaValues = " << deltaValues; return nullptr; } Loading Loading @@ -272,12 +268,10 @@ void VelocityTracker::addMovement(nsecs_t eventTime, int32_t pointerId, int32_t mConfiguredStrategies[axis]->addMovement(eventTime, pointerId, position); if (DEBUG_VELOCITY) { ALOGD("VelocityTracker: addMovement eventTime=%" PRId64 ", pointerId=%" PRId32 ", activePointerId=%s", eventTime, pointerId, toString(mActivePointerId).c_str()); ALOGD(" %d: axis=%d, position=%0.3f, velocity=%s", pointerId, axis, position, toString(getVelocity(axis, pointerId)).c_str()); LOG(INFO) << "VelocityTracker: addMovement axis=" << MotionEvent::getLabel(axis) << ", eventTime=" << eventTime << ", pointerId=" << pointerId << ", activePointerId=" << toString(mActivePointerId) << ", position=" << position << ", velocity=" << toString(getVelocity(axis, pointerId)); } } Loading libs/input/tests/VelocityTracker_test.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -278,6 +278,11 @@ static void computeAndCheckAxisScrollVelocity( const std::vector<std::pair<std::chrono::nanoseconds, float>>& motions, std::optional<float> targetVelocity) { checkVelocity(computeVelocity(strategy, motions, AMOTION_EVENT_AXIS_SCROLL), targetVelocity); // The strategy LSQ2 is not compatible with AXIS_SCROLL. In those situations, we should fall // back to a strategy that supports differential axes. checkVelocity(computeVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_SCROLL), targetVelocity); } static void computeAndCheckQuadraticVelocity(const std::vector<PlanarMotionEventEntry>& motions, Loading Loading
include/input/VelocityTracker.h +1 −2 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ public: INT2 = 8, LEGACY = 9, MAX = LEGACY, ftl_last = LEGACY, }; /* Loading Loading @@ -81,8 +82,6 @@ public: // TODO(b/32830165): support axis-specific strategies. VelocityTracker(const Strategy strategy = Strategy::DEFAULT); ~VelocityTracker(); /** Return true if the axis is supported for velocity tracking, false otherwise. */ static bool isAxisSupported(int32_t axis); Loading
libs/input/VelocityTracker.cpp +13 −19 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #define LOG_TAG "VelocityTracker" #include <android-base/logging.h> #include <ftl/enum.h> #include <inttypes.h> #include <limits.h> #include <math.h> Loading Loading @@ -148,27 +149,19 @@ static std::string matrixToString(const float* a, uint32_t m, uint32_t n, bool r VelocityTracker::VelocityTracker(const Strategy strategy) : mLastEventTime(0), mCurrentPointerIdBits(0), mOverrideStrategy(strategy) {} VelocityTracker::~VelocityTracker() { } bool VelocityTracker::isAxisSupported(int32_t axis) { return DEFAULT_STRATEGY_BY_AXIS.find(axis) != DEFAULT_STRATEGY_BY_AXIS.end(); } void VelocityTracker::configureStrategy(int32_t axis) { const bool isDifferentialAxis = DIFFERENTIAL_AXES.find(axis) != DIFFERENTIAL_AXES.end(); std::unique_ptr<VelocityTrackerStrategy> createdStrategy; if (mOverrideStrategy != VelocityTracker::Strategy::DEFAULT) { createdStrategy = createStrategy(mOverrideStrategy, /*deltaValues=*/isDifferentialAxis); } else { createdStrategy = createStrategy(DEFAULT_STRATEGY_BY_AXIS.at(axis), if (isDifferentialAxis || mOverrideStrategy == VelocityTracker::Strategy::DEFAULT) { // Do not allow overrides of strategies for differential axes, for now. mConfiguredStrategies[axis] = createStrategy(DEFAULT_STRATEGY_BY_AXIS.at(axis), /*deltaValues=*/isDifferentialAxis); } else { mConfiguredStrategies[axis] = createStrategy(mOverrideStrategy, /*deltaValues=*/false); } LOG_ALWAYS_FATAL_IF(createdStrategy == nullptr, "Could not create velocity tracker strategy for axis '%" PRId32 "'!", axis); mConfiguredStrategies[axis] = std::move(createdStrategy); } std::unique_ptr<VelocityTrackerStrategy> VelocityTracker::createStrategy( Loading Loading @@ -216,6 +209,9 @@ std::unique_ptr<VelocityTrackerStrategy> VelocityTracker::createStrategy( default: break; } LOG(FATAL) << "Invalid strategy: " << ftl::enum_string(strategy) << ", deltaValues = " << deltaValues; return nullptr; } Loading Loading @@ -272,12 +268,10 @@ void VelocityTracker::addMovement(nsecs_t eventTime, int32_t pointerId, int32_t mConfiguredStrategies[axis]->addMovement(eventTime, pointerId, position); if (DEBUG_VELOCITY) { ALOGD("VelocityTracker: addMovement eventTime=%" PRId64 ", pointerId=%" PRId32 ", activePointerId=%s", eventTime, pointerId, toString(mActivePointerId).c_str()); ALOGD(" %d: axis=%d, position=%0.3f, velocity=%s", pointerId, axis, position, toString(getVelocity(axis, pointerId)).c_str()); LOG(INFO) << "VelocityTracker: addMovement axis=" << MotionEvent::getLabel(axis) << ", eventTime=" << eventTime << ", pointerId=" << pointerId << ", activePointerId=" << toString(mActivePointerId) << ", position=" << position << ", velocity=" << toString(getVelocity(axis, pointerId)); } } Loading
libs/input/tests/VelocityTracker_test.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -278,6 +278,11 @@ static void computeAndCheckAxisScrollVelocity( const std::vector<std::pair<std::chrono::nanoseconds, float>>& motions, std::optional<float> targetVelocity) { checkVelocity(computeVelocity(strategy, motions, AMOTION_EVENT_AXIS_SCROLL), targetVelocity); // The strategy LSQ2 is not compatible with AXIS_SCROLL. In those situations, we should fall // back to a strategy that supports differential axes. checkVelocity(computeVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_SCROLL), targetVelocity); } static void computeAndCheckQuadraticVelocity(const std::vector<PlanarMotionEventEntry>& motions, Loading