ActivityThread、View、Activity等各个类中更新view、layout、window attrs时都会触发ViewRootImpl的scheduleTraversals逻辑,进入绘制流程:
ViewRootImpl:scheduleTraversals()
->Choreographer:postCallback()->postCallbackDelayedInternal()->scheduleFrameLocked()->scheduleVsync()
->ThreadedRenderer:notifyFramePending()
postCallback将traversal放入Choreographer队列,同时scheduleFrameLocked()->scheduleVsyncLocked(),待vsync信号从DisplayEventDispatcher回调上来后,进入FrameDisplayEventReceiver onVsync函数,异步消息后执行doFrame进行绘制。
notifyFramePending通知RenderProxy,新建RenderTask放入RenderThread栈顶:
Choreographer doFrame触发Application绘制流程
Choreographer:doFrame()->doCallbacks()->CallbackRecord:run()
->TraversalRunnable:run()
->ViewRootImpl:doTraversal()->performTraversals()->performDraw()->draw()
->ThreadRenderer:draw()→updateRootDisplayList()->updateViewTreeDisplayList()
->View:updateDisplayListIfDirty()->draw()->onDraw()
performTraversals中触发relayoutWindow、performMeasure、performLayout、performDraw等逻辑,updateRootDisplayList内会回调ViewRootImpl的onPreDraw和onPostDraw函数。
时序图如下: