@@ -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 {
@@ -111,19 +120,20 @@ bool Rasterize(RasterCacheItem::CacheState cache_state,
111120 .leaf_nodes_canvas = canvas,
112121 .gr_context = paint_context.gr_context ,
113122 .dst_color_space = paint_context.dst_color_space ,
114- .view_embedder = paint_context. view_embedder ,
123+ .view_embedder = nullptr ,
115124 .raster_time = paint_context.raster_time ,
116125 .ui_time = paint_context.ui_time ,
117126 .texture_registry = paint_context.texture_registry ,
118- .raster_cache = paint_context.raster_cache ,
127+ .raster_cache = layer-> subtree_has_platform_view () ? nullptr : paint_context.raster_cache ,
119128 .checkerboard_offscreen_layers = paint_context.checkerboard_offscreen_layers ,
120129 .frame_device_pixel_ratio = paint_context.frame_device_pixel_ratio ,
121130 // clang-format on
122131 };
123-
124132 switch (cache_state) {
125133 case RasterCacheItem::CacheState::kCurrent :
126- FML_DCHECK (layer->needs_painting (context));
134+ if (!layer->needs_painting (context)) {
135+ return false ;
136+ }
127137 layer->Paint (context);
128138 break ;
129139 case RasterCacheItem::CacheState::kChildren :
@@ -140,7 +150,11 @@ static const auto* flow_type = "RasterCacheFlow::Layer";
140150
141151bool LayerRasterCacheItem::TryToPrepareRasterCache (const PaintContext& context,
142152 bool parent_cached) const {
143- if (!context.raster_cache || parent_cached) {
153+ if (!context.raster_cache ) {
154+ return false ;
155+ }
156+ if (parent_cached) {
157+ context.raster_cache ->Touch (GetId ().value (), matrix_);
144158 return false ;
145159 }
146160 if (cache_state_ != kNone ) {
@@ -159,7 +173,7 @@ bool LayerRasterCacheItem::TryToPrepareRasterCache(const PaintContext& context,
159173 GetId ().value (), r_context,
160174 [ctx = context, cache_state = cache_state_,
161175 layer = layer_](SkCanvas* canvas) {
162- Rasterize (cache_state, layer, ctx, canvas);
176+ return Rasterize (cache_state, layer, ctx, canvas);
163177 });
164178 }
165179 }
@@ -174,20 +188,10 @@ bool LayerRasterCacheItem::Draw(const PaintContext& context,
174188bool LayerRasterCacheItem::Draw (const PaintContext& context,
175189 SkCanvas* canvas,
176190 const SkPaint* paint) const {
177- if (!context.raster_cache || !canvas) {
191+ if (!context.raster_cache || !canvas || cache_state_ == CacheState:: kNone ) {
178192 return false ;
179193 }
180- switch (cache_state_) {
181- case RasterCacheItem::kNone :
182- return false ;
183- case RasterCacheItem::kCurrent : {
184- return context.raster_cache ->Draw (key_id_, *canvas, paint);
185- }
186- case RasterCacheItem::kChildren : {
187- return context.raster_cache ->Draw (layer_children_id_.value (), *canvas,
188- paint);
189- }
190- }
194+ return context.raster_cache ->Draw (GetId ().value (), *canvas, paint);
191195}
192196
193197} // namespace flutter
0 commit comments