Flutter Engine
flutter::ImageFilterLayer Class Reference

#include <image_filter_layer.h>

Inheritance diagram for flutter::ImageFilterLayer:
flutter::MergedContainerLayer flutter::ContainerLayer flutter::Layer

Public Member Functions

 ImageFilterLayer (sk_sp< SkImageFilter > filter)
 
void Preroll (PrerollContext *context, const SkMatrix &matrix) override
 
void Paint (PaintContext &context) const override
 
- Public Member Functions inherited from flutter::MergedContainerLayer
 MergedContainerLayer ()
 
void Add (std::shared_ptr< Layer > layer) override
 
- Public Member Functions inherited from flutter::ContainerLayer
 ContainerLayer ()
 
const std::vector< std::shared_ptr< Layer > > & layers () const
 
- Public Member Functions inherited from flutter::Layer
 Layer ()
 
virtual ~Layer ()
 
void AssignOldLayer (Layer *old_layer)
 
bool subtree_has_platform_view () const
 
void set_subtree_has_platform_view (bool value)
 
const SkRect & paint_bounds () const
 
void set_paint_bounds (const SkRect &paint_bounds)
 
bool is_empty () const
 
bool needs_painting (PaintContext &context) const
 
uint64_t original_layer_id () const
 
uint64_t unique_id () const
 

Additional Inherited Members

- Protected Member Functions inherited from flutter::MergedContainerLayer
ContainerLayerGetChildContainer () const
 Returns the ContainerLayer used to hold all of the children of the MergedContainerLayer. Note that this may not be the best layer to use for caching the children. More...
 
LayerGetCacheableChild () const
 Returns the best choice for a Layer object that can be used in RasterCache operations to cache the children. More...
 
- Protected Member Functions inherited from flutter::ContainerLayer
void PrerollChildren (PrerollContext *context, const SkMatrix &child_matrix, SkRect *child_paint_bounds)
 
void PaintChildren (PaintContext &context) const
 
- Static Protected Member Functions inherited from flutter::ContainerLayer
static void TryToPrepareRasterCache (PrerollContext *context, Layer *layer, const SkMatrix &matrix)
 

Detailed Description

Definition at line 13 of file image_filter_layer.h.

Constructor & Destructor Documentation

◆ ImageFilterLayer()

flutter::ImageFilterLayer::ImageFilterLayer ( sk_sp< SkImageFilter >  filter)

Definition at line 9 of file image_filter_layer.cc.

References FML_DCHECK.

10  : filter_(std::move(filter)),
11  transformed_filter_(nullptr),
12  render_count_(1) {}

Member Function Documentation

◆ Paint()

void flutter::ImageFilterLayer::Paint ( PaintContext context) const
overridevirtual

Reimplemented from flutter::ContainerLayer.

Definition at line 98 of file image_filter_layer.cc.

References flutter::Layer::AutoSaveLayer::Create(), flutter::RasterCache::Draw(), FML_DCHECK, flutter::MergedContainerLayer::GetCacheableChild(), flutter::MergedContainerLayer::GetChildContainer(), flutter::Layer::PaintContext::leaf_nodes_canvas, flutter::Layer::needs_painting(), flutter::Layer::paint_bounds(), flutter::ContainerLayer::PaintChildren(), flutter::Layer::PaintContext::raster_cache, and TRACE_EVENT0.

98  {
99  TRACE_EVENT0("flutter", "ImageFilterLayer::Paint");
100  FML_DCHECK(needs_painting(context));
101 
102  if (context.raster_cache) {
103  if (context.raster_cache->Draw(this, *context.leaf_nodes_canvas)) {
104  return;
105  }
106  if (transformed_filter_) {
107  SkPaint paint;
108  paint.setImageFilter(transformed_filter_);
109 
110  if (context.raster_cache->Draw(GetCacheableChild(),
111  *context.leaf_nodes_canvas, &paint)) {
112  return;
113  }
114  }
115  }
116 
117  SkPaint paint;
118  paint.setImageFilter(filter_);
119 
120  // Normally a save_layer is sized to the current layer bounds, but in this
121  // case the bounds of the child may not be the same as the filtered version
122  // so we use the bounds of the child container which do not include any
123  // modifications that the filter might apply.
124  Layer::AutoSaveLayer save_layer = Layer::AutoSaveLayer::Create(
125  context, GetChildContainer()->paint_bounds(), &paint);
126  PaintChildren(context);
127 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
#define FML_DCHECK(condition)
Definition: logging.h:86
bool needs_painting(PaintContext &context) const
Definition: layer.h:249
Layer * GetCacheableChild() const
Returns the best choice for a Layer object that can be used in RasterCache operations to cache the ch...
ContainerLayer * GetChildContainer() const
Returns the ContainerLayer used to hold all of the children of the MergedContainerLayer. Note that this may not be the best layer to use for caching the children.
const SkRect & paint_bounds() const
Definition: layer.h:227
void PaintChildren(PaintContext &context) const
static AutoSaveLayer Create(const PaintContext &paint_context, const SkRect &bounds, const SkPaint *paint, SaveMode save_mode=SaveMode::kInternalNodesCanvas)
Definition: layer.cc:82

◆ Preroll()

void flutter::ImageFilterLayer::Preroll ( PrerollContext context,
const SkMatrix &  matrix 
)
overridevirtual

Reimplemented from flutter::ContainerLayer.

Definition at line 45 of file image_filter_layer.cc.

References flutter::Layer::AutoPrerollSaveLayerState::Create(), flutter::MergedContainerLayer::GetCacheableChild(), flutter::ContainerLayer::PrerollChildren(), flutter::Layer::set_paint_bounds(), TRACE_EVENT0, and flutter::ContainerLayer::TryToPrepareRasterCache().

46  {
47  TRACE_EVENT0("flutter", "ImageFilterLayer::Preroll");
48  Layer::AutoPrerollSaveLayerState save =
50 
51  SkRect child_bounds = SkRect::MakeEmpty();
52  PrerollChildren(context, matrix, &child_bounds);
53 
54  if (!filter_) {
55  set_paint_bounds(child_bounds);
56  return;
57  }
58 
59  const SkIRect filter_input_bounds = child_bounds.roundOut();
60  SkIRect filter_output_bounds = filter_->filterBounds(
61  filter_input_bounds, SkMatrix::I(), SkImageFilter::kForward_MapDirection);
62  child_bounds = SkRect::Make(filter_output_bounds);
63 
64  set_paint_bounds(child_bounds);
65 
66  transformed_filter_ = nullptr;
67  if (render_count_ >= kMinimumRendersBeforeCachingFilterLayer) {
68  // We have rendered this same ImageFilterLayer object enough
69  // times to consider its properties and children to be stable
70  // from frame to frame so we try to cache the layer itself
71  // for maximum performance.
72  TryToPrepareRasterCache(context, this, matrix);
73  } else {
74  // This ImageFilterLayer is not yet considered stable so we
75  // increment the count to measure how many times it has been
76  // seen from frame to frame.
77  render_count_++;
78 
79  // Now we will try to pre-render the children into the cache.
80  // To apply the filter to pre-rendered children, we must first
81  // modify the filter to be aware of the transform under which
82  // the cached bitmap was produced. Some SkImageFilter
83  // instances can do this operation on some transforms and some
84  // (filters or transforms) cannot. We can only cache the children
85  // and apply the filter on the fly if this operation succeeds.
86  transformed_filter_ = filter_->makeWithLocalMatrix(matrix);
87  if (transformed_filter_) {
88  // With a modified SkImageFilter we can now try to cache the
89  // children to avoid their rendering costs if they remain
90  // stable between frames and also avoiding a rendering surface
91  // switch during the Paint phase even if they are not stable.
92  // This benefit is seen most during animations.
93  TryToPrepareRasterCache(context, GetCacheableChild(), matrix);
94  }
95  }
96 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
void PrerollChildren(PrerollContext *context, const SkMatrix &child_matrix, SkRect *child_paint_bounds)
Layer * GetCacheableChild() const
Returns the best choice for a Layer object that can be used in RasterCache operations to cache the ch...
static AutoPrerollSaveLayerState Create(PrerollContext *preroll_context, bool save_layer_is_active=true, bool layer_itself_performs_readback=false)
Definition: layer.cc:44
void set_paint_bounds(const SkRect &paint_bounds)
Definition: layer.h:240
static void TryToPrepareRasterCache(PrerollContext *context, Layer *layer, const SkMatrix &matrix)

The documentation for this class was generated from the following files: