Flutter Engine
image_filter_layer.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_FLOW_LAYERS_IMAGE_FILTER_LAYER_H_
6 #define FLUTTER_FLOW_LAYERS_IMAGE_FILTER_LAYER_H_
7 
8 #include "flutter/flow/layers/container_layer.h"
9 #include "third_party/skia/include/core/SkImageFilter.h"
10 
11 namespace flutter {
12 
14  public:
15  ImageFilterLayer(sk_sp<SkImageFilter> filter);
16 
17  void Preroll(PrerollContext* context, const SkMatrix& matrix) override;
18 
19  void Paint(PaintContext& context) const override;
20 
21  private:
22  // The ImageFilterLayer might cache the filtered output of this layer
23  // if the layer remains stable (if it is not animating for instance).
24  // If the ImageFilterLayer is not the same between rendered frames,
25  // though, it will cache its children instead and filter their cached
26  // output on the fly.
27  // Caching just the children saves the time to render them and also
28  // avoids a rendering surface switch to draw them.
29  // Caching the layer itself avoids all of that and additionally avoids
30  // the cost of applying the filter, but can be worse than caching the
31  // children if the filter itself is not stable from frame to frame.
32  // This constant controls how many times we will Preroll and Paint this
33  // same ImageFilterLayer before we consider the layer and filter to be
34  // stable enough to switch from caching the children to caching the
35  // filtered output of this layer.
36  static constexpr int kMinimumRendersBeforeCachingFilterLayer = 3;
37 
38  sk_sp<SkImageFilter> filter_;
39  sk_sp<SkImageFilter> transformed_filter_;
40  int render_count_;
41 
42  FML_DISALLOW_COPY_AND_ASSIGN(ImageFilterLayer);
43 };
44 
45 } // namespace flutter
46 
47 #endif // FLUTTER_FLOW_LAYERS_IMAGE_FILTER_LAYER_H_
ImageFilterLayer(sk_sp< SkImageFilter > filter)
void Preroll(PrerollContext *context, const SkMatrix &matrix) override
void Paint(PaintContext &context) const override