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 #ifdef FLUTTER_ENABLE_DIFF_CONTEXT
18 
19  void Diff(DiffContext* context, const Layer* old_layer) override;
20 
21 #endif // FLUTTER_ENABLE_DIFF_CONTEXT
22 
23  void Preroll(PrerollContext* context, const SkMatrix& matrix) override;
24 
25  void Paint(PaintContext& context) const override;
26 
27  private:
28  // The ImageFilterLayer might cache the filtered output of this layer
29  // if the layer remains stable (if it is not animating for instance).
30  // If the ImageFilterLayer is not the same between rendered frames,
31  // though, it will cache its children instead and filter their cached
32  // output on the fly.
33  // Caching just the children saves the time to render them and also
34  // avoids a rendering surface switch to draw them.
35  // Caching the layer itself avoids all of that and additionally avoids
36  // the cost of applying the filter, but can be worse than caching the
37  // children if the filter itself is not stable from frame to frame.
38  // This constant controls how many times we will Preroll and Paint this
39  // same ImageFilterLayer before we consider the layer and filter to be
40  // stable enough to switch from caching the children to caching the
41  // filtered output of this layer.
42  static constexpr int kMinimumRendersBeforeCachingFilterLayer = 3;
43 
44  sk_sp<SkImageFilter> filter_;
45  sk_sp<SkImageFilter> transformed_filter_;
46  int render_count_;
47 
48  FML_DISALLOW_COPY_AND_ASSIGN(ImageFilterLayer);
49 };
50 
51 } // namespace flutter
52 
53 #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