Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: ui/events/gesture_detection/velocity_tracker.h

Issue 128613003: [Tracking Patch] Unified gesture detection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef UI_EVENTS_GESTURE_DETECTION_VELOCITY_TRACKER_H_
6 #define UI_EVENTS_GESTURE_DETECTION_VELOCITY_TRACKER_H_
7
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/time.h"
11 #include "ui/events/gesture_detection/bitset_32.h"
12
13 namespace ui {
14
15 class MotionEvent;
16 class VelocityTrackerStrategy;
17
18 namespace {
19 struct Estimator;
20 struct Position;
21 }
22
23 // Port of VelocityTracker from Android
24 // * platform/frameworks/native/include/input/VelocityTracker.h
25 // * Change-Id: I4983db61b53e28479fc90d9211fafff68f7f49a6
26 // * Please update the Change-Id as upstream Android changes are pulled.
27 class VelocityTracker {
28 public:
29 enum {
30 MAX_POINTERS = 16,
31 MAX_POINTER_ID = 31
32 };
33
34 enum Strategy {
35 // 1st order least squares. Quality: POOR.
36 // Frequently underfits the touch data especially when the finger
37 // accelerates or changes direction. Often underestimates velocity. The
38 // direction is overly influenced by historical touch points.
39 LSQ1,
40
41 // 2nd order least squares. Quality: VERY GOOD.
42 // Pretty much ideal, but can be confused by certain kinds of touch data,
43 // particularly if the panel has a tendency to generate delayed,
44 // duplicate or jittery touch coordinates when the finger is released.
45 LSQ2,
46
47 // 3rd order least squares. Quality: UNUSABLE.
48 // Frequently overfits the touch data yielding wildly divergent estimates
49 // of the velocity when the finger is released.
50 LSQ3,
51
52 // 2nd order weighted least squares, delta weighting.
53 // Quality: EXPERIMENTAL
54 WLSQ2_DELTA,
55
56 // 2nd order weighted least squares, central weighting.
57 // Quality: EXPERIMENTAL
58 WLSQ2_CENTRAL,
59
60 // 2nd order weighted least squares, recent weighting.
61 // Quality: EXPERIMENTAL
62 WLSQ2_RECENT,
63
64 // 1st order integrating filter. Quality: GOOD.
65 // Not as good as 'lsq2' because it cannot estimate acceleration but it is
66 // more tolerant of errors. Like 'lsq1', this strategy tends to
67 // underestimate
68 // the velocity of a fling but this strategy tends to respond to changes in
69 // direction more quickly and accurately.
70 INT1,
71
72 // 2nd order integrating filter. Quality: EXPERIMENTAL.
73 // For comparison purposes only. Unlike 'int1' this strategy can compensate
74 // for acceleration but it typically overestimates the effect.
75 INT2,
76
77 STRATEGY_MAX = INT2,
78
79 // The default velocity tracker strategy.
80 // Although other strategies are available for testing and comparison
81 // purposes, this is the strategy that applications will actually use. Be
82 // very careful when adjusting the default strategy because it can
83 // dramatically affect (often in a bad way) the user experience.
84 STRATEGY_DEFAULT = LSQ2,
85 };
86
87 // Creates a velocity tracker using the default strategy for the platform.
88 VelocityTracker();
89
90 // Creates a velocity tracker using the specified strategy.
91 // If strategy is NULL, uses the default strategy for the platform.
92 explicit VelocityTracker(Strategy strategy);
93
94 ~VelocityTracker();
95
96 // Resets the velocity tracker state.
97 void Clear();
98
99 // Adds movement information for all pointers in a MotionEvent, including
100 // historical samples.
101 void AddMovement(const MotionEvent& event);
102
103 // Gets the velocity of the specified pointer id in position units per second.
104 // Returns false and sets the velocity components to zero if there is
105 // insufficient movement information for the pointer.
106 bool GetVelocity(uint32_t id, float* outVx, float* outVy) const;
107
108 // Gets the active pointer id, or -1 if none.
109 inline int32_t GetActivePointerId() const { return active_pointer_id_; }
110
111 // Gets a bitset containing all pointer ids from the most recent movement.
112 inline BitSet32 GetCurrentPointerIdBits() const {
113 return current_pointer_id_bits_;
114 }
115
116 private:
117 // Resets the velocity tracker state for specific pointers.
118 // Call this method when some pointers have changed and may be reusing
119 // an id that was assigned to a different pointer earlier.
120 void ClearPointers(BitSet32 id_bits);
121
122 // Adds movement information for a set of pointers.
123 // The id_bits bitfield specifies the pointer ids of the pointers whose
124 // positions
125 // are included in the movement.
126 // The positions array contains position information for each pointer in order
127 // by
128 // increasing id. Its size should be equal to the number of one bits in
129 // id_bits.
130 void AddMovement(const base::TimeTicks& event_time,
131 BitSet32 id_bits,
132 const Position* positions);
133
134 // Gets an estimator for the recent movements of the specified pointer id.
135 // Returns false and clears the estimator if there is no information available
136 // about the pointer.
137 bool GetEstimator(uint32_t id, Estimator* out_estimator) const;
138
139 base::TimeTicks last_event_time_;
140 BitSet32 current_pointer_id_bits_;
141 int32_t active_pointer_id_;
142 scoped_ptr<VelocityTrackerStrategy> strategy_;
143 };
144
145 } // namespace ui
146
147 #endif // UI_EVENTS_GESTURE_DETECTION_VELOCITY_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698