fixes color filter + advanced blends (flutter/engine#55448)

fixes https://github.com/flutter/flutter/issues/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
This commit is contained in:
gaaclarke
2024-09-26 09:20:06 -07:00
committed by GitHub
parent 81d35bf59e
commit 015281d470
3 changed files with 67 additions and 6 deletions

View File

@@ -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,
@@ -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(),

View File

@@ -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()) {

View File

@@ -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
@@ -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