[Impeller] EntityPass::Clone needs to clone harder (flutter/engine#45313)

Fixes https://github.com/flutter/flutter/issues/133731
This commit is contained in:
Jonah Williams
2023-09-01 10:19:03 -07:00
committed by GitHub
parent b3fc48b91b
commit baa288096b
4 changed files with 51 additions and 5 deletions

View File

@@ -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(

View File

@@ -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));
}
}

View File

@@ -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;
}
@@ -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;
}

View File

@@ -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
@@ -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);