 |
Flutter Impeller
|
|
Go to the documentation of this file.
24 Scalar scalar = std::min((1.0f / 47.6f) * sigma + 2.5f, 3.5f);
25 return sigma * scalar;
36 corner_radii_ = corner_radii;
44 color_ =
color.Premultiply();
52 Point vOverS = v * sInverse * 0.5;
53 Point vOverS_squared = -(vOverS * vOverS);
54 return {std::exp(vOverS_squared.
x), std::exp(vOverS_squared.
y)};
63 x = x + (0.24295 + (0.03395 + 0.0104 * xx) * xx) * (x * xx);
64 return x / sqrt(1.0 + x * x);
68 return {std::min(v, 0.0f), std::max(v, 0.0f)};
72 RRectBlurPipeline::FragmentShader::FragInfo& frag_info,
79 frag_info.center = rSize * 0.5f;
80 frag_info.minEdge = std::min(rSize.
x, rSize.
y);
81 double rMax = 0.5 * frag_info.minEdge;
82 double r0 = std::min(std::hypot(radius, sigma * 1.15), rMax);
83 frag_info.r1 = std::min(std::hypot(radius, sigma * 2.0), rMax);
85 frag_info.exponent = 2.0 * frag_info.r1 / r0;
87 frag_info.sInv = 1.0 / sigma;
91 double delta = 1.25 * sigma * (eccentricV.
x - eccentricV.
y);
94 frag_info.adjust = rSize * 0.5 - frag_info.r1;
95 frag_info.exponentInv = 1.0 / frag_info.exponent;
98 (std::max(rSize.x, rSize.y) - 0.5 * radius));
102 const Entity& entity)
const {
103 if (!rect_.has_value()) {
109 return rect_->Expand(radius).TransformBounds(entity.
GetTransform());
115 if (!rect_.has_value()) {
129 Rect positive_rect = rect_->GetPositive();
135 std::array<VS::PerVertexData, 4> vertices = {
136 VS::PerVertexData{
Point(left, top)},
137 VS::PerVertexData{
Point(right, top)},
138 VS::PerVertexData{
Point(left, bottom)},
139 VS::PerVertexData{
Point(right, bottom)},
150 VS::FrameInfo frame_info;
156 FS::FragInfo frag_info;
157 frag_info.color =
color;
169 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
170 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
172 if (!pass.
Draw().ok()) {
181 color_ = color_filter_proc(color_);
FragmentShader_ FragmentShader
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
float GetShaderClipDepth() const
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
constexpr float kEhCloseEnough
void SetSigma(Sigma sigma)
void SetColor(Color color)
virtual bool SetVertexBuffer(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
static Scalar computeErf7(Scalar x)
constexpr Point GetCenter() const
Get the center point as a |Point|.
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
static constexpr Matrix MakeTranslation(const Vector3 &t)
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
constexpr TPoint< Type > GetOrigin() const
Returns the upper left corner of the rectangle as specified by the left/top or x/y values when it was...
virtual fml::Status Draw()
Record the currently pending command.
static void SetupFragInfo(RRectBlurPipeline::FragmentShader::FragInfo &frag_info, Scalar blurSigma, Point center, Point rSize, Scalar radius)
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
static Point NegPos(Scalar v)
VertexBuffer CreateVertexBuffer(std::array< VertexType, size > input, HostBuffer &host_buffer)
Create an index-less vertex buffer from a fixed size array.
std::function< Color(Color)> ColorFilterProc
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
static Scalar kTwoOverSqrtPi
VertexShader_ VertexShader
static constexpr Color White()
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
std::shared_ptr< Pipeline< PipelineDescriptor > > GetRRectBlurPipeline(ContentContextOptions opts) const
bool is_for_rrect_blur_clear
bool ApplyColorFilter(const ColorFilterProc &color_filter_proc) override
If possible, applies a color filter to this contents inputs on the CPU.
BlendMode GetBlendMode() const
PrimitiveType primitive_type
Render passes encode render commands directed as one specific render target into an underlying comman...
constexpr TSize< Type > GetSize() const
Returns the size of the rectangle which may be negative in either width or height and may have been c...
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Vector2 blur_radius
Blur radius in source pixels based on scaled_sigma.
void SetRRect(std::optional< Rect > rect, Size corner_radii={})
virtual void SetPipeline(const std::shared_ptr< Pipeline< PipelineDescriptor >> &pipeline)
The pipeline to use for this command.
static Point eccentricity(Point v, double sInverse)
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.
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
~SolidRRectBlurContents() override