From ec74b5fbef0edddfe8fe9d01402956ed9eeffd37 Mon Sep 17 00:00:00 2001 From: gaaclarke <30870216+gaaclarke@users.noreply.github.com> Date: Thu, 1 Feb 2024 11:12:43 -0800 Subject: [PATCH] [Impeller] new blur: round downsample to power of two (flutter/engine#50245) This makes the downsampling step of the new blur round to the nearest power of 2. This makes the changes in downsampling less frequent and the output of downsampling hypothetically higher quality since downsampling by a power of 2 is easier. issue: https://github.com/flutter/flutter/issues/141510 ## before https://github.com/flutter/engine/assets/30870216/73e78f02-1346-4dde-ad6e-8aaa7c910bac ## after https://github.com/flutter/engine/assets/30870216/b4153ada-6a82-4d0a-a4c2-158134c7b74f [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../entity/contents/filters/gaussian_blur_filter_contents.cc | 5 ++++- engine/src/flutter/impeller/entity/entity_unittests.cc | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index 838a87c4086..f9f9aa77ca7 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -207,7 +207,10 @@ Scalar GaussianBlurFilterContents::CalculateScale(Scalar sigma) { if (sigma <= 4) { return 1.0; } - return 4.0 / sigma; + Scalar result = 4.0 / sigma; + // Round to the nearest 1/(2^n) to get the best quality down scaling. + Scalar rounded = pow(2.0f, round(log2(result))); + return rounded; }; std::optional GaussianBlurFilterContents::GetFilterSourceCoverage( diff --git a/engine/src/flutter/impeller/entity/entity_unittests.cc b/engine/src/flutter/impeller/entity/entity_unittests.cc index 6841439095d..042c1baf2d4 100644 --- a/engine/src/flutter/impeller/entity/entity_unittests.cc +++ b/engine/src/flutter/impeller/entity/entity_unittests.cc @@ -987,7 +987,8 @@ TEST_P(EntityTest, Filters) { } TEST_P(EntityTest, GaussianBlurFilter) { - auto boston = CreateTextureForFixture("boston.jpg"); + auto boston = + CreateTextureForFixture("boston.jpg", /*enable_mipmapping=*/true); ASSERT_TRUE(boston); auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {