Flutter Engine
 
Loading...
Searching...
No Matches
impeller::SolidRRectLikeBlurContents Class Referenceabstract

A base class for SolidRRectBlurContents and SolidRSuperellipseBlurContents. More...

#include <solid_rrect_like_blur_contents.h>

Inheritance diagram for impeller::SolidRRectLikeBlurContents:
impeller::Contents impeller::SolidRRectBlurContents impeller::SolidRSuperellipseBlurContents

Classes

struct  PassContext
 

Public Member Functions

 ~SolidRRectLikeBlurContents () override
 
void SetShape (Rect rect, Scalar corner_radius)
 
void SetSigma (Sigma sigma)
 
void SetColor (Color color)
 
Color GetColor () const
 
std::optional< RectGetCoverage (const Entity &entity) const override
 Get the area of the render pass that will be affected when this contents is rendered.
 
bool Render (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
 
bool ApplyColorFilter (const ColorFilterProc &color_filter_proc) override
 If possible, applies a color filter to this contents inputs on the CPU.
 
- Public Member Functions inherited from impeller::Contents
 Contents ()
 
virtual ~Contents ()
 
void SetCoverageHint (std::optional< Rect > coverage_hint)
 Hint that specifies the coverage area of this Contents that will actually be used during rendering. This is for optimization purposes only and can not be relied on as a clip. May optionally affect the result of GetCoverage().
 
const std::optional< Rect > & GetCoverageHint () const
 
virtual bool IsOpaque (const Matrix &transform) const
 Whether this Contents only emits opaque source colors from the fragment stage. This value does not account for any entity properties (e.g. the blend mode), clips/visibility culling, or inherited opacity.
 
virtual std::optional< SnapshotRenderToSnapshot (const ContentContext &renderer, const Entity &entity, const SnapshotOptions &options) const
 Render this contents to a snapshot, respecting the entity's transform, path, clip depth, and blend mode. The result texture size is always the size of GetCoverage(entity).
 
std::optional< SizeGetColorSourceSize () const
 Return the color source's intrinsic size, if available.
 
void SetColorSourceSize (Size size)
 
virtual void SetInheritedOpacity (Scalar opacity)
 Inherit the provided opacity.
 
virtual std::optional< ColorAsBackgroundColor (const Entity &entity, ISize target_size) const
 Returns a color if this Contents will flood the given target_size with a color. This output color is the "Source" color that will be used for the Entity's blend operation.
 

Protected Member Functions

 SolidRRectLikeBlurContents ()
 
virtual bool SetPassInfo (RenderPass &pass, const ContentContext &renderer, PassContext &pass_context) const =0
 
Rect GetRect () const
 
Scalar GetCornerRadius () const
 
Sigma GetSigma () const
 

Static Protected Member Functions

static Vector4 Concat (Vector2 &a, Vector2 &b)
 

Additional Inherited Members

- Public Types inherited from impeller::Contents
using ColorFilterProc = std::function< Color(Color)>
 
using RenderProc = std::function< bool(const ContentContext &renderer, const Entity &entity, RenderPass &pass)>
 
using CoverageProc = std::function< std::optional< Rect >(const Entity &entity)>
 
- Static Public Member Functions inherited from impeller::Contents
static std::shared_ptr< ContentsMakeAnonymous (RenderProc render_proc, CoverageProc coverage_proc)
 

Detailed Description

Constructor & Destructor Documentation

◆ ~SolidRRectLikeBlurContents()

impeller::SolidRRectLikeBlurContents::~SolidRRectLikeBlurContents ( )
overridedefault

◆ SolidRRectLikeBlurContents()

impeller::SolidRRectLikeBlurContents::SolidRRectLikeBlurContents ( )
protecteddefault

Member Function Documentation

◆ ApplyColorFilter()

bool impeller::SolidRRectLikeBlurContents::ApplyColorFilter ( const ColorFilterProc color_filter_proc)
overridevirtual

If possible, applies a color filter to this contents inputs on the CPU.

This method will either fully apply the color filter or perform no action. Partial/incorrect application of the color filter will never occur.

Parameters
[in]color_filter_procA function that filters a given unpremultiplied color to produce a new unpremultiplied color.
Returns
True if the color filter was able to be fully applied to all all relevant inputs. Otherwise, this operation is a no-op and false is returned.

Reimplemented from impeller::Contents.

Definition at line 187 of file solid_rrect_like_blur_contents.cc.

188 {
189 color_ = color_filter_proc(color_);
190 return true;
191}

◆ Concat()

Vector4 impeller::SolidRRectLikeBlurContents::Concat ( Vector2 a,
Vector2 b 
)
staticprotected

Definition at line 193 of file solid_rrect_like_blur_contents.cc.

193 {
194 return {a.x, a.y, b.x, b.y};
195}

References impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by impeller::SolidRRectBlurContents::SetPassInfo().

◆ GetColor()

Color impeller::SolidRRectLikeBlurContents::GetColor ( ) const

Definition at line 46 of file solid_rrect_like_blur_contents.cc.

46 {
47 return color_;
48}

Referenced by impeller::SolidRRectBlurContents::SetPassInfo().

◆ GetCornerRadius()

Scalar impeller::SolidRRectLikeBlurContents::GetCornerRadius ( ) const
inlineprotected

Definition at line 66 of file solid_rrect_like_blur_contents.h.

66{ return corner_radius_; }

◆ GetCoverage()

std::optional< Rect > impeller::SolidRRectLikeBlurContents::GetCoverage ( const Entity entity) const
overridevirtual

Get the area of the render pass that will be affected when this contents is rendered.

During rendering, coverage coordinates count pixels from the top left corner of the framebuffer.

Returns
The coverage rectangle. An std::nullopt result means that rendering this contents has no effect on the output color.

Implements impeller::Contents.

Definition at line 108 of file solid_rrect_like_blur_contents.cc.

109 {
110 Scalar radius = PadForSigma(sigma_.sigma);
111
112 return rect_.Expand(radius).TransformBounds(entity.GetTransform());
113}
float Scalar
Definition scalar.h:19
Scalar sigma
Definition sigma.h:33
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition rect.h:472
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.
Definition rect.h:618

References impeller::TRect< T >::Expand(), impeller::Entity::GetTransform(), impeller::Sigma::sigma, and impeller::TRect< T >::TransformBounds().

◆ GetRect()

Rect impeller::SolidRRectLikeBlurContents::GetRect ( ) const
inlineprotected

Definition at line 65 of file solid_rrect_like_blur_contents.h.

65{ return rect_; }

◆ GetSigma()

Sigma impeller::SolidRRectLikeBlurContents::GetSigma ( ) const
inlineprotected

Definition at line 67 of file solid_rrect_like_blur_contents.h.

67{ return sigma_; }

◆ Render()

bool impeller::SolidRRectLikeBlurContents::Render ( const ContentContext renderer,
const Entity entity,
RenderPass pass 
) const
overridevirtual

Implements impeller::Contents.

Definition at line 115 of file solid_rrect_like_blur_contents.cc.

117 {
118 using VS = RrectLikeBlurVertexShader;
119
120 Matrix basis_invert = entity.GetTransform().Basis().Invert();
121 Vector2 max_sigmas =
122 Vector2((basis_invert * Vector2(500.f, 0.f)).GetLength(),
123 (basis_invert * Vector2(0.f, 500.f)).GetLength());
124 Scalar max_sigma = std::min(max_sigmas.x, max_sigmas.y);
125 // Clamp the max kernel width/height to 1000 (@ 2x) to limit the extent
126 // of the blur and to kEhCloseEnough to prevent NaN calculations
127 // trying to evaluate a Gaussian distribution with a sigma of 0.
128 auto blur_sigma = std::clamp(sigma_.sigma, kEhCloseEnough, max_sigma);
129 // Increase quality by making the radius a bit bigger than the typical
130 // sigma->radius conversion we use for slower blurs.
131 Scalar blur_radius = PadForSigma(blur_sigma);
132 Rect positive_rect = rect_.GetPositive();
134 Scalar top = -blur_radius;
135 Scalar right = positive_rect.GetWidth() + blur_radius;
136 Scalar bottom = positive_rect.GetHeight() + blur_radius;
137
138 ContentContextOptions opts = OptionsFromPassAndEntity(pass, entity);
139 opts.primitive_type = PrimitiveType::kTriangleStrip;
140 Color color = color_;
141 if (entity.GetBlendMode() == BlendMode::kClear) {
142 opts.is_for_rrect_blur_clear = true;
143 color = Color::White();
144 }
145
146 std::array<VS::PerVertexData, 4> vertices = {
147 VS::PerVertexData{Point(left, top)},
148 VS::PerVertexData{Point(right, top)},
149 VS::PerVertexData{Point(left, bottom)},
150 VS::PerVertexData{Point(right, bottom)},
151 };
152
153 PassContext pass_context = {
154 .opts = opts,
155 };
156
157 Scalar radius = std::min(std::clamp(corner_radius_, kEhCloseEnough,
158 positive_rect.GetWidth() * 0.5f),
159 std::clamp(corner_radius_, kEhCloseEnough,
160 positive_rect.GetHeight() * 0.5f));
161 if (!PopulateFragContext(pass_context, blur_sigma, positive_rect.GetCenter(),
162 Point(positive_rect.GetSize()), radius)) {
163 return true;
164 }
165
166 if (!SetPassInfo(pass, renderer, pass_context)) {
167 return true;
168 }
169
170 VS::FrameInfo frame_info;
171 frame_info.mvp = Entity::GetShaderTransform(
172 entity.GetShaderClipDepth(), pass,
173 entity.GetTransform() *
174 Matrix::MakeTranslation(positive_rect.GetOrigin()));
175
176 auto& data_host_buffer = renderer.GetTransientsDataBuffer();
177 pass.SetVertexBuffer(CreateVertexBuffer(vertices, data_host_buffer));
178 VS::BindFrameInfo(pass, data_host_buffer.EmplaceUniform(frame_info));
179
180 if (!pass.Draw().ok()) {
181 return false;
182 }
183
184 return true;
185}
Matrix GetShaderTransform(const RenderPass &pass) const
Definition entity.cc:48
virtual bool SetPassInfo(RenderPass &pass, const ContentContext &renderer, PassContext &pass_context) const =0
Vector2 blur_radius
Blur radius in source pixels based on scaled_sigma.
Point Vector2
Definition point.h:331
constexpr float kEhCloseEnough
Definition constants.h:57
TRect< Scalar > Rect
Definition rect.h:788
TPoint< Scalar > Point
Definition point.h:327
VertexBuffer CreateVertexBuffer(std::array< VertexType, size > input, HostBuffer &data_host_buffer)
Create an index-less vertex buffer from a fixed size array.
LinePipeline::VertexShader VS
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition contents.cc:34
static constexpr Color White()
Definition color.h:264
static constexpr Matrix MakeTranslation(const Vector3 &t)
Definition matrix.h:95
constexpr TRect GetPositive() const
Get a version of this rectangle that has a non-negative size.
Definition rect.h:398

References impeller::Matrix::Basis(), blur_radius, impeller::CreateVertexBuffer(), impeller::RenderPass::Draw(), impeller::Entity::GetBlendMode(), impeller::TRect< T >::GetCenter(), impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetOrigin(), impeller::TRect< T >::GetPositive(), impeller::Entity::GetShaderClipDepth(), impeller::Entity::GetShaderTransform(), impeller::TRect< T >::GetSize(), impeller::Entity::GetTransform(), impeller::ContentContext::GetTransientsDataBuffer(), impeller::TRect< T >::GetWidth(), impeller::Matrix::Invert(), impeller::ContentContextOptions::is_for_rrect_blur_clear, impeller::kClear, impeller::kEhCloseEnough, impeller::kTriangleStrip, impeller::Matrix::MakeTranslation(), fml::Status::ok(), impeller::OptionsFromPassAndEntity(), impeller::SolidRRectLikeBlurContents::PassContext::opts, impeller::ContentContextOptions::primitive_type, SetPassInfo(), impeller::RenderPass::SetVertexBuffer(), impeller::Sigma::sigma, impeller::Color::White(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

◆ SetColor()

void impeller::SolidRRectLikeBlurContents::SetColor ( Color  color)

Definition at line 42 of file solid_rrect_like_blur_contents.cc.

42 {
43 color_ = color.Premultiply();
44}
constexpr Color Premultiply() const
Definition color.h:212

References impeller::Color::Premultiply().

◆ SetPassInfo()

virtual bool impeller::SolidRRectLikeBlurContents::SetPassInfo ( RenderPass pass,
const ContentContext renderer,
PassContext pass_context 
) const
protectedpure virtual

Implemented in impeller::SolidRRectBlurContents.

Referenced by Render().

◆ SetShape()

void impeller::SolidRRectLikeBlurContents::SetShape ( Rect  rect,
Scalar  corner_radius 
)

Definition at line 33 of file solid_rrect_like_blur_contents.cc.

33 {
34 rect_ = rect;
35 corner_radius_ = corner_radius;
36}

◆ SetSigma()

void impeller::SolidRRectLikeBlurContents::SetSigma ( Sigma  sigma)

Definition at line 38 of file solid_rrect_like_blur_contents.cc.

38 {
39 sigma_ = sigma;
40}

The documentation for this class was generated from the following files: