InputReader触摸调用流程

该文章详细阐述了Android系统中InputFlinger服务如何处理输入事件,从InputReader的processEventsLocked方法开始,经过设备检查、事件处理,到TouchInputMapper和MultiTouchInputMapper对多指触摸的同步和分发,最终触发通知InputDispatcher进行动作调度。
摘要由CSDN通过智能技术生成

请部分请参考android Input专题- Q/R/S 10/11/12 InputReader源码分析1_learnframework的博客-CSDN博客

1、frameworks/native/services/inputflinger/InputReader.cpp

void InputReader::processEventsLocked(const RawEvent* rawEvents, size_t count) {

#if DEBUG_RAW_EVENTS
            ALOGD("BatchSize: %d Count: %d", batchSize, count);
#endif
            processEventsForDeviceLocked(deviceId, rawEvent, batchSize);
        } else {
}

2、frameworks/native/services/inputflinger/InputReader.cpp

void InputReader::processEventsForDeviceLocked(int32_t deviceId,
        const RawEvent* rawEvents, size_t count) {
    ssize_t deviceIndex = mDevices.indexOfKey(deviceId);
    if (deviceIndex < 0) {
        ALOGW("Discarding event for unknown deviceId %d.", deviceId);
        return;
    }

    InputDevice* device = mDevices.valueAt(deviceIndex);
    if (device->isIgnored()) {
        //ALOGD("Discarding event for ignored deviceId %d.", deviceId);
        return;
    }

    device->process(rawEvents, count);
}

3、frameworks/native/services/inputflinger/InputReader.cpp

void InputDevice::process(const RawEvent* rawEvents, size_t count) {

        } else {
            for (size_t i = 0; i < numMappers; i++) {
                InputMapper* mapper = mMappers[i];
                mapper->process(rawEvent);
            }
4、MultiTouchInputMapper多指触摸

void MultiTouchInputMapper::process(const RawEvent* rawEvent) {
    TouchInputMapper::process(rawEvent);

    mMultiTouchMotionAccumulator.process(rawEvent);
}

5、TouchInputMapper

void TouchInputMapper::process(const RawEvent* rawEvent) {

    if (rawEvent->type == EV_SYN && rawEvent->code == SYN_REPORT) {
        sync(rawEvent->when);
    }
}

6、TouchInputMapper

void TouchInputMapper::sync(nsecs_t when) {
 

// Sync touch

syncTouch(when, next);

// Assign pointer ids.

if (!mHavePointerIds) {

assignPointerIds(last, next);

}

processRawTouches(false /*timeout*/);

}

7、MultiTouchInputMapper

void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) {
    size_t inCount = mMultiTouchMotionAccumulator.getSlotCount();
    size_t outCount = 0;
    BitSet32 newPointerIdBits;
    mHavePointerIds = true;

    mMultiTouchMotionAccumulator.finishSync();
}

8、TouchInputMapper

void TouchInputMapper::processRawTouches(bool timeout) {

for (count = 0; count < N; count++) {

// All ready to go.

clearStylusDataPendingFlags();

mCurrentRawState.copyFrom(next);

cookAndDispatch(mCurrentRawState.when);

}

}

9、TouchInputMapper

void TouchInputMapper::cookAndDispatch(nsecs_t when) {

cookPointerData();

// Apply stylus pressure to current cooked state.

applyExternalStylusTouchState(when);

if (!mCurrentMotionAborted) {

dispatchButtonRelease(when, policyFlags);

dispatchHoverExit(when, policyFlags);

dispatchTouches(when, policyFlags);

dispatchHoverEnterAndMove(when, policyFlags);

dispatchButtonPress(when, policyFlags);

}

}

10、TouchInputMapper

void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) {

dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_MOVE, 0, 0, metaState,

buttonState, 0, mCurrentCookedState.cookedPointerData.pointerProperties,

mCurrentCookedState.cookedPointerData.pointerCoords,

mCurrentCookedState.cookedPointerData.idToIndex, dispatchedIdBits, -1,

mOrientedXPrecision, mOrientedYPrecision, mDownTime);

}

11、TouchInputMapper

void TouchInputMapper::dispatchMotion(.....){

    NotifyMotionArgs args(getContext()->getNextId(), when, readTime, deviceId, source, displayId,
                          policyFlags, action, actionButton, flags, metaState, buttonState,
                          MotionClassification::NONE, edgeFlags, pointerCount, pointerProperties,
                          pointerCoords, xPrecision, yPrecision, xCursorPosition, yCursorPosition,
                          downTime, std::move(frames));
    getListener().notifyMotion(&args);

}

12、InputDispatcher

void InputDispatcher::notifyMotion(const NotifyMotionArgs* args) {

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值