in packages/core/src/compositing/raster-cache.ts [204:236]
static rasterizePicture(picture: Picture, matrix: Matrix) {
const cacheBounds = RasterCache.getCacheBounds(picture.cullRect, matrix)
// 太大了
if (
cacheBounds.width > RasterCache.DEFAULT_PICTURE_CACHE_LONG_SIDE
|| cacheBounds.height > RasterCache.DEFAULT_PICTURE_CACHE_LONG_SIDE
|| cacheBounds.width * cacheBounds.height > RasterCache.DEFAULT_PICTURE_CACHE_AREA) {
return undefined
}
const surface = RasterCache.surfacePool.take()
const frame = surface.acquireFrame(Size.fromWH(cacheBounds.width, cacheBounds.height))
const canvas = frame.canvas
// 从池子里拿出来的 frame,可能留有上一帧的渲染结果,需要手动 reset
canvas.resetTransform()
canvas.clear()
// 然后执行缓存的绘制
canvas.translate(-cacheBounds.left, -cacheBounds.top)
canvas.transform(matrix)
canvas.drawPicture(picture)
if (DebugFlags.paintRasterCacheWaterMark) {
canvas.resetTransform()
canvas.debugDrawCheckerboard(1)
}
return new RasterCacheResult(
surface.toImage(),
picture.cullRect,
surface,
)
}