[Impeller] Fix the rendering issue when the tile mode of gradient is set to 'decal' (flutter/engine#42591)

fix issue https://github.com/flutter/flutter/issues/128327
without patch 
![oOFhefzmN6](https://github.com/flutter/engine/assets/31977171/9d219ba8-b808-4de6-87ae-cc21e3b1411f)

with patch
![a5A81re5tD](https://github.com/flutter/engine/assets/31977171/7010b7b6-0d3b-481f-ac3b-36aeb1da1785)
This commit is contained in:
ColdPaleLight
2023-06-07 00:31:17 +08:00
committed by GitHub
parent a208719197
commit ef42a7d173
6 changed files with 45 additions and 4 deletions

View File

@@ -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;

View File

@@ -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_) {

View File

@@ -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_) {

View File

@@ -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_) {

View File

@@ -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()) {

View File

@@ -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) {
@@ -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) {
@@ -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) {