From eb293e7c594a706c0af2bd0d591ce8501162ddfd Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Thu, 1 Feb 2024 10:08:24 -0800 Subject: [PATCH] [Impeller] new blur: round downsample to power of two --- .../entity/contents/filters/gaussian_blur_filter_contents.cc | 5 ++++- impeller/entity/entity_unittests.cc | 3 ++- 2 files changed, 6 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 838a87c408610..f9f9aa77ca758 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/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/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index 6841439095d06..042c1baf2d425 100644 --- a/impeller/entity/entity_unittests.cc +++ b/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 {