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

Side by Side Diff: ui/events/ozone/evdev/touch_noise/far_apart_taps_touch_noise_filter.cc

Issue 991533002: Port Chromium OS touch noise filtering to Chromium (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 2015 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 #include "ui/events/ozone/evdev/touch_noise/far_apart_taps_touch_noise_filter.h"
6
7 #include <cmath>
8
9 #include "base/logging.h"
10 #include "base/strings/stringprintf.h"
11
12 namespace ui {
13
14 namespace {
15
16 // Minimum squared distance between taps to be considered far apart.
17 const int kMinDistance2 = 1500 * 1500;
18
19 // Max time between taps considered.
20 const int kMaxTapDeltaMs = 30;
21
22 // Maximum squared movement of a touch to still be considered a tap.
23 const int kMaxTapMovement2 = 20 * 20;
24
25 // Returns the squared distance between |p1| and |p2|.
26 int Distance2(const gfx::PointF& p1, const gfx::PointF& p2) {
27 gfx::Vector2dF offset = p2 - p1;
28 return offset.x() * offset.x() + offset.y() * offset.y();
29 }
30
31 } // namespace
32
33 void FarApartTapsTouchNoiseFilter::FilterFrame(Frame* previous,
34 Frame* current) {
35 // Remove old taps and touches moving more than min delta.
36 base::TimeDelta tap_cutoff =
37 current->timestamp - base::TimeDelta::FromMilliseconds(kMaxTapDeltaMs);
38 for (size_t i = 0; i < kNumSlots; ++i) {
39 if (tracked_taps_[i].start < tap_cutoff)
40 tracked_taps_[i].Invalidate();
41 }
42
43 for (size_t slot = 0; slot < kNumSlots; ++slot) {
44 Finger* cur = &current->fingers[slot];
45 Finger* prev = &previous->fingers[slot];
46
47 // Only look at slots with active touches.
48 if (cur->tracking_id == -1 && prev->tracking_id == -1)
49 continue;
50
51 bool arrived = prev->tracking_id == -1 && cur->tracking_id > 0;
52 bool departing = prev->tracking_id >= 0 && cur->tracking_id == -1;
53
54 if (arrived) {
55 // Track new finger info.
56 tracked_taps_[slot] = Tap(current->timestamp, cur->location);
57 } else if (tracked_taps_[slot].is_valid()) {
58 // Check if this finger has moved too far to be considered a tap.
59 if (kMaxTapMovement2 <
60 Distance2(cur->location, tracked_taps_[slot].location)) {
61 tracked_taps_[slot].Invalidate();
62 }
63 }
64
65 if (tracked_taps_[slot].is_valid()) {
66 // Check distance from other tracked taps.
67 int min_distance2 = -1;
68 for (size_t i = 0; i < kNumSlots; ++i) {
69 if (i == slot || !tracked_taps_[i].is_valid())
70 continue;
71
72 int dist2 = Distance2(tracked_taps_[i].location, cur->location);
73 if (min_distance2 < 0 || dist2 < min_distance2)
74 min_distance2 = dist2;
75 }
76
77 if (min_distance2 > kMinDistance2) {
78 // The other finger should see this one on its next frame and also
79 // get canceled.
80 VLOG(2) << base::StringPrintf(
81 "Cancel tracking id %d %.0fpx from other current taps.",
82 departing ? prev->tracking_id : cur->tracking_id,
83 sqrt(min_distance2));
84 cur->canceled = true;
flackr 2015/03/10 05:23:40 Since we're in chrome codebase now, we should add
pkotwicz 2015/03/13 03:53:16 I'd rather do this in a separate CL. I have filed
flackr 2015/03/13 15:08:36 Of course, we may also want to track a histogram o
85 }
86 }
87
88 if (departing)
89 tracked_taps_[slot].Invalidate();
90 }
91 }
92
93 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698