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

Commit 182739c

Browse files
gaaclarkeharryterkelsen
authored andcommitted
[Impeller] fixes behavior for blurred rounded rect clear (#46167)
fixes: flutter/flutter#132849 I decided to mimic skia's blend function for clear only in the case for blurred rounded rects since that fixes the listed issue. I'm not sure if there are are other cases where we'd want this behavior. I've added golden tests for the other clear cases too to make sure we didn't break them. ## 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] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [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/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/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
1 parent 81af0ce commit 182739c

File tree

4 files changed

+59
-11
lines changed

4 files changed

+59
-11
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,5 +3581,37 @@ TEST_P(AiksTest, VerticesGeometryUVPositionData) {
35813581
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
35823582
}
35833583

3584+
TEST_P(AiksTest, ClearBlendWithBlur) {
3585+
Canvas canvas;
3586+
Paint white;
3587+
white.color = Color::Blue();
3588+
canvas.DrawRect(Rect::MakeXYWH(0, 0, 600.0, 600.0), white);
3589+
3590+
Paint clear;
3591+
clear.blend_mode = BlendMode::kClear;
3592+
clear.mask_blur_descriptor = Paint::MaskBlurDescriptor{
3593+
.style = FilterContents::BlurStyle::kNormal,
3594+
.sigma = Sigma(20),
3595+
};
3596+
3597+
canvas.DrawCircle(Point::MakeXY(300.0, 300.0), 200.0, clear);
3598+
3599+
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
3600+
}
3601+
3602+
TEST_P(AiksTest, ClearBlend) {
3603+
Canvas canvas;
3604+
Paint white;
3605+
white.color = Color::Blue();
3606+
canvas.DrawRect(Rect::MakeXYWH(0, 0, 600.0, 600.0), white);
3607+
3608+
Paint clear;
3609+
clear.blend_mode = BlendMode::kClear;
3610+
3611+
canvas.DrawCircle(Point::MakeXY(300.0, 300.0), 200.0, clear);
3612+
3613+
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
3614+
}
3615+
35843616
} // namespace testing
35853617
} // namespace impeller

impeller/entity/contents/content_context.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,19 @@ void ContentContextOptions::ApplyToPipelineDescriptor(
3838

3939
switch (pipeline_blend) {
4040
case BlendMode::kClear:
41-
color0.dst_alpha_blend_factor = BlendFactor::kZero;
42-
color0.dst_color_blend_factor = BlendFactor::kZero;
43-
color0.src_alpha_blend_factor = BlendFactor::kZero;
44-
color0.src_color_blend_factor = BlendFactor::kZero;
41+
if (is_for_rrect_blur_clear) {
42+
color0.alpha_blend_op = BlendOperation::kReverseSubtract;
43+
color0.color_blend_op = BlendOperation::kReverseSubtract;
44+
color0.dst_alpha_blend_factor = BlendFactor::kOne;
45+
color0.dst_color_blend_factor = BlendFactor::kOne;
46+
color0.src_alpha_blend_factor = BlendFactor::kDestinationColor;
47+
color0.src_color_blend_factor = BlendFactor::kDestinationColor;
48+
} else {
49+
color0.dst_alpha_blend_factor = BlendFactor::kZero;
50+
color0.dst_color_blend_factor = BlendFactor::kZero;
51+
color0.src_alpha_blend_factor = BlendFactor::kZero;
52+
color0.src_color_blend_factor = BlendFactor::kZero;
53+
}
4554
break;
4655
case BlendMode::kSource:
4756
color0.blending_enabled = false;

impeller/entity/contents/content_context.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,14 @@ struct ContentContextOptions {
308308
PixelFormat color_attachment_pixel_format = PixelFormat::kUnknown;
309309
bool has_stencil_attachment = true;
310310
bool wireframe = false;
311+
bool is_for_rrect_blur_clear = false;
311312

312313
struct Hash {
313314
constexpr std::size_t operator()(const ContentContextOptions& o) const {
314-
return fml::HashCombine(o.sample_count, o.blend_mode, o.stencil_compare,
315-
o.stencil_operation, o.primitive_type,
316-
o.color_attachment_pixel_format,
317-
o.has_stencil_attachment, o.wireframe);
315+
return fml::HashCombine(
316+
o.sample_count, o.blend_mode, o.stencil_compare, o.stencil_operation,
317+
o.primitive_type, o.color_attachment_pixel_format,
318+
o.has_stencil_attachment, o.wireframe, o.is_for_rrect_blur_clear);
318319
}
319320
};
320321

@@ -329,7 +330,8 @@ struct ContentContextOptions {
329330
lhs.color_attachment_pixel_format ==
330331
rhs.color_attachment_pixel_format &&
331332
lhs.has_stencil_attachment == rhs.has_stencil_attachment &&
332-
lhs.wireframe == rhs.wireframe;
333+
lhs.wireframe == rhs.wireframe &&
334+
lhs.is_for_rrect_blur_clear == rhs.is_for_rrect_blur_clear;
333335
}
334336
};
335337

impeller/entity/contents/solid_rrect_blur_contents.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,13 @@ bool SolidRRectBlurContents::Render(const ContentContext& renderer,
8888

8989
Command cmd;
9090
DEBUG_COMMAND_INFO(cmd, "RRect Shadow");
91-
auto opts = OptionsFromPassAndEntity(pass, entity);
91+
ContentContextOptions opts = OptionsFromPassAndEntity(pass, entity);
9292
opts.primitive_type = PrimitiveType::kTriangle;
93+
Color color = color_;
94+
if (entity.GetBlendMode() == BlendMode::kClear) {
95+
opts.is_for_rrect_blur_clear = true;
96+
color = Color::White();
97+
}
9398
cmd.pipeline = renderer.GetRRectBlurPipeline(opts);
9499
cmd.stencil_reference = entity.GetStencilDepth();
95100

@@ -102,7 +107,7 @@ bool SolidRRectBlurContents::Render(const ContentContext& renderer,
102107
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));
103108

104109
FS::FragInfo frag_info;
105-
frag_info.color = color_;
110+
frag_info.color = color;
106111
frag_info.blur_sigma = blur_sigma;
107112
frag_info.rect_size = Point(positive_rect.size);
108113
frag_info.corner_radius =

0 commit comments

Comments
 (0)