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

Commit a1d0e31f authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Rounded corner child clipping tests

Fixed original rounded corners test - I assumed that a Rect was expressed in
Rect(x, y, w, h) instead of Rect(l, t, r, b) - and introduced new test that
verifies if child layers are clipped correctly.

Bug: 118461793
Bug: 111514493
Test: /data/nativetest64/SurfaceFlinger_test/SurfaceFlinger_test
Change-Id: I2dfde220e0d56c2aa0d48ae7b4006a97e04039d2
parent d653633b
Loading
Loading
Loading
Loading
+35 −5
Original line number Diff line number Diff line
@@ -1229,7 +1229,7 @@ TEST_P(LayerTypeTransactionTest, SetCornerRadius) {
    sp<SurfaceControl> layer;
    const uint8_t size = 64;
    const uint8_t testArea = 4;
    const float cornerRadius = 16.0f;
    const float cornerRadius = 20.0f;
    ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", size, size));
    ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, size, size));

@@ -1237,13 +1237,43 @@ TEST_P(LayerTypeTransactionTest, SetCornerRadius) {
            .setCornerRadius(layer, cornerRadius)
            .apply();
    {
        const uint8_t bottom = size - 1;
        const uint8_t right = size - 1;
        auto shot = screenshot();
        // Transparent corners
        shot->expectColor(Rect(0, 0, testArea, testArea), Color::BLACK);
        shot->expectColor(Rect(0, size - testArea, testArea, testArea), Color::BLACK);
        shot->expectColor(Rect(size - testArea, 0, testArea, testArea), Color::BLACK);
        shot->expectColor(Rect(size - testArea, size - testArea, testArea, testArea),
            Color::BLACK);
        shot->expectColor(Rect(size - testArea, 0, right, testArea), Color::BLACK);
        shot->expectColor(Rect(0, bottom - testArea, testArea, bottom), Color::BLACK);
        shot->expectColor(Rect(size - testArea, bottom - testArea, right, bottom), Color::BLACK);
    }
}

TEST_P(LayerTypeTransactionTest, SetCornerRadiusChildCrop) {
    sp<SurfaceControl> parent;
    sp<SurfaceControl> child;
    const uint8_t size = 64;
    const uint8_t testArea = 4;
    const float cornerRadius = 20.0f;
    ASSERT_NO_FATAL_FAILURE(parent = createLayer("parent", size, size));
    ASSERT_NO_FATAL_FAILURE(fillLayerColor(parent, Color::RED, size, size));
    ASSERT_NO_FATAL_FAILURE(child = createLayer("child", size, size / 2));
    ASSERT_NO_FATAL_FAILURE(fillLayerColor(child, Color::GREEN, size, size / 2));

    Transaction()
            .setCornerRadius(parent, cornerRadius)
            .reparent(child, parent->getHandle())
            .setPosition(child, 0, size / 2)
            .apply();
    {
        const uint8_t bottom = size - 1;
        const uint8_t right = size - 1;
        auto shot = screenshot();
        // Top edge of child should not have rounded corners because it's translated in the parent
        shot->expectColor(Rect(0, size / 2, right, static_cast<int>(bottom - cornerRadius)),
            Color::GREEN);
        // But bottom edges should have been clipped according to parent bounds
        shot->expectColor(Rect(0, bottom - testArea, testArea, bottom), Color::BLACK);
        shot->expectColor(Rect(right - testArea, bottom - testArea, right, bottom), Color::BLACK);
    }
}