Skip to content

Commit 9e33c6f

Browse files
bderodnfield
authored andcommitted
Transform clips by the entity's transform (flutter#87)
1 parent 8784ff4 commit 9e33c6f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#include <array>
56
#include "flutter/testing/testing.h"
67
#include "impeller/aiks/aiks_playground.h"
78
#include "impeller/aiks/canvas.h"
@@ -122,6 +123,26 @@ TEST_F(AiksTest, CanRenderNestedClips) {
122123
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
123124
}
124125

126+
TEST_F(AiksTest, ClipsUseCurrentTransform) {
127+
std::array<Color, 5> colors = {Color::White(), Color::Black(),
128+
Color::SkyBlue(), Color::Red(),
129+
Color::Yellow()};
130+
Canvas canvas;
131+
Paint paint;
132+
133+
canvas.Translate(Vector3(300, 300));
134+
for (int i = 0; i < 15; i++) {
135+
canvas.Translate(-Vector3(300, 300));
136+
canvas.Scale(Vector3(0.8, 0.8));
137+
canvas.Translate(Vector3(300, 300));
138+
139+
paint.color = colors[i % colors.size()];
140+
canvas.ClipPath(PathBuilder{}.AddCircle({0, 0}, 300).TakePath());
141+
canvas.DrawRect(Rect(-300, -300, 600, 600), paint);
142+
}
143+
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
144+
}
145+
125146
TEST_F(AiksTest, CanSaveLayerStandalone) {
126147
Canvas canvas;
127148

impeller/entity/contents/clip_contents.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ bool ClipContents::Render(const ContentContext& renderer,
3535
VS::FrameInfo info;
3636
// The color really doesn't matter.
3737
info.color = Color::SkyBlue();
38-
info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize());
38+
info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
39+
entity.GetTransformation();
3940

4041
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info));
4142

0 commit comments

Comments
 (0)