24 Scalar scalar = std::min((1.0f / 47.6f) * sigma + 2.5f, 3.5f);
25 return sigma * scalar;
35 corner_radius_ = corner_radius;
51 Point vOverS = v * sInverse * 0.5;
52 Point vOverS_squared = -(vOverS * vOverS);
53 return {std::exp(vOverS_squared.
x), std::exp(vOverS_squared.
y)};
62 x =
x + (0.24295 + (0.03395 + 0.0104 * xx) * xx) * (
x * xx);
63 return x / sqrt(1.0 +
x *
x);
67 return {std::min(v, 0.0f), std::max(v, 0.0f)};
70 bool SolidRRectLikeBlurContents::PopulateFragContext(PassContext& pass_context,
77 pass_context.center = rSize * 0.5f;
78 pass_context.minEdge = std::min(rSize.x, rSize.y);
79 double rMax = 0.5 * pass_context.minEdge;
80 double r0 = std::min(std::hypot(radius, sigma * 1.15), rMax);
81 pass_context.r1 = std::min(std::hypot(radius, sigma * 2.0), rMax);
83 pass_context.exponent = 2.0 * pass_context.r1 / r0;
85 pass_context.sInv = 1.0 / sigma;
89 double delta = 1.25 * sigma * (eccentricV.x - eccentricV.y);
92 pass_context.adjust = rSize * 0.5 - pass_context.r1;
93 pass_context.exponentInv = 1.0 / pass_context.exponent;
96 (std::max(rSize.x, rSize.y) - 0.5 * radius));
98 return pass_context.center.IsFinite() &&
99 pass_context.adjust.IsFinite() &&
100 std::isfinite(pass_context.minEdge) &&
101 std::isfinite(pass_context.r1) &&
102 std::isfinite(pass_context.exponent) &&
103 std::isfinite(pass_context.sInv) &&
104 std::isfinite(pass_context.exponentInv) &&
105 std::isfinite(pass_context.scale);
109 const Entity& entity)
const {
118 using VS = RrectLikeBlurVertexShader;
123 (basis_invert *
Vector2(0.f, 500.f)).GetLength());
124 Scalar max_sigma = std::min(max_sigmas.
x, max_sigmas.
y);
140 Color color = color_;
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)},
161 if (!PopulateFragContext(pass_context, blur_sigma, positive_rect.
GetCenter(),
170 VS::FrameInfo frame_info;
178 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
180 if (!pass.
Draw().ok()) {
189 color_ = color_filter_proc(color_);
194 return {a.
x, a.
y,
b.x,
b.y};
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
std::function< Color(Color)> ColorFilterProc
Matrix GetShaderTransform(const RenderPass &pass) const
BlendMode GetBlendMode() const
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
float GetShaderClipDepth() const
Render passes encode render commands directed as one specific render target into an underlying comman...
virtual bool SetVertexBuffer(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
virtual fml::Status Draw()
Record the currently pending command.
void SetShape(Rect rect, Scalar corner_radius)
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.
~SolidRRectLikeBlurContents() override
virtual bool SetPassInfo(RenderPass &pass, const ContentContext &renderer, PassContext &pass_context) const =0
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
void SetSigma(Sigma sigma)
bool ApplyColorFilter(const ColorFilterProc &color_filter_proc) override
If possible, applies a color filter to this contents inputs on the CPU.
static Vector4 Concat(Vector2 &a, Vector2 &b)
SolidRRectLikeBlurContents()
void SetColor(Color color)
Vector2 blur_radius
Blur radius in source pixels based on scaled_sigma.
static Scalar computeErf7(Scalar x)
constexpr float kEhCloseEnough
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.
static Point eccentricity(Point v, double sInverse)
static Scalar kTwoOverSqrtPi
LinePipeline::VertexShader VS
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
static constexpr Color White()
constexpr Color Premultiply() const
PrimitiveType primitive_type
bool is_for_rrect_blur_clear
A 4x4 matrix using column-major storage.
static constexpr Matrix MakeTranslation(const Vector3 &t)
constexpr Matrix Basis() const
The Matrix without its w components (without translation).
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
ContentContextOptions opts
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
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...
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...
constexpr TRect GetPositive() const
Get a version of this rectangle that has a non-negative size.
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
constexpr Point GetCenter() const
Get the center point as a |Point|.