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

Commit ead3931

Browse files
committed
[Impeller] Fix the rendering issue when the tile mode of gradient is set to 'decal'
1 parent 445db0d commit ead3931

File tree

6 files changed

+45
-4
lines changed

6 files changed

+45
-4
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,37 @@ TEST_P(AiksTest, CanRenderConicalGradient) {
791791
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
792792
}
793793

794+
TEST_P(AiksTest, CanRenderGradientDecalWithBackground) {
795+
std::vector<Color> colors = {Color::MakeRGBA8(0xF4, 0x43, 0x36, 0xFF),
796+
Color::MakeRGBA8(0xFF, 0xEB, 0x3B, 0xFF),
797+
Color::MakeRGBA8(0x4c, 0xAF, 0x50, 0xFF),
798+
Color::MakeRGBA8(0x21, 0x96, 0xF3, 0xFF)};
799+
std::vector<Scalar> stops = {0.0, 1.f / 3.f, 2.f / 3.f, 1.0};
800+
801+
std::array<ColorSource, 3> color_sources = {
802+
ColorSource::MakeLinearGradient({0, 0}, {100, 100}, colors, stops,
803+
Entity::TileMode::kDecal, {}),
804+
ColorSource::MakeRadialGradient({100, 100}, 100, colors, stops,
805+
Entity::TileMode::kDecal, {}),
806+
ColorSource::MakeSweepGradient({100, 100}, Degrees(45), Degrees(135),
807+
colors, stops, Entity::TileMode::kDecal,
808+
{}),
809+
};
810+
811+
Canvas canvas;
812+
Paint paint;
813+
paint.color = Color::White();
814+
canvas.DrawRect(Rect::MakeLTRB(0, 0, 605, 205), paint);
815+
for (int i = 0; i < 3; i++) {
816+
canvas.Save();
817+
canvas.Translate({i * 200.0f, 0, 0});
818+
paint.color_source = color_sources[i];
819+
canvas.DrawRect(Rect::MakeLTRB(0, 0, 200, 200), paint);
820+
canvas.Restore();
821+
}
822+
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
823+
}
824+
794825
TEST_P(AiksTest, CanRenderDifferentShapesWithSameColorSource) {
795826
Canvas canvas;
796827
Paint paint;

impeller/entity/contents/linear_gradient_contents.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void LinearGradientContents::SetTileMode(Entity::TileMode tile_mode) {
4545
}
4646

4747
bool LinearGradientContents::IsOpaque() const {
48-
if (GetOpacity() < 1) {
48+
if (GetOpacity() < 1 || tile_mode_ == Entity::TileMode::kDecal) {
4949
return false;
5050
}
5151
for (auto color : colors_) {

impeller/entity/contents/radial_gradient_contents.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const std::vector<Scalar>& RadialGradientContents::GetStops() const {
4646
}
4747

4848
bool RadialGradientContents::IsOpaque() const {
49-
if (GetOpacity() < 1) {
49+
if (GetOpacity() < 1 || tile_mode_ == Entity::TileMode::kDecal) {
5050
return false;
5151
}
5252
for (auto color : colors_) {

impeller/entity/contents/sweep_gradient_contents.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const std::vector<Scalar>& SweepGradientContents::GetStops() const {
5151
}
5252

5353
bool SweepGradientContents::IsOpaque() const {
54-
if (GetOpacity() < 1) {
54+
if (GetOpacity() < 1 || tile_mode_ == Entity::TileMode::kDecal) {
5555
return false;
5656
}
5757
for (auto color : colors_) {

impeller/entity/contents/tiled_texture_contents.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ bool TiledTextureContents::UsesEmulatedTileMode(
103103

104104
// |Contents|
105105
bool TiledTextureContents::IsOpaque() const {
106-
if (GetOpacity() < 1) {
106+
if (GetOpacity() < 1 || x_tile_mode_ == Entity::TileMode::kDecal ||
107+
y_tile_mode_ == Entity::TileMode::kDecal) {
107108
return false;
108109
}
109110
if (color_filter_.has_value()) {

impeller/entity/entity_unittests.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,6 +2556,9 @@ TEST_P(EntityTest, LinearGradientContentsIsOpaque) {
25562556
ASSERT_TRUE(contents.IsOpaque());
25572557
contents.SetColors({Color::CornflowerBlue().WithAlpha(0.5)});
25582558
ASSERT_FALSE(contents.IsOpaque());
2559+
contents.SetColors({Color::CornflowerBlue()});
2560+
contents.SetTileMode(Entity::TileMode::kDecal);
2561+
ASSERT_FALSE(contents.IsOpaque());
25592562
}
25602563

25612564
TEST_P(EntityTest, RadialGradientContentsIsOpaque) {
@@ -2564,6 +2567,9 @@ TEST_P(EntityTest, RadialGradientContentsIsOpaque) {
25642567
ASSERT_TRUE(contents.IsOpaque());
25652568
contents.SetColors({Color::CornflowerBlue().WithAlpha(0.5)});
25662569
ASSERT_FALSE(contents.IsOpaque());
2570+
contents.SetColors({Color::CornflowerBlue()});
2571+
contents.SetTileMode(Entity::TileMode::kDecal);
2572+
ASSERT_FALSE(contents.IsOpaque());
25672573
}
25682574

25692575
TEST_P(EntityTest, SweepGradientContentsIsOpaque) {
@@ -2572,6 +2578,9 @@ TEST_P(EntityTest, SweepGradientContentsIsOpaque) {
25722578
ASSERT_TRUE(contents.IsOpaque());
25732579
contents.SetColors({Color::CornflowerBlue().WithAlpha(0.5)});
25742580
ASSERT_FALSE(contents.IsOpaque());
2581+
contents.SetColors({Color::CornflowerBlue()});
2582+
contents.SetTileMode(Entity::TileMode::kDecal);
2583+
ASSERT_FALSE(contents.IsOpaque());
25752584
}
25762585

25772586
TEST_P(EntityTest, TiledTextureContentsIsOpaque) {

0 commit comments

Comments
 (0)