Another coverage fix for border mask blur (flutter/engine#158)

This commit is contained in:
Brandon DeRosier
2022-04-25 12:23:38 -07:00
committed by Dan Field
parent 7cea95af87
commit 389534cb82
2 changed files with 37 additions and 12 deletions

View File

@@ -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));

View File

@@ -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);
@@ -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