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

Commit 5351777

Browse files
authored
fixes color filter + advanced blends (#55448)
fixes flutter/flutter#155691 I'm also renaming the test I just introduced, it was named wrong, talking about "image filter", not "color filter". [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 9e6133e commit 5351777

File tree

3 files changed

+67
-6
lines changed

3 files changed

+67
-6
lines changed

impeller/display_list/aiks_dl_blend_unittests.cc

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ TEST_P(AiksTest, PaintBlendModeIsRespected) {
195195
}
196196

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

249+
// Verification for: https://github.com/flutter/flutter/issues/155691
250+
TEST_P(AiksTest, ColorFilterAdvancedBlend) {
251+
bool has_color_filter = true;
252+
auto callback = [&]() -> sk_sp<DisplayList> {
253+
if (AiksTest::ImGuiBegin("Controls", nullptr,
254+
ImGuiWindowFlags_AlwaysAutoResize)) {
255+
ImGui::Checkbox("has color filter", &has_color_filter);
256+
ImGui::End();
257+
}
258+
259+
DisplayListBuilder builder;
260+
builder.Scale(GetContentScale().x, GetContentScale().y);
261+
262+
auto src_image =
263+
DlImageImpeller::Make(CreateTextureForFixture("blend_mode_src.png"));
264+
auto dst_image =
265+
DlImageImpeller::Make(CreateTextureForFixture("blend_mode_dst.png"));
266+
267+
std::vector<DlBlendMode> blend_modes = {
268+
DlBlendMode::kScreen, DlBlendMode::kOverlay,
269+
DlBlendMode::kDarken, DlBlendMode::kLighten,
270+
DlBlendMode::kColorDodge, DlBlendMode::kColorBurn,
271+
DlBlendMode::kHardLight, DlBlendMode::kSoftLight,
272+
DlBlendMode::kDifference, DlBlendMode::kExclusion,
273+
DlBlendMode::kMultiply, DlBlendMode::kHue,
274+
DlBlendMode::kSaturation, DlBlendMode::kColor,
275+
DlBlendMode::kLuminosity,
276+
};
277+
278+
for (uint32_t i = 0; i < blend_modes.size(); ++i) {
279+
builder.Save();
280+
builder.Translate((i % 5) * 200, (i / 5) * 200);
281+
builder.Scale(0.4, 0.4);
282+
{
283+
DlPaint dstPaint;
284+
builder.DrawImage(dst_image, {0, 0}, DlImageSampling::kMipmapLinear,
285+
&dstPaint);
286+
}
287+
{
288+
DlPaint srcPaint;
289+
srcPaint.setBlendMode(blend_modes[i]);
290+
if (has_color_filter) {
291+
std::shared_ptr<const DlColorFilter> color_filter =
292+
DlBlendColorFilter::Make(DlColor::RGBA(0.9, 0.5, 0.0, 1.0),
293+
DlBlendMode::kSrcIn);
294+
srcPaint.setColorFilter(color_filter);
295+
}
296+
builder.DrawImage(src_image, {0, 0}, DlImageSampling::kMipmapLinear,
297+
&srcPaint);
298+
}
299+
builder.Restore();
300+
}
301+
return builder.Build();
302+
};
303+
ASSERT_TRUE(OpenPlaygroundHere(callback));
304+
}
305+
249306
// Bug: https://github.com/flutter/flutter/issues/142549
250307
TEST_P(AiksTest, BlendModePlusAlphaWideGamut) {
251308
EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),

impeller/entity/contents/filters/blend_filter_contents.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,9 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
461461
FS::FragInfo frag_info;
462462
VS::FrameInfo frame_info;
463463

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

467468
auto dst_sampler_descriptor = dst_snapshot->sampler_descriptor;
468469
if (renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode()) {

testing/impeller_golden_tests_output.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,12 @@ impeller_Play_AiksTest_CollapsedDrawPaintInSubpassBackdropFilter_Vulkan.png
523523
impeller_Play_AiksTest_CollapsedDrawPaintInSubpass_Metal.png
524524
impeller_Play_AiksTest_CollapsedDrawPaintInSubpass_OpenGLES.png
525525
impeller_Play_AiksTest_CollapsedDrawPaintInSubpass_Vulkan.png
526+
impeller_Play_AiksTest_ColorFilterAdvancedBlend_Metal.png
527+
impeller_Play_AiksTest_ColorFilterAdvancedBlend_OpenGLES.png
528+
impeller_Play_AiksTest_ColorFilterAdvancedBlend_Vulkan.png
529+
impeller_Play_AiksTest_ColorFilterBlend_Metal.png
530+
impeller_Play_AiksTest_ColorFilterBlend_OpenGLES.png
531+
impeller_Play_AiksTest_ColorFilterBlend_Vulkan.png
526532
impeller_Play_AiksTest_ColorMatrixFilterSubpassCollapseOptimization_Metal.png
527533
impeller_Play_AiksTest_ColorMatrixFilterSubpassCollapseOptimization_OpenGLES.png
528534
impeller_Play_AiksTest_ColorMatrixFilterSubpassCollapseOptimization_Vulkan.png
@@ -711,9 +717,6 @@ impeller_Play_AiksTest_GradientStrokesRenderCorrectly_Vulkan.png
711717
impeller_Play_AiksTest_ImageColorSourceEffectTransform_Metal.png
712718
impeller_Play_AiksTest_ImageColorSourceEffectTransform_OpenGLES.png
713719
impeller_Play_AiksTest_ImageColorSourceEffectTransform_Vulkan.png
714-
impeller_Play_AiksTest_ImageFilterBlend_Metal.png
715-
impeller_Play_AiksTest_ImageFilterBlend_OpenGLES.png
716-
impeller_Play_AiksTest_ImageFilterBlend_Vulkan.png
717720
impeller_Play_AiksTest_ImageFilteredSaveLayerWithUnboundedContents_Metal.png
718721
impeller_Play_AiksTest_ImageFilteredSaveLayerWithUnboundedContents_OpenGLES.png
719722
impeller_Play_AiksTest_ImageFilteredSaveLayerWithUnboundedContents_Vulkan.png

0 commit comments

Comments
 (0)