Choreographer原理
Choreographer启动流程
public ViewRootImpl(Context context, Display display) {
...
//获取Choreographer实例
mChoreographer = Choreographer.getInstance();
...
}getInstance()
//frameworks/base/core/java/android/view/Choreographer.java
public static Choreographer getInstance() {
return sThreadInstance.get();
}
// Thread local storage for the choreographer.
private static final ThreadLocal<Choreographer> sThreadInstance =
new ThreadLocal<Choreographer>() {
@Override
protected Choreographer initialValue() {
//获取当前线程Looper
Looper looper = Looper.myLooper();
if (looper == null) {
throw new IllegalStateException("The current thread must have a looper!");
}
Choreographer choreographer = new Choreographer(looper, VSYNC_SOURCE_APP);
if (looper == Looper.getMainLooper()) {
mMainInstance = choreographer;
}
return choreographer;
}
};创建Choreographer
创建FrameHandler
postCallback
postCallbackDelayedInternal
创建FrameDisplayEventReceiver
Vysnc回调流程
handleEvent
dispatchVsync
onVsync
doFrame()
doCallbacks
CallbackRecord
动画显示过程
参考
最后更新于