Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] Skip mask blur with 0 sigma. #48457

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4096,5 +4096,23 @@ TEST_P(AiksTest, ArcWithZeroSweepAndBlur) {
canvas.EndRecordingAsPicture();
}

TEST_P(AiksTest, MaskBlurWithZeroSigmaIsSkipped) {
Canvas canvas;

Paint paint = {
.color = Color::White(),
.mask_blur_descriptor =
Paint::MaskBlurDescriptor{
.style = FilterContents::BlurStyle::kNormal,
.sigma = Sigma(0),
},
};

canvas.DrawCircle({300, 300}, 200, paint);
canvas.DrawRect(Rect::MakeLTRB(100, 300, 500, 600), paint);

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

} // namespace testing
} // namespace impeller
5 changes: 5 additions & 0 deletions impeller/aiks/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "impeller/entity/contents/texture_contents.h"
#include "impeller/entity/contents/vertices_contents.h"
#include "impeller/entity/geometry/geometry.h"
#include "impeller/geometry/constants.h"
#include "impeller/geometry/path_builder.h"

namespace impeller {
Expand Down Expand Up @@ -202,6 +203,10 @@ bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
paint.mask_blur_descriptor->style != FilterContents::BlurStyle::kNormal) {
return false;
}
// A blur sigma that is close to zero should not result in any shadow.
if (std::fabs(paint.mask_blur_descriptor->sigma.sigma) <= kEhCloseEnough) {
return true;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add an early return to SolidRRectBlurContents too?

Because there's no guard against zero sigma, nothing is protecting us from div by zero in IPGaussian, so NaNs are probably propagating from the shader and getting mapped to a negative number on the float format we use for wide gamut.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Sorry for the late red light, I just realized what's probably happening here.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Yes the nan issue, I remember it now. Thanks @bdero :)


Paint new_paint = paint;

Expand Down