import type { Canvas, Image, Picture } from '../canvas'; import { Matrix, Rect } from '../math'; import { Surface } from '../surface'; export type RasterCacheKey = string; export type RasterCacheEntry = { key: RasterCacheKey; usedThisFrame: boolean; accessCount: number; failed: boolean; result?: RasterCacheResult; }; export declare class RasterCacheResult { private readonly image; private readonly paintBounds; readonly surface?: Surface | undefined; constructor(image: Image, paintBounds: Rect, surface?: Surface | undefined); /** * 将缓存的内容绘制到 Canvas 上,如果绘制成功返回 true,否则返回 false * * todo(haocong): 增加 canvas.getTransform 方法,避免传递 matrix */ draw(canvas: Canvas, matrix: Matrix): void; } export declare class RasterCache { static readonly DEFAULT_ACCESS_THRESHOLD = 3; static readonly DEFAULT_PICTURE_CACHE_LIMIT_PER_FRAME = 1; /** * 缓存的大小,默认值是 5 分之一 4K 分辨率 * * 例如,如长边为 8192px,短边最大可以是 101 */ static readonly DEFAULT_PICTURE_CACHE_AREA: number; /** * 缓存的最大边长 */ static readonly DEFAULT_PICTURE_CACHE_LONG_SIDE = 8192; static readonly DEFAULT_SURFACE_POOL_CAPACITY = 4; /** * 当 Picture 的 drawOps 超过该数值时,视为复杂的 Picture,可以被缓存,否则不会被缓存 */ static readonly COMPLEX_PICTURE = 5; private static readonly surfacePool; protected entries: Map; private accessThreshold; private pictureCacheLimitPerFrame; private pictureCachedThisFrame; protected onDeleteEntry(entry: RasterCacheEntry): void; prepareBeforeFrame(): void; sweepAfterFrame(): void; private getOrCreateRasterCacheEntry; private getRasterCacheEntry; prepare(picture: Picture, matrix: Matrix, willChange: boolean): boolean; protected updateCacheResult(entry: RasterCacheEntry, picture: Picture, matrix: Matrix): void; static rasterizePicture(picture: Picture, matrix: Matrix): RasterCacheResult | undefined; drawPicture(picture: Picture, canvas: Canvas, matrix: Matrix): boolean; static getCacheBounds(bounds: Rect, matrix: Matrix): Rect; static getCacheKey(picture: Picture, matrix: Matrix): RasterCacheKey; }