Android input处理机制(一)InputReader

InputManager类处理过程:

InputManager 先创建InputDispatcher 和InputReader对象,并把InputReader和InputDispatcher对象为参数再创建两个线程对象,InputReaderThread 以及InputDispatcherThread。InputManager::start()启动两个线程。

InputReader类处理过程:

InputReader::loopOnce()--->EventHub::getEvents()--->InputReader::processEventsLocked()---

--->InputReader::processEventsForDeviceLocked()--->InputDevice::process()--->TouchInputMapper::process()--

--->TouchInputMapper::sync()--->TouchInputMapper::dispatchTouches()

EventHub类处理过程:

getEvents()函数负责处理事件,可以处理不止一个事件,这个之前版本源码不同,scanDirLock()负责扫描设备,openDeviceLock()负责生成设备相关信息,新版函数都在后面加了Lock。


读过一些源码之后,我思考了两个问题

1.有些文章说InputReaderThread 和InputDispatcherThread都会在没有事件时进入睡眠状态。研读源码发现InputDispatcher::dispatchOnce()以及mLooper->pollOnce()确实在没有事件需要处理时进行睡眠,但研读InputRedaer源码时,没有了解其如何睡眠。

2.InputReader是如何和InputDispatcher交互的?因为老版本源码,InputReader有getDispatcher()函数,但新版本替换为getListener()。


继续研读代码发现答案:

1.InputReaderThread::loopOnce会休眠到EventHub::getEvents()中的epoll_wait(),epoll_wait()是系统调用,负责轮询IO的。

2.getListener()是一个队列 ,队列缓存了需要处理的事件,队列对象还持有一个Inputdispatcher对象。

明天继续研读,写写笔记免得自己忘掉。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值