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

Commit 76630c65 authored by Chia-I Wu's avatar Chia-I Wu
Browse files

graphics: fix readback buffer tests

Make readback buffer support optional.  Fix incorrect use of
setReadbackBuffer and getReadbackBufferFence.

Bug:  80030364
Test: VTS
Change-Id: I278a031c3c086ac38c460b7076a2952db57a91a4
parent a1efbcfc
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -44,6 +44,10 @@ std::unique_ptr<ComposerClient> Composer::createClient() {
    return client;
}

sp<IComposerClient> ComposerClient::getRaw() const {
    return mClient;
}

std::vector<IComposerClient::PerFrameMetadataKey> ComposerClient::getPerFrameMetadataKeys(
    Display display) {
    std::vector<IComposerClient::PerFrameMetadataKey> keys;
+2 −0
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ class ComposerClient : public V2_1::vts::ComposerClient {
    explicit ComposerClient(const sp<IComposerClient>& client)
        : V2_1::vts::ComposerClient(client), mClient(client) {}

    sp<IComposerClient> getRaw() const;

    void execute(V2_1::vts::TestCommandReader* reader, CommandWriterBase* writer);

    std::vector<IComposerClient::PerFrameMetadataKey> getPerFrameMetadataKeys(Display display);
+40 −8
Original line number Diff line number Diff line
@@ -76,6 +76,11 @@ class GraphicsComposerHidlTest : public ::testing::VtsHalHidlTargetTestBase {
        // explicitly disable vsync
        mComposerClient->setVsyncEnabled(mPrimaryDisplay, false);
        mComposerCallback->setVsyncAllowed(false);

        mComposerClient->getRaw()->getReadbackBufferAttributes(
            mPrimaryDisplay, [&](const auto& tmpError, const auto&, const auto&) {
                mHasReadbackBuffer = tmpError == Error::NONE;
            });
    }

    void TearDown() override {
@@ -94,6 +99,7 @@ class GraphicsComposerHidlTest : public ::testing::VtsHalHidlTargetTestBase {
    sp<V2_1::vts::GraphicsComposerCallback> mComposerCallback;
    // the first display and is assumed never to be removed
    Display mPrimaryDisplay;
    bool mHasReadbackBuffer;

   private:
    Display waitForFirstDisplay() {
@@ -255,18 +261,44 @@ TEST_F(GraphicsComposerHidlTest, setPowerMode_2_2) {
}

TEST_F(GraphicsComposerHidlTest, setReadbackBuffer) {
    mComposerClient->setReadbackBuffer(mPrimaryDisplay, nullptr, -1);
}

TEST_F(GraphicsComposerHidlTest, getReadbackBufferFence) {
    int32_t fence;
    mComposerClient->getReadbackBufferFence(mPrimaryDisplay, &fence);
    if (!mHasReadbackBuffer) {
        return;
    }

TEST_F(GraphicsComposerHidlTest, getReadbackBufferAttributes) {
    PixelFormat pixelFormat;
    Dataspace dataspace;
    mComposerClient->getReadbackBufferAttributes(mPrimaryDisplay, &pixelFormat, &dataspace);
    ASSERT_LT(static_cast<PixelFormat>(0), pixelFormat);
    ASSERT_NE(Dataspace::UNKNOWN, dataspace);

    IMapper::BufferDescriptorInfo info{};
    Config config = mComposerClient->getActiveConfig(mPrimaryDisplay);
    info.width = mComposerClient->getDisplayAttribute(mPrimaryDisplay, config,
                                                      IComposerClient::Attribute::WIDTH);
    info.height = mComposerClient->getDisplayAttribute(mPrimaryDisplay, config,
                                                       IComposerClient::Attribute::HEIGHT);
    info.layerCount = 1;
    info.format = pixelFormat;
    // BufferUsage::COMPOSER_OUTPUT is missing
    info.usage = static_cast<uint64_t>(BufferUsage::COMPOSER_OVERLAY | BufferUsage::CPU_READ_OFTEN);

    std::unique_ptr<Gralloc> gralloc;
    const native_handle_t* buffer;
    ASSERT_NO_FATAL_FAILURE(gralloc = std::make_unique<Gralloc>());
    ASSERT_NO_FATAL_FAILURE(buffer = gralloc->allocate(info));

    mComposerClient->setReadbackBuffer(mPrimaryDisplay, buffer, -1);
}

TEST_F(GraphicsComposerHidlTest, getReadbackBufferFenceInactive) {
    if (!mHasReadbackBuffer) {
        return;
    }

    mComposerClient->getRaw()->getReadbackBufferFence(
        mPrimaryDisplay, [&](const auto& tmpError, const auto&) {
            ASSERT_EQ(Error::UNSUPPORTED, tmpError) << "readback buffer is active";
        });
}

/**