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

Commit 9666ac59 authored by Vishnu Nair's avatar Vishnu Nair Committed by Automerger Merge Worker
Browse files

SurfaceFlinger: Don't render rounded corners without a valid crop am: b1845593 am: 0a13ecc9

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/16009809

Change-Id: Ic644e38cd1f480373b1b37b41b65aace28855f0d
parents 0af0e063 0a13ecc9
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -1922,8 +1922,9 @@ Layer::RoundedCornerState Layer::getRoundedCornerState() const {
    Rect layerCropRect = getCroppedBufferSize(getDrawingState());
    const float radius = getDrawingState().cornerRadius;
    RoundedCornerState layerSettings(layerCropRect.toFloatRect(), radius);
    const bool layerSettingsValid = layerSettings.radius > 0 && layerCropRect.isValid();

    if (layerSettings.radius > 0 && parentSettings.radius > 0) {
    if (layerSettingsValid && parentSettings.radius > 0) {
        // If the parent and the layer have rounded corner settings, use the parent settings if the
        // parent crop is entirely inside the layer crop.
        // This has limitations and cause rendering artifacts. See b/200300845 for correct fix.
@@ -1935,7 +1936,7 @@ Layer::RoundedCornerState Layer::getRoundedCornerState() const {
        } else {
            return layerSettings;
        }
    } else if (layerSettings.radius > 0) {
    } else if (layerSettingsValid) {
        return layerSettings;
    } else if (parentSettings.radius > 0) {
        return parentSettings;
+31 −0
Original line number Diff line number Diff line
@@ -208,6 +208,37 @@ TEST_P(LayerTypeAndRenderTypeTransactionTest, SetCornerRadius) {
    }
}

// b/200781179 - don't round a layer without a valid crop
// This behaviour should be fixed since we treat buffer layers differently than
// effect or container layers.
TEST_P(LayerTypeAndRenderTypeTransactionTest, SetCornerRadiusInvalidCrop) {
    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::GREEN, size, size));
    ASSERT_NO_FATAL_FAILURE(child = createColorLayer("child", Color::RED));

    Transaction().setCornerRadius(child, cornerRadius).reparent(child, parent).show(child).apply();
    {
        const uint8_t bottom = size - 1;
        const uint8_t right = size - 1;
        auto shot = getScreenCapture();
        std::this_thread::sleep_for(std::chrono::seconds(5));
        // Solid corners since we don't round a layer without a valid crop
        shot->expectColor(Rect(0, 0, testArea, testArea), Color::RED);
        shot->expectColor(Rect(size - testArea, 0, right, testArea), Color::RED);
        shot->expectColor(Rect(0, bottom - testArea, testArea, bottom), Color::RED);
        shot->expectColor(Rect(size - testArea, bottom - testArea, right, bottom), Color::RED);
        // Solid center
        shot->expectColor(Rect(size / 2 - testArea / 2, size / 2 - testArea / 2,
                               size / 2 + testArea / 2, size / 2 + testArea / 2),
                          Color::RED);
    }
}

TEST_P(LayerTypeAndRenderTypeTransactionTest, SetCornerRadiusRotated) {
    sp<SurfaceControl> parent;
    sp<SurfaceControl> child;