[Impeller] let images with opacity and filters passthrough. (flutter/engine#39237)
* [impeller] let images with opacity and filters passthrough * ++ * ++ * ++ * ++ * Update aiks_unittests.cc * ++ * ++ * Update canvas.cc
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -107,4 +107,8 @@ std::shared_ptr<FilterContents> Paint::MaskBlurDescriptor::CreateMaskBlur(
|
||||
effect_transform);
|
||||
}
|
||||
|
||||
bool Paint::HasColorFilter() const {
|
||||
return color_filter.has_value();
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user