Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
Contributor 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
4 changes: 3 additions & 1 deletion impeller/entity/contents/solid_rrect_blur_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "impeller/entity/contents/content_context.h"
#include "impeller/entity/entity.h"
#include "impeller/geometry/color.h"
#include "impeller/geometry/constants.h"
#include "impeller/geometry/path.h"
#include "impeller/geometry/path_builder.h"
#include "impeller/renderer/render_pass.h"
Expand Down Expand Up @@ -63,7 +64,8 @@ std::optional<Rect> SolidRRectBlurContents::GetCoverage(
bool SolidRRectBlurContents::Render(const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const {
if (!rect_.has_value()) {
// Early return if sigma is close to zero to avoid rendering NaNs.
if (!rect_.has_value() || std::fabs(sigma_.sigma) <= kEhCloseEnough) {
return true;
}

Expand Down