From 1846c0d3948584263bbd23839a988b42febf909d Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Thu, 6 Jun 2024 09:45:51 -0700 Subject: [PATCH 01/15] [Impeller] fixes non-uniform gaussian blurs of non-textures --- impeller/aiks/aiks_blur_unittests.cc | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/impeller/aiks/aiks_blur_unittests.cc b/impeller/aiks/aiks_blur_unittests.cc index e3253b39488b9..96bd0f589b7ab 100644 --- a/impeller/aiks/aiks_blur_unittests.cc +++ b/impeller/aiks/aiks_blur_unittests.cc @@ -665,6 +665,46 @@ TEST_P(AiksTest, GaussianBlurRotatedAndClippedInteractive) { ASSERT_TRUE(OpenPlaygroundHere(callback)); } +TEST_P(AiksTest, GaussianBlurRotatedNonUniform) { + auto callback = [&](AiksContext& renderer) -> std::optional { + const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"}; + const Entity::TileMode tile_modes[] = { + Entity::TileMode::kClamp, Entity::TileMode::kRepeat, + Entity::TileMode::kMirror, Entity::TileMode::kDecal}; + + static float rotation = 45; + static float scale = 0.6; + static int selected_tile_mode = 3; + + if (AiksTest::ImGuiBegin("Controls", nullptr, + ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::SliderFloat("Rotation (degrees)", &rotation, -180, 180); + ImGui::SliderFloat("Scale", &scale, 0, 2.0); + ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names, + sizeof(tile_mode_names) / sizeof(char*)); + ImGui::End(); + } + + Canvas canvas; + Paint paint = { + .color = Color::Green(), + .image_filter = + ImageFilter::MakeBlur(Sigma(50.0), Sigma(0.0), + FilterContents::BlurStyle::kNormal, + tile_modes[selected_tile_mode])}; + Vector2 center = Vector2(1024, 768) / 2; + canvas.Scale(GetContentScale()); + canvas.Translate({center.x, center.y, 0}); + canvas.Scale({scale, scale, 1}); + canvas.Rotate(Degrees(rotation)); + + canvas.DrawRRect(Rect::MakeXYWH(-100, -100, 200, 200), Size(10, 10), paint); + return canvas.EndRecordingAsPicture(); + }; + + ASSERT_TRUE(OpenPlaygroundHere(callback)); +} + // This addresses a bug where tiny blurs could result in mip maps that beyond // the limits for the textures used for blurring. // See also: b/323402168 From e4795ed54436f6e288c80bd2680c092f4f4f4f25 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Thu, 6 Jun 2024 10:57:35 -0700 Subject: [PATCH 02/15] pulled out decompose function --- .../filters/gaussian_blur_filter_contents.cc | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index 0dfbdf2211db4..573bc423bf0c9 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -379,6 +379,22 @@ std::optional GaussianBlurFilterContents::GetFilterCoverage( return input_coverage.value().Expand(Point(local_padding.x, local_padding.y)); } +namespace { +struct DecomposedMatrix { + Vector2 scale; + Scalar rotation; +}; + +DecomposedMatrix DecomposeMatrix(const Matrix& matrix) { + Vector2 entity_scale_x = matrix * Vector2(1.0, 0.0); + Vector2 entity_scale_y = matrix * Vector2(0.0, 1.0); + return DecomposedMatrix{ + .scale = Vector2(entity_scale_x.GetLength(), entity_scale_y.GetLength()), + .rotation = atan2(entity_scale_x.y, entity_scale_x.x), + }; +} +} // namespace + std::optional GaussianBlurFilterContents::RenderFilter( const FilterInput::Vector& inputs, const ContentContext& renderer, @@ -390,13 +406,14 @@ std::optional GaussianBlurFilterContents::RenderFilter( return std::nullopt; } - Vector2 entity_scale_x = entity.GetTransform().Basis() * Vector2(1.0, 0.0); - Vector2 entity_scale_y = entity.GetTransform().Basis() * Vector2(0.0, 1.0); - Vector2 scaled_sigma = (effect_transform.Basis() * - Matrix::MakeScale({entity_scale_x.GetLength(), - entity_scale_y.GetLength(), 1.0}) * - Vector2(ScaleSigma(sigma_x_), ScaleSigma(sigma_y_))) - .Abs(); + DecomposedMatrix decomposed_entity_transform = + DecomposeMatrix(entity.GetTransform().Basis()); + Vector2 scaled_sigma = + (effect_transform.Basis() * + Matrix::MakeScale({decomposed_entity_transform.scale.x, + decomposed_entity_transform.scale.y, 1.0}) * + Vector2(ScaleSigma(sigma_x_), ScaleSigma(sigma_y_))) + .Abs(); scaled_sigma.x = std::min(scaled_sigma.x, kMaxSigma); scaled_sigma.y = std::min(scaled_sigma.y, kMaxSigma); Vector2 blur_radius = Vector2(CalculateBlurRadius(scaled_sigma.x), From ec71008a9df6d3577d15aa71597d6df99a5fc05f Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Thu, 6 Jun 2024 14:02:20 -0700 Subject: [PATCH 03/15] it draws right for this one case --- .../filters/gaussian_blur_filter_contents.cc | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index 573bc423bf0c9..ee494170ca580 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -408,12 +408,10 @@ std::optional GaussianBlurFilterContents::RenderFilter( DecomposedMatrix decomposed_entity_transform = DecomposeMatrix(entity.GetTransform().Basis()); - Vector2 scaled_sigma = - (effect_transform.Basis() * - Matrix::MakeScale({decomposed_entity_transform.scale.x, - decomposed_entity_transform.scale.y, 1.0}) * - Vector2(ScaleSigma(sigma_x_), ScaleSigma(sigma_y_))) - .Abs(); + FML_LOG(ERROR) << decomposed_entity_transform.rotation; + Vector2 scaled_sigma = (effect_transform.Basis() * + Vector2(ScaleSigma(sigma_x_), ScaleSigma(sigma_y_))) + .Abs(); scaled_sigma.x = std::min(scaled_sigma.x, kMaxSigma); scaled_sigma.y = std::min(scaled_sigma.y, kMaxSigma); Vector2 blur_radius = Vector2(CalculateBlurRadius(scaled_sigma.x), @@ -437,9 +435,14 @@ std::optional GaussianBlurFilterContents::RenderFilter( mip_count = 1; } + Entity snapshot_entity = entity.Clone(); + snapshot_entity.SetTransform(Matrix()); + std::optional source_expanded_coverage_hint = + expanded_coverage_hint->TransformBounds(entity.GetTransform().Invert()); + std::optional input_snapshot = - inputs[0]->GetSnapshot("GaussianBlur", renderer, entity, - /*coverage_limit=*/expanded_coverage_hint, + inputs[0]->GetSnapshot("GaussianBlur", renderer, snapshot_entity, + /*coverage_limit=*/source_expanded_coverage_hint, /*mip_count=*/mip_count); if (!input_snapshot.has_value()) { return std::nullopt; @@ -479,7 +482,7 @@ std::optional GaussianBlurFilterContents::RenderFilter( Vector2 effective_scalar = Vector2(subpass_size) / source_rect_padded.GetSize(); - Quad uvs = CalculateUVs(inputs[0], entity, source_rect_padded, + Quad uvs = CalculateUVs(inputs[0], snapshot_entity, source_rect_padded, input_snapshot->texture->GetSize()); std::shared_ptr command_buffer = @@ -511,7 +514,7 @@ std::optional GaussianBlurFilterContents::RenderFilter( input_snapshot.value().transform.IsTranslationScaleOnly()) { // Only process the uvs where the blur is happening, not the whole texture. std::optional uvs = MakeReferenceUVs(input_snapshot_coverage.value(), - expanded_coverage_hint.value()) + source_expanded_coverage_hint.value()) .Intersection(Rect::MakeSize(Size(1, 1))); FML_DCHECK(uvs.has_value()); if (uvs.has_value()) { @@ -577,7 +580,8 @@ std::optional GaussianBlurFilterContents::RenderFilter( Entity blur_output_entity = Entity::FromSnapshot( Snapshot{.texture = pass3_out.value().GetRenderTargetTexture(), - .transform = input_snapshot->transform * + .transform = entity.GetTransform() * + input_snapshot->transform * padding_snapshot_adjustment * Matrix::MakeScale(1 / effective_scalar), .sampler_descriptor = sampler_desc, From 4796abc8c3b24ac8f7a14e3c0cad2c95c2b80511 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Thu, 6 Jun 2024 14:19:44 -0700 Subject: [PATCH 04/15] removed some tests --- .../filters/gaussian_blur_filter_contents.cc | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index ee494170ca580..fa97ad3251e31 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -379,22 +379,6 @@ std::optional GaussianBlurFilterContents::GetFilterCoverage( return input_coverage.value().Expand(Point(local_padding.x, local_padding.y)); } -namespace { -struct DecomposedMatrix { - Vector2 scale; - Scalar rotation; -}; - -DecomposedMatrix DecomposeMatrix(const Matrix& matrix) { - Vector2 entity_scale_x = matrix * Vector2(1.0, 0.0); - Vector2 entity_scale_y = matrix * Vector2(0.0, 1.0); - return DecomposedMatrix{ - .scale = Vector2(entity_scale_x.GetLength(), entity_scale_y.GetLength()), - .rotation = atan2(entity_scale_x.y, entity_scale_x.x), - }; -} -} // namespace - std::optional GaussianBlurFilterContents::RenderFilter( const FilterInput::Vector& inputs, const ContentContext& renderer, @@ -406,9 +390,6 @@ std::optional GaussianBlurFilterContents::RenderFilter( return std::nullopt; } - DecomposedMatrix decomposed_entity_transform = - DecomposeMatrix(entity.GetTransform().Basis()); - FML_LOG(ERROR) << decomposed_entity_transform.rotation; Vector2 scaled_sigma = (effect_transform.Basis() * Vector2(ScaleSigma(sigma_x_), ScaleSigma(sigma_y_))) .Abs(); From f5d442cf8a695fb5be2bb1fd789ec347a01e78c4 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Thu, 6 Jun 2024 14:20:20 -0700 Subject: [PATCH 05/15] format --- impeller/aiks/aiks_blur_unittests.cc | 5 ++--- .../contents/filters/gaussian_blur_filter_contents.cc | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/impeller/aiks/aiks_blur_unittests.cc b/impeller/aiks/aiks_blur_unittests.cc index 96bd0f589b7ab..df9a937cc18a6 100644 --- a/impeller/aiks/aiks_blur_unittests.cc +++ b/impeller/aiks/aiks_blur_unittests.cc @@ -686,9 +686,8 @@ TEST_P(AiksTest, GaussianBlurRotatedNonUniform) { } Canvas canvas; - Paint paint = { - .color = Color::Green(), - .image_filter = + Paint paint = {.color = Color::Green(), + .image_filter = ImageFilter::MakeBlur(Sigma(50.0), Sigma(0.0), FilterContents::BlurStyle::kNormal, tile_modes[selected_tile_mode])}; diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index fa97ad3251e31..5c1750c2e8170 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -494,9 +494,10 @@ std::optional GaussianBlurFilterContents::RenderFilter( input_snapshot.has_value() && input_snapshot.value().transform.IsTranslationScaleOnly()) { // Only process the uvs where the blur is happening, not the whole texture. - std::optional uvs = MakeReferenceUVs(input_snapshot_coverage.value(), - source_expanded_coverage_hint.value()) - .Intersection(Rect::MakeSize(Size(1, 1))); + std::optional uvs = + MakeReferenceUVs(input_snapshot_coverage.value(), + source_expanded_coverage_hint.value()) + .Intersection(Rect::MakeSize(Size(1, 1))); FML_DCHECK(uvs.has_value()); if (uvs.has_value()) { blur_uvs[0] = uvs->GetLeftTop(); @@ -561,8 +562,7 @@ std::optional GaussianBlurFilterContents::RenderFilter( Entity blur_output_entity = Entity::FromSnapshot( Snapshot{.texture = pass3_out.value().GetRenderTargetTexture(), - .transform = entity.GetTransform() * - input_snapshot->transform * + .transform = entity.GetTransform() * input_snapshot->transform * padding_snapshot_adjustment * Matrix::MakeScale(1 / effective_scalar), .sampler_descriptor = sampler_desc, From 2685b7eeb766cefa3b98512d1a89da1836d490b6 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Thu, 6 Jun 2024 15:22:09 -0700 Subject: [PATCH 06/15] tidy --- .../contents/filters/gaussian_blur_filter_contents.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index 5c1750c2e8170..2a0adf711c030 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -418,8 +418,14 @@ std::optional GaussianBlurFilterContents::RenderFilter( Entity snapshot_entity = entity.Clone(); snapshot_entity.SetTransform(Matrix()); - std::optional source_expanded_coverage_hint = - expanded_coverage_hint->TransformBounds(entity.GetTransform().Invert()); + std::optional source_expanded_coverage_hint; + FML_DCHECK(expanded_coverage_hint.has_value()); + if (expanded_coverage_hint.has_value()) { + source_expanded_coverage_hint = + expanded_coverage_hint->TransformBounds(entity.GetTransform().Invert()); + } else { + return std::nullopt; + } std::optional input_snapshot = inputs[0]->GetSnapshot("GaussianBlur", renderer, snapshot_entity, From b8394c1c7ed2e96f4a7b60b55116b31c3fc61476 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 7 Jun 2024 09:47:29 -0700 Subject: [PATCH 07/15] made lack of a hint not a crash --- .../entity/contents/filters/gaussian_blur_filter_contents.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index 2a0adf711c030..4be2da173d230 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -419,12 +419,9 @@ std::optional GaussianBlurFilterContents::RenderFilter( Entity snapshot_entity = entity.Clone(); snapshot_entity.SetTransform(Matrix()); std::optional source_expanded_coverage_hint; - FML_DCHECK(expanded_coverage_hint.has_value()); if (expanded_coverage_hint.has_value()) { source_expanded_coverage_hint = expanded_coverage_hint->TransformBounds(entity.GetTransform().Invert()); - } else { - return std::nullopt; } std::optional input_snapshot = From 3b5067bfa48147cbb708e45d6f508c81af0d89d4 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 7 Jun 2024 09:47:44 -0700 Subject: [PATCH 08/15] temporarily turn off coverage test to get goldens --- ...gaussian_blur_filter_contents_unittests.cc | 72 ++++++++++--------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents_unittests.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents_unittests.cc index dad6c5bc0ba6d..be953e6e1b246 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents_unittests.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents_unittests.cc @@ -369,41 +369,43 @@ TEST_P(GaussianBlurFilterContentsTest, TextureContentsWithDestinationRect) { } } -TEST_P(GaussianBlurFilterContentsTest, - TextureContentsWithDestinationRectScaled) { - std::shared_ptr texture = MakeTexture(ISize(100, 100)); - auto texture_contents = std::make_shared(); - texture_contents->SetSourceRect(Rect::MakeSize(texture->GetSize())); - texture_contents->SetTexture(texture); - texture_contents->SetDestinationRect(Rect::MakeXYWH( - 50, 40, texture->GetSize().width, texture->GetSize().height)); - - fml::StatusOr sigma_radius_1 = - CalculateSigmaForBlurRadius(1.0, Matrix()); - auto contents = std::make_unique( - sigma_radius_1.value(), sigma_radius_1.value(), Entity::TileMode::kDecal, - FilterContents::BlurStyle::kNormal, /*mask_geometry=*/nullptr); - contents->SetInputs({FilterInput::Make(texture_contents)}); - std::shared_ptr renderer = GetContentContext(); - - Entity entity; - entity.SetTransform(Matrix::MakeScale({2.0, 2.0, 1.0})); - std::optional result = - contents->GetEntity(*renderer, entity, /*coverage_hint=*/{}); - EXPECT_TRUE(result.has_value()); - if (result.has_value()) { - EXPECT_EQ(result.value().GetBlendMode(), BlendMode::kSourceOver); - std::optional result_coverage = result.value().GetCoverage(); - std::optional contents_coverage = contents->GetCoverage(entity); - EXPECT_TRUE(result_coverage.has_value()); - EXPECT_TRUE(contents_coverage.has_value()); - if (result_coverage.has_value() && contents_coverage.has_value()) { - EXPECT_TRUE(RectNear(result_coverage.value(), contents_coverage.value())); - EXPECT_TRUE(RectNear(contents_coverage.value(), - Rect::MakeXYWH(94.f, 74.f, 212.f, 212.f))); - } - } -} +// TEST_P(GaussianBlurFilterContentsTest, +// TextureContentsWithDestinationRectScaled) { +// std::shared_ptr texture = MakeTexture(ISize(100, 100)); +// auto texture_contents = std::make_shared(); +// texture_contents->SetSourceRect(Rect::MakeSize(texture->GetSize())); +// texture_contents->SetTexture(texture); +// texture_contents->SetDestinationRect(Rect::MakeXYWH( +// 50, 40, texture->GetSize().width, texture->GetSize().height)); + +// fml::StatusOr sigma_radius_1 = +// CalculateSigmaForBlurRadius(1.0, Matrix()); +// auto contents = std::make_unique( +// sigma_radius_1.value(), sigma_radius_1.value(), +// Entity::TileMode::kDecal, FilterContents::BlurStyle::kNormal, +// /*mask_geometry=*/nullptr); +// contents->SetInputs({FilterInput::Make(texture_contents)}); +// std::shared_ptr renderer = GetContentContext(); + +// Entity entity; +// entity.SetTransform(Matrix::MakeScale({2.0, 2.0, 1.0})); +// std::optional result = +// contents->GetEntity(*renderer, entity, /*coverage_hint=*/{}); +// EXPECT_TRUE(result.has_value()); +// if (result.has_value()) { +// EXPECT_EQ(result.value().GetBlendMode(), BlendMode::kSourceOver); +// std::optional result_coverage = result.value().GetCoverage(); +// std::optional contents_coverage = contents->GetCoverage(entity); +// EXPECT_TRUE(result_coverage.has_value()); +// EXPECT_TRUE(contents_coverage.has_value()); +// if (result_coverage.has_value() && contents_coverage.has_value()) { +// EXPECT_TRUE(RectNear(result_coverage.value(), +// contents_coverage.value())); +// EXPECT_TRUE(RectNear(contents_coverage.value(), +// Rect::MakeXYWH(94.f, 74.f, 212.f, 212.f))); +// } +// } +// } TEST_P(GaussianBlurFilterContentsTest, TextureContentsWithEffectTransform) { Matrix effect_transform = Matrix::MakeScale({2.0, 2.0, 1.0}); From 34d3455600bafed40bdc5d4e13676fce4250b62f Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 7 Jun 2024 10:03:51 -0700 Subject: [PATCH 09/15] fixed coverage test and turned it back on --- .../filters/gaussian_blur_filter_contents.cc | 20 +++-- ...gaussian_blur_filter_contents_unittests.cc | 73 +++++++++---------- 2 files changed, 48 insertions(+), 45 deletions(-) diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index 4be2da173d230..2a90f97f84c9b 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -359,15 +359,14 @@ std::optional GaussianBlurFilterContents::GetFilterCoverage( return {}; } - std::optional input_coverage = inputs[0]->GetCoverage(entity); - if (!input_coverage.has_value()) { + Entity snapshot_entity = entity.Clone(); + snapshot_entity.SetTransform(Matrix()); + std::optional source_coverage = inputs[0]->GetCoverage(snapshot_entity); + if (!source_coverage.has_value()) { return {}; } - Vector2 entity_scale_x = entity.GetTransform().Basis() * Vector2(1.0, 0.0); - Vector2 entity_scale_y = entity.GetTransform().Basis() * Vector2(0.0, 1.0); - Vector2 scaled_sigma = (Matrix::MakeScale({entity_scale_x.GetLength(), - entity_scale_y.GetLength(), 1.0}) * + Vector2 scaled_sigma = (effect_transform.Basis() * Vector2(ScaleSigma(sigma_x_), ScaleSigma(sigma_y_))) .Abs(); scaled_sigma.x = std::min(scaled_sigma.x, kMaxSigma); @@ -375,8 +374,13 @@ std::optional GaussianBlurFilterContents::GetFilterCoverage( Vector2 blur_radius = Vector2(CalculateBlurRadius(scaled_sigma.x), CalculateBlurRadius(scaled_sigma.y)); Vector2 padding(ceil(blur_radius.x), ceil(blur_radius.y)); - Vector2 local_padding = (entity.GetTransform().Basis() * padding).Abs(); - return input_coverage.value().Expand(Point(local_padding.x, local_padding.y)); + std::optional expanded_source_coverage = + source_coverage->Expand(Point(padding.x, padding.y)); + if (expanded_source_coverage.has_value()) { + return expanded_source_coverage->TransformBounds(entity.GetTransform()); + } + + return std::nullopt; } std::optional GaussianBlurFilterContents::RenderFilter( diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents_unittests.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents_unittests.cc index be953e6e1b246..cf4b955f1311a 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents_unittests.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents_unittests.cc @@ -369,43 +369,42 @@ TEST_P(GaussianBlurFilterContentsTest, TextureContentsWithDestinationRect) { } } -// TEST_P(GaussianBlurFilterContentsTest, -// TextureContentsWithDestinationRectScaled) { -// std::shared_ptr texture = MakeTexture(ISize(100, 100)); -// auto texture_contents = std::make_shared(); -// texture_contents->SetSourceRect(Rect::MakeSize(texture->GetSize())); -// texture_contents->SetTexture(texture); -// texture_contents->SetDestinationRect(Rect::MakeXYWH( -// 50, 40, texture->GetSize().width, texture->GetSize().height)); - -// fml::StatusOr sigma_radius_1 = -// CalculateSigmaForBlurRadius(1.0, Matrix()); -// auto contents = std::make_unique( -// sigma_radius_1.value(), sigma_radius_1.value(), -// Entity::TileMode::kDecal, FilterContents::BlurStyle::kNormal, -// /*mask_geometry=*/nullptr); -// contents->SetInputs({FilterInput::Make(texture_contents)}); -// std::shared_ptr renderer = GetContentContext(); - -// Entity entity; -// entity.SetTransform(Matrix::MakeScale({2.0, 2.0, 1.0})); -// std::optional result = -// contents->GetEntity(*renderer, entity, /*coverage_hint=*/{}); -// EXPECT_TRUE(result.has_value()); -// if (result.has_value()) { -// EXPECT_EQ(result.value().GetBlendMode(), BlendMode::kSourceOver); -// std::optional result_coverage = result.value().GetCoverage(); -// std::optional contents_coverage = contents->GetCoverage(entity); -// EXPECT_TRUE(result_coverage.has_value()); -// EXPECT_TRUE(contents_coverage.has_value()); -// if (result_coverage.has_value() && contents_coverage.has_value()) { -// EXPECT_TRUE(RectNear(result_coverage.value(), -// contents_coverage.value())); -// EXPECT_TRUE(RectNear(contents_coverage.value(), -// Rect::MakeXYWH(94.f, 74.f, 212.f, 212.f))); -// } -// } -// } +TEST_P(GaussianBlurFilterContentsTest, + TextureContentsWithDestinationRectScaled) { + std::shared_ptr texture = MakeTexture(ISize(100, 100)); + auto texture_contents = std::make_shared(); + texture_contents->SetSourceRect(Rect::MakeSize(texture->GetSize())); + texture_contents->SetTexture(texture); + texture_contents->SetDestinationRect(Rect::MakeXYWH( + 50, 40, texture->GetSize().width, texture->GetSize().height)); + + fml::StatusOr sigma_radius_1 = + CalculateSigmaForBlurRadius(1.0, Matrix()); + auto contents = std::make_unique( + sigma_radius_1.value(), sigma_radius_1.value(), Entity::TileMode::kDecal, + FilterContents::BlurStyle::kNormal, + /*mask_geometry=*/nullptr); + contents->SetInputs({FilterInput::Make(texture_contents)}); + std::shared_ptr renderer = GetContentContext(); + + Entity entity; + entity.SetTransform(Matrix::MakeScale({2.0, 2.0, 1.0})); + std::optional result = + contents->GetEntity(*renderer, entity, /*coverage_hint=*/{}); + EXPECT_TRUE(result.has_value()); + if (result.has_value()) { + EXPECT_EQ(result.value().GetBlendMode(), BlendMode::kSourceOver); + std::optional result_coverage = result.value().GetCoverage(); + std::optional contents_coverage = contents->GetCoverage(entity); + EXPECT_TRUE(result_coverage.has_value()); + EXPECT_TRUE(contents_coverage.has_value()); + if (result_coverage.has_value() && contents_coverage.has_value()) { + EXPECT_TRUE(RectNear(result_coverage.value(), contents_coverage.value())); + EXPECT_TRUE(RectNear(contents_coverage.value(), + Rect::MakeXYWH(98.f, 78.f, 204.0f, 204.f))); + } + } +} TEST_P(GaussianBlurFilterContentsTest, TextureContentsWithEffectTransform) { Matrix effect_transform = Matrix::MakeScale({2.0, 2.0, 1.0}); From 7ffd89ccb2c2a05bd889f6b241b6e80284341d29 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 7 Jun 2024 10:30:53 -0700 Subject: [PATCH 10/15] tidy and removed unnecessary check --- .../contents/filters/gaussian_blur_filter_contents.cc | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index 2a90f97f84c9b..e4ebe0bc282df 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -492,14 +492,9 @@ std::optional GaussianBlurFilterContents::RenderFilter( std::optional input_snapshot_coverage = input_snapshot->GetCoverage(); Quad blur_uvs = {Point(0, 0), Point(1, 0), Point(0, 1), Point(1, 1)}; - if (expanded_coverage_hint.has_value() && - input_snapshot_coverage.has_value() && - // TODO(https://github.com/flutter/flutter/issues/140890): Remove this - // condition. There is some flaw in coverage stopping us from using this - // today. I attempted to use source coordinates to calculate the uvs, - // but that didn't work either. - input_snapshot.has_value() && - input_snapshot.value().transform.IsTranslationScaleOnly()) { + FML_DCHECK(input_snapshot.value().transform.IsTranslationScaleOnly()); + if (source_expanded_coverage_hint.has_value() && + input_snapshot_coverage.has_value()) { // Only process the uvs where the blur is happening, not the whole texture. std::optional uvs = MakeReferenceUVs(input_snapshot_coverage.value(), From bae3001e8522efd9425e46777e712845a1ebd84b Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 7 Jun 2024 10:53:38 -0700 Subject: [PATCH 11/15] updated golden list --- testing/impeller_golden_tests_output.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testing/impeller_golden_tests_output.txt b/testing/impeller_golden_tests_output.txt index c3c1caba8337b..eb4cf2355e680 100644 --- a/testing/impeller_golden_tests_output.txt +++ b/testing/impeller_golden_tests_output.txt @@ -617,6 +617,9 @@ impeller_Play_AiksTest_GaussianBlurRotatedAndClippedInteractive_Vulkan.png impeller_Play_AiksTest_GaussianBlurRotatedAndClipped_Metal.png impeller_Play_AiksTest_GaussianBlurRotatedAndClipped_OpenGLES.png impeller_Play_AiksTest_GaussianBlurRotatedAndClipped_Vulkan.png +impeller_Play_AiksTest_GaussianBlurRotatedNonUniform_Metal.png +impeller_Play_AiksTest_GaussianBlurRotatedNonUniform_OpenGLES.png +impeller_Play_AiksTest_GaussianBlurRotatedNonUniform_Vulkan.png impeller_Play_AiksTest_GaussianBlurScaledAndClipped_Metal.png impeller_Play_AiksTest_GaussianBlurScaledAndClipped_OpenGLES.png impeller_Play_AiksTest_GaussianBlurScaledAndClipped_Vulkan.png From d1a2c6912f028e3cd7168192bf90d3fd3731be6a Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 7 Jun 2024 13:39:21 -0700 Subject: [PATCH 12/15] fixed zero sigma path --- .../contents/filters/gaussian_blur_filter_contents.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index e4ebe0bc282df..4d679a9d00cee 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -437,8 +437,11 @@ std::optional GaussianBlurFilterContents::RenderFilter( } if (scaled_sigma.x < kEhCloseEnough && scaled_sigma.y < kEhCloseEnough) { - return Entity::FromSnapshot(input_snapshot.value(), - entity.GetBlendMode()); // No blur to render. + Entity result = + Entity::FromSnapshot(input_snapshot.value(), + entity.GetBlendMode()); // No blur to render. + result.SetTransform(entity.GetTransform() * input_snapshot->transform); + return result; } // In order to avoid shimmering in downsampling step, we should have mips. From 3a25e1065f43efd9d46266b7274a1ed1d0ac7512 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 7 Jun 2024 14:05:22 -0700 Subject: [PATCH 13/15] fixed solid blur style --- .../entity/contents/filters/gaussian_blur_filter_contents.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index 4d679a9d00cee..e1c0451b83fb2 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -263,7 +263,8 @@ Entity ApplyBlurStyle(FilterContents::BlurStyle blur_style, Entity::FromSnapshot(input_snapshot, entity.GetBlendMode()); Entity result; Matrix blurred_transform = blur_entity.GetTransform(); - Matrix snapshot_transform = snapshot_entity.GetTransform(); + Matrix snapshot_transform = + entity.GetTransform() * snapshot_entity.GetTransform(); result.SetContents(Contents::MakeAnonymous( fml::MakeCopyable([blur_entity = blur_entity.Clone(), blurred_transform, snapshot_transform, From 8a3188d878bb7a06d5ba2a54eb0e9dd3005e0e66 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 7 Jun 2024 16:47:29 -0700 Subject: [PATCH 14/15] jim feedback --- .../entity/contents/filters/gaussian_blur_filter_contents.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index e1c0451b83fb2..9decf05aba683 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -376,7 +376,7 @@ std::optional GaussianBlurFilterContents::GetFilterCoverage( CalculateBlurRadius(scaled_sigma.y)); Vector2 padding(ceil(blur_radius.x), ceil(blur_radius.y)); std::optional expanded_source_coverage = - source_coverage->Expand(Point(padding.x, padding.y)); + source_coverage->Expand(padding); if (expanded_source_coverage.has_value()) { return expanded_source_coverage->TransformBounds(entity.GetTransform()); } From 927c44ec14e01d2d297ac5bb18e65c34b5ba6848 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 7 Jun 2024 16:50:20 -0700 Subject: [PATCH 15/15] jim feedback 2 --- .../contents/filters/gaussian_blur_filter_contents.cc | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index 9decf05aba683..918d145a75dfd 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -375,13 +375,8 @@ std::optional GaussianBlurFilterContents::GetFilterCoverage( Vector2 blur_radius = Vector2(CalculateBlurRadius(scaled_sigma.x), CalculateBlurRadius(scaled_sigma.y)); Vector2 padding(ceil(blur_radius.x), ceil(blur_radius.y)); - std::optional expanded_source_coverage = - source_coverage->Expand(padding); - if (expanded_source_coverage.has_value()) { - return expanded_source_coverage->TransformBounds(entity.GetTransform()); - } - - return std::nullopt; + Rect expanded_source_coverage = source_coverage->Expand(padding); + return expanded_source_coverage.TransformBounds(entity.GetTransform()); } std::optional GaussianBlurFilterContents::RenderFilter(