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

fixes color filter + advanced blends #55448

Merged
merged 4 commits into from
Sep 26, 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
59 changes: 58 additions & 1 deletion impeller/display_list/aiks_dl_blend_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ TEST_P(AiksTest, PaintBlendModeIsRespected) {
}

// Compare results with https://api.flutter.dev/flutter/dart-ui/BlendMode.html
TEST_P(AiksTest, ImageFilterBlend) {
TEST_P(AiksTest, ColorFilterBlend) {
bool has_color_filter = true;
auto callback = [&]() -> sk_sp<DisplayList> {
if (AiksTest::ImGuiBegin("Controls", nullptr,
Expand Down Expand Up @@ -246,6 +246,63 @@ TEST_P(AiksTest, ImageFilterBlend) {
ASSERT_TRUE(OpenPlaygroundHere(callback));
}

// Verification for: https://github.com/flutter/flutter/issues/155691
TEST_P(AiksTest, ColorFilterAdvancedBlend) {
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::kScreen, DlBlendMode::kOverlay,
DlBlendMode::kDarken, DlBlendMode::kLighten,
DlBlendMode::kColorDodge, DlBlendMode::kColorBurn,
DlBlendMode::kHardLight, DlBlendMode::kSoftLight,
DlBlendMode::kDifference, DlBlendMode::kExclusion,
DlBlendMode::kMultiply, DlBlendMode::kHue,
DlBlendMode::kSaturation, DlBlendMode::kColor,
DlBlendMode::kLuminosity,
};

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
5 changes: 3 additions & 2 deletions impeller/entity/contents/filters/blend_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,9 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
FS::FragInfo frag_info;
VS::FrameInfo frame_info;

frame_info.mvp = Entity::GetShaderTransform(entity.GetShaderClipDepth(),
pass, dst_snapshot->transform);
frame_info.mvp = Entity::GetShaderTransform(
entity.GetShaderClipDepth(), pass,
entity.GetTransform() * dst_snapshot->transform);

auto dst_sampler_descriptor = dst_snapshot->sampler_descriptor;
if (renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode()) {
Expand Down
9 changes: 6 additions & 3 deletions testing/impeller_golden_tests_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,12 @@ impeller_Play_AiksTest_CollapsedDrawPaintInSubpassBackdropFilter_Vulkan.png
impeller_Play_AiksTest_CollapsedDrawPaintInSubpass_Metal.png
impeller_Play_AiksTest_CollapsedDrawPaintInSubpass_OpenGLES.png
impeller_Play_AiksTest_CollapsedDrawPaintInSubpass_Vulkan.png
impeller_Play_AiksTest_ColorFilterAdvancedBlend_Metal.png
impeller_Play_AiksTest_ColorFilterAdvancedBlend_OpenGLES.png
impeller_Play_AiksTest_ColorFilterAdvancedBlend_Vulkan.png
impeller_Play_AiksTest_ColorFilterBlend_Metal.png
impeller_Play_AiksTest_ColorFilterBlend_OpenGLES.png
impeller_Play_AiksTest_ColorFilterBlend_Vulkan.png
impeller_Play_AiksTest_ColorMatrixFilterSubpassCollapseOptimization_Metal.png
impeller_Play_AiksTest_ColorMatrixFilterSubpassCollapseOptimization_OpenGLES.png
impeller_Play_AiksTest_ColorMatrixFilterSubpassCollapseOptimization_Vulkan.png
Expand Down Expand Up @@ -711,9 +717,6 @@ 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