New impulse-based VelocityTracker strategy.
New velocity calculation strategy for VelocityTracker.
The strategy models the phone screen as a physical object
that gets pushed by the finger. Upon liftoff, the total
work done on the object (past 100ms of data and at most
20 most recent samples) is considered to be kinetic energy,
which gets converted into equivalent velocity.
Works well with "bad" data - unclean touch liftoff,
repeated coordinates. Time-shift invariant. Performance
otherwise similar to the current default strategy,
quadratic unweighted least squares.
Bug: 35412046
Test: Recorded bad scroll event on swordfish, this fixes the
fling in the wrong direction. Also tested common usecase
scenarios on sailfish, no regressions observed. Similar
velocity values to lsq2 strategy.
Change-Id: Ib439db0ce3b4fe84f59cf66683eae0b5df7776eb
diff --git a/include/input/VelocityTracker.h b/include/input/VelocityTracker.h
index 795f575..ffa1614 100644
--- a/include/input/VelocityTracker.h
+++ b/include/input/VelocityTracker.h
@@ -264,6 +264,40 @@
Movement mMovements[HISTORY_SIZE];
};
+class ImpulseVelocityTrackerStrategy : public VelocityTrackerStrategy {
+public:
+ ImpulseVelocityTrackerStrategy();
+ virtual ~ImpulseVelocityTrackerStrategy();
+
+ virtual void clear();
+ virtual void clearPointers(BitSet32 idBits);
+ virtual void addMovement(nsecs_t eventTime, BitSet32 idBits,
+ const VelocityTracker::Position* positions);
+ virtual bool getEstimator(uint32_t id, VelocityTracker::Estimator* outEstimator) const;
+
+private:
+ // Sample horizon.
+ // We don't use too much history by default since we want to react to quick
+ // changes in direction.
+ static constexpr nsecs_t HORIZON = 100 * 1000000; // 100 ms
+
+ // Number of samples to keep.
+ static constexpr size_t HISTORY_SIZE = 20;
+
+ struct Movement {
+ nsecs_t eventTime;
+ BitSet32 idBits;
+ VelocityTracker::Position positions[MAX_POINTERS];
+
+ inline const VelocityTracker::Position& getPosition(uint32_t id) const {
+ return positions[idBits.getIndexOfBit(id)];
+ }
+ };
+
+ size_t mIndex;
+ Movement mMovements[HISTORY_SIZE];
+};
+
} // namespace android
#endif // _LIBINPUT_VELOCITY_TRACKER_H