24 Scalar scalar = std::min((1.0f / 47.6f) * sigma + 2.5f, 3.5f);
25 return sigma * scalar;
36 corner_radii_ = corner_radii;
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));
100 return frag_info.center.IsFinite() &&
101 frag_info.adjust.IsFinite() &&
102 std::isfinite(frag_info.minEdge) &&
103 std::isfinite(frag_info.r1) &&
104 std::isfinite(frag_info.exponent) &&
105 std::isfinite(frag_info.sInv) &&
106 std::isfinite(frag_info.exponentInv) &&
107 std::isfinite(frag_info.scale);
111 const Entity& entity)
const {
112 if (!rect_.has_value()) {
118 return rect_->Expand(radius).TransformBounds(entity.
GetTransform());
124 if (!rect_.has_value()) {
138 Rect positive_rect = rect_->GetPositive();
144 std::array<VS::PerVertexData, 4> vertices = {
145 VS::PerVertexData{
Point(left, top)},
146 VS::PerVertexData{
Point(right, top)},
147 VS::PerVertexData{
Point(left, bottom)},
148 VS::PerVertexData{
Point(right, bottom)},
153 Color color = color_;
159 VS::FrameInfo frame_info;
165 FS::FragInfo frag_info;
166 frag_info.color = color;
181 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
182 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
184 if (!pass.
Draw().ok()) {
193 color_ = color_filter_proc(color_);
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
PipelineRef GetRRectBlurPipeline(ContentContextOptions opts) const
std::function< Color(Color)> ColorFilterProc
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
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 void SetPipeline(PipelineRef pipeline)
The pipeline to use for this command.
virtual fml::Status Draw()
Record the currently pending command.
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
VertexShader_ VertexShader
FragmentShader_ FragmentShader
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.
bool ApplyColorFilter(const ColorFilterProc &color_filter_proc) override
If possible, applies a color filter to this contents inputs on the CPU.
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
void SetSigma(Sigma sigma)
~SolidRRectBlurContents() override
void SetColor(Color color)
void SetRRect(std::optional< Rect > rect, Size corner_radii={})
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)
GlyphAtlasPipeline::VertexShader VS
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 bool SetupFragInfo(RRectBlurPipeline::FragmentShader::FragInfo &frag_info, Scalar blurSigma, Point center, Point rSize, Scalar radius)
static Scalar kTwoOverSqrtPi
GlyphAtlasPipeline::FragmentShader FS
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
static constexpr Matrix MakeTranslation(const Vector3 &t)
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
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 Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
constexpr Point GetCenter() const
Get the center point as a |Point|.