Flutter Engine
The Flutter Engine
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>
12
13namespace impeller {
14
20};
21
22GaussianBlurPipeline::FragmentShader::KernelSamples GenerateBlurInfo(
23 BlurParameters parameters);
24
25/// This will shrink the size of a kernel by roughly half by sampling between
26/// samples and relying on linear interpolation between the samples.
27GaussianBlurPipeline::FragmentShader::KernelSamples LerpHackKernelSamples(
28 GaussianBlurPipeline::FragmentShader::KernelSamples samples);
29
30/// Performs a bidirectional Gaussian blur.
31///
32/// This is accomplished by rendering multiple passes in multiple directions.
33/// Note: This will replace `DirectionalGaussianBlurFilterContents`.
35 public:
36 static std::string_view kNoMipsError;
37 static const int32_t kBlurFilterRequiredMipCount;
38
40 Scalar sigma_x,
41 Scalar sigma_y,
42 Entity::TileMode tile_mode,
43 BlurStyle mask_blur_style,
44 const std::shared_ptr<Geometry>& mask_geometry);
45
46 Scalar GetSigmaX() const { return sigma_x_; }
47 Scalar GetSigmaY() const { return sigma_y_; }
48
49 // |FilterContents|
50 std::optional<Rect> GetFilterSourceCoverage(
51 const Matrix& effect_transform,
52 const Rect& output_limit) const override;
53
54 // |FilterContents|
55 std::optional<Rect> GetFilterCoverage(
57 const Entity& entity,
58 const Matrix& effect_transform) const override;
59
60 /// Given a sigma (standard deviation) calculate the blur radius (1/2 the
61 /// kernel size).
62 static Scalar CalculateBlurRadius(Scalar sigma);
63
64 /// Calculate the UV coordinates for rendering the filter_input.
65 /// @param filter_input The FilterInput that should be rendered.
66 /// @param entity The associated entity for the filter_input.
67 /// @param source_rect The rect in source coordinates to convert to uvs.
68 /// @param texture_size The rect to convert in source coordinates.
69 static Quad CalculateUVs(const std::shared_ptr<FilterInput>& filter_input,
70 const Entity& entity,
71 const Rect& source_rect,
72 const ISize& texture_size);
73
74 /// Calculate the scale factor for the downsample pass given a sigma value.
75 ///
76 /// Visible for testing.
77 static Scalar CalculateScale(Scalar sigma);
78
79 /// Scales down the sigma value to match Skia's behavior.
80 ///
81 /// effective_blur_radius = CalculateBlurRadius(ScaleSigma(sigma_));
82 ///
83 /// This function was calculated by observing Skia's behavior. Its blur at
84 /// 500 seemed to be 0.15. Since we clamp at 500 I solved the quadratic
85 /// equation that puts the minima there and a f(0)=1.
86 static Scalar ScaleSigma(Scalar sigma);
87
88 private:
89 // |FilterContents|
90 std::optional<Entity> RenderFilter(
91 const FilterInput::Vector& input_textures,
93 const Entity& entity,
94 const Matrix& effect_transform,
95 const Rect& coverage,
96 const std::optional<Rect>& coverage_hint) const override;
97
98 const Scalar sigma_x_ = 0.0;
99 const Scalar sigma_y_ = 0.0;
100 const Entity::TileMode tile_mode_;
101 const BlurStyle mask_blur_style_;
102 std::shared_ptr<Geometry> mask_geometry_;
103};
104
105} // namespace impeller
106
107#endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_FILTERS_GAUSSIAN_BLUR_FILTER_CONTENTS_H_
std::vector< FilterInput::Ref > Vector
Definition: filter_input.h:33
GaussianBlurFilterContents(Scalar sigma_x, Scalar sigma_y, Entity::TileMode tile_mode, BlurStyle mask_blur_style, const std::shared_ptr< Geometry > &mask_geometry)
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...
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...
static Quad CalculateUVs(const std::shared_ptr< FilterInput > &filter_input, const Entity &entity, const Rect &source_rect, const ISize &texture_size)
GaussianBlurPipeline::FragmentShader::KernelSamples GenerateBlurInfo(BlurParameters parameters)
GaussianBlurPipeline::FragmentShader::KernelSamples LerpHackKernelSamples(GaussianBlurPipeline::FragmentShader::KernelSamples parameters)
float Scalar
Definition: scalar.h:18
std::array< Point, 4 > Quad
Definition: point.h:327
A 4x4 matrix using column-major storage.
Definition: matrix.h:37