android GUI 流程记录

本文详细解析了Android中ViewRootImpl与WindowManagerService(WMS)之间的交互过程,包括按键事件处理流程、Activity恢复时ViewRootImpl的主要操作及布局绘制流程。深入探讨了从按键事件分发到Surface创建、从measure到draw的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


ViewRootImpl 与 wms

 

 

ViewRootImple里的 WindowSeesion是WindowManagerService的proxy, 通过这个句柄来调用WMS的功能
而W是 wms用来控制app window的句柄, 比如dispatch各种事件,focus,move,resize等, 都是由wms控制w来完成
android 按键触屏分发大致的流程:
·  WMS所在的SystemServer进程接收到按键事件。
·  WMS找到UI位于屏幕顶端的进程所对应的IWindow对象,这是一个Bp端对象。
·  调用这个IWindow对象的dispatchKey。IWindow对象的Bn端位于ViewRoot中,ViewRoot再根据内部View的位置信息找到真正处理这个事件的View,最后调用dispatchKey函数完成按键的处理。


activity resume时:

ViewRootImpl:
setView()->:
(1)mView = view; //decorView
(2)requestLayout();
(3)mWindowSession.addToDisplay(mWindow, mSeq, mWindowAttributes, //mWindow 即W, 把W句柄给wms
getHostVisibility(), mDisplay.getDisplayId(),
mAttachInfo.mContentInsets, mInputChannel);

 

requestLayout()->scheduleTraversals()->TraversalRunnable::doTraversal()->performTraversals():
(1)relayoutResult = relayoutWindow(params, viewVisibility, insetsPending);
int relayoutResult = mWindowSession.relayout(
mWindow, mSeq, params,
(int) (mView.getMeasuredWidth() * appScale + 0.5f),
(int) (mView.getMeasuredHeight() * appScale + 0.5f),
viewVisibility, insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0,
mWinFrame, mPendingOverscanInsets, mPendingContentInsets, mPendingVisibleInsets,
mPendingConfiguration, mSurface);
|
Binder
|
WindowManagerService:
relayoutWindow()->:
...
//在wms进程中创建surface并且拷贝到app进程中去
//createSurfaceLocked() --JNI--> nativeCreate, nativeSetXXX 等在c++层实现 -> SurfaceComposerClient::createSurface
①SurfaceControl surfaceControl = winAnimator.createSurfaceLocked();
-> new SurfaceControl() --JNI--> nativeCreate() -> SurfaceComposerClient::createSurface ->
②if (surfaceControl != null) {
outSurface.copyFrom(surfaceControl); //把surface对象从wms进程拷贝到app进程, java层的surface对象都只是对native对象的封装,包含一个native surface的指针
if (SHOW_TRANSACTIONS) Slog.i(TAG,
" OUT SURFACE " + outSurface + ": copied");
} else {
// For some reason there isn't a surface. Clear the
// caller's object so they see the same state.
outSurface.release();
}
...
(2)performMeasure()->mView.measure(childWidthMeasureSpec, childHeightMeasureSpec); //测量长宽
(3)performLayout()->host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight()); //确定位置
(4)performDraw()->draw(fullRedrawNeeded) //画图
①Surface surface = mSurface;
...
②drawSoftware(surface, attachInfo, yoff, scalingRequired, dirty))
canvas = mSurface.lockCanvas(dirty);
...
mView.draw(canvas);
...
surface.unlockCanvasAndPost(canvas);

 

转载于:https://www.cnblogs.com/hushpa/p/6502369.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值