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

Unified Diff: ui/events/ozone/evdev/touch_noise/touch_noise_remover.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 side-by-side diff with in-line comments
Download patch
Index: ui/events/ozone/evdev/touch_noise/touch_noise_remover.cc
diff --git a/ui/events/ozone/evdev/touch_noise/touch_noise_remover.cc b/ui/events/ozone/evdev/touch_noise/touch_noise_remover.cc
new file mode 100644
index 0000000000000000000000000000000000000000..da56da7025aefe48b770fdcd87935c2e1612336e
--- /dev/null
+++ b/ui/events/ozone/evdev/touch_noise/touch_noise_remover.cc
@@ -0,0 +1,63 @@
+// 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_noise/touch_noise_remover.h"
+
+#include "base/logging.h"
+#include "base/stl_util.h"
+#include "base/strings/stringprintf.h"
+#include "base/time/time.h"
+#include "ui/events/event.h"
+#include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h"
+#include "ui/events/ozone/evdev/touch_noise/far_apart_taps_touch_noise_filter.h"
+#include "ui/events/ozone/evdev/touch_noise/horizontally_aligned_touch_noise_filter.h"
+#include "ui/events/ozone/evdev/touch_noise/single_position_touch_noise_filter.h"
+
+namespace ui {
+
+TouchNoiseRemover::TouchNoiseRemover() {
+ filters_.push_back(new FarApartTapsTouchNoiseFilter);
+ filters_.push_back(new HorizontallyAlignedTouchNoiseFilter);
+ filters_.push_back(new SinglePositionTouchNoiseFilter);
+}
+
+TouchNoiseRemover::~TouchNoiseRemover() {
+ STLDeleteElements(&filters_);
+}
+
+void TouchNoiseRemover::RemoveNoise(
+ std::vector<ui::TouchEventParams>* touches,
+ base::TimeDelta timestamp) {
+ TouchNoiseFilter::Frame prev_frame = frame_;
+ const int num_slots = static_cast<int>(arraysize(frame_.fingers));
+ frame_.timestamp = timestamp;
+ for (const ui::TouchEventParams& touch : *touches) {
+ int slot = touch.touch_id;
+ if (slot < 0 || slot >= num_slots)
flackr 2015/03/10 05:23:40 Why do we need to check for slot < 0 || slot >= nu
+ continue;
+
+ DCHECK_EQ(timestamp, touch.timestamp);
+ frame_.fingers[slot].location = touch.location;
+ frame_.fingers[slot].tracking_id =
+ (touch.type == ET_TOUCH_RELEASED) ? -1 : touch.tracking_id;
+
+ if (touch.type == ET_TOUCH_PRESSED)
+ frame_.fingers[slot].canceled = false;
+ }
+
+ for (TouchNoiseFilter* filter : filters_)
+ filter->FilterFrame(&prev_frame, &frame_);
+
+ for (auto it = touches->begin(); it != touches->end();) {
+ int slot = it->touch_id;
+ if (slot < 0 || slot >= num_slots || frame_.fingers[slot].canceled) {
flackr 2015/03/10 05:23:40 ditto
+ VLOG(2) << base::StringPrintf("TrackingID %d cancelled", it->tracking_id);
+ it = touches->erase(it);
flackr 2015/03/10 05:23:40 Should use std::remove_if for linear complexity.
+ } else {
+ ++it;
+ }
+ }
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698