../ui-drawing-in-android
By VickyeeUI Drawing in Android
- Android drawing process (Android 6.0): from ViewRootImpl.performTraversals → to child View.draw.
Reference: Android硬件加速原理与实现简介
What happens after calling View.invalidate()?
Reference: i) 源码分析-Android-View-invalidate 绘制流程, ii) Android-requestLayout与invalidate方法解析.
View.invalidate() -View.invalidate(boolean invalidateCache) --View.invalidateInternal(..) ---ViewGroup.invalidateChild(..) ----ViewParent.invalidateChildInParent(..) ----ViewRootImpl.invalidateChildInParent(..) -----ViewRootImpl.invalidateRectOnScreen(..) ------ViewRootImpl.scheduleTraversals(..) -------ViewRootImpl.mTraversalRunnable.run() --------ViewRootImpl.performTraversals() ---------ViewRootImpl.performMeasure(..) ----------View.measure(..) ---------ViewRootImpl.performLayout(..) ----------.. ---------ViewRootImpl.performDraw() ----------..
- From
ViewRootImpl.performDraw()
toView.onDraw()
calling, print the stack trace of calling hierarchy. - For
View.requestLayout()
, it will callViewRootImpl.requestLayout()
, thenViewRootImpl.mLayoutRequested
would be set to true, and this true variable would be used in the processing of deciding whether to perform measure & layout.
- From
How does Choreographer receive the VSync time plusing?
Main works done by Choreographer for each frame after receiving a VSync signal:
Reference: Android基于Choreographer的渲染机制详解
// Choreographer.java (android.view) // From onVSync() to self.run(), then doFrame() void doFrame(long frameTimeNanos, int frame) { // i) calculate skipped frames // ii) log frames in FrameInfo // iii) doCallbacks() ... doCallbacks(Choreographer.CALLBACK_INPUT, frameIntervalNanos); doCallbacks(Choreographer.CALLBACK_ANIMATION, frameIntervalNanos); doCallbacks(Choreographer.CALLBACK_INSETS_ANIMATION, frameIntervalNanos); doCallbacks(Choreographer.CALLBACK_TRAVERSAL, frameIntervalNanos); doCallbacks(Choreographer.CALLBACK_COMMIT, frameIntervalNanos); ... }
A Stack dumped within a custom imageView’s onDraw().
onDraw:34, LogImageView (com.tbuonomo.viewpagerdotsindicator.log) draw:24289, View (android.view) updateDisplayListIfDirty:23099, View (android.view) draw:23997, View (android.view) drawChild:4662, ViewGroup (android.view) dispatchDraw:4415, ViewGroup (android.view) updateDisplayListIfDirty:23090, View (android.view) draw:23997, View (android.view) drawChild:4662, ViewGroup (android.view) dispatchDraw:4415, ViewGroup (android.view) updateDisplayListIfDirty:23090, View (android.view) draw:23997, View (android.view) drawChild:4662, ViewGroup (android.view) drawChild:233, BaseDotsIndicator (com.tbuonomo.viewpagerdotsindicator) dispatchDraw:4415, ViewGroup (android.view) updateDisplayListIfDirty:23090, View (android.view) draw:23997, View (android.view) drawChild:4662, ViewGroup (android.view) dispatchDraw:4415, ViewGroup (android.view) 1 hidden frame draw:24292, View (android.view) updateDisplayListIfDirty:23099, View (android.view) draw:23997, View (android.view) drawChild:4662, ViewGroup (android.view) dispatchDraw:4415, ViewGroup (android.view) updateDisplayListIfDirty:23090, View (android.view) draw:23997, View (android.view) drawChild:4662, ViewGroup (android.view) dispatchDraw:4415, ViewGroup (android.view) updateDisplayListIfDirty:23090, View (android.view) draw:23997, View (android.view) drawChild:4662, ViewGroup (android.view) dispatchDraw:4415, ViewGroup (android.view) updateDisplayListIfDirty:23090, View (android.view) draw:23997, View (android.view) drawChild:4662, ViewGroup (android.view) dispatchDraw:4415, ViewGroup (android.view) updateDisplayListIfDirty:23090, View (android.view) draw:23997, View (android.view) drawChild:4662, ViewGroup (android.view) dispatchDraw:4415, ViewGroup (android.view) updateDisplayListIfDirty:23090, View (android.view) draw:23997, View (android.view) drawChild:4662, ViewGroup (android.view) dispatchDraw:4415, ViewGroup (android.view) draw:24292, View (android.view) draw:909, DecorView (com.android.internal.policy) updateDisplayListIfDirty:23099, View (android.view) updateViewTreeDisplayList:713, ThreadedRenderer (android.view) updateRootDisplayList:719, ThreadedRenderer (android.view) draw:821, ThreadedRenderer (android.view) draw:5634, ViewRootImpl (android.view) performDraw:5279, ViewRootImpl (android.view) performTraversals:4309, ViewRootImpl (android.view) doTraversal:2799, ViewRootImpl (android.view) run:10351, ViewRootImpl$TraversalRunnable (android.view) run:1525, Choreographer$CallbackRecord (android.view) run:1534, Choreographer$CallbackRecord (android.view) doCallbacks:1089, Choreographer (android.view) doFrame:979, Choreographer (android.view) run:1508, Choreographer$FrameDisplayEventReceiver (android.view) handleCallback:958, Handler (android.os) dispatchMessage:99, Handler (android.os) loopOnce:255, Looper (android.os) loop:364, Looper (android.os) main:8938, ActivityThread (android.app) 1 hidden frame run:572, RuntimeInit$MethodAndArgsCaller (com.android.internal.os) main:1053, ZygoteInit (com.android.internal.os)