Commit e48628f4 authored by Rob Schonberger's avatar Rob Schonberger Committed by Commit Bot

Instantiate and use PalmDetectionFilter within TouchEventConverterEvdev.

Do so by creating a Factory for PalmDetectionFilter, controlled by
flags and feature parameters, called
PalmDetectionFilterFactory. Thoroughly unit test this factory.

Add an instance of SharedPalmDetectionFilterState to
InputDeviceFactoryEvdev, and pipe it through to instances of
TouchEventConverterEvdev so that all PalmDetectionFilter get the same
shared instance, as intended.


Bug: 982118
Change-Id: I5878bc126a9e4bf809b9d5869520bef814aace8f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1716000
Commit-Queue: Rob Schonberger <robsc@chromium.org>
Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682567}
parent 004271d7
...@@ -624,6 +624,7 @@ if (!is_ios) { ...@@ -624,6 +624,7 @@ if (!is_ios) {
"ozone/evdev/touch_filter/false_touch_finder_unittest.cc", "ozone/evdev/touch_filter/false_touch_finder_unittest.cc",
"ozone/evdev/touch_filter/heuristic_stylus_palm_detection_filter_unittest.cc", "ozone/evdev/touch_filter/heuristic_stylus_palm_detection_filter_unittest.cc",
"ozone/evdev/touch_filter/open_palm_detection_filter_unittest.cc", "ozone/evdev/touch_filter/open_palm_detection_filter_unittest.cc",
"ozone/evdev/touch_filter/palm_detection_filter_factory_unittest.cc",
"ozone/gamepad/generic_gamepad_mapping_unittest.cc", "ozone/gamepad/generic_gamepad_mapping_unittest.cc",
] ]
......
...@@ -126,6 +126,8 @@ if (use_ozone) { ...@@ -126,6 +126,8 @@ if (use_ozone) {
"evdev/touch_filter/open_palm_detection_filter.h", "evdev/touch_filter/open_palm_detection_filter.h",
"evdev/touch_filter/palm_detection_filter.cc", "evdev/touch_filter/palm_detection_filter.cc",
"evdev/touch_filter/palm_detection_filter.h", "evdev/touch_filter/palm_detection_filter.h",
"evdev/touch_filter/palm_detection_filter_factory.cc",
"evdev/touch_filter/palm_detection_filter_factory.h",
"evdev/touch_filter/shared_palm_detection_filter_state.h", "evdev/touch_filter/shared_palm_detection_filter_state.h",
"evdev/touch_filter/single_position_touch_noise_filter.cc", "evdev/touch_filter/single_position_touch_noise_filter.cc",
"evdev/touch_filter/single_position_touch_noise_filter.h", "evdev/touch_filter/single_position_touch_noise_filter.h",
......
...@@ -56,6 +56,7 @@ struct OpenInputDeviceParams { ...@@ -56,6 +56,7 @@ struct OpenInputDeviceParams {
#if defined(USE_EVDEV_GESTURES) #if defined(USE_EVDEV_GESTURES)
GesturePropertyProvider* gesture_property_provider; GesturePropertyProvider* gesture_property_provider;
#endif #endif
SharedPalmDetectionFilterState* shared_palm_state;
}; };
#if defined(USE_EVDEV_GESTURES) #if defined(USE_EVDEV_GESTURES)
...@@ -105,7 +106,8 @@ std::unique_ptr<EventConverterEvdev> CreateConverter( ...@@ -105,7 +106,8 @@ std::unique_ptr<EventConverterEvdev> CreateConverter(
if (devinfo.HasTouchscreen()) { if (devinfo.HasTouchscreen()) {
std::unique_ptr<TouchEventConverterEvdev> converter( std::unique_ptr<TouchEventConverterEvdev> converter(
new TouchEventConverterEvdev(std::move(fd), params.path, params.id, new TouchEventConverterEvdev(std::move(fd), params.path, params.id,
devinfo, params.dispatcher)); devinfo, params.shared_palm_state,
params.dispatcher));
converter->Initialize(devinfo); converter->Initialize(devinfo);
return std::move(converter); return std::move(converter);
} }
...@@ -169,6 +171,7 @@ InputDeviceFactoryEvdev::InputDeviceFactoryEvdev( ...@@ -169,6 +171,7 @@ InputDeviceFactoryEvdev::InputDeviceFactoryEvdev(
CursorDelegateEvdev* cursor) CursorDelegateEvdev* cursor)
: task_runner_(base::ThreadTaskRunnerHandle::Get()), : task_runner_(base::ThreadTaskRunnerHandle::Get()),
cursor_(cursor), cursor_(cursor),
shared_palm_state_(new SharedPalmDetectionFilterState),
#if defined(USE_EVDEV_GESTURES) #if defined(USE_EVDEV_GESTURES)
gesture_property_provider_(new GesturePropertyProvider), gesture_property_provider_(new GesturePropertyProvider),
#endif #endif
...@@ -186,6 +189,7 @@ void InputDeviceFactoryEvdev::AddInputDevice(int id, ...@@ -186,6 +189,7 @@ void InputDeviceFactoryEvdev::AddInputDevice(int id,
params.path = path; params.path = path;
params.cursor = cursor_; params.cursor = cursor_;
params.dispatcher = dispatcher_.get(); params.dispatcher = dispatcher_.get();
params.shared_palm_state = shared_palm_state_.get();
#if defined(USE_EVDEV_GESTURES) #if defined(USE_EVDEV_GESTURES)
params.gesture_property_provider = gesture_property_provider_.get(); params.gesture_property_provider = gesture_property_provider_.get();
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "ui/events/ozone/evdev/event_device_info.h" #include "ui/events/ozone/evdev/event_device_info.h"
#include "ui/events/ozone/evdev/events_ozone_evdev_export.h" #include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
#include "ui/events/ozone/evdev/input_device_settings_evdev.h" #include "ui/events/ozone/evdev/input_device_settings_evdev.h"
#include "ui/events/ozone/evdev/touch_filter/shared_palm_detection_filter_state.h"
#include "ui/ozone/public/input_controller.h" #include "ui/ozone/public/input_controller.h"
#if defined(USE_EVDEV_GESTURES) #if defined(USE_EVDEV_GESTURES)
...@@ -110,6 +111,9 @@ class EVENTS_OZONE_EVDEV_EXPORT InputDeviceFactoryEvdev { ...@@ -110,6 +111,9 @@ class EVENTS_OZONE_EVDEV_EXPORT InputDeviceFactoryEvdev {
// Cursor movement. // Cursor movement.
CursorDelegateEvdev* cursor_; CursorDelegateEvdev* cursor_;
// Shared Palm state.
const std::unique_ptr<SharedPalmDetectionFilterState> shared_palm_state_;
#if defined(USE_EVDEV_GESTURES) #if defined(USE_EVDEV_GESTURES)
// Gesture library property provider (used by touchpads/mice). // Gesture library property provider (used by touchpads/mice).
std::unique_ptr<GesturePropertyProvider> gesture_property_provider_; std::unique_ptr<GesturePropertyProvider> gesture_property_provider_;
......
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h"
#include "ui/events/ozone/evdev/touch_evdev_types.h" #include "ui/events/ozone/evdev/touch_evdev_types.h"
#include "ui/events/ozone/evdev/touch_filter/false_touch_finder.h" #include "ui/events/ozone/evdev/touch_filter/false_touch_finder.h"
#include "ui/events/ozone/evdev/touch_filter/palm_detection_filter.h"
#include "ui/events/ozone/evdev/touch_filter/palm_detection_filter_factory.h"
#include "ui/ozone/public/input_controller.h" #include "ui/ozone/public/input_controller.h"
namespace { namespace {
...@@ -120,6 +122,7 @@ TouchEventConverterEvdev::TouchEventConverterEvdev( ...@@ -120,6 +122,7 @@ TouchEventConverterEvdev::TouchEventConverterEvdev(
base::FilePath path, base::FilePath path,
int id, int id,
const EventDeviceInfo& devinfo, const EventDeviceInfo& devinfo,
SharedPalmDetectionFilterState* shared_palm_state,
DeviceEventDispatcherEvdev* dispatcher) DeviceEventDispatcherEvdev* dispatcher)
: EventConverterEvdev(fd.get(), : EventConverterEvdev(fd.get(),
path, path,
...@@ -131,7 +134,9 @@ TouchEventConverterEvdev::TouchEventConverterEvdev( ...@@ -131,7 +134,9 @@ TouchEventConverterEvdev::TouchEventConverterEvdev(
devinfo.product_id(), devinfo.product_id(),
devinfo.version()), devinfo.version()),
input_device_fd_(std::move(fd)), input_device_fd_(std::move(fd)),
dispatcher_(dispatcher) { dispatcher_(dispatcher),
palm_detection_filter_(
CreatePalmDetectionFilter(devinfo, shared_palm_state)) {
touch_evdev_debug_buffer_.Initialize(devinfo); touch_evdev_debug_buffer_.Initialize(devinfo);
} }
...@@ -547,12 +552,15 @@ void TouchEventConverterEvdev::ReportEvents(base::TimeTicks timestamp) { ...@@ -547,12 +552,15 @@ void TouchEventConverterEvdev::ReportEvents(base::TimeTicks timestamp) {
if (false_touch_finder_) if (false_touch_finder_)
false_touch_finder_->HandleTouches(events_, timestamp); false_touch_finder_->HandleTouches(events_, timestamp);
std::bitset<kNumTouchEvdevSlots> hold, suppress;
palm_detection_filter_->Filter(events_, timestamp, &hold, &suppress);
for (size_t i = 0; i < events_.size(); i++) { for (size_t i = 0; i < events_.size(); i++) {
InProgressTouchEvdev* event = &events_[i]; InProgressTouchEvdev* event = &events_[i];
if (IsPalm(*event)) { if (IsPalm(*event)) {
event->cancelled = true; event->cancelled = true;
} }
event->held |= hold.test(i);
event->cancelled |= suppress.test(i);
if (event->altered && (event->cancelled || if (event->altered && (event->cancelled ||
(false_touch_finder_ && (false_touch_finder_ &&
false_touch_finder_->SlotHasNoise(event->slot)))) { false_touch_finder_->SlotHasNoise(event->slot)))) {
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "ui/events/ozone/evdev/event_device_info.h" #include "ui/events/ozone/evdev/event_device_info.h"
#include "ui/events/ozone/evdev/events_ozone_evdev_export.h" #include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
#include "ui/events/ozone/evdev/touch_evdev_debug_buffer.h" #include "ui/events/ozone/evdev/touch_evdev_debug_buffer.h"
#include "ui/events/ozone/evdev/touch_filter/palm_detection_filter.h"
namespace ui { namespace ui {
...@@ -43,6 +44,7 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev ...@@ -43,6 +44,7 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev
base::FilePath path, base::FilePath path,
int id, int id,
const EventDeviceInfo& devinfo, const EventDeviceInfo& devinfo,
SharedPalmDetectionFilterState* shared_palm_state,
DeviceEventDispatcherEvdev* dispatcher); DeviceEventDispatcherEvdev* dispatcher);
~TouchEventConverterEvdev() override; ~TouchEventConverterEvdev() override;
...@@ -173,6 +175,9 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev ...@@ -173,6 +175,9 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev
// Finds touches that need to be filtered. // Finds touches that need to be filtered.
std::unique_ptr<FalseTouchFinder> false_touch_finder_; std::unique_ptr<FalseTouchFinder> false_touch_finder_;
// Finds touches that are palms with user software not just firmware.
const std::unique_ptr<PalmDetectionFilter> palm_detection_filter_;
// Records the recent touch events. It is used to fill the feedback reports // Records the recent touch events. It is used to fill the feedback reports
TouchEventLogEvdev touch_evdev_debug_buffer_; TouchEventLogEvdev touch_evdev_debug_buffer_;
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "ui/events/ozone/evdev/event_device_test_util.h" #include "ui/events/ozone/evdev/event_device_test_util.h"
#include "ui/events/ozone/evdev/touch_evdev_types.h" #include "ui/events/ozone/evdev/touch_evdev_types.h"
#include "ui/events/ozone/evdev/touch_filter/false_touch_finder.h" #include "ui/events/ozone/evdev/touch_filter/false_touch_finder.h"
#include "ui/events/ozone/evdev/touch_filter/shared_palm_detection_filter_state.h"
#include "ui/events/ozone/evdev/touch_filter/touch_filter.h" #include "ui/events/ozone/evdev/touch_filter/touch_filter.h"
#include "ui/events/platform/platform_event_dispatcher.h" #include "ui/events/platform/platform_event_dispatcher.h"
#include "ui/events/platform/platform_event_source.h" #include "ui/events/platform/platform_event_source.h"
...@@ -90,10 +91,13 @@ struct GenericEventParams { ...@@ -90,10 +91,13 @@ struct GenericEventParams {
class MockTouchEventConverterEvdev : public TouchEventConverterEvdev { class MockTouchEventConverterEvdev : public TouchEventConverterEvdev {
public: public:
MockTouchEventConverterEvdev(base::ScopedFD fd, MockTouchEventConverterEvdev(
base::FilePath path,
const EventDeviceInfo& devinfo, base::ScopedFD fd,
DeviceEventDispatcherEvdev* dispatcher); base::FilePath path,
const EventDeviceInfo& devinfo,
SharedPalmDetectionFilterState* shared_palm_state,
DeviceEventDispatcherEvdev* dispatcher);
~MockTouchEventConverterEvdev() override; ~MockTouchEventConverterEvdev() override;
void ConfigureReadMock(struct input_event* queue, void ConfigureReadMock(struct input_event* queue,
...@@ -180,8 +184,14 @@ MockTouchEventConverterEvdev::MockTouchEventConverterEvdev( ...@@ -180,8 +184,14 @@ MockTouchEventConverterEvdev::MockTouchEventConverterEvdev(
base::ScopedFD fd, base::ScopedFD fd,
base::FilePath path, base::FilePath path,
const EventDeviceInfo& devinfo, const EventDeviceInfo& devinfo,
SharedPalmDetectionFilterState* shared_palm_state,
DeviceEventDispatcherEvdev* dispatcher) DeviceEventDispatcherEvdev* dispatcher)
: TouchEventConverterEvdev(std::move(fd), path, 1, devinfo, dispatcher) { : TouchEventConverterEvdev(std::move(fd),
path,
1,
devinfo,
shared_palm_state,
dispatcher) {
int fds[2]; int fds[2];
if (pipe(fds)) if (pipe(fds))
...@@ -232,13 +242,14 @@ class TouchEventConverterEvdevTest : public testing::Test { ...@@ -232,13 +242,14 @@ class TouchEventConverterEvdevTest : public testing::Test {
// Device creation happens on a worker thread since it may involve blocking // Device creation happens on a worker thread since it may involve blocking
// operations. Simulate that by creating it before creating a UI message // operations. Simulate that by creating it before creating a UI message
// loop. // loop.
shared_palm_state_.reset(new ui::SharedPalmDetectionFilterState);
EventDeviceInfo devinfo; EventDeviceInfo devinfo;
dispatcher_.reset(new ui::MockDeviceEventDispatcherEvdev( dispatcher_.reset(new ui::MockDeviceEventDispatcherEvdev(
base::BindRepeating(&TouchEventConverterEvdevTest::DispatchCallback, base::BindRepeating(&TouchEventConverterEvdevTest::DispatchCallback,
base::Unretained(this)))); base::Unretained(this))));
device_.reset(new ui::MockTouchEventConverterEvdev( device_.reset(new ui::MockTouchEventConverterEvdev(
std::move(events_in), base::FilePath(kTestDevicePath), devinfo, std::move(events_in), base::FilePath(kTestDevicePath), devinfo,
dispatcher_.get())); shared_palm_state_.get(), dispatcher_.get()));
device_->Initialize(devinfo); device_->Initialize(devinfo);
loop_ = new base::MessageLoopForUI; loop_ = new base::MessageLoopForUI;
...@@ -258,7 +269,9 @@ class TouchEventConverterEvdevTest : public testing::Test { ...@@ -258,7 +269,9 @@ class TouchEventConverterEvdevTest : public testing::Test {
} }
ui::MockTouchEventConverterEvdev* device() { return device_.get(); } ui::MockTouchEventConverterEvdev* device() { return device_.get(); }
ui::SharedPalmDetectionFilterState* shared_palm_state() {
return shared_palm_state_.get();
}
unsigned size() { return dispatched_events_.size(); } unsigned size() { return dispatched_events_.size(); }
const ui::TouchEventParams& dispatched_touch_event(unsigned index) { const ui::TouchEventParams& dispatched_touch_event(unsigned index) {
DCHECK_GT(dispatched_events_.size(), index); DCHECK_GT(dispatched_events_.size(), index);
...@@ -297,7 +310,7 @@ class TouchEventConverterEvdevTest : public testing::Test { ...@@ -297,7 +310,7 @@ class TouchEventConverterEvdevTest : public testing::Test {
std::unique_ptr<ui::MockTouchEventConverterEvdev> device_; std::unique_ptr<ui::MockTouchEventConverterEvdev> device_;
std::unique_ptr<ui::MockDeviceEventDispatcherEvdev> dispatcher_; std::unique_ptr<ui::MockDeviceEventDispatcherEvdev> dispatcher_;
std::unique_ptr<ui::test::ScopedEventTestTickClock> test_clock_; std::unique_ptr<ui::test::ScopedEventTestTickClock> test_clock_;
std::unique_ptr<ui::SharedPalmDetectionFilterState> shared_palm_state_;
base::ScopedFD events_out_; base::ScopedFD events_out_;
void DispatchCallback(const GenericEventParams& params) { void DispatchCallback(const GenericEventParams& params) {
......
...@@ -60,5 +60,17 @@ HeuristicStylusPalmDetectionFilter::HeuristicStylusPalmDetectionFilter( ...@@ -60,5 +60,17 @@ HeuristicStylusPalmDetectionFilter::HeuristicStylusPalmDetectionFilter(
DCHECK(hold >= cancel) << "Expected hold time to be longer than cancel time."; DCHECK(hold >= cancel) << "Expected hold time to be longer than cancel time.";
} }
const char HeuristicStylusPalmDetectionFilter::kFilterName[] =
"HeuristicStylusPalmDetectionFilter";
std::string HeuristicStylusPalmDetectionFilter::FilterNameForTesting() const {
return kFilterName;
}
HeuristicStylusPalmDetectionFilter::~HeuristicStylusPalmDetectionFilter() {} HeuristicStylusPalmDetectionFilter::~HeuristicStylusPalmDetectionFilter() {}
base::TimeDelta HeuristicStylusPalmDetectionFilter::HoldTime() const {
return time_after_stylus_to_hold_;
}
base::TimeDelta HeuristicStylusPalmDetectionFilter::CancelTime() const {
return time_after_stylus_to_cancel_;
}
} // namespace ui } // namespace ui
...@@ -26,6 +26,11 @@ namespace ui { ...@@ -26,6 +26,11 @@ namespace ui {
// this are held for the stroke count (as above). If they're cancelled // this are held for the stroke count (as above). If they're cancelled
// externally, we never report them. If they terminate before the count, we // externally, we never report them. If they terminate before the count, we
// output all items. // output all items.
//
// NOTE: This filter is only intended for certain boards of hardware that have
// poor interaction between a mutually exclusive stylus and finger input:
// Turning it on for devices where is not intended will probably degrade
// performance and create a poor UX.
class EVENTS_OZONE_EVDEV_EXPORT HeuristicStylusPalmDetectionFilter class EVENTS_OZONE_EVDEV_EXPORT HeuristicStylusPalmDetectionFilter
: public PalmDetectionFilter { : public PalmDetectionFilter {
public: public:
...@@ -40,6 +45,12 @@ class EVENTS_OZONE_EVDEV_EXPORT HeuristicStylusPalmDetectionFilter ...@@ -40,6 +45,12 @@ class EVENTS_OZONE_EVDEV_EXPORT HeuristicStylusPalmDetectionFilter
std::bitset<kNumTouchEvdevSlots>* slots_to_hold, std::bitset<kNumTouchEvdevSlots>* slots_to_hold,
std::bitset<kNumTouchEvdevSlots>* slots_to_suppress) override; std::bitset<kNumTouchEvdevSlots>* slots_to_suppress) override;
const static char kFilterName[];
std::string FilterNameForTesting() const override;
base::TimeDelta HoldTime() const;
base::TimeDelta CancelTime() const;
private: private:
const int hold_stroke_count_; const int hold_stroke_count_;
const base::TimeDelta time_after_stylus_to_hold_; const base::TimeDelta time_after_stylus_to_hold_;
......
...@@ -18,5 +18,10 @@ void OpenPalmDetectionFilter::Filter( ...@@ -18,5 +18,10 @@ void OpenPalmDetectionFilter::Filter(
slots_to_suppress->reset(); slots_to_suppress->reset();
} }
const char OpenPalmDetectionFilter::kFilterName[] = "OpenPalmDetectionFilter";
std::string OpenPalmDetectionFilter::FilterNameForTesting() const {
return kFilterName;
}
OpenPalmDetectionFilter::~OpenPalmDetectionFilter() {} OpenPalmDetectionFilter::~OpenPalmDetectionFilter() {}
} // namespace ui } // namespace ui
...@@ -27,6 +27,9 @@ class EVENTS_OZONE_EVDEV_EXPORT OpenPalmDetectionFilter ...@@ -27,6 +27,9 @@ class EVENTS_OZONE_EVDEV_EXPORT OpenPalmDetectionFilter
std::bitset<kNumTouchEvdevSlots>* slots_to_hold, std::bitset<kNumTouchEvdevSlots>* slots_to_hold,
std::bitset<kNumTouchEvdevSlots>* slots_to_suppress) override; std::bitset<kNumTouchEvdevSlots>* slots_to_suppress) override;
const static char kFilterName[];
std::string FilterNameForTesting() const override;
private: private:
DISALLOW_COPY_AND_ASSIGN(OpenPalmDetectionFilter); DISALLOW_COPY_AND_ASSIGN(OpenPalmDetectionFilter);
}; };
......
...@@ -39,6 +39,10 @@ class EVENTS_OZONE_EVDEV_EXPORT PalmDetectionFilter { ...@@ -39,6 +39,10 @@ class EVENTS_OZONE_EVDEV_EXPORT PalmDetectionFilter {
base::TimeTicks time, base::TimeTicks time,
std::bitset<kNumTouchEvdevSlots>* slots_to_hold, std::bitset<kNumTouchEvdevSlots>* slots_to_hold,
std::bitset<kNumTouchEvdevSlots>* slots_to_suppress) = 0; std::bitset<kNumTouchEvdevSlots>* slots_to_suppress) = 0;
// The name of this filter, for testing purposes.
virtual std::string FilterNameForTesting() const = 0;
virtual ~PalmDetectionFilter(); virtual ~PalmDetectionFilter();
protected: protected:
......
// Copyright 2019 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/palm_detection_filter_factory.h"
#include <memory>
#include "base/feature_list.h"
#include "base/time/time.h"
#include "ui/events/ozone/evdev/event_device_info.h"
#include "ui/events/ozone/evdev/touch_filter/heuristic_stylus_palm_detection_filter.h"
#include "ui/events/ozone/evdev/touch_filter/open_palm_detection_filter.h"
#include "ui/events/ozone/evdev/touch_filter/palm_detection_filter.h"
namespace ui {
const base::Feature kEnableHeuristicPalmDetectionFilter{
"EnableHeuristicPalmDetectionFilter", base::FEATURE_DISABLED_BY_DEFAULT};
const base::FeatureParam<double> kHeuristicCancelThresholdSeconds{
&kEnableHeuristicPalmDetectionFilter,
"heuristic_palm_cancel_threshold_seconds", 0.4};
const base::FeatureParam<double> kHeuristicHoldThresholdSeconds{
&kEnableHeuristicPalmDetectionFilter,
"heuristic_palm_hold_threshold_seconds", 1.0};
const base::FeatureParam<int> kHeuristicStrokeCount{
&kEnableHeuristicPalmDetectionFilter, "heuristic_palm_stroke_count", 0};
std::unique_ptr<PalmDetectionFilter> CreatePalmDetectionFilter(
const EventDeviceInfo& devinfo,
SharedPalmDetectionFilterState* shared_palm_state) {
if (base::FeatureList::IsEnabled(kEnableHeuristicPalmDetectionFilter)) {
const base::TimeDelta hold_time =
base::TimeDelta::FromSecondsD(kHeuristicHoldThresholdSeconds.Get());
const base::TimeDelta cancel_time =
base::TimeDelta::FromSecondsD(kHeuristicCancelThresholdSeconds.Get());
const int stroke_count = kHeuristicStrokeCount.Get();
return std::make_unique<HeuristicStylusPalmDetectionFilter>(
shared_palm_state, stroke_count, hold_time, cancel_time);
}
return std::make_unique<OpenPalmDetectionFilter>(shared_palm_state);
}
} // namespace ui
// Copyright 2019 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.
#ifndef UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_PALM_DETECTION_FILTER_FACTORY_H_
#define UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_PALM_DETECTION_FILTER_FACTORY_H_
#include <memory>
#include <set>
#include <string>
#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
#include "base/time/time.h"
#include "ui/events/ozone/evdev/event_device_info.h"
#include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
#include "ui/events/ozone/evdev/touch_filter/heuristic_stylus_palm_detection_filter.h"
#include "ui/events/ozone/evdev/touch_filter/open_palm_detection_filter.h"
#include "ui/events/ozone/evdev/touch_filter/palm_detection_filter.h"
#include "ui/events/ozone/evdev/touch_filter/shared_palm_detection_filter_state.h"
namespace ui {
extern const EVENTS_OZONE_EVDEV_EXPORT base::Feature
kEnableHeuristicPalmDetectionFilter;
extern const EVENTS_OZONE_EVDEV_EXPORT base::FeatureParam<double>
kHeuristicCancelThresholdSeconds;
extern const EVENTS_OZONE_EVDEV_EXPORT base::FeatureParam<double>
kHeuristicHoldThresholdSeconds;
extern const EVENTS_OZONE_EVDEV_EXPORT base::FeatureParam<int>
kHeuristicStrokeCount;
std::unique_ptr<PalmDetectionFilter> EVENTS_OZONE_EVDEV_EXPORT
CreatePalmDetectionFilter(const EventDeviceInfo& devinfo,
SharedPalmDetectionFilterState* shared_palm_state);
} // namespace ui
#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_PALM_DETECTION_FILTER_FACTORY_H_
// Copyright 2019 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/palm_detection_filter_factory.h"
#include <linux/input.h>
#include "base/test/scoped_feature_list.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/ozone/evdev/event_device_info.h"
#include "ui/events/ozone/evdev/event_device_test_util.h"
#include "ui/events/ozone/evdev/touch_filter/open_palm_detection_filter.h"
#include "ui/events/ozone/evdev/touch_filter/palm_detection_filter.h"
#include "ui/events/ozone/evdev/touch_filter/shared_palm_detection_filter_state.h"
namespace ui {
class PalmDetectionFilterFactoryTest : public testing::Test {
public:
PalmDetectionFilterFactoryTest() = default;
void SetUp() override {
EXPECT_TRUE(
CapabilitiesToDeviceInfo(kEveTouchScreen, &eve_touchscreen_info_));
EXPECT_TRUE(CapabilitiesToDeviceInfo(kNocturneTouchScreen,
&nocturne_touchscreen_info_));
EXPECT_TRUE(
CapabilitiesToDeviceInfo(kNocturneStylus, &nocturne_stylus_info_));
EXPECT_TRUE(CapabilitiesToDeviceInfo(kEveStylus, &eve_stylus_info_));
scoped_feature_list_.reset(new base::test::ScopedFeatureList);
}
protected:
std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_;
EventDeviceInfo eve_touchscreen_info_, eve_stylus_info_,
nocturne_touchscreen_info_, nocturne_stylus_info_;
SharedPalmDetectionFilterState shared_palm_state_;
DISALLOW_COPY_AND_ASSIGN(PalmDetectionFilterFactoryTest);
};
TEST_F(PalmDetectionFilterFactoryTest, AllDisabled) {
scoped_feature_list_->InitAndDisableFeature(
ui::kEnableHeuristicPalmDetectionFilter);
std::unique_ptr<PalmDetectionFilter> palm_filter =
CreatePalmDetectionFilter(eve_touchscreen_info_, &shared_palm_state_);
EXPECT_EQ(OpenPalmDetectionFilter::kFilterName,
palm_filter->FilterNameForTesting());
palm_filter = CreatePalmDetectionFilter(nocturne_touchscreen_info_,
&shared_palm_state_);
EXPECT_EQ(OpenPalmDetectionFilter::kFilterName,
palm_filter->FilterNameForTesting());
}
TEST_F(PalmDetectionFilterFactoryTest, HeuristicEnabledForEve) {
scoped_feature_list_->InitWithFeaturesAndParameters(
{base::test::ScopedFeatureList::FeatureAndParams(
ui::kEnableHeuristicPalmDetectionFilter, {})},
{});
std::unique_ptr<PalmDetectionFilter> palm_filter =
CreatePalmDetectionFilter(eve_touchscreen_info_, &shared_palm_state_);
EXPECT_EQ(HeuristicStylusPalmDetectionFilter::kFilterName,
palm_filter->FilterNameForTesting());
palm_filter = CreatePalmDetectionFilter(nocturne_touchscreen_info_,
&shared_palm_state_);
EXPECT_EQ(HeuristicStylusPalmDetectionFilter::kFilterName,
palm_filter->FilterNameForTesting());
// And the stylus.
palm_filter =
CreatePalmDetectionFilter(nocturne_stylus_info_, &shared_palm_state_);
EXPECT_EQ(HeuristicStylusPalmDetectionFilter::kFilterName,
palm_filter->FilterNameForTesting());
palm_filter =
CreatePalmDetectionFilter(eve_stylus_info_, &shared_palm_state_);
EXPECT_EQ(HeuristicStylusPalmDetectionFilter::kFilterName,
palm_filter->FilterNameForTesting());
}
TEST_F(PalmDetectionFilterFactoryTest, HeuristicTimesSet) {
scoped_feature_list_->InitWithFeaturesAndParameters(
{base::test::ScopedFeatureList::FeatureAndParams(
ui::kEnableHeuristicPalmDetectionFilter,
{{"heuristic_palm_cancel_threshold_seconds", "0.8"},
{"heuristic_palm_hold_threshold_seconds", "15.327"}})},
{});
std::unique_ptr<PalmDetectionFilter> palm_filter = CreatePalmDetectionFilter(
nocturne_touchscreen_info_, &shared_palm_state_);
ASSERT_EQ(HeuristicStylusPalmDetectionFilter::kFilterName,
palm_filter->FilterNameForTesting());
HeuristicStylusPalmDetectionFilter* heuristic_filter =
static_cast<HeuristicStylusPalmDetectionFilter*>(palm_filter.get());
EXPECT_EQ(base::TimeDelta::FromSecondsD(0.8), heuristic_filter->CancelTime());
EXPECT_EQ(base::TimeDelta::FromSecondsD(15.327),
heuristic_filter->HoldTime());
}
} // namespace ui
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment