Skip to content

Commit

Permalink
[Impeller] EntityPass::Clone needs to clone harder (#45313)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahwilliams authored Sep 1, 2023
1 parent 9446392 commit 66e53ee
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
36 changes: 36 additions & 0 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3119,6 +3119,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<Image>(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(
Expand Down
4 changes: 2 additions & 2 deletions impeller/aiks/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,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<OpacityPeepholePassDelegate>(paint));
std::make_shared<OpacityPeepholePassDelegate>(paint));
} else {
new_layer_pass.SetDelegate(std::make_unique<PaintPassDelegate>(paint));
new_layer_pass.SetDelegate(std::make_shared<PaintPassDelegate>(paint));
}
}

Expand Down
12 changes: 11 additions & 1 deletion impeller/entity/entity_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ EntityPass::EntityPass() = default;

EntityPass::~EntityPass() = default;

void EntityPass::SetDelegate(std::unique_ptr<EntityPassDelegate> delegate) {
void EntityPass::SetDelegate(std::shared_ptr<EntityPassDelegate> delegate) {
if (!delegate) {
return;
}
Expand Down Expand Up @@ -1020,6 +1020,16 @@ std::unique_ptr<EntityPass> EntityPass::Clone() const {

auto pass = std::make_unique<EntityPass>();
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;
}

Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/entity_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class EntityPass {

~EntityPass();

void SetDelegate(std::unique_ptr<EntityPassDelegate> delgate);
void SetDelegate(std::shared_ptr<EntityPassDelegate> 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
Expand Down Expand Up @@ -279,7 +279,7 @@ class EntityPass {

BackdropFilterProc backdrop_filter_proc_ = nullptr;

std::unique_ptr<EntityPassDelegate> delegate_ =
std::shared_ptr<EntityPassDelegate> delegate_ =
EntityPassDelegate::MakeDefault();

FML_DISALLOW_COPY_AND_ASSIGN(EntityPass);
Expand Down

0 comments on commit 66e53ee

Please sign in to comment.