diff options
author | Denis Brockus <dbrockus@google.com> | 2023-03-17 11:18:41 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-03-21 17:30:03 +0000 |
commit | 1737b251d7e22532158941caa45c9b11fdc5e99c (patch) | |
tree | 9d88a383a5f1be17422e349a4281cfe66daee0fc | |
parent | 1e3890f8c3637a4d61f60d660462e0fd9a29f716 (diff) | |
download | libchrome-gestures-1737b251d7e22532158941caa45c9b11fdc5e99c.tar.gz |
metrics_filter_interpreter: remove the use of MemoryManagedList
Remove all references of MemoryManager
Remove all references of MemoryManagedList
Follow the mechanism in LookaheadFilterInterpreter crrev/c/4334918
BUG=b:271591258
TEST=USE="coverage" FEATURES="test noclean" emerge-brya chromeos-base/gestures
Change-Id: Ia2ca7ef7db0d44f880b969a6e0babf92c508f244
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/gestures/+/4348019
Commit-Queue: Harry Cutts <hcutts@chromium.org>
Auto-Submit: Denis Brockus <dbrockus@chromium.org>
Tested-by: Denis Brockus <dbrockus@chromium.org>
Reviewed-by: Harry Cutts <hcutts@chromium.org>
Code-Coverage: Harry Cutts <hcutts@chromium.org>
-rw-r--r-- | include/metrics_filter_interpreter.h | 41 | ||||
-rw-r--r-- | src/metrics_filter_interpreter.cc | 74 |
2 files changed, 41 insertions, 74 deletions
diff --git a/include/metrics_filter_interpreter.h b/include/metrics_filter_interpreter.h index 60d5898..b58aabf 100644 --- a/include/metrics_filter_interpreter.h +++ b/include/metrics_filter_interpreter.h @@ -2,16 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <map> #include <gtest/gtest.h> // for FRIEND_TEST +#include <list> +#include <map> +#include <optional> #include "include/filter_interpreter.h" #include "include/finger_metrics.h" #include "include/gestures.h" -#include "include/list.h" -#include "include/memory_manager.h" #include "include/prop_registry.h" #include "include/tracer.h" +#include "include/util.h" #ifndef GESTURES_METRICS_FILTER_INTERPRETER_H_ #define GESTURES_METRICS_FILTER_INTERPRETER_H_ @@ -43,31 +44,29 @@ class MetricsFilterInterpreter : public FilterInterpreter { template <class DataType, size_t kHistorySize> struct State { State() {} - State(const DataType& fs, const HardwareState& hwstate) { - Init(fs, hwstate); - } - - void Init(const DataType& fs, const HardwareState& hwstate) { - timestamp = hwstate.timestamp; - data = fs; - } + State(const DataType& fs, const HardwareState& hwstate) + : timestamp(hwstate.timestamp), data(fs) {} static size_t MaxHistorySize() { return kHistorySize; } stime_t timestamp; DataType data; - State<DataType, kHistorySize>* next_; - State<DataType, kHistorySize>* prev_; }; // struct for one finger's data of one frame. typedef State<FingerState, 3> MState; - typedef MemoryManagedList<MState> FingerHistory; + typedef std::list<MState> MStateListType; + typedef std::optional<std::reference_wrapper<MState>> OptionalRefMState; + + struct FingerHistory : public MStateListType { + OptionalRefMState at(int offset) { + return ListAt<OptionalRefMState, MStateListType>(*this, offset); + } + }; // Push the new data into the buffer. - template <class StateType, class DataType> - void AddNewStateToBuffer(MemoryManagedList<StateType>* history, - const DataType& data, + void AddNewStateToBuffer(FingerHistory& history, + const FingerState& data, const HardwareState& hwstate); // Update the class with new finger data, check if there is any interesting @@ -75,7 +74,7 @@ class MetricsFilterInterpreter : public FilterInterpreter { void UpdateFingerState(const HardwareState& hwstate); // Detect the noisy ground pattern and send GestureMetrics - bool DetectNoisyGround(const FingerHistory* history); + bool DetectNoisyGround(FingerHistory& history); // Update the class with new mouse movement data. void UpdateMouseMovementState(const HardwareState& hwstate); @@ -83,12 +82,8 @@ class MetricsFilterInterpreter : public FilterInterpreter { // Compute interested statistics for the mouse history, send GestureMetrics. void ReportMouseStatistics(); - // memory managers to prevent malloc during interrupt calls - MemoryManager<MState> mstate_mm_; - MemoryManager<FingerHistory> history_mm_; - // A map to store each finger's past data - typedef std::map<short, FingerHistory*> FingerHistoryMap; + typedef std::map<short, FingerHistory> FingerHistoryMap; FingerHistoryMap histories_; // Device class (e.g. touchpad, mouse). diff --git a/src/metrics_filter_interpreter.cc b/src/metrics_filter_interpreter.cc index de6ca33..39c9766 100644 --- a/src/metrics_filter_interpreter.cc +++ b/src/metrics_filter_interpreter.cc @@ -22,8 +22,6 @@ MetricsFilterInterpreter::MetricsFilterInterpreter( Tracer* tracer, GestureInterpreterDeviceClass devclass) : FilterInterpreter(NULL, next, tracer, false), - mstate_mm_(kMaxFingers * MState::MaxHistorySize()), - history_mm_(kMaxFingers), devclass_(devclass), mouse_movement_session_index_(0), mouse_movement_current_session_length(0), @@ -44,7 +42,7 @@ MetricsFilterInterpreter::MetricsFilterInterpreter( } void MetricsFilterInterpreter::SyncInterpretImpl(HardwareState* hwstate, - stime_t* timeout) { + stime_t* timeout) { if (devclass_ == GESTURES_DEVCLASS_TOUCHPAD) { // Right now, we only want to update finger states for built-in touchpads // because all the generated metrics gestures would be put under each @@ -66,22 +64,16 @@ void MetricsFilterInterpreter::SyncInterpretImpl(HardwareState* hwstate, next_->SyncInterpret(hwstate, timeout); } -template <class StateType, class DataType> void MetricsFilterInterpreter::AddNewStateToBuffer( - MemoryManagedList<StateType>* history, - const DataType& data, + FingerHistory& history, + const FingerState& data, const HardwareState& hwstate) { // The history buffer is already full, pop one - if (history->size() == StateType::MaxHistorySize()) - history->DeleteFront(); + if (history.size() == MState::MaxHistorySize()) + history.pop_front(); // Push the new finger state to the back of buffer - StateType* current = history->PushNewEltBack(); - if (!current) { - Err("MetricsFilterInterpreter buffer out of space"); - return; - } - current->Init(data, hwstate); + (void)history.emplace_back(data, hwstate); } void MetricsFilterInterpreter::UpdateMouseMovementState( @@ -138,68 +130,48 @@ void MetricsFilterInterpreter::ReportMouseStatistics() { void MetricsFilterInterpreter::UpdateFingerState( const HardwareState& hwstate) { - FingerHistoryMap removed; - RemoveMissingIdsFromMap(&histories_, hwstate, &removed); - for (FingerHistoryMap::const_iterator it = - removed.begin(); it != removed.end(); ++it) { - it->second->clear(); - history_mm_.Free(it->second); -} + RemoveMissingIdsFromMap(&histories_, hwstate); FingerState *fs = hwstate.fingers; for (short i = 0; i < hwstate.finger_cnt; i++) { - FingerHistory* hp; - // Update the map if the contact is new if (!MapContainsKey(histories_, fs[i].tracking_id)) { - hp = history_mm_.Allocate(); - if (!hp) { - Err("FingerHistory out of space"); - continue; - } - hp->Init(&mstate_mm_); - histories_[fs[i].tracking_id] = hp; - } else { - hp = histories_[fs[i].tracking_id]; + histories_[fs[i].tracking_id] = FingerHistory{}; } + auto& href = histories_[fs[i].tracking_id]; // Check if the finger history contains interesting patterns - AddNewStateToBuffer(hp, fs[i], hwstate); - DetectNoisyGround(hp); + AddNewStateToBuffer(href, fs[i], hwstate); + DetectNoisyGround(href); } } -bool MetricsFilterInterpreter::DetectNoisyGround( - const FingerHistory* history) { - auto iter = history->end(); - MState* current = *(--iter); - size_t n_samples = history->size(); +bool MetricsFilterInterpreter::DetectNoisyGround(FingerHistory& history) { // Noise pattern takes 3 samples - if (n_samples < 3) + if (history.size() < 3) return false; - MState* past_1 = *(--iter); - MState* past_2 = *(--iter); + auto current = history.at(-1)->get(); + auto past_1 = history.at(-2)->get(); + auto past_2 = history.at(-3)->get(); // Noise pattern needs to happen in a short period of time - if(current->timestamp - past_2->timestamp > - noisy_ground_time_threshold_.val_) { + if (current.timestamp - past_2.timestamp > noisy_ground_time_threshold_.val_) return false; - } // vec[when][x,y] float vec[2][2]; - vec[0][0] = current->data.position_x - past_1->data.position_x; - vec[0][1] = current->data.position_y - past_1->data.position_y; - vec[1][0] = past_1->data.position_x - past_2->data.position_x; - vec[1][1] = past_1->data.position_y - past_2->data.position_y; + vec[0][0] = current.data.position_x - past_1.data.position_x; + vec[0][1] = current.data.position_y - past_1.data.position_y; + vec[1][0] = past_1.data.position_x - past_2.data.position_x; + vec[1][1] = past_1.data.position_y - past_2.data.position_y; const float thr = noisy_ground_distance_threshold_.val_; // We dictate the noise pattern as two consecutive big moves in // opposite directions in either X or Y for (size_t i = 0; i < arraysize(vec[0]); i++) if ((vec[0][i] < -thr && vec[1][i] > thr) || (vec[0][i] > thr && vec[1][i] < -thr)) { - ProduceGesture(Gesture(kGestureMetrics, past_2->timestamp, - current->timestamp, kGestureMetricsTypeNoisyGround, + ProduceGesture(Gesture(kGestureMetrics, past_2.timestamp, + current.timestamp, kGestureMetricsTypeNoisyGround, vec[0][i], vec[1][i])); return true; } |