summaryrefslogtreecommitdiff
path: root/chromium/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_report_filter.cc
blob: 2fe91172bf583d45621cc2564c80c11cfc8c0411 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// 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_report_filter.h"

#include "base/metrics/histogram_macros.h"

namespace ui {

NeuralStylusReportFilter::NeuralStylusReportFilter(
    SharedPalmDetectionFilterState* shared_palm_state)
    : PalmDetectionFilter(shared_palm_state) {}

NeuralStylusReportFilter::~NeuralStylusReportFilter() {}

bool NeuralStylusReportFilter::CompatibleWithNeuralStylusReportFilter(
    const EventDeviceInfo& devinfo) {
  return devinfo.HasStylus();
}

void NeuralStylusReportFilter::Filter(
    const std::vector<InProgressTouchEvdev>& touches,
    base::TimeTicks time,
    std::bitset<kNumTouchEvdevSlots>* slots_to_hold,
    std::bitset<kNumTouchEvdevSlots>* slots_to_suppress) {
  bool should_update = false;
  for (const auto& touch : touches) {
    // Is a stylus detected? We should be updating.
    if (touch.altered && touch.stylus_button) {
      should_update = true;
      continue;
    }
  }
  // Only update once when a stylus is detected.
  if (!previous_update_ && should_update) {
    // Once a stylus is detected, we report.
    base::TimeDelta palm_age =
        time - shared_palm_state_->latest_palm_touch_time;
    base::TimeDelta finger_age =
        time - shared_palm_state_->latest_finger_touch_time;
    UMA_HISTOGRAM_TIMES(kNeuralPalmAge, palm_age);
    UMA_HISTOGRAM_TIMES(kNeuralFingerAge, finger_age);
    UMA_HISTOGRAM_COUNTS_100(kNeuralPalmTouchCount,
                             shared_palm_state_->active_palm_touches);
  }
  previous_update_ = should_update;
  slots_to_hold->reset();
  slots_to_suppress->reset();
}

const char NeuralStylusReportFilter::kFilterName[] = "NeuralStylusReportFilter";
const char NeuralStylusReportFilter::kNeuralPalmAge[] =
    "Ozone.NeuralStylusReport.PalmAgeBeforeStylus";
const char NeuralStylusReportFilter::kNeuralFingerAge[] =
    "Ozone.NeuralStylusReport.FingerAgeBeforeStylus";
const char NeuralStylusReportFilter::kNeuralPalmTouchCount[] =
    "Ozone.NeuralStylusReport.ActivePalmTouchCount";
std::string NeuralStylusReportFilter::FilterNameForTesting() const {
  return kFilterName;
}

}  // namespace ui