From 646130aff69e333014c991bf251384eb899fb91e Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 5 Feb 2020 15:23:44 -0800 Subject: [PATCH] Add missing raster cache LRU accounting RasterCache::Get() methods were not updating the RasterCache::Entry access_count and used_this_frame fields, as is done in RasterCache::Prepare(). This can result in onscreen images being evicted from the cache as new entries are created (e.g. as new elements scroll onscreen). --- flow/raster_cache.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/flow/raster_cache.cc b/flow/raster_cache.cc index a3bbb20b9b05a..39c80ee7b677d 100644 --- a/flow/raster_cache.cc +++ b/flow/raster_cache.cc @@ -231,13 +231,25 @@ RasterCacheResult RasterCache::Get(const SkPicture& picture, const SkMatrix& ctm) const { PictureRasterCacheKey cache_key(picture.uniqueID(), ctm); auto it = picture_cache_.find(cache_key); - return it == picture_cache_.end() ? RasterCacheResult() : it->second.image; + if (it == picture_cache_.end()) { + return RasterCacheResult(); + } + Entry& entry = const_cast(it->second); + entry.access_count = ClampSize(entry.access_count + 1, 0, access_threshold_); + entry.used_this_frame = true; + return entry.image; } RasterCacheResult RasterCache::Get(Layer* layer, const SkMatrix& ctm) const { LayerRasterCacheKey cache_key(layer->unique_id(), ctm); auto it = layer_cache_.find(cache_key); - return it == layer_cache_.end() ? RasterCacheResult() : it->second.image; + if (it == layer_cache_.end()) { + return RasterCacheResult(); + } + Entry& entry = const_cast(it->second); + entry.access_count = ClampSize(entry.access_count + 1, 0, access_threshold_); + entry.used_this_frame = true; + return entry.image; } void RasterCache::SweepAfterFrame() {