? ? ? 在sever端中。InputReader和InputDispatcher是native 层的两个线程,前者不断地从EventHub中读取事件(包含全部的事件。对不同的事件会做推断处理)。后者则不断地分发InputReader读取到的事件。而实际的分发操作时在InputPublish中进行的,它里面保存的有一个指向server端InputChannel端的指针。和一个指向ShareMemory(共享内存)的指针。当有事件要分发时,它会将事件写入到ShareMemory中,而且传递一个特定的字符串给InputChannel。由inutChannel将该字符串写入到管道中。在client端,一旦InputChannel从管道中读取到有事件分发过来,便会通知InPutConsumer从ShareMemory中读取详细的事件。并传递到framework层的InputQueue中。相同。一旦事件消费完毕,client端会通过管道告诉server端,事件已经消费完毕,流程与上面的似。
大致的流程就是这样。
另外。顺便说下这里的两个InputChannel,这两个InputChannel是在native 层的。他们在framework层各自有一个相应的InputChannel类,对于这两个framework层的InputChannel。client端的是在ViewRootImpl中的setView中new出来的,可是并未做不论什么初始化操作(真正的初始化操作是跟server端的一起在WMS中运行的)。也就是构造方法里面为空。
// Schedule the first layout -before- adding to the window
// manager, to make sure we do the relayout before receiving
// any other events from the system.
requestLayout();
if ((mWindowAttributes.inputFeatures
& WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL) == 0) {
mInputChannel = new InputChannel();
}
server端的InputChannel尽管是在server端创建的,但其创建过程是在client端发起的。ViewRootImpl中有server端的Session的代理,相同是setview方法中。通过Session代理运行server端Session的addToDisplay方法。该方法接受了client端的InputChannel方法
mOrigWindowType = mWindowAttributes.type;
mAttachInfo.mRecomputeGlobalAttributes = true;
collectViewAttributes();
res = mWindowSession.addToDisplay(mWindow, mSeq, mWindowAttributes,
getHostVisibility(), mDisplay.getDisplayId(),
mAttachInfo.mContentInsets, mInputChannel);
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/shouji/article-84984-2.html
一场战役