[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
This commit is contained in:
gaaclarke
2024-02-01 11:12:43 -08:00
committed by GitHub
parent 7c04b55f07
commit ec74b5fbef
2 changed files with 6 additions and 2 deletions

View File

@@ -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<Rect> GaussianBlurFilterContents::GetFilterSourceCoverage(

View File

@@ -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 {