| Flutter Impeller |

solid_rrect_like_blur_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_SOLID_RRECT_LIKE_BLUR_CONTENTS_H_
6 #define FLUTTER_IMPELLER_ENTITY_CONTENTS_SOLID_RRECT_LIKE_BLUR_CONTENTS_H_
7
8 #include <functional>
9 #include <memory>
10 #include <vector>
11
12 #include "impeller/entity/contents/contents.h"
13 #include "impeller/entity/contents/filters/filter_contents.h"
14 #include "impeller/geometry/color.h"
15
16 namespace impeller {
17
18 /// @brief A base class for any accelerated single color blur Contents
19 /// that lets the |Canvas::AttemptDrawBlur| call deliver the
20 /// color after the contents has been constructed and the method
21 /// has a chance to re-consider the actual color that will be
22 /// used to render the shadow.
23 class SolidBlurContents : public Contents {
24 public:
25 virtual void SetColor(Color color) = 0;
26 };
27
28 /// @brief A base class for SolidRRectBlurContents and
29 /// SolidRSuperellipseBlurContents.
30 class SolidRRectLikeBlurContents : public SolidBlurContents {
31 public:
32 ~SolidRRectLikeBlurContents() override;
33
34 void SetShape(Rect rect, Scalar corner_radius);
35
36 void SetSigma(Sigma sigma);
37
38 // |SolidBlurContents|
39 void SetColor(Color color) override;
40
41 Color GetColor() const;
42
43 // |Contents|
44 std::optional<Rect> GetCoverage(const Entity& entity) const override;
45
46 // |Contents|
47 bool Render(const ContentContext& renderer,
48 const Entity& entity,
49 RenderPass& pass) const override;
50
51 // |Contents|
52 [[nodiscard]] bool ApplyColorFilter(
53 const ColorFilterProc& color_filter_proc) override;
54
55 protected:
56 struct PassContext {
57 // General info
58 ContentContextOptions opts;
59 // Frag info
60 Point center;
61 Point adjust;
62 Scalar minEdge;
63 Scalar r1;
64 Scalar exponent;
65 Scalar sInv;
66 Scalar exponentInv;
67 Scalar scale;
68 };
69
70 SolidRRectLikeBlurContents();
71
72 virtual bool SetPassInfo(RenderPass& pass,
73 const ContentContext& renderer,
74 PassContext& pass_context) const = 0;
75
76 Rect GetRect() const { return rect_; }
77 Scalar GetCornerRadius() const { return corner_radius_; }
78 Sigma GetSigma() const { return sigma_; }
79
80 static Vector4 Concat(Vector2& a, Vector2& b);
81
82 private:
83 static bool PopulateFragContext(PassContext& pass_context,
84 Scalar blurSigma,
85 Point center,
86 Point rSize,
87 Scalar radius);
88
89 Rect rect_;
90 Scalar corner_radius_;
91 Sigma sigma_;
92 Color color_;
93
94 SolidRRectLikeBlurContents(const SolidRRectLikeBlurContents&) = delete;
95
96 SolidRRectLikeBlurContents& operator=(const SolidRRectLikeBlurContents&) =
97 delete;
98 };
99
100 } // namespace impeller
101
102 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_SOLID_RRECT_LIKE_BLUR_CONTENTS_H_
impeller::ContentContext
Definition: content_context.h:122
impeller::Contents
Definition: contents.h:31
impeller::Contents::ColorFilterProc
std::function< Color(Color)> ColorFilterProc
Definition: contents.h:35
impeller::Entity
Definition: entity.h:26
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
impeller::SolidBlurContents
A base class for any accelerated single color blur Contents that lets the |Canvas::AttemptDrawBlur| c...
Definition: solid_rrect_like_blur_contents.h:23
impeller::SolidBlurContents::SetColor
virtual void SetColor(Color color)=0
impeller::SolidRRectLikeBlurContents
A base class for SolidRRectBlurContents and SolidRSuperellipseBlurContents.
Definition: solid_rrect_like_blur_contents.h:30
impeller::SolidRRectLikeBlurContents::SetShape
void SetShape(Rect rect, Scalar corner_radius)
Definition: solid_rrect_like_blur_contents.cc:33
impeller::SolidRRectLikeBlurContents::GetCoverage
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the area of the render pass that will be affected when this contents is rendered.
Definition: solid_rrect_like_blur_contents.cc:108
impeller::SolidRRectLikeBlurContents::~SolidRRectLikeBlurContents
~SolidRRectLikeBlurContents() override
impeller::SolidRRectLikeBlurContents::SetPassInfo
virtual bool SetPassInfo(RenderPass &pass, const ContentContext &renderer, PassContext &pass_context) const =0
impeller::SolidRRectLikeBlurContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: solid_rrect_like_blur_contents.cc:115
impeller::SolidRRectLikeBlurContents::SetSigma
void SetSigma(Sigma sigma)
Definition: solid_rrect_like_blur_contents.cc:38
impeller::SolidRRectLikeBlurContents::GetColor
Color GetColor() const
Definition: solid_rrect_like_blur_contents.cc:46
impeller::SolidRRectLikeBlurContents::ApplyColorFilter
bool ApplyColorFilter(const ColorFilterProc &color_filter_proc) override
If possible, applies a color filter to this contents inputs on the CPU.
Definition: solid_rrect_like_blur_contents.cc:187
impeller::SolidRRectLikeBlurContents::Concat
static Vector4 Concat(Vector2 &a, Vector2 &b)
Definition: solid_rrect_like_blur_contents.cc:193
impeller::SolidRRectLikeBlurContents::SolidRRectLikeBlurContents
SolidRRectLikeBlurContents()
impeller::SolidRRectLikeBlurContents::SetColor
void SetColor(Color color) override
Definition: solid_rrect_like_blur_contents.cc:42
impeller::SolidRRectLikeBlurContents::GetCornerRadius
Scalar GetCornerRadius() const
Definition: solid_rrect_like_blur_contents.h:77
impeller::SolidRRectLikeBlurContents::GetRect
Rect GetRect() const
Definition: solid_rrect_like_blur_contents.h:76
impeller::SolidRRectLikeBlurContents::GetSigma
Sigma GetSigma() const
Definition: solid_rrect_like_blur_contents.h:78
color.h
contents.h
filter_contents.h
impeller::saturated::b
SI b
Definition: saturated_math.h:87
impeller
Definition: allocation.cc:12
impeller::Scalar
float Scalar
Definition: scalar.h:19
impeller::Color
Definition: color.h:124
impeller::ContentContextOptions
Definition: content_context.h:40
impeller::Sigma
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
Definition: sigma.h:32
impeller::SolidRRectLikeBlurContents::PassContext
Definition: solid_rrect_like_blur_contents.h:56
impeller::SolidRRectLikeBlurContents::PassContext::scale
Scalar scale
Definition: solid_rrect_like_blur_contents.h:67
impeller::SolidRRectLikeBlurContents::PassContext::r1
Scalar r1
Definition: solid_rrect_like_blur_contents.h:63
impeller::SolidRRectLikeBlurContents::PassContext::adjust
Point adjust
Definition: solid_rrect_like_blur_contents.h:61
impeller::SolidRRectLikeBlurContents::PassContext::exponentInv
Scalar exponentInv
Definition: solid_rrect_like_blur_contents.h:66
impeller::SolidRRectLikeBlurContents::PassContext::sInv
Scalar sInv
Definition: solid_rrect_like_blur_contents.h:65
impeller::SolidRRectLikeBlurContents::PassContext::opts
ContentContextOptions opts
Definition: solid_rrect_like_blur_contents.h:58
impeller::SolidRRectLikeBlurContents::PassContext::minEdge
Scalar minEdge
Definition: solid_rrect_like_blur_contents.h:62
impeller::SolidRRectLikeBlurContents::PassContext::exponent
Scalar exponent
Definition: solid_rrect_like_blur_contents.h:64
impeller::SolidRRectLikeBlurContents::PassContext::center
Point center
Definition: solid_rrect_like_blur_contents.h:60
impeller::TPoint< Scalar >
impeller::TRect< Scalar >
impeller::Vector4
Definition: vector.h:232