[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:  After: 
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user