diff --git a/engine/src/flutter/impeller/display_list/display_list_unittests.cc b/engine/src/flutter/impeller/display_list/display_list_unittests.cc index 3124f803e0..f80888d2b5 100644 --- a/engine/src/flutter/impeller/display_list/display_list_unittests.cc +++ b/engine/src/flutter/impeller/display_list/display_list_unittests.cc @@ -328,6 +328,37 @@ TEST_P(DisplayListTest, CanDrawWithComposeImageFilter) { ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); } +TEST_P(DisplayListTest, CanClampTheResultingColorOfColorMatrixFilter) { + auto texture = CreateTextureForFixture("boston.jpg"); + const float inner_color_matrix[20] = { + 1, 0, 0, 0, 0, // + 0, 1, 0, 0, 0, // + 0, 0, 1, 0, 0, // + 0, 0, 0, 2, 0, // + }; + const float outer_color_matrix[20] = { + 1, 0, 0, 0, 0, // + 0, 1, 0, 0, 0, // + 0, 0, 1, 0, 0, // + 0, 0, 0, 0.5, 0, // + }; + auto inner_color_filter = + std::make_shared(inner_color_matrix); + auto outer_color_filter = + std::make_shared(outer_color_matrix); + auto inner = + std::make_shared(inner_color_filter); + auto outer = + std::make_shared(outer_color_filter); + auto compose = std::make_shared(outer, inner); + + flutter::DisplayListBuilder builder; + builder.setImageFilter(compose.get()); + builder.drawImage(DlImageImpeller::Make(texture), SkPoint::Make(100, 100), + flutter::DlImageSampling::kNearestNeighbor, true); + ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); +} + TEST_P(DisplayListTest, CanDrawBackdropFilter) { auto texture = CreateTextureForFixture("embarcadero.jpg"); diff --git a/engine/src/flutter/impeller/entity/shaders/color_matrix_color_filter.frag b/engine/src/flutter/impeller/entity/shaders/color_matrix_color_filter.frag index 47280649dd..a2baf4291d 100644 --- a/engine/src/flutter/impeller/entity/shaders/color_matrix_color_filter.frag +++ b/engine/src/flutter/impeller/entity/shaders/color_matrix_color_filter.frag @@ -44,7 +44,7 @@ void main() { // unpremultiply first, as filter inputs are premultiplied. vec4 color = IPUnpremultiply(input_color); - color = frag_info.color_m * color + frag_info.color_v; + color = clamp(frag_info.color_m * color + frag_info.color_v, 0.0, 1.0); // premultiply the outputs frag_color = vec4(color.rgb * color.a, color.a);