diff --git a/impeller/aiks/aiks_unittests.cc b/impeller/aiks/aiks_unittests.cc index 99b4deb4d726a..d1d7f40029f3e 100644 --- a/impeller/aiks/aiks_unittests.cc +++ b/impeller/aiks/aiks_unittests.cc @@ -3089,6 +3089,42 @@ TEST_P(AiksTest, CanCanvasDrawPicture) { ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } +TEST_P(AiksTest, CanCanvasDrawPictureWithAdvancedBlend) { + Canvas subcanvas; + subcanvas.DrawRect( + Rect::MakeLTRB(-100, -50, 100, 50), + {.color = Color::CornflowerBlue(), .blend_mode = BlendMode::kColorDodge}); + auto picture = subcanvas.EndRecordingAsPicture(); + + Canvas canvas; + canvas.Translate({200, 200}); + canvas.DrawPicture(picture); + + ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); +} + +TEST_P(AiksTest, CanCanvasDrawPictureWithBackdropFilter) { + Canvas subcanvas; + subcanvas.SaveLayer({}, {}, + [](const FilterInput::Ref& input, + const Matrix& effect_transform, bool is_subpass) { + return FilterContents::MakeGaussianBlur( + input, Sigma(20.0), Sigma(20.0)); + }); + auto image = std::make_shared(CreateTextureForFixture("kalimba.jpg")); + Paint paint; + paint.color = Color::Red(); + subcanvas.DrawImage(image, Point::MakeXY(100.0, 100.0), paint); + + auto picture = subcanvas.EndRecordingAsPicture(); + + Canvas canvas; + canvas.Translate({200, 200}); + canvas.DrawPicture(picture); + + ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); +} + TEST_P(AiksTest, DrawPictureWithText) { Canvas subcanvas; ASSERT_TRUE(RenderTextInCanvasSkia( diff --git a/impeller/aiks/canvas.cc b/impeller/aiks/canvas.cc index 5e278b717c945..777d8f820e5b5 100644 --- a/impeller/aiks/canvas.cc +++ b/impeller/aiks/canvas.cc @@ -542,9 +542,9 @@ void Canvas::SaveLayer(const Paint& paint, // Only apply opacity peephole on default blending. if (paint.blend_mode == BlendMode::kSourceOver) { new_layer_pass.SetDelegate( - std::make_unique(paint)); + std::make_shared(paint)); } else { - new_layer_pass.SetDelegate(std::make_unique(paint)); + new_layer_pass.SetDelegate(std::make_shared(paint)); } } diff --git a/impeller/entity/entity_pass.cc b/impeller/entity/entity_pass.cc index e926cd997236b..dc4e4e33e72ac 100644 --- a/impeller/entity/entity_pass.cc +++ b/impeller/entity/entity_pass.cc @@ -59,7 +59,7 @@ EntityPass::EntityPass() = default; EntityPass::~EntityPass() = default; -void EntityPass::SetDelegate(std::unique_ptr delegate) { +void EntityPass::SetDelegate(std::shared_ptr delegate) { if (!delegate) { return; } @@ -1023,6 +1023,16 @@ std::unique_ptr EntityPass::Clone() const { auto pass = std::make_unique(); pass->SetElements(std::move(new_elements)); + pass->backdrop_filter_reads_from_pass_texture_ = + backdrop_filter_reads_from_pass_texture_; + pass->advanced_blend_reads_from_pass_texture_ = + advanced_blend_reads_from_pass_texture_; + pass->backdrop_filter_proc_ = backdrop_filter_proc_; + pass->blend_mode_ = blend_mode_; + pass->delegate_ = delegate_; + // Note: I tried also adding flood clip and bounds limit but one of the + // two caused rendering in wonderous to break. It's 10:51 PM, and I'm + // ready to move on. return pass; } diff --git a/impeller/entity/entity_pass.h b/impeller/entity/entity_pass.h index 423e0e6498509..b614701733d8c 100644 --- a/impeller/entity/entity_pass.h +++ b/impeller/entity/entity_pass.h @@ -53,7 +53,7 @@ class EntityPass { ~EntityPass(); - void SetDelegate(std::unique_ptr delgate); + void SetDelegate(std::shared_ptr delgate); /// @brief Set the bounds limit, which is provided by the user when creating /// a SaveLayer. This is a hint that allows the user to communicate @@ -278,7 +278,7 @@ class EntityPass { BackdropFilterProc backdrop_filter_proc_ = nullptr; - std::unique_ptr delegate_ = + std::shared_ptr delegate_ = EntityPassDelegate::MakeDefault(); FML_DISALLOW_COPY_AND_ASSIGN(EntityPass);