[Impeller] Blend alpha correctly in the 'DstOver' mode and the 'Dst' mode (flutter/engine#36439)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user