FTxxxx系列------x,y坐标的计算以及上报

最近无聊,看看x,y的坐标是怎么从0x转成float


void MultiTouchInputMapper::syncTouch(nsecs_t when, bool* outHavePointerIds) {

for (size_t inIndex = 0; inIndex < inCount; inIndex++) {
        const MultiTouchMotionAccumulator::Slot* inSlot =
                mMultiTouchMotionAccumulator.getSlot(inIndex);  //获取了inSlot  得看看slot的数据从哪里来


[
其实slot在
void MultiTouchMotionAccumulator::process(const RawEvent* rawEvent) {


 Slot* slot = &mSlots[mCurrentSlot];


            switch (rawEvent->code) {
            case ABS_MT_POSITION_X:
                slot->mInUse = true;
                slot->mAbsMTPositionX = rawEvent->value;
                break;
            case ABS_MT_POSITION_Y:
                slot->mInUse = true;
                slot->mAbsMTPositionY = rawEvent->value;
                break;
            case ABS_MT_TOUCH_MAJOR:
                slot->mInUse = true;
                slot->mAbsMTTouchMajor = rawEvent->value;
                break;
注意这里非常喜欢用类似的指针直接赋值来填充这些mSlots[mCurrentSlot];
]


RawPointerData::Pointer& outPointer = mCurrentRawPointerData.pointers[outCount];  //这里用了个指针来指向mCurrentRawPointerData,从而给mCurrentRawPointerData赋值所以后面都从mCurrentRawPointerData取值
        outPointer.x = inSlot->getX();//这里获取到的x是个整数也就是


D/InputReader( 1068): lisa-outPointer.x: 640 
D/InputReader( 1068): lisa- count=5
D/InputReader( 1068): lisa-outPointer.x: 650 
D/InputReader( 1068): lisa- count=3
D/InputReader( 1068): lisa-outPointer.x: 659 




        outPointer.y = inSlot->getY();
        outPointer.pressure = inSlot->getPressure();
        outPointer.touchMajor = inSlot->getTouchMajor();


然后到了void TouchInputMapper::cookPointerData() {


  default:
ALOGD("lisa-1: %f-1: %f-1: %f-1: %f+++++mSurfaceOrientation=%d ", xTransformed,mRawPointerAxes.x.minValue,mXScale,mXTranslate,mSurfaceOrientation);
ALOGD("lisa-1: %f-1: %f--------------: ",mXScale,mXTranslate);
            x = float(xTransformed - mRawPointerAxes.x.minValue) * mXScale + mXTranslate;
            y = float(yTransformed - mRawPointerAxes.y.minValue) * mYScale + mYTranslate;
            left = float(rawLeft - mRawPointerAxes.x.minValue) * mXScale + mXTranslate;
            right = float(rawRight - mRawPointerAxes.x.minValue) * mXScale + mXTranslate;
            bottom = float(rawBottom - mRawPointerAxes.y.minValue) * mYScale + mYTranslate;
            top = float(rawTop - mRawPointerAxes.y.minValue) * mYScale + mYTranslate;
            break;




D/InputReader( 1029): lisa-1: 345.000000-1: 0.998613-1: 0.000000-1: 0.000000+++++mSurfaceOrientation=0 
D/InputReader( 1029): lisa-1: 345.000000-1: 0.998613-1: 0.000000-1: 0.497226+++++mSurfaceOrientation=0 
D/InputReader( 1029): lisa-1: 0.998613-1: 0.000000--------------: 
D/InputReader( 1029): lisa-xTransformed.x: 344.521515+1 
这里的值就变成了带小数的部分

接着把数据装到mCurrentCookedPointerData.pointerCoords里头

PointerCoords& out = mCurrentCookedPointerData.pointerCoords[i];

out.setAxisValue(AMOTION_EVENT_AXIS_X, x);
out.setAxisValue(AMOTION_EVENT_AXIS_Y, y);

这里cook完之后,到了

 dispatchMotion(when, policyFlags, mSource,
                    AMOTION_EVENT_ACTION_POINTER_DOWN, 0, metaState, buttonState, 0,
                    mCurrentCookedPointerData.pointerProperties,
                    mCurrentCookedPointerData.pointerCoords,
                    mCurrentCookedPointerData.idToIndex,
                    dispatchedIdBits, downId,
                    mOrientedXPrecision, mOrientedYPrecision, mDownTime);


然后    pointerCoords[pointerCount].copyFrom(coords[index]);

 NotifyMotionArgs args(when, getDeviceId(), source, policyFlags,
            action, flags, metaState, buttonState, edgeFlags,
            mViewport.displayId, pointerCount, pointerProperties, pointerCoords,
            xPrecision, yPrecision, downTime);
    getListener()->notifyMotion(&args);

跑到了inputdispatcher里

 MotionEntry* newEntry = new MotionEntry(args->eventTime,
                args->deviceId, args->source, policyFlags,
                args->action, args->flags, args->metaState, args->buttonState,
                args->edgeFlags, args->xPrecision, args->yPrecision, args->downTime,
                args->displayId,
                args->pointerCount, args->pointerProperties, args->pointerCoords, 0, 0);

把x,y的值放到了这个event里,但是类型是motionevent

needWake = enqueueInboundEventLocked(newEntry);

bool InputDispatcher::enqueueInboundEventLocked(EventEntry* entry) 但是接下来放到queue里的时候却变成了evententry类型,这个会不停得MotionEntryEventEntry之间转化


然后   mInboundQueue.enqueueAtTail(entry);加入到enqueue里

到了void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) 里

  mPendingEvent = mInboundQueue.dequeueAtHead();这个 EventEntry* mPendingEvent;所以又变了

再转型 MotionEntry* typedEntry = static_cast<MotionEntry*>(mPendingEvent);

跑到bool InputDispatcher::dispatchMotionLocked(nsecs_t currentTime, MotionEntry* entry, DropReason* dropReason, nsecs_t* nextWakeupTime)

接着void InputDispatcher::dispatchEventLocked(nsecs_t currentTime,  EventEntry* eventEntry, const Vector<InputTarget>& inputTargets) 

接着void InputDispatcher::prepareDispatchCycleLocked(nsecs_t currentTime,  const sp<Connection>& connection, EventEntry* eventEntry, const InputTarget* inputTarget) 

 MotionEntry* splitMotionEntry = splitMotionEvent( originalMotionEntry, inputTarget->pointerIds);


然后

void InputDispatcher::enqueueDispatchEntriesLocked(nsecs_t currentTime,const sp<Connection>& connection, EventEntry* eventEntry, const InputTarget* inputTarget)

继续

void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime,const sp<Connection>& connection) 

然后

status_t InputPublisher::publishMotionEvent(
        uint32_t seq,
        int32_t deviceId,
        int32_t source,
        int32_t action,
        int32_t flags,
        int32_t edgeFlags,
        int32_t metaState,
        int32_t buttonState,
        float xOffset,
        float yOffset,
        float xPrecision,
        float yPrecision,
        nsecs_t downTime,
        nsecs_t eventTime,
        uint32_t pointerCount,
        const PointerProperties* pointerProperties,
        const PointerCoords* pointerCoords) 

const char* matt= mChannel->getName().string();
char* matt1="smmitest";
if(strstr(matt,matt1)!=NULL)
ALOGD("matt-motionEntry->x=%f,y=%f",pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X),pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y));

最后x和y在这里被传往view那边



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值