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

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

Merge "blast: fix crop and display frame"

parents fbf18cc3 290ad08a
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -204,8 +204,16 @@ bool BufferLayer::prepareClientLayer(const RenderArea& renderArea, const Region&
        }

        const Rect win{getBounds()};
        const float bufferWidth = getBufferSize(s).getWidth();
        const float bufferHeight = getBufferSize(s).getHeight();
        float bufferWidth = getBufferSize(s).getWidth();
        float bufferHeight = getBufferSize(s).getHeight();

        // BufferStateLayers can have a "buffer size" of [0, 0, -1, -1] when no display frame has
        // been set and there is no parent layer bounds. In that case, the scale is meaningless so
        // ignore them.
        if (!getBufferSize(s).isValid()) {
            bufferWidth = float(win.right) - float(win.left);
            bufferHeight = float(win.bottom) - float(win.top);
        }

        const float scaleHeight = (float(win.bottom) - float(win.top)) / bufferHeight;
        const float scaleWidth = (float(win.right) - float(win.left)) / bufferWidth;
+2 −0
Original line number Diff line number Diff line
@@ -181,6 +181,8 @@ private:
    // main thread.
    bool mBufferLatched{false}; // TODO: Use mActiveBuffer?

    // BufferStateLayers can return Rect::INVALID_RECT if the layer does not have a display frame
    // and its parent layer is not bounded
    Rect getBufferSize(const State& s) const override;

    std::shared_ptr<compositionengine::Layer> mCompositionLayer;
+15 −6
Original line number Diff line number Diff line
@@ -156,9 +156,22 @@ bool BufferStateLayer::setTransformToDisplayInverse(bool transformToDisplayInver
}

bool BufferStateLayer::setCrop(const Rect& crop) {
    if (mCurrentState.crop == crop) return false;
    Rect c = crop;
    if (c.left < 0) {
        c.left = 0;
    }
    if (c.top < 0) {
        c.top = 0;
    }
    // If the width and/or height are < 0, make it [0, 0, -1, -1] so the equality comparision below
    // treats all invalid rectangles the same.
    if (!c.isValid()) {
        c.makeInvalid();
    }

    if (mCurrentState.crop == c) return false;
    mCurrentState.sequence++;
    mCurrentState.crop = crop;
    mCurrentState.crop = c;
    mCurrentState.modified = true;
    setTransactionFlags(eTransactionNeeded);
    return true;
@@ -327,10 +340,6 @@ Rect BufferStateLayer::getBufferSize(const State& s) const {
        }
    }

    // if there is no parent layer, use the buffer's bounds as the buffer size
    if (s.buffer) {
        return s.buffer->getBounds();
    }
    return Rect::INVALID_RECT;
}

+20 −4
Original line number Diff line number Diff line
@@ -286,6 +286,14 @@ ui::Transform Layer::getTransformWithScale() const {
        return mEffectiveTransform;
    }

    // If the layer is a buffer state layer, the active width and height
    // could be infinite. In that case, return the effective transform.
    const uint32_t activeWidth = getActiveWidth(getDrawingState());
    const uint32_t activeHeight = getActiveHeight(getDrawingState());
    if (activeWidth >= UINT32_MAX && activeHeight >= UINT32_MAX) {
        return mEffectiveTransform;
    }

    int bufferWidth;
    int bufferHeight;
    if ((mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) == 0) {
@@ -295,8 +303,9 @@ ui::Transform Layer::getTransformWithScale() const {
        bufferHeight = mActiveBuffer->getWidth();
        bufferWidth = mActiveBuffer->getHeight();
    }
    float sx = getActiveWidth(getDrawingState()) / static_cast<float>(bufferWidth);
    float sy = getActiveHeight(getDrawingState()) / static_cast<float>(bufferHeight);
    float sx = activeWidth / static_cast<float>(bufferWidth);
    float sy = activeHeight / static_cast<float>(bufferHeight);

    ui::Transform extraParentScaling;
    extraParentScaling.set(sx, 0, 0, sy);
    return mEffectiveTransform * extraParentScaling;
@@ -400,6 +409,15 @@ FloatRect Layer::computeCrop(const sp<const DisplayDevice>& display) const {
    Rect activeCrop = computeInitialCrop(display);
    Rect bufferSize = getBufferSize(s);

    int32_t winWidth = bufferSize.getWidth();
    int32_t winHeight = bufferSize.getHeight();

    // The bufferSize for buffer state layers can be unbounded ([0, 0, -1, -1]) if display frame
    // hasn't been set and the parent is an unbounded layer.
    if (winWidth < 0 && winHeight < 0) {
        return crop;
    }

    // Transform the window crop to match the buffer coordinate system,
    // which means using the inverse of the current transform set on the
    // SurfaceFlingerConsumer.
@@ -419,8 +437,6 @@ FloatRect Layer::computeCrop(const sp<const DisplayDevice>& display) const {
                        ui::Transform(invTransform)).getOrientation();
    }

    int winWidth = bufferSize.getWidth();
    int winHeight = bufferSize.getHeight();
    if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
        // If the activeCrop has been rotate the ends are rotated but not
        // the space itself so when transforming ends back we can't rely on
+48 −49
Original line number Diff line number Diff line
@@ -2022,8 +2022,8 @@ TEST_P(LayerRenderTypeTransactionTest, SetCropBasic_BufferState) {

    Transaction().setCrop(layer, crop).apply();
    auto shot = getScreenCapture();
    shot->expectColor(Rect(0, 0, 32, 32), Color::RED);
    shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
    shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED);
    shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
}

TEST_P(LayerRenderTypeTransactionTest, SetCropEmpty_BufferQueue) {
@@ -2053,13 +2053,13 @@ TEST_P(LayerRenderTypeTransactionTest, SetCropEmpty_BufferState) {
    {
        SCOPED_TRACE("empty rect");
        Transaction().setCrop(layer, Rect(8, 8, 8, 8)).apply();
        getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED);
        getScreenCapture()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED);
    }

    {
        SCOPED_TRACE("negative rect");
        Transaction().setCrop(layer, Rect(8, 8, 0, 0)).apply();
        getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED);
        getScreenCapture()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED);
    }
}

@@ -2076,37 +2076,36 @@ TEST_P(LayerRenderTypeTransactionTest, SetCropOutOfBounds_BufferQueue) {

TEST_P(LayerRenderTypeTransactionTest, SetCropOutOfBounds_BufferState) {
    sp<SurfaceControl> layer;
    ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", mDisplayWidth, mDisplayHeight / 2,
                                                ISurfaceComposerClient::eFXSurfaceBufferState));
    ASSERT_NO_FATAL_FAILURE(
            layer = createLayer("test", 32, 64, ISurfaceComposerClient::eFXSurfaceBufferState));
    sp<GraphicBuffer> buffer =
            new GraphicBuffer(mDisplayWidth, mDisplayHeight / 2, PIXEL_FORMAT_RGBA_8888, 1,
            new GraphicBuffer(32, 64, PIXEL_FORMAT_RGBA_8888, 1,
                              BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
                                      BufferUsage::COMPOSER_OVERLAY,
                              "test");
    fillGraphicBufferColor(buffer, Rect(0, 0, mDisplayWidth, mDisplayHeight / 4), Color::BLUE);
    fillGraphicBufferColor(buffer, Rect(0, mDisplayHeight / 4, mDisplayWidth, mDisplayHeight / 2),
                           Color::RED);
    fillGraphicBufferColor(buffer, Rect(0, 0, 32, 16), Color::BLUE);
    fillGraphicBufferColor(buffer, Rect(0, 16, 32, 64), Color::RED);

    Transaction().setFrame(layer, Rect(0, 0, 64, 64)).apply();

    Transaction().setBuffer(layer, buffer).apply();

    // Partially out of bounds in the negative (upper left) direction
    Transaction().setCrop(layer, Rect(-128, -128, mDisplayWidth, mDisplayHeight / 4)).apply();
    Transaction().setCrop(layer, Rect(-128, -128, 32, 16)).apply();
    {
        SCOPED_TRACE("out of bounds, negative (upper left) direction");
        auto shot = getScreenCapture();
        shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight / 2), Color::BLUE);
        shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight / 2), Color::BLACK);
        shot->expectColor(Rect(0, 0, 64, 64), Color::BLUE);
        shot->expectBorder(Rect(0, 0, 64, 64), Color::BLACK);
    }

    // Partially out of bounds in the positive (lower right) direction
    Transaction()
            .setCrop(layer, Rect(0, mDisplayHeight / 4, mDisplayWidth + 1, mDisplayHeight))
            .apply();
    Transaction().setCrop(layer, Rect(0, 16, 128, 128)).apply();
    {
        SCOPED_TRACE("out of bounds, positive (lower right) direction");
        auto shot = getScreenCapture();
        shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight / 2), Color::RED);
        shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight / 2), Color::BLACK);
        shot->expectColor(Rect(0, 0, 64, 64), Color::RED);
        shot->expectBorder(Rect(0, 0, 64, 64), Color::BLACK);
    }

    // Fully out of buffer space bounds
@@ -2114,9 +2113,9 @@ TEST_P(LayerRenderTypeTransactionTest, SetCropOutOfBounds_BufferState) {
    {
        SCOPED_TRACE("Fully out of bounds");
        auto shot = getScreenCapture();
        shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight / 4), Color::BLUE);
        shot->expectColor(Rect(0, mDisplayHeight / 4, mDisplayWidth, mDisplayHeight / 2),
                          Color::RED);
        shot->expectColor(Rect(0, 0, 64, 16), Color::BLUE);
        shot->expectColor(Rect(0, 16, 64, 64), Color::RED);
        shot->expectBorder(Rect(0, 0, 64, 64), Color::BLACK);
    }
}

@@ -2293,8 +2292,8 @@ TEST_P(LayerRenderTypeTransactionTest, SetFrameDefaultParentless_BufferState) {

    // A parentless layer will default to a frame with the same size as the buffer
    auto shot = getScreenCapture();
    shot->expectColor(Rect(0, 0, 10, 10), Color::RED);
    shot->expectBorder(Rect(0, 0, 10, 10), Color::BLACK);
    shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED);
    shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
}

TEST_P(LayerRenderTypeTransactionTest, SetFrameDefaultBSParent_BufferState) {
@@ -2377,8 +2376,8 @@ TEST_P(LayerRenderTypeTransactionTest, SetBufferBasic_BufferState) {
    ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32));

    auto shot = getScreenCapture();
    shot->expectColor(Rect(0, 0, 32, 32), Color::RED);
    shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
    shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED);
    shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
}

TEST_P(LayerRenderTypeTransactionTest, SetBufferMultipleBuffers_BufferState) {
@@ -2391,8 +2390,8 @@ TEST_P(LayerRenderTypeTransactionTest, SetBufferMultipleBuffers_BufferState) {
    {
        SCOPED_TRACE("set buffer 1");
        auto shot = getScreenCapture();
        shot->expectColor(Rect(0, 0, 32, 32), Color::RED);
        shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
        shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED);
        shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
    }

    ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::BLUE, 32, 32));
@@ -2400,8 +2399,8 @@ TEST_P(LayerRenderTypeTransactionTest, SetBufferMultipleBuffers_BufferState) {
    {
        SCOPED_TRACE("set buffer 2");
        auto shot = getScreenCapture();
        shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE);
        shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
        shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLUE);
        shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
    }

    ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32));
@@ -2409,8 +2408,8 @@ TEST_P(LayerRenderTypeTransactionTest, SetBufferMultipleBuffers_BufferState) {
    {
        SCOPED_TRACE("set buffer 3");
        auto shot = getScreenCapture();
        shot->expectColor(Rect(0, 0, 32, 32), Color::RED);
        shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
        shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED);
        shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
    }
}

@@ -2492,8 +2491,8 @@ TEST_P(LayerRenderTypeTransactionTest, SetBufferCaching_BufferState) {

            Color color = colors[idx % colors.size()];
            auto shot = screenshot();
            shot->expectColor(Rect(0, 0, 32, 32), color);
            shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
            shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), color);
            shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
        }
        idx++;
    }
@@ -2528,8 +2527,8 @@ TEST_P(LayerRenderTypeTransactionTest, SetBufferCaching_LeastRecentlyUsed_Buffer

            Color color = colors[idx % colors.size()];
            auto shot = screenshot();
            shot->expectColor(Rect(0, 0, 32, 32), color);
            shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
            shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), color);
            shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
        }
        idx++;
    }
@@ -2564,8 +2563,8 @@ TEST_P(LayerRenderTypeTransactionTest, SetBufferCaching_DestroyedBuffer_BufferSt

            Color color = colors[idx % colors.size()];
            auto shot = screenshot();
            shot->expectColor(Rect(0, 0, 32, 32), color);
            shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
            shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), color);
            shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
        }
        if (idx == 0) {
            buffers[0].clear();
@@ -2663,8 +2662,8 @@ TEST_P(LayerRenderTypeTransactionTest, SetFenceBasic_BufferState) {
    std::this_thread::sleep_for(200ms);

    auto shot = getScreenCapture();
    shot->expectColor(Rect(0, 0, 32, 32), Color::RED);
    shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
    shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED);
    shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
}

TEST_P(LayerRenderTypeTransactionTest, SetFenceNull_BufferState) {
@@ -2687,8 +2686,8 @@ TEST_P(LayerRenderTypeTransactionTest, SetFenceNull_BufferState) {
            .apply();

    auto shot = getScreenCapture();
    shot->expectColor(Rect(0, 0, 32, 32), Color::RED);
    shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
    shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED);
    shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
}

TEST_P(LayerRenderTypeTransactionTest, SetDataspaceBasic_BufferState) {
@@ -2709,8 +2708,8 @@ TEST_P(LayerRenderTypeTransactionTest, SetDataspaceBasic_BufferState) {
            .apply();

    auto shot = getScreenCapture();
    shot->expectColor(Rect(0, 0, 32, 32), Color::RED);
    shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
    shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED);
    shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
}

TEST_P(LayerRenderTypeTransactionTest, SetHdrMetadataBasic_BufferState) {
@@ -2733,8 +2732,8 @@ TEST_P(LayerRenderTypeTransactionTest, SetHdrMetadataBasic_BufferState) {
            .apply();

    auto shot = getScreenCapture();
    shot->expectColor(Rect(0, 0, 32, 32), Color::RED);
    shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
    shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED);
    shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
}

TEST_P(LayerRenderTypeTransactionTest, SetSurfaceDamageRegionBasic_BufferState) {
@@ -2757,8 +2756,8 @@ TEST_P(LayerRenderTypeTransactionTest, SetSurfaceDamageRegionBasic_BufferState)
            .apply();

    auto shot = getScreenCapture();
    shot->expectColor(Rect(0, 0, 32, 32), Color::RED);
    shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
    shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED);
    shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
}

TEST_P(LayerRenderTypeTransactionTest, SetApiBasic_BufferState) {
@@ -2779,8 +2778,8 @@ TEST_P(LayerRenderTypeTransactionTest, SetApiBasic_BufferState) {
            .apply();

    auto shot = getScreenCapture();
    shot->expectColor(Rect(0, 0, 32, 32), Color::RED);
    shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
    shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED);
    shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
}

TEST_F(LayerTransactionTest, SetSidebandStreamNull_BufferState) {