Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6dbd0ce2 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

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
parent 08843dfa
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -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;
};

/*
+18 −15
Original line number Diff line number Diff line
@@ -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++) {
+0 −2
Original line number Diff line number Diff line
@@ -29,8 +29,6 @@
#endif
#include <unordered_set>

#include <android/hardware/input/classifier/1.0/IInputClassifier.h>

#define INDENT1 "  "
#define INDENT2 "    "
#define INDENT3 "      "
+0 −1
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@
#include <utils/Errors.h>
#include <utils/RefBase.h>
#include <utils/Timers.h>
#include <utils/Vector.h>

using android::os::BnInputFlinger;