Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions impeller/entity/contents/filters/gaussian_blur_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,18 @@ GaussianBlurPipeline::FragmentShader::KernelSamples GenerateBlurInfo(
x_offset = 1;
}

// This is a safe-guard to make sure we don't overflow the fragment shader.
// The kernel size is multiplied by 2 since we'll use the lerp hack on the
// result. In practice this isn't throwing away much data since the blur radii
// are around 53 before the down-sampling and max sigma of 500 kick in.
//
// TODO(https://github.com/flutter/flutter/issues/150462): Come up with a more
// wholistic remedy for this. A proper downsample size should not make this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

holistic ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both spellings are accepted. After a slight rabbit hole I can report that it isn't some sort of british-ism. "Wholistic" came about about 100 years ago for some goofy reason, probably to sell snake oil.

// required. Or we can increase the kernel size.
if (result.sample_count > (2 * (kMaxKernelSize - 1))) {
result.sample_count = 2 * (kMaxKernelSize - 1);
}

Scalar tally = 0.0f;
for (int i = 0; i < result.sample_count; ++i) {
int x = x_offset + (i * parameters.step_size) - parameters.blur_radius;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,5 +614,18 @@ TEST(GaussianBlurFilterContentsTest, LerpHackKernelSamplesComplex) {
EXPECT_NEAR(output, fast_output, 0.1);
}

TEST(GaussianBlurFilterContentsTest, ChopHugeBlurs) {
Scalar sigma = 30.5f;
int32_t blur_radius = static_cast<int32_t>(
std::ceil(GaussianBlurFilterContents::CalculateBlurRadius(sigma)));
BlurParameters parameters = {.blur_uv_offset = Point(1, 0),
.blur_sigma = sigma,
.blur_radius = blur_radius,
.step_size = 1};
GaussianBlurPipeline::FragmentShader::KernelSamples kernel_samples =
GenerateBlurInfo(parameters);
EXPECT_EQ(kernel_samples.sample_count, 98);
}

} // namespace testing
} // namespace impeller