diff --git a/impeller/aiks/aiks_unittests.cc b/impeller/aiks/aiks_unittests.cc index 57b6f1ccd1152..0d2c00a30e0cd 100644 --- a/impeller/aiks/aiks_unittests.cc +++ b/impeller/aiks/aiks_unittests.cc @@ -1842,5 +1842,37 @@ TEST_P(AiksTest, SceneColorSource) { ASSERT_TRUE(OpenPlaygroundHere(callback)); } +TEST_P(AiksTest, PaintWithFilters) { + // validate that a paint with a color filter "HasFilters", no other filters + // impact this setting. + Paint paint; + + ASSERT_FALSE(paint.HasColorFilter()); + + paint.color_filter = [](FilterInput::Ref input) { + return ColorFilterContents::MakeBlend(BlendMode::kSourceOver, + {std::move(input)}, Color::Blue()); + }; + + ASSERT_TRUE(paint.HasColorFilter()); + + paint.image_filter = [](const FilterInput::Ref& input, + const Matrix& effect_transform) { + return FilterContents::MakeGaussianBlur( + input, Sigma(1.0), Sigma(1.0), FilterContents::BlurStyle::kNormal, + Entity::TileMode::kClamp, effect_transform); + }; + + ASSERT_TRUE(paint.HasColorFilter()); + + paint.mask_blur_descriptor = {}; + + ASSERT_TRUE(paint.HasColorFilter()); + + paint.color_filter = std::nullopt; + + ASSERT_FALSE(paint.HasColorFilter()); +} + } // namespace testing } // namespace impeller diff --git a/impeller/aiks/canvas.cc b/impeller/aiks/canvas.cc index 536fb378df21a..2d281c6069e08 100644 --- a/impeller/aiks/canvas.cc +++ b/impeller/aiks/canvas.cc @@ -306,6 +306,7 @@ void Canvas::DrawImageRect(const std::shared_ptr& image, contents->SetSourceRect(source); contents->SetSamplerDescriptor(std::move(sampler)); contents->SetOpacity(paint.color.alpha); + contents->SetDeferApplyingOpacity(paint.HasColorFilter()); Entity entity; entity.SetBlendMode(paint.blend_mode); diff --git a/impeller/aiks/paint.cc b/impeller/aiks/paint.cc index 04b93e248bea1..1d94c8ce85618 100644 --- a/impeller/aiks/paint.cc +++ b/impeller/aiks/paint.cc @@ -107,4 +107,8 @@ std::shared_ptr Paint::MaskBlurDescriptor::CreateMaskBlur( effect_transform); } +bool Paint::HasColorFilter() const { + return color_filter.has_value(); +} + } // namespace impeller diff --git a/impeller/aiks/paint.h b/impeller/aiks/paint.h index 7db7b4223a49e..60699f96f56d1 100644 --- a/impeller/aiks/paint.h +++ b/impeller/aiks/paint.h @@ -106,6 +106,9 @@ struct Paint { std::shared_ptr CreateContentsForGeometry( std::unique_ptr geometry) const; + /// @brief Whether this paint has a color filter that can apply opacity + bool HasColorFilter() const; + private: std::shared_ptr WithMaskBlur(std::shared_ptr input, bool is_solid_color,