Skip to content

Commit

Permalink
[Impeller] shrunk the buffer for the rrect_blur (#53068)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke authored May 28, 2024
1 parent 2feb07c commit 414229b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
34 changes: 22 additions & 12 deletions impeller/aiks/aiks_blur_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,29 @@ TEST_P(AiksTest, ClearBlendWithBlur) {
}

TEST_P(AiksTest, BlurHasNoEdge) {
Canvas canvas;
canvas.Scale(GetContentScale());
canvas.DrawPaint({});
Paint blur = {
.color = Color::Green(),
.mask_blur_descriptor =
Paint::MaskBlurDescriptor{
.style = FilterContents::BlurStyle::kNormal,
.sigma = Sigma(47.6),
},
Scalar sigma = 47.6;
auto callback = [&](AiksContext& renderer) -> std::optional<Picture> {
if (AiksTest::ImGuiBegin("Controls", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::SliderFloat("Sigma", &sigma, 0, 50);
ImGui::End();
}
Canvas canvas;
canvas.Scale(GetContentScale());
canvas.DrawPaint({});
Paint blur = {
.color = Color::Green(),
.mask_blur_descriptor =
Paint::MaskBlurDescriptor{
.style = FilterContents::BlurStyle::kNormal,
.sigma = Sigma(sigma),
},
};
canvas.DrawRect(Rect::MakeXYWH(300, 300, 200, 200), blur);
return canvas.EndRecordingAsPicture();
};
canvas.DrawRect(Rect::MakeXYWH(300, 300, 200, 200), blur);
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));

ASSERT_TRUE(OpenPlaygroundHere(callback));
}

TEST_P(AiksTest, BlurredRectangleWithShader) {
Expand Down
10 changes: 7 additions & 3 deletions impeller/entity/contents/solid_rrect_blur_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
namespace impeller {

namespace {
// Generous padding to make sure blurs with large sigmas are fully visible.
// Used to expand the geometry around the rrect.
// Generous padding to make sure blurs with large sigmas are fully visible. Used
// to expand the geometry around the rrect. Larger sigmas have more subtle
// gradients so they need larger padding to avoid hard cutoffs. Sigma is
// maximized to 3.5 since that should cover 99.95% of all samples. 3.0 should
// cover 99.7% but that was seen to be not enough for large sigmas.
Scalar PadForSigma(Scalar sigma) {
return sigma * 4.0;
Scalar scalar = std::min((1.0f / 47.6f) * sigma + 2.5f, 3.5f);
return sigma * scalar;
}
} // namespace

Expand Down

0 comments on commit 414229b

Please sign in to comment.