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

Commit a6a2af85 authored by Marissa Wall's avatar Marissa Wall
Browse files

gralloc: clarify lock access region

Update lock to clarify that if the access region is outside the
bounds of the buffer, the lock call should fail.

Bug: 141631415
Test: VtsHalGraphicsMapperV4_0TargetTest

Change-Id: Ic9ccac9361c8cafc59660b107686d2cbb54faf2d
parent c325670c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -219,7 +219,8 @@ interface IMapper {
     *     - `BAD_BUFFER` if the buffer is invalid or is incompatible with this
     *       function.
     *     - `BAD_VALUE` if @p cpuUsage is 0, contains non-CPU usage flags, or
     *       is incompatible with the buffer.
     *       is incompatible with the buffer. Also if the @p accessRegion is
     *       outside the bounds of the buffer or the accessRegion is invalid.
     *     - `NO_RESOURCES` if the buffer cannot be locked at this time. Note
     *       that locking may succeed at a later time.
     * @return data CPU-accessible pointer to the buffer data.
+43 −0
Original line number Diff line number Diff line
@@ -403,6 +403,49 @@ TEST_F(GraphicsMapperHidlTest, LockYCbCrBasic) {
    }
}

/**
 * Test IMapper::unlock with bad access region
 */
TEST_F(GraphicsMapperHidlTest, LockBadAccessRegion) {
    const auto& info = mDummyDescriptorInfo;

    const native_handle_t* bufferHandle;
    ASSERT_NO_FATAL_FAILURE(bufferHandle = mGralloc->allocate(info, true));

    const IMapper::Rect accessRegion{0, 0, static_cast<int32_t>(info.width * 2),
                                     static_cast<int32_t>(info.height * 2)};
    int acquireFence = -1;

    NATIVE_HANDLE_DECLARE_STORAGE(acquireFenceStorage, 1, 0);
    hidl_handle acquireFenceHandle;
    if (acquireFence >= 0) {
        auto h = native_handle_init(acquireFenceStorage, 1, 0);
        h->data[0] = acquireFence;
        acquireFenceHandle = h;
    }

    auto buffer = const_cast<native_handle_t*>(bufferHandle);
    mGralloc->getMapper()->lock(buffer, info.usage, accessRegion, acquireFenceHandle,
                                [&](const auto& tmpError, const auto& /*tmpData*/,
                                    int32_t /*tmpBytesPerPixel*/, int32_t /*tmpBytesPerStride*/) {
                                    EXPECT_EQ(Error::BAD_VALUE, tmpError)
                                            << "locking with a bad access region should fail";
                                });

    if (::testing::Test::HasFailure()) {
        if (acquireFence >= 0) {
            close(acquireFence);
        }

        int releaseFence = -1;
        ASSERT_NO_FATAL_FAILURE(releaseFence = mGralloc->unlock(bufferHandle));

        if (releaseFence >= 0) {
            close(releaseFence);
        }
    }
}

/**
 * Test IMapper::unlock with invalid buffers.
 */