feat: refine

This commit is contained in:
LiuBinPeng
2022-05-30 15:02:31 +08:00
parent 538801e651
commit 6cd0cf5144
60 changed files with 135 additions and 1487 deletions

View File

@@ -2,13 +2,13 @@
## 渲染机制
![](https://raw.githubusercontent.com/FantasticLBP/knowledge-kit/assets/RenderStructure.png)
![](./../assets/RenderStructure.png)
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最终显示到屏幕上。
![](https://raw.githubusercontent.com/FantasticLBP/knowledge-kit/assets/RenderPipeline.png)
![](./../assets/RenderPipeline.png)
- Core Animation 提交会话(事务),包括自己和子树(view hierarchy) 的布局状态
@@ -20,13 +20,13 @@ iOS 图形界面的显示是一个复杂的流程,一部分数据通过 Core G
## Core Animation
![](https://raw.githubusercontent.com/FantasticLBP/knowledge-kit/assets/APM-CoreAnimationPipeline.png)
![](./../assets/APM-CoreAnimationPipeline.png)
可以看到 Core Animation pipeline 由4部分组成Application 层的 Core Animation 部分、Render Server 中的 Core Animation 部分、GPU 渲染、显示器显示。
### Application 层 Core Animation 部分
![](https://raw.githubusercontent.com/FantasticLBP/knowledge-kit/assets/CoreAnimationCommit.png)
![](./../assets/CoreAnimationCommit.png)
- 布局(Layout)`layoutSubviews``addSubview`,这里通常是 CPU、IO 繁忙
@@ -52,7 +52,7 @@ Render Server 是一个独立的渲染进程,当收到来自 Application 的 (
## UIView 绘制流程
![](https://raw.githubusercontent.com/FantasticLBP/knowledge-kit/assets/UIRenderPipeline.png)
![](./../assets/UIRenderPipeline.png)
- 每个 UIView 都有一个 CALayerlayer 属性都有 contentscontents 其实是一块缓存,叫做 backing store
@@ -60,7 +60,7 @@ Render Server 是一个独立的渲染进程,当收到来自 Application 的 (
- 当 backing store 写完后,通过 Render Server 交给 GPU 去渲染,最后显示到屏幕上
![](https://raw.githubusercontent.com/FantasticLBP/knowledge-kit/assets/UIViewRenderPipeline.png)
![](./../assets/UIViewRenderPipeline.png)
- 调用 `[UIView setNeedsDisplay]` 方法时,并没有立即执行绘制工作,而是马上调用 `[view.layer setNeedsDisplay]` 方法,给当前 layer 打上标记
@@ -76,7 +76,7 @@ Render Server 是一个独立的渲染进程,当收到来自 Application 的 (
### 系统绘制流程
![](https://raw.githubusercontent.com/FantasticLBP/knowledge-kit/assets/iOSRenderProcess.png)
![](./../assets/iOSRenderProcess.png)
- 首先 CALayer 内部会创建一个 CGContextRef在 drwaRect 方法中,可以通过上下文堆栈取出 context拿到当前视图渲染上下文也就是 backing store
@@ -88,7 +88,7 @@ Render Server 是一个独立的渲染进程,当收到来自 Application 的 (
### 异步绘制流程
![](https://raw.githubusercontent.com/FantasticLBP/knowledge-kit/assets/iOSAsyncRender.png)
![](./../assets/iOSAsyncRender.png)
- 如果 layer 有代理对象,且代理对象实现了代理方法,则可以进入异步绘制流程