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 ()
 
bool needs_system_composite () const
 
void set_needs_system_composite (bool value)
 
const SkRect & paint_bounds () const
 
void set_paint_bounds (const SkRect &paint_bounds)
 
bool needs_painting () 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.

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 64 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.

64  {
65  TRACE_EVENT0("flutter", "ImageFilterLayer::Paint");
67 
68  if (context.raster_cache) {
69  if (context.raster_cache->Draw(this, *context.leaf_nodes_canvas)) {
70  return;
71  }
72  if (transformed_filter_) {
73  SkPaint paint;
74  paint.setImageFilter(transformed_filter_);
75 
76  if (context.raster_cache->Draw(GetCacheableChild(),
77  *context.leaf_nodes_canvas, &paint)) {
78  return;
79  }
80  }
81  }
82 
83  SkPaint paint;
84  paint.setImageFilter(filter_);
85 
86  // Normally a save_layer is sized to the current layer bounds, but in this
87  // case the bounds of the child may not be the same as the filtered version
88  // so we use the bounds of the child container which do not include any
89  // modifications that the filter might apply.
90  Layer::AutoSaveLayer save_layer = Layer::AutoSaveLayer::Create(
91  context, GetChildContainer()->paint_bounds(), &paint);
92  PaintChildren(context);
93 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
#define FML_DCHECK(condition)
Definition: logging.h:86
static AutoSaveLayer Create(const PaintContext &paint_context, const SkRect &bounds, const SkPaint *paint)
Definition: layer.cc:96
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.
bool needs_painting() const
Definition: layer.h:174
const SkRect & paint_bounds() const
Definition: layer.h:166
void PaintChildren(PaintContext &context) const

◆ Preroll()

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

Reimplemented from flutter::ContainerLayer.

Definition at line 14 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().

15  {
16  TRACE_EVENT0("flutter", "ImageFilterLayer::Preroll");
17 
18  Layer::AutoPrerollSaveLayerState save =
20 
21  SkRect child_bounds = SkRect::MakeEmpty();
22  PrerollChildren(context, matrix, &child_bounds);
23  if (filter_) {
24  const SkIRect filter_input_bounds = child_bounds.roundOut();
25  SkIRect filter_output_bounds =
26  filter_->filterBounds(filter_input_bounds, SkMatrix::I(),
27  SkImageFilter::kForward_MapDirection);
28  child_bounds = SkRect::Make(filter_output_bounds);
29  }
30  set_paint_bounds(child_bounds);
31 
32  transformed_filter_ = nullptr;
33  if (render_count_ >= kMinimumRendersBeforeCachingFilterLayer) {
34  // We have rendered this same ImageFilterLayer object enough
35  // times to consider its properties and children to be stable
36  // from frame to frame so we try to cache the layer itself
37  // for maximum performance.
38  TryToPrepareRasterCache(context, this, matrix);
39  } else {
40  // This ImageFilterLayer is not yet considered stable so we
41  // increment the count to measure how many times it has been
42  // seen from frame to frame.
43  render_count_++;
44 
45  // Now we will try to pre-render the children into the cache.
46  // To apply the filter to pre-rendered children, we must first
47  // modify the filter to be aware of the transform under which
48  // the cached bitmap was produced. Some SkImageFilter
49  // instances can do this operation on some transforms and some
50  // (filters or transforms) cannot. We can only cache the children
51  // and apply the filter on the fly if this operation succeeds.
52  transformed_filter_ = filter_->makeWithLocalMatrix(matrix);
53  if (transformed_filter_) {
54  // With a modified SkImageFilter we can now try to cache the
55  // children to avoid their rendering costs if they remain
56  // stable between frames and also avoiding a rendering surface
57  // switch during the Paint phase even if they are not stable.
58  // This benefit is seen most during animations.
59  TryToPrepareRasterCache(context, GetCacheableChild(), matrix);
60  }
61  }
62 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
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:43
void set_paint_bounds(const SkRect &paint_bounds)
Definition: layer.h:170
static void TryToPrepareRasterCache(PrerollContext *context, Layer *layer, const SkMatrix &matrix)

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