OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/events/ozone/evdev/touch_noise/single_position_touch_noise_filter.h
" | 5 #include "ui/events/ozone/evdev/touch_noise/single_position_touch_noise_filter.h
" |
6 | 6 |
7 #include <inttypes.h> | 7 #include <inttypes.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 } // namespace | 39 } // namespace |
40 | 40 |
41 SinglePositionTouchNoiseFilter::SinglePositionTouchNoiseFilter() | 41 SinglePositionTouchNoiseFilter::SinglePositionTouchNoiseFilter() |
42 : tracked_touches_start_(0), tracked_touches_end_(0) { | 42 : tracked_touches_start_(0), tracked_touches_end_(0) { |
43 for (size_t i = 0; i < kNumTouchEvdevSlots; ++i) | 43 for (size_t i = 0; i < kNumTouchEvdevSlots; ++i) |
44 tracked_slots_[i] = kNumTrackedTouches; | 44 tracked_slots_[i] = kNumTrackedTouches; |
45 } | 45 } |
46 | 46 |
47 void SinglePositionTouchNoiseFilter::Filter( | 47 void SinglePositionTouchNoiseFilter::Filter( |
48 const std::vector<InProgressTouchEvdev>& touches, | 48 const std::vector<InProgressTouchEvdev>& touches, |
49 base::TimeDelta time, | 49 base::TimeTicks time, |
50 std::bitset<kNumTouchEvdevSlots>* slots_with_noise) { | 50 std::bitset<kNumTouchEvdevSlots>* slots_with_noise) { |
51 // Forget old touches which will no longer be considered for overlap. | 51 // Forget old touches which will no longer be considered for overlap. |
52 base::TimeDelta touch_cutoff = | 52 base::TimeTicks touch_cutoff = |
53 time - base::TimeDelta::FromMilliseconds(kMaxDurationMs); | 53 time - base::TimeDelta::FromMilliseconds(kMaxDurationMs); |
54 for (size_t i = tracked_touches_start_; i != tracked_touches_end_; | 54 for (size_t i = tracked_touches_start_; i != tracked_touches_end_; |
55 i = (i + 1) % kNumTrackedTouches) { | 55 i = (i + 1) % kNumTrackedTouches) { |
56 if (!tracked_touches_[i].valid) | 56 if (!tracked_touches_[i].valid) |
57 continue; | 57 continue; |
58 if (tracked_touches_[i].end < touch_cutoff) | 58 if (tracked_touches_[i].end < touch_cutoff) |
59 StopTrackingTouch(i); | 59 StopTrackingTouch(i); |
60 } | 60 } |
61 | 61 |
62 for (const InProgressTouchEvdev& touch : touches) { | 62 for (const InProgressTouchEvdev& touch : touches) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 while (!tracked_touches_[tracked_touches_start_].valid && | 135 while (!tracked_touches_[tracked_touches_start_].valid && |
136 tracked_touches_start_ != tracked_touches_end_) { | 136 tracked_touches_start_ != tracked_touches_end_) { |
137 tracked_touches_start_ = | 137 tracked_touches_start_ = |
138 (tracked_touches_start_ + 1) % kNumTrackedTouches; | 138 (tracked_touches_start_ + 1) % kNumTrackedTouches; |
139 } | 139 } |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 void SinglePositionTouchNoiseFilter::TrackTouch( | 143 void SinglePositionTouchNoiseFilter::TrackTouch( |
144 const InProgressTouchEvdev& touch, | 144 const InProgressTouchEvdev& touch, |
145 base::TimeDelta time) { | 145 base::TimeTicks time) { |
146 size_t index = tracked_touches_end_; | 146 size_t index = tracked_touches_end_; |
147 tracked_touches_end_ = (tracked_touches_end_ + 1) % kNumTrackedTouches; | 147 tracked_touches_end_ = (tracked_touches_end_ + 1) % kNumTrackedTouches; |
148 // If we would reach the start touch index, we cannot track any more touches. | 148 // If we would reach the start touch index, we cannot track any more touches. |
149 if (tracked_touches_end_ == tracked_touches_start_) { | 149 if (tracked_touches_end_ == tracked_touches_start_) { |
150 tracked_touches_end_ = index; | 150 tracked_touches_end_ = index; |
151 return; | 151 return; |
152 } | 152 } |
153 | 153 |
154 tracked_touches_[index].valid = true; | 154 tracked_touches_[index].valid = true; |
155 tracked_touches_[index].slot = touch.slot; | 155 tracked_touches_[index].slot = touch.slot; |
156 tracked_touches_[index].x = touch.x; | 156 tracked_touches_[index].x = touch.x; |
157 tracked_touches_[index].y = touch.y; | 157 tracked_touches_[index].y = touch.y; |
158 tracked_touches_[index].begin = time; | 158 tracked_touches_[index].begin = time; |
159 tracked_touches_[index].end = time; | 159 tracked_touches_[index].end = time; |
160 tracked_slots_[touch.slot] = index; | 160 tracked_slots_[touch.slot] = index; |
161 } | 161 } |
162 | 162 |
163 SinglePositionTouchNoiseFilter::SinglePositionTouchNoiseFilter::TrackedTouch:: | 163 SinglePositionTouchNoiseFilter::SinglePositionTouchNoiseFilter::TrackedTouch:: |
164 TrackedTouch() | 164 TrackedTouch() |
165 : valid(false), slot(0), x(0), y(0) { | 165 : valid(false), slot(0), x(0), y(0) { |
166 } | 166 } |
167 | 167 |
168 SinglePositionTouchNoiseFilter::SinglePositionTouchNoiseFilter::TrackedTouch:: | 168 SinglePositionTouchNoiseFilter::SinglePositionTouchNoiseFilter::TrackedTouch:: |
169 ~TrackedTouch() { | 169 ~TrackedTouch() { |
170 } | 170 } |
171 | 171 |
172 } // namespace ui | 172 } // namespace ui |
OLD | NEW |