in packages/core/src/rendering/render-object.ts [1011:1055]
/* friend of RenderPipeline */paintWithContext(context: PaintingContext, offset: Point) {
assert(!this._debugDoingThisPaint, '节点不能单独重复调用 _paintWithContext')
if (this._layoutDirty) {
return
}
assert(() => {
if (this._needsCompositingDirty) {
if (this.parent) {
let visitedByParent = false
this.parent.visitChildren(child => {
if (child === this) {
visitedByParent = true
}
})
if (!visitedByParent) {
throw new Error(`节点未通过其父节点进行绘制`)
}
}
throw new Error(`不允许节点在 _needsCompositingDirty = true 时绘制`)
}
})
let debugLastActivePaint: RenderObject | undefined
assert(() => {
this._debugDoingThisPaint = true
debugLastActivePaint = RenderObject._debugActivePaint
RenderObject._debugActivePaint = this
assert(!this.repaintBoundary || this._layer !== null)
})
this._paintDirty = false
if (!this._hidden) {
try {
this.paint(context, offset)
this.onPaint?.(offset)
assert(!this._layoutDirty, '检测到 paint 方法中重新将 _layoutDirty 标记为 true')
assert(!this._paintDirty, '检测到 paint 方法中重新将 _paintDirty 标记为 true')
} catch (err) {
console.error(err)
}
}
assert(() => {
this.debugPaint(context, offset)
RenderObject._debugActivePaint = debugLastActivePaint
this._debugDoingThisPaint = false
})
}