[Impeller] fix UV and color blending. (flutter/engine#42293)

Fixes https://github.com/flutter/flutter/issues/127486

Combinations of UV mapping and color blending would cause us to double apply the UV mapping which rendered either nothing or garbage.

Before:

![image](https://github.com/flutter/engine/assets/8975114/84cfbd68-9025-42d2-98be-72af7e26d8be)

After:

![image](https://github.com/flutter/engine/assets/8975114/4a0d5a11-d2a0-48a4-885e-32310d62a6c7)
This commit is contained in:
Jonah Williams
2023-05-24 15:57:42 -07:00
committed by GitHub
parent a98191b4c0
commit 32d648ec7f
3 changed files with 37 additions and 9 deletions

View File

@@ -598,8 +598,7 @@ void Canvas::DrawVertices(const std::shared_ptr<VerticesGeometry>& vertices,
std::shared_ptr<Contents> src_contents =
src_paint.CreateContentsForGeometry(vertices);
if (vertices->HasTextureCoordinates() &&
paint.color_source.GetType() != ColorSource::Type::kImage) {
if (vertices->HasTextureCoordinates()) {
// If the color source has an intrinsic size, then we use that to
// create the src contents as a simplification. Otherwise we use
// the extent of the texture coordinates to determine how large

View File

@@ -1370,6 +1370,35 @@ TEST_P(DisplayListTest, DrawVerticesImageSourceWithTextureCoordinates) {
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}
TEST_P(DisplayListTest,
DrawVerticesImageSourceWithTextureCoordinatesAndColorBlending) {
auto texture = CreateTextureForFixture("embarcadero.jpg");
auto dl_image = DlImageImpeller::Make(texture);
std::vector<SkPoint> positions = {SkPoint::Make(100, 300),
SkPoint::Make(200, 100),
SkPoint::Make(300, 300)};
std::vector<flutter::DlColor> colors = {flutter::DlColor::kWhite(),
flutter::DlColor::kGreen(),
flutter::DlColor::kWhite()};
std::vector<SkPoint> texture_coordinates = {
SkPoint::Make(0, 0), SkPoint::Make(100, 200), SkPoint::Make(200, 100)};
auto vertices = flutter::DlVertices::Make(
flutter::DlVertexMode::kTriangles, 3, positions.data(),
texture_coordinates.data(), colors.data());
flutter::DisplayListBuilder builder;
flutter::DlPaint paint;
auto image_source = flutter::DlImageColorSource(
dl_image, flutter::DlTileMode::kRepeat, flutter::DlTileMode::kRepeat);
paint.setColorSource(&image_source);
builder.DrawVertices(vertices, flutter::DlBlendMode::kModulate, paint);
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}
TEST_P(DisplayListTest, DrawVerticesSolidColorTrianglesWithIndices) {
std::vector<SkPoint> positions = {
SkPoint::Make(100, 300), SkPoint::Make(200, 100), SkPoint::Make(300, 300),

View File

@@ -107,13 +107,13 @@ bool VerticesUVContents::Render(const ContentContext& renderer,
auto src_contents = parent_.GetSourceContents();
auto snapshot = src_contents->RenderToSnapshot(
renderer, // renderer
entity, // entity
Rect::MakeSize(pass.GetRenderTargetSize()), // coverage_limit
std::nullopt, // sampler_descriptor
true, // msaa_enabled
"VerticesUVContents Snapshot"); // label
auto snapshot =
src_contents->RenderToSnapshot(renderer, // renderer
entity, // entity
std::nullopt, // coverage_limit
std::nullopt, // sampler_descriptor
true, // msaa_enabled
"VerticesUVContents Snapshot"); // label
if (!snapshot.has_value()) {
return false;
}