Merge "gralloc: clarify lock access region"

This commit is contained in:
TreeHugger Robot 2019-11-07 21:42:18 +00:00 committed by Android (Google) Code Review
commit d9ea718964
2 changed files with 45 additions and 1 deletions

View file

@ -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.

View file

@ -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.
*/