Skip to content

Commit

Permalink
Respect TextureContents/Canvas::DrawImageRect source rect (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdero authored and dnfield committed Apr 27, 2022
1 parent 26090e4 commit cb9997a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ TEST_F(AiksTest, CanRenderImage) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, DISABLED_CanRenderImageRect) {
TEST_F(AiksTest, CanRenderImageRect) {
Canvas canvas;
Paint paint;
auto image = std::make_shared<Image>(CreateTextureForFixture("kalimba.jpg"));
Expand Down
8 changes: 6 additions & 2 deletions impeller/entity/contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,15 @@ bool TextureContents::Render(const ContentContext& renderer,
const auto tess_result =
Tessellator{entity.GetPath().GetFillType()}.Tessellate(
entity.GetPath().CreatePolyline(),
[&vertex_builder, &coverage_rect](Point vtx) {
[this, &vertex_builder, &coverage_rect, &texture_size](Point vtx) {
VS::PerVertexData data;
data.vertices = vtx;
auto coverage_coords =
(vtx - coverage_rect->origin) / coverage_rect->size;
data.texture_coords =
((vtx - coverage_rect->origin) / coverage_rect->size);
(source_rect_.origin +
source_rect_.size * coverage_coords) /
texture_size;
vertex_builder.AppendVertex(data);
});
if (!tess_result) {
Expand Down

0 comments on commit cb9997a

Please sign in to comment.