@@ -42,18 +42,11 @@ void LayerRasterCacheItem::PrerollFinalize(PrerollContext* context,
4242 if (!context->raster_cache || !context->raster_cached_entries ) {
4343 return ;
4444 }
45- // We've marked the cache entry that we would like to cache so it stays
46- // alive, but if the following conditions apply then we need to set our
47- // state back to kDoNotCache so that we don't populate the entry later.
48- if (context->has_platform_view || context->has_texture_layer ||
49- !SkRect::Intersects (context->cull_rect , layer_->paint_bounds ())) {
50- return ;
51- }
5245 child_items_ = context->raster_cached_entries ->size () - child_items_;
46+ // Determine cache current layer or cache children.
5347 if (num_cache_attempts_ >= layer_cached_threshold_) {
5448 // the layer can be cached
5549 cache_state_ = CacheState::kCurrent ;
56- context->raster_cache ->MarkSeen (key_id_, matrix_);
5750 } else {
5851 num_cache_attempts_++;
5952 // access current layer
@@ -67,9 +60,25 @@ void LayerRasterCacheItem::PrerollFinalize(PrerollContext* context,
6760 RasterCacheKeyType::kLayerChildren );
6861 }
6962 cache_state_ = CacheState::kChildren ;
70- context->raster_cache ->MarkSeen (layer_children_id_.value (), matrix_);
7163 }
7264 }
65+ // We've marked the cache entry that we would like to cache so it stays
66+ // alive, but if the following conditions apply then we need to set our
67+ // state back to kDoNotCache so that we don't populate the entry later.
68+ if (context->has_platform_view || context->has_texture_layer ||
69+ !SkRect::Intersects (context->cull_rect , layer_->paint_bounds ())) {
70+ if (cache_state_ != CacheState::kNone ) {
71+ // Only touch the entry, do not to cache the layer or children.
72+ context->raster_cache ->Touch (GetId ().value (), matrix);
73+ cache_state_ = CacheState::kNone ;
74+ }
75+ return ;
76+ }
77+ // The layer can be cache, so we should create a entry.
78+ if (cache_state_ != CacheState::kNone ) {
79+ // Create Cache entry
80+ context->raster_cache ->MarkSeen (GetId ().value (), matrix);
81+ }
7382}
7483
7584std::optional<RasterCacheKeyID> LayerRasterCacheItem::GetId () const {
@@ -138,9 +147,9 @@ bool Rasterize(RasterCacheItem::CacheState cache_state,
138147
139148static const auto * flow_type = " RasterCacheFlow::Layer" ;
140149
141- bool LayerRasterCacheItem::TryToPrepareRasterCache (const PaintContext& context,
142- bool parent_cached ) const {
143- if (!context.raster_cache || parent_cached ) {
150+ bool LayerRasterCacheItem::TryToPrepareRasterCache (
151+ const PaintContext& context ) const {
152+ if (!context.raster_cache ) {
144153 return false ;
145154 }
146155 if (cache_state_ != kNone ) {
@@ -171,6 +180,10 @@ bool LayerRasterCacheItem::Draw(const PaintContext& context,
171180 return Draw (context, context.leaf_nodes_canvas , paint);
172181}
173182
183+ bool LayerRasterCacheItem::Touch (const PaintContext* context) const {
184+ return context->raster_cache ->Touch (GetId ().value (), matrix_);
185+ }
186+
174187bool LayerRasterCacheItem::Draw (const PaintContext& context,
175188 SkCanvas* canvas,
176189 const SkPaint* paint) const {
0 commit comments