mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Throttle picture raster cache (flutter/engine#7759)
This decreases worst_frame_rasterizer_time_millis from 30ms to 10ms when we enabled picture raster cache in tiles_scroll (i.e., lower the threshold from 10 to 5).
This commit is contained in:
parent
84800939f6
commit
6a320ce6ae
@ -36,8 +36,11 @@ void RasterCacheResult::draw(SkCanvas& canvas, const SkPaint* paint) const {
|
||||
canvas.drawImage(image_, bounds.fLeft, bounds.fTop, paint);
|
||||
}
|
||||
|
||||
RasterCache::RasterCache(size_t threshold)
|
||||
: threshold_(threshold), checkerboard_images_(false), weak_factory_(this) {}
|
||||
RasterCache::RasterCache(size_t threshold, size_t picture_cache_limit_per_frame)
|
||||
: threshold_(threshold),
|
||||
picture_cache_limit_per_frame_(picture_cache_limit_per_frame),
|
||||
checkerboard_images_(false),
|
||||
weak_factory_(this) {}
|
||||
|
||||
RasterCache::~RasterCache() = default;
|
||||
|
||||
@ -182,6 +185,9 @@ bool RasterCache::Prepare(GrContext* context,
|
||||
SkColorSpace* dst_color_space,
|
||||
bool is_complex,
|
||||
bool will_change) {
|
||||
if (picture_cached_this_frame_ >= picture_cache_limit_per_frame_) {
|
||||
return false;
|
||||
}
|
||||
if (!IsPictureWorthRasterizing(picture, will_change, is_complex)) {
|
||||
// We only deal with pictures that are worthy of rasterization.
|
||||
return false;
|
||||
@ -211,6 +217,7 @@ bool RasterCache::Prepare(GrContext* context,
|
||||
entry.image = RasterizePicture(picture, context, transformation_matrix,
|
||||
dst_color_space, checkerboard_images_);
|
||||
}
|
||||
picture_cached_this_frame_++;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -232,6 +239,7 @@ void RasterCache::SweepAfterFrame() {
|
||||
using LayerCache = LayerRasterCacheKey::Map<Entry>;
|
||||
SweepOneCacheAfterFrame<PictureCache, PictureCache::iterator>(picture_cache_);
|
||||
SweepOneCacheAfterFrame<LayerCache, LayerCache::iterator>(layer_cache_);
|
||||
picture_cached_this_frame_ = 0;
|
||||
}
|
||||
|
||||
void RasterCache::Clear() {
|
||||
|
||||
@ -42,7 +42,15 @@ struct PrerollContext;
|
||||
|
||||
class RasterCache {
|
||||
public:
|
||||
explicit RasterCache(size_t threshold = 3);
|
||||
// The default max number of picture raster caches to be generated per frame.
|
||||
// Generating too many caches in one frame may cause jank on that frame. This
|
||||
// limit allows us to throttle the cache and distribute the work across
|
||||
// multiple frames.
|
||||
static constexpr int kDefaultPictureCacheLimitPerFrame = 3;
|
||||
|
||||
explicit RasterCache(
|
||||
size_t threshold = 3,
|
||||
size_t picture_cache_limit_per_frame = kDefaultPictureCacheLimitPerFrame);
|
||||
|
||||
~RasterCache();
|
||||
|
||||
@ -67,6 +75,8 @@ class RasterCache {
|
||||
// 1. The picture is not worth rasterizing
|
||||
// 2. The matrix is singular
|
||||
// 3. The picture is accessed too few times
|
||||
// 4. There are too many pictures to be cached in the current frame.
|
||||
// (See also kDefaultPictureCacheLimitPerFrame.)
|
||||
bool Prepare(GrContext* context,
|
||||
SkPicture* picture,
|
||||
const SkMatrix& transformation_matrix,
|
||||
@ -110,6 +120,8 @@ class RasterCache {
|
||||
}
|
||||
|
||||
const size_t threshold_;
|
||||
const size_t picture_cache_limit_per_frame_;
|
||||
size_t picture_cached_this_frame_ = 0;
|
||||
PictureRasterCacheKey::Map<Entry> picture_cache_;
|
||||
LayerRasterCacheKey::Map<Entry> layer_cache_;
|
||||
bool checkerboard_images_;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user