[Impeller] Blend alpha correctly in the 'DstOver' mode and the 'Dst' mode (flutter/engine#36439)

This commit is contained in:
ColdPaleLight
2022-09-29 08:32:16 +08:00
committed by GitHub
parent a7f9b3829a
commit c34c9941e4
2 changed files with 53 additions and 2 deletions

View File

@@ -815,5 +815,56 @@ TEST_P(DisplayListTest, CanDrawPaintWithColorSource) {
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}
TEST_P(DisplayListTest, CanBlendDstOverAndDstCorrectly) {
flutter::DisplayListBuilder builder;
{
builder.saveLayer(nullptr, nullptr);
builder.translate(100, 100);
flutter::DlPaint paint;
paint.setColor(flutter::DlColor::kRed());
builder.drawRect(SkRect::MakeSize({200, 200}), paint);
paint.setColor(flutter::DlColor::kBlue().withAlpha(127));
paint.setBlendMode(flutter::DlBlendMode::kSrcOver);
builder.drawRect(SkRect::MakeSize({200, 200}), paint);
builder.restore();
}
{
builder.saveLayer(nullptr, nullptr);
builder.translate(300, 100);
flutter::DlPaint paint;
paint.setColor(flutter::DlColor::kBlue().withAlpha(127));
builder.drawRect(SkRect::MakeSize({200, 200}), paint);
paint.setColor(flutter::DlColor::kRed());
paint.setBlendMode(flutter::DlBlendMode::kDstOver);
builder.drawRect(SkRect::MakeSize({200, 200}), paint);
builder.restore();
}
{
builder.saveLayer(nullptr, nullptr);
builder.translate(100, 300);
flutter::DlPaint paint;
paint.setColor(flutter::DlColor::kRed());
builder.drawRect(SkRect::MakeSize({200, 200}), paint);
paint.setColor(flutter::DlColor::kBlue().withAlpha(127));
paint.setBlendMode(flutter::DlBlendMode::kSrc);
builder.drawRect(SkRect::MakeSize({200, 200}), paint);
builder.restore();
}
{
builder.saveLayer(nullptr, nullptr);
builder.translate(300, 300);
flutter::DlPaint paint;
paint.setColor(flutter::DlColor::kBlue().withAlpha(127));
builder.drawRect(SkRect::MakeSize({200, 200}), paint);
paint.setColor(flutter::DlColor::kRed());
paint.setBlendMode(flutter::DlBlendMode::kDst);
builder.drawRect(SkRect::MakeSize({200, 200}), paint);
builder.restore();
}
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}
} // namespace testing
} // namespace impeller

View File

@@ -43,7 +43,7 @@ void ContentContextOptions::ApplyToPipelineDescriptor(
color0.src_color_blend_factor = BlendFactor::kOne;
break;
case BlendMode::kDestination:
color0.dst_alpha_blend_factor = BlendFactor::kDestinationAlpha;
color0.dst_alpha_blend_factor = BlendFactor::kOne;
color0.dst_color_blend_factor = BlendFactor::kOne;
color0.src_alpha_blend_factor = BlendFactor::kZero;
color0.src_color_blend_factor = BlendFactor::kZero;
@@ -55,7 +55,7 @@ void ContentContextOptions::ApplyToPipelineDescriptor(
color0.src_color_blend_factor = BlendFactor::kOne;
break;
case BlendMode::kDestinationOver:
color0.dst_alpha_blend_factor = BlendFactor::kDestinationAlpha;
color0.dst_alpha_blend_factor = BlendFactor::kOne;
color0.dst_color_blend_factor = BlendFactor::kOne;
color0.src_alpha_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
color0.src_color_blend_factor = BlendFactor::kOneMinusDestinationAlpha;