Android 输入系统解析 (2)
2012-07-03 17:48
429 查看
3. InputReader
在frameworks/base/services/input/InputReader.cpp中InputReader类成员函数loopOnce将调用EventHub类成员函数getEvents。
?
processEventsLocked进一步调用processEventsForDeviceLocked,而processEventsForDeviceLocked调用InputDevice类成员函数process来处理获得的输入事件。
?
?
4. InputMapper
从InputReader.h中的定义可知,InputMapper是一个抽象类。事实上,每个InputDevice在创建时(InputReader::createDeviceLocked)都会为此设备增加一个或多个Mapper,每个Mappr会根据设备类别的不同来分配一个相对应的InputMapper继承类对象。
?
以单点触摸类别设备为例,其Mapper对输入事件的处理为:
?
其中,以下语句均是将输入事件信息转存至类成员变量中。
mCursorButtonAccumulator.process(rawEvent);
mCursorScrollAccumulator.process(rawEvent);
mTouchButtonAccumulator.process(rawEvent);
mSingleTouchMotionAccumulator.process(rawEvent);
看来输入事件的处理关键在TouchInputMapper::sync。
?
cookPointerData将原始的输入事件(坐标)转变为屏幕坐标,而以dispatch开头的这几个函数最终将输入事件分发出去,下面以dispatchPointerUsage为例加以说明。
?
?
?
很明显,调用getListener()->notifyMotion来分发事件。下面来跟踪下getListener()返回的具体对象。
?
?
getListener在InputMapper基类中定义,其返回的对象为mContext->getListener()。由其构造函数可知,InputMapper.mContext即InputDevice.mContext ( InputDevice::getContext函数返回)。InputDevice.mContext在其构造函数中初始化。
?
在InputReader::createDeviceLocked函数中,分配InputDevice时传给InputDevice构造函数的context参数为InputReader.mContext的引用。这样,InputMapper::getListener返回的其实为InputReader的ContextImpl类成员变量mContext。
?
mQueuedInputListener的定义为: sp<QueuedInputListener> mQueuedListener。这样,在InputMapper::sync中getListener()->notifyMotion的最终调用为:
QueuedInputListener::notifyMotion (InputReader.mQueuedInputListener->notifyMotion )。
QueuedInputListener类在InputListener.h和InputListener.cpp中定义和实现,其notify系列成员函数只是将传入的参数复制一份并存入数组成员变量mArgsQueue中。
在frameworks/base/services/input/InputReader.cpp中InputReader类成员函数loopOnce将调用EventHub类成员函数getEvents。
?
?
从InputReader.h中的定义可知,InputMapper是一个抽象类。事实上,每个InputDevice在创建时(InputReader::createDeviceLocked)都会为此设备增加一个或多个Mapper,每个Mappr会根据设备类别的不同来分配一个相对应的InputMapper继承类对象。
?
?
mCursorButtonAccumulator.process(rawEvent);
mCursorScrollAccumulator.process(rawEvent);
mTouchButtonAccumulator.process(rawEvent);
mSingleTouchMotionAccumulator.process(rawEvent);
看来输入事件的处理关键在TouchInputMapper::sync。
?
?
?
?
?
QueuedInputListener::notifyMotion (InputReader.mQueuedInputListener->notifyMotion )。
QueuedInputListener类在InputListener.h和InputListener.cpp中定义和实现,其notify系列成员函数只是将传入的参数复制一份并存入数组成员变量mArgsQueue中。
相关文章推荐
- Android 输入事件系统之 EventHub 和 Input Lib(事件解析库)
- Android 输入系统解析 (1)
- 深度剖析 Android音频系统解析与改进
- Android 4.0 事件输入(Event Input)系统
- Android系统层的input设备解析
- 解析android中系统日期时间的获取
- 全面的Android文件目录解析和获取方法(包含对6.0系统的说明)
- Android 输入系统(三)InputReader
- Android系统架构的详细解析——很全面
- Android系统启动过程全解析
- Android系统中长按事件的实现机制解析
- Android4.1输入系统参数配置和输入事件校准
- 玩转安卓 Android系统文件夹结构解析(绝对有用)
- java 输入输出流和File简单解析(附android中文乱码问题解决)
- 安装、输入-LinuxNote3.WIn7与ubuntu双系统以及Android开发环境-by小雨
- Android系统启动流程(一)解析init进程启动过程
- 【android开发】手写签名系统的设计与实现之实现解析pdf文件(二)
- android 图片工具类 (图片压缩 图片长按缓存 Bitmap转Base64 Bitmap转File File转Bitmap 打开系统相册解析URI)
- 全面的Android文件目录解析和获取方法(包含对6.0系统的说明) simen201310 2016-08-28 15:52:12 浏览3290 评论0 移动开发与客户端 android 摘要
- Android 输入系统 与 按键