1、刷新率介绍
我们先来理一下基本的概念:
1、60 fps 的意思是说,画面每秒更新 60 次
2、这 60 次更新,是要均匀更新的,不是说一会快,一会慢,那样视觉上也会觉得不流畅
3、每秒 60 次,也就是 1/60 ~= 16.67 ms 要更新一次
4、一般来说屏幕的刷新率是硬件概念,意思是1秒显示60张图片。如果屏幕分辨率为60HZ,应用程序设置的刷新率要小于或等于60HZ。


2、图层介绍
2.1、绘制介绍
在Android渲染系统中,⽣产者是应⽤进程,消费者是SurfaceFlinger进程,两个不同的进程数据的交换就涉及跨 进程通信,⽽服务它们跨进程通信的组件是BufferQueue。BufferQueue就像是⼀个桥梁,让原本孤⽴的应⽤进程 和SurfaceFlinger进程联系在⼀起,有了BufferQueue这个桥梁,图形显示系统基本架构可变成如下:



Perfetto中SurfaceFlinger图层数据显示如下

代码环节中,ViewRootImpl.java中的drawSoftware
函数中,使用mSurface.lockCanvas(dirty)来获取SurfaceFlinger缓冲区

在surface.unlockCanvasAndPost(canvas);来释放缓冲区

2.2、卡顿是如何生成的呢?
既然出现了生产者和消费者,那么不是16.7ms类相关流程没有完成,是否就会感受到卡顿?
参考https://perfetto.dev/docs/data-sources/frametimeline

查看Perfetto log时,绿色表示正常绘制,其他颜色表示没按时绘制。

当APP绘制时长超过30帧后,对应在Log中有如下打印。

当APP Choreographer中来不及绘制时,是否就出现了卡顿呢?
答案是不一定,这个涉及到Buffer缓冲区设计
2.3、 Triple Buffer
Buffer缓冲区设计具体得参考
https://blog.csdn.net/flc2762/article/details/122881577