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

Commit 66e53ee

Browse files
author
Jonah Williams
authored
[Impeller] EntityPass::Clone needs to clone harder (#45313)
Fixes flutter/flutter#133731
1 parent 9446392 commit 66e53ee

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3119,6 +3119,42 @@ TEST_P(AiksTest, CanCanvasDrawPicture) {
31193119
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
31203120
}
31213121

3122+
TEST_P(AiksTest, CanCanvasDrawPictureWithAdvancedBlend) {
3123+
Canvas subcanvas;
3124+
subcanvas.DrawRect(
3125+
Rect::MakeLTRB(-100, -50, 100, 50),
3126+
{.color = Color::CornflowerBlue(), .blend_mode = BlendMode::kColorDodge});
3127+
auto picture = subcanvas.EndRecordingAsPicture();
3128+
3129+
Canvas canvas;
3130+
canvas.Translate({200, 200});
3131+
canvas.DrawPicture(picture);
3132+
3133+
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
3134+
}
3135+
3136+
TEST_P(AiksTest, CanCanvasDrawPictureWithBackdropFilter) {
3137+
Canvas subcanvas;
3138+
subcanvas.SaveLayer({}, {},
3139+
[](const FilterInput::Ref& input,
3140+
const Matrix& effect_transform, bool is_subpass) {
3141+
return FilterContents::MakeGaussianBlur(
3142+
input, Sigma(20.0), Sigma(20.0));
3143+
});
3144+
auto image = std::make_shared<Image>(CreateTextureForFixture("kalimba.jpg"));
3145+
Paint paint;
3146+
paint.color = Color::Red();
3147+
subcanvas.DrawImage(image, Point::MakeXY(100.0, 100.0), paint);
3148+
3149+
auto picture = subcanvas.EndRecordingAsPicture();
3150+
3151+
Canvas canvas;
3152+
canvas.Translate({200, 200});
3153+
canvas.DrawPicture(picture);
3154+
3155+
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
3156+
}
3157+
31223158
TEST_P(AiksTest, DrawPictureWithText) {
31233159
Canvas subcanvas;
31243160
ASSERT_TRUE(RenderTextInCanvasSkia(

impeller/aiks/canvas.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,9 @@ void Canvas::SaveLayer(const Paint& paint,
527527
// Only apply opacity peephole on default blending.
528528
if (paint.blend_mode == BlendMode::kSourceOver) {
529529
new_layer_pass.SetDelegate(
530-
std::make_unique<OpacityPeepholePassDelegate>(paint));
530+
std::make_shared<OpacityPeepholePassDelegate>(paint));
531531
} else {
532-
new_layer_pass.SetDelegate(std::make_unique<PaintPassDelegate>(paint));
532+
new_layer_pass.SetDelegate(std::make_shared<PaintPassDelegate>(paint));
533533
}
534534
}
535535

impeller/entity/entity_pass.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ EntityPass::EntityPass() = default;
5959

6060
EntityPass::~EntityPass() = default;
6161

62-
void EntityPass::SetDelegate(std::unique_ptr<EntityPassDelegate> delegate) {
62+
void EntityPass::SetDelegate(std::shared_ptr<EntityPassDelegate> delegate) {
6363
if (!delegate) {
6464
return;
6565
}
@@ -1020,6 +1020,16 @@ std::unique_ptr<EntityPass> EntityPass::Clone() const {
10201020

10211021
auto pass = std::make_unique<EntityPass>();
10221022
pass->SetElements(std::move(new_elements));
1023+
pass->backdrop_filter_reads_from_pass_texture_ =
1024+
backdrop_filter_reads_from_pass_texture_;
1025+
pass->advanced_blend_reads_from_pass_texture_ =
1026+
advanced_blend_reads_from_pass_texture_;
1027+
pass->backdrop_filter_proc_ = backdrop_filter_proc_;
1028+
pass->blend_mode_ = blend_mode_;
1029+
pass->delegate_ = delegate_;
1030+
// Note: I tried also adding flood clip and bounds limit but one of the
1031+
// two caused rendering in wonderous to break. It's 10:51 PM, and I'm
1032+
// ready to move on.
10231033
return pass;
10241034
}
10251035

impeller/entity/entity_pass.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class EntityPass {
5454

5555
~EntityPass();
5656

57-
void SetDelegate(std::unique_ptr<EntityPassDelegate> delgate);
57+
void SetDelegate(std::shared_ptr<EntityPassDelegate> delgate);
5858

5959
/// @brief Set the bounds limit, which is provided by the user when creating
6060
/// a SaveLayer. This is a hint that allows the user to communicate
@@ -279,7 +279,7 @@ class EntityPass {
279279

280280
BackdropFilterProc backdrop_filter_proc_ = nullptr;
281281

282-
std::unique_ptr<EntityPassDelegate> delegate_ =
282+
std::shared_ptr<EntityPassDelegate> delegate_ =
283283
EntityPassDelegate::MakeDefault();
284284

285285
FML_DISALLOW_COPY_AND_ASSIGN(EntityPass);

0 commit comments

Comments
 (0)