Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] move more aiks tests to DL. #53792

Merged
merged 6 commits into from
Jul 11, 2024
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
1 change: 1 addition & 0 deletions ci/licenses_golden/excluded_files
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
../../../flutter/impeller/display_list/aiks_dl_gradient_unittests.cc
../../../flutter/impeller/display_list/aiks_dl_opacity_unittests.cc
../../../flutter/impeller/display_list/aiks_dl_path_unittests.cc
../../../flutter/impeller/display_list/aiks_dl_unittests.cc
../../../flutter/impeller/display_list/aiks_dl_vertices_unittests.cc
../../../flutter/impeller/display_list/dl_golden_blur_unittests.cc
../../../flutter/impeller/display_list/dl_golden_unittests.cc
Expand Down
5 changes: 3 additions & 2 deletions display_list/dl_color.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ struct DlColor {
static constexpr DlColor kLightGrey() {return DlColor(0xFFC0C0C0);};
static constexpr DlColor kAliceBlue() {return DlColor(0xFFF0F8FF);};
static constexpr DlColor kFuchsia() {return DlColor(0xFFFF00FF);};
static constexpr DlColor kMaroon() {return DlColor(0xFF800000);}
static constexpr DlColor kSkyBlue() {return DlColor(0xFF87CEEB);}
static constexpr DlColor kMaroon() {return DlColor(0xFF800000);};
static constexpr DlColor kSkyBlue() {return DlColor(0xFF87CEEB);};
static constexpr DlColor kCornflowerBlue() {return DlColor(0xFF6495ED);};
// clang-format on

constexpr bool isOpaque() const { return getAlpha() == 0xFF; }
Expand Down
349 changes: 0 additions & 349 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1758,143 +1758,6 @@ TEST_P(AiksTest, ClearColorOptimizationDoesNotApplyForBackdropFilters) {
EXPECT_FALSE(actual_color.has_value());
}

TEST_P(AiksTest, CollapsedDrawPaintInSubpass) {
Canvas canvas;
canvas.DrawPaint(
{.color = Color::Yellow(), .blend_mode = BlendMode::kSource});
canvas.SaveLayer({.blend_mode = BlendMode::kMultiply});
canvas.DrawPaint({.color = Color::CornflowerBlue().WithAlpha(0.75),
.blend_mode = BlendMode::kSourceOver});

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, CollapsedDrawPaintInSubpassBackdropFilter) {
// Bug: https://github.com/flutter/flutter/issues/131576
Canvas canvas;
canvas.DrawPaint(
{.color = Color::Yellow(), .blend_mode = BlendMode::kSource});
canvas.SaveLayer({}, {},
ImageFilter::MakeBlur(Sigma(20.0), Sigma(20.0),
FilterContents::BlurStyle::kNormal,
Entity::TileMode::kDecal));
canvas.DrawPaint(
{.color = Color::CornflowerBlue(), .blend_mode = BlendMode::kSourceOver});

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, ColorMatrixFilterSubpassCollapseOptimization) {
Canvas canvas;

canvas.SaveLayer({
.color_filter =
ColorFilter::MakeMatrix({.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 //
}}),
});

canvas.Translate({500, 300, 0});
canvas.Rotate(Radians(2 * kPi / 3));
canvas.DrawRect(Rect::MakeXYWH(100, 100, 200, 200), {.color = Color::Blue()});

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, LinearToSrgbFilterSubpassCollapseOptimization) {
Canvas canvas;

canvas.SaveLayer({
.color_filter = ColorFilter::MakeLinearToSrgb(),
});

canvas.Translate({500, 300, 0});
canvas.Rotate(Radians(2 * kPi / 3));
canvas.DrawRect(Rect::MakeXYWH(100, 100, 200, 200), {.color = Color::Blue()});

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, SrgbToLinearFilterSubpassCollapseOptimization) {
Canvas canvas;

canvas.SaveLayer({
.color_filter = ColorFilter::MakeSrgbToLinear(),
});

canvas.Translate({500, 300, 0});
canvas.Rotate(Radians(2 * kPi / 3));
canvas.DrawRect(Rect::MakeXYWH(100, 100, 200, 200), {.color = Color::Blue()});

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, TranslucentSaveLayerDrawsCorrectly) {
Canvas canvas;

canvas.DrawRect(Rect::MakeXYWH(100, 100, 300, 300), {.color = Color::Blue()});

canvas.SaveLayer({.color = Color::Black().WithAlpha(0.5)});
canvas.DrawRect(Rect::MakeXYWH(100, 500, 300, 300), {.color = Color::Blue()});
canvas.Restore();

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, TranslucentSaveLayerWithBlendColorFilterDrawsCorrectly) {
Canvas canvas;

canvas.DrawRect(Rect::MakeXYWH(100, 100, 300, 300), {.color = Color::Blue()});

canvas.SaveLayer({
.color = Color::Black().WithAlpha(0.5),
.color_filter =
ColorFilter::MakeBlend(BlendMode::kDestinationOver, Color::Red()),
});
canvas.DrawRect(Rect::MakeXYWH(100, 500, 300, 300), {.color = Color::Blue()});
canvas.Restore();

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, TranslucentSaveLayerWithBlendImageFilterDrawsCorrectly) {
Canvas canvas;

canvas.DrawRect(Rect::MakeXYWH(100, 100, 300, 300), {.color = Color::Blue()});

canvas.SaveLayer({
.color = Color::Black().WithAlpha(0.5),
.image_filter = ImageFilter::MakeFromColorFilter(
*ColorFilter::MakeBlend(BlendMode::kDestinationOver, Color::Red())),
});

canvas.DrawRect(Rect::MakeXYWH(100, 500, 300, 300), {.color = Color::Blue()});
canvas.Restore();

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, TranslucentSaveLayerWithColorAndImageFilterDrawsCorrectly) {
Canvas canvas;

canvas.DrawRect(Rect::MakeXYWH(100, 100, 300, 300), {.color = Color::Blue()});

canvas.SaveLayer({
.color = Color::Black().WithAlpha(0.5),
.color_filter =
ColorFilter::MakeBlend(BlendMode::kDestinationOver, Color::Red()),
});

canvas.DrawRect(Rect::MakeXYWH(100, 500, 300, 300), {.color = Color::Blue()});
canvas.Restore();

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, ImageFilteredSaveLayerWithUnboundedContents) {
Canvas canvas;
canvas.Scale(GetContentScale());
Expand Down Expand Up @@ -1984,144 +1847,6 @@ TEST_P(AiksTest, ImageFilteredSaveLayerWithUnboundedContents) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, ImageFilteredUnboundedSaveLayerWithUnboundedContents) {
Canvas canvas;
canvas.Scale(GetContentScale());

auto blur_filter = ImageFilter::MakeBlur(Sigma{10.0}, Sigma{10.0},
FilterContents::BlurStyle::kNormal,
Entity::TileMode::kDecal);

canvas.SaveLayer({.image_filter = blur_filter}, std::nullopt);
{
// DrawPaint to verify correct behavior when the contents are unbounded.
canvas.DrawPaint({.color = Color::Yellow()});

// Contrasting rectangle to see interior blurring
canvas.DrawRect(Rect::MakeLTRB(125, 125, 175, 175),
{.color = Color::Blue()});
}
canvas.Restore();

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, TranslucentSaveLayerImageDrawsCorrectly) {
Canvas canvas;

auto image = std::make_shared<Image>(CreateTextureForFixture("airplane.jpg"));
canvas.DrawImage(image, {100, 100}, {});

canvas.SaveLayer({.color = Color::Black().WithAlpha(0.5)});
canvas.DrawImage(image, {100, 500}, {});
canvas.Restore();

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, TranslucentSaveLayerWithColorMatrixColorFilterDrawsCorrectly) {
Canvas canvas;

auto image = std::make_shared<Image>(CreateTextureForFixture("airplane.jpg"));
canvas.DrawImage(image, {100, 100}, {});

canvas.SaveLayer({
.color = Color::Black().WithAlpha(0.5),
.color_filter = ColorFilter::MakeMatrix({.array =
{
1, 0, 0, 0, 0, //
0, 1, 0, 0, 0, //
0, 0, 1, 0, 0, //
0, 0, 0, 2, 0 //
}}),
});
canvas.DrawImage(image, {100, 500}, {});
canvas.Restore();

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, TranslucentSaveLayerWithColorMatrixImageFilterDrawsCorrectly) {
Canvas canvas;

auto image = std::make_shared<Image>(CreateTextureForFixture("airplane.jpg"));
canvas.DrawImage(image, {100, 100}, {});

canvas.SaveLayer({
.color = Color::Black().WithAlpha(0.5),
.image_filter = ImageFilter::MakeFromColorFilter(
*ColorFilter::MakeMatrix({.array =
{
1, 0, 0, 0, 0, //
0, 1, 0, 0, 0, //
0, 0, 1, 0, 0, //
0, 0, 0, 2, 0 //
}})),
});
canvas.DrawImage(image, {100, 500}, {});
canvas.Restore();

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest,
TranslucentSaveLayerWithColorFilterAndImageFilterDrawsCorrectly) {
Canvas canvas;

auto image = std::make_shared<Image>(CreateTextureForFixture("airplane.jpg"));
canvas.DrawImage(image, {100, 100}, {});

canvas.SaveLayer({
.color = Color::Black().WithAlpha(0.5),
.image_filter = ImageFilter::MakeFromColorFilter(
*ColorFilter::MakeMatrix({.array =
{
1, 0, 0, 0, 0, //
0, 1, 0, 0, 0, //
0, 0.2, 1, 0, 0, //
0, 0, 0, 0.5, 0 //
}})),
.color_filter =
ColorFilter::MakeBlend(BlendMode::kModulate, Color::Green()),
});
canvas.DrawImage(image, {100, 500}, {});
canvas.Restore();

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, TranslucentSaveLayerWithAdvancedBlendModeDrawsCorrectly) {
Canvas canvas;
canvas.DrawRect(Rect::MakeXYWH(0, 0, 400, 400), {.color = Color::Red()});
canvas.SaveLayer({
.color = Color::Black().WithAlpha(0.5),
.blend_mode = BlendMode::kLighten,
});
canvas.DrawCircle({200, 200}, 100, {.color = Color::Green()});
canvas.Restore();
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

/// This is a regression check for https://github.com/flutter/engine/pull/41129
/// The entire screen is green if successful. If failing, no frames will render,
/// or the entire screen will be transparent black.
TEST_P(AiksTest, CanRenderTinyOverlappingSubpasses) {
Canvas canvas;
canvas.DrawPaint({.color = Color::Red()});

// Draw two overlapping subpixel circles.
canvas.SaveLayer({});
canvas.DrawCircle({100, 100}, 0.1, {.color = Color::Yellow()});
canvas.Restore();
canvas.SaveLayer({});
canvas.DrawCircle({100, 100}, 0.1, {.color = Color::Yellow()});
canvas.Restore();

canvas.DrawPaint({.color = Color::Green()});

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, OpaqueEntitiesGetCoercedToSource) {
Canvas canvas;
canvas.Scale(Vector2(1.618, 1.618));
Expand Down Expand Up @@ -2151,20 +1876,6 @@ TEST_P(AiksTest, OpaqueEntitiesGetCoercedToSource) {
ASSERT_EQ(entity[0].GetBlendMode(), BlendMode::kSource);
}

TEST_P(AiksTest, CanRenderDestructiveSaveLayer) {
Canvas canvas;

canvas.DrawPaint({.color = Color::Red()});
// Draw an empty savelayer with a destructive blend mode, which will replace
// the entire red screen with fully transparent black, except for the green
// circle drawn within the layer.
canvas.SaveLayer({.blend_mode = BlendMode::kSource});
canvas.DrawCircle({300, 300}, 100, {.color = Color::Green()});
canvas.Restore();

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

// Regression test for https://github.com/flutter/flutter/issues/126701 .
TEST_P(AiksTest, CanRenderClippedRuntimeEffects) {
auto runtime_stages =
Expand Down Expand Up @@ -2228,66 +1939,6 @@ TEST_P(AiksTest, DrawPaintTransformsBounds) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, CanDrawPoints) {
std::vector<Point> points = {
{0, 0}, //
{100, 100}, //
{100, 0}, //
{0, 100}, //
{0, 0}, //
{48, 48}, //
{52, 52}, //
};
std::vector<PointStyle> caps = {
PointStyle::kRound,
PointStyle::kSquare,
};
Paint paint;
paint.color = Color::Yellow().WithAlpha(0.5);

Paint background;
background.color = Color::Black();

Canvas canvas;
canvas.DrawPaint(background);
canvas.Translate({200, 200});
canvas.DrawPoints(points, 10, paint, PointStyle::kRound);
canvas.Translate({150, 0});
canvas.DrawPoints(points, 10, paint, PointStyle::kSquare);

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, CanDrawPointsWithTextureMap) {
auto texture = CreateTextureForFixture("table_mountain_nx.png",
/*enable_mipmapping=*/true);

std::vector<Point> points = {
{0, 0}, //
{100, 100}, //
{100, 0}, //
{0, 100}, //
{0, 0}, //
{48, 48}, //
{52, 52}, //
};
std::vector<PointStyle> caps = {
PointStyle::kRound,
PointStyle::kSquare,
};
Paint paint;
paint.color_source = ColorSource::MakeImage(texture, Entity::TileMode::kClamp,
Entity::TileMode::kClamp, {}, {});

Canvas canvas;
canvas.Translate({200, 200});
canvas.DrawPoints(points, 100, paint, PointStyle::kRound);
canvas.Translate({150, 0});
canvas.DrawPoints(points, 100, paint, PointStyle::kSquare);

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

// This currently renders solid blue, as the support for text color sources was
// moved into DLDispatching. Path data requires the SkTextBlobs which are not
// used in impeller::TextFrames.
Expand Down
Loading