Android移动鼠标的流程

//移动鼠标,InputReader
@frameworks/native/services/inputflinger/reader/InputReader.cpp
InputReader::start
    loopOnce()
        processEventsLocked(mEventBuffer, count);
            case EventHubInterface::DEVICE_ADDED: addDeviceLocked(rawEvent->when, rawEvent->deviceId);  //添加设备
                InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(eventHubId);
                if(identifier.vendor == 8183 && identifier.product == 4084) { return; }  //根据keyboard设备类型判断,不添加设备,以免vd启动异常
                std::shared_ptr<InputDevice> device = createDeviceLocked(eventHubId, identifier)
@/p/sx/db/rk3588/frameworks/native/services/inputflinger/reader/InputDevice.cpp                
                    device->addEventHubDevice(eventHubId);  //添加触摸光标设备
                        if (classes.test(InputDeviceClass::BATTERY) || classes.test(InputDeviceClass::LIGHT)) {  mController = std::make_unique<PeripheralController>(*contextPtr); }
                        if (classes.test(InputDeviceClass::CURSOR)) { mappers.push_back(std::make_unique<CursorInputMapper>(*contextPtr)); }
                        //addDeviceLocked Device added: id=3, eventHubId=8, name='hyn_ts', descriptor='dd768709fe8e1221a31cd1cbe2fb6da013ae6c46',sources=0x00002002
                        mDevices.insert({eventHubId, std::make_pair(std::move(contextPtr), std::move(mappers))});            
            processEventsForDeviceLocked(deviceId, rawEvent, batchSize);
                auto deviceIt = mDevices.find(eventHubId);
                device->process(rawEvents, count);
@frameworks/native/services/inputflinger/reader/InputDevice.cpp
                    for_each_mapper_in_subdevice(rawEvent->deviceId, [rawEvent](InputMapper& mapper)
                        auto deviceIt = mDevices.find(eventHubDevice);   //eventHubDevice=8
@frameworks/native/services/inputflinger/reader/mapper/CursorInputMapper.cpp                        
                        mapper.process(rawEvent);  //CursorInputMapper::process
                            mCursorButtonAccumulator.process(rawEvent);
                            mCursorMotionAccumulator.process(rawEvent);
                            mCursorScrollAccumulator.process(rawEvent);
                                sync(rawEvent->when, rawEvent->readTime);  //CursorInputMapper::sync
                                    //更新鼠标显示位置
@frameworks/base/libs/input/PointerController.cpp
                                    mPointerController->move(dx, dy);
@frameworks/base/libs/input/MouseCursorController.cpp
                                        CursorController.move(deltaX, deltaY);
                                            setPositionLocked(mLocked.pointerX + deltaX, mLocked.pointerY + deltaY);  //mLocked.pointerX是当前点的绝对坐标, deltaX=-13.000000, deltaY=0.000000 mLocked.pointerX=1919.500000 mLocked.pointerY=539.500000
                                            if (getBoundsLocked(&minX, &minY, &maxX, &maxY)){  //获取边缘并调整边缘,设置mLocked.pointerX、mLocked.pointerY,x=1906.500000, y=539.500000
                                                if (x <= minX) {
                                                    mLocked.pointerX = minX;
                                                } else if (x >= maxX) {
                                                    mLocked.pointerX = maxX;
                                                } else {
                                                    mLocked.pointerX = x;
                                                }
                                                if (y <= minY) {
                                                    mLocked.pointerY = minY;
                                                } else if (y >= maxY) {
                                                    mLocked.pointerY = maxY;
                                                } else {
                                                    mLocked.pointerY = y;
                                                }
                                                updatePointerLocked();     //setPositionLocked, x=1906.500000, y=539.500000
@frameworks/base/libs/input/SpriteController.cpp
                                                    mLocked.pointerSprite->setPosition(mLocked.pointerX, mLocked.pointerY);  //获取mLocked.pointerX、mLocked.pointerY,x=1906.500000, y=539.500000
                                                        mLocked.state.positionX = x;
                                                        mLocked.state.positionY = y;                                                    
                                                        invalidateLocked(DIRTY_POSITION);
                                                            if (!wasDirty) {  mController->invalidateSpriteLocked(this);    }
                                                                mLocked.invalidatedSprites.push(sprite);  //放入invalidatedSprites
                                                                SpriteController::handleMessage
                                                                    case MSG_UPDATE_SPRITES: doUpdateSprites
                                                                        Vector<SpriteUpdate> updates;
                                                                        numSprites = mLocked.invalidatedSprites.size();
                                                                        for (size_t i = 0; i < numSprites; i++) {
                                                                            const sp<SpriteImpl>& sprite = mLocked.invalidatedSprites.itemAt(i);  取出invalidatedSprites
                                                                            updates.push(SpriteUpdate(sprite, sprite->getStateLocked()));
                                                                        SurfaceComposerClient::Transaction t;
                                                                        for (size_t i = 0; i < numSprites; i++) {
                                                                            SpriteUpdate& update = updates.editItemAt(i);
                                                                            if (update.state.surfaceControl == NULL && update.state.wantSurfaceVisible()) {
                                                                                 update.state.surfaceControl = obtainSurface(update.state.surfaceWidth, update.state.surfaceHeight);   //创建Surface                                                 
                                                                                     sp<SurfaceControl> surfaceControl = mSurfaceComposerClient->createSurface(String8("Sprite"), width, height, PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eHidden | ISurfaceComposerClient::eCursorWindow);
                                                                                 update.surfaceChanged = surfaceChanged = true;
                                                                            if (update.surfaceChanged || update.state.dirty & DIRTY_DISPLAY_ID)  //创建Surface时设置update.surfaceChanged成true,更新Layer的displayId,这里决定了2D鼠标在哪个显示屏上显示
                                                                                t.setLayerStack(update.state.surfaceControl, update.state.displayId);
                                                                            if (wantSurfaceVisibleAndDrawn && (becomingVisible || (update.state.dirty & (DIRTY_POSITION | DIRTY_HOTSPOT)))) {
                                                                                //设置显示位置, update.state.positionX=1906.500000,update.state.positionY=539.500000, update.state.icon.hotSpotX=10.000000 update.state.icon.hotSpotY=10.000000
                                                                                t.setPosition(update.state.surfaceControl, update.state.positionX - update.state.icon.hotSpotX, update.state.positionY - update.state.icon.hotSpotY);                       
                                                    mLocked.pointerSprite->setDisplayId(mLocked.viewport.displayId);
                                                        if (mLocked.state.displayId != displayId) { mLocked.state.displayId = displayId;  invalidateLocked(DIRTY_DISPLAY_ID);  } //不相等则更新displayId,设置成viewport.displayId
@frameworks/base/libs/input/PointerController.cpp                                                        
                                    mPointerController->getPosition(&xCursorPosition, &yCursorPosition);
@frameworks/base/libs/input/MouseCursorController.cpp
                                        mCursorController.getPosition(outX, outY);  //获取mLocked.pointerX、mLocked.pointerY,x=1906.500000, y=539.500000
                                            *outX = mLocked.pointerX;
                                            *outY = mLocked.pointerY;
                                    NotifyMotionArgs args(getContext()->getNextId(), getDeviceId(), mSource, displayId, currentButtonState, MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties, &pointerCoords, mXPrecision, mYPrecision, xCursorPosition, yCursorPosition
                                    getListener()->notifyMotion(&args);
                                        InputDispatcher::notifyMotion
                                            mPolicy->interceptMotionBeforeQueueing(args->displayId, args->eventTime, /*byref*/ policyFlags);
                                                needWake = enqueueInboundEventLocked(std::move(newEntry));
                                                    mInboundQueue.push_back(std::move(newEntry)); //放入mInboundQueue队列,InputDispater会从这里读事件


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

薛文旺

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值