Android Input Framework(三)---InputReader&InputDispatcher
来源:互联网 发布:原生js 触发事件 编辑:程序博客网 时间:2024/06/05 19:27
1InputReader处理Input消息
在InputReaderThread继承于Thread中,读取RawEvent数据流程如下:
1)
2)
3)
4)
n
n
RawEvent结构体中有一个type变量,用这个变量来识别到底是什么事件:
n
n
n
n
代码如下:
voidInputReader::processEventsLocked(const RawEvent* rawEvents, size_tcount) {
}
1.1 处理设备增加、删除和修改事件
1.1.1 增加设备
voidInputReader::addDeviceLocked(nsecs_t when, int32_t deviceId){
}
调用createDeviceLocked()创建了一个InputDevice对象,并添加到mDevices列表中。下面看看createDeviceLocked是如何创建设备的。
先根据mContext, deviceId, name, classes创建一个InputDevice对象,它用于表示单个输入设备的状态。其中的classes为对应Device的classes成员,它用于表示设备类型,定义如下:
enum{
};
创建InputDevice对象之后,会根据classs类型,创建对应的InputManager对象,InputMapper对象主要负责将输入的原始数据进行处理,使其转换成标准的输入事件,每一个InputDevice至少有一个InputMapper,类图关系如下:
这张图,我们关注下mContext变量,InputReader::mContext在构造时用自己的指针初始化了mContext,从而mContext::mReader则为此InputReader实例。在InputReader::createDeviceLocked中创建InputDevice时,把自己的mContext作为参数传入,从而把它保存在InputDevice::mContext中;在创建InputMapper时,以InputDevice作为参数,且InputMapper把它保存在mDevice中,然后从把InputDevice中的mContext也保存在InputMapper的mContext中。
这里我们主要关注的是触摸屏消息:
INPUT_DEVICE_CLASS_TOUCH_MT
INPUT_DEVICE_CLASS_TOUCH
//Touchscreens and touchpad devices.
1.2触摸屏消息处理
1.2.1时序图(触摸消息)
1.2.2 消息处理
关注下两个变量:
n
InputReader::mContext在构造时用自己的指针初始化了mContext,从而mContext::mReader则为此InputReader实例。在InputReader::createDeviceLocked中创建InputDevice时,把自己的mContext作为参数传入,从而把它保存在InputDevice::mContext中;在创建InputMapper时,以InputDevice作为参数,且InputMapper把它保存在mDevice中,然后从把InputDevice中的mContext也保存在InputMapper的mContext中。
n
该变量是在InputReader构造函数中创建的QueuedListener对象,在QueuedListener的构造函数中,将InputDispatcher的实例作为参数赋给内部变量mInnerListener。
mContext->getListener()返回的就是mQueuedListener。
分析RawEvent结构体数据,
n
#define
#define
#define
#define
n
#define
#define
#define
#define
#define
#define
#define
#define
#define
n
对于多点触摸,消息发送方式如下:
ABS_MT_POSITION_X
ABS_MT_POSITION_Y
ABS_MT_TRACKING_ID
ABS_MT_TOUCH_MAJOR
ABS_MT_WIDTH_MAJOR
SYN_MT_REPORT
……
……
ABS_MT_POSITION_X
ABS_MT_POSITION_Y
ABS_MT_TRACKING_ID
ABS_MT_TOUCH_MAJOR
ABS_MT_WIDTH_MAJOR
SYN_MT_REPORT
SYN_REPORT
其中ABS_MT_POSITION_X\Y表示触摸消息的坐标值,ABS_MT_TRACKING_ID表示目前数据是几个手指触摸,SYN_MT_REPORT表示某个触摸信息已经上报完,SYN_REPORT表示一笔完整的多点触摸消息已经上报完成。
对于多点触摸消息,将在MultiTouchInputMapper对消息处理,看看process方法:
voidMultiTouchInputMapper::process(const RawEvent* rawEvent){
}
voidTouchInputMapper::process(const RawEvent* rawEvent) {
}
mCursorButtonAccumulator
mCursorScrollAccumulator
mTouchButtonAccumulator处理EV_KEY类型输入事件
mMultiTouchMotionAccumul
n
n
n
n
调用dispatchMotion
n
n
n
把传递过来的NotifyMotionArg参数复制一份,然后加入QueuedInputListener::mArgsQueue例表中。
此时触摸事件的数据已经都放在了mArgsQueue列表中,在InputReader::LoopOnce中,调用mQueuedListener->flush()开始把数据分发到InputDispatcher中,mInnerListener就是InputDispatcher的实例。
voidQueuedInputListener::flush() {
}
调用链表中每个NotifyArgs的notify函数这么多类NotifyArgs,为描述方便,下面以NotifyMotionArgs为例,其代码为:
voidNotifyMotionArgs::notify(const sp& listener) const {
}
1.2.3消息结构变化流程
2InputDispatcher 消息分发
InputDispatcherThread开启了一个线程来接收InputReader发送过来的消息,当没有消息的时候,线程进行了休眠,当有消息的时候,mLooer->wake()唤醒线程。InputDispatcherThread主循环如下:
1)
2)
3)
4)
分发消息
5)
2.1 唤醒线程
voidInputDispatcher::notifyMotion(const NotifyMotionArgs* args){
}
n
n
2.2InputDispatcher线程工作
在5.1中,调用了mLooper->wake()唤醒InputDispatcher线程,分发工作主要是在dispatchOnceInnerLocked方法中。
n
n
n
n
n
n
- Android Input Framework(三)---InputReader&InputDispatcher
- Android Input Framework(三)---InputReader&InputDispatcher
- Android Input Framework-InputReader&InputDispatcher
- Android input处理机制(三)InputDispatcher
- Android Input流程分析(三):InputReader
- Android输入事件InputReader和InputDispatcher分析
- InputReader和InputDispatcher
- Android中InputManagerService里的InputReader和inputDispatcher
- Android input处理机制(一)InputReader
- Android Input流程分析(四):InputDispatcher
- Android 5.0输入系统分析之InputReader和InputDispatcher线程启动过程
- Linux/Android——Input系统之InputReader (七)
- Linux/Android——Input系统之InputReader (七)
- Android Input framework(一)
- android 4.0 framework input
- Android Input Framework(一)
- Android Input framework(一)
- Android Input Framework(一)
- Android Input Framework(二)---EventHub
- 爬虫基础-网站篇
- 【16-20】LeetCode:Python解题
- 决策树算法 python实现
- 「Deep Learning」Instance Normalization
- Android Input Framework(三)---InputReader&InputDispatcher
- 修饰符权限
- mybatis官网参考文档-XML配置_映射器(mappers)(版本: 3.4.6-SNAPSHOT)
- LNMP环境安装包配置
- Jupyter Notebook 修改默认启动目录
- for of
- window.location.href 带参数跳转 如何获取值(解决)
- 科大讯飞语音开发包上手体验(2)
- 数论函数&狄利克雷卷积