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

Commit 92bf548f authored by Valerie Hau's avatar Valerie Hau
Browse files

Add rounded corners to BLAST layers

BLAST layers have no concept of crop, which is used
to calculate rounded corners.  Instead, use display frame
to calculate rounded corners for BLAST layers

Bug: 147109621
Test: build, boot, SurfaceFlinger_test
Change-Id: Iea453313625f9352e5f0131bb7bfa9bd11151045
parent 90e9861f
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -742,6 +742,33 @@ sp<Layer> BufferStateLayer::createClone() {
    layer->setInitialValuesForClone(this);
    return layer;
}

Layer::RoundedCornerState BufferStateLayer::getRoundedCornerState() const {
    const auto& p = mDrawingParent.promote();
    if (p != nullptr) {
        RoundedCornerState parentState = p->getRoundedCornerState();
        if (parentState.radius > 0) {
            ui::Transform t = getActiveTransform(getDrawingState());
            t = t.inverse();
            parentState.cropRect = t.transform(parentState.cropRect);
            // The rounded corners shader only accepts 1 corner radius for performance reasons,
            // but a transform matrix can define horizontal and vertical scales.
            // Let's take the average between both of them and pass into the shader, practically we
            // never do this type of transformation on windows anyway.
            parentState.radius *= (t[0][0] + t[1][1]) / 2.0f;
            return parentState;
        }
    }
    const float radius = getDrawingState().cornerRadius;
    const State& s(getDrawingState());
    if (radius <= 0 || (getActiveWidth(s) == UINT32_MAX && getActiveHeight(s) == UINT32_MAX))
        return RoundedCornerState();
    return RoundedCornerState(FloatRect(static_cast<float>(s.active.transform.tx()),
                                        static_cast<float>(s.active.transform.ty()),
                                        static_cast<float>(s.active.transform.tx() + s.active.w),
                                        static_cast<float>(s.active.transform.ty() + s.active.h)),
                              radius);
}
} // namespace android

// TODO(b/129481165): remove the #pragma below and fix conversion issues
+1 −0
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ public:

    Rect getBufferSize(const State& s) const override;
    FloatRect computeSourceBounds(const FloatRect& parentBounds) const override;
    Layer::RoundedCornerState getRoundedCornerState() const override;

    // -----------------------------------------------------------------------

+1 −1
Original line number Diff line number Diff line
@@ -710,7 +710,7 @@ public:
    // corner definition and converting it into current layer's coordinates.
    // As of now, only 1 corner radius per display list is supported. Subsequent ones will be
    // ignored.
    RoundedCornerState getRoundedCornerState() const;
    virtual RoundedCornerState getRoundedCornerState() const;

    renderengine::ShadowSettings getShadowSettings(const Rect& viewport) const;

+26 −10
Original line number Diff line number Diff line
@@ -199,10 +199,17 @@ TEST_P(LayerTypeAndRenderTypeTransactionTest, SetCornerRadius) {
    ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", size, size));
    ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, size, size));

    if (mLayerType == ISurfaceComposerClient::eFXSurfaceBufferQueue) {
        Transaction()
                .setCornerRadius(layer, cornerRadius)
                .setCrop_legacy(layer, Rect(0, 0, size, size))
                .apply();
    } else {
        Transaction()
                .setCornerRadius(layer, cornerRadius)
                .setFrame(layer, Rect(0, 0, size, size))
                .apply();
    }
    {
        const uint8_t bottom = size - 1;
        const uint8_t right = size - 1;
@@ -226,12 +233,21 @@ TEST_P(LayerTypeAndRenderTypeTransactionTest, SetCornerRadiusChildCrop) {
    ASSERT_NO_FATAL_FAILURE(child = createLayer("child", size, size / 2));
    ASSERT_NO_FATAL_FAILURE(fillLayerColor(child, Color::GREEN, size, size / 2));

    if (mLayerType == ISurfaceComposerClient::eFXSurfaceBufferQueue) {
        Transaction()
                .setCornerRadius(parent, cornerRadius)
                .setCrop_legacy(parent, Rect(0, 0, size, size))
                .reparent(child, parent->getHandle())
                .setPosition(child, 0, size / 2)
                .apply();
    } else {
        Transaction()
                .setCornerRadius(parent, cornerRadius)
                .setFrame(parent, Rect(0, 0, size, size))
                .reparent(child, parent->getHandle())
                .setFrame(child, Rect(0, size / 2, size, size))
                .apply();
    }
    {
        const uint8_t bottom = size - 1;
        const uint8_t right = size - 1;