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

Fixes blend + color filter #55411

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions impeller/display_list/aiks_dl_blend_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,58 @@ TEST_P(AiksTest, PaintBlendModeIsRespected) {
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}

// Compare results with https://api.flutter.dev/flutter/dart-ui/BlendMode.html
TEST_P(AiksTest, ImageFilterBlend) {
bool has_color_filter = true;
auto callback = [&]() -> sk_sp<DisplayList> {
if (AiksTest::ImGuiBegin("Controls", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Checkbox("has color filter", &has_color_filter);
ImGui::End();
}

DisplayListBuilder builder;
builder.Scale(GetContentScale().x, GetContentScale().y);

auto src_image =
DlImageImpeller::Make(CreateTextureForFixture("blend_mode_src.png"));
auto dst_image =
DlImageImpeller::Make(CreateTextureForFixture("blend_mode_dst.png"));

std::vector<DlBlendMode> blend_modes = {
DlBlendMode::kSrc, DlBlendMode::kSrcATop, DlBlendMode::kSrcOver,
DlBlendMode::kSrcIn, DlBlendMode::kSrcOut, DlBlendMode::kDst,
DlBlendMode::kDstATop, DlBlendMode::kDstOver, DlBlendMode::kDstIn,
DlBlendMode::kDstOut, DlBlendMode::kClear, DlBlendMode::kXor};

for (uint32_t i = 0; i < blend_modes.size(); ++i) {
builder.Save();
builder.Translate((i % 5) * 200, (i / 5) * 200);
builder.Scale(0.4, 0.4);
{
DlPaint dstPaint;
builder.DrawImage(dst_image, {0, 0}, DlImageSampling::kMipmapLinear,
&dstPaint);
}
{
DlPaint srcPaint;
srcPaint.setBlendMode(blend_modes[i]);
if (has_color_filter) {
std::shared_ptr<const DlColorFilter> color_filter =
DlBlendColorFilter::Make(DlColor::RGBA(0.9, 0.5, 0.0, 1.0),
DlBlendMode::kSrcIn);
srcPaint.setColorFilter(color_filter);
}
builder.DrawImage(src_image, {0, 0}, DlImageSampling::kMipmapLinear,
&srcPaint);
}
builder.Restore();
}
return builder.Build();
};
ASSERT_TRUE(OpenPlaygroundHere(callback));
}

// Bug: https://github.com/flutter/flutter/issues/142549
TEST_P(AiksTest, BlendModePlusAlphaWideGamut) {
EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
Expand Down
3 changes: 2 additions & 1 deletion impeller/entity/contents/filters/blend_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
BlendModeToString(blend_mode)));
#endif // IMPELLER_DEBUG
pass.SetVertexBuffer(std::move(vtx_buffer));
auto options = OptionsFromPass(pass);
auto options = OptionsFromPassAndEntity(pass, entity);
options.primitive_type = PrimitiveType::kTriangleStrip;
pass.SetPipeline(renderer.GetPorterDuffBlendPipeline(options));

Expand Down Expand Up @@ -505,6 +505,7 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(

Entity sub_entity;
sub_entity.SetContents(std::move(contents));
sub_entity.SetBlendMode(entity.GetBlendMode());

return sub_entity;
}
Expand Down
3 changes: 3 additions & 0 deletions testing/impeller_golden_tests_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,9 @@ impeller_Play_AiksTest_GradientStrokesRenderCorrectly_Vulkan.png
impeller_Play_AiksTest_ImageColorSourceEffectTransform_Metal.png
impeller_Play_AiksTest_ImageColorSourceEffectTransform_OpenGLES.png
impeller_Play_AiksTest_ImageColorSourceEffectTransform_Vulkan.png
impeller_Play_AiksTest_ImageFilterBlend_Metal.png
impeller_Play_AiksTest_ImageFilterBlend_OpenGLES.png
impeller_Play_AiksTest_ImageFilterBlend_Vulkan.png
impeller_Play_AiksTest_ImageFilteredSaveLayerWithUnboundedContents_Metal.png
impeller_Play_AiksTest_ImageFilteredSaveLayerWithUnboundedContents_OpenGLES.png
impeller_Play_AiksTest_ImageFilteredSaveLayerWithUnboundedContents_Vulkan.png
Expand Down