Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] Fix render transform is not correct. #39617

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,52 @@ TEST_P(EntityTest, CubicCurveTest) {
ASSERT_TRUE(OpenPlaygroundHere(entity));
}

TEST_P(EntityTest, CanDrawCorrectlyWithRotatedTransformation) {
auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
const char* input_axis[] = {"X", "Y", "Z"};
static int rotation_axis_index = 0;
static float rotation = 0;
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::SliderFloat("Rotation", &rotation, -kPi, kPi);
ImGui::Combo("Rotation Axis", &rotation_axis_index, input_axis,
sizeof(input_axis) / sizeof(char*));
Matrix rotation_matrix;
switch (rotation_axis_index) {
case 0:
rotation_matrix = Matrix::MakeRotationX(Radians(rotation));
break;
case 1:
rotation_matrix = Matrix::MakeRotationY(Radians(rotation));
break;
case 2:
rotation_matrix = Matrix::MakeRotationZ(Radians(rotation));
break;
default:
rotation_matrix = Matrix{};
break;
}

if (ImGui::Button("Reset")) {
rotation = 0;
}
ImGui::End();
Matrix current_transform =
Matrix::MakeScale(GetContentScale())
.MakeTranslation(
Vector3(Point(pass.GetRenderTargetSize().width / 2.0,
pass.GetRenderTargetSize().height / 2.0)));
Matrix result_transform = current_transform * rotation_matrix;
Path path =
PathBuilder{}.AddRect(Rect::MakeXYWH(-300, -400, 600, 800)).TakePath();

Entity entity;
entity.SetTransformation(result_transform);
entity.SetContents(SolidColorContents::Make(path, Color::Red()));
return entity.Render(context, pass);
};
ASSERT_TRUE(OpenPlaygroundHere(callback));
}

TEST_P(EntityTest, CubicCurveAndOverlapTest) {
// Compare with https://fiddle.skia.org/c/7a05a3e186c65a8dfb732f68020aae06
Path path =
Expand Down
4 changes: 2 additions & 2 deletions impeller/geometry/geometry_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ TEST(GeometryTest, MatrixMakeOrthographic) {
auto expect = Matrix{
0.02, 0, 0, 0, //
0, -0.01, 0, 0, //
0, 0, 1, 0, //
0, 0, 0, 0, //
-1, 1, 0.5, 1, //
};
ASSERT_MATRIX_NEAR(m, expect);
Expand All @@ -352,7 +352,7 @@ TEST(GeometryTest, MatrixMakeOrthographic) {
auto expect = Matrix{
0.005, 0, 0, 0, //
0, -0.02, 0, 0, //
0, 0, 1, 0, //
0, 0, 0, 0, //
-1, 1, 0.5, 1, //
};
ASSERT_MATRIX_NEAR(m, expect);
Expand Down
2 changes: 1 addition & 1 deletion impeller/geometry/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ struct Matrix {
// Per assumptions about NDC documented above.
const auto scale =
MakeScale({2.0f / static_cast<Scalar>(size.width),
-2.0f / static_cast<Scalar>(size.height), 1.0});
-2.0f / static_cast<Scalar>(size.height), 0.0});
const auto translate = MakeTranslation({-1.0, 1.0, 0.5});
return translate * scale;
}
Expand Down