summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiarhei Vishniakou <svv@google.com>2022-06-17 10:54:08 -0700
committerSiarhei Vishniakou <svv@google.com>2022-07-18 20:13:13 +0000
commite197334646f68ac0fd9569135482e27466ace146 (patch)
treed4fb99efb96bfae0125b0fd8c71c651fed27a04e
parent6ad0003b776077840361843f8cc5f682e97d58d6 (diff)
downloadlibpalmrejection-e197334646f68ac0fd9569135482e27466ace146.tar.gz
Address upstream feedback on resampling
Changes here are for addressing code review feedback from upstream. To do: 1) go back to upsteam and switch to base::Optional instead of absl 2) try to add resampling constant to the header file somewhere Reviewed on: https://chromium-review.googlesource.com/c/chromium/src/+/3673342 and https://chromium-review.googlesource.com/c/chromium/src/+/3689765 Bug: 233488803 Test: build only Change-Id: I87e9e057217b98ca51c47625bb0ceceedb64acea
-rw-r--r--ui/events/ozone/evdev/touch_evdev_types.cc14
-rw-r--r--ui/events/ozone/evdev/touch_evdev_types.h18
-rw-r--r--ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.cc13
-rw-r--r--ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.h7
-rw-r--r--ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_model.h18
-rw-r--r--ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.cc34
-rw-r--r--ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.h16
-rw-r--r--ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util_unittest.cc98
-rw-r--r--ui/events/ozone/evdev/touch_filter/palm_model/onedevice_train_palm_detection_filter_model.cc4
-rw-r--r--ui/events/ozone/evdev/touch_filter/palm_model/onedevice_train_palm_detection_filter_model.h3
10 files changed, 138 insertions, 87 deletions
diff --git a/ui/events/ozone/evdev/touch_evdev_types.cc b/ui/events/ozone/evdev/touch_evdev_types.cc
index 4b20d99..39e598b 100644
--- a/ui/events/ozone/evdev/touch_evdev_types.cc
+++ b/ui/events/ozone/evdev/touch_evdev_types.cc
@@ -6,12 +6,18 @@
namespace ui {
-InProgressTouchEvdev::InProgressTouchEvdev() {
-}
+InProgressTouchEvdev::InProgressTouchEvdev() = default;
InProgressTouchEvdev::InProgressTouchEvdev(const InProgressTouchEvdev& other) =
default;
-InProgressTouchEvdev::~InProgressTouchEvdev() {}
+InProgressTouchEvdev::~InProgressTouchEvdev() = default;
-} // namespace ui \ No newline at end of file
+InProgressStylusState::InProgressStylusState() = default;
+
+InProgressStylusState::InProgressStylusState(
+ const InProgressStylusState& other) = default;
+
+InProgressStylusState::~InProgressStylusState() = default;
+
+} // namespace ui
diff --git a/ui/events/ozone/evdev/touch_evdev_types.h b/ui/events/ozone/evdev/touch_evdev_types.h
index 9ad9a29..fee670a 100644
--- a/ui/events/ozone/evdev/touch_evdev_types.h
+++ b/ui/events/ozone/evdev/touch_evdev_types.h
@@ -11,6 +11,7 @@
#include <stddef.h>
#include "base/component_export.h"
+#include "base/time/time.h"
#include "ui/events/event_constants.h"
namespace ui {
@@ -77,6 +78,21 @@ struct COMPONENT_EXPORT(EVDEV) InProgressTouchEvdev {
bool stylus_button = false;
};
+// Contains information about stylus event, the useful relate ddevice info and
+// the timestamp.
+struct COMPONENT_EXPORT(EVDEV) InProgressStylusState {
+ InProgressStylusState();
+ InProgressStylusState(const InProgressStylusState& other);
+ ~InProgressStylusState();
+
+ InProgressTouchEvdev stylus_event;
+ // Stylus x and y resolution, used for normalization.
+ int x_res = 1;
+ int y_res = 1;
+
+ base::TimeTicks timestamp = base::TimeTicks();
+};
+
} // namespace ui
-#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_EVDEV_TYPES_H_ \ No newline at end of file
+#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_EVDEV_TYPES_H_
diff --git a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.cc b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.cc
index d799fd9..e04c97c 100644
--- a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.cc
+++ b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.cc
@@ -161,8 +161,7 @@ void NeuralStylusPalmDetectionFilter::Filter(
DCHECK(strokes_.count(tracking_id) == 0)
<< " Tracking id " << tracking_id;
- strokes_.emplace(
- std::make_pair(tracking_id, PalmFilterStroke(model_->config())));
+ strokes_.emplace(tracking_id, PalmFilterStroke(model_->config()));
strokes_.find(tracking_id)->second.SetTrackingId(tracking_id);
tracking_ids_[slot] = tracking_id;
is_palm_.set(slot, false);
@@ -228,7 +227,7 @@ void NeuralStylusPalmDetectionFilter::Filter(
config.early_stage_sample_counts.find(stroke.samples_seen()) !=
config.early_stage_sample_counts.end()) {
VLOG(1) << "About to run a early_stage prediction.";
- if (DetectSpuriousStroke(ExtractFeatures(tracking_id), tracking_id,
+ if (DetectSpuriousStroke(ExtractFeatures(tracking_id),
model_->config().output_threshold)) {
VLOG(1) << "hold detected.";
is_delay_.set(slot, true);
@@ -251,9 +250,8 @@ void NeuralStylusPalmDetectionFilter::Filter(
is_palm_.set(slot, IsHeuristicPalmStroke(stroke));
continue;
}
- is_palm_.set(slot,
- DetectSpuriousStroke(ExtractFeatures(tracking_id), tracking_id,
- model_->config().output_threshold));
+ is_palm_.set(slot, DetectSpuriousStroke(ExtractFeatures(tracking_id),
+ model_->config().output_threshold));
if (is_palm_.test(slot)) {
shared_palm_state_->latest_palm_touch_time = time;
}
@@ -320,7 +318,6 @@ bool NeuralStylusPalmDetectionFilter::IsHeuristicPalmStroke(
bool NeuralStylusPalmDetectionFilter::DetectSpuriousStroke(
const std::vector<float>& features,
- int tracking_id,
float threshold) const {
auto inference_value = model_->Inference(features);
if (VLOG_IS_ON(1)) {
@@ -534,4 +531,4 @@ void NeuralStylusPalmDetectionFilter::EraseOldStrokes(base::TimeTicks time) {
}
previous_report_time_ = time;
}
-} // namespace ui \ No newline at end of file
+} // namespace ui
diff --git a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.h b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.h
index 027daea..fa8b2fa 100644
--- a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.h
+++ b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.h
@@ -27,6 +27,10 @@
namespace ui {
+#if defined(__ANDROID__) || defined(__ANDROID_HOST__)
+const base::TimeDelta kResamplePeriod = base::Milliseconds(8);
+#endif
+
// An implementation of PalmDetectionFilter that relies on a DNN implementation
// to decide on palm detection. Requires a configured model as an argument.
// Heuristics are added for handling short strokes
@@ -82,7 +86,6 @@ class COMPONENT_EXPORT(EVDEV) NeuralStylusPalmDetectionFilter
std::vector<std::pair<float, int>>* biggest_strokes) const;
bool DetectSpuriousStroke(const std::vector<float>& features,
- int tracking_id,
float threshold) const;
// Extracts the feature vector for the specified stroke.
std::vector<float> ExtractFeatures(int tracking_id) const;
@@ -109,4 +112,4 @@ class COMPONENT_EXPORT(EVDEV) NeuralStylusPalmDetectionFilter
} // namespace ui
-#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_NEURAL_STYLUS_PALM_DETECTION_FILTER_H_ \ No newline at end of file
+#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_NEURAL_STYLUS_PALM_DETECTION_FILTER_H_
diff --git a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_model.h b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_model.h
index f40c36d..c2f4863 100644
--- a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_model.h
+++ b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_model.h
@@ -14,6 +14,7 @@
#include <vector>
#include "base/component_export.h"
+#include "base/optional.h"
#include "base/time/time.h"
namespace ui {
@@ -95,16 +96,11 @@ struct COMPONENT_EXPORT(EVDEV) NeuralStylusPalmDetectionFilterModelConfig {
// check if it's spurious and mark it held if so.
std::unordered_set<uint32_t> early_stage_sample_counts;
- // True if the touch data should be resampled. Enable this if your device
- // has a non-120 Hz touchscreen. Since the model is hardcoded to assume 8 ms
- // between samples, non-120Hz touchscreens will not work correctly without
- // resampling.
- bool resample_touch = false;
-
- // Time between resampled values. This must match the period hardcoded
- // into the model, so it's made const. It can only be updated at compile
- // time, together with the model.
- const base::TimeDelta resample_period = base::Milliseconds(8.0);
+ // If set, time between values to resample. Must match the value coded into
+ // model. Currently the model is developed for 120Hz touch devices, so this
+ // value must be set to "8 ms" if your device has a different refresh rate.
+ // If not set, no resampling is done.
+ base::Optional<base::TimeDelta> resample_period;
};
// An abstract model utilized by NueralStylusPalmDetectionFilter.
@@ -123,4 +119,4 @@ class COMPONENT_EXPORT(EVDEV) NeuralStylusPalmDetectionFilterModel {
} // namespace ui
-#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_NEURAL_STYLUS_PALM_DETECTION_FILTER_MODEL_H_ \ No newline at end of file
+#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_NEURAL_STYLUS_PALM_DETECTION_FILTER_MODEL_H_
diff --git a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.cc b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.cc
index b369ece..2874d50 100644
--- a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.cc
+++ b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.cc
@@ -65,13 +65,28 @@ float interpolate(float start_value, float end_value, float proportion) {
return start_value + (end_value - start_value) * proportion;
}
+/**
+ * During resampling, the later events are used as a basis to populate
+ * non-resampled fields like major and minor. However, if the requested time is
+ * within this delay of the earlier event, the earlier event will be used as a
+ * basis instead.
+ */
+const static auto kPreferInitialEventDelay =
+ base::TimeDelta::FromMicroseconds(1);
+
+/**
+ * Interpolate between the "before" and "after" events to get a resampled value
+ * at the timestamp 'time'. Not all fields are interpolated. For fields that are
+ * not interpolated, the values are taken from the 'after' sample unless the
+ * requested time is very close to the 'before' sample.
+ */
PalmFilterSample getSampleAtTime(base::TimeTicks time,
const PalmFilterSample& before,
const PalmFilterSample& after) {
// Use the newest sample as the base, except when the requested time is very
// close to the 'before' sample.
PalmFilterSample result = after;
- if (time - before.time < base::TimeDelta::FromMicroseconds(1)) {
+ if (time - before.time < kPreferInitialEventDelay) {
result = before;
}
// Only the x and y values are interpolated. We could also interpolate the
@@ -128,23 +143,25 @@ PalmFilterSample CreatePalmFilterSample(
PalmFilterStroke::PalmFilterStroke(
const NeuralStylusPalmDetectionFilterModelConfig& model_config)
- : model_config_(model_config) {}
+ : max_sample_count_(model_config.max_sample_count),
+ resample_period_(model_config.resample_period) {}
PalmFilterStroke::PalmFilterStroke(const PalmFilterStroke& other) = default;
PalmFilterStroke::PalmFilterStroke(PalmFilterStroke&& other) = default;
+PalmFilterStroke::~PalmFilterStroke() {}
void PalmFilterStroke::ProcessSample(const PalmFilterSample& sample) {
if (samples_seen_ == 0) {
tracking_id_ = sample.tracking_id;
}
DCHECK_EQ(tracking_id_, sample.tracking_id);
- if (model_config_.resample_touch) {
+ if (resample_period_.has_value()) {
Resample(sample);
return;
}
AddSample(sample);
- while (samples_.size() > model_config_.max_sample_count) {
+ while (samples_.size() > max_sample_count_) {
AddToUnscaledCentroid(-samples_.front().point.OffsetFromOrigin());
samples_.pop_front();
}
@@ -171,17 +188,16 @@ void PalmFilterStroke::Resample(const PalmFilterSample& sample) {
// We already have a valid last sample here.
DCHECK_LE(last_sample_.time, sample.time);
// Generate resampled values
- base::TimeTicks next_sample_time =
- samples_.back().time + model_config_.resample_period;
+ base::TimeTicks next_sample_time = samples_.back().time + *resample_period_;
while (next_sample_time <= sample.time) {
AddSample(getSampleAtTime(next_sample_time, last_sample_, sample));
- next_sample_time = samples_.back().time + model_config_.resample_period;
+ next_sample_time = samples_.back().time + (*resample_period_);
}
last_sample_ = sample;
// Prune the resampled collection
while ((samples_.back().time - samples_.front().time) >=
- model_config_.resample_period * model_config_.max_sample_count) {
+ (*resample_period_) * max_sample_count_) {
AddToUnscaledCentroid(-samples_.front().point.OffsetFromOrigin());
samples_.pop_front();
}
@@ -241,4 +257,4 @@ float PalmFilterStroke::BiggestSize() const {
return biggest;
}
-} // namespace ui \ No newline at end of file
+} // namespace ui
diff --git a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.h b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.h
index 0052364..e5e9419 100644
--- a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.h
+++ b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.h
@@ -12,6 +12,7 @@
#if defined(__ANDROID__) || defined(__ANDROID_HOST__)
#undef LOG_INFO
#undef LOG_WARNING
+#include <chrome_to_android_compatibility_test_support.h>
#endif
#include "base/time/time.h"
#if !defined(__ANDROID__) && !defined(__ANDROID_HOST__)
@@ -50,6 +51,13 @@ struct COMPONENT_EXPORT(EVDEV) PalmFilterSample {
int tracking_id = 0;
gfx::PointF point;
base::TimeTicks time;
+
+ bool operator==(const PalmFilterSample& other) const {
+ return major_radius == other.major_radius &&
+ minor_radius == other.minor_radius && pressure == other.pressure &&
+ edge == other.edge && tracking_id == other.tracking_id &&
+ point == other.point && time == other.time;
+ }
};
COMPONENT_EXPORT(EVDEV)
@@ -65,6 +73,7 @@ class COMPONENT_EXPORT(EVDEV) PalmFilterStroke {
const NeuralStylusPalmDetectionFilterModelConfig& model_config);
PalmFilterStroke(const PalmFilterStroke& other);
PalmFilterStroke(PalmFilterStroke&& other);
+ ~PalmFilterStroke();
void ProcessSample(const PalmFilterSample& sample);
gfx::PointF GetCentroid() const;
@@ -100,7 +109,10 @@ class COMPONENT_EXPORT(EVDEV) PalmFilterStroke {
* to compute the resampled value.
*/
PalmFilterSample last_sample_;
- const NeuralStylusPalmDetectionFilterModelConfig& model_config_;
+
+ const uint64_t max_sample_count_;
+ const base::Optional<base::TimeDelta> resample_period_;
+
gfx::PointF unscaled_centroid_ = gfx::PointF(0., 0.);
// Used in part of the kahan summation.
gfx::Vector2dF unscaled_centroid_sum_error_ =
@@ -109,4 +121,4 @@ class COMPONENT_EXPORT(EVDEV) PalmFilterStroke {
} // namespace ui
-#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_NEURAL_STYLUS_PALM_DETECTION_FILTER_UTIL_H_ \ No newline at end of file
+#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_NEURAL_STYLUS_PALM_DETECTION_FILTER_UTIL_H_
diff --git a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util_unittest.cc b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util_unittest.cc
index 18b4d15..41364ae 100644
--- a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util_unittest.cc
+++ b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util_unittest.cc
@@ -9,6 +9,7 @@
#include <utility>
#include <vector>
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(__ANDROID__) || defined(__ANDROID_HOST__)
#include <linux/input-event-codes.h>
@@ -20,6 +21,9 @@
#include "ui/events/ozone/evdev/touch_filter/palm_detection_filter.h"
#include "ui/events/ozone/evdev/touch_filter/shared_palm_detection_filter_state.h"
+using ::testing::ElementsAre;
+using ::testing::IsEmpty;
+
namespace ui {
#if defined(__ANDROID__) || defined(__ANDROID_HOST__)
@@ -83,6 +87,11 @@ bool CapabilitiesToDeviceInfo(DeviceType, EventDeviceInfo*) {
}
#endif
+MATCHER_P(SampleTime, time, "Does the sample have given time.") {
+ *result_listener << "Sample time" << arg.time << " is not " << time;
+ return time == arg.time;
+}
+
class NeuralStylusPalmDetectionFilterUtilTest
: public testing::TestWithParam<bool> {
public:
@@ -103,7 +112,10 @@ class NeuralStylusPalmDetectionFilterUtilTest
touch_.x = 21;
touch_.y = 20;
model_config_.max_sample_count = 3;
- model_config_.resample_touch = GetParam();
+ const bool resample_touch = GetParam();
+ if (resample_touch) {
+ model_config_.resample_period = base::Milliseconds(8);
+ }
}
protected:
@@ -140,8 +152,8 @@ TEST_P(NeuralStylusPalmDetectionFilterUtilTest, DistilledNocturneTest) {
}
TEST_P(NeuralStylusPalmDetectionFilterUtilTest, NoMinorResTest) {
- // Nocturne has minor resolution: but lets pretend it didnt. we should recover
- // "1" as the resolution.
+ // Nocturne has minor resolution, but let's pretend it doesn't. we should
+ // recover "1" as the resolution.
auto abs_info = nocturne_touchscreen_.GetAbsInfoByCode(ABS_MT_TOUCH_MINOR);
abs_info.resolution = 0;
nocturne_touchscreen_.SetAbsInfo(ABS_MT_TOUCH_MINOR, abs_info);
@@ -239,7 +251,7 @@ TEST_P(NeuralStylusPalmDetectionFilterUtilTest, PalmFilterStrokeTest) {
touch_.x = 15 + i;
PalmFilterSample sample =
CreatePalmFilterSample(touch_, time, model_config_, nocturne_distilled);
- time += model_config_.resample_period;
+ time += base::Milliseconds(8);
stroke.ProcessSample(std::move(sample));
EXPECT_EQ(touch_.tracking_id, stroke.tracking_id());
if (i < 3) {
@@ -292,7 +304,7 @@ TEST_P(NeuralStylusPalmDetectionFilterUtilTest,
no_minor_stroke.ProcessSample(std::move(second_sample));
EXPECT_FLOAT_EQ((2 + i) * (2 + i), no_minor_stroke.BiggestSize());
ASSERT_EQ(std::min(3ul, 1ul + i), stroke.samples().size());
- time += model_config_.resample_period;
+ time += base::Milliseconds(8);
}
}
@@ -362,14 +374,14 @@ TEST_P(NeuralStylusPalmDetectionFilterUtilTest, SampleRadiusConversion) {
TEST(PalmFilterStrokeTest, NumberOfResampledValues) {
NeuralStylusPalmDetectionFilterModelConfig model_config_;
model_config_.max_sample_count = 3;
- model_config_.resample_touch = true;
+ model_config_.resample_period = base::Milliseconds(8);
base::TimeTicks down_time = base::TimeTicks::UnixEpoch() + base::Seconds(30);
PalmFilterStroke stroke(model_config_);
const PalmFilterDeviceInfo device_info;
// Initially, no samples
- ASSERT_EQ(0u, stroke.samples().size());
+ ASSERT_THAT(stroke.samples(), IsEmpty());
ASSERT_EQ(0u, stroke.samples_seen());
// Add first sample at time = T
@@ -377,33 +389,32 @@ TEST(PalmFilterStrokeTest, NumberOfResampledValues) {
PalmFilterSample sample =
CreatePalmFilterSample(touch_, down_time, model_config_, device_info);
stroke.ProcessSample(sample);
- ASSERT_EQ(1u, stroke.samples().size());
+ ASSERT_THAT(stroke.samples(), ElementsAre(SampleTime(down_time)));
ASSERT_EQ(1u, stroke.samples_seen());
- ASSERT_EQ(down_time, stroke.samples().back().time);
// Add second sample at time = T + 2ms. It's not yet time for the new frame,
// so no new sample should be generated.
base::TimeTicks time = down_time + base::Milliseconds(4);
sample = CreatePalmFilterSample(touch_, time, model_config_, device_info);
stroke.ProcessSample(sample);
- ASSERT_EQ(1u, stroke.samples().size());
+ ASSERT_THAT(stroke.samples(), ElementsAre(SampleTime(down_time)));
ASSERT_EQ(1u, stroke.samples_seen());
- ASSERT_EQ(down_time, stroke.samples().back().time);
// Add third sample at time = T + 10ms. An event at time = T + 8ms should be
// generated.
time = down_time + base::Milliseconds(10);
sample = CreatePalmFilterSample(touch_, time, model_config_, device_info);
stroke.ProcessSample(sample);
- ASSERT_EQ(2u, stroke.samples().size());
+ ASSERT_THAT(stroke.samples(),
+ ElementsAre(SampleTime(down_time),
+ SampleTime(down_time + base::Milliseconds(8))));
ASSERT_EQ(2u, stroke.samples_seen());
- ASSERT_EQ(down_time + base::Milliseconds(8), stroke.samples().back().time);
}
TEST(PalmFilterStrokeTest, ResamplingTest) {
NeuralStylusPalmDetectionFilterModelConfig model_config_;
model_config_.max_sample_count = 3;
- model_config_.resample_touch = true;
+ model_config_.resample_period = base::Milliseconds(8);
PalmFilterStroke stroke(model_config_);
PalmFilterDeviceInfo device_info;
@@ -416,16 +427,11 @@ TEST(PalmFilterStrokeTest, ResamplingTest) {
touch_.major = 4;
touch_.minor = 3;
base::TimeTicks down_time = base::TimeTicks::UnixEpoch() + base::Seconds(30);
- PalmFilterSample sample =
+ PalmFilterSample sample1 =
CreatePalmFilterSample(touch_, down_time, model_config_, device_info);
- stroke.ProcessSample(sample);
+ stroke.ProcessSample(sample1);
// First sample should not be modified
- ASSERT_EQ(1u, stroke.samples().size());
- EXPECT_EQ(1, stroke.samples().back().point.x());
- EXPECT_EQ(2, stroke.samples().back().point.y());
- EXPECT_EQ(4, stroke.samples().back().major_radius);
- EXPECT_EQ(3, stroke.samples().back().minor_radius);
- EXPECT_EQ(down_time, stroke.samples().back().time);
+ ASSERT_THAT(stroke.samples(), ElementsAre(sample1));
// Add second sample at time = T + 2ms. It's not yet time for the new frame,
// so no new sample should be generated.
@@ -434,9 +440,11 @@ TEST(PalmFilterStrokeTest, ResamplingTest) {
touch_.y = 20;
touch_.major = 12;
touch_.minor = 11;
- sample = CreatePalmFilterSample(touch_, time, model_config_, device_info);
- stroke.ProcessSample(sample);
- ASSERT_EQ(1u, stroke.samples().size());
+ PalmFilterSample sample2 =
+ CreatePalmFilterSample(touch_, time, model_config_, device_info);
+ stroke.ProcessSample(sample2);
+ // The samples should remain unchanged
+ ASSERT_THAT(stroke.samples(), ElementsAre(sample1));
// Add third sample at time = T + 12ms. A resampled event at time = T + 8ms
// should be generated.
@@ -445,20 +453,23 @@ TEST(PalmFilterStrokeTest, ResamplingTest) {
touch_.y = 24;
touch_.major = 14;
touch_.minor = 13;
- sample = CreatePalmFilterSample(touch_, time, model_config_, device_info);
- stroke.ProcessSample(sample);
- ASSERT_EQ(2u, stroke.samples().size());
+ PalmFilterSample sample3 =
+ CreatePalmFilterSample(touch_, time, model_config_, device_info);
+ stroke.ProcessSample(sample3);
+ ASSERT_THAT(
+ stroke.samples(),
+ ElementsAre(sample1, SampleTime(down_time + base::Milliseconds(8))));
+
EXPECT_EQ(150, stroke.samples().back().point.x());
EXPECT_EQ(22, stroke.samples().back().point.y());
EXPECT_EQ(14, stroke.samples().back().major_radius);
EXPECT_EQ(13, stroke.samples().back().minor_radius);
- EXPECT_EQ(down_time + base::Milliseconds(8), stroke.samples().back().time);
}
TEST(PalmFilterStrokeTest, MultipleResampledValues) {
NeuralStylusPalmDetectionFilterModelConfig model_config_;
model_config_.max_sample_count = 3;
- model_config_.resample_touch = true;
+ model_config_.resample_period = base::Milliseconds(8);
PalmFilterStroke stroke(model_config_);
PalmFilterDeviceInfo device_info;
@@ -471,16 +482,11 @@ TEST(PalmFilterStrokeTest, MultipleResampledValues) {
touch_.major = 200;
touch_.minor = 100;
base::TimeTicks down_time = base::TimeTicks::UnixEpoch() + base::Seconds(30);
- PalmFilterSample sample =
+ PalmFilterSample sample1 =
CreatePalmFilterSample(touch_, down_time, model_config_, device_info);
- stroke.ProcessSample(sample);
- // First sample should not be modified
- ASSERT_EQ(1u, stroke.samples().size());
- EXPECT_EQ(0, stroke.samples().back().point.x());
- EXPECT_EQ(10, stroke.samples().back().point.y());
- EXPECT_EQ(200, stroke.samples().back().major_radius);
- EXPECT_EQ(100, stroke.samples().back().minor_radius);
- EXPECT_EQ(down_time, stroke.samples().back().time);
+ stroke.ProcessSample(sample1);
+ // First sample should go in as is
+ ASSERT_THAT(stroke.samples(), ElementsAre(sample1));
// Add second sample at time = T + 20ms. Two resampled values should be
// generated: 1) at time = T+8ms 2) at time = T+16ms
@@ -489,23 +495,25 @@ TEST(PalmFilterStrokeTest, MultipleResampledValues) {
touch_.y = 30;
touch_.major = 220;
touch_.minor = 120;
- sample = CreatePalmFilterSample(touch_, time, model_config_, device_info);
- stroke.ProcessSample(sample);
- ASSERT_EQ(3u, stroke.samples().size());
+ PalmFilterSample sample2 =
+ CreatePalmFilterSample(touch_, time, model_config_, device_info);
+ stroke.ProcessSample(sample2);
+ ASSERT_THAT(stroke.samples(),
+ ElementsAre(SampleTime(down_time),
+ SampleTime(down_time + base::Milliseconds(8)),
+ SampleTime(down_time + base::Milliseconds(16))));
// First sample : time = T + 8ms
EXPECT_EQ(8, stroke.samples()[1].point.x());
EXPECT_EQ(18, stroke.samples()[1].point.y());
EXPECT_EQ(220, stroke.samples()[1].major_radius);
EXPECT_EQ(120, stroke.samples()[1].minor_radius);
- EXPECT_EQ(down_time + base::Milliseconds(8), stroke.samples()[1].time);
// Second sample : time = T + 16ms
EXPECT_EQ(16, stroke.samples().back().point.x());
EXPECT_EQ(26, stroke.samples().back().point.y());
EXPECT_EQ(220, stroke.samples().back().major_radius);
EXPECT_EQ(120, stroke.samples().back().minor_radius);
- EXPECT_EQ(down_time + base::Milliseconds(16), stroke.samples().back().time);
}
-} // namespace ui \ No newline at end of file
+} // namespace ui
diff --git a/ui/events/ozone/evdev/touch_filter/palm_model/onedevice_train_palm_detection_filter_model.cc b/ui/events/ozone/evdev/touch_filter/palm_model/onedevice_train_palm_detection_filter_model.cc
index 905e8bd..acf43d8 100644
--- a/ui/events/ozone/evdev/touch_filter/palm_model/onedevice_train_palm_detection_filter_model.cc
+++ b/ui/events/ozone/evdev/touch_filter/palm_model/onedevice_train_palm_detection_filter_model.cc
@@ -21,9 +21,7 @@
#include "ui/events/ozone/evdev/touch_filter/palm_model/onedevice_train_palm_detection_filter_inference.h"
#include "ui/events/ozone/evdev/touch_filter/palm_model/onedevice_train_palm_detection_filter_inference_beta.h"
#include "ui/events/ozone/evdev/touch_filter/palm_model/onedevice_train_palm_detection_filter_inference_v2.h"
-
#include "ui/events/ozone/features.h"
-
#define USE_EIGEN 0
namespace ui {
@@ -127,4 +125,4 @@ OneDeviceTrainNeuralStylusPalmDetectionFilterModel::
Initialize();
}
-} // namespace ui \ No newline at end of file
+} // namespace ui
diff --git a/ui/events/ozone/evdev/touch_filter/palm_model/onedevice_train_palm_detection_filter_model.h b/ui/events/ozone/evdev/touch_filter/palm_model/onedevice_train_palm_detection_filter_model.h
index da69463..eb020c8 100644
--- a/ui/events/ozone/evdev/touch_filter/palm_model/onedevice_train_palm_detection_filter_model.h
+++ b/ui/events/ozone/evdev/touch_filter/palm_model/onedevice_train_palm_detection_filter_model.h
@@ -31,7 +31,6 @@ class COMPONENT_EXPORT(EVDEV) OneDeviceTrainNeuralStylusPalmDetectionFilterModel
const NeuralStylusPalmDetectionFilterModelConfig& config() const override;
- // Config is further modified by Android classes inheriting from this class
protected:
NeuralStylusPalmDetectionFilterModelConfig config_;
@@ -42,4 +41,4 @@ class COMPONENT_EXPORT(EVDEV) OneDeviceTrainNeuralStylusPalmDetectionFilterModel
} // namespace ui
-#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_PALM_MODEL_ONEDEVICE_TRAIN_PALM_DETECTION_FILTER_MODEL_H_ \ No newline at end of file
+#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_PALM_MODEL_ONEDEVICE_TRAIN_PALM_DETECTION_FILTER_MODEL_H_