Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45a829ca authored by Arpit Singh's avatar Arpit Singh
Browse files

Non-unity scale should change transform type

Transform logic has some optimisation for identity transform. At present
applying a non-unity scale doesn't change the transform type which
results in the incorrect transform logic.

This CL forces the type calculation in transform if a non-unity scale is
applied.

Test: atest Transform_test
Bug: 245989146
Flag: EXEMPT BUG_FIX
Change-Id: I261a03067ad1ea06d7875acb29a7f3e53ff44b8e
parent 7c5fb4b2
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -96,6 +96,11 @@ Transform Transform::operator * (float value) const {
            R[i][j] = M[i][j] * value;
        }
    }
    if (value != 1.0) {
        // If a non-unity scale is applied, the type might change.
        // Mark it as UNKNOWN to force re-computation.
        r.mType = UNKNOWN_TYPE;
    }
    r.type();
    return r;
}
+11 −0
Original line number Diff line number Diff line
@@ -46,4 +46,15 @@ TEST(TransformTest, inverseRotation_hasCorrectType) {
    testRotationFlagsForInverse(Transform::FLIP_V, Transform::FLIP_V, false);
}

TEST(TransformTest, scaling_hasCorrectType) {
    const Transform identityTransform = Transform();
    EXPECT_TRUE(identityTransform.getType() == Transform::IDENTITY);

    // An unity scale should keep transform unchanged.
    EXPECT_TRUE(identityTransform == (identityTransform * 1.0));

    // A non-unity scale should result in SCALE transform.
    EXPECT_TRUE((identityTransform * 2.0).getType() == Transform::SCALE);
}

} // namespace android::ui