summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorMarissa Wall <marissaw@google.com>2018-12-30 12:37:18 -0800
committerMarissa Wall <marissaw@google.com>2019-01-22 22:07:10 +0000
commit69292faf0ba99b93ba8a6b582a8358b7aef00876 (patch)
tree1692a8f491b4fc911595427c008307a9f96a77e4 /graphics
parent2f43f46211f964e456437eacf732f0743755b6e7 (diff)
downloadplatform_hardware_interfaces-69292faf0ba99b93ba8a6b582a8358b7aef00876.tar.gz
platform_hardware_interfaces-69292faf0ba99b93ba8a6b582a8358b7aef00876.tar.bz2
platform_hardware_interfaces-69292faf0ba99b93ba8a6b582a8358b7aef00876.zip
mapper: update lock's return values
Require mapper to return more information when locking a buffer. Opaque vendor formats make it difficult to manipulate a locked buffer. The pointer to the buffer's data is always at the top left hand corner of the buffer. It can be impossible to know where the locked region begins. The mapper now must return the bytes per pixel and bytes per stride of a locked buffer when the values are consistent and known. Bug: 120493579 Test: vts Change-Id: Id0921f191f1e388d4950ecef73acab6a34010dc4
Diffstat (limited to 'graphics')
-rw-r--r--graphics/mapper/3.0/IMapper.hal12
-rw-r--r--graphics/mapper/3.0/utils/vts/MapperVts.cpp8
-rw-r--r--graphics/mapper/3.0/utils/vts/include/mapper-vts/3.0/MapperVts.h3
-rw-r--r--graphics/mapper/3.0/vts/functional/VtsHalGraphicsMapperV3_0TargetTest.cpp18
4 files changed, 35 insertions, 6 deletions
diff --git a/graphics/mapper/3.0/IMapper.hal b/graphics/mapper/3.0/IMapper.hal
index 0361b7b689..b8248e47f6 100644
--- a/graphics/mapper/3.0/IMapper.hal
+++ b/graphics/mapper/3.0/IMapper.hal
@@ -196,6 +196,12 @@ interface IMapper {
* memory. This address will represent the top-left corner of the entire
* buffer, even if @p accessRegion does not begin at the top-left corner.
*
+ * On success, bytesPerPixel must contain the number of bytes per pixel in
+ * the buffer. If the bytesPerPixel is unknown or variable, a value of -1
+ * should be returned. bytesPerStride must contain the bytes per stride of
+ * the buffer. If the bytesPerStride is unknown or variable, a value of -1
+ * should be returned.
+ *
* @param buffer Buffer to lock.
* @param cpuUsage CPU usage flags to request. See +ndk
* libnativewindow#AHardwareBuffer_UsageFlags for possible values.
@@ -214,13 +220,17 @@ interface IMapper {
* - `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.
+ * @return bytesPerPixel the number of bytes per pixel in the buffer
+ * @return bytesPerStride the number of bytes per stride of the buffer
*/
lock(pointer buffer,
uint64_t cpuUsage,
Rect accessRegion,
handle acquireFence)
generates (Error error,
- pointer data);
+ pointer data,
+ int32_t bytesPerPixel,
+ int32_t bytesPerStride);
/**
* Locks a YCbCr buffer for the specified CPU usage.
diff --git a/graphics/mapper/3.0/utils/vts/MapperVts.cpp b/graphics/mapper/3.0/utils/vts/MapperVts.cpp
index 842840353c..4b24a1f134 100644
--- a/graphics/mapper/3.0/utils/vts/MapperVts.cpp
+++ b/graphics/mapper/3.0/utils/vts/MapperVts.cpp
@@ -164,7 +164,8 @@ void Gralloc::freeBuffer(const native_handle_t* bufferHandle) {
}
void* Gralloc::lock(const native_handle_t* bufferHandle, uint64_t cpuUsage,
- const IMapper::Rect& accessRegion, int acquireFence) {
+ const IMapper::Rect& accessRegion, int acquireFence, int32_t* outBytesPerPixel,
+ int32_t* outBytesPerStride) {
auto buffer = const_cast<native_handle_t*>(bufferHandle);
NATIVE_HANDLE_DECLARE_STORAGE(acquireFenceStorage, 1, 0);
@@ -177,9 +178,12 @@ void* Gralloc::lock(const native_handle_t* bufferHandle, uint64_t cpuUsage,
void* data = nullptr;
mMapper->lock(buffer, cpuUsage, accessRegion, acquireFenceHandle,
- [&](const auto& tmpError, const auto& tmpData) {
+ [&](const auto& tmpError, const auto& tmpData, int32_t tmpBytesPerPixel,
+ int32_t tmpBytesPerStride) {
ASSERT_EQ(Error::NONE, tmpError) << "failed to lock buffer " << buffer;
data = tmpData;
+ *outBytesPerPixel = tmpBytesPerPixel;
+ *outBytesPerStride = tmpBytesPerStride;
});
if (acquireFence >= 0) {
diff --git a/graphics/mapper/3.0/utils/vts/include/mapper-vts/3.0/MapperVts.h b/graphics/mapper/3.0/utils/vts/include/mapper-vts/3.0/MapperVts.h
index c94961c489..efae82f75b 100644
--- a/graphics/mapper/3.0/utils/vts/include/mapper-vts/3.0/MapperVts.h
+++ b/graphics/mapper/3.0/utils/vts/include/mapper-vts/3.0/MapperVts.h
@@ -68,7 +68,8 @@ class Gralloc {
// in and out of the mapper. The ownership of the fd is always transferred
// with each of these functions.
void* lock(const native_handle_t* bufferHandle, uint64_t cpuUsage,
- const IMapper::Rect& accessRegion, int acquireFence);
+ const IMapper::Rect& accessRegion, int acquireFence, int32_t* outBytesPerPixel,
+ int32_t* outBytesPerStride);
YCbCrLayout lockYCbCr(const native_handle_t* bufferHandle, uint64_t cpuUsage,
const IMapper::Rect& accessRegion, int acquireFence);
int unlock(const native_handle_t* bufferHandle);
diff --git a/graphics/mapper/3.0/vts/functional/VtsHalGraphicsMapperV3_0TargetTest.cpp b/graphics/mapper/3.0/vts/functional/VtsHalGraphicsMapperV3_0TargetTest.cpp
index 430a526851..b198f21146 100644
--- a/graphics/mapper/3.0/vts/functional/VtsHalGraphicsMapperV3_0TargetTest.cpp
+++ b/graphics/mapper/3.0/vts/functional/VtsHalGraphicsMapperV3_0TargetTest.cpp
@@ -298,8 +298,15 @@ TEST_F(GraphicsMapperHidlTest, LockUnlockBasic) {
static_cast<int32_t>(info.height)};
int fence = -1;
uint8_t* data;
+ int32_t bytesPerPixel = -1;
+ int32_t bytesPerStride = -1;
ASSERT_NO_FATAL_FAILURE(
- data = static_cast<uint8_t*>(mGralloc->lock(bufferHandle, info.usage, region, fence)));
+ data = static_cast<uint8_t*>(mGralloc->lock(bufferHandle, info.usage, region, fence,
+ &bytesPerPixel, &bytesPerStride)));
+
+ // Valid return values are -1 for unsupported or the number bytes for supported which is >=0
+ EXPECT_GT(bytesPerPixel, -1);
+ EXPECT_GT(bytesPerStride, -1);
// RGBA_8888
size_t strideInBytes = stride * 4;
@@ -312,9 +319,13 @@ TEST_F(GraphicsMapperHidlTest, LockUnlockBasic) {
ASSERT_NO_FATAL_FAILURE(fence = mGralloc->unlock(bufferHandle));
+ bytesPerPixel = -1;
+ bytesPerStride = -1;
+
// lock again for reading
ASSERT_NO_FATAL_FAILURE(
- data = static_cast<uint8_t*>(mGralloc->lock(bufferHandle, info.usage, region, fence)));
+ data = static_cast<uint8_t*>(mGralloc->lock(bufferHandle, info.usage, region, fence,
+ &bytesPerPixel, &bytesPerStride)));
for (uint32_t y = 0; y < info.height; y++) {
for (size_t i = 0; i < writeInBytes; i++) {
EXPECT_EQ(static_cast<uint8_t>(y), data[i]);
@@ -322,6 +333,9 @@ TEST_F(GraphicsMapperHidlTest, LockUnlockBasic) {
data += strideInBytes;
}
+ EXPECT_GT(bytesPerPixel, -1);
+ EXPECT_GT(bytesPerStride, -1);
+
ASSERT_NO_FATAL_FAILURE(fence = mGralloc->unlock(bufferHandle));
if (fence >= 0) {
close(fence);