mirror of
https://github.com/NohamR/knowledge-kit.git
synced 2026-05-25 04:17:17 +00:00
feat: refine
This commit is contained in:
@@ -2,13 +2,13 @@
|
||||
|
||||
## 渲染机制
|
||||
|
||||

|
||||

|
||||
|
||||
iOS 渲染框架可以分为4层,顶层是 UIKit,包括图形界面的高级 API 和常用的各种 UI 控件。UIKit 下层是 Core Animation,不要被名字误解了,它不光是处理动画相关,也在做图形渲染相关的事情(比如 UIView 的 CALayer 就处于 Core Animation 中)。Core Animation 之下就是由 OpenGL ES 和 CoreGraphics 组成的图形渲染层,OpenGL ES 主要操作 GPU 进行图形渲染,CoreGraphics 主要操作 CPU 进行图形渲染。上面3层都属于渲染图形软件层,再下层就是图形显示硬件层。
|
||||
|
||||
iOS 图形界面的显示是一个复杂的流程,一部分数据通过 Core Graphics、Core Image 有 CPU 预处理,最终通过 OpenGL ES 将数据传输给 GPU,最终显示到屏幕上。
|
||||
|
||||

|
||||

|
||||
|
||||
- Core Animation 提交会话(事务),包括自己和子树(view hierarchy) 的布局状态
|
||||
|
||||
@@ -20,13 +20,13 @@ iOS 图形界面的显示是一个复杂的流程,一部分数据通过 Core G
|
||||
|
||||
## Core Animation
|
||||
|
||||

|
||||

|
||||
|
||||
可以看到 Core Animation pipeline 由4部分组成:Application 层的 Core Animation 部分、Render Server 中的 Core Animation 部分、GPU 渲染、显示器显示。
|
||||
|
||||
### Application 层 Core Animation 部分
|
||||
|
||||

|
||||

|
||||
|
||||
- 布局(Layout):`layoutSubviews`、`addSubview`,这里通常是 CPU、IO 繁忙
|
||||
|
||||
@@ -52,7 +52,7 @@ Render Server 是一个独立的渲染进程,当收到来自 Application 的 (
|
||||
|
||||
## UIView 绘制流程
|
||||
|
||||

|
||||

|
||||
|
||||
- 每个 UIView 都有一个 CALayer,layer 属性都有 contents,contents 其实是一块缓存,叫做 backing store
|
||||
|
||||
@@ -60,7 +60,7 @@ Render Server 是一个独立的渲染进程,当收到来自 Application 的 (
|
||||
|
||||
- 当 backing store 写完后,通过 Render Server 交给 GPU 去渲染,最后显示到屏幕上
|
||||
|
||||

|
||||

|
||||
|
||||
- 调用 `[UIView setNeedsDisplay]` 方法时,并没有立即执行绘制工作,而是马上调用 `[view.layer setNeedsDisplay]` 方法,给当前 layer 打上标记
|
||||
|
||||
@@ -76,7 +76,7 @@ Render Server 是一个独立的渲染进程,当收到来自 Application 的 (
|
||||
|
||||
### 系统绘制流程
|
||||
|
||||

|
||||

|
||||
|
||||
- 首先 CALayer 内部会创建一个 CGContextRef,在 drwaRect 方法中,可以通过上下文堆栈取出 context,拿到当前视图渲染上下文也就是 backing store
|
||||
|
||||
@@ -88,7 +88,7 @@ Render Server 是一个独立的渲染进程,当收到来自 Application 的 (
|
||||
|
||||
### 异步绘制流程
|
||||
|
||||

|
||||

|
||||
|
||||
- 如果 layer 有代理对象,且代理对象实现了代理方法,则可以进入异步绘制流程
|
||||
|
||||
|
||||
Reference in New Issue
Block a user