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

Commit d143ca8

Browse files
authored
Fixes blend + color filter (#55411)
fixes flutter/flutter#155456 Thanks @jason-simmons for identifying the fix. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
1 parent 4709c42 commit d143ca8

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

impeller/display_list/aiks_dl_blend_unittests.cc

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,58 @@ TEST_P(AiksTest, PaintBlendModeIsRespected) {
194194
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
195195
}
196196

197+
// Compare results with https://api.flutter.dev/flutter/dart-ui/BlendMode.html
198+
TEST_P(AiksTest, ImageFilterBlend) {
199+
bool has_color_filter = true;
200+
auto callback = [&]() -> sk_sp<DisplayList> {
201+
if (AiksTest::ImGuiBegin("Controls", nullptr,
202+
ImGuiWindowFlags_AlwaysAutoResize)) {
203+
ImGui::Checkbox("has color filter", &has_color_filter);
204+
ImGui::End();
205+
}
206+
207+
DisplayListBuilder builder;
208+
builder.Scale(GetContentScale().x, GetContentScale().y);
209+
210+
auto src_image =
211+
DlImageImpeller::Make(CreateTextureForFixture("blend_mode_src.png"));
212+
auto dst_image =
213+
DlImageImpeller::Make(CreateTextureForFixture("blend_mode_dst.png"));
214+
215+
std::vector<DlBlendMode> blend_modes = {
216+
DlBlendMode::kSrc, DlBlendMode::kSrcATop, DlBlendMode::kSrcOver,
217+
DlBlendMode::kSrcIn, DlBlendMode::kSrcOut, DlBlendMode::kDst,
218+
DlBlendMode::kDstATop, DlBlendMode::kDstOver, DlBlendMode::kDstIn,
219+
DlBlendMode::kDstOut, DlBlendMode::kClear, DlBlendMode::kXor};
220+
221+
for (uint32_t i = 0; i < blend_modes.size(); ++i) {
222+
builder.Save();
223+
builder.Translate((i % 5) * 200, (i / 5) * 200);
224+
builder.Scale(0.4, 0.4);
225+
{
226+
DlPaint dstPaint;
227+
builder.DrawImage(dst_image, {0, 0}, DlImageSampling::kMipmapLinear,
228+
&dstPaint);
229+
}
230+
{
231+
DlPaint srcPaint;
232+
srcPaint.setBlendMode(blend_modes[i]);
233+
if (has_color_filter) {
234+
std::shared_ptr<const DlColorFilter> color_filter =
235+
DlBlendColorFilter::Make(DlColor::RGBA(0.9, 0.5, 0.0, 1.0),
236+
DlBlendMode::kSrcIn);
237+
srcPaint.setColorFilter(color_filter);
238+
}
239+
builder.DrawImage(src_image, {0, 0}, DlImageSampling::kMipmapLinear,
240+
&srcPaint);
241+
}
242+
builder.Restore();
243+
}
244+
return builder.Build();
245+
};
246+
ASSERT_TRUE(OpenPlaygroundHere(callback));
247+
}
248+
197249
// Bug: https://github.com/flutter/flutter/issues/142549
198250
TEST_P(AiksTest, BlendModePlusAlphaWideGamut) {
199251
EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),

impeller/entity/contents/filters/blend_filter_contents.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
454454
BlendModeToString(blend_mode)));
455455
#endif // IMPELLER_DEBUG
456456
pass.SetVertexBuffer(std::move(vtx_buffer));
457-
auto options = OptionsFromPass(pass);
457+
auto options = OptionsFromPassAndEntity(pass, entity);
458458
options.primitive_type = PrimitiveType::kTriangleStrip;
459459
pass.SetPipeline(renderer.GetPorterDuffBlendPipeline(options));
460460

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

506506
Entity sub_entity;
507507
sub_entity.SetContents(std::move(contents));
508+
sub_entity.SetBlendMode(entity.GetBlendMode());
508509

509510
return sub_entity;
510511
}

testing/impeller_golden_tests_output.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,9 @@ impeller_Play_AiksTest_GradientStrokesRenderCorrectly_Vulkan.png
711711
impeller_Play_AiksTest_ImageColorSourceEffectTransform_Metal.png
712712
impeller_Play_AiksTest_ImageColorSourceEffectTransform_OpenGLES.png
713713
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
714717
impeller_Play_AiksTest_ImageFilteredSaveLayerWithUnboundedContents_Metal.png
715718
impeller_Play_AiksTest_ImageFilteredSaveLayerWithUnboundedContents_OpenGLES.png
716719
impeller_Play_AiksTest_ImageFilteredSaveLayerWithUnboundedContents_Vulkan.png

0 commit comments

Comments
 (0)