Commit 016609c1 authored by Michael Spang's avatar Michael Spang Committed by Commit Bot

ozone: evdev: Minor stylistic cleanups for touch filtering

Fix a number of minor style deviations in the touch filtering code:

- Add blank lines where they are typically expected
- Avoid some potential namespace conflicts by using less generic names
- Un-abbreviate some local variable names
- Make structs less interesting by pulling member functions out
- Replace TimeTicks::UnixEpoch() with TimeTicks() as we don't care about dates
- s/const static/static const/
- Exports come before any other qualifiers.
- Opportunistically constify a few members
- Define assignment operators when there are copy/move constructors.
- Class data members must be either private or const.
- Only one declaration per statement.

Change-Id: I35570a98a82d8a60c04c1b956e278f40e1b694b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1839435Reviewed-by: default avatarRob Schonberger <robsc@chromium.org>
Commit-Queue: Rob Schonberger <robsc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708917}
parent 55600186
......@@ -694,4 +694,5 @@ const char TouchEventConverterEvdev::kHoldCountAtCancelEventName[] =
"Ozone.TouchEventConverterEvdev.HoldCountAtCancel";
const char TouchEventConverterEvdev::kPalmFilterTimerEventName[] =
"Ozone.TouchEventConverterEvdev.PalmDetectionFilterTime";
} // namespace ui
......@@ -37,7 +37,7 @@ class DeviceEventDispatcherEvdev;
class FalseTouchFinder;
struct InProgressTouchEvdev;
extern const EVENTS_OZONE_EVDEV_EXPORT base::Feature kEnableSingleCancelTouch;
EVENTS_OZONE_EVDEV_EXPORT extern const base::Feature kEnableSingleCancelTouch;
class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev
: public EventConverterEvdev {
......@@ -102,9 +102,11 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev
void UpdateTrackingId(int slot, int tracking_id);
void ReleaseTouches();
// Returns true if all touches were marked cancelled. Otherwise false.
bool MaybeCancelAllTouches();
bool IsPalm(const InProgressTouchEvdev& touch);
// Normalize pressure value to [0, 1].
float ScalePressure(int32_t value) const;
......@@ -186,6 +188,7 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev
// Callback to enable/disable palm suppression.
base::RepeatingCallback<void(bool)> enable_palm_suppression_callback_;
DISALLOW_COPY_AND_ASSIGN(TouchEventConverterEvdev);
};
......
......@@ -16,7 +16,6 @@
namespace ui {
namespace {
// The maximum distance from the border to be considered for filtering
......@@ -30,9 +29,9 @@ bool IsNearBorder(const gfx::Point& point, gfx::Size touchscreen_size) {
} // namespace
EdgeTouchFilter::EdgeTouchFilter(gfx::Size& touchscreen_size)
: touchscreen_size_(touchscreen_size) {
}
EdgeTouchFilter::EdgeTouchFilter(const gfx::Size& touchscreen_size)
: touchscreen_size_(touchscreen_size) {}
EdgeTouchFilter::~EdgeTouchFilter() {}
void EdgeTouchFilter::Filter(
......
......@@ -14,7 +14,7 @@ namespace ui {
class EdgeTouchFilter : public TouchFilter {
public:
EdgeTouchFilter(gfx::Size& touchscreen_size);
EdgeTouchFilter(const gfx::Size& touchscreen_size);
~EdgeTouchFilter() override;
// TouchFilter:
......@@ -27,7 +27,7 @@ class EdgeTouchFilter : public TouchFilter {
gfx::Point start_positions_[kNumTouchEvdevSlots];
std::bitset<kNumTouchEvdevSlots> slots_filtered_;
gfx::Size touchscreen_size_;
const gfx::Size touchscreen_size_;
DISALLOW_COPY_AND_ASSIGN(EdgeTouchFilter);
};
......
......@@ -17,6 +17,7 @@
#include "ui/events/event_switches.h"
#include "ui/events/ozone/evdev/touch_evdev_types.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/size.h"
namespace ui {
......@@ -32,6 +33,8 @@ class FalseTouchFinderTest : public testing::Test {
bool expect_delay;
};
static constexpr gfx::Size kTouchscreenSize = gfx::Size(4000, 4000);
FalseTouchFinderTest() {}
~FalseTouchFinderTest() override {}
......@@ -79,8 +82,6 @@ class FalseTouchFinderTest : public testing::Test {
return true;
}
gfx::Size touchscreen_size = gfx::Size(4000,4000);
private:
// testing::Test:
void SetUp() override {
......@@ -90,7 +91,7 @@ class FalseTouchFinderTest : public testing::Test {
switches::kEdgeTouchFiltering);
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kLowPressureTouchFiltering);
false_touch_finder_ = FalseTouchFinder::Create(touchscreen_size);
false_touch_finder_ = FalseTouchFinder::Create(kTouchscreenSize);
}
std::unique_ptr<FalseTouchFinder> false_touch_finder_;
......@@ -98,6 +99,8 @@ class FalseTouchFinderTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(FalseTouchFinderTest);
};
constexpr gfx::Size FalseTouchFinderTest::kTouchscreenSize;
// Test that taps which are far apart in quick succession are considered noise.
TEST_F(FalseTouchFinderTest, FarApartTaps) {
const TouchEntry kTestData[] = {
......@@ -172,21 +175,25 @@ TEST_F(FalseTouchFinderTest, MultiSecondTouch) {
// Test that a touch on the edge which never leaves is delayed and never
// released.
TEST_F(FalseTouchFinderTest, EdgeTap) {
int ts_width = touchscreen_size.width();
int ts_height = touchscreen_size.height();
int touchscreen_width = kTouchscreenSize.width();
int touchscreen_height = kTouchscreenSize.height();
const TouchEntry kTestData[] = {
{10, 1, true, gfx::PointF(0, 100), 0.35, false, true},
{20, 1, true, gfx::PointF(0, 100), 0.35, false, true},
{30, 1, false, gfx::PointF(0, 100), 0.35, false, true},
{40, 2, true, gfx::PointF(ts_width - 1, 100), 0.35, false, true},
{50, 2, true, gfx::PointF(ts_width - 1, 100), 0.35, false, true},
{60, 2, false, gfx::PointF(ts_width - 1, 100), 0.35, false, true},
{40, 2, true, gfx::PointF(touchscreen_width - 1, 100), 0.35, false, true},
{50, 2, true, gfx::PointF(touchscreen_width - 1, 100), 0.35, false, true},
{60, 2, false, gfx::PointF(touchscreen_width - 1, 100), 0.35, false,
true},
{70, 3, true, gfx::PointF(100, 0), 0.35, false, true},
{80, 3, true, gfx::PointF(100, 0), 0.35, false, true},
{90, 3, false, gfx::PointF(100, 0), 0.35, false, true},
{100, 4, true, gfx::PointF(100, ts_height - 1), 0.35, false, true},
{110, 4, true, gfx::PointF(100, ts_height - 1), 0.35, false, true},
{120, 4, false, gfx::PointF(100, ts_height - 1), 0.35, false, true}};
{100, 4, true, gfx::PointF(100, touchscreen_height - 1), 0.35, false,
true},
{110, 4, true, gfx::PointF(100, touchscreen_height - 1), 0.35, false,
true},
{120, 4, false, gfx::PointF(100, touchscreen_height - 1), 0.35, false,
true}};
EXPECT_TRUE(FilterAndCheck(kTestData, base::size(kTestData)));
}
......
......@@ -60,17 +60,21 @@ HeuristicStylusPalmDetectionFilter::HeuristicStylusPalmDetectionFilter(
DCHECK(hold >= cancel) << "Expected hold time to be longer than cancel time.";
}
HeuristicStylusPalmDetectionFilter::~HeuristicStylusPalmDetectionFilter() {}
const char HeuristicStylusPalmDetectionFilter::kFilterName[] =
"HeuristicStylusPalmDetectionFilter";
std::string HeuristicStylusPalmDetectionFilter::FilterNameForTesting() const {
return kFilterName;
}
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
......@@ -12,6 +12,7 @@
#include "ui/events/ozone/evdev/touch_evdev_types.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 {
// A heuristic implementation of PalmDetectionFilter.
......@@ -40,12 +41,13 @@ class EVENTS_OZONE_EVDEV_EXPORT HeuristicStylusPalmDetectionFilter
base::TimeDelta hold,
base::TimeDelta cancel);
~HeuristicStylusPalmDetectionFilter() override;
void Filter(const std::vector<InProgressTouchEvdev>& touches,
base::TimeTicks time,
std::bitset<kNumTouchEvdevSlots>* slots_to_hold,
std::bitset<kNumTouchEvdevSlots>* slots_to_suppress) override;
const static char kFilterName[];
static const char kFilterName[];
std::string FilterNameForTesting() const override;
base::TimeDelta HoldTime() const;
......@@ -57,10 +59,13 @@ class EVENTS_OZONE_EVDEV_EXPORT HeuristicStylusPalmDetectionFilter
const base::TimeDelta time_after_stylus_to_cancel_;
std::vector<base::TimeTicks> touch_started_time_;
// How many items have we seen in this stroke so far?
std::vector<int> stroke_length_;
DISALLOW_COPY_AND_ASSIGN(HeuristicStylusPalmDetectionFilter);
};
} // namespace ui
#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_HEURISTIC_STYLUS_PALM_DETECTION_FILTER_H_
......@@ -12,6 +12,7 @@
#include "ui/events/ozone/evdev/touch_filter/shared_palm_detection_filter_state.h"
namespace ui {
class HeuristicStylusPalmDetectionFilterTest : public testing::Test {
public:
HeuristicStylusPalmDetectionFilterTest() = default;
......@@ -32,10 +33,12 @@ class HeuristicStylusPalmDetectionFilterTest : public testing::Test {
const base::TimeDelta sample_interval =
base::TimeDelta::FromMillisecondsD(7.5);
std::unique_ptr<SharedPalmDetectionFilterState> shared_palm_state;
std::unique_ptr<PalmDetectionFilter> palm_detection_filter_;
std::vector<InProgressTouchEvdev> touches_;
base::TimeTicks test_start_time_;
DISALLOW_COPY_AND_ASSIGN(HeuristicStylusPalmDetectionFilterTest);
};
......@@ -174,4 +177,5 @@ TEST_F(HeuristicStylusPalmDetectionFilterTest, TestHover) {
hold.reset(0);
EXPECT_TRUE(hold.none());
}
} // namespace ui
......@@ -5,55 +5,59 @@
#include "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.h"
namespace ui {
DistilledDevInfo::DistilledDevInfo(const EventDeviceInfo& devinfo) {
max_x = devinfo.GetAbsMaximum(ABS_MT_POSITION_X);
x_res = devinfo.GetAbsResolution(ABS_MT_POSITION_X);
max_y = devinfo.GetAbsMaximum(ABS_MT_POSITION_Y);
y_res = devinfo.GetAbsResolution(ABS_MT_POSITION_Y);
if (x_res == 0) {
x_res = 1;
PalmFilterDeviceInfo CreatePalmFilterDeviceInfo(
const EventDeviceInfo& devinfo) {
PalmFilterDeviceInfo info;
info.max_x = devinfo.GetAbsMaximum(ABS_MT_POSITION_X);
info.x_res = devinfo.GetAbsResolution(ABS_MT_POSITION_X);
info.max_y = devinfo.GetAbsMaximum(ABS_MT_POSITION_Y);
info.y_res = devinfo.GetAbsResolution(ABS_MT_POSITION_Y);
if (info.x_res == 0) {
info.x_res = 1;
}
if (y_res == 0) {
y_res = 1;
if (info.y_res == 0) {
info.y_res = 1;
}
major_radius_res = devinfo.GetAbsResolution(ABS_MT_TOUCH_MAJOR);
if (major_radius_res == 0) {
info.major_radius_res = devinfo.GetAbsResolution(ABS_MT_TOUCH_MAJOR);
if (info.major_radius_res == 0) {
// Device does not report major res: set to 1.
major_radius_res = 1;
info.major_radius_res = 1;
}
if (devinfo.HasAbsEvent(ABS_MT_TOUCH_MINOR)) {
minor_radius_supported = true;
minor_radius_res = devinfo.GetAbsResolution(ABS_MT_TOUCH_MINOR);
info.minor_radius_supported = true;
info.minor_radius_res = devinfo.GetAbsResolution(ABS_MT_TOUCH_MINOR);
} else {
minor_radius_supported = false;
minor_radius_res = major_radius_res;
info.minor_radius_supported = false;
info.minor_radius_res = info.major_radius_res;
}
if (minor_radius_res == 0) {
if (info.minor_radius_res == 0) {
// Device does not report minor res: set to 1.
minor_radius_res = 1;
info.minor_radius_res = 1;
}
}
const DistilledDevInfo DistilledDevInfo::Create(
const EventDeviceInfo& devinfo) {
return DistilledDevInfo(devinfo);
return info;
}
Sample::Sample(const InProgressTouchEvdev& touch,
const base::TimeTicks& time,
const DistilledDevInfo& dev_info)
: time(time) { // radius_x and radius_y have been
// scaled by resolution.already.
PalmFilterSample CreatePalmFilterSample(const InProgressTouchEvdev& touch,
const base::TimeTicks& time,
const PalmFilterDeviceInfo& dev_info) {
// radius_x and radius_y have been
// scaled by resolution already.
PalmFilterSample sample;
sample.time = time;
// Original model here is not normalized appropriately, so we divide by 40.
major_radius = std::max(touch.major, touch.minor) * dev_info.x_res / 40.0 *
dev_info.major_radius_res;
sample.major_radius = std::max(touch.major, touch.minor) * dev_info.x_res /
40.0 * dev_info.major_radius_res;
if (dev_info.minor_radius_supported) {
minor_radius = std::min(touch.major, touch.minor) * dev_info.x_res / 40.0 *
dev_info.minor_radius_res;
sample.minor_radius = std::min(touch.major, touch.minor) * dev_info.x_res /
40.0 * dev_info.minor_radius_res;
} else {
minor_radius = major_radius;
sample.minor_radius = sample.major_radius;
}
// Nearest edge distance, in cm.
......@@ -61,33 +65,38 @@ Sample::Sample(const InProgressTouchEvdev& touch,
float nearest_y_edge = std::min(touch.y, dev_info.max_y - touch.y);
float normalized_x_edge = nearest_x_edge / dev_info.x_res;
float normalized_y_edge = nearest_y_edge / dev_info.y_res;
edge = std::min(normalized_x_edge, normalized_y_edge);
point = gfx::PointF(touch.x / dev_info.x_res, touch.y / dev_info.y_res);
tracking_id = touch.tracking_id;
pressure = touch.pressure;
}
sample.edge = std::min(normalized_x_edge, normalized_y_edge);
sample.point =
gfx::PointF(touch.x / dev_info.x_res, touch.y / dev_info.y_res);
sample.tracking_id = touch.tracking_id;
sample.pressure = touch.pressure;
Sample::Sample(const Sample& other) = default;
Sample& Sample::operator=(const Sample& other) = default;
Stroke::Stroke(const Stroke& other) = default;
Stroke::Stroke(Stroke&& other) = default;
Stroke::Stroke(int max_length) : max_length_(max_length) {}
Stroke::~Stroke() {}
return sample;
}
void Stroke::AddSample(const Sample& samp) {
PalmFilterStroke::PalmFilterStroke(size_t max_length)
: max_length_(max_length) {}
PalmFilterStroke::PalmFilterStroke(const PalmFilterStroke& other) = default;
PalmFilterStroke::PalmFilterStroke(PalmFilterStroke&& other) = default;
PalmFilterStroke& PalmFilterStroke::operator=(const PalmFilterStroke& other) =
default;
PalmFilterStroke& PalmFilterStroke::operator=(PalmFilterStroke&& other) =
default;
PalmFilterStroke::~PalmFilterStroke() {}
void PalmFilterStroke::AddSample(const PalmFilterSample& sample) {
samples_seen_++;
if (samples_.empty()) {
tracking_id_ = samp.tracking_id;
tracking_id_ = sample.tracking_id;
}
DCHECK_EQ(tracking_id_, samp.tracking_id);
samples_.push_back(samp);
DCHECK_EQ(tracking_id_, sample.tracking_id);
samples_.push_back(sample);
while (samples_.size() > max_length_) {
samples_.pop_front();
}
}
gfx::PointF Stroke::GetCentroid() const {
gfx::PointF PalmFilterStroke::GetCentroid() const {
// TODO(robsc): Implement a Kahan sum to accurately track running sum instead
// of brute force.
if (samples_.size() == 0) {
......@@ -100,23 +109,23 @@ gfx::PointF Stroke::GetCentroid() const {
return gfx::ScalePoint(unscaled_centroid, 1.f / samples_.size());
}
const std::deque<Sample>& Stroke::samples() const {
const std::deque<PalmFilterSample>& PalmFilterStroke::samples() const {
return samples_;
}
int Stroke::tracking_id() const {
int PalmFilterStroke::tracking_id() const {
return tracking_id_;
}
uint64_t Stroke::samples_seen() const {
uint64_t PalmFilterStroke::samples_seen() const {
return samples_seen_;
}
void Stroke::SetTrackingId(int tracking_id) {
void PalmFilterStroke::SetTrackingId(int tracking_id) {
tracking_id_ = tracking_id;
}
float Stroke::MaxMajorRadius() const {
float PalmFilterStroke::MaxMajorRadius() const {
float maximum = 0.0;
for (const auto& sample : samples_) {
maximum = std::max(maximum, sample.major_radius);
......@@ -124,7 +133,7 @@ float Stroke::MaxMajorRadius() const {
return maximum;
}
float Stroke::BiggestSize() const {
float PalmFilterStroke::BiggestSize() const {
float biggest = 0;
for (const auto& sample : samples_) {
float size;
......
......@@ -4,6 +4,7 @@
#ifndef UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_NEURAL_STYLUS_PALM_DETECTION_FILTER_UTIL_H_
#define UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_NEURAL_STYLUS_PALM_DETECTION_FILTER_UTIL_H_
#include <cstdint>
#include <deque>
#include <vector>
......@@ -14,13 +15,8 @@
#include "ui/gfx/geometry/point_f.h"
namespace ui {
struct EVENTS_OZONE_EVDEV_EXPORT DistilledDevInfo {
private:
explicit DistilledDevInfo(const EventDeviceInfo& devinfo);
public:
static const DistilledDevInfo Create(const EventDeviceInfo& devinfo);
DistilledDevInfo() = delete;
struct EVENTS_OZONE_EVDEV_EXPORT PalmFilterDeviceInfo {
float max_x = 0.f;
float max_y = 0.f;
float x_res = 1.f;
......@@ -30,48 +26,51 @@ struct EVENTS_OZONE_EVDEV_EXPORT DistilledDevInfo {
bool minor_radius_supported = false;
};
// Data for a single touch event.
class EVENTS_OZONE_EVDEV_EXPORT Sample {
public:
Sample(const InProgressTouchEvdev& touch,
const base::TimeTicks& time,
const DistilledDevInfo& dev_info);
Sample(const Sample& other);
Sample() = delete;
Sample& operator=(const Sample& other);
EVENTS_OZONE_EVDEV_EXPORT
PalmFilterDeviceInfo CreatePalmFilterDeviceInfo(const EventDeviceInfo& devinfo);
// Data for a single touch event.
struct EVENTS_OZONE_EVDEV_EXPORT PalmFilterSample {
float major_radius = 0;
float minor_radius = 0;
float pressure = 0;
float edge = 0;
int tracking_id = 0;
gfx::PointF point;
base::TimeTicks time = base::TimeTicks::UnixEpoch();
base::TimeTicks time;
};
class EVENTS_OZONE_EVDEV_EXPORT Stroke {
EVENTS_OZONE_EVDEV_EXPORT
PalmFilterSample CreatePalmFilterSample(const InProgressTouchEvdev& touch,
const base::TimeTicks& time,
const PalmFilterDeviceInfo& dev_info);
class EVENTS_OZONE_EVDEV_EXPORT PalmFilterStroke {
public:
explicit Stroke(int max_length);
Stroke(const Stroke& other);
Stroke(Stroke&& other);
virtual ~Stroke();
explicit PalmFilterStroke(size_t max_length);
PalmFilterStroke(const PalmFilterStroke& other);
PalmFilterStroke(PalmFilterStroke&& other);
PalmFilterStroke& operator=(const PalmFilterStroke& other);
PalmFilterStroke& operator=(PalmFilterStroke&& other);
~PalmFilterStroke();
void AddSample(const Sample& sample);
void AddSample(const PalmFilterSample& sample);
gfx::PointF GetCentroid() const;
float BiggestSize() const;
// If no elements in stroke, returns 0.0;
float MaxMajorRadius() const;
void SetTrackingId(int tracking_id);
const std::deque<Sample>& samples() const;
const std::deque<PalmFilterSample>& samples() const;
uint64_t samples_seen() const;
int tracking_id() const;
private:
std::deque<Sample> samples_;
std::deque<PalmFilterSample> samples_;
int tracking_id_ = 0;
uint64_t samples_seen_ = 0;
uint64_t max_length_;
};
} // namespace ui
#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_NEURAL_STYLUS_PALM_DETECTION_FILTER_UTIL_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/neural_stylus_palm_detection_filter_util.h"
#include <algorithm>
......@@ -13,10 +14,13 @@
#include "ui/events/ozone/evdev/touch_evdev_types.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 NeuralStylusPalmDetectionFilterUtilTest : public testing::Test {
public:
NeuralStylusPalmDetectionFilterUtilTest() = default;
void SetUp() override {
EXPECT_TRUE(
CapabilitiesToDeviceInfo(kNocturneTouchScreen, &nocturne_touchscreen_));
......@@ -31,12 +35,13 @@ class NeuralStylusPalmDetectionFilterUtilTest : public testing::Test {
protected:
InProgressTouchEvdev touch_;
EventDeviceInfo nocturne_touchscreen_;
DISALLOW_COPY_AND_ASSIGN(NeuralStylusPalmDetectionFilterUtilTest);
};
TEST_F(NeuralStylusPalmDetectionFilterUtilTest, DistilledNocturneTest) {
const DistilledDevInfo nocturne_distilled =
DistilledDevInfo::Create(nocturne_touchscreen_);
const PalmFilterDeviceInfo nocturne_distilled =
CreatePalmFilterDeviceInfo(nocturne_touchscreen_);
EXPECT_FLOAT_EQ(nocturne_distilled.max_x,
nocturne_touchscreen_.GetAbsMaximum(ABS_MT_POSITION_X));
EXPECT_FLOAT_EQ(nocturne_distilled.max_y,
......@@ -58,8 +63,8 @@ TEST_F(NeuralStylusPalmDetectionFilterUtilTest, NoMinorResTest) {
auto abs_info = nocturne_touchscreen_.GetAbsInfoByCode(ABS_MT_TOUCH_MINOR);
abs_info.resolution = 0;
nocturne_touchscreen_.SetAbsInfo(ABS_MT_TOUCH_MINOR, abs_info);
const DistilledDevInfo nocturne_distilled =
DistilledDevInfo::Create(nocturne_touchscreen_);
const PalmFilterDeviceInfo nocturne_distilled =
CreatePalmFilterDeviceInfo(nocturne_touchscreen_);
EXPECT_EQ(1, nocturne_distilled.minor_radius_res);
EXPECT_EQ(1, nocturne_distilled.major_radius_res);
}
......@@ -68,8 +73,8 @@ TEST_F(NeuralStylusPalmDetectionFilterUtilTest, DistillerKohakuTest) {
EventDeviceInfo kohaku_touchscreen;
ASSERT_TRUE(
CapabilitiesToDeviceInfo(kKohakuTouchscreen, &kohaku_touchscreen));
const DistilledDevInfo kohaku_distilled =
DistilledDevInfo::Create(kohaku_touchscreen);
const PalmFilterDeviceInfo kohaku_distilled =
CreatePalmFilterDeviceInfo(kohaku_touchscreen);
EXPECT_FALSE(kohaku_distilled.minor_radius_supported);
EXPECT_EQ(1, kohaku_distilled.x_res);
EXPECT_EQ(1, kohaku_distilled.y_res);
......@@ -78,57 +83,57 @@ TEST_F(NeuralStylusPalmDetectionFilterUtilTest, DistillerKohakuTest) {
TEST_F(NeuralStylusPalmDetectionFilterUtilTest, DistilledLinkTest) {
EventDeviceInfo link_touchscreen;
ASSERT_TRUE(CapabilitiesToDeviceInfo(kLinkTouchscreen, &link_touchscreen));
const DistilledDevInfo link_distilled =
DistilledDevInfo::Create(link_touchscreen);
const PalmFilterDeviceInfo link_distilled =
CreatePalmFilterDeviceInfo(link_touchscreen);
EXPECT_FALSE(link_distilled.minor_radius_supported);
EXPECT_FLOAT_EQ(1.f, link_distilled.major_radius_res);
EXPECT_FLOAT_EQ(link_distilled.major_radius_res,
link_distilled.minor_radius_res);
}
TEST_F(NeuralStylusPalmDetectionFilterUtilTest, SampleTest) {
base::TimeTicks t =
base::TimeTicks::UnixEpoch() + base::TimeDelta::FromSeconds(30);
const DistilledDevInfo nocturne_distilled =
DistilledDevInfo::Create(nocturne_touchscreen_);
const Sample s(touch_, t, nocturne_distilled);
EXPECT_EQ(t, s.time);
EXPECT_EQ(25, s.major_radius);
EXPECT_EQ(24, s.minor_radius);
EXPECT_EQ(23, s.pressure);
EXPECT_EQ(22, s.tracking_id);
EXPECT_EQ(gfx::PointF(21 / 40.f, 20 / 40.f), s.point);
EXPECT_EQ(0.5, s.edge);
TEST_F(NeuralStylusPalmDetectionFilterUtilTest, PalmFilterSampleTest) {
base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(30);
const PalmFilterDeviceInfo nocturne_distilled =
CreatePalmFilterDeviceInfo(nocturne_touchscreen_);
const PalmFilterSample sample =
CreatePalmFilterSample(touch_, time, nocturne_distilled);
EXPECT_EQ(time, sample.time);
EXPECT_EQ(25, sample.major_radius);
EXPECT_EQ(24, sample.minor_radius);
EXPECT_EQ(23, sample.pressure);
EXPECT_EQ(22, sample.tracking_id);
EXPECT_EQ(gfx::PointF(21 / 40.f, 20 / 40.f), sample.point);
EXPECT_EQ(0.5, sample.edge);
}
TEST_F(NeuralStylusPalmDetectionFilterUtilTest, LinkTouchscreenSampleTest) {
EventDeviceInfo link_touchscreen;
base::TimeTicks t =
base::TimeTicks::UnixEpoch() + base::TimeDelta::FromSeconds(30);
base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(30);
ASSERT_TRUE(CapabilitiesToDeviceInfo(kLinkTouchscreen, &link_touchscreen));
const DistilledDevInfo link_distilled =
DistilledDevInfo::Create(link_touchscreen);
const PalmFilterDeviceInfo link_distilled =
CreatePalmFilterDeviceInfo(link_touchscreen);
touch_.minor = 0; // no minor from link.
const Sample s(touch_, t, link_distilled);
EXPECT_FLOAT_EQ(12.5, s.major_radius);
EXPECT_FLOAT_EQ(12.5, s.minor_radius);
const PalmFilterSample sample =
CreatePalmFilterSample(touch_, time, link_distilled);
EXPECT_FLOAT_EQ(12.5, sample.major_radius);
EXPECT_FLOAT_EQ(12.5, sample.minor_radius);
}
TEST_F(NeuralStylusPalmDetectionFilterUtilTest, StrokeTest) {
Stroke stroke(3); // maxsize: 3.
TEST_F(NeuralStylusPalmDetectionFilterUtilTest, PalmFilterStrokeTest) {
PalmFilterStroke stroke(3); // maxsize: 3.
EXPECT_EQ(0, stroke.tracking_id());
// With no points, center is 0.
EXPECT_EQ(gfx::PointF(0., 0.), stroke.GetCentroid());
base::TimeTicks t =
base::TimeTicks::UnixEpoch() + base::TimeDelta::FromSeconds(30);
const DistilledDevInfo nocturne_distilled =
DistilledDevInfo::Create(nocturne_touchscreen_);
base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(30);
const PalmFilterDeviceInfo nocturne_distilled =
CreatePalmFilterDeviceInfo(nocturne_touchscreen_);
// Deliberately long test to ensure floating point continued accuracy.
for (int i = 0; i < 500000; ++i) {
touch_.x = 15 + i;
Sample s(touch_, t, nocturne_distilled);
stroke.AddSample(std::move(s));
PalmFilterSample sample =
CreatePalmFilterSample(touch_, time, nocturne_distilled);
stroke.AddSample(std::move(sample));
EXPECT_EQ(touch_.tracking_id, stroke.tracking_id());
if (i < 3) {
if (i == 0) {
......@@ -152,44 +157,48 @@ TEST_F(NeuralStylusPalmDetectionFilterUtilTest, StrokeTest) {
EXPECT_EQ(55, stroke.tracking_id());
}
TEST_F(NeuralStylusPalmDetectionFilterUtilTest, StrokeBiggestSizeTest) {
Stroke stroke(3), no_minor_stroke(3); // maxsize: 3.
TEST_F(NeuralStylusPalmDetectionFilterUtilTest,
PalmFilterStrokeBiggestSizeTest) {
PalmFilterStroke stroke(3);
PalmFilterStroke no_minor_stroke(3); // maxsize: 3.
EXPECT_EQ(0, stroke.BiggestSize());
base::TimeTicks t =
base::TimeTicks::UnixEpoch() + base::TimeDelta::FromSeconds(30);
const DistilledDevInfo nocturne_distilled =
DistilledDevInfo::Create(nocturne_touchscreen_);
base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(30);
const PalmFilterDeviceInfo nocturne_distilled =
CreatePalmFilterDeviceInfo(nocturne_touchscreen_);
for (int i = 0; i < 500; ++i) {
touch_.major = 2 + i;
touch_.minor = 1 + i;
Sample s(touch_, t, nocturne_distilled);
PalmFilterSample sample =
CreatePalmFilterSample(touch_, time, nocturne_distilled);
EXPECT_EQ(static_cast<uint64_t>(i), stroke.samples_seen());
stroke.AddSample(std::move(s));
stroke.AddSample(sample);
EXPECT_FLOAT_EQ((1 + i) * (2 + i), stroke.BiggestSize());
Sample second_s(touch_, t, nocturne_distilled);
second_s.minor_radius = 0;
no_minor_stroke.AddSample(std::move(second_s));
PalmFilterSample second_sample =
CreatePalmFilterSample(touch_, time, nocturne_distilled);
second_sample.minor_radius = 0;
no_minor_stroke.AddSample(std::move(second_sample));
EXPECT_FLOAT_EQ((2 + i) * (2 + i), no_minor_stroke.BiggestSize());
EXPECT_EQ(std::min(3ul, 1ul + i), stroke.samples().size());
}
}
TEST_F(NeuralStylusPalmDetectionFilterUtilTest, StrokeGetMaxMajorTest) {
Stroke stroke(3);
PalmFilterStroke stroke(3);
EXPECT_FLOAT_EQ(0, stroke.MaxMajorRadius());
base::TimeTicks t =
base::TimeTicks time =
base::TimeTicks::UnixEpoch() + base::TimeDelta::FromSeconds(30);
const DistilledDevInfo nocturne_distilled =
DistilledDevInfo::Create(nocturne_touchscreen_);
const PalmFilterDeviceInfo nocturne_distilled =
CreatePalmFilterDeviceInfo(nocturne_touchscreen_);
for (int i = 1; i < 50; ++i) {
touch_.major = i;
touch_.minor = i - 1;
Sample s(touch_, t, nocturne_distilled);
t += base::TimeDelta::FromMilliseconds(8);
PalmFilterSample sample =
CreatePalmFilterSample(touch_, time, nocturne_distilled);
time += base::TimeDelta::FromMilliseconds(8);
EXPECT_EQ(static_cast<uint64_t>(i - 1), stroke.samples_seen());
stroke.AddSample(s);
stroke.AddSample(sample);
EXPECT_FLOAT_EQ(i, stroke.MaxMajorRadius());
}
}
......
......@@ -5,10 +5,13 @@
#include "ui/events/ozone/evdev/touch_filter/open_palm_detection_filter.h"
namespace ui {
OpenPalmDetectionFilter::OpenPalmDetectionFilter(
SharedPalmDetectionFilterState* shared_palm_state)
: PalmDetectionFilter(shared_palm_state) {}
OpenPalmDetectionFilter::~OpenPalmDetectionFilter() {}
void OpenPalmDetectionFilter::Filter(
const std::vector<InProgressTouchEvdev>& touches,
base::TimeTicks time,
......@@ -19,9 +22,9 @@ void OpenPalmDetectionFilter::Filter(
}
const char OpenPalmDetectionFilter::kFilterName[] = "OpenPalmDetectionFilter";
std::string OpenPalmDetectionFilter::FilterNameForTesting() const {
return kFilterName;
}
OpenPalmDetectionFilter::~OpenPalmDetectionFilter() {}
} // namespace ui
......@@ -12,6 +12,7 @@
#include "ui/events/ozone/evdev/touch_evdev_types.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 {
// A simple implementation of PalmDetectionFilter.
......@@ -22,17 +23,19 @@ class EVENTS_OZONE_EVDEV_EXPORT OpenPalmDetectionFilter
explicit OpenPalmDetectionFilter(
SharedPalmDetectionFilterState* shared_palm_state);
~OpenPalmDetectionFilter() override;
void Filter(const std::vector<InProgressTouchEvdev>& touches,
base::TimeTicks time,
std::bitset<kNumTouchEvdevSlots>* slots_to_hold,
std::bitset<kNumTouchEvdevSlots>* slots_to_suppress) override;
const static char kFilterName[];
static const char kFilterName[];
std::string FilterNameForTesting() const override;
private:
DISALLOW_COPY_AND_ASSIGN(OpenPalmDetectionFilter);
};
} // namespace ui
#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_OPEN_PALM_DETECTION_FILTER_H_
......@@ -7,10 +7,13 @@
#include "testing/gtest/include/gtest/gtest.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 OpenPalmDetectionFilterTest : public testing::Test {
public:
OpenPalmDetectionFilterTest() = default;
void SetUp() override {
shared_palm_state = std::make_unique<SharedPalmDetectionFilterState>();
palm_detection_filter_.reset(
......@@ -19,8 +22,8 @@ class OpenPalmDetectionFilterTest : public testing::Test {
protected:
std::unique_ptr<SharedPalmDetectionFilterState> shared_palm_state;
std::unique_ptr<PalmDetectionFilter> palm_detection_filter_;
DISALLOW_COPY_AND_ASSIGN(OpenPalmDetectionFilterTest);
};
......@@ -35,4 +38,5 @@ TEST_F(OpenPalmDetectionFilterTest, TestSetsToZero) {
EXPECT_TRUE(hold.none());
EXPECT_TRUE(suppress.none());
}
} // namespace ui
......@@ -5,10 +5,13 @@
#include "ui/events/ozone/evdev/touch_filter/palm_detection_filter.h"
namespace ui {
PalmDetectionFilter::PalmDetectionFilter(
SharedPalmDetectionFilterState* shared_palm_state)
: shared_palm_state_(shared_palm_state) {
DCHECK(shared_palm_state != nullptr);
}
PalmDetectionFilter::~PalmDetectionFilter() {}
} // namespace ui
......@@ -24,6 +24,7 @@ class EVENTS_OZONE_EVDEV_EXPORT PalmDetectionFilter {
// shared_palm_state is not owned!
explicit PalmDetectionFilter(
SharedPalmDetectionFilterState* shared_palm_state);
virtual ~PalmDetectionFilter();
// Execute a filter event. Expected to be executed on every update to touches.
// Arguments are:
......@@ -43,12 +44,11 @@ class EVENTS_OZONE_EVDEV_EXPORT PalmDetectionFilter {
// The name of this filter, for testing purposes.
virtual std::string FilterNameForTesting() const = 0;
virtual ~PalmDetectionFilter();
protected:
// Not owned!
SharedPalmDetectionFilterState* shared_palm_state_;
SharedPalmDetectionFilterState* const shared_palm_state_;
};
} // namespace ui
#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_PALM_DETECTION_FILTER_H_
......@@ -14,6 +14,7 @@
#include "ui/events/ozone/evdev/touch_filter/palm_detection_filter.h"
namespace ui {
const base::Feature kEnableHeuristicPalmDetectionFilter{
"EnableHeuristicPalmDetectionFilter", base::FEATURE_DISABLED_BY_DEFAULT};
......
// 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_
......@@ -10,27 +11,29 @@
#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;
EVENTS_OZONE_EVDEV_EXPORT
extern const base::Feature kEnableHeuristicPalmDetectionFilter;
EVENTS_OZONE_EVDEV_EXPORT
extern const base::FeatureParam<double> kHeuristicCancelThresholdSeconds;
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
EVENTS_OZONE_EVDEV_EXPORT
extern const base::FeatureParam<double> kHeuristicHoldThresholdSeconds;
EVENTS_OZONE_EVDEV_EXPORT
extern const base::FeatureParam<int> kHeuristicStrokeCount;
EVENTS_OZONE_EVDEV_EXPORT std::unique_ptr<PalmDetectionFilter>
CreatePalmDetectionFilter(const EventDeviceInfo& devinfo,
SharedPalmDetectionFilterState* shared_palm_state);
} // namespace ui
#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_PALM_DETECTION_FILTER_FACTORY_H_
......@@ -10,14 +10,17 @@
#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/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 {
class PalmDetectionFilterFactoryTest : public testing::Test {
public:
PalmDetectionFilterFactoryTest() = default;
void SetUp() override {
EXPECT_TRUE(
CapabilitiesToDeviceInfo(kEveTouchScreen, &eve_touchscreen_info_));
......@@ -34,6 +37,7 @@ class PalmDetectionFilterFactoryTest : public testing::Test {
EventDeviceInfo eve_touchscreen_info_, eve_stylus_info_,
nocturne_touchscreen_info_, nocturne_stylus_info_;
SharedPalmDetectionFilterState shared_palm_state_;
DISALLOW_COPY_AND_ASSIGN(PalmDetectionFilterFactoryTest);
};
......
......@@ -4,13 +4,16 @@
#ifndef UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_SHARED_PALM_DETECTION_FILTER_STATE_H_
#define UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_SHARED_PALM_DETECTION_FILTER_STATE_H_
#include "base/time/time.h"
namespace ui {
struct SharedPalmDetectionFilterState {
// The latest stylus touch time. Note that this can include "hover".
base::TimeTicks latest_stylus_touch_time_ = base::TimeTicks::UnixEpoch();
base::TimeTicks latest_stylus_touch_time_;
};
} // namespace ui
#endif
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