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

Commit 3f6ee31

Browse files
committed
cleanup
1 parent 4c9f3be commit 3f6ee31

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

impeller/entity/contents/filters/filter_contents.cc

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

53+
#define IMPELLER_ENABLE_NEW_GAUSSIAN_FILTER 1
54+
5355
std::shared_ptr<FilterContents> FilterContents::MakeGaussianBlur(
5456
const FilterInput::Ref& input,
5557
Sigma sigma_x,

impeller/entity/contents/filters/gaussian_blur_filter_contents.cc

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ using GaussianBlurVertexShader = GaussianBlurPipeline::VertexShader;
1717
using GaussianBlurFragmentShader = GaussianBlurPipeline::FragmentShader;
1818

1919
namespace {
20+
21+
std::optional<Rect> ExpandCoverageHint(const std::optional<Rect>& coverage_hint,
22+
const Matrix& source_to_local_transform,
23+
const Vector2& padding) {
24+
if (!coverage_hint.has_value()) {
25+
return std::nullopt;
26+
}
27+
Vector2 transformed_padding = (source_to_local_transform * padding).Abs();
28+
return coverage_hint->Expand(transformed_padding);
29+
}
30+
2031
SamplerDescriptor MakeSamplerDescriptor(MinMagFilter filter,
2132
SamplerAddressMode address_mode) {
2233
SamplerDescriptor sampler_desc;
@@ -66,7 +77,8 @@ std::shared_ptr<Texture> MakeDownsampleSubpass(
6677
frame_info.alpha = 1.0;
6778

6879
// Insert transparent gutter around the downsampled image so the blur
69-
// creates a halo effect.
80+
// creates a halo effect. This compensates for when the expanded clip
81+
// region can't give us the full gutter we want.
7082
Vector2 texture_size = Vector2(input_texture->GetSize());
7183
Quad vertices =
7284
MakeAnchorScale({0.5, 0.5},
@@ -106,6 +118,8 @@ std::shared_ptr<Texture> MakeBlurSubpass(
106118
std::shared_ptr<Texture> input_texture,
107119
const SamplerDescriptor& sampler_descriptor,
108120
const GaussianBlurFragmentShader::BlurInfo& blur_info) {
121+
// TODO(gaaclarke): This blurs the whole image, but because we know the clip
122+
// region we could focus on just blurring that.
109123
ISize subpass_size = input_texture->GetSize();
110124
ContentContext::SubpassCallback subpass_callback =
111125
[&](const ContentContext& renderer, RenderPass& pass) {
@@ -201,19 +215,18 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter(
201215
}
202216

203217
Scalar blur_radius = CalculateBlurRadius(sigma_);
204-
Scalar desired_scalar = CalculateScale(sigma_);
205-
// TODO(jonahwilliams): if scaling value is 1.0, then skip the downsample
206-
// pass.
207-
208-
Vector2 downsample_scalar(desired_scalar, desired_scalar);
209218
Vector2 padding(ceil(blur_radius), ceil(blur_radius));
210219

211-
std::optional<Rect> expanded_coverage_hint;
212-
if (coverage_hint.has_value()) {
213-
Matrix transform = entity.GetTransform() * effect_transform.Basis();
214-
Vector2 transformed_padding = (transform * padding).Abs();
215-
expanded_coverage_hint = coverage_hint->Expand(transformed_padding);
216-
}
220+
// Apply as much of the desired padding as possible from the source. This may
221+
// be ignored so must be accounted for in the downsample pass by adding a
222+
// transparent gutter.
223+
std::optional<Rect> expanded_coverage_hint = ExpandCoverageHint(
224+
coverage_hint, entity.GetTransform() * effect_transform, padding);
225+
// TODO(gaaclarke): How much of the gutter is thrown away can be used to
226+
// adjust the padding that is added in the downsample pass.
227+
// For example, if we get all the padding we requested from
228+
// the expanded_coverage_hint, there is no need to add a
229+
// transparent gutter.
217230

218231
std::optional<Snapshot> input_snapshot =
219232
inputs[0]->GetSnapshot("GaussianBlur", renderer, entity,
@@ -227,6 +240,8 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter(
227240
entity.GetClipDepth()); // No blur to render.
228241
}
229242

243+
Scalar desired_scalar = CalculateScale(sigma_);
244+
Vector2 downsample_scalar(desired_scalar, desired_scalar);
230245
Vector2 padded_size =
231246
Vector2(input_snapshot->texture->GetSize()) + 2.0 * padding;
232247
Vector2 downsampled_size = padded_size * downsample_scalar;

0 commit comments

Comments
 (0)