|
18 | 18 | #include "impeller/aiks/paint_pass_delegate.h" |
19 | 19 | #include "impeller/aiks/testing/context_spy.h" |
20 | 20 | #include "impeller/entity/contents/color_source_contents.h" |
| 21 | +#include "impeller/entity/contents/conical_gradient_contents.h" |
21 | 22 | #include "impeller/entity/contents/filters/inputs/filter_input.h" |
| 23 | +#include "impeller/entity/contents/linear_gradient_contents.h" |
22 | 24 | #include "impeller/entity/contents/scene_contents.h" |
23 | 25 | #include "impeller/entity/contents/solid_color_contents.h" |
24 | 26 | #include "impeller/entity/contents/tiled_texture_contents.h" |
@@ -393,6 +395,30 @@ TEST_P(AiksTest, CanRenderLinearGradientDecal) { |
393 | 395 | CanRenderLinearGradient(this, Entity::TileMode::kDecal); |
394 | 396 | } |
395 | 397 |
|
| 398 | +TEST_P(AiksTest, CanRenderLinearGradientDecalWithColorFilter) { |
| 399 | + Canvas canvas; |
| 400 | + canvas.Scale(GetContentScale()); |
| 401 | + Paint paint; |
| 402 | + canvas.Translate({100.0f, 0, 0}); |
| 403 | + |
| 404 | + std::vector<Color> colors = {Color{0.9568, 0.2627, 0.2118, 1.0}, |
| 405 | + Color{0.1294, 0.5882, 0.9529, 0.0}}; |
| 406 | + std::vector<Scalar> stops = {0.0, 1.0}; |
| 407 | + |
| 408 | + paint.color_source = ColorSource::MakeLinearGradient( |
| 409 | + {0, 0}, {200, 200}, std::move(colors), std::move(stops), |
| 410 | + Entity::TileMode::kDecal, {}); |
| 411 | + // Overlay the gradient with 25% green. This should appear as the entire |
| 412 | + // rectangle being drawn with 25% green, including the border area outside the |
| 413 | + // decal gradient. |
| 414 | + paint.color_filter = ColorFilter::MakeBlend(BlendMode::kSourceOver, |
| 415 | + Color::Green().WithAlpha(0.25)); |
| 416 | + |
| 417 | + paint.color = Color(1.0, 1.0, 1.0, 1.0); |
| 418 | + canvas.DrawRect({0, 0, 600, 600}, paint); |
| 419 | + ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); |
| 420 | +} |
| 421 | + |
396 | 422 | namespace { |
397 | 423 | void CanRenderLinearGradientWithOverlappingStops(AiksTest* aiks_test, |
398 | 424 | Entity::TileMode tile_mode) { |
@@ -2896,5 +2922,35 @@ TEST_P(AiksTest, MatrixBackdropFilter) { |
2896 | 2922 | ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); |
2897 | 2923 | } |
2898 | 2924 |
|
| 2925 | +TEST_P(AiksTest, SolidColorApplyColorFilter) { |
| 2926 | + auto contents = SolidColorContents(); |
| 2927 | + contents.SetColor(Color::CornflowerBlue().WithAlpha(0.75)); |
| 2928 | + auto result = contents.ApplyColorFilter([](const Color& color) { |
| 2929 | + return color.Blend(Color::LimeGreen().WithAlpha(0.75), BlendMode::kScreen); |
| 2930 | + }); |
| 2931 | + ASSERT_TRUE(result); |
| 2932 | + ASSERT_COLOR_NEAR(contents.GetColor(), |
| 2933 | + Color(0.433247, 0.879523, 0.825324, 0.75)); |
| 2934 | +} |
| 2935 | + |
| 2936 | +#define APPLY_COLOR_FILTER_GRADIENT_TEST(name) \ |
| 2937 | + TEST_P(AiksTest, name##GradientApplyColorFilter) { \ |
| 2938 | + auto contents = name##GradientContents(); \ |
| 2939 | + contents.SetColors({Color::CornflowerBlue().WithAlpha(0.75)}); \ |
| 2940 | + auto result = contents.ApplyColorFilter([](const Color& color) { \ |
| 2941 | + return color.Blend(Color::LimeGreen().WithAlpha(0.75), \ |
| 2942 | + BlendMode::kScreen); \ |
| 2943 | + }); \ |
| 2944 | + ASSERT_TRUE(result); \ |
| 2945 | + \ |
| 2946 | + std::vector<Color> expected = {Color(0.433247, 0.879523, 0.825324, 0.75)}; \ |
| 2947 | + ASSERT_COLORS_NEAR(contents.GetColors(), expected); \ |
| 2948 | + } |
| 2949 | + |
| 2950 | +APPLY_COLOR_FILTER_GRADIENT_TEST(Linear); |
| 2951 | +APPLY_COLOR_FILTER_GRADIENT_TEST(Radial); |
| 2952 | +APPLY_COLOR_FILTER_GRADIENT_TEST(Conical); |
| 2953 | +APPLY_COLOR_FILTER_GRADIENT_TEST(Sweep); |
| 2954 | + |
2899 | 2955 | } // namespace testing |
2900 | 2956 | } // namespace impeller |
0 commit comments