Skip to content

Commit

Permalink
Another coverage fix for border mask blur (flutter#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdero authored and dnfield committed Apr 27, 2022
1 parent da9cfb3 commit 3ebfe9e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,10 @@ std::optional<Rect> BorderMaskBlurFilterContents::GetFilterCoverage(
if (!coverage.has_value()) {
return std::nullopt;
}

auto transform = inputs[0]->GetTransform(entity);
auto transformed_blur_vector =
inputs[0]
->GetTransform(entity)
.TransformDirection(
Vector2(Radius{sigma_x_}.radius, Radius{sigma_y_}.radius))
.Abs();
transform.TransformDirection(Vector2(Radius{sigma_x_}.radius, 0)).Abs() +
transform.TransformDirection(Vector2(0, Radius{sigma_y_}.radius)).Abs();
auto extent = coverage->size + transformed_blur_vector * 2;
return Rect(coverage->origin - transformed_blur_vector,
Size(extent.x, extent.y));
Expand Down
40 changes: 34 additions & 6 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -766,12 +766,12 @@ TEST_P(EntityTest, GaussianBlurFilter) {
// Renders a red "cover" rectangle that shows the original position of the
// unfiltered input.
Entity cover_entity;
cover_entity.SetContents(
SolidColorContents::Make(PathBuilder{}
.AddRect(Rect(-Point(bridge->GetSize()) / 2,
Size(bridge->GetSize())))
.TakePath(),
cover_color));
cover_entity.SetContents(SolidColorContents::Make(
PathBuilder{}
.AddRect(
Rect(-Point(bridge->GetSize()) / 2, Size(bridge->GetSize())))
.TakePath(),
cover_color));
cover_entity.SetTransformation(ctm);

cover_entity.Render(context, pass);
Expand Down Expand Up @@ -853,5 +853,33 @@ TEST_P(EntityTest, SolidStrokeCoverageIsCorrect) {
}
}

TEST_P(EntityTest, BorderMaskBlurCoverageIsCorrect) {
auto fill = std::make_shared<SolidColorContents>();
fill->SetPath(
PathBuilder{}.AddRect(Rect::MakeXYWH(0, 0, 300, 400)).TakePath());
fill->SetColor(Color::CornflowerBlue());
auto border_mask_blur = FilterContents::MakeBorderMaskBlur(
FilterInput::Make(fill), FilterContents::Radius{3},
FilterContents::Radius{4});

{
Entity e;
e.SetTransformation(Matrix());
auto actual = border_mask_blur->GetCoverage(e);
auto expected = Rect::MakeXYWH(-3, -4, 306, 408);
ASSERT_TRUE(actual.has_value());
ASSERT_RECT_NEAR(actual.value(), expected);
}

{
Entity e;
e.SetTransformation(Matrix::MakeRotationZ(Radians{kPi / 4}));
auto actual = border_mask_blur->GetCoverage(e);
auto expected = Rect::MakeXYWH(-287.792, -4.94975, 504.874, 504.874);
ASSERT_TRUE(actual.has_value());
ASSERT_RECT_NEAR(actual.value(), expected);
}
}

} // namespace testing
} // namespace impeller

0 comments on commit 3ebfe9e

Please sign in to comment.