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

Commit 64a20eb

Browse files
authored
[Impeller] Fix and reland drawPaint collapsing optimization. (#43097)
Collapses DrawPaint calls into clear colors when possible. issue flutter/flutter#129292 relands #41711 ## 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 Hixie said 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 [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 c98e64e commit 64a20eb

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,18 @@ TEST_P(AiksTest, OpacityPeepHoleApplicationTest) {
19921992
ASSERT_TRUE(delegate->CanCollapseIntoParentPass(entity_pass.get()));
19931993
}
19941994

1995+
TEST_P(AiksTest, DrawPaintAbsorbsClears) {
1996+
Canvas canvas;
1997+
canvas.DrawPaint({.color = Color::Red(), .blend_mode = BlendMode::kSource});
1998+
canvas.DrawPaint(
1999+
{.color = Color::CornflowerBlue(), .blend_mode = BlendMode::kSource});
2000+
2001+
Picture picture = canvas.EndRecordingAsPicture();
2002+
2003+
ASSERT_EQ(picture.pass->GetElementCount(), 0u);
2004+
ASSERT_EQ(picture.pass->GetClearColor(), Color::CornflowerBlue());
2005+
}
2006+
19952007
TEST_P(AiksTest, ForegroundBlendSubpassCollapseOptimization) {
19962008
Canvas canvas;
19972009

impeller/aiks/canvas.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ void Canvas::DrawPath(const Path& path, const Paint& paint) {
172172
}
173173

174174
void Canvas::DrawPaint(const Paint& paint) {
175+
if (xformation_stack_.size() == 1 && // If we're recording the root pass,
176+
GetCurrentPass().GetElementCount() == 0 && // and this is the first item,
177+
(paint.blend_mode == BlendMode::kSourceOver ||
178+
paint.blend_mode == BlendMode::kSource) &&
179+
paint.color.alpha >= 1.0f) {
180+
// Then we can absorb this drawPaint as the clear color of the pass.
181+
GetCurrentPass().SetClearColor(paint.color);
182+
return;
183+
}
184+
175185
Entity entity;
176186
entity.SetTransformation(GetCurrentTransformation());
177187
entity.SetStencilDepth(GetStencilDepth());

impeller/entity/entity_pass.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
478478
renderer, // renderer
479479
subpass_size, // size
480480
subpass->GetTotalPassReads(renderer) > 0, // readable
481-
clear_color_.Premultiply()); // clear_color
481+
Color::BlackTransparent()); // clear_color
482482

483483
if (!subpass_target.IsValid()) {
484484
VALIDATION_LOG << "Subpass render target is invalid.";

impeller/renderer/render_target.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ RenderTarget RenderTarget::CreateOffscreenMSAA(
313313
// Color attachment.
314314

315315
ColorAttachment color0;
316-
color0.clear_color = Color::BlackTransparent();
316+
color0.clear_color = color_attachment_config.clear_color;
317317
color0.load_action = color_attachment_config.load_action;
318318
color0.store_action = color_attachment_config.store_action;
319319
color0.texture = color0_msaa_tex;

0 commit comments

Comments
 (0)