| Flutter Impeller |

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_GAUSSIAN_BLUR_FILTER_CONTENTS_H_
6 #define FLUTTER_IMPELLER_ENTITY_CONTENTS_FILTERS_GAUSSIAN_BLUR_FILTER_CONTENTS_H_
7
8 #include <optional>
9 #include "impeller/entity/contents/content_context.h"
10 #include "impeller/entity/contents/filters/filter_contents.h"
11
12 namespace impeller {
13
14 struct BlurParameters {
15 Point blur_uv_offset;
16 Scalar blur_sigma;
17 int blur_radius;
18 int step_size;
19 };
20
21 KernelPipeline::FragmentShader::KernelSamples GenerateBlurInfo(
22 BlurParameters parameters);
23
24 /// Performs a bidirectional Gaussian blur.
25 ///
26 /// This is accomplished by rendering multiple passes in multiple directions.
27 /// Note: This will replace `DirectionalGaussianBlurFilterContents`.
28 class GaussianBlurFilterContents final : public FilterContents {
29 public:
30 explicit GaussianBlurFilterContents(Scalar sigma_x,
31 Scalar sigma_y,
32 Entity::TileMode tile_mode);
33
34 Scalar GetSigmaX() const { return sigma_x_; }
35 Scalar GetSigmaY() const { return sigma_y_; }
36
37 // |FilterContents|
38 std::optional<Rect> GetFilterSourceCoverage(
39 const Matrix& effect_transform,
40 const Rect& output_limit) const override;
41
42 // |FilterContents|
43 std::optional<Rect> GetFilterCoverage(
44 const FilterInput::Vector& inputs,
45 const Entity& entity,
46 const Matrix& effect_transform) const override;
47
48 /// Given a sigma (standard deviation) calculate the blur radius (1/2 the
49 /// kernel size).
50 static Scalar CalculateBlurRadius(Scalar sigma);
51
52 /// Calculate the UV coordinates for rendering the filter_input.
53 /// @param filter_input The FilterInput that should be rendered.
54 /// @param entity The associated entity for the filter_input.
55 /// @param source_rect The rect in source coordinates to convert to uvs.
56 /// @param texture_size The rect to convert in source coordinates.
57 static Quad CalculateUVs(const std::shared_ptr<FilterInput>& filter_input,
58 const Entity& entity,
59 const Rect& source_rect,
60 const ISize& texture_size);
61
62 /// Calculate the scale factor for the downsample pass given a sigma value.
63 ///
64 /// Visible for testing.
65 static Scalar CalculateScale(Scalar sigma);
66
67 /// Scales down the sigma value to match Skia's behavior.
68 ///
69 /// effective_blur_radius = CalculateBlurRadius(ScaleSigma(sigma_));
70 ///
71 /// This function was calculated by observing Skia's behavior. Its blur at
72 /// 500 seemed to be 0.15. Since we clamp at 500 I solved the quadratic
73 /// equation that puts the minima there and a f(0)=1.
74 static Scalar ScaleSigma(Scalar sigma);
75
76 private:
77 // |FilterContents|
78 std::optional<Entity> RenderFilter(
79 const FilterInput::Vector& input_textures,
80 const ContentContext& renderer,
81 const Entity& entity,
82 const Matrix& effect_transform,
83 const Rect& coverage,
84 const std::optional<Rect>& coverage_hint) const override;
85
86 const Scalar sigma_x_ = 0.0;
87 const Scalar sigma_y_ = 0.0;
88 const Entity::TileMode tile_mode_;
89 };
90
91 } // namespace impeller
92
93 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_FILTERS_GAUSSIAN_BLUR_FILTER_CONTENTS_H_
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::BlurParameters::blur_uv_offset
Point blur_uv_offset
Definition: gaussian_blur_filter_contents.h:15
impeller::GaussianBlurFilterContents::CalculateBlurRadius
static Scalar CalculateBlurRadius(Scalar sigma)
Definition: gaussian_blur_filter_contents.cc:405
impeller::GenerateBlurInfo
KernelPipeline::FragmentShader::KernelSamples GenerateBlurInfo(BlurParameters parameters)
Definition: gaussian_blur_filter_contents.cc:435
impeller::GaussianBlurFilterContents::GetSigmaX
Scalar GetSigmaX() const
Definition: gaussian_blur_filter_contents.h:34
impeller::GaussianBlurFilterContents::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: gaussian_blur_filter_contents.cc:225
impeller::BlurParameters::blur_radius
int blur_radius
Definition: gaussian_blur_filter_contents.h:17
impeller::Entity
Definition: entity.h:21
impeller::TSize< int64_t >
impeller::Quad
std::array< Point, 4 > Quad
Definition: point.h:313
filter_contents.h
impeller::GaussianBlurFilterContents::GaussianBlurFilterContents
GaussianBlurFilterContents(Scalar sigma_x, Scalar sigma_y, Entity::TileMode tile_mode)
Definition: gaussian_blur_filter_contents.cc:198
impeller::GaussianBlurFilterContents::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: gaussian_blur_filter_contents.cc:214
impeller::BlurParameters::step_size
int step_size
Definition: gaussian_blur_filter_contents.h:18
impeller::BlurParameters
Definition: gaussian_blur_filter_contents.h:14
impeller::Entity::TileMode
TileMode
Definition: entity.h:40
impeller::GaussianBlurFilterContents::GetSigmaY
Scalar GetSigmaY() const
Definition: gaussian_blur_filter_contents.h:35
content_context.h
impeller::TPoint< Scalar >
impeller::GaussianBlurFilterContents::CalculateScale
static Scalar CalculateScale(Scalar sigma)
Definition: gaussian_blur_filter_contents.cc:207
impeller::GaussianBlurFilterContents::CalculateUVs
static Quad CalculateUVs(const std::shared_ptr< FilterInput > &filter_input, const Entity &entity, const Rect &source_rect, const ISize &texture_size)
Definition: gaussian_blur_filter_contents.cc:409
impeller::FilterInput::Vector
std::vector< FilterInput::Ref > Vector
Definition: filter_input.h:33
impeller::GaussianBlurFilterContents
Definition: gaussian_blur_filter_contents.h:28
impeller
Definition: aiks_context.cc:10
impeller::BlurParameters::blur_sigma
Scalar blur_sigma
Definition: gaussian_blur_filter_contents.h:16
impeller::ContentContext
Definition: content_context.h:332
impeller::TRect
Definition: rect.h:22
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::FilterContents
Definition: filter_contents.h:21
impeller::GaussianBlurFilterContents::ScaleSigma
static Scalar ScaleSigma(Scalar sigma)
Definition: gaussian_blur_filter_contents.cc:425