Skip to content

Commit 58bc964

Browse files
authored
[Impeller] rrect_blur: scale max radius clamp by transform (flutter#161238)
migrated PR flutter/engine#54350 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent a5ed6ae commit 58bc964

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

engine/src/flutter/impeller/display_list/dl_golden_blur_unittests.cc

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ TEST_P(DlGoldenTest, ShimmerTest) {
154154

155155
TEST_P(DlGoldenTest, StrokedRRectFastBlur) {
156156
impeller::Point content_scale = GetContentScale();
157-
158157
DlRect rect = DlRect::MakeXYWH(50, 50, 100, 100);
159158
DlRoundRect rrect = DlRoundRect::MakeRectRadius(rect, 10.0f);
160159
DlPaint fill = DlPaint().setColor(DlColor::kBlue());
@@ -176,5 +175,37 @@ TEST_P(DlGoldenTest, StrokedRRectFastBlur) {
176175
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
177176
}
178177

178+
// Top left and bottom right circles are expected to be comparable (not exactly
179+
// equal).
180+
// See also: https://github.com/flutter/flutter/issues/152778
181+
TEST_P(DlGoldenTest, LargeDownscaleRrect) {
182+
impeller::Point content_scale = GetContentScale();
183+
auto draw = [&](DlCanvas* canvas, const std::vector<sk_sp<DlImage>>& images) {
184+
canvas->Scale(content_scale.x, content_scale.y);
185+
canvas->DrawColor(DlColor(0xff111111));
186+
{
187+
canvas->Save();
188+
canvas->Scale(0.25, 0.25);
189+
DlPaint paint;
190+
paint.setColor(DlColor::kYellow());
191+
paint.setMaskFilter(
192+
DlBlurMaskFilter::Make(DlBlurStyle::kNormal, /*sigma=*/1000));
193+
canvas->DrawCircle(SkPoint::Make(0, 0), 1200, paint);
194+
canvas->Restore();
195+
}
196+
197+
DlPaint paint;
198+
paint.setColor(DlColor::kYellow());
199+
paint.setMaskFilter(
200+
DlBlurMaskFilter::Make(DlBlurStyle::kNormal, /*sigma=*/250));
201+
canvas->DrawCircle(SkPoint::Make(1024, 768), 300, paint);
202+
};
203+
204+
DisplayListBuilder builder;
205+
draw(&builder, /*images=*/{});
206+
207+
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
208+
}
209+
179210
} // namespace testing
180211
} // namespace flutter

engine/src/flutter/impeller/entity/contents/solid_rrect_blur_contents.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,15 @@ bool SolidRRectBlurContents::Render(const ContentContext& renderer,
128128
using VS = RRectBlurPipeline::VertexShader;
129129
using FS = RRectBlurPipeline::FragmentShader;
130130

131-
// Clamp the max kernel width/height to 1000 to limit the extent
131+
Matrix basis_invert = entity.GetTransform().Basis().Invert();
132+
Vector2 max_sigmas =
133+
Vector2((basis_invert * Vector2(500.f, 0.f)).GetLength(),
134+
(basis_invert * Vector2(0.f, 500.f)).GetLength());
135+
Scalar max_sigma = std::min(max_sigmas.x, max_sigmas.y);
136+
// Clamp the max kernel width/height to 1000 (@ 2x) to limit the extent
132137
// of the blur and to kEhCloseEnough to prevent NaN calculations
133-
// trying to evaluate a Guassian distribution with a sigma of 0.
134-
Scalar blur_sigma = std::clamp(sigma_.sigma, kEhCloseEnough, 250.0f);
138+
// trying to evaluate a Gaussian distribution with a sigma of 0.
139+
auto blur_sigma = std::clamp(sigma_.sigma, kEhCloseEnough, max_sigma);
135140
// Increase quality by making the radius a bit bigger than the typical
136141
// sigma->radius conversion we use for slower blurs.
137142
Scalar blur_radius = PadForSigma(blur_sigma);

engine/src/flutter/testing/impeller_golden_tests_output.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,9 @@ impeller_Play_DlGoldenTest_GaussianVsRRectBlurScaled_Vulkan.png
988988
impeller_Play_DlGoldenTest_GaussianVsRRectBlur_Metal.png
989989
impeller_Play_DlGoldenTest_GaussianVsRRectBlur_OpenGLES.png
990990
impeller_Play_DlGoldenTest_GaussianVsRRectBlur_Vulkan.png
991+
impeller_Play_DlGoldenTest_LargeDownscaleRrect_Metal.png
992+
impeller_Play_DlGoldenTest_LargeDownscaleRrect_OpenGLES.png
993+
impeller_Play_DlGoldenTest_LargeDownscaleRrect_Vulkan.png
991994
impeller_Play_DlGoldenTest_SaveLayerAtFractionalValue_Metal.png
992995
impeller_Play_DlGoldenTest_SaveLayerAtFractionalValue_OpenGLES.png
993996
impeller_Play_DlGoldenTest_SaveLayerAtFractionalValue_Vulkan.png

0 commit comments

Comments
 (0)