Skip to content

Commit

Permalink
[Impeller] Fix the rendering issue when the tile mode of gradient is …
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdPaleLight authored Jun 6, 2023
1 parent db999fc commit 8ba7bc8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
31 changes: 31 additions & 0 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,37 @@ TEST_P(AiksTest, CanRenderConicalGradient) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, CanRenderGradientDecalWithBackground) {
std::vector<Color> colors = {Color::MakeRGBA8(0xF4, 0x43, 0x36, 0xFF),
Color::MakeRGBA8(0xFF, 0xEB, 0x3B, 0xFF),
Color::MakeRGBA8(0x4c, 0xAF, 0x50, 0xFF),
Color::MakeRGBA8(0x21, 0x96, 0xF3, 0xFF)};
std::vector<Scalar> stops = {0.0, 1.f / 3.f, 2.f / 3.f, 1.0};

std::array<ColorSource, 3> color_sources = {
ColorSource::MakeLinearGradient({0, 0}, {100, 100}, colors, stops,
Entity::TileMode::kDecal, {}),
ColorSource::MakeRadialGradient({100, 100}, 100, colors, stops,
Entity::TileMode::kDecal, {}),
ColorSource::MakeSweepGradient({100, 100}, Degrees(45), Degrees(135),
colors, stops, Entity::TileMode::kDecal,
{}),
};

Canvas canvas;
Paint paint;
paint.color = Color::White();
canvas.DrawRect(Rect::MakeLTRB(0, 0, 605, 205), paint);
for (int i = 0; i < 3; i++) {
canvas.Save();
canvas.Translate({i * 200.0f, 0, 0});
paint.color_source = color_sources[i];
canvas.DrawRect(Rect::MakeLTRB(0, 0, 200, 200), paint);
canvas.Restore();
}
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, CanRenderDifferentShapesWithSameColorSource) {
Canvas canvas;
Paint paint;
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/linear_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void LinearGradientContents::SetTileMode(Entity::TileMode tile_mode) {
}

bool LinearGradientContents::IsOpaque() const {
if (GetOpacity() < 1) {
if (GetOpacity() < 1 || tile_mode_ == Entity::TileMode::kDecal) {
return false;
}
for (auto color : colors_) {
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/radial_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const std::vector<Scalar>& RadialGradientContents::GetStops() const {
}

bool RadialGradientContents::IsOpaque() const {
if (GetOpacity() < 1) {
if (GetOpacity() < 1 || tile_mode_ == Entity::TileMode::kDecal) {
return false;
}
for (auto color : colors_) {
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/sweep_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const std::vector<Scalar>& SweepGradientContents::GetStops() const {
}

bool SweepGradientContents::IsOpaque() const {
if (GetOpacity() < 1) {
if (GetOpacity() < 1 || tile_mode_ == Entity::TileMode::kDecal) {
return false;
}
for (auto color : colors_) {
Expand Down
3 changes: 2 additions & 1 deletion impeller/entity/contents/tiled_texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ bool TiledTextureContents::UsesEmulatedTileMode(

// |Contents|
bool TiledTextureContents::IsOpaque() const {
if (GetOpacity() < 1) {
if (GetOpacity() < 1 || x_tile_mode_ == Entity::TileMode::kDecal ||
y_tile_mode_ == Entity::TileMode::kDecal) {
return false;
}
if (color_filter_.has_value()) {
Expand Down
9 changes: 9 additions & 0 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2556,6 +2556,9 @@ TEST_P(EntityTest, LinearGradientContentsIsOpaque) {
ASSERT_TRUE(contents.IsOpaque());
contents.SetColors({Color::CornflowerBlue().WithAlpha(0.5)});
ASSERT_FALSE(contents.IsOpaque());
contents.SetColors({Color::CornflowerBlue()});
contents.SetTileMode(Entity::TileMode::kDecal);
ASSERT_FALSE(contents.IsOpaque());
}

TEST_P(EntityTest, RadialGradientContentsIsOpaque) {
Expand All @@ -2564,6 +2567,9 @@ TEST_P(EntityTest, RadialGradientContentsIsOpaque) {
ASSERT_TRUE(contents.IsOpaque());
contents.SetColors({Color::CornflowerBlue().WithAlpha(0.5)});
ASSERT_FALSE(contents.IsOpaque());
contents.SetColors({Color::CornflowerBlue()});
contents.SetTileMode(Entity::TileMode::kDecal);
ASSERT_FALSE(contents.IsOpaque());
}

TEST_P(EntityTest, SweepGradientContentsIsOpaque) {
Expand All @@ -2572,6 +2578,9 @@ TEST_P(EntityTest, SweepGradientContentsIsOpaque) {
ASSERT_TRUE(contents.IsOpaque());
contents.SetColors({Color::CornflowerBlue().WithAlpha(0.5)});
ASSERT_FALSE(contents.IsOpaque());
contents.SetColors({Color::CornflowerBlue()});
contents.SetTileMode(Entity::TileMode::kDecal);
ASSERT_FALSE(contents.IsOpaque());
}

TEST_P(EntityTest, TiledTextureContentsIsOpaque) {
Expand Down

0 comments on commit 8ba7bc8

Please sign in to comment.