| Flutter Impeller |

directional_gaussian_blur_filter_contents.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_IMPELLER_ENTITY_CONTENTS_FILTERS_DIRECTIONAL_GAUSSIAN_BLUR_FILTER_CONTENTS_H_
6 #define FLUTTER_IMPELLER_ENTITY_CONTENTS_FILTERS_DIRECTIONAL_GAUSSIAN_BLUR_FILTER_CONTENTS_H_
7
8 #include <memory>
9 #include <optional>
10 #include "impeller/entity/contents/filters/filter_contents.h"
11 #include "impeller/entity/contents/filters/inputs/filter_input.h"
12
13 namespace impeller {
14
15 /// A gaussian blur filter that performs the work for one dimension of a
16 /// multi-dimensional Gaussian blur.
17 ///
18 /// This filter takes a snapshot of its provided FilterInput, creates a new
19 /// render pass and blurs the contents. Two of these are chained together to
20 /// perform a full 2D blur effect.
21 ///
22 /// Example:
23 ///
24 /// Input Pass 1
25 /// +-------------+ +-----+
26 /// | | | |
27 /// | | | | Pass 2
28 /// | | | | +----+
29 /// | | | | | |
30 /// | | -> | | -> | |
31 /// | | | | | |
32 /// | | | | +----+
33 /// | | | | 87x102
34 /// +-------------+ +-----+
35 /// 586x678 97x678
36 ///
37 /// The math for determining how much of the input should be processed for a
38 /// given sigma (aka radius) is found in `Sigma::operator Radius`. The math for
39 /// determining how much to scale down the input based on the radius is inside
40 /// the curve function in this implementation.
41 ///
42 /// See also:
43 /// - `FilterContents::MakeGaussianBlur`
44 /// - //flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur.glsl
45 ///
46 class DirectionalGaussianBlurFilterContents final : public FilterContents {
47 public:
48 DirectionalGaussianBlurFilterContents();
49
50 ~DirectionalGaussianBlurFilterContents() override;
51
52 /// Set sigma (stddev) used for 'direction_'.
53 void SetSigma(Sigma sigma);
54
55 /// Set sigma (stddev) used for direction 90 degrees from 'direction_'.
56 /// Not used if `!is_second_pass_`.
57 void SetSecondarySigma(Sigma sigma);
58
59 void SetDirection(Vector2 direction);
60
61 void SetBlurStyle(BlurStyle blur_style);
62
63 void SetTileMode(Entity::TileMode tile_mode);
64
65 /// Determines if this filter represents the second pass in a chained
66 /// 2D gaussian blur.
67 /// If `is_second_pass_ == true` then the `secondary_sigma_` is used to
68 /// determine the blur radius in the 90 degree rotation of direction_. Its
69 /// output aspect-ratio will closely match the FilterInput snapshot at the
70 /// beginning of the chain.
71 void SetIsSecondPass(bool is_second_pass);
72
73 // |FilterContents|
74 std::optional<Rect> GetFilterSourceCoverage(
75 const Matrix& effect_transform,
76 const Rect& output_limit) const override;
77
78 // |FilterContents|
79 std::optional<Rect> GetFilterCoverage(
80 const FilterInput::Vector& inputs,
81 const Entity& entity,
82 const Matrix& effect_transform) const override;
83
84 private:
85 // |FilterContents|
86 std::optional<Entity> RenderFilter(
87 const FilterInput::Vector& input_textures,
88 const ContentContext& renderer,
89 const Entity& entity,
90 const Matrix& effect_transform,
91 const Rect& coverage,
92 const std::optional<Rect>& coverage_hint) const override;
93 Sigma blur_sigma_;
94 Sigma secondary_blur_sigma_;
95 Vector2 blur_direction_;
96 BlurStyle blur_style_ = BlurStyle::kNormal;
97 Entity::TileMode tile_mode_ = Entity::TileMode::kDecal;
98 bool is_second_pass_ = false;
99
100 DirectionalGaussianBlurFilterContents(
101 const DirectionalGaussianBlurFilterContents&) = delete;
102
103 DirectionalGaussianBlurFilterContents& operator=(
104 const DirectionalGaussianBlurFilterContents&) = delete;
105 };
106
107 } // namespace impeller
108
109 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_FILTERS_DIRECTIONAL_GAUSSIAN_BLUR_FILTER_CONTENTS_H_
impeller::DirectionalGaussianBlurFilterContents::SetIsSecondPass
void SetIsSecondPass(bool is_second_pass)
Definition: directional_gaussian_blur_filter_contents.cc:64
impeller::DirectionalGaussianBlurFilterContents::SetBlurStyle
void SetBlurStyle(BlurStyle blur_style)
Definition: directional_gaussian_blur_filter_contents.cc:55
impeller::DirectionalGaussianBlurFilterContents::SetSecondarySigma
void SetSecondarySigma(Sigma sigma)
Definition: directional_gaussian_blur_filter_contents.cc:44
impeller::FilterContents::BlurStyle
BlurStyle
Definition: filter_contents.h:23
impeller::Entity::TileMode::kDecal
@ kDecal
impeller::FilterContents::BlurStyle::kNormal
@ kNormal
Blurred inside and outside.
impeller::DirectionalGaussianBlurFilterContents::GetFilterSourceCoverage
std::optional< Rect > GetFilterSourceCoverage(const Matrix &effect_transform, const Rect &output_limit) const override
Internal utility method for |GetSourceCoverage| that computes the inverse effect of this transform on...
Definition: directional_gaussian_blur_filter_contents.cc:282
impeller::Entity
Definition: entity.h:21
filter_contents.h
impeller::Sigma
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
Definition: sigma.h:32
filter_input.h
impeller::Entity::TileMode
TileMode
Definition: entity.h:40
impeller::DirectionalGaussianBlurFilterContents::SetTileMode
void SetTileMode(Entity::TileMode tile_mode)
Definition: directional_gaussian_blur_filter_contents.cc:59
impeller::DirectionalGaussianBlurFilterContents::DirectionalGaussianBlurFilterContents
DirectionalGaussianBlurFilterContents()
impeller::DirectionalGaussianBlurFilterContents::SetSigma
void SetSigma(Sigma sigma)
Set sigma (stddev) used for 'direction_'.
Definition: directional_gaussian_blur_filter_contents.cc:40
impeller::DirectionalGaussianBlurFilterContents::~DirectionalGaussianBlurFilterContents
~DirectionalGaussianBlurFilterContents() override
impeller::DirectionalGaussianBlurFilterContents::GetFilterCoverage
std::optional< Rect > GetFilterCoverage(const FilterInput::Vector &inputs, const Entity &entity, const Matrix &effect_transform) const override
Internal utility method for |GetLocalCoverage| that computes the output coverage of this filter acros...
Definition: directional_gaussian_blur_filter_contents.cc:292
impeller::DirectionalGaussianBlurFilterContents::SetDirection
void SetDirection(Vector2 direction)
Definition: directional_gaussian_blur_filter_contents.cc:48
impeller::TPoint< Scalar >
impeller::FilterInput::Vector
std::vector< FilterInput::Ref > Vector
Definition: filter_input.h:33
impeller
Definition: aiks_context.cc:10
impeller::ContentContext
Definition: content_context.h:332
impeller::TRect< Scalar >
impeller::DirectionalGaussianBlurFilterContents
Definition: directional_gaussian_blur_filter_contents.h:46
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::FilterContents
Definition: filter_contents.h:21