diff --git a/engine/src/flutter/impeller/aiks/aiks_unittests.cc b/engine/src/flutter/impeller/aiks/aiks_unittests.cc index 9266f0e3a1..af8255d704 100644 --- a/engine/src/flutter/impeller/aiks/aiks_unittests.cc +++ b/engine/src/flutter/impeller/aiks/aiks_unittests.cc @@ -1230,11 +1230,17 @@ TEST_P(AiksTest, TextRotated) { } TEST_P(AiksTest, CanDrawPaint) { - Paint paint; - paint.color = Color::MediumTurquoise(); Canvas canvas; canvas.Scale(Vector2(0.2, 0.2)); - canvas.DrawPaint(paint); + canvas.DrawPaint({.color = Color::MediumTurquoise()}); + ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); +} + +TEST_P(AiksTest, CanDrawPaintMultipleTimes) { + Canvas canvas; + canvas.Scale(Vector2(0.2, 0.2)); + canvas.DrawPaint({.color = Color::MediumTurquoise()}); + canvas.DrawPaint({.color = Color::Color::OrangeRed().WithAlpha(0.5)}); ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } diff --git a/engine/src/flutter/impeller/aiks/canvas.cc b/engine/src/flutter/impeller/aiks/canvas.cc index a9f68a457a..1d0cd014f1 100644 --- a/engine/src/flutter/impeller/aiks/canvas.cc +++ b/engine/src/flutter/impeller/aiks/canvas.cc @@ -167,15 +167,16 @@ void Canvas::DrawPath(const Path& path, const Paint& paint) { } void Canvas::DrawPaint(const Paint& paint) { - bool is_clear = - paint.blend_mode == BlendMode::kSource || - (paint.blend_mode == BlendMode::kSourceOver && paint.color.alpha == 1); if (xformation_stack_.size() == 1 && // If we're recording the root pass, GetCurrentPass().GetElementCount() == 0 && // and this is the first item, - is_clear // and the backdrop is being replaced + // TODO(bdero): Fix the advanced blends in Color::BlendColor. + // https://github.com/flutter/flutter/issues/124623 + paint.blend_mode <= Entity::kLastPipelineBlendMode // ) { // Then we can absorb this drawPaint as the clear color of the pass. - GetCurrentPass().SetClearColor(paint.color); + auto color = Color::BlendColor( + paint.color, GetCurrentPass().GetClearColor(), paint.blend_mode); + GetCurrentPass().SetClearColor(color); return; } diff --git a/engine/src/flutter/impeller/entity/entity_pass.cc b/engine/src/flutter/impeller/entity/entity_pass.cc index 6869bb6fc8..f76452bfdf 100644 --- a/engine/src/flutter/impeller/entity/entity_pass.cc +++ b/engine/src/flutter/impeller/entity/entity_pass.cc @@ -214,8 +214,9 @@ bool EntityPass::Render(ContentContext& renderer, .stencil_depth = 0}}; if (GetTotalPassReads(renderer) > 0) { - auto offscreen_target = CreateRenderTarget( - renderer, render_target.GetRenderTargetSize(), true, clear_color_); + auto offscreen_target = + CreateRenderTarget(renderer, render_target.GetRenderTargetSize(), true, + clear_color_.Premultiply()); if (!OnRender(renderer, // renderer offscreen_target.GetRenderTarget() @@ -277,7 +278,7 @@ bool EntityPass::Render(ContentContext& renderer, // Set up the clear color of the root pass. auto color0 = render_target.GetColorAttachments().find(0)->second; - color0.clear_color = clear_color_; + color0.clear_color = clear_color_.Premultiply(); auto root_render_target = render_target; root_render_target.SetColorAttachment(color0, 0); @@ -402,7 +403,7 @@ EntityPass::EntityResult EntityPass::GetEntityForElement( CreateRenderTarget(renderer, // ISize(subpass_coverage->size), // subpass->GetTotalPassReads(renderer) > 0, // - clear_color_); + clear_color_.Premultiply()); if (!subpass_target.GetRenderTarget().GetRenderTargetTexture()) { return EntityPass::EntityResult::Failure();