blob: 29dd7a8ed31d378e1f3b6ad75be054ef65246dc1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/events/ozone/evdev/touch_filter/horizontally_aligned_touch_noise_filter.h"
#include <inttypes.h>
#include <cmath>
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/stringprintf.h"
namespace ui {
namespace {
// The maximum horizontal distance between touches considered aligned.
int kMaxDistance = 3;
} // namespace
void HorizontallyAlignedTouchNoiseFilter::Filter(
const std::vector<InProgressTouchEvdev>& touches,
base::TimeTicks time,
std::bitset<kNumTouchEvdevSlots>* slots_with_noise) {
for (const InProgressTouchEvdev& touch : touches) {
// Only consider new touches.
if (!touch.touching || touch.was_touching)
continue;
// Check if within kMaxDistance of an existing touch.
for (const InProgressTouchEvdev& other_touch : touches) {
if (touch.slot == other_touch.slot || !other_touch.touching)
continue;
int distance = std::abs(other_touch.x - touch.x);
// Log |distance| to a UMA histogram to allow tuning of |kMaxDistance|.
UMA_HISTOGRAM_COUNTS_100(
"Ozone.TouchNoiseFilter.HorizontallyAlignedDistance", distance);
if (distance <= kMaxDistance) {
VLOG(2) << base::StringPrintf(
"Cancel tracking id %d, down at %" PRId64
" at %f,%f near touch %d at "
"%f,%f",
touch.tracking_id, time.since_origin().InMicroseconds(), touch.x,
touch.y, other_touch.tracking_id, other_touch.x, other_touch.y);
slots_with_noise->set(touch.slot);
}
}
}
}
} // namespace ui
|