1// Copyright 2013 The Flutter Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5part of engine; 6 7/// A cache of [Picture]s that have already been rasterized. 8/// 9/// In the case of a [Picture] with a lot of complex drawing commands, it can 10/// be faster to rasterize that [Picture] into it's own canvas and composite 11/// that canvas into the scene rather than replay the drawing commands for that 12/// picture into the overall scene. 13/// 14/// This class is responsible for deciding if a [Picture] should be cached and 15/// for creating the cached [Picture]s that can be drawn directly into the 16/// canvas. 17class RasterCache { 18 /// Make a decision on whether to cache [picture] under transform [matrix]. 19 /// 20 /// This is based on heuristics such as how many times [picture] has been 21 /// drawn before and the complexity of the drawing commands in [picture]. 22 /// 23 /// We also take into account the current transform [matrix], because, for 24 /// example, a picture may be rasterized with the identity transform, but 25 /// when it is used, the transform is a 3x scale. In this case, compositing 26 /// the rendered picture would result in pixelation. So, we must use both 27 /// the picture and the transform as a cache key. 28 /// 29 /// The flag [isComplex] is a hint to the raster cache that this picture 30 /// contains complex drawing commands, and as such should be more strongly 31 /// considered for caching. 32 /// 33 /// The flag [willChange] is a hint to the raster cache that this picture 34 /// will change, and so should be less likely to be cached. 35 void prepare( 36 ui.Picture picture, Matrix4 matrix, bool isComplex, bool willChange) {} 37 38 /// Gets a raster cache result for the [picture] at transform [matrix]. 39 RasterCacheResult get(ui.Picture picture, Matrix4 matrix) => 40 RasterCacheResult(); 41} 42 43/// A cache entry for a given picture and matrix. 44class RasterCacheResult { 45 /// Whether or not this result represents a rasterized picture that can be 46 /// drawn into the scene. 47 bool get isValid => false; 48 49 /// Draws the rasterized picture into the [canvas]. 50 void draw(SkCanvas canvas) {} 51} 52