Skip to content

Commit 79c13e5

Browse files
author
jonahwilliams
committed
some texture coordinates work
1 parent 2a27640 commit 79c13e5

5 files changed

Lines changed: 52 additions & 9 deletions

File tree

impeller/aiks/canvas.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,11 @@ void Canvas::DrawVertices(std::unique_ptr<VerticesGeometry> vertices,
398398
return;
399399
}
400400
auto contents = std::make_shared<VerticesContents>();
401-
contents->SetSrcContents(paint.CreateContentsForGeometry(
401+
auto opaque_paint = paint;
402+
opaque_paint.color = opaque_paint.color.WithAlpha(1.0);
403+
contents->SetSrcContents(opaque_paint.CreateContentsForGeometry(
402404
Geometry::MakeRect(Rect::MakeSize(rect.value().size))));
403-
contents->SetColor(paint.color);
405+
contents->SetAlpha(paint.color.alpha);
404406
contents->SetBlendMode(blend_mode);
405407
contents->SetGeometry(std::move(vertices));
406408
entity.SetContents(paint.WithFilters(contents));

impeller/display_list/display_list_unittests.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,38 @@ TEST_P(DisplayListTest, DrawVerticesLinearGradientWithoutIndices) {
11111111
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
11121112
}
11131113

1114+
TEST_P(DisplayListTest, DrawVerticesLinearGradientWithTextureCoordinates) {
1115+
std::vector<SkPoint> positions = {SkPoint::Make(100, 300),
1116+
SkPoint::Make(200, 100),
1117+
SkPoint::Make(300, 300)};
1118+
std::vector<SkPoint> texture_coordinates = {SkPoint::Make(1.0, 1.0),
1119+
SkPoint::Make(0.0, 1.0),
1120+
SkPoint::Make(0.0, 0.0)};
1121+
std::vector<flutter::DlColor> colors = {flutter::DlColor::kRed(),
1122+
flutter::DlColor::kGreen(),
1123+
flutter::DlColor::kBlue()};
1124+
1125+
auto vertices = flutter::DlVertices::Make(
1126+
flutter::DlVertexMode::kTriangles, 3, positions.data(),
1127+
texture_coordinates.data(), colors.data());
1128+
1129+
std::vector<flutter::DlColor> gradient_colors = {flutter::DlColor::kBlue(),
1130+
flutter::DlColor::kRed()};
1131+
const float stops[2] = {0.0, 1.0};
1132+
1133+
auto linear = flutter::DlColorSource::MakeLinear(
1134+
{100.0, 100.0}, {300.0, 300.0}, 2, gradient_colors.data(), stops,
1135+
flutter::DlTileMode::kRepeat);
1136+
1137+
flutter::DisplayListBuilder builder;
1138+
flutter::DlPaint paint;
1139+
1140+
paint.setColorSource(linear);
1141+
builder.drawVertices(vertices, flutter::DlBlendMode::kSrcOver, paint);
1142+
1143+
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1144+
}
1145+
11141146
TEST_P(DisplayListTest, DrawVerticesSolidColorTrianglesWithIndices) {
11151147
std::vector<SkPoint> positions = {
11161148
SkPoint::Make(100, 300), SkPoint::Make(200, 100), SkPoint::Make(300, 300),

impeller/display_list/display_list_vertices_geometry.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ static Rect ToRect(const SkRect& rect) {
2121
return Rect::MakeLTRB(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2222
}
2323

24+
static Point ToPoint(const SkPoint& point) {
25+
return Point::MakeXY(point.fX, point.fY);
26+
}
27+
2428
// Fan mode isn't natively supported. Unroll into triangle mode by
2529
// manipulating the index array.
2630
//
@@ -234,16 +238,21 @@ GeometryResult DLVerticesGeometry::GetPositionUVBuffer(
234238
: normalized_indices_.data();
235239
auto* dl_vertices = vertices_->vertices();
236240
auto* dl_colors = vertices_->colors();
241+
auto* dl_tex_coords = vertices_->texture_coordinates();
237242

238243
auto coverage_rect = ToRect(vertices_->bounds());
239244
std::vector<VS::PerVertexData> vertex_data(vertex_count);
245+
240246
for (auto i = 0; i < vertex_count; i++) {
241247
auto dl_color = dl_colors[i];
242248
auto color = Color(dl_color.getRedF(), dl_color.getGreenF(),
243249
dl_color.getBlueF(), dl_color.getAlphaF());
244250
auto sk_point = dl_vertices[i];
245251
auto vertex = Point(sk_point.x(), sk_point.y());
246-
auto coverage_coords = (vertex - coverage_rect.origin) / coverage_rect.size;
252+
auto coverage_coords =
253+
(dl_tex_coords == nullptr)
254+
? (vertex - coverage_rect.origin) / coverage_rect.size
255+
: ToPoint(dl_tex_coords[i]);
247256

248257
vertex_data[i] = {
249258
.vertices = vertex,

impeller/entity/contents/vertices_contents.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ void VerticesContents::SetGeometry(std::unique_ptr<VerticesGeometry> geometry) {
2929
geometry_ = std::move(geometry);
3030
}
3131

32-
void VerticesContents::SetColor(Color color) {
33-
color_ = color;
32+
void VerticesContents::SetAlpha(Scalar alpha) {
33+
alpha_ = alpha;
3434
}
3535

3636
void VerticesContents::SetBlendMode(BlendMode blend_mode) {
@@ -184,7 +184,7 @@ bool VerticesContents::Render(const ContentContext& renderer,
184184

185185
FS::FragInfo frag_info;
186186
frag_info.src_y_coord_scale = src_texture->texture->GetYCoordScale();
187-
frag_info.alpha = color_.alpha;
187+
frag_info.alpha = alpha_;
188188

189189
cmd.stencil_reference = entity.GetStencilDepth();
190190
cmd.BindVertices(geometry_result.vertex_buffer);
@@ -222,7 +222,7 @@ bool VerticesContents::RenderDestination(const ContentContext& renderer,
222222
VS::BindVertInfo(cmd, host_buffer.EmplaceUniform(vert_info));
223223

224224
FS::FragInfo frag_info;
225-
frag_info.alpha = color_.alpha;
225+
frag_info.alpha = alpha_;
226226
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
227227

228228
return pass.AddCommand(std::move(cmd));

impeller/entity/contents/vertices_contents.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class VerticesContents final : public Contents {
2727

2828
void SetGeometry(std::unique_ptr<VerticesGeometry> geometry);
2929

30-
void SetColor(Color color);
30+
void SetAlpha(Scalar alpha);
3131

3232
void SetBlendMode(BlendMode blend_mode);
3333

@@ -46,7 +46,7 @@ class VerticesContents final : public Contents {
4646
const Entity& entity,
4747
RenderPass& pass) const;
4848

49-
Color color_;
49+
Scalar alpha_;
5050
std::shared_ptr<Contents> src_contents_;
5151
std::unique_ptr<VerticesGeometry> geometry_;
5252
BlendMode blend_mode_ = BlendMode::kSource;

0 commit comments

Comments
 (0)