Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[勘误] 14.6.5 创建新的 PictureLayer #214

Open
hanger23 opened this issue Jan 12, 2024 · 0 comments
Open

[勘误] 14.6.5 创建新的 PictureLayer #214

hanger23 opened this issue Jan 12, 2024 · 0 comments

Comments

@hanger23
Copy link

原文是:
当绘制完 RepaintBoundary 走到 childContext.stopRecordingIfNeeded() 时, childContext 对应的 Layer 是 OffsetLayer1,而 _currentLayer 是 PictureLayer1, _canvas 对应的是 Canvas1。我们看到实现很简单,先将 Canvas1 的绘制产物保存在 PictureLayer1 中,然后将一些变量都置空。
以下是我的理解:我的是3.3.4版本
当没有 Text5 时,Row的孩子只有2个,所以绘制完 RepaintBoundary,就会走到childContext.stopRecordingIfNeeded(),这没问题的。
但当有 Text5 时,Row的孩子有3个,绘制完 RepaintBoundary并不会走到childContext.stopRecordingIfNeeded(),而是在绘制RepaintBoundary前就stopRecordingIfNeeded()了,所以绘制完 RepaintBoundary,再绘制Text5 依然使用了新的 PictureLayer 和 Canvas,所以结论没问题。只有所有孩子绘制完毕,才会走到childContext.stopRecordingIfNeeded()。

看源码:
void paintChild(RenderObject child, Offset offset) {
//如果子节点是绘制边界节点
if (child.isRepaintBoundary) {
//结束上一个兄弟的绘制,保存绘制产物到父的 pictureLayer,并_canvas 置空
stopRecordingIfNeeded();
if (child._needsPaint || !child._wasRepaintBoundary) {
//调用repaintCompositedChild,内部产生新的PaintingContext
repaintCompositedChild(child, debugAlsoPaintedParent: true);
} else {
...
}
...
} else {
//绘制子项
child._paintWithContext(this, offset);
}
}
不知道我的理解是否有误?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant