Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit aede5b0

Browse files
authored
Reland: [Impeller] Turned on new blur. (#48472) (#49642)
This is a reland of the new gaussian blur. Changes since revert: 1) Textures are now recycled with ping ponging to reduce memory usage 1) Mipmaps are generated to diminish the shimmering that happens with animated blurs (in metal) --- This new blur should perform faster since it scales down the image before blurring it. Jonah did early testing of it and found it to be faster. Scrolling around with the blur perf bug it seems faster. It also has a wider test bed and is hopefully easier to maintain since it contains all of its logic for both directions. testing: There are existing blur tests and we've backfilled more as we've added features to this blur. fixes flutter/flutter#131580 fixes flutter/flutter#138259 https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
1 parent 6614de3 commit aede5b0

File tree

4 files changed

+41
-44
lines changed

4 files changed

+41
-44
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3758,10 +3758,13 @@ TEST_P(AiksTest, GaussianBlurSetsMipCountOnPass) {
37583758
canvas.Restore();
37593759

37603760
Picture picture = canvas.EndRecordingAsPicture();
3761-
EXPECT_EQ(1, picture.pass->GetRequiredMipCount());
3761+
EXPECT_EQ(4, picture.pass->GetRequiredMipCount());
37623762
}
37633763

37643764
TEST_P(AiksTest, GaussianBlurAllocatesCorrectMipCountRenderTarget) {
3765+
size_t blur_required_mip_count =
3766+
GetParam() == PlaygroundBackend::kMetal ? 4 : 1;
3767+
37653768
Canvas canvas;
37663769
canvas.DrawCircle({100, 100}, 50, {.color = Color::CornflowerBlue()});
37673770
canvas.SaveLayer({}, std::nullopt,
@@ -3782,11 +3785,14 @@ TEST_P(AiksTest, GaussianBlurAllocatesCorrectMipCountRenderTarget) {
37823785
max_mip_count =
37833786
std::max(it->texture->GetTextureDescriptor().mip_count, max_mip_count);
37843787
}
3785-
EXPECT_EQ(max_mip_count, 1lu);
3788+
EXPECT_EQ(max_mip_count, blur_required_mip_count);
37863789
}
37873790

37883791
TEST_P(AiksTest, GaussianBlurMipMapNestedLayer) {
37893792
fml::testing::LogCapture log_capture;
3793+
size_t blur_required_mip_count =
3794+
GetParam() == PlaygroundBackend::kMetal ? 4 : 1;
3795+
37903796
Canvas canvas;
37913797
canvas.DrawPaint({.color = Color::Wheat()});
37923798
canvas.SaveLayer({.blend_mode = BlendMode::kMultiply});
@@ -3809,12 +3815,19 @@ TEST_P(AiksTest, GaussianBlurMipMapNestedLayer) {
38093815
max_mip_count =
38103816
std::max(it->texture->GetTextureDescriptor().mip_count, max_mip_count);
38113817
}
3812-
EXPECT_EQ(max_mip_count, 1lu);
3813-
EXPECT_EQ(log_capture.str().find(GaussianBlurFilterContents::kNoMipsError),
3814-
std::string::npos);
3818+
EXPECT_EQ(max_mip_count, blur_required_mip_count);
3819+
if (GetParam() == PlaygroundBackend::kMetal) {
3820+
EXPECT_EQ(log_capture.str().find(GaussianBlurFilterContents::kNoMipsError),
3821+
std::string::npos);
3822+
} else {
3823+
EXPECT_NE(log_capture.str().find(GaussianBlurFilterContents::kNoMipsError),
3824+
std::string::npos);
3825+
}
38153826
}
38163827

38173828
TEST_P(AiksTest, GaussianBlurMipMapImageFilter) {
3829+
size_t blur_required_mip_count =
3830+
GetParam() == PlaygroundBackend::kMetal ? 4 : 1;
38183831
fml::testing::LogCapture log_capture;
38193832
Canvas canvas;
38203833
canvas.SaveLayer(
@@ -3835,9 +3848,14 @@ TEST_P(AiksTest, GaussianBlurMipMapImageFilter) {
38353848
max_mip_count =
38363849
std::max(it->texture->GetTextureDescriptor().mip_count, max_mip_count);
38373850
}
3838-
EXPECT_EQ(max_mip_count, 1lu);
3839-
EXPECT_EQ(log_capture.str().find(GaussianBlurFilterContents::kNoMipsError),
3840-
std::string::npos);
3851+
EXPECT_EQ(max_mip_count, blur_required_mip_count);
3852+
if (GetParam() == PlaygroundBackend::kMetal) {
3853+
EXPECT_EQ(log_capture.str().find(GaussianBlurFilterContents::kNoMipsError),
3854+
std::string::npos);
3855+
} else {
3856+
EXPECT_NE(log_capture.str().find(GaussianBlurFilterContents::kNoMipsError),
3857+
std::string::npos);
3858+
}
38413859
}
38423860

38433861
} // namespace testing

impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ namespace impeller {
4343
/// - `FilterContents::MakeGaussianBlur`
4444
/// - //flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur.glsl
4545
///
46+
///\deprecated Previously 2 of these were chained to do 2D blurs, use
47+
/// \ref GaussianBlurFilterContents instead since it has better
48+
/// performance.
4649
class DirectionalGaussianBlurFilterContents final : public FilterContents {
4750
public:
4851
DirectionalGaussianBlurFilterContents();

impeller/entity/contents/filters/filter_contents.cc

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -50,50 +50,18 @@ std::shared_ptr<FilterContents> FilterContents::MakeDirectionalGaussianBlur(
5050
return blur;
5151
}
5252

53-
#ifdef IMPELLER_ENABLE_NEW_GAUSSIAN_FILTER
5453
const int32_t FilterContents::kBlurFilterRequiredMipCount = 4;
55-
#else
56-
const int32_t FilterContents::kBlurFilterRequiredMipCount = 1;
57-
#endif
5854

5955
std::shared_ptr<FilterContents> FilterContents::MakeGaussianBlur(
6056
const FilterInput::Ref& input,
6157
Sigma sigma_x,
6258
Sigma sigma_y,
6359
BlurStyle blur_style,
6460
Entity::TileMode tile_mode) {
65-
constexpr bool use_new_filter =
66-
#ifdef IMPELLER_ENABLE_NEW_GAUSSIAN_FILTER
67-
true;
68-
#else
69-
false;
70-
#endif
71-
72-
// TODO(https://github.com/flutter/flutter/issues/131580): Remove once the new
73-
// blur handles all cases.
74-
if (use_new_filter) {
75-
auto blur = std::make_shared<GaussianBlurFilterContents>(
76-
sigma_x.sigma, sigma_y.sigma, tile_mode);
77-
blur->SetInputs({input});
78-
return blur;
79-
}
80-
std::shared_ptr<FilterContents> x_blur = MakeDirectionalGaussianBlur(
81-
/*input=*/input,
82-
/*sigma=*/sigma_x,
83-
/*direction=*/Point(1, 0),
84-
/*blur_style=*/BlurStyle::kNormal,
85-
/*tile_mode=*/tile_mode,
86-
/*is_second_pass=*/false,
87-
/*secondary_sigma=*/{});
88-
std::shared_ptr<FilterContents> y_blur = MakeDirectionalGaussianBlur(
89-
/*input=*/FilterInput::Make(x_blur),
90-
/*sigma=*/sigma_y,
91-
/*direction=*/Point(0, 1),
92-
/*blur_style=*/blur_style,
93-
/*tile_mode=*/tile_mode,
94-
/*is_second_pass=*/true,
95-
/*secondary_sigma=*/sigma_x);
96-
return y_blur;
61+
auto blur = std::make_shared<GaussianBlurFilterContents>(
62+
sigma_x.sigma, sigma_y.sigma, tile_mode);
63+
blur->SetInputs({input});
64+
return blur;
9765
}
9866

9967
std::shared_ptr<FilterContents> FilterContents::MakeBorderMaskBlur(

impeller/entity/entity_pass.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,14 @@ static EntityPassTarget CreateRenderTarget(ContentContext& renderer,
256256
/// What's important is the `StorageMode` of the textures, which cannot be
257257
/// changed for the lifetime of the textures.
258258

259+
if (context->GetBackendType() != Context::BackendType::kMetal) {
260+
// TODO(https://github.com/flutter/flutter/issues/141495): Implement mip map
261+
// generation on vulkan.
262+
// TODO(https://github.com/flutter/flutter/issues/141732): Implement mip map
263+
// generation on opengles.
264+
mip_count = 1;
265+
}
266+
259267
RenderTarget target;
260268
if (context->GetCapabilities()->SupportsOffscreenMSAA()) {
261269
target = RenderTarget::CreateOffscreenMSAA(

0 commit comments

Comments
 (0)