diff options
author | Denis Brockus <dbrockus@google.com> | 2023-03-20 14:01:39 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-03-23 19:26:58 +0000 |
commit | d434c1bc882f2627f37327f3805bc3cfbc2df37f (patch) | |
tree | 9f827cfe9a0b210716c3f3c5b5c3c19e59977a47 | |
parent | 930aa64c667122525a3e3cdaf9f0d03518a73c39 (diff) | |
download | libchrome-gestures-d434c1bc882f2627f37327f3805bc3cfbc2df37f.tar.gz |
trend_classifying_filter_interpreter: remove 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: Ie3774ec0596e96571617b2775ced719b639dd536
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/gestures/+/4357692
Code-Coverage: Henry Barnor <hbarnor@chromium.org>
Auto-Submit: Denis Brockus <dbrockus@chromium.org>
Commit-Queue: Denis Brockus <dbrockus@chromium.org>
Reviewed-by: Harry Cutts <hcutts@chromium.org>
Tested-by: Denis Brockus <dbrockus@chromium.org>
-rw-r--r-- | include/trend_classifying_filter_interpreter.h | 26 | ||||
-rw-r--r-- | src/trend_classifying_filter_interpreter.cc | 64 |
2 files changed, 35 insertions, 55 deletions
diff --git a/include/trend_classifying_filter_interpreter.h b/include/trend_classifying_filter_interpreter.h index b2e8436..1de25cd 100644 --- a/include/trend_classifying_filter_interpreter.h +++ b/include/trend_classifying_filter_interpreter.h @@ -2,17 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <gtest/gtest.h> // for FRIEND_TEST +#include <list> #include <map> +#include <optional> #include <set> -#include <gtest/gtest.h> // for FRIEND_TEST #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_TREND_CLASSIFYING_FILTER_INTERPRETER_H_ #define GESTURES_TREND_CLASSIFYING_FILTER_INTERPRETER_H_ @@ -151,12 +152,17 @@ private: GESTURES_FINGER_TREND_DEC_TOUCH_MAJOR }; return flags[idx]; } + }; - KState* next_; - KState* prev_; + typedef std::list<KState> KStateListType; + typedef std::optional<std::reference_wrapper<KState>> OptionalRefKState; + + struct FingerHistory : public KStateListType { + OptionalRefKState at(int offset) { + return ListAt<OptionalRefKState, KStateListType>(*this, offset); + } }; - typedef MemoryManagedList<KState> FingerHistory; // Trend types for internal use enum TrendType { @@ -169,7 +175,7 @@ private: void UpdateFingerState(const HardwareState& hwstate); // Push new finger data into the buffer and update values - void AddNewStateToBuffer(FingerHistory* history, const FingerState& fs); + void AddNewStateToBuffer(FingerHistory& history, const FingerState& fs); // Assess statistical significance with a classic two-tail hypothesis test TrendType RunKTTest(const KState::KAxis* current, const size_t n_samples); @@ -220,13 +226,9 @@ private: const unsigned flag_decreasing, unsigned* flags); - // memory managers to prevent malloc during interrupt calls - MemoryManager<KState> kstate_mm_; - MemoryManager<FingerHistory> history_mm_; - // A map to store each finger's past coordinates and calculation // intermediates - typedef std::map<short, FingerHistory*> FingerHistoryMap; + typedef std::map<short, FingerHistory> FingerHistoryMap; FingerHistoryMap histories_; // Flag to turn on/off the trend classifying filter diff --git a/src/trend_classifying_filter_interpreter.cc b/src/trend_classifying_filter_interpreter.cc index d6ddd21..2bfa156 100644 --- a/src/trend_classifying_filter_interpreter.cc +++ b/src/trend_classifying_filter_interpreter.cc @@ -30,8 +30,6 @@ namespace gestures { TrendClassifyingFilterInterpreter::TrendClassifyingFilterInterpreter( PropRegistry* prop_reg, Interpreter* next, Tracer* tracer) : FilterInterpreter(NULL, next, tracer, false), - kstate_mm_(kMaxFingers * kNumOfSamples), - history_mm_(kMaxFingers), trend_classifying_filter_enable_( prop_reg, "Trend Classifying Filter Enabled", true), second_order_enable_( @@ -72,37 +70,32 @@ void TrendClassifyingFilterInterpreter::InterpretTestResult( } void TrendClassifyingFilterInterpreter::AddNewStateToBuffer( - FingerHistory* history, const FingerState& fs) { + FingerHistory& history, const FingerState& fs) { // The history buffer is already full, pop one - if (history->size() == static_cast<size_t>(num_of_samples_.val_)) - history->DeleteFront(); + if (history.size() == static_cast<size_t>(num_of_samples_.val_)) + history.pop_front(); // Push the new finger state to the back of buffer - KState* previous_end = history->back(); - KState* current = history->PushNewEltBack(); - if (!current) { - Err("KState buffer out of space"); - return; - } - current->Init(fs); - if (history->size() == 1) + auto& current = history.emplace_back(fs); + if (history.size() == 1) return; + auto& previous_end = history.at(-2)->get(); - current->DxAxis()->val = current->XAxis()->val - previous_end->XAxis()->val; - current->DyAxis()->val = current->YAxis()->val - previous_end->YAxis()->val; + current.DxAxis()->val = current.XAxis()->val - previous_end.XAxis()->val; + current.DyAxis()->val = current.YAxis()->val - previous_end.YAxis()->val; // Update the nodes already in the buffer and compute the Kendall score/ // variance along the way. Complexity is O(|buffer|) per finger. int tie_n2[KState::n_axes_] = { 0, 0, 0, 0, 0, 0 }; int tie_n3[KState::n_axes_] = { 0, 0, 0, 0, 0, 0 }; - for (auto it = history->begin(); it != history->end(); ++it) + for (auto it = history.begin(); it != history.end(); ++it) for (size_t i = 0; i < KState::n_axes_; i++) - if (it != history->begin() || !KState::IsDelta(i)) { - UpdateKTValuePair(&(*it)->axes_[i], ¤t->axes_[i], + if (it != history.begin() || !KState::IsDelta(i)) { + UpdateKTValuePair(&it->axes_[i], ¤t.axes_[i], &tie_n2[i], &tie_n3[i]); } - size_t n_samples = history->size(); + size_t n_samples = history.size(); for (size_t i = 0; i < KState::n_axes_; i++) { - current->axes_[i].var = ComputeKTVariance(tie_n2[i], tie_n3[i], + current.axes_[i].var = ComputeKTVariance(tie_n2[i], tie_n3[i], KState::IsDelta(i) ? n_samples - 1 : n_samples); } } @@ -132,38 +125,23 @@ TrendClassifyingFilterInterpreter::RunKTTest(const KState::KAxis* current, void TrendClassifyingFilterInterpreter::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; + 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(&kstate_mm_); - histories_[fs[i].tracking_id] = hp; - } else { - hp = histories_[fs[i].tracking_id]; + histories_[fs[i].tracking_id] = FingerHistory{}; } + auto& history = histories_[fs[i].tracking_id]; // Check if the score demonstrates statistical significance - AddNewStateToBuffer(hp, fs[i]); - KState* current = hp->back(); - size_t n_samples = hp->size(); + AddNewStateToBuffer(history, fs[i]); + const auto& current = history.back(); + const size_t n_samples = history.size(); for (size_t idx = 0; idx < KState::n_axes_; idx++) if (second_order_enable_.val_ || !KState::IsDelta(idx)) { - TrendType result = RunKTTest(¤t->axes_[idx], + TrendType result = RunKTTest(¤t.axes_[idx], KState::IsDelta(idx) ? n_samples - 1 : n_samples); InterpretTestResult(result, KState::IncFlag(idx), KState::DecFlag(idx), &(fs[i].flags)); |