RenderThread vs UI线程 [英] RenderThread vs UI thread

查看:872
本文介绍了RenderThread vs UI线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自Android线程文档:

From the Android Threads doc:

您不得从辅助线程中操作UI,而必须从UI线程中对用户界面进行所有操作

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中,他们引入了 一个 RenderThread :

So I believe that everything on the screen is rendered by the UI thread. But in Android Lollipop they have introduced a RenderThread:

名为RenderThread的新系统管理处理线程即使在主UI线程中存在延迟也可以使动画保持平滑

A new system-managed processing thread called RenderThread keeps animations smooth even when there are delays in the main UI thread

它如何工作? RenderThread 是否使用 UI线程在屏幕上渲染动画(具有新属性的视图)?如果是这样,为什么它不阻止 UI线程?

How does it work? 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?

推荐答案

RenderThread取决于UI Thread,但它确实与上一个提到的并行运行.

The RenderThread depends on the UI Thread but it does run in parallel along with the last mentioned one.

它的主要工作是在GPU上运行昂贵的计算,以清空UI Thread的沉重负担.

Its main job is to run expensive computation on the GPU in order to empty the heavy load of the UI Thread.

它如何工作?

How does it work?

基本上,UI Thread充当作业调度程序.它准备要在RenderThread上执行的命令管道.

Basically, the UI Thread acts as a job dispatcher. It prepares a pipeline of commands to be executed on the RenderThread.

GPU不知道动画是什么.它只能理解基本命令,例如:

The GPU doesn't know what an animation is; it can only understand basic commands, e.g:

  • translation(x,y,z)
  • rotate(x,y)
  • translation(x,y,z)
  • rotate(x,y)

或基本绘图实用程序:

  • drawCircle(centerX, centerY, radius, paint)
  • drawRoundRect(left, top, right, bottom, cornerRadiusX, cornerRadiusY, paint)
  • drawCircle(centerX, centerY, radius, paint)
  • drawRoundRect(left, top, right, bottom, cornerRadiusX, cornerRadiusY, paint)

它们结合在一起形成了您在屏幕上看到的复杂动画.

Combined together they form the complex animation you see on the screen.

RenderThread是否使用UI线程在屏幕上渲染动画(具有新属性的视图)?

Does the RenderThread use the UI thread to render animations (Views with new properties) on the screen?

否,它异步运行

如果是,为什么它不阻止UI线程?

If so, why doesn't it block the UI thread?

文档解释了渲染过程分为两个阶段:

The docs explain that the rendering is performed in two phases:

  1. View#draw-> UI Thread
  2. DrawFrame-> RenderThread,它根据View#draw阶段执行工作.
  1. View#draw -> UI Thread
  2. DrawFrame -> RenderThread, which performs work based on the View#draw phase.

在较低的级别上,当使用硬件加速时,延迟的rendering

On a lower level, when using hardware acceleration, the deferred rendering is executed by a DisplayListCanvas.

在此Canvas实现中,您可以找到上述的绘制命令,例如drawCircle.

In this Canvas implementation you can find the aforementioned drawing commands, such as drawCircle.

因此,DisplayListCanvas也是

As such, the DisplayListCanvas is also the drawing target of the RenderNodeAnimator, which runs the basic animation commands (translate, scale, alpha, ...).

这篇关于RenderThread vs UI线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆