Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions impeller/aiks/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ void Canvas::DrawImageRect(const std::shared_ptr<Image>& 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);
Expand Down
4 changes: 4 additions & 0 deletions impeller/aiks/paint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,8 @@ std::shared_ptr<FilterContents> Paint::MaskBlurDescriptor::CreateMaskBlur(
effect_transform);
}

bool Paint::HasColorFilter() const {
return color_filter.has_value();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why color filters specifically? Not all color filters absorb opacity IIRC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I should check for this with #39266

The general answer is that the high level framework API makes it extrenely easy to apply color blend filters to images, and no other type of color or image filter. see color and colorBlendMode in https://api.flutter.dev/flutter/widgets/Image-class.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of now, all color filters absorb opacity.

}

} // namespace impeller
3 changes: 3 additions & 0 deletions impeller/aiks/paint.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ struct Paint {
std::shared_ptr<Contents> CreateContentsForGeometry(
std::unique_ptr<Geometry> geometry) const;

/// @brief Whether this paint has a color filter that can apply opacity
bool HasColorFilter() const;

private:
std::shared_ptr<Contents> WithMaskBlur(std::shared_ptr<Contents> input,
bool is_solid_color,
Expand Down