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

Commit d2ea0d59 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use std::vector instead of VLA for addMovement"

parents bb541072 ae0f9908
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ public:
    // are included in the movement.
    // The positions array contains position information for each pointer in order by
    // increasing id.  Its size should be equal to the number of one bits in idBits.
    void addMovement(nsecs_t eventTime, BitSet32 idBits, const Position* positions);
    void addMovement(nsecs_t eventTime, BitSet32 idBits, const std::vector<Position>& positions);

    // Adds movement information for all pointers in a MotionEvent, including historical samples.
    void addMovement(const MotionEvent* event);
@@ -149,7 +149,7 @@ public:
    virtual void clear() = 0;
    virtual void clearPointers(BitSet32 idBits) = 0;
    virtual void addMovement(nsecs_t eventTime, BitSet32 idBits,
            const VelocityTracker::Position* positions) = 0;
                             const std::vector<VelocityTracker::Position>& positions) = 0;
    virtual bool getEstimator(uint32_t id, VelocityTracker::Estimator* outEstimator) const = 0;
};

@@ -180,8 +180,8 @@ public:

    virtual void clear();
    virtual void clearPointers(BitSet32 idBits);
    virtual void addMovement(nsecs_t eventTime, BitSet32 idBits,
            const VelocityTracker::Position* positions);
    void addMovement(nsecs_t eventTime, BitSet32 idBits,
                     const std::vector<VelocityTracker::Position>& positions) override;
    virtual bool getEstimator(uint32_t id, VelocityTracker::Estimator* outEstimator) const;

private:
@@ -223,8 +223,8 @@ public:

    virtual void clear();
    virtual void clearPointers(BitSet32 idBits);
    virtual void addMovement(nsecs_t eventTime, BitSet32 idBits,
            const VelocityTracker::Position* positions);
    void addMovement(nsecs_t eventTime, BitSet32 idBits,
                     const std::vector<VelocityTracker::Position>& positions) override;
    virtual bool getEstimator(uint32_t id, VelocityTracker::Estimator* outEstimator) const;

private:
@@ -257,8 +257,8 @@ public:

    virtual void clear();
    virtual void clearPointers(BitSet32 idBits);
    virtual void addMovement(nsecs_t eventTime, BitSet32 idBits,
            const VelocityTracker::Position* positions);
    void addMovement(nsecs_t eventTime, BitSet32 idBits,
                     const std::vector<VelocityTracker::Position>& positions) override;
    virtual bool getEstimator(uint32_t id, VelocityTracker::Estimator* outEstimator) const;

private:
@@ -292,8 +292,8 @@ public:

    virtual void clear();
    virtual void clearPointers(BitSet32 idBits);
    virtual void addMovement(nsecs_t eventTime, BitSet32 idBits,
            const VelocityTracker::Position* positions);
    void addMovement(nsecs_t eventTime, BitSet32 idBits,
                     const std::vector<VelocityTracker::Position>& positions) override;
    virtual bool getEstimator(uint32_t id, VelocityTracker::Estimator* outEstimator) const;

private:
+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ void VelocityControl::move(nsecs_t eventTime, float* deltaX, float* deltaY) {
        if (deltaY) {
            mRawPosition.y += *deltaY;
        }
        mVelocityTracker.addMovement(eventTime, BitSet32(BitSet32::valueForBit(0)), &mRawPosition);
        mVelocityTracker.addMovement(eventTime, BitSet32(BitSet32::valueForBit(0)), {mRawPosition});

        float vx, vy;
        float scale = mParameters.scale;
+19 −10
Original line number Diff line number Diff line
@@ -193,7 +193,11 @@ void VelocityTracker::clearPointers(BitSet32 idBits) {
    mStrategy->clearPointers(idBits);
}

void VelocityTracker::addMovement(nsecs_t eventTime, BitSet32 idBits, const Position* positions) {
void VelocityTracker::addMovement(nsecs_t eventTime, BitSet32 idBits,
                                  const std::vector<VelocityTracker::Position>& positions) {
    LOG_ALWAYS_FATAL_IF(idBits.count() != positions.size(),
                        "Mismatching number of pointers, idBits=%" PRIu32 ", positions=%zu",
                        idBits.count(), positions.size());
    while (idBits.count() > MAX_POINTERS) {
        idBits.clearLastMarkedBit();
    }
@@ -286,7 +290,8 @@ void VelocityTracker::addMovement(const MotionEvent* event) {
    }

    nsecs_t eventTime;
    Position positions[pointerCount];
    std::vector<Position> positions;
    positions.resize(pointerCount);

    size_t historySize = event->getHistorySize();
    for (size_t h = 0; h < historySize; h++) {
@@ -346,8 +351,9 @@ void LeastSquaresVelocityTrackerStrategy::clearPointers(BitSet32 idBits) {
    mMovements[mIndex].idBits = remainingIdBits;
}

void LeastSquaresVelocityTrackerStrategy::addMovement(nsecs_t eventTime, BitSet32 idBits,
        const VelocityTracker::Position* positions) {
void LeastSquaresVelocityTrackerStrategy::addMovement(
        nsecs_t eventTime, BitSet32 idBits,
        const std::vector<VelocityTracker::Position>& positions) {
    if (mMovements[mIndex].eventTime != eventTime) {
        // When ACTION_POINTER_DOWN happens, we will first receive ACTION_MOVE with the coordinates
        // of the existing pointers, and then ACTION_POINTER_DOWN with the coordinates that include
@@ -758,8 +764,9 @@ void IntegratingVelocityTrackerStrategy::clearPointers(BitSet32 idBits) {
    mPointerIdBits.value &= ~idBits.value;
}

void IntegratingVelocityTrackerStrategy::addMovement(nsecs_t eventTime, BitSet32 idBits,
        const VelocityTracker::Position* positions) {
void IntegratingVelocityTrackerStrategy::addMovement(
        nsecs_t eventTime, BitSet32 idBits,
        const std::vector<VelocityTracker::Position>& positions) {
    uint32_t index = 0;
    for (BitSet32 iterIdBits(idBits); !iterIdBits.isEmpty();) {
        uint32_t id = iterIdBits.clearFirstMarkedBit();
@@ -876,8 +883,9 @@ void LegacyVelocityTrackerStrategy::clearPointers(BitSet32 idBits) {
    mMovements[mIndex].idBits = remainingIdBits;
}

void LegacyVelocityTrackerStrategy::addMovement(nsecs_t eventTime, BitSet32 idBits,
        const VelocityTracker::Position* positions) {
void LegacyVelocityTrackerStrategy::addMovement(
        nsecs_t eventTime, BitSet32 idBits,
        const std::vector<VelocityTracker::Position>& positions) {
    if (++mIndex == HISTORY_SIZE) {
        mIndex = 0;
    }
@@ -990,8 +998,9 @@ void ImpulseVelocityTrackerStrategy::clearPointers(BitSet32 idBits) {
    mMovements[mIndex].idBits = remainingIdBits;
}

void ImpulseVelocityTrackerStrategy::addMovement(nsecs_t eventTime, BitSet32 idBits,
        const VelocityTracker::Position* positions) {
void ImpulseVelocityTrackerStrategy::addMovement(
        nsecs_t eventTime, BitSet32 idBits,
        const std::vector<VelocityTracker::Position>& positions) {
    if (mMovements[mIndex].eventTime != eventTime) {
        // When ACTION_POINTER_DOWN happens, we will first receive ACTION_MOVE with the coordinates
        // of the existing pointers, and then ACTION_POINTER_DOWN with the coordinates that include
+5 −5
Original line number Diff line number Diff line
@@ -2624,14 +2624,14 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi

    // Update the velocity tracker.
    {
        VelocityTracker::Position positions[MAX_POINTERS];
        uint32_t count = 0;
        for (BitSet32 idBits(mCurrentCookedState.fingerIdBits); !idBits.isEmpty(); count++) {
        std::vector<VelocityTracker::Position> positions;
        for (BitSet32 idBits(mCurrentCookedState.fingerIdBits); !idBits.isEmpty();) {
            uint32_t id = idBits.clearFirstMarkedBit();
            const RawPointerData::Pointer& pointer =
                    mCurrentRawState.rawPointerData.pointerForId(id);
            positions[count].x = pointer.x * mPointerXMovementScale;
            positions[count].y = pointer.y * mPointerYMovementScale;
            float x = pointer.x * mPointerXMovementScale;
            float y = pointer.y * mPointerYMovementScale;
            positions.push_back({x, y});
        }
        mPointerGesture.velocityTracker.addMovement(when, mCurrentCookedState.fingerIdBits,
                                                    positions);