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

Commit aee7eb92 authored by Prabir Pradhan's avatar Prabir Pradhan Committed by Android (Google) Code Review
Browse files

Merge changes I0b34480e,I9889e7f8,I5e008d03

* changes:
  TouchInputMapper: Rely on default c'tor and copy c'tors for structs
  Use the last cooked touch state for generating button release events
  Use std::array and default copy assignment for PointerCoords
parents d500ef2e d6ccedb2
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -366,7 +366,7 @@ struct PointerCoords {

    // Values of axes that are stored in this structure packed in order by axis id
    // for each axis that is present in the structure according to 'bits'.
    float values[MAX_AXES];
    std::array<float, MAX_AXES> values;

    inline void clear() {
        BitSet64::clear(bits);
@@ -406,7 +406,8 @@ struct PointerCoords {
        return !(*this == other);
    }

    void copyFrom(const PointerCoords& other);
    inline void copyFrom(const PointerCoords& other) { *this = other; }
    PointerCoords& operator=(const PointerCoords&) = default;

private:
    void tooManyAxes(int axis);
+0 −8
Original line number Diff line number Diff line
@@ -438,14 +438,6 @@ bool PointerCoords::operator==(const PointerCoords& other) const {
    return true;
}

void PointerCoords::copyFrom(const PointerCoords& other) {
    bits = other.bits;
    uint32_t count = BitSet64::count(bits);
    for (uint32_t i = 0; i < count; i++) {
        values[i] = other.values[i];
    }
}

void PointerCoords::transform(const ui::Transform& transform) {
    const vec2 xy = transform.transform(getXYValue());
    setAxisValue(AMOTION_EVENT_AXIS_X, xy.x);
+2 −2
Original line number Diff line number Diff line
@@ -304,8 +304,8 @@ static void getHalPropertiesAndCoords(const NotifyMotionArgs& args,
        common::PointerCoords coords;
        // OK to copy bits because we have static_assert for pointerCoords axes
        coords.bits = args.pointerCoords[i].bits;
        coords.values = std::vector<float>(args.pointerCoords[i].values,
                                           args.pointerCoords[i].values +
        coords.values = std::vector<float>(args.pointerCoords[i].values.cbegin(),
                                           args.pointerCoords[i].values.cbegin() +
                                                   BitSet64::count(args.pointerCoords[i].bits));
        outPointerCoords.push_back(coords);
    }
+9 −16
Original line number Diff line number Diff line
@@ -67,22 +67,15 @@ struct RawEvent {

/* Describes an absolute axis. */
struct RawAbsoluteAxisInfo {
    bool valid; // true if the information is valid, false otherwise

    int32_t minValue;   // minimum value
    int32_t maxValue;   // maximum value
    int32_t flat;       // center flat position, eg. flat == 8 means center is between -8 and 8
    int32_t fuzz;       // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise
    int32_t resolution; // resolution in units per mm or radians per mm

    inline void clear() {
        valid = false;
        minValue = 0;
        maxValue = 0;
        flat = 0;
        fuzz = 0;
        resolution = 0;
    }
    bool valid{false}; // true if the information is valid, false otherwise

    int32_t minValue{};   // minimum value
    int32_t maxValue{};   // maximum value
    int32_t flat{};       // center flat position, eg. flat == 8 means center is between -8 and 8
    int32_t fuzz{};       // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise
    int32_t resolution{}; // resolution in units per mm or radians per mm

    inline void clear() { *this = RawAbsoluteAxisInfo(); }
};

/*
+43 −117
Original line number Diff line number Diff line
@@ -73,53 +73,8 @@ inline static int32_t signExtendNybble(int32_t value) {
    return value >= 8 ? value - 16 : value;
}

// --- RawPointerAxes ---

RawPointerAxes::RawPointerAxes() {
    clear();
}

void RawPointerAxes::clear() {
    x.clear();
    y.clear();
    pressure.clear();
    touchMajor.clear();
    touchMinor.clear();
    toolMajor.clear();
    toolMinor.clear();
    orientation.clear();
    distance.clear();
    tiltX.clear();
    tiltY.clear();
    trackingId.clear();
    slot.clear();
}

// --- RawPointerData ---

RawPointerData::RawPointerData() {
    clear();
}

void RawPointerData::clear() {
    pointerCount = 0;
    clearIdBits();
}

void RawPointerData::copyFrom(const RawPointerData& other) {
    pointerCount = other.pointerCount;
    hoveringIdBits = other.hoveringIdBits;
    touchingIdBits = other.touchingIdBits;
    canceledIdBits = other.canceledIdBits;

    for (uint32_t i = 0; i < pointerCount; i++) {
        pointers[i] = other.pointers[i];

        int id = pointers[i].id;
        idToIndex[id] = other.idToIndex[id];
    }
}

void RawPointerData::getCentroidOfTouchingPointers(float* outX, float* outY) const {
    float x = 0, y = 0;
    uint32_t count = touchingIdBits.count();
@@ -137,35 +92,6 @@ void RawPointerData::getCentroidOfTouchingPointers(float* outX, float* outY) con
    *outY = y;
}

// --- CookedPointerData ---

CookedPointerData::CookedPointerData() {
    clear();
}

void CookedPointerData::clear() {
    pointerCount = 0;
    hoveringIdBits.clear();
    touchingIdBits.clear();
    canceledIdBits.clear();
    validIdBits.clear();
}

void CookedPointerData::copyFrom(const CookedPointerData& other) {
    pointerCount = other.pointerCount;
    hoveringIdBits = other.hoveringIdBits;
    touchingIdBits = other.touchingIdBits;
    validIdBits = other.validIdBits;

    for (uint32_t i = 0; i < pointerCount; i++) {
        pointerProperties[i].copyFrom(other.pointerProperties[i]);
        pointerCoords[i].copyFrom(other.pointerCoords[i]);

        int id = pointerProperties[i].id;
        idToIndex[id] = other.idToIndex[id];
    }
}

// --- TouchInputMapper ---

TouchInputMapper::TouchInputMapper(InputDeviceContext& deviceContext)
@@ -1583,7 +1509,7 @@ std::list<NotifyArgs> TouchInputMapper::processRawTouches(bool timeout) {

        // All ready to go.
        clearStylusDataPendingFlags();
        mCurrentRawState.copyFrom(next);
        mCurrentRawState = next;
        if (mCurrentRawState.when < mLastRawState.when) {
            mCurrentRawState.when = mLastRawState.when;
            mCurrentRawState.readTime = mLastRawState.readTime;
@@ -1598,7 +1524,7 @@ std::list<NotifyArgs> TouchInputMapper::processRawTouches(bool timeout) {
        if (timeout) {
            nsecs_t when = mExternalStylusFusionTimeout - STYLUS_DATA_LATENCY;
            clearStylusDataPendingFlags();
            mCurrentRawState.copyFrom(mLastRawState);
            mCurrentRawState = mLastRawState;
            ALOGD_IF(DEBUG_STYLUS_FUSION,
                     "Timeout expired, synthesizing event with new stylus data");
            const nsecs_t readTime = when; // consider this synthetic event to be zero latency
@@ -1723,8 +1649,8 @@ std::list<NotifyArgs> TouchInputMapper::cookAndDispatch(nsecs_t when, nsecs_t re
    mCurrentRawState.rawHScroll = 0;

    // Copy current touch to last touch in preparation for the next cycle.
    mLastRawState.copyFrom(mCurrentRawState);
    mLastCookedState.copyFrom(mCurrentCookedState);
    mLastRawState = mCurrentRawState;
    mLastCookedState = mCurrentCookedState;
    return out;
}

@@ -1744,8 +1670,8 @@ void TouchInputMapper::updateTouchSpots() {
    mPointerController->fade(PointerControllerInterface::Transition::GRADUAL);

    mPointerController->setButtonState(mCurrentRawState.buttonState);
    mPointerController->setSpots(mCurrentCookedState.cookedPointerData.pointerCoords,
                                 mCurrentCookedState.cookedPointerData.idToIndex,
    mPointerController->setSpots(mCurrentCookedState.cookedPointerData.pointerCoords.cbegin(),
                                 mCurrentCookedState.cookedPointerData.idToIndex.cbegin(),
                                 mCurrentCookedState.cookedPointerData.touchingIdBits,
                                 mViewport.displayId);
}
@@ -1993,6 +1919,36 @@ std::list<NotifyArgs> TouchInputMapper::abortTouches(nsecs_t when, nsecs_t readT
    return out;
}

// Updates pointer coords and properties for pointers with specified ids that have moved.
// Returns true if any of them changed.
static bool updateMovedPointers(const PropertiesArray& inProperties, CoordsArray& inCoords,
                                const IdToIndexArray& inIdToIndex, PropertiesArray& outProperties,
                                CoordsArray& outCoords, IdToIndexArray& outIdToIndex,
                                BitSet32 idBits) {
    bool changed = false;
    while (!idBits.isEmpty()) {
        uint32_t id = idBits.clearFirstMarkedBit();
        uint32_t inIndex = inIdToIndex[id];
        uint32_t outIndex = outIdToIndex[id];

        const PointerProperties& curInProperties = inProperties[inIndex];
        const PointerCoords& curInCoords = inCoords[inIndex];
        PointerProperties& curOutProperties = outProperties[outIndex];
        PointerCoords& curOutCoords = outCoords[outIndex];

        if (curInProperties != curOutProperties) {
            curOutProperties.copyFrom(curInProperties);
            changed = true;
        }

        if (curInCoords != curOutCoords) {
            curOutCoords.copyFrom(curInCoords);
            changed = true;
        }
    }
    return changed;
}

std::list<NotifyArgs> TouchInputMapper::dispatchTouches(nsecs_t when, nsecs_t readTime,
                                                        uint32_t policyFlags) {
    std::list<NotifyArgs> out;
@@ -2160,9 +2116,9 @@ std::list<NotifyArgs> TouchInputMapper::dispatchButtonRelease(nsecs_t when, nsec
        out.push_back(dispatchMotion(when, readTime, policyFlags, mSource,
                                     AMOTION_EVENT_ACTION_BUTTON_RELEASE, actionButton, 0,
                                     metaState, buttonState, 0,
                                     mCurrentCookedState.cookedPointerData.pointerProperties,
                                     mCurrentCookedState.cookedPointerData.pointerCoords,
                                     mCurrentCookedState.cookedPointerData.idToIndex, idBits, -1,
                                     mLastCookedState.cookedPointerData.pointerProperties,
                                     mLastCookedState.cookedPointerData.pointerCoords,
                                     mLastCookedState.cookedPointerData.idToIndex, idBits, -1,
                                     mOrientedXPrecision, mOrientedYPrecision, mDownTime,
                                     MotionClassification::NONE));
    }
@@ -2539,8 +2495,8 @@ std::list<NotifyArgs> TouchInputMapper::dispatchPointerGestures(nsecs_t when, ns
        }

        if (mPointerGesture.currentGestureMode == PointerGesture::Mode::FREEFORM) {
            mPointerController->setSpots(mPointerGesture.currentGestureCoords,
                                         mPointerGesture.currentGestureIdToIndex,
            mPointerController->setSpots(mPointerGesture.currentGestureCoords.cbegin(),
                                         mPointerGesture.currentGestureIdToIndex.cbegin(),
                                         mPointerGesture.currentGestureIdBits,
                                         mPointerController->getDisplayId());
        }
@@ -3743,8 +3699,8 @@ std::list<NotifyArgs> TouchInputMapper::abortPointerSimple(nsecs_t when, nsecs_t
NotifyMotionArgs TouchInputMapper::dispatchMotion(
        nsecs_t when, nsecs_t readTime, uint32_t policyFlags, uint32_t source, int32_t action,
        int32_t actionButton, int32_t flags, int32_t metaState, int32_t buttonState,
        int32_t edgeFlags, const PointerProperties* properties, const PointerCoords* coords,
        const uint32_t* idToIndex, BitSet32 idBits, int32_t changedId, float xPrecision,
        int32_t edgeFlags, const PropertiesArray& properties, const CoordsArray& coords,
        const IdToIndexArray& idToIndex, BitSet32 idBits, int32_t changedId, float xPrecision,
        float yPrecision, nsecs_t downTime, MotionClassification classification) {
    PointerCoords pointerCoords[MAX_POINTERS];
    PointerProperties pointerProperties[MAX_POINTERS];
@@ -3798,36 +3754,6 @@ NotifyMotionArgs TouchInputMapper::dispatchMotion(
                            downTime, std::move(frames));
}

bool TouchInputMapper::updateMovedPointers(const PointerProperties* inProperties,
                                           const PointerCoords* inCoords,
                                           const uint32_t* inIdToIndex,
                                           PointerProperties* outProperties,
                                           PointerCoords* outCoords, const uint32_t* outIdToIndex,
                                           BitSet32 idBits) const {
    bool changed = false;
    while (!idBits.isEmpty()) {
        uint32_t id = idBits.clearFirstMarkedBit();
        uint32_t inIndex = inIdToIndex[id];
        uint32_t outIndex = outIdToIndex[id];

        const PointerProperties& curInProperties = inProperties[inIndex];
        const PointerCoords& curInCoords = inCoords[inIndex];
        PointerProperties& curOutProperties = outProperties[outIndex];
        PointerCoords& curOutCoords = outCoords[outIndex];

        if (curInProperties != curOutProperties) {
            curOutProperties.copyFrom(curInProperties);
            changed = true;
        }

        if (curInCoords != curOutCoords) {
            curOutCoords.copyFrom(curInCoords);
            changed = true;
        }
    }
    return changed;
}

std::list<NotifyArgs> TouchInputMapper::cancelTouch(nsecs_t when, nsecs_t readTime) {
    std::list<NotifyArgs> out;
    out += abortPointerUsage(when, readTime, 0 /*policyFlags*/);
Loading