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

Commit 37efa199 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Recalculate Transform type after obtaining an inverse Transform"

parents 01e59a47 61b41739
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -396,6 +396,11 @@ Transform Transform::inverse() const {
        result.mMatrix[1][0] = -b*idet;
        result.mMatrix[1][1] =  a*idet;
        result.mType = mType;
        if (getOrientation() & ROT_90) {
            // Recalculate the type if there is a 90-degree rotation component, since the inverse
            // of ROT_90 is ROT_270 and vice versa.
            result.mType |= UNKNOWN_TYPE;
        }

        vec2 T(-x, -y);
        T = result.transform(T);
+49 −10
Original line number Diff line number Diff line
@@ -27,28 +27,40 @@ cc_test {
    name: "Region_test",
    shared_libs: ["libui"],
    srcs: ["Region_test.cpp"],
    cflags: ["-Wall", "-Werror"],
    cflags: [
        "-Wall",
        "-Werror",
    ],
}

cc_test {
    name: "colorspace_test",
    shared_libs: ["libui"],
    srcs: ["colorspace_test.cpp"],
    cflags: ["-Wall", "-Werror"],
    cflags: [
        "-Wall",
        "-Werror",
    ],
}

cc_test {
    name: "DisplayId_test",
    shared_libs: ["libui"],
    srcs: ["DisplayId_test.cpp"],
    cflags: ["-Wall", "-Werror"],
    cflags: [
        "-Wall",
        "-Werror",
    ],
}

cc_test {
    name: "FlattenableHelpers_test",
    shared_libs: ["libui"],
    srcs: ["FlattenableHelpers_test.cpp"],
    cflags: ["-Wall", "-Werror"],
    cflags: [
        "-Wall",
        "-Werror",
    ],
}

cc_test {
@@ -68,7 +80,10 @@ cc_test {
        "GraphicBufferAllocator_test.cpp",
        "mock/MockGrallocAllocator.cpp",
    ],
    cflags: ["-Wall", "-Werror"],
    cflags: [
        "-Wall",
        "-Werror",
    ],
}

cc_test {
@@ -83,14 +98,20 @@ cc_test {
        "libutils",
    ],
    srcs: ["GraphicBuffer_test.cpp"],
    cflags: ["-Wall", "-Werror"],
    cflags: [
        "-Wall",
        "-Werror",
    ],
}

// This test has a main method, and requires a separate binary to be built.
cc_test {
    name: "GraphicBufferOverBinder_test",
    srcs: ["GraphicBufferOverBinder_test.cpp"],
    cflags: ["-Wall", "-Werror"],
    cflags: [
        "-Wall",
        "-Werror",
    ],
    shared_libs: [
        "libbinder",
        "libgui",
@@ -105,7 +126,10 @@ cc_test {
    test_suites: ["device-tests"],
    shared_libs: ["libui"],
    srcs: ["Rect_test.cpp"],
    cflags: ["-Wall", "-Werror"],
    cflags: [
        "-Wall",
        "-Werror",
    ],
}

cc_test {
@@ -113,7 +137,10 @@ cc_test {
    test_suites: ["device-tests"],
    shared_libs: ["libui"],
    srcs: ["Size_test.cpp"],
    cflags: ["-Wall", "-Werror"],
    cflags: [
        "-Wall",
        "-Werror",
    ],
}

cc_test {
@@ -121,6 +148,18 @@ cc_test {
    shared_libs: ["libui"],
    static_libs: ["libgmock"],
    srcs: ["MockFence_test.cpp"],
    cflags: ["-Wall", "-Werror"],
    cflags: [
        "-Wall",
        "-Werror",
    ],
}

cc_test {
    name: "Transform_test",
    shared_libs: ["libui"],
    srcs: ["Transform_test.cpp"],
    cflags: [
        "-Wall",
        "-Werror",
    ],
}
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <ui/Transform.h>

#include <gtest/gtest.h>

namespace android::ui {

TEST(TransformTest, inverseRotation_hasCorrectType) {
    const auto testRotationFlagsForInverse = [](Transform::RotationFlags rotation,
                                                Transform::RotationFlags expectedInverse,
                                                bool isRotation) {
        const Transform t(rotation, 0, 0);
        EXPECT_EQ(t.getOrientation(), rotation);
        const Transform inverse = t.inverse();
        EXPECT_EQ(inverse.getOrientation(), expectedInverse);

        if (isRotation) {
            EXPECT_TRUE(t.getType() & Transform::ROTATE);
            EXPECT_TRUE(inverse.getType() & Transform::ROTATE);
        } else {
            EXPECT_FALSE(t.getType() & Transform::ROTATE);
            EXPECT_FALSE(inverse.getType() & Transform::ROTATE);
        }
    };

    testRotationFlagsForInverse(Transform::ROT_0, Transform::ROT_0, false);
    testRotationFlagsForInverse(Transform::ROT_90, Transform::ROT_270, true);
    testRotationFlagsForInverse(Transform::ROT_180, Transform::ROT_180, true);
    testRotationFlagsForInverse(Transform::ROT_270, Transform::ROT_90, true);
    testRotationFlagsForInverse(Transform::FLIP_H, Transform::FLIP_H, false);
    testRotationFlagsForInverse(Transform::FLIP_V, Transform::FLIP_V, false);
}

} // namespace android::ui