来自 Android 线程 doc :
you must not manipulate your UI from a worker thread—you must do all manipulation to your user interface from the UI thread
所以我相信屏幕上的所有内容都是由UI 线程 呈现的。但在 Android Lollipop 中他们有 introduced一个RenderThread:
A new system-managed processing thread called RenderThread keeps animations smooth even when there are delays in the main UI thread
它是如何工作的? RenderThread 是否使用UI 线程 在屏幕上呈现动画(具有新属性的 View )?如果是这样,它为什么不阻塞 UI 线程?
最佳答案
RenderThread
依赖于 UI Thread
但它确实与最后提到的并行运行。
它的主要工作是在 GPU
上运行昂贵的计算,以清空 UI 线程
的繁重负载。
How does it work?
基本上,UI 线程
充当作业调度程序。它准备要在 RenderThread
上执行的命令管道。
GPU
不知道什么是动画;它只能理解基本命令,例如:
平移(x,y,z)
旋转(x,y)
或基本绘图工具:
drawCircle(centerX, centerY, radius, paint)
drawRoundRect(left, top, right, bottom, cornerRadiusX, cornerRadiusY, paint)
它们结合在一起形成了您在屏幕上看到的复杂动画。
Does the RenderThread use the UI thread to render animations (Views with new properties) on the screen?
不,它是异步运行的
If so, why doesn't it block the UI thread?
docs说明渲染分两个阶段执行:
View#draw
->UI 线程
DrawFrame
->RenderThread
,它基于View#draw
阶段执行工作。
在较低的层次上,当使用硬件加速时,延迟的渲染
由DisplayListCanvas执行。 .
在这个 Canvas
实现中,您可以找到上述绘图命令,例如 drawCircle
。
因此,DisplayListCanvas
也是 RenderNodeAnimator 的绘图目标,它运行基本的动画命令(translate
、scale
、alpha
、...)。
关于android - RenderThread 与 UI 线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48618444/