Skip to content

Commit 3ebfe9e

Browse files
bderodnfield
authored andcommitted
Another coverage fix for border mask blur (#158)
1 parent da9cfb3 commit 3ebfe9e

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

impeller/entity/contents/filters/border_mask_blur_filter_contents.cc

+3-6
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,10 @@ std::optional<Rect> BorderMaskBlurFilterContents::GetFilterCoverage(
117117
if (!coverage.has_value()) {
118118
return std::nullopt;
119119
}
120-
120+
auto transform = inputs[0]->GetTransform(entity);
121121
auto transformed_blur_vector =
122-
inputs[0]
123-
->GetTransform(entity)
124-
.TransformDirection(
125-
Vector2(Radius{sigma_x_}.radius, Radius{sigma_y_}.radius))
126-
.Abs();
122+
transform.TransformDirection(Vector2(Radius{sigma_x_}.radius, 0)).Abs() +
123+
transform.TransformDirection(Vector2(0, Radius{sigma_y_}.radius)).Abs();
127124
auto extent = coverage->size + transformed_blur_vector * 2;
128125
return Rect(coverage->origin - transformed_blur_vector,
129126
Size(extent.x, extent.y));

impeller/entity/entity_unittests.cc

+34-6
Original file line numberDiff line numberDiff line change
@@ -766,12 +766,12 @@ TEST_P(EntityTest, GaussianBlurFilter) {
766766
// Renders a red "cover" rectangle that shows the original position of the
767767
// unfiltered input.
768768
Entity cover_entity;
769-
cover_entity.SetContents(
770-
SolidColorContents::Make(PathBuilder{}
771-
.AddRect(Rect(-Point(bridge->GetSize()) / 2,
772-
Size(bridge->GetSize())))
773-
.TakePath(),
774-
cover_color));
769+
cover_entity.SetContents(SolidColorContents::Make(
770+
PathBuilder{}
771+
.AddRect(
772+
Rect(-Point(bridge->GetSize()) / 2, Size(bridge->GetSize())))
773+
.TakePath(),
774+
cover_color));
775775
cover_entity.SetTransformation(ctm);
776776

777777
cover_entity.Render(context, pass);
@@ -853,5 +853,33 @@ TEST_P(EntityTest, SolidStrokeCoverageIsCorrect) {
853853
}
854854
}
855855

856+
TEST_P(EntityTest, BorderMaskBlurCoverageIsCorrect) {
857+
auto fill = std::make_shared<SolidColorContents>();
858+
fill->SetPath(
859+
PathBuilder{}.AddRect(Rect::MakeXYWH(0, 0, 300, 400)).TakePath());
860+
fill->SetColor(Color::CornflowerBlue());
861+
auto border_mask_blur = FilterContents::MakeBorderMaskBlur(
862+
FilterInput::Make(fill), FilterContents::Radius{3},
863+
FilterContents::Radius{4});
864+
865+
{
866+
Entity e;
867+
e.SetTransformation(Matrix());
868+
auto actual = border_mask_blur->GetCoverage(e);
869+
auto expected = Rect::MakeXYWH(-3, -4, 306, 408);
870+
ASSERT_TRUE(actual.has_value());
871+
ASSERT_RECT_NEAR(actual.value(), expected);
872+
}
873+
874+
{
875+
Entity e;
876+
e.SetTransformation(Matrix::MakeRotationZ(Radians{kPi / 4}));
877+
auto actual = border_mask_blur->GetCoverage(e);
878+
auto expected = Rect::MakeXYWH(-287.792, -4.94975, 504.874, 504.874);
879+
ASSERT_TRUE(actual.has_value());
880+
ASSERT_RECT_NEAR(actual.value(), expected);
881+
}
882+
}
883+
856884
} // namespace testing
857885
} // namespace impeller

0 commit comments

Comments
 (0)