55#include " flutter/flow/layers/display_list_layer.h"
66
77#include " flutter/display_list/display_list_builder.h"
8- #include " flutter/flow/layers/layer.h"
98
109namespace flutter {
1110
@@ -92,28 +91,34 @@ bool DisplayListLayer::Compare(DiffContext::Statistics& statistics,
9291void DisplayListLayer::Preroll (PrerollContext* context,
9392 const SkMatrix& matrix) {
9493 TRACE_EVENT0 (" flutter" , " DisplayListLayer::Preroll" );
95- context->raster_cached_entries .emplace_back (RasterCacheEntry (this ));
94+ context->raster_cached_entries .emplace_back (
95+ RasterCacheEntry (this , *context, matrix));
9696
9797 auto & cache_entry = context->raster_cached_entries .back ();
98- // display layer is a leaf node
99- cache_entry.num_child_entries = 0 ;
100- cache_entry.need_caching = IsNeedCached (context, matrix);
98+ auto cached_type = NeedCaching (context, matrix);
99+ cache_entry.need_caching = cached_type == CacheableLayer::CacheType::kCurrent ;
101100}
102101
103- bool DisplayListLayer::IsNeedCached (PrerollContext* context,
104- const SkMatrix& ctm) {
102+ CacheableLayer::CacheType DisplayListLayer::NeedCaching (PrerollContext* context,
103+ const SkMatrix& ctm) {
105104 DisplayList* disp_list = display_list ();
106-
107105 SkRect bounds = disp_list->bounds ().makeOffset (offset_.x (), offset_.y ());
108106
109107 if (auto * cache = context->raster_cache ) {
110108 TRACE_EVENT0 (" flutter" , " DisplayListLayer::RasterCache (Preroll)" );
111- if (context->cull_rect .intersects (bounds)) {
112- return cache->ShouldBeCached (context, disp_list, is_complex_,
113- will_change_, ctm);
109+ // For display_list_layer if the context has raster_cache, we will try to
110+ // collection it when we raster cache it, we will to decision Prepare or
111+ // Touch cache
112+ if (context->cull_rect .intersect (bounds) &&
113+ cache->ShouldBeCached (context, disp_list, is_complex_, will_change_,
114+ ctm)) {
115+ // if current Layer can be cached, we change the
116+ // subtree_can_inherit_opacity to true
117+ context->subtree_can_inherit_opacity = true ;
114118 }
119+ return CacheableLayer::CacheType::kCurrent ;
115120 }
116- return false ;
121+ return CacheableLayer::CacheType:: kNone ;
117122}
118123
119124void DisplayListLayer::TryToPrepareRasterCache (PrerollContext* context,
@@ -123,10 +128,7 @@ void DisplayListLayer::TryToPrepareRasterCache(PrerollContext* context,
123128 SkRect bounds = disp_list->bounds ().makeOffset (offset_.x (), offset_.y ());
124129 auto * cache = context->raster_cache ;
125130 if (context->cull_rect .intersects (bounds)) {
126- if (cache->Prepare (context, disp_list, is_complex_, will_change_, ctm,
127- offset_)) {
128- context->subtree_can_inherit_opacity = true ;
129- }
131+ cache->Prepare (context, disp_list, is_complex_, will_change_, ctm, offset_);
130132 } else {
131133 // Don't evict raster cache entry during partial repaint
132134 cache->Touch (disp_list, ctm);
0 commit comments