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

Commit b1845593 authored by Vishnu Nair's avatar Vishnu Nair
Browse files

SurfaceFlinger: Don't render rounded corners without a valid crop

A behaviour difference introduced by I6975332392756d3d96fed1d6f81245a9c7bf0a19
This will cause layers to not render if there is a corner radius
left behind.

Test: SurfaceFlinger_test
Test: repro steps in bug
Bug: 200781179
Change-Id: Ie2548fc37bb7676c10be69130d04f93e7323e79b
parent 0363ad30
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -1939,8 +1939,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.
@@ -1952,7 +1953,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;