diff options
author | 2022-01-13 01:24:14 -0800 | |
---|---|---|
committer | 2022-01-13 01:52:37 -0800 | |
commit | 6dbd0ce22d86e487b000d4eac75af35c1ffec58e (patch) | |
tree | 6b67a592ebd2ff3d7ab81ad09de6be273d7ab46b | |
parent | 08843dfa88678ab317a4f2515f716e8e21c0f349 (diff) |
Use std::vector in Input.h
Convert old code from android's Vector to std::vector.
Bug: 167946763
Test: atest libinput_tests
Change-Id: I5c53583f6f1e5d577882d94d356f23bdd516be1e
-rw-r--r-- | include/input/Input.h | 12 | ||||
-rw-r--r-- | libs/input/Input.cpp | 33 | ||||
-rw-r--r-- | services/inputflinger/InputClassifier.cpp | 2 | ||||
-rw-r--r-- | services/inputflinger/InputManager.h | 1 |
4 files changed, 23 insertions, 25 deletions
diff --git a/include/input/Input.h b/include/input/Input.h index ddff144954..f4147a0409 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -31,10 +31,8 @@ #include <stdint.h> #include <ui/Transform.h> #include <utils/BitSet.h> -#include <utils/KeyedVector.h> #include <utils/RefBase.h> #include <utils/Timers.h> -#include <utils/Vector.h> #include <array> #include <limits> #include <queue> @@ -88,7 +86,7 @@ enum { */ AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE = 0x40, -#ifdef __linux__ +#if defined(__linux__) /** * This event was generated or modified by accessibility service. */ @@ -799,11 +797,11 @@ public: // Low-level accessors. inline const PointerProperties* getPointerProperties() const { - return mPointerProperties.array(); + return mPointerProperties.data(); } inline const nsecs_t* getSampleEventTimes() const { return mSampleEventTimes.data(); } inline const PointerCoords* getSamplePointerCoords() const { - return mSamplePointerCoords.array(); + return mSamplePointerCoords.data(); } static const char* getLabel(int32_t axis); @@ -834,9 +832,9 @@ protected: float mRawYCursorPosition; ui::Transform mRawTransform; nsecs_t mDownTime; - Vector<PointerProperties> mPointerProperties; + std::vector<PointerProperties> mPointerProperties; std::vector<nsecs_t> mSampleEventTimes; - Vector<PointerCoords> mSamplePointerCoords; + std::vector<PointerCoords> mSamplePointerCoords; }; /* diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 84dba84e2b..3073d94dbe 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -456,7 +456,8 @@ void MotionEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, int3 mRawTransform = rawTransform; mDownTime = downTime; mPointerProperties.clear(); - mPointerProperties.appendArray(pointerProperties, pointerCount); + mPointerProperties.insert(mPointerProperties.end(), &pointerProperties[0], + &pointerProperties[pointerCount]); mSampleEventTimes.clear(); mSamplePointerCoords.clear(); addSample(eventTime, pointerCoords); @@ -490,8 +491,10 @@ void MotionEvent::copyFrom(const MotionEvent* other, bool keepHistory) { mSamplePointerCoords.clear(); size_t pointerCount = other->getPointerCount(); size_t historySize = other->getHistorySize(); - mSamplePointerCoords.appendArray(other->mSamplePointerCoords.array() - + (historySize * pointerCount), pointerCount); + mSamplePointerCoords + .insert(mSamplePointerCoords.end(), + &other->mSamplePointerCoords[historySize * pointerCount], + &other->mSamplePointerCoords[historySize * pointerCount + pointerCount]); } } @@ -499,7 +502,8 @@ void MotionEvent::addSample( int64_t eventTime, const PointerCoords* pointerCoords) { mSampleEventTimes.push_back(eventTime); - mSamplePointerCoords.appendArray(pointerCoords, getPointerCount()); + mSamplePointerCoords.insert(mSamplePointerCoords.end(), &pointerCoords[0], + &pointerCoords[getPointerCount()]); } int MotionEvent::getSurfaceRotation() const { @@ -569,7 +573,7 @@ float MotionEvent::getHistoricalAxisValue(int32_t axis, size_t pointerIndex, ssize_t MotionEvent::findPointerIndex(int32_t pointerId) const { size_t pointerCount = mPointerProperties.size(); for (size_t i = 0; i < pointerCount; i++) { - if (mPointerProperties.itemAt(i).id == pointerId) { + if (mPointerProperties[i].id == pointerId) { return i; } } @@ -591,8 +595,7 @@ void MotionEvent::scale(float globalScaleFactor) { size_t numSamples = mSamplePointerCoords.size(); for (size_t i = 0; i < numSamples; i++) { - mSamplePointerCoords.editItemAt(i).scale(globalScaleFactor, globalScaleFactor, - globalScaleFactor); + mSamplePointerCoords[i].scale(globalScaleFactor, globalScaleFactor, globalScaleFactor); } } @@ -686,15 +689,15 @@ status_t MotionEvent::readFromParcel(Parcel* parcel) { mDownTime = parcel->readInt64(); mPointerProperties.clear(); - mPointerProperties.setCapacity(pointerCount); + mPointerProperties.reserve(pointerCount); mSampleEventTimes.clear(); mSampleEventTimes.reserve(sampleCount); mSamplePointerCoords.clear(); - mSamplePointerCoords.setCapacity(sampleCount * pointerCount); + mSamplePointerCoords.reserve(sampleCount * pointerCount); for (size_t i = 0; i < pointerCount; i++) { - mPointerProperties.push(); - PointerProperties& properties = mPointerProperties.editTop(); + mPointerProperties.push_back({}); + PointerProperties& properties = mPointerProperties.back(); properties.id = parcel->readInt32(); properties.toolType = parcel->readInt32(); } @@ -703,8 +706,8 @@ status_t MotionEvent::readFromParcel(Parcel* parcel) { sampleCount--; mSampleEventTimes.push_back(parcel->readInt64()); for (size_t i = 0; i < pointerCount; i++) { - mSamplePointerCoords.push(); - status_t status = mSamplePointerCoords.editTop().readFromParcel(parcel); + mSamplePointerCoords.push_back({}); + status_t status = mSamplePointerCoords.back().readFromParcel(parcel); if (status) { return status; } @@ -750,12 +753,12 @@ status_t MotionEvent::writeToParcel(Parcel* parcel) const { parcel->writeInt64(mDownTime); for (size_t i = 0; i < pointerCount; i++) { - const PointerProperties& properties = mPointerProperties.itemAt(i); + const PointerProperties& properties = mPointerProperties[i]; parcel->writeInt32(properties.id); parcel->writeInt32(properties.toolType); } - const PointerCoords* pc = mSamplePointerCoords.array(); + const PointerCoords* pc = mSamplePointerCoords.data(); for (size_t h = 0; h < sampleCount; h++) { parcel->writeInt64(mSampleEventTimes[h]); for (size_t i = 0; i < pointerCount; i++) { diff --git a/services/inputflinger/InputClassifier.cpp b/services/inputflinger/InputClassifier.cpp index 19cad7b9ad..6c4b11e0e5 100644 --- a/services/inputflinger/InputClassifier.cpp +++ b/services/inputflinger/InputClassifier.cpp @@ -29,8 +29,6 @@ #endif #include <unordered_set> -#include <android/hardware/input/classifier/1.0/IInputClassifier.h> - #define INDENT1 " " #define INDENT2 " " #define INDENT3 " " diff --git a/services/inputflinger/InputManager.h b/services/inputflinger/InputManager.h index a6baf2f56d..e00028364a 100644 --- a/services/inputflinger/InputManager.h +++ b/services/inputflinger/InputManager.h @@ -33,7 +33,6 @@ #include <utils/Errors.h> #include <utils/RefBase.h> #include <utils/Timers.h> -#include <utils/Vector.h> using android::os::BnInputFlinger; |