@@ -39,12 +39,22 @@ void ImageFilterLayer::Diff(DiffContext* context, const Layer* old_layer) {
3939void ImageFilterLayer::Preroll (PrerollContext* context,
4040 const SkMatrix& matrix) {
4141 TRACE_EVENT0 (" flutter" , " ImageFilterLayer::Preroll" );
42+
4243 Layer::AutoPrerollSaveLayerState save =
4344 Layer::AutoPrerollSaveLayerState::Create (context);
4445
46+ context->raster_cached_entries .emplace_back (RasterCacheEntry (this ));
47+ auto current_index = context->raster_cached_entries .size ();
48+
49+ auto & cache_entry = context->raster_cached_entries .back ();
50+
4551 SkRect child_bounds = SkRect::MakeEmpty ();
4652 PrerollChildren (context, matrix, &child_bounds);
4753
54+ cache_entry.num_child_entries =
55+ context->raster_cached_entries .size () - current_index;
56+ cache_entry.need_caching = IsNeedCached (context, matrix);
57+
4858 if (!filter_) {
4959 set_paint_bounds (child_bounds);
5060 return ;
@@ -56,37 +66,36 @@ void ImageFilterLayer::Preroll(PrerollContext* context,
5666 child_bounds = SkRect::Make (filter_output_bounds);
5767
5868 set_paint_bounds (child_bounds);
69+ }
5970
60- transformed_filter_ = nullptr ;
71+ bool ImageFilterLayer::IsNeedCached (PrerollContext* context,
72+ const SkMatrix& ctm) {
6173 if (render_count_ >= kMinimumRendersBeforeCachingFilterLayer ) {
62- // We have rendered this same ImageFilterLayer object enough
63- // times to consider its properties and children to be stable
64- // from frame to frame so we try to cache the layer itself
65- // for maximum performance.
66- TryToPrepareRasterCache (context, this , matrix);
67- } else {
68- // This ImageFilterLayer is not yet considered stable so we
69- // increment the count to measure how many times it has been
70- // seen from frame to frame.
71- render_count_++;
72-
73- // Now we will try to pre-render the children into the cache.
74- // To apply the filter to pre-rendered children, we must first
75- // modify the filter to be aware of the transform under which
76- // the cached bitmap was produced. Some SkImageFilter
77- // instances can do this operation on some transforms and some
78- // (filters or transforms) cannot. We can only cache the children
79- // and apply the filter on the fly if this operation succeeds.
80- transformed_filter_ = filter_->makeWithLocalMatrix (matrix);
81- if (transformed_filter_) {
82- // With a modified SkImageFilter we can now try to cache the
83- // children to avoid their rendering costs if they remain
84- // stable between frames and also avoiding a rendering surface
85- // switch during the Paint phase even if they are not stable.
86- // This benefit is seen most during animations.
87- TryToPrepareRasterCache (context, GetCacheableChild (), matrix);
88- }
74+ return true ;
75+ }
76+ transformed_filter_ = nullptr ;
77+ // This ImageFilterLayer is not yet considered stable so we
78+ // increment the count to measure how many times it has been
79+ // seen from frame to frame.
80+ render_count_++;
81+
82+ // Now we will try to pre-render the children into the cache.
83+ // To apply the filter to pre-rendered children, we must first
84+ // modify the filter to be aware of the transform under which
85+ // the cached bitmap was produced. Some SkImageFilter
86+ // instances can do this operation on some transforms and some
87+ // (filters or transforms) cannot. We can only cache the children
88+ // and apply the filter on the fly if this operation succeeds.
89+ transformed_filter_ = filter_->makeWithLocalMatrix (ctm);
90+ if (transformed_filter_) {
91+ // With a modified SkImageFilter we can now try to cache the
92+ // children to avoid their rendering costs if they remain
93+ // stable between frames and also avoiding a rendering surface
94+ // switch during the Paint phase even if they are not stable.
95+ // This benefit is seen most during animations.
96+ return true ;
8997 }
98+ return false ;
9099}
91100
92101void ImageFilterLayer::Paint (PaintContext& context) const {
0 commit comments