#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.h"
#include <functional>
#include <memory>
#include <queue>
#include <string>
#include <tuple>
#include <unordered_set>
#include <utility>
#include <vector>
#include "base/command_line.h"
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/ranges/algorithm.h"
#include "base/values.h"
#include "ui/events/ozone/evdev/event_device_info.h"
#include "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_model.h"
#include "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.h"
#include "ui/events/ozone/features.h"
namespace ui {
namespace {
float EuclideanDistance(const gfx::PointF& a, const gfx::PointF& b) { … }
bool IsEarlyStageSample(
const PalmFilterStroke& stroke,
const NeuralStylusPalmDetectionFilterModelConfig& config) { … }
bool HasDecidedStroke(
const PalmFilterStroke& stroke,
const NeuralStylusPalmDetectionFilterModelConfig& config) { … }
bool IsVeryShortStroke(
const PalmFilterStroke& stroke,
const NeuralStylusPalmDetectionFilterModelConfig& config) { … }
bool HasInsufficientDataAsNeighbor(
const PalmFilterStroke& neighbor_stroke,
size_t neighbor_min_sample_count,
const NeuralStylusPalmDetectionFilterModelConfig& config) { … }
}
NeuralStylusPalmDetectionFilter::NeuralStylusPalmDetectionFilter(
const EventDeviceInfo& devinfo,
std::unique_ptr<NeuralStylusPalmDetectionFilterModel> palm_model,
SharedPalmDetectionFilterState* shared_palm_state)
: … { … }
NeuralStylusPalmDetectionFilter::~NeuralStylusPalmDetectionFilter() { … }
void NeuralStylusPalmDetectionFilter::FindBiggestNeighborsWithin(
int neighbor_count,
unsigned long neighbor_min_sample_count,
float max_distance,
const PalmFilterStroke& stroke,
std::vector<std::pair<float, int>>* biggest_strokes) const { … }
void NeuralStylusPalmDetectionFilter::FindNearestNeighborsWithin(
int neighbor_count,
unsigned long neighbor_min_sample_count,
float max_distance,
const PalmFilterStroke& stroke,
std::vector<std::pair<float, int>>* nearest_strokes) const { … }
void NeuralStylusPalmDetectionFilter::Filter(
const std::vector<InProgressTouchEvdev>& touches,
base::TimeTicks time,
std::bitset<kNumTouchEvdevSlots>* slots_to_hold,
std::bitset<kNumTouchEvdevSlots>* slots_to_suppress) { … }
bool NeuralStylusPalmDetectionFilter::ShouldDecideStroke(
const PalmFilterStroke& stroke) const { … }
bool NeuralStylusPalmDetectionFilter::IsHeuristicPalmStroke(
const PalmFilterStroke& stroke) const { … }
bool NeuralStylusPalmDetectionFilter::DetectSpuriousStroke(
const std::vector<float>& features,
float threshold) const { … }
std::vector<float> NeuralStylusPalmDetectionFilter::ExtractFeatures(
int tracking_id) const { … }
void NeuralStylusPalmDetectionFilter::AppendFeatures(
const PalmFilterStroke& stroke,
std::vector<float>* features) const { … }
void NeuralStylusPalmDetectionFilter::AppendResampledFeatures(
const PalmFilterStroke& stroke,
std::vector<float>* features) const { … }
void NeuralStylusPalmDetectionFilter::AppendFeaturesAsNeighbor(
const PalmFilterStroke& stroke,
float distance,
std::vector<float>* features) const { … }
const int NeuralStylusPalmDetectionFilter::kExtraFeaturesForNeighbor = …;
const int NeuralStylusPalmDetectionFilter::kFeaturesPerSample = …;
const char NeuralStylusPalmDetectionFilter::kFilterName[] = …;
std::string NeuralStylusPalmDetectionFilter::FilterNameForTesting() const { … }
bool NeuralStylusPalmDetectionFilter::
CompatibleWithNeuralStylusPalmDetectionFilter(
const EventDeviceInfo& devinfo) { … }
bool NeuralStylusPalmDetectionFilter::
CompatibleWithNeuralStylusPalmDetectionFilter(
const EventDeviceInfo& devinfo,
const std::string& ozone_params_switch_string) { … }
void NeuralStylusPalmDetectionFilter::EraseOldStrokes(base::TimeTicks time) { … }
}