diff options
| author | 2019-10-29 13:05:57 -0700 | |
|---|---|---|
| committer | 2019-10-31 23:06:10 +0000 | |
| commit | 00fca7c4db1f24701b17b05321abb9701b695de4 (patch) | |
| tree | 91ff309356d2bc09247a18ff185892fdb97dec6a | |
| parent | dcc57af9e27cf5899510e4c9c38cb6170234cb1e (diff) | |
Return vector of cancellation events
Instead of passing a vector to a void function, return the vector from
the function to make ownership explicit.
In the future, we could return a vector of unique_ptr.
Bug: none
Test: none
Change-Id: I9e50e37fff53fd888149f8686c6671a93e4781b1
| -rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.cpp | 4 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/InputState.cpp | 39 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/InputState.h | 4 |
3 files changed, 24 insertions, 23 deletions
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index 9e5f5f7fb7..af671e613a 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -2493,8 +2493,8 @@ void InputDispatcher::synthesizeCancelationEventsForConnectionLocked( nsecs_t currentTime = now(); - std::vector<EventEntry*> cancelationEvents; - connection->inputState.synthesizeCancelationEvents(currentTime, cancelationEvents, options); + std::vector<EventEntry*> cancelationEvents = + connection->inputState.synthesizeCancelationEvents(currentTime, options); if (!cancelationEvents.empty()) { #if DEBUG_OUTBOUND_EVENT_DETAILS diff --git a/services/inputflinger/dispatcher/InputState.cpp b/services/inputflinger/dispatcher/InputState.cpp index 603c257c4d..c43e304758 100644 --- a/services/inputflinger/dispatcher/InputState.cpp +++ b/services/inputflinger/dispatcher/InputState.cpp @@ -249,17 +249,17 @@ void InputState::MotionMemento::setPointers(const MotionEntry& entry) { } } -void InputState::synthesizeCancelationEvents(nsecs_t currentTime, - std::vector<EventEntry*>& outEvents, - const CancelationOptions& options) { +std::vector<EventEntry*> InputState::synthesizeCancelationEvents( + nsecs_t currentTime, const CancelationOptions& options) { + std::vector<EventEntry*> events; for (KeyMemento& memento : mKeyMementos) { if (shouldCancelKey(memento, options)) { - outEvents.push_back(new KeyEntry(SYNTHESIZED_EVENT_SEQUENCE_NUM, currentTime, - memento.deviceId, memento.source, memento.displayId, - memento.policyFlags, AKEY_EVENT_ACTION_UP, - memento.flags | AKEY_EVENT_FLAG_CANCELED, - memento.keyCode, memento.scanCode, memento.metaState, - 0, memento.downTime)); + events.push_back(new KeyEntry(SYNTHESIZED_EVENT_SEQUENCE_NUM, currentTime, + memento.deviceId, memento.source, memento.displayId, + memento.policyFlags, AKEY_EVENT_ACTION_UP, + memento.flags | AKEY_EVENT_FLAG_CANCELED, memento.keyCode, + memento.scanCode, memento.metaState, 0 /*repeatCount*/, + memento.downTime)); } } @@ -267,18 +267,19 @@ void InputState::synthesizeCancelationEvents(nsecs_t currentTime, if (shouldCancelMotion(memento, options)) { const int32_t action = memento.hovering ? AMOTION_EVENT_ACTION_HOVER_EXIT : AMOTION_EVENT_ACTION_CANCEL; - outEvents.push_back( - new MotionEntry(SYNTHESIZED_EVENT_SEQUENCE_NUM, currentTime, memento.deviceId, - memento.source, memento.displayId, memento.policyFlags, action, - 0 /*actionButton*/, memento.flags, AMETA_NONE, - 0 /*buttonState*/, MotionClassification::NONE, - AMOTION_EVENT_EDGE_FLAG_NONE, memento.xPrecision, - memento.yPrecision, memento.xCursorPosition, - memento.yCursorPosition, memento.downTime, memento.pointerCount, - memento.pointerProperties, memento.pointerCoords, 0 /*xOffset*/, - 0 /*yOffset*/)); + events.push_back(new MotionEntry(SYNTHESIZED_EVENT_SEQUENCE_NUM, currentTime, + memento.deviceId, memento.source, memento.displayId, + memento.policyFlags, action, 0 /*actionButton*/, + memento.flags, AMETA_NONE, 0 /*buttonState*/, + MotionClassification::NONE, + AMOTION_EVENT_EDGE_FLAG_NONE, memento.xPrecision, + memento.yPrecision, memento.xCursorPosition, + memento.yCursorPosition, memento.downTime, + memento.pointerCount, memento.pointerProperties, + memento.pointerCoords, 0 /*xOffset*/, 0 /*yOffset*/)); } } + return events; } void InputState::clear() { diff --git a/services/inputflinger/dispatcher/InputState.h b/services/inputflinger/dispatcher/InputState.h index cc72152d04..a93f486596 100644 --- a/services/inputflinger/dispatcher/InputState.h +++ b/services/inputflinger/dispatcher/InputState.h @@ -49,8 +49,8 @@ public: bool trackMotion(const MotionEntry& entry, int32_t action, int32_t flags); // Synthesizes cancelation events for the current state and resets the tracked state. - void synthesizeCancelationEvents(nsecs_t currentTime, std::vector<EventEntry*>& outEvents, - const CancelationOptions& options); + std::vector<EventEntry*> synthesizeCancelationEvents(nsecs_t currentTime, + const CancelationOptions& options); // Clears the current state. void clear(); |