[Impeller] Implement inherited opacity for ColorFilterContents (#161834)

Inherited opacity should be combined with the alpha of the
ColorFilterContents when drawing objects with filters inside an opacity
layer.
This commit is contained in:
Jason Simmons 2025-01-23 07:45:55 -08:00 committed by GitHub
parent b56b5b6a23
commit 6a8d77dccd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 36 additions and 1 deletions

View File

@ -1376,5 +1376,29 @@ TEST_P(AiksTest,
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}
TEST_P(AiksTest, BlurGradientWithOpacity) {
DisplayListBuilder builder;
builder.Scale(GetContentScale().x, GetContentScale().y);
std::vector<DlColor> colors = {DlColor(0xFFFF0000), DlColor(0xFF00FF00)};
std::vector<Scalar> stops = {0.0, 1.0};
auto gradient = DlColorSource::MakeLinear(
{0, 0}, {400, 400}, 2, colors.data(), stops.data(), DlTileMode::kClamp);
DlPaint save_paint;
save_paint.setOpacity(0.5);
builder.SaveLayer(nullptr, &save_paint);
DlPaint paint;
paint.setColorSource(gradient);
paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 1));
builder.DrawRect(SkRect::MakeXYWH(100, 100, 200, 200), paint);
builder.Restore();
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}
} // namespace testing
} // namespace impeller

View File

@ -96,7 +96,11 @@ void ColorFilterContents::SetAlpha(Scalar alpha) {
}
std::optional<Scalar> ColorFilterContents::GetAlpha() const {
return alpha_;
return alpha_.value_or(1.0) * inherited_opacity_;
}
void ColorFilterContents::SetInheritedOpacity(Scalar opacity) {
inherited_opacity_ = opacity;
}
std::optional<Rect> ColorFilterContents::GetFilterSourceCoverage(

View File

@ -45,6 +45,9 @@ class ColorFilterContents : public FilterContents {
std::optional<Scalar> GetAlpha() const;
// |Contents|
void SetInheritedOpacity(Scalar opacity) override;
// |FilterContents|
std::optional<Rect> GetFilterSourceCoverage(
const Matrix& effect_transform,
@ -53,6 +56,7 @@ class ColorFilterContents : public FilterContents {
private:
AbsorbOpacity absorb_opacity_ = AbsorbOpacity::kNo;
std::optional<Scalar> alpha_;
Scalar inherited_opacity_ = 1.0;
ColorFilterContents(const ColorFilterContents&) = delete;

View File

@ -185,6 +185,9 @@ impeller_Play_AiksTest_BlendModeSrcAlphaXor_Vulkan.png
impeller_Play_AiksTest_BlendModeXor_Metal.png
impeller_Play_AiksTest_BlendModeXor_OpenGLES.png
impeller_Play_AiksTest_BlendModeXor_Vulkan.png
impeller_Play_AiksTest_BlurGradientWithOpacity_Metal.png
impeller_Play_AiksTest_BlurGradientWithOpacity_OpenGLES.png
impeller_Play_AiksTest_BlurGradientWithOpacity_Vulkan.png
impeller_Play_AiksTest_BlurHasNoEdge_Metal.png
impeller_Play_AiksTest_BlurHasNoEdge_OpenGLES.png
impeller_Play_AiksTest_BlurHasNoEdge_Vulkan.png