diff options
author | Harry Cutts <hcutts@google.com> | 2023-03-10 19:15:36 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-03-10 19:15:36 +0000 |
commit | 20ab3e76e32f89c292a0bcb00d13854f45381500 (patch) | |
tree | e65830aa73b07fb96a0d5808413630dbade8bce8 | |
parent | 22c5cd7bfe024e2fad7d97d15b350c654a31f2b1 (diff) | |
parent | 6c1bd8279106bae21cf56fda8469d76e4f141c8b (diff) | |
download | libchrome-gestures-20ab3e76e32f89c292a0bcb00d13854f45381500.tar.gz |
Merge latest patches from upstream am: fdad07cb6e am: 771b6d93c6 am: 6c1bd82791
Original change: https://android-review.googlesource.com/c/platform/external/libchrome-gestures/+/2480579
Change-Id: I0051830c62d5e48b3723663d5e3aebd5ac7f876b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | Android.bp | 1 | ||||
-rw-r--r-- | METADATA.android | 4 | ||||
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | include/gestures.h | 3 | ||||
-rw-r--r-- | include/list.h | 104 | ||||
-rw-r--r-- | include/lookahead_filter_interpreter.h | 13 | ||||
-rw-r--r-- | include/prop_registry.h | 58 | ||||
-rw-r--r-- | src/iir_filter_interpreter.cc | 2 | ||||
-rw-r--r-- | src/immediate_interpreter.cc | 3 | ||||
-rw-r--r-- | src/list_unittest.cc | 93 | ||||
-rw-r--r-- | src/logging_filter_interpreter.cc | 10 | ||||
-rw-r--r-- | src/lookahead_filter_interpreter.cc | 137 | ||||
-rw-r--r-- | src/lookahead_filter_interpreter_unittest.cc | 99 | ||||
-rw-r--r-- | src/metrics_filter_interpreter.cc | 9 | ||||
-rw-r--r-- | src/mouse_interpreter.cc | 4 | ||||
-rw-r--r-- | src/prop_registry.cc | 12 | ||||
-rw-r--r-- | src/prop_registry_unittest.cc | 65 | ||||
-rw-r--r-- | src/scaling_filter_interpreter.cc | 9 | ||||
-rw-r--r-- | src/scaling_filter_interpreter_unittest.cc | 43 | ||||
-rw-r--r-- | src/trend_classifying_filter_interpreter.cc | 12 | ||||
-rwxr-xr-x | tools/local_coverage_rate.sh | 2 | ||||
-rwxr-xr-x | tools/regression_test.sh | 2 | ||||
-rwxr-xr-x | tools/replay_log | 2 | ||||
-rwxr-xr-x | tools/tplog.py | 2 |
24 files changed, 337 insertions, 355 deletions
@@ -132,7 +132,6 @@ cc_test { "src/immediate_interpreter_unittest.cc", "src/integral_gesture_filter_interpreter_unittest.cc", "src/interpreter_unittest.cc", - "src/list_unittest.cc", "src/logging_filter_interpreter_unittest.cc", "src/lookahead_filter_interpreter_unittest.cc", "src/mouse_interpreter_unittest.cc", diff --git a/METADATA.android b/METADATA.android index 00233ca..4aee07c 100644 --- a/METADATA.android +++ b/METADATA.android @@ -6,7 +6,7 @@ third_party { type: GIT value: "https://chromium.googlesource.com/chromiumos/platform/gestures/" } - version: "3059225019e295de1138574a16c0102c6845fefb" - last_upgrade_date { year: 2023 month: 02 day: 27 } + version: "2a80cba49fb09f6f2632b61f21ea7dc62acd82d7" + last_upgrade_date { year: 2023 month: 03 day: 10 } license_type: NOTICE } @@ -60,7 +60,6 @@ TEST_OBJECTS=\ $(OBJDIR)/immediate_interpreter_unittest.o \ $(OBJDIR)/integral_gesture_filter_interpreter_unittest.o \ $(OBJDIR)/interpreter_unittest.o \ - $(OBJDIR)/list_unittest.o \ $(OBJDIR)/logging_filter_interpreter_unittest.o \ $(OBJDIR)/lookahead_filter_interpreter_unittest.o \ $(OBJDIR)/non_linearity_filter_interpreter_unittest.o \ @@ -112,7 +111,7 @@ DESTDIR = . CXXFLAGS+=\ -g \ - -std=gnu++11 \ + -std=gnu++17 \ -fno-exceptions \ -fno-strict-aliasing \ -fPIC \ diff --git a/include/gestures.h b/include/gestures.h index e4f7cc2..f21d531 100644 --- a/include/gestures.h +++ b/include/gestures.h @@ -55,7 +55,8 @@ struct HardwareProperties { float right; // The maximum Y coordinate that the device can report. float bottom; - // The resolutions of the X and Y axes, in units per mm. + // The resolutions of the X and Y axes, in units per mm. Set to 0 if the + // resolution is unknown. float res_x; float res_y; diff --git a/include/list.h b/include/list.h index d5d94c4..c822e7a 100644 --- a/include/list.h +++ b/include/list.h @@ -5,104 +5,27 @@ #ifndef GESTURES_LIST_H__ #define GESTURES_LIST_H__ +#include <list> #include "include/logging.h" #include "include/memory_manager.h" namespace gestures { -// Elt must have the following members: -// Elt* next_; -// Elt* prev_; - -template<typename Elt> -class List { - public: - List() { Init(); } - ~List() { DeleteAll(); } - - // inserts new_elt before existing. Assumes existing is in list already. - void InsertBefore(Elt *existing, Elt* new_elt) { - size_++; - Elt* pre_new = existing->prev_; - pre_new->next_ = new_elt; - new_elt->prev_ = pre_new; - new_elt->next_ = existing; - existing->prev_ = new_elt; - } - - Elt* Unlink(Elt* existing) { - if (Empty()) { - Err("Can't pop from empty list!"); - return NULL; - } - size_--; - existing->prev_->next_ = existing->next_; - existing->next_->prev_ = existing->prev_; - existing->prev_ = existing->next_ = NULL; - return existing; - } - - void PushFront(Elt* elt) { InsertBefore(sentinel_.next_, elt); } - Elt* PopFront() { return Unlink(sentinel_.next_); } - void PushBack(Elt* elt) { InsertBefore(&sentinel_, elt); } - Elt* PopBack() { return Unlink(sentinel_.prev_); } - - virtual void DeleteAll() { - while (!Empty()) - delete PopFront(); - } - - Elt* Head() const { return sentinel_.next_; } - Elt* Tail() const { return sentinel_.prev_; } - size_t size() const { return size_; } - bool Empty() const { return size() == 0; } - - // Iterator-like methods - Elt* Begin() const { return Head(); } - Elt* End() const { return const_cast<Elt*>(&sentinel_); } - - void Init() { - size_ = 0; - sentinel_.next_ = sentinel_.prev_ = &sentinel_; - } - - private: - // sentinel element - Elt sentinel_; - - size_t size_; -}; - - template<typename Elt> -class MemoryManagedList : public List<Elt> { +class MemoryManagedList : public std::list<Elt*> { public: - using List<Elt>::Empty; - using List<Elt>::PopBack; - using List<Elt>::PopFront; - using List<Elt>::PushBack; - using List<Elt>::PushFront; - MemoryManagedList() { }; - ~MemoryManagedList() { DeleteAll(); } + ~MemoryManagedList() { clear(); } void Init(MemoryManager<Elt>* memory_manager) { memory_manager_ = memory_manager; - List<Elt>::Init(); - } - - Elt* NewElt() { - Elt* elt = memory_manager_->Allocate(); - AssertWithReturnValue(elt, NULL); - elt->next_ = elt->prev_ = NULL; - return elt; } Elt* PushNewEltBack() { AssertWithReturnValue(memory_manager_, NULL); Elt* elt = NewElt(); AssertWithReturnValue(elt, NULL); - PushBack(elt); + this->push_back(elt); return elt; } @@ -110,26 +33,35 @@ class MemoryManagedList : public List<Elt> { AssertWithReturnValue(memory_manager_, NULL); Elt* elt = NewElt(); AssertWithReturnValue(elt, NULL); - PushFront(elt); + this->push_front(elt); return elt; } void DeleteFront() { AssertWithReturn(memory_manager_); - memory_manager_->Free(PopFront()); + memory_manager_->Free(this->front()); + this->pop_front(); } void DeleteBack() { AssertWithReturn(memory_manager_); - memory_manager_->Free(PopBack()); + memory_manager_->Free(this->pop_back()); } - virtual void DeleteAll() { - while (!Empty()) + void clear() { + while (!this->empty()) DeleteFront(); } + private: MemoryManager<Elt>* memory_manager_; + + Elt* NewElt() { + Elt* elt = memory_manager_->Allocate(); + AssertWithReturnValue(elt, NULL); + elt->next_ = elt->prev_ = NULL; + return elt; + } }; diff --git a/include/lookahead_filter_interpreter.h b/include/lookahead_filter_interpreter.h index 33dcc9b..31aefe4 100644 --- a/include/lookahead_filter_interpreter.h +++ b/include/lookahead_filter_interpreter.h @@ -3,15 +3,16 @@ // found in the LICENSE file. #include <algorithm> +#include <list> #include <map> #include <memory> +#include <vector> #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/prop_registry.h" #include "include/tracer.h" @@ -33,6 +34,8 @@ class LookaheadFilterInterpreter : public FilterInterpreter { FRIEND_TEST(LookaheadFilterInterpreterTest, SimpleTest); FRIEND_TEST(LookaheadFilterInterpreterTest, SpuriousCallbackTest); FRIEND_TEST(LookaheadFilterInterpreterTest, VariableDelayTest); + FRIEND_TEST(LookaheadFilterInterpreterTest, QStateListTest); + public: LookaheadFilterInterpreter(PropRegistry* prop_reg, Interpreter* next, Tracer* tracer); @@ -108,8 +111,12 @@ class LookaheadFilterInterpreter : public FilterInterpreter { stime_t ExtraVariableDelay() const; - List<QState> queue_; - List<QState> free_list_; + class QStateList : public std::list<QState*> { + public: + QState* at(int offset); + } queue_; + + std::vector<QState*> free_list_; // The last id assigned to a contact (part of drumroll suppression) short last_id_; diff --git a/include/prop_registry.h b/include/prop_registry.h index 836b98b..4545a33 100644 --- a/include/prop_registry.h +++ b/include/prop_registry.h @@ -46,9 +46,8 @@ class PropertyDelegate; class Property { public: - Property(PropRegistry* parent, const char* name, - PropertyDelegate* delegate) - : gprop_(NULL), parent_(parent), delegate_(delegate), name_(name) {} + Property(PropRegistry* parent, const char* name) + : parent_(parent), name_(name) {} virtual ~Property() { if (parent_) @@ -59,18 +58,9 @@ class Property { virtual void CreatePropImpl() = 0; void DestroyProp(); - // b/253585974 - // delegate used to get passed as a constructor parameter but that - // led to a chance that the delegate was 'this' and setting the - // delegate to 'this' in the initializer list allowed the property - // creation to use 'this' before it was initialized. This could - // lead to unexpected behavior and if you were lucky to a crash. - // - // Now the delegate is always NULL on initilization of the property - // instance and after the delegate and property are completely - // created the user should set the delegate in the constructor - // body. This will allow access to this in a safe manner. - void SetDelegate(PropertyDelegate* delegate); + void SetDelegate(PropertyDelegate* delegate) { + delegate_ = delegate; + } const char* name() { return name_; } // Returns a newly allocated Value object @@ -91,9 +81,9 @@ class Property { virtual void HandleGesturesPropWritten() = 0; protected: - GesturesProp* gprop_; + GesturesProp* gprop_ = NULL; PropRegistry* parent_; - PropertyDelegate* delegate_; + PropertyDelegate* delegate_ = NULL; private: const char* name_; @@ -101,9 +91,8 @@ class Property { class BoolProperty : public Property { public: - BoolProperty(PropRegistry* reg, const char* name, GesturesPropBool val, - PropertyDelegate* delegate = NULL) - : Property(reg, name, delegate), val_(val) { + BoolProperty(PropRegistry* reg, const char* name, GesturesPropBool val) + : Property(reg, name), val_(val) { if (parent_) parent_->Register(this); } @@ -118,8 +107,8 @@ class BoolProperty : public Property { class BoolArrayProperty : public Property { public: BoolArrayProperty(PropRegistry* reg, const char* name, GesturesPropBool* vals, - size_t count, PropertyDelegate* delegate = NULL) - : Property(reg, name, delegate), vals_(vals), count_(count) { + size_t count) + : Property(reg, name), vals_(vals), count_(count) { if (parent_) parent_->Register(this); } @@ -134,9 +123,8 @@ class BoolArrayProperty : public Property { class DoubleProperty : public Property { public: - DoubleProperty(PropRegistry* reg, const char* name, double val, - PropertyDelegate* delegate = NULL) - : Property(reg, name, delegate), val_(val) { + DoubleProperty(PropRegistry* reg, const char* name, double val) + : Property(reg, name), val_(val) { if (parent_) parent_->Register(this); } @@ -151,8 +139,8 @@ class DoubleProperty : public Property { class DoubleArrayProperty : public Property { public: DoubleArrayProperty(PropRegistry* reg, const char* name, double* vals, - size_t count, PropertyDelegate* delegate = NULL) - : Property(reg, name, delegate), vals_(vals), count_(count) { + size_t count) + : Property(reg, name), vals_(vals), count_(count) { if (parent_) parent_->Register(this); } @@ -167,9 +155,8 @@ class DoubleArrayProperty : public Property { class IntProperty : public Property { public: - IntProperty(PropRegistry* reg, const char* name, int val, - PropertyDelegate* delegate = NULL) - : Property(reg, name, delegate), val_(val) { + IntProperty(PropRegistry* reg, const char* name, int val) + : Property(reg, name), val_(val) { if (parent_) parent_->Register(this); } @@ -183,9 +170,9 @@ class IntProperty : public Property { class IntArrayProperty : public Property { public: - IntArrayProperty(PropRegistry* reg, const char* name, int* vals, size_t count, - PropertyDelegate* delegate = NULL) - : Property(reg, name, delegate), vals_(vals), count_(count) { + IntArrayProperty(PropRegistry* reg, const char* name, int* vals, + size_t count) + : Property(reg, name), vals_(vals), count_(count) { if (parent_) parent_->Register(this); } @@ -200,9 +187,8 @@ class IntArrayProperty : public Property { class StringProperty : public Property { public: - StringProperty(PropRegistry* reg, const char* name, const char* val, - PropertyDelegate* delegate = NULL) - : Property(reg, name, delegate), val_(val) { + StringProperty(PropRegistry* reg, const char* name, const char* val) + : Property(reg, name), val_(val) { if (parent_) parent_->Register(this); } diff --git a/src/iir_filter_interpreter.cc b/src/iir_filter_interpreter.cc index 0558ef6..042e0f5 100644 --- a/src/iir_filter_interpreter.cc +++ b/src/iir_filter_interpreter.cc @@ -41,6 +41,7 @@ IirFilterInterpreter::IirFilterInterpreter(PropRegistry* prop_reg, a2_(prop_reg, "IIR a2", 0.412801598096189), iir_dist_thresh_(prop_reg, "IIR Distance Threshold", 10), adjust_iir_on_warp_(prop_reg, "Adjust IIR History On Warp", false) { + InitName(); b0_.SetDelegate(this); b1_.SetDelegate(this); b2_.SetDelegate(this); @@ -48,7 +49,6 @@ IirFilterInterpreter::IirFilterInterpreter(PropRegistry* prop_reg, a1_.SetDelegate(this); a2_.SetDelegate(this); iir_dist_thresh_.SetDelegate(this); - InitName(); } void IirFilterInterpreter::SyncInterpretImpl(HardwareState* hwstate, diff --git a/src/immediate_interpreter.cc b/src/immediate_interpreter.cc index 70369eb..7af423c 100644 --- a/src/immediate_interpreter.cc +++ b/src/immediate_interpreter.cc @@ -1095,7 +1095,7 @@ ImmediateInterpreter::ImmediateInterpreter(PropRegistry* prop_reg, keyboard_touched_timeval_high_(prop_reg, "Keyboard Touched Timeval High", 0), keyboard_touched_timeval_low_(prop_reg, "Keyboard Touched Timeval Low", - 0, this), + 0), keyboard_palm_prevent_timeout_(prop_reg, "Keyboard Palm Prevent Timeout", 0.5), motion_tap_prevent_timeout_(prop_reg, "Motion Tap Prevent Timeout", @@ -1136,6 +1136,7 @@ ImmediateInterpreter::ImmediateInterpreter(PropRegistry* prop_reg, quick_acceleration_factor_(prop_reg, "Quick Acceleration Factor", 0.0) { InitName(); requires_metrics_ = true; + keyboard_touched_timeval_low_.SetDelegate(this); } void ImmediateInterpreter::SyncInterpretImpl(HardwareState* hwstate, diff --git a/src/list_unittest.cc b/src/list_unittest.cc deleted file mode 100644 index 9c8ea74..0000000 --- a/src/list_unittest.cc +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2011 The ChromiumOS Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <algorithm> -#include <set> - -#include <gtest/gtest.h> - -#include "include/list.h" -#include "include/util.h" - -namespace gestures { - -class ListTest : public ::testing::Test {}; - -namespace { -struct Node { - explicit Node() : val_(-1) {} - explicit Node(int val) : val_(val) {} - int val_; - Node* next_; - Node* prev_; -}; - -void VerifyList(List<Node>& list) { - Node* first = list.Head()->prev_; // sentinel - Node* second = list.Head(); // next elt (sentinel or first element) - std::set<Node*> seen_nodes; - if (!list.Empty()) - EXPECT_NE(first, second); - else - EXPECT_EQ(first, second); - seen_nodes.insert(second); - for (size_t i = 0; i <= list.size(); ++i) { - EXPECT_EQ(first->next_, second); - EXPECT_EQ(second->prev_, first); - if (i < list.size()) { - first = second; - second = second->next_; - EXPECT_FALSE(SetContainsValue(seen_nodes, second)); - seen_nodes.insert(second); - } - } - EXPECT_EQ(seen_nodes.size(), list.size() + 1); - // second should now be sentinal tail - Node* sen_tail = list.Tail()->next_; - EXPECT_EQ(second, sen_tail); -} -} - -TEST(ListTest, SimpleTest) { - List<Node> list; - VerifyList(list); - EXPECT_TRUE(list.Empty()); - EXPECT_EQ(0, list.size()); - list.PushFront(new Node(4)); - VerifyList(list); - EXPECT_FALSE(list.Empty()); - EXPECT_EQ(1, list.size()); - list.PushFront(new Node(5)); - VerifyList(list); - EXPECT_EQ(2, list.size()); - EXPECT_EQ(4, list.Tail()->val_); - EXPECT_EQ(5, list.Head()->val_); - list.PushBack(new Node(3)); - VerifyList(list); - EXPECT_EQ(3, list.size()); - - Node* node = list.PopFront(); - VerifyList(list); - ASSERT_TRUE(node); - EXPECT_EQ(5, node->val_); - delete node; - - node = list.PopBack(); - VerifyList(list); - ASSERT_TRUE(node); - EXPECT_EQ(3, node->val_); - delete node; - - node = list.PopBack(); - VerifyList(list); - ASSERT_TRUE(node); - EXPECT_EQ(4, node->val_); - delete node; - - node = list.PopBack(); - VerifyList(list); - EXPECT_EQ(NULL, node); -} - -} // namespace gestures diff --git a/src/logging_filter_interpreter.cc b/src/logging_filter_interpreter.cc index d504607..2c43238 100644 --- a/src/logging_filter_interpreter.cc +++ b/src/logging_filter_interpreter.cc @@ -17,15 +17,19 @@ LoggingFilterInterpreter::LoggingFilterInterpreter(PropRegistry* prop_reg, Interpreter* next, Tracer* tracer) : FilterInterpreter(prop_reg, next, tracer, true), - event_logging_enable_(prop_reg, "Event Logging Enable", false, this), - logging_notify_(prop_reg, "Logging Notify", 0, this), - logging_reset_(prop_reg, "Logging Reset", 0, this), + event_logging_enable_(prop_reg, "Event Logging Enable", false), + logging_notify_(prop_reg, "Logging Notify", 0), + logging_reset_(prop_reg, "Logging Reset", 0), log_location_(prop_reg, "Log Path", "/var/log/xorg/touchpad_activity_log.txt"), integrated_touchpad_(prop_reg, "Integrated Touchpad", false) { InitName(); if (prop_reg && log_.get()) prop_reg->set_activity_log(log_.get()); + event_logging_enable_.SetDelegate(this); + BoolWasWritten(&event_logging_enable_); + logging_notify_.SetDelegate(this); + logging_reset_.SetDelegate(this); } void LoggingFilterInterpreter::IntWasWritten(IntProperty* prop) { diff --git a/src/lookahead_filter_interpreter.cc b/src/lookahead_filter_interpreter.cc index f7abaf5..f60b0f5 100644 --- a/src/lookahead_filter_interpreter.cc +++ b/src/lookahead_filter_interpreter.cc @@ -19,9 +19,12 @@ namespace { static const stime_t kMaxDelay = 0.09; // 90ms } +static const size_t kMaxQNodes = 16; + LookaheadFilterInterpreter::LookaheadFilterInterpreter( PropRegistry* prop_reg, Interpreter* next, Tracer* tracer) : FilterInterpreter(NULL, next, tracer, false), + free_list_(kMaxQNodes), last_id_(0), max_fingers_per_hwstate_(0), interpreter_due_(-1.0), last_interpreted_time_(-1.0), min_nonsuppress_speed_(prop_reg, "Input Queue Min Nonsuppression Speed", @@ -46,40 +49,42 @@ LookaheadFilterInterpreter::LookaheadFilterInterpreter( void LookaheadFilterInterpreter::SyncInterpretImpl(HardwareState* hwstate, stime_t* timeout) { // Push back into queue - if (free_list_.Empty()) { + if (free_list_.empty()) { Err("Can't accept new hwstate b/c we're out of nodes!"); Err("Now: %f, interpreter_due_ %f", hwstate->timestamp, interpreter_due_); Err("Dump of queue:"); - for (QState* it = queue_.Begin(); it != queue_.End(); it = it->next_) - Err("Due: %f%s", it->due_, it->completed_ ? " (c)" : ""); + for (const auto& element : queue_) + Err("Due: %f%s", element->due_, element->completed_ ? " (c)" : ""); return; } - QState* node = free_list_.PopFront(); + QState* node = free_list_.back(); + free_list_.pop_back(); node->set_state(*hwstate); double delay = max(0.0, min<stime_t>(kMaxDelay, min_delay_.val_)); node->due_ = hwstate->timestamp + delay; node->completed_ = false; - if (queue_.Empty()) + if (queue_.empty()) node->output_ids_.clear(); else - node->output_ids_ = queue_.Tail()->output_ids_; - // At this point, if ExtraVariableDelay() > 0, queue_.Tail()->due_ may have + node->output_ids_ = queue_.back()->output_ids_; + // At this point, if ExtraVariableDelay() > 0, queue_.back()->due_ may have // ExtraVariableDelay() applied, but node->due_ does not, yet. - if (!queue_.Empty() && - (queue_.Tail()->due_ - node->due_ > ExtraVariableDelay())) { + if (!queue_.empty() && + (queue_.back()->due_ - node->due_ > ExtraVariableDelay())) { Err("Clock changed backwards. Flushing queue."); stime_t next_timeout = NO_DEADLINE; - QState* q_node = queue_.Head(); + auto q_node_iter = queue_.begin(); do { - if (!q_node->completed_) - next_->SyncInterpret(&q_node->state_, &next_timeout); - q_node = q_node->next_; - free_list_.PushBack(queue_.PopFront()); - } while (!queue_.Empty()); + if (!(*q_node_iter)->completed_) + next_->SyncInterpret(&(*q_node_iter)->state_, &next_timeout); + ++q_node_iter; + free_list_.push_back(queue_.front()); + queue_.pop_front(); + } while (!queue_.empty()); interpreter_due_ = -1.0; last_interpreted_time_ = -1.0; } - queue_.PushBack(node); + queue_.push_back(node); AssignTrackingIds(); AttemptInterpolation(); UpdateInterpreterDue(interpreter_due_ < 0.0 ? @@ -88,7 +93,7 @@ void LookaheadFilterInterpreter::SyncInterpretImpl(HardwareState* hwstate, HandleTimerImpl(hwstate->timestamp, timeout); // Copy finger flags for upstream filters. - QState* q_node = queue_.Head(); + QState* q_node = queue_.front(); if (q_node->state_.SameFingersAs(*hwstate)) { for (size_t i = 0; i < hwstate->finger_cnt; i++) { hwstate->fingers[i].flags = q_node->state_.fingers[i].flags; @@ -143,7 +148,7 @@ void LookaheadFilterInterpreter::AssignTrackingIds() { // Always reassign trackingID on the very first hwstate so that // the next hwstate can inherit the trackingID mapping. if (queue_.size() == 1) { - QState* tail = queue_.Tail(); + QState* tail = queue_.back(); HardwareState* hs = &tail->state_; for (size_t i = 0; i < hs->finger_cnt; i++) { FingerState* fs = &hs->fingers[i]; @@ -156,11 +161,11 @@ void LookaheadFilterInterpreter::AssignTrackingIds() { return; } - QState* tail = queue_.Tail(); + auto tail = queue_.at(-1); HardwareState* hs = &tail->state_; - QState* prev_qs = queue_.size() < 2 ? NULL : tail->prev_; + QState* prev_qs = queue_.size() < 2 ? NULL : queue_.at(-2); HardwareState* prev_hs = prev_qs ? &prev_qs->state_ : NULL; - QState* prev2_qs = queue_.size() < 3 ? NULL : prev_qs->prev_; + QState* prev2_qs = queue_.size() < 3 ? NULL : queue_.at(-3); HardwareState* prev2_hs = prev2_qs ? &prev2_qs->state_ : NULL; RemoveMissingIdsFromMap(&tail->output_ids_, *hs); @@ -356,11 +361,12 @@ void LookaheadFilterInterpreter::TapDownOccurringGesture(stime_t now) { return; if (queue_.size() < 2) return; // Not enough data to know - HardwareState& hs = queue_.Tail()->state_; - if (queue_.Tail()->state_.timestamp != now) + HardwareState& hs = queue_.back()->state_; + if (queue_.back()->state_.timestamp != now) return; // We didn't push a new hardware state now - // See if latest hwstate has finger that previous doesn't - HardwareState& prev_hs = queue_.Tail()->prev_->state_; + // See if latest hwstate has finger that previous doesn't. + // Get the state_ of back->prev + HardwareState& prev_hs = queue_.at(-2)->state_; if (hs.finger_cnt > prev_hs.finger_cnt) { // Finger was added. ProduceGesture(Gesture(kGestureFling, prev_hs.timestamp, hs.timestamp, @@ -396,18 +402,20 @@ short LookaheadFilterInterpreter::NextTrackingId() { void LookaheadFilterInterpreter::AttemptInterpolation() { if (queue_.size() < 2) return; - QState* new_node = queue_.Tail(); - QState* prev = new_node->prev_; + QState* new_node = queue_.at(-1); + QState* prev = queue_.at(-2); if (new_node->state_.timestamp - prev->state_.timestamp < - split_min_period_.val_) + split_min_period_.val_) { return; // Nodes came in too quickly to need interpolation + } if (!prev->state_.SameFingersAs(new_node->state_)) return; - QState* node = free_list_.PopFront(); - if (!node) { + if (free_list_.empty()) { Err("out of nodes?"); return; } + QState* node = free_list_.back(); + free_list_.pop_back(); node->state_.fingers = node->fs_.get(); node->completed_ = false; Interpolate(prev->state_, new_node->state_, &node->state_); @@ -418,11 +426,10 @@ void LookaheadFilterInterpreter::AttemptInterpolation() { if (node->state_.timestamp <= last_interpreted_time_) { // Time wouldn't seem monotonically increasing w/ this new event, so // discard it. - free_list_.PushBack(node); - return; + free_list_.push_back(node); + } else { + queue_.insert(--queue_.end(), node); } - - queue_.InsertBefore(new_node, node); } void LookaheadFilterInterpreter::HandleTimerImpl(stime_t now, @@ -440,12 +447,16 @@ void LookaheadFilterInterpreter::HandleTimerImpl(stime_t now, last_interpreted_time_ = now; next_->HandleTimer(now, &next_timeout); } else { - if (queue_.Empty()) + if (queue_.empty()) break; // Get next uncompleted and overdue hwstate - QState* node = queue_.Head(); - while (node != queue_.Tail() && node->completed_) - node = node->next_; + auto node = queue_.back(); + for (auto state : queue_) { + if (!state->completed_) { + node = state; + break; + } + } if (node->completed_ || node->due_ > now) break; next_timeout = NO_DEADLINE; @@ -471,8 +482,10 @@ void LookaheadFilterInterpreter::HandleTimerImpl(stime_t now, next_->SyncInterpret(&hs_copy, &next_timeout); // Clear previously completed nodes, but keep at least two nodes. - while (queue_.size() > 2 && queue_.Head()->completed_) - free_list_.PushBack(queue_.PopFront()); + while (queue_.size() > 2 && queue_.front()->completed_) { + free_list_.push_back(queue_.front()); + queue_.pop_front(); + } // Mark current node completed. This should be the only completed // node in the queue. @@ -489,7 +502,7 @@ void LookaheadFilterInterpreter::HandleTimerImpl(stime_t now, } void LookaheadFilterInterpreter::ConsumeGesture(const Gesture& gesture) { - QState* node = queue_.Head(); + QState* node = queue_.front(); float distance_sq = 0.0; // Slow movements should potentially be suppressed @@ -516,10 +529,11 @@ void LookaheadFilterInterpreter::ConsumeGesture(const Gesture& gesture) { return; } // Speed is slow. Suppress if fingers have changed. - for (QState* iter = node->next_; iter != queue_.End(); iter = iter->next_) - if (!node->state_.SameFingersAs(iter->state_) || - (node->state_.buttons_down != iter->state_.buttons_down)) + for (auto iter = ++queue_.begin(); iter != queue_.end(); ++iter) { + if (!node->state_.SameFingersAs((*iter)->state_) || + (node->state_.buttons_down != (*iter)->state_.buttons_down)) return; // suppress + } ProduceGesture(gesture); } @@ -532,11 +546,10 @@ void LookaheadFilterInterpreter::UpdateInterpreterDue( // timeout, so we use -DBL_MAX as the invalid value. stime_t next_hwstate_timeout = -DBL_MAX; // Scan queue_ to find when next hwstate is due. - for (QState* node = queue_.Begin(); node != queue_.End(); - node = node->next_) { - if (node->completed_) + for (auto elem : queue_) { + if (elem->completed_) continue; - next_hwstate_timeout = node->due_ - now; + next_hwstate_timeout = elem->due_ - now; break; } @@ -557,12 +570,11 @@ void LookaheadFilterInterpreter::Initialize( MetricsProperties* mprops, GestureConsumer* consumer) { FilterInterpreter::Initialize(hwprops, NULL, mprops, consumer); - const size_t kMaxQNodes = 16; - queue_.DeleteAll(); - free_list_.DeleteAll(); + queue_.clear(); + free_list_.clear(); for (size_t i = 0; i < kMaxQNodes; ++i) { QState* node = new QState(hwprops_->max_finger_cnt); - free_list_.PushBack(node); + free_list_.push_back(node); } } @@ -603,4 +615,25 @@ void LookaheadFilterInterpreter::QState::set_state( state_.msc_timestamp = new_state.msc_timestamp; } +LookaheadFilterInterpreter::QState* +LookaheadFilterInterpreter::QStateList::at(int offset) { + // Traverse to the appropriate offset + if (offset < 0) { + // negative offset is from end to begin + auto count = size(); + for (auto iter = --end(); count > 0; --count, --iter) { + if (++offset == 0) + return *iter; + } + } else { + // positive offset is from begin to end + for (auto elem : *this) { + if (offset-- == 0) + return elem; + } + } + // invalid offset returns NULL + return nullptr; +} + } // namespace gestures diff --git a/src/lookahead_filter_interpreter_unittest.cc b/src/lookahead_filter_interpreter_unittest.cc index 788d785..1c84eb4 100644 --- a/src/lookahead_filter_interpreter_unittest.cc +++ b/src/lookahead_filter_interpreter_unittest.cc @@ -788,42 +788,42 @@ TEST(LookaheadFilterInterpreterTest, QuickMoveTest) { wrapper.Reset(interpreter.get()); stime_t timeout = NO_DEADLINE; - List<LookaheadFilterInterpreter::QState>* queue = &interpreter->queue_; + const auto& queue = interpreter->queue_; // Pushing the first event wrapper.SyncInterpret(&hs[0], &timeout); - EXPECT_EQ(queue->size(), 1); - EXPECT_EQ(queue->Tail()->fs_[0].tracking_id, 1); + EXPECT_EQ(queue.size(), 1); + EXPECT_EQ(queue.back()->fs_[0].tracking_id, 1); // Expecting Drumroll detected and ID reassigned 1 -> 2. wrapper.SyncInterpret(&hs[1], &timeout); - EXPECT_EQ(queue->size(), 2); - EXPECT_EQ(queue->Tail()->fs_[0].tracking_id, 2); + EXPECT_EQ(queue.size(), 2); + EXPECT_EQ(queue.back()->fs_[0].tracking_id, 2); // Expecting Drumroll detected and ID reassigned 1 -> 3. wrapper.SyncInterpret(&hs[2], &timeout); - EXPECT_EQ(queue->size(), 3); - EXPECT_EQ(queue->Tail()->fs_[0].tracking_id, 3); + EXPECT_EQ(queue.size(), 3); + EXPECT_EQ(queue.back()->fs_[0].tracking_id, 3); // Removing the touch. wrapper.SyncInterpret(&hs[3], &timeout); - EXPECT_EQ(queue->size(), 4); + EXPECT_EQ(queue.size(), 4); // New event comes, old events removed from the queue. // New finger tracking ID assigned 2 - > 4. wrapper.SyncInterpret(&hs[4], &timeout); - EXPECT_EQ(queue->size(), 2); - EXPECT_EQ(queue->Tail()->fs_[0].tracking_id, 4); + EXPECT_EQ(queue.size(), 2); + EXPECT_EQ(queue.back()->fs_[0].tracking_id, 4); // Expecting Drumroll detected and ID reassigned 2 -> 5. wrapper.SyncInterpret(&hs[5], &timeout); - EXPECT_EQ(queue->Tail()->fs_[0].tracking_id, 5); + EXPECT_EQ(queue.back()->fs_[0].tracking_id, 5); // Expecting Quick movement detected and ID correction 5 -> 4. wrapper.SyncInterpret(&hs[6], &timeout); - EXPECT_EQ(queue->Tail()->fs_[0].tracking_id, 4); - EXPECT_EQ(queue->Tail()->prev_->fs_[0].tracking_id, 4); - EXPECT_EQ(queue->Tail()->prev_->prev_->fs_[0].tracking_id, 4); + EXPECT_EQ(interpreter->queue_.at(-1)->fs_[0].tracking_id, 4); + EXPECT_EQ(interpreter->queue_.at(-2)->fs_[0].tracking_id, 4); + EXPECT_EQ(interpreter->queue_.at(-3)->fs_[0].tracking_id, 4); } struct QuickSwipeTestInputs { @@ -1263,16 +1263,79 @@ TEST(LookaheadFilterInterpreterTest, SemiMtNoTrackingIdAssignmentTest) { wrapper.Reset(interpreter.get()); stime_t timeout = NO_DEADLINE; - List<LookaheadFilterInterpreter::QState>* queue = &interpreter->queue_; + const auto& queue = interpreter->queue_; wrapper.SyncInterpret(&hs[0], &timeout); - EXPECT_EQ(queue->Tail()->fs_[0].tracking_id, 20); + EXPECT_EQ(queue.back()->fs_[0].tracking_id, 20); // Test if the fingers in queue have the same tracking ids from input. for (size_t i = 1; i < arraysize(hs); i++) { wrapper.SyncInterpret(&hs[i], &timeout); - EXPECT_EQ(queue->Tail()->fs_[0].tracking_id, 20); // the same input id - EXPECT_EQ(queue->Tail()->fs_[1].tracking_id, 21); + EXPECT_EQ(queue.back()->fs_[0].tracking_id, 20); // the same input id + EXPECT_EQ(queue.back()->fs_[1].tracking_id, 21); } } + +TEST(LookaheadFilterInterpreterTest, QStateListTest) { + LookaheadFilterInterpreterTestInterpreter* base_interpreter = NULL; + std::unique_ptr<LookaheadFilterInterpreter> interpreter; + + HardwareProperties hwprops = { + 0, 0, 100, 100, // left, top, right, bottom + 1, // x res (pixels/mm) + 1, // y res (pixels/mm) + 25, 25, // scrn DPI X, Y + -1, // orientation minimum + 2, // orientation maximum + 2, 5, // max fingers, max_touch + 1, 1, 0, // t5r2, semi, button pad + 0, 0, // has wheel, vertical wheel is high resolution + 0, // haptic pad + }; + TestInterpreterWrapper wrapper(interpreter.get(), &hwprops); + + base_interpreter = new LookaheadFilterInterpreterTestInterpreter; + interpreter.reset(new LookaheadFilterInterpreter( + NULL, base_interpreter, NULL)); + wrapper.Reset(interpreter.get()); + + auto& queue = interpreter->queue_; + auto& free_list = interpreter->free_list_; + + // Release all of the QStates + while (!queue.empty()) { + free_list.push_back(queue.front()); + queue.pop_front(); + } + EXPECT_EQ(queue.size(), 0); + EXPECT_EQ(free_list.size(), 16); + + EXPECT_EQ(queue.at(-1), nullptr); + EXPECT_EQ(queue.at(queue.size()), nullptr); + + // fill up the QStates + while (!free_list.empty()) { + queue.push_front(free_list.back()); + free_list.pop_back(); + } + EXPECT_EQ(queue.size(), 16); + EXPECT_EQ(free_list.size(), 0); + + EXPECT_NE(queue.at(-1), nullptr); + EXPECT_EQ(queue.at(-1), queue.at(queue.size() - 1)); + + EXPECT_EQ(queue.at(queue.size()), nullptr); + + for (int i = 0; i < 16; ++i) { + for (int j = 0; j < 16; ++j) { + if (i == j) { + EXPECT_EQ(queue.at(i), queue.at(j)); + } else { + EXPECT_NE(queue.at(i), queue.at(j)); + } + } + } + + LookaheadFilterInterpreter::QState qs; +} } // namespace gestures diff --git a/src/metrics_filter_interpreter.cc b/src/metrics_filter_interpreter.cc index e608f23..de6ca33 100644 --- a/src/metrics_filter_interpreter.cc +++ b/src/metrics_filter_interpreter.cc @@ -142,7 +142,7 @@ void MetricsFilterInterpreter::UpdateFingerState( RemoveMissingIdsFromMap(&histories_, hwstate, &removed); for (FingerHistoryMap::const_iterator it = removed.begin(); it != removed.end(); ++it) { - it->second->DeleteAll(); + it->second->clear(); history_mm_.Free(it->second); } @@ -171,14 +171,15 @@ void MetricsFilterInterpreter::UpdateFingerState( bool MetricsFilterInterpreter::DetectNoisyGround( const FingerHistory* history) { - MState* current = history->Tail(); + auto iter = history->end(); + MState* current = *(--iter); size_t n_samples = history->size(); // Noise pattern takes 3 samples if (n_samples < 3) return false; - MState* past_1 = current->prev_; - MState* past_2 = past_1->prev_; + MState* past_1 = *(--iter); + MState* past_2 = *(--iter); // Noise pattern needs to happen in a short period of time if(current->timestamp - past_2->timestamp > noisy_ground_time_threshold_.val_) { diff --git a/src/mouse_interpreter.cc b/src/mouse_interpreter.cc index b26de8f..f3055b3 100644 --- a/src/mouse_interpreter.cc +++ b/src/mouse_interpreter.cc @@ -29,8 +29,7 @@ MouseInterpreter::MouseInterpreter(PropRegistry* prop_reg, Tracer* tracer) scroll_accel_curve_, sizeof(scroll_accel_curve_) / sizeof(double)), scroll_max_allowed_input_speed_(prop_reg, "Mouse Scroll Max Input Speed", - 177.0, - this), + 177.0), force_scroll_wheel_emulation_(prop_reg, "Force Scroll Wheel Emulation", false), @@ -53,6 +52,7 @@ MouseInterpreter::MouseInterpreter(PropRegistry* prop_reg, Tracer* tracer) scroll_accel_curve_[2] = 2.5737e-02; scroll_accel_curve_[3] = 8.0428e-05; scroll_accel_curve_[4] = -9.1149e-07; + scroll_max_allowed_input_speed_.SetDelegate(this); } void MouseInterpreter::SyncInterpretImpl(HardwareState* hwstate, diff --git a/src/prop_registry.cc b/src/prop_registry.cc index 58e3a1a..2d9d454 100644 --- a/src/prop_registry.cc +++ b/src/prop_registry.cc @@ -70,18 +70,6 @@ void Property::DestroyProp() { gprop_ = NULL; } -void Property::SetDelegate(PropertyDelegate* delegate) { - bool delegate_was_late_set = !delegate_ && delegate; - delegate_ = delegate; - // In the normal path of creation of a property with a parent, the - // delegate is set late and the CreatePropImpl will not call the - // WasWritten method. So catch the transition from NULL to not - // NULL in this condition and make sure to call the initial - // WasWritten to mimick the original code. - if (delegate_was_late_set && parent_ && parent_->PropProvider()) - HandleGesturesPropWritten(); -} - void BoolProperty::CreatePropImpl() { GesturesPropBool orig_val = val_; gprop_ = parent_->PropProvider()->create_bool_fn( diff --git a/src/prop_registry_unittest.cc b/src/prop_registry_unittest.cc index 23ba9d8..503a552 100644 --- a/src/prop_registry_unittest.cc +++ b/src/prop_registry_unittest.cc @@ -48,7 +48,8 @@ TEST(PropRegistryTest, SimpleTest) { PropRegistryTestDelegate delegate; int expected_call_cnt = 0; - BoolProperty bp1(®, "hi", false, &delegate); + BoolProperty bp1(®, "hi", false); + bp1.SetDelegate(&delegate); EXPECT_TRUE(strstr(ValueForProperty(bp1).c_str(), "false")); bp1.HandleGesturesPropWritten(); EXPECT_EQ(++expected_call_cnt, delegate.call_cnt_); @@ -58,7 +59,8 @@ TEST(PropRegistryTest, SimpleTest) { bp2.HandleGesturesPropWritten(); EXPECT_EQ(expected_call_cnt, delegate.call_cnt_); - DoubleProperty dp1(®, "hi", 2721.0, &delegate); + DoubleProperty dp1(®, "hi", 2721.0); + dp1.SetDelegate(&delegate); EXPECT_TRUE(strstr(ValueForProperty(dp1).c_str(), "2721")); dp1.HandleGesturesPropWritten(); EXPECT_EQ(++expected_call_cnt, delegate.call_cnt_); @@ -68,7 +70,8 @@ TEST(PropRegistryTest, SimpleTest) { dp2.HandleGesturesPropWritten(); EXPECT_EQ(expected_call_cnt, delegate.call_cnt_); - IntProperty ip1(®, "hi", 567, &delegate); + IntProperty ip1(®, "hi", 567); + ip1.SetDelegate(&delegate); EXPECT_TRUE(strstr(ValueForProperty(ip1).c_str(), "567")); ip1.HandleGesturesPropWritten(); EXPECT_EQ(++expected_call_cnt, delegate.call_cnt_); @@ -78,7 +81,8 @@ TEST(PropRegistryTest, SimpleTest) { ip2.HandleGesturesPropWritten(); EXPECT_EQ(expected_call_cnt, delegate.call_cnt_); - StringProperty stp1(®, "hi", "foo", &delegate); + StringProperty stp1(®, "hi", "foo"); + stp1.SetDelegate(&delegate); EXPECT_TRUE(strstr(ValueForProperty(stp1).c_str(), "foo")); stp1.HandleGesturesPropWritten(); EXPECT_EQ(++expected_call_cnt, delegate.call_cnt_); @@ -194,29 +198,31 @@ TEST(PropRegistryTest, SetAtCreateShouldNotifyTest) { PropRegistry reg; PropRegistryTestDelegate delegate; - BoolProperty my_bool(®, "MyBool", 0, &delegate); - DoubleProperty my_double(®, "MyDouble", 0.0, &delegate); - IntProperty my_int(®, "MyInt", 0, &delegate); - IntProperty my_int_no_change(®, "MyIntNoChange", 1, &delegate); - StringProperty my_string(®, "MyString", "mine", &delegate); + BoolProperty my_bool(®, "MyBool", 0); + my_bool.SetDelegate(&delegate); + DoubleProperty my_double(®, "MyDouble", 0.0); + my_double.SetDelegate(&delegate); + IntProperty my_int(®, "MyInt", 0); + my_int.SetDelegate(&delegate); + IntProperty my_int_no_change(®, "MyIntNoChange", 1); + my_int_no_change.SetDelegate(&delegate); + StringProperty my_string(®, "MyString", "mine"); + my_string.SetDelegate(&delegate); EXPECT_EQ(0, delegate.call_cnt_); reg.SetPropProvider(&mock_gestures_props_provider, NULL); EXPECT_EQ(4, delegate.call_cnt_); - - BoolProperty my_bool2(®, "MyBool2", 1); - EXPECT_EQ(4, delegate.call_cnt_); - my_bool2.SetDelegate(&delegate); - EXPECT_EQ(5, delegate.call_cnt_); } TEST(PropRegistryTest, DoublePromoteIntTest) { PropRegistry reg; PropRegistryTestDelegate delegate; - DoubleProperty my_double(®, "MyDouble", 1234.5, &delegate); + DoubleProperty my_double(®, "MyDouble", 1234.5); + my_double.SetDelegate(&delegate); EXPECT_TRUE(strstr(ValueForProperty(my_double).c_str(), "1234.5")); - IntProperty my_int(®, "MyInt", 321, &delegate); + IntProperty my_int(®, "MyInt", 321); + my_int.SetDelegate(&delegate); Json::Value my_int_val = my_int.NewValue(); EXPECT_TRUE(my_double.SetValue(my_int_val)); EXPECT_TRUE(strstr(ValueForProperty(my_double).c_str(), "321")); @@ -229,15 +235,18 @@ TEST(PropRegistryTest, BoolArrayTest) { GesturesPropBool vals[] = { false, true }; BoolArrayProperty my_bool_array_w_delegate( - ®, "MyBoolArray", vals, 2, &delegate); + ®, "MyBoolArray", vals, 2); + my_bool_array_w_delegate.SetDelegate(&delegate); EXPECT_EQ(0, delegate.call_cnt_); my_bool_array_w_delegate.HandleGesturesPropWritten(); EXPECT_EQ(1, delegate.call_cnt_); delegate.BoolArrayWasWritten(&my_bool_array_w_delegate); EXPECT_EQ(2, delegate.call_cnt_); - IntProperty ip1(®, "hi", 567, &delegate); - StringProperty stp1(®, "hi", "foo", &delegate); + IntProperty ip1(®, "hi", 567); + ip1.SetDelegate(&delegate); + StringProperty stp1(®, "hi", "foo"); + stp1.SetDelegate(&delegate); Json::Value my_bool_array_val = my_bool_array_w_delegate.NewValue(); Json::Value my_int_val = ip1.NewValue(); Json::Value my_str_val = stp1.NewValue(); @@ -261,15 +270,18 @@ TEST(PropRegistryTest, DoubleArrayTest) { double vals[] = { 0.0, 1.0 }; DoubleArrayProperty my_double_array_w_delegate( - ®, "MyDoubleArray", vals, 2, &delegate); + ®, "MyDoubleArray", vals, 2); + my_double_array_w_delegate.SetDelegate(&delegate); EXPECT_EQ(0, delegate.call_cnt_); my_double_array_w_delegate.HandleGesturesPropWritten(); EXPECT_EQ(1, delegate.call_cnt_); delegate.DoubleArrayWasWritten(&my_double_array_w_delegate); EXPECT_EQ(2, delegate.call_cnt_); - IntProperty ip1(®, "hi", 567, &delegate); - StringProperty stp1(®, "hi", "foo", &delegate); + IntProperty ip1(®, "hi", 567); + ip1.SetDelegate(&delegate); + StringProperty stp1(®, "hi", "foo"); + stp1.SetDelegate(&delegate); Json::Value my_double_array_val = my_double_array_w_delegate.NewValue(); Json::Value my_int_val = ip1.NewValue(); Json::Value my_str_val = stp1.NewValue(); @@ -293,15 +305,18 @@ TEST(PropRegistryTest, IntArrayTest) { int vals[] = { 0, 1 }; IntArrayProperty my_int_array_w_delegate( - ®, "MyIntArray", vals, 2, &delegate); + ®, "MyIntArray", vals, 2); + my_int_array_w_delegate.SetDelegate(&delegate); EXPECT_EQ(0, delegate.call_cnt_); my_int_array_w_delegate.HandleGesturesPropWritten(); EXPECT_EQ(1, delegate.call_cnt_); delegate.IntArrayWasWritten(&my_int_array_w_delegate); EXPECT_EQ(2, delegate.call_cnt_); - IntProperty ip1(®, "hi", 567, &delegate); - StringProperty stp1(®, "hi", "foo", &delegate); + IntProperty ip1(®, "hi", 567); + ip1.SetDelegate(&delegate); + StringProperty stp1(®, "hi", "foo"); + stp1.SetDelegate(&delegate); Json::Value my_int_array_val = my_int_array_w_delegate.NewValue(); Json::Value my_int_val = ip1.NewValue(); Json::Value my_str_val = stp1.NewValue(); diff --git a/src/scaling_filter_interpreter.cc b/src/scaling_filter_interpreter.cc index 1094455..2d2aad9 100644 --- a/src/scaling_filter_interpreter.cc +++ b/src/scaling_filter_interpreter.cc @@ -318,8 +318,13 @@ void ScalingFilterInterpreter::Initialize(const HardwareProperties* hwprops, Metrics* metrics, MetricsProperties* mprops, GestureConsumer* consumer) { - tp_x_scale_ = 1.0 / hwprops->res_x; - tp_y_scale_ = 1.0 / hwprops->res_y; + // If the touchpad doesn't specify its resolution in one or both axes, use a + // reasonable default instead. + float res_x = hwprops->res_x != 0 ? hwprops->res_x : 32; + float res_y = hwprops->res_y != 0 ? hwprops->res_y : 32; + + tp_x_scale_ = 1.0 / res_x; + tp_y_scale_ = 1.0 / res_y; tp_x_translate_ = -1.0 * (hwprops->left * tp_x_scale_); tp_y_translate_ = -1.0 * (hwprops->top * tp_y_scale_); diff --git a/src/scaling_filter_interpreter_unittest.cc b/src/scaling_filter_interpreter_unittest.cc index d701c7f..93f8e79 100644 --- a/src/scaling_filter_interpreter_unittest.cc +++ b/src/scaling_filter_interpreter_unittest.cc @@ -68,7 +68,7 @@ class ScalingFilterInterpreterTestInterpreter : public Interpreter { EXPECT_FLOAT_EQ(expected_pressures_.front(), hwstate->fingers[0].pressure); expected_pressures_.pop_front(); - } else { + } else if (!expected_finger_cnt_.empty() && !expected_touch_cnt_.empty()) { // Test if the low pressure event is dropped EXPECT_EQ(expected_finger_cnt_.front(), hwstate->finger_cnt); expected_finger_cnt_.pop_front(); @@ -272,6 +272,47 @@ TEST(ScalingFilterInterpreterTest, SimpleTest) { out = wrapper.SyncInterpret(&hs2[2], NULL); } +TEST(ScalingFilterInterpreterTest, ResolutionFallback) { + ScalingFilterInterpreterTestInterpreter* base_interpreter = + new ScalingFilterInterpreterTestInterpreter; + ScalingFilterInterpreter interpreter(NULL, base_interpreter, NULL, + GESTURES_DEVCLASS_TOUCHPAD); + HardwareProperties initial_hwprops = { + 0, 0, 2000, 1000, // left, top, right, bottom + 0, 0, // X/Y resolutions (pixels/mm) + 0, 0, // screen DPI X, Y (deprecated) + -1, // orientation minimum + 2, // orientation maximum + 2, 5, // max fingers, max_touch + 0, 0, 0, // t5r2, semi, button pad + 0, 0, // has wheel, vertical wheel is high resolution + 0, // haptic pad + }; + HardwareProperties expected_hwprops = { + 0, 0, 2000 / 32.0, 1000 / 32.0, // left, top, right, bottom + 1, 1, // X/Y resolutions (pixels/mm) + 25.4, 25.4, // x DPI, y DPI + -M_PI_4, // orientation minimum (1 tick above X-axis) + M_PI_2, // orientation maximum + 2, 5, 0, 0, 0, // max_fingers, max_touch, t5r2, semi_mt, is button pad + 0, 0, // has wheel, vertical wheel is high resolution + 0, // is haptic pad + }; + base_interpreter->expected_hwprops_ = expected_hwprops; + + TestInterpreterWrapper wrapper(&interpreter, &initial_hwprops); + EXPECT_TRUE(base_interpreter->initialize_called_); + + FingerState fs = { 1, 0, 0, 0, 1, 0, 1000, 500, 1, 0 }; + HardwareState hs = make_hwstate(10000, 0, 1, 1, &fs); + + base_interpreter->expected_coordinates_.push_back( + std::vector<pair<float, float>>(1, make_pair( + static_cast<float>(1000 / 32.0), static_cast<float>(500 / 32.0)))); + + wrapper.SyncInterpret(&hs, NULL); +} + static void RunTouchMajorAndMinorTest( ScalingFilterInterpreterTestInterpreter* base_interpreter, ScalingFilterInterpreter* interpreter, diff --git a/src/trend_classifying_filter_interpreter.cc b/src/trend_classifying_filter_interpreter.cc index 45699a9..d6ddd21 100644 --- a/src/trend_classifying_filter_interpreter.cc +++ b/src/trend_classifying_filter_interpreter.cc @@ -78,7 +78,7 @@ void TrendClassifyingFilterInterpreter::AddNewStateToBuffer( history->DeleteFront(); // Push the new finger state to the back of buffer - KState* previous_end = history->Tail(); + KState* previous_end = history->back(); KState* current = history->PushNewEltBack(); if (!current) { Err("KState buffer out of space"); @@ -94,10 +94,10 @@ void TrendClassifyingFilterInterpreter::AddNewStateToBuffer( // 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 (KState* it = history->Begin(); it != history->Tail(); it = it->next_) + 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(); @@ -136,7 +136,7 @@ void TrendClassifyingFilterInterpreter::UpdateFingerState( RemoveMissingIdsFromMap(&histories_, hwstate, &removed); for (FingerHistoryMap::const_iterator it = removed.begin(); it != removed.end(); ++it) { - it->second->DeleteAll(); + it->second->clear(); history_mm_.Free(it->second); } @@ -159,7 +159,7 @@ void TrendClassifyingFilterInterpreter::UpdateFingerState( // Check if the score demonstrates statistical significance AddNewStateToBuffer(hp, fs[i]); - KState* current = hp->Tail(); + KState* current = hp->back(); size_t n_samples = hp->size(); for (size_t idx = 0; idx < KState::n_axes_; idx++) if (second_order_enable_.val_ || !KState::IsDelta(idx)) { diff --git a/tools/local_coverage_rate.sh b/tools/local_coverage_rate.sh index 710d91c..d1f9fff 100755 --- a/tools/local_coverage_rate.sh +++ b/tools/local_coverage_rate.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (c) 2011 The Chromium OS Authors. All rights reserved. +# Copyright 2011 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tools/regression_test.sh b/tools/regression_test.sh index db7535b..f97118a 100755 --- a/tools/regression_test.sh +++ b/tools/regression_test.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (c) 2012 The Chromium OS Authors. All rights reserved. +# Copyright 2012 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tools/replay_log b/tools/replay_log index bfdca70..76ddbbd 100755 --- a/tools/replay_log +++ b/tools/replay_log @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright (c) 2012 The Chromium OS Authors. All rights reserved. +# Copyright 2012 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tools/tplog.py b/tools/tplog.py index b2a685f..3ede9b7 100755 --- a/tools/tplog.py +++ b/tools/tplog.py @@ -1,6 +1,6 @@ #!/usr/bin/python # -# Copyright (c) 2012 The Chromium OS Authors. All rights reserved. +# Copyright 2012 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. |