[Impeller] Implement invert colors flag. (flutter/engine#39729)
* [Impeller] implement invert colors flag * [Impeller] add invert colors support
This commit is contained in:
@@ -82,6 +82,16 @@ TEST_P(AiksTest, CanRenderImage) {
|
||||
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
|
||||
}
|
||||
|
||||
TEST_P(AiksTest, CanRenderInvertedImage) {
|
||||
Canvas canvas;
|
||||
Paint paint;
|
||||
auto image = std::make_shared<Image>(CreateTextureForFixture("kalimba.jpg"));
|
||||
paint.color = Color::Red();
|
||||
paint.invert_colors = true;
|
||||
canvas.DrawImage(image, Point::MakeXY(100.0, 100.0), paint);
|
||||
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
|
||||
}
|
||||
|
||||
bool GenerateMipmap(const std::shared_ptr<Context>& context,
|
||||
std::shared_ptr<Texture> texture,
|
||||
std::string label) {
|
||||
|
||||
@@ -61,6 +61,7 @@ std::shared_ptr<Contents> Paint::WithFilters(
|
||||
const Matrix& effect_transform) const {
|
||||
bool is_solid_color_val = is_solid_color.value_or(!color_source);
|
||||
input = WithColorFilter(input);
|
||||
input = WithInvertFilter(input);
|
||||
input = WithMaskBlur(input, is_solid_color_val, effect_transform);
|
||||
input = WithImageFilter(input, effect_transform);
|
||||
return input;
|
||||
@@ -114,6 +115,28 @@ std::shared_ptr<Contents> Paint::WithColorFilter(
|
||||
return input;
|
||||
}
|
||||
|
||||
/// A color matrix which inverts colors.
|
||||
// clang-format off
|
||||
constexpr ColorFilterContents::ColorMatrix kColorInversion = {
|
||||
.array = {
|
||||
-1.0, 0, 0, 1.0, 0, //
|
||||
0, -1.0, 0, 1.0, 0, //
|
||||
0, 0, -1.0, 1.0, 0, //
|
||||
1.0, 1.0, 1.0, 1.0, 0 //
|
||||
}
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
std::shared_ptr<Contents> Paint::WithInvertFilter(
|
||||
std::shared_ptr<Contents> input) const {
|
||||
if (!invert_colors) {
|
||||
return input;
|
||||
}
|
||||
|
||||
return ColorFilterContents::MakeColorMatrix(
|
||||
{FilterInput::Make(std::move(input))}, kColorInversion);
|
||||
}
|
||||
|
||||
std::shared_ptr<FilterContents> Paint::MaskBlurDescriptor::CreateMaskBlur(
|
||||
const FilterInput::Ref& input,
|
||||
bool is_solid_color,
|
||||
|
||||
@@ -67,6 +67,7 @@ struct Paint {
|
||||
Scalar stroke_miter = 4.0;
|
||||
Style style = Style::kFill;
|
||||
BlendMode blend_mode = BlendMode::kSourceOver;
|
||||
bool invert_colors = false;
|
||||
|
||||
std::optional<ImageFilterProc> image_filter;
|
||||
std::optional<ColorFilterProc> color_filter;
|
||||
@@ -123,6 +124,9 @@ struct Paint {
|
||||
|
||||
std::shared_ptr<Contents> WithColorFilter(std::shared_ptr<Contents> input,
|
||||
bool absorb_opacity = false) const;
|
||||
|
||||
std::shared_ptr<Contents> WithInvertFilter(
|
||||
std::shared_ptr<Contents> input) const;
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -580,7 +580,7 @@ void DisplayListDispatcher::setColorFilter(
|
||||
|
||||
// |flutter::Dispatcher|
|
||||
void DisplayListDispatcher::setInvertColors(bool invert) {
|
||||
UNIMPLEMENTED;
|
||||
paint_.invert_colors = invert;
|
||||
}
|
||||
|
||||
// |flutter::Dispatcher|
|
||||
|
||||
Reference in New Issue
Block a user