Chromium Code Reviews| 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 |