Choreographer实例化 //Choreographer.java public static Choreographer getInstance() { return...= new ThreadLocal() { @Override protected Choreographer initialValue...Choreographer choreographer = new Choreographer(looper, VSYNC_SOURCE_APP); //......return choreographer; } }; private Choreographer(Looper looper, int vsyncSource...小结1 通过上面一系列方法,我们能得到一个初步的逻辑过程了: ViewRootImpl初始化的时候,会实例化Choreographer对象,也就是获取当前线程(一般就是主线程)对应的Choreographer
Choreographer对于一些同学来说可能比较陌生,但是,它其实出场率是极高的。View的三大流程就是靠着Choreographer来实现的,翻译过来这个单词的意思是“编舞者”。...; } //初始化 Choreographer choreographer = new Choreographer(looper, VSYNC_SOURCE_APP...回到Choreographer的构造方法 //Choreographer.java private Choreographer(Looper looper, int vsyncSource) {...Choreographer 流程原理 现在我们来说一下Choreographer的postCallback(),也就是ViewRootImpl使用的地方 //Choreographer.java //ViewRootImpl...Choreographer的使命也基本完成了。 上面就是Choreographer的工作流程。
Choreographer: Skipped 60 frames! The application may be doing too much work on its main thread....Skipped 2.1 那我们来分析一下Choreographer Skipped生成的流程 private Choreographer(Looper looper, int vsyncSource...2.4 总结 Choreographer Skipped真正反映的是onVsync和doFrame两个方法调用的时间间隔 其实这句话并不准确,我在[037]Choreographer Skipped含义再探中进行了修正...四、为什么要理解Choreographer Skipped 因为在解决性能问题的时候,尤其是解决启动慢,丢帧问题的时候,大家要完整的梳理整个主线程中处理所有的Message任务,然后自己想办法写出Demo...尾巴 在[037]Choreographer Skipped含义再探中我会介绍另外一种Demo。
Choreographer中postFrameCallback的调用时机 当下一个Vsync信号来临时,会按照Type取出CallbackQuenes中的链表里面存储的CallBackRecord进行遍历其...比如这部分讲解的postFrameCallback在Choreographer中会将其转换为FrameCallback的Token和ANIMATION的Callback的type,而像其他的postCallBacl
前言 在[036]Choreographer Skipped真正含义中,我介绍了一种可以产生Choreographer Skipped的情况。...那还有没有其他方式可以产生这个Choreographer Skipped呢?...D KobeWang2: onClick : start D KobeWang2: onClick : end I Choreographer: Skipped 60 frames!...三、总结 其实有很多Demo可以产生Choreographer Skipped,但是不管你怎么写,肯定是下面两种场景之一。...场景二 3.3 更正 更正一下我在[036]Choreographer Skipped真正含义说的话 Choreographer Skipped真正反映的是onVsync和doFrame两个方法调用的时间间隔
Choreographer机制,用于同Vsync机制配合,实现统一调度界面绘图。...1、Choreographer的构造 Choreographer是线程级别的单例,并且具有处理当前线程消息循环队列的功能。...(); } //每个线程一个Choreographer实例 private static final ThreadLocal sThreadInstance...的消息处理 3.1、Choreographer接受消息 public final class Choreographer { //Input callback....回调 2、Choreographer的使用部分讲述了ViewRootImpl使用Choreographer的使用,那么我们现在来看一下ViewRootImpl对Choreographer回调时间的处理。
这次重构的三个关键点 VSynch 垂直同步 Triple Buffer 三重缓存 Choreographer 编舞者 这篇文章我们主要聊一聊Choregrapher,后续的我们写关于其他。...choreographer 界面的显示大体会经过CPU的计算-> GPU合成栅格化->显示设备显示。...这个在android4.1及以后的版本中加入了Choreographer这个类,让我们扒开看看他是怎么实现的。 ?..., frameTimeNanos); doCallbacks(Choreographer.CALLBACK_COMMIT, frameTimeNanos); }...三、小结 Choreographer对外提供了postCallback等方法,最终他们内部都是通过调用postCallbackDelayedInternal()实现这个方法主要会做两件事情 存储Action
的Choreographer.CALLBACK_TRAVERSAL队列中添加了一个mTraversalRunnable,同时申请VSYNC,这个mTraversalRunnable要一直等到申请的VSYNC...再VSYNC到来之后,Choreographer利用Handler将FrameDisplayEventReceiver封装成一个异步Message,发送到UI线程的MessageQueue, private...--真正开始处理业务--> Trace.traceBegin(Trace.TRACE_TAG_VIEW, "Choreographer#doFrame"); mFrameInfo.markAnimationsStart(); doCallbacks(Choreographer.CALLBACK_ANIMATION...--不知道干啥的--> doCallbacks(Choreographer.CALLBACK_COMMIT, frameTimeNanos); } finally {
本节就来讲 "drawing with VSync" 的实现——Choreographer。 Choreographer,意为 舞蹈编导、编舞者。...Choreographer,是一个Java类,包路径android.view.Choreographer。类注释是“协调动画、输入和绘图的计时”。...接下来,就是分析的重点——Choreographer。...; } Choreographer choreographer = new Choreographer(looper, VSYNC_SOURCE_APP)...好了,Choreographer整个代码逻辑都讲完了,引用《Android 之 Choreographer 详细分析》的流程图: ?
at android.view.Choreographer...$CallbackRecord.run(Choreographer.java:761)...at android.view.Choreographer.doCallbacks(Choreographer.java:574)...at android.view.Choreographer.doFrame(Choreographer.java:544)...at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
Handler 发送异步消息到主线程(这个线程是初始化 Choreographer 的线程,可以是主线程也可以是其他线程,每个线程都可以有一个 Choreographer 对象)Choreographer.FrameDisplayEventReceiver...; } Choreographer choreographer = new Choreographer(looper, VSYNC_SOURCE_APP);...(); // ThreadLocal.get 方法会回调 initialValue() 来创建实例 }Choreographer 是线程内单例的Choreographer 的 5 种 callback...监控帧率的原理前面提到过每一帧会调用 android.view.Choreographer#doFrame() 方法来处理逻辑从 Choreographer 的队列数组 mCallbackQueues...里面取出 Choreographer.
初始化 Choreographer,通过 Threadlocal 存储 mChoreographer = Choreographer.getInstance(); ...... } 在...> Choreographer.java public static Choreographer getInstance() { return sThreadInstance.get(); }...; } // 新建 Choreographer 对象 Choreographer choreographer = new Choreographer(looper...再回到 Choreographer,我们来看一下它的构造函数。...介绍完 Choreographer 是如何初始化的,再回到 Choreographer 发送任务那块。
Choreographer单例是怎么实现的?保存在哪里? 刚才我们看到了编舞者Choreographer的身影,那么它又是从哪里来的呢?...; } Choreographer choreographer = new Choreographer(looper, VSync_SOURCE_APP)...细节就不说了,ThreadLocal主要是保证一个线程对应一个实例,Choreographer一般只存在于主线程,所以就是用于单例。 Choreographer怎么处理绘制任务呢?...VSync信号到来的时候,Choreographer会怎么操作? 接下来就看看垂直同步信号来的时候,Choreographer做了啥。...总结:Choreographer是什么? Choreographer到底是什么呢? 是View绘制、动画等界面变动任务的接收和执行者。
at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:5909) at android.view.Choreographer...$CallbackRecord.run (Choreographer.java:767) at android.view.Choreographer.doCallbacks(Choreographer.java...:580) at android.view.Choreographer.doFrame(Choreographer.java:550) at android.view.Choreographer...$FrameDisplayEventReceiver.run (Choreographer.java:753) at android.os.Handler.handleCallback(
ViewRootImpl.java:5779) at android.view.Choreographer...$CallbackRecord.run(Choreographer.java:767)...at android.view.Choreographer.doCallbacks(Choreographer.java:580)...at android.view.Choreographer.doFrame(Choreographer.java:550)...at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
在Android中, Vysnc 信号的产生是由底层 HWComposer 负责的,而通知应用进行刷新,是Java层的 Choreographer ,Android整个屏幕刷新的核心就在于这个 Choreographer...它就是答案~ 2.3 Choreographer.postCallback() 先来简单说一下 Choreographer , Choreographer 中文翻译叫 编舞者 ,它的主要作用是进行系统协调的...private static final ThreadLocal<Choreographer sThreadInstance = new ThreadLocal<Choreographer...; } Choreographer choreographer = new Choreographer(looper, VSYNC_SOURCE_APP); if (...looper == Looper.getMainLooper()) { mMainInstance = choreographer; } return choreographer
#postCallback 触发绘制流程 往上查找,找到是 Choreographer#postCallback 触发了整个绘制流程, Choreographer 的 postCallback 方法中也是通过一个...Choreographer initialValue() { // 对象是主线程实例化的,所以这个是主线程 looper Looper looper =...; } Choreographer choreographer = new Choreographer(looper, VSYNC_SOURCE_APP)...for the SF choreographer....private static final ThreadLocal sSfThreadInstance = new ThreadLocal<Choreographer
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600) at android.view.Choreographer...$CallbackRecord.run(Choreographer.java:761) at android.view.Choreographer.doCallbacks(Choreographer.java...:574) at android.view.Choreographer.doFrame(Choreographer.java:544) at android.view.Choreographer...$FrameDisplayEventReceiver.run(Choreographer.java:747) at android.os.Handler.handleCallback(Handler.java
如 SM、Skipped frames 这类指标,由于其基础数据取自 Choreographer,若 某些 Surface 的绘制不依赖于 Choreographer ,则这些指标无法衡量该 Surface...) 先说一句有点绕口的话: Choreographer 是依据 Choreographer 绘制的 Surface 在 UI 绘制过程中最为核心的机制。...那么,当 Choreographer 接收到 VSYNC 信号时,Choreographer 会调用 doFrame 函数依次对上述借口进行回调,从而进行渲染。...而这样的基础数据,Choreographer 自身也进行了记录。...优点:与 Choreographer.FrameCallback 方案一致。 该方案可以简单理解为通过注入的方式来实现与 Choreographer.FrameCallback 方案一样的目的。
领取专属 10元无门槛券
手把手带您无忧上云