您的位置:首页 > 移动开发 > Android开发

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中。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: