Add layered image support to gralloc1 hal.
Bug: 31686534
Test: manual
Change-Id: I6442413072cef2a19abd3aacddf964ca1f4e7481
diff --git a/graphics/allocator/2.0/IAllocator.hal b/graphics/allocator/2.0/IAllocator.hal
index 8accb82..ff08a7e 100644
--- a/graphics/allocator/2.0/IAllocator.hal
+++ b/graphics/allocator/2.0/IAllocator.hal
@@ -26,11 +26,16 @@
* is supported.
*/
TEST_ALLOCATE = 1,
+
+ /*
+ * layerCount must be 1 unless this capability is supported.
+ */
+ LAYERED_BUFFERS = 2,
};
struct BufferDescriptorInfo {
/*
- * The width specifies how many columns of pixels should be in the
+ * The width specifies how many columns of pixels must be in the
* allocated buffer, but does not necessarily represent the offset in
* columns between the same column in adjacent rows. The rows may be
* padded.
@@ -38,11 +43,16 @@
uint32_t width;
/*
- * The height specifies how many rows of pixels should be in the
+ * The height specifies how many rows of pixels must be in the
* allocated buffer.
*/
uint32_t height;
+ /*
+ * The number of image layers that must be in the allocated buffer.
+ */
+ uint32_t layerCount;
+
/* Buffer pixel format. */
PixelFormat format;
diff --git a/graphics/allocator/2.0/default/Gralloc.cpp b/graphics/allocator/2.0/default/Gralloc.cpp
index a7fc6c1..8a74661 100644
--- a/graphics/allocator/2.0/default/Gralloc.cpp
+++ b/graphics/allocator/2.0/default/Gralloc.cpp
@@ -74,6 +74,7 @@
GRALLOC1_PFN_DESTROY_DESCRIPTOR destroyDescriptor;
GRALLOC1_PFN_SET_DIMENSIONS setDimensions;
GRALLOC1_PFN_SET_FORMAT setFormat;
+ GRALLOC1_PFN_SET_LAYER_COUNT setLayerCount;
GRALLOC1_PFN_SET_CONSUMER_USAGE setConsumerUsage;
GRALLOC1_PFN_SET_PRODUCER_USAGE setProducerUsage;
GRALLOC1_PFN_ALLOCATE allocate;
@@ -135,6 +136,10 @@
GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR);
initDispatch(mDispatch.setDimensions, GRALLOC1_FUNCTION_SET_DIMENSIONS);
initDispatch(mDispatch.setFormat, GRALLOC1_FUNCTION_SET_FORMAT);
+ if (hasCapability(Capability::LAYERED_BUFFERS)) {
+ initDispatch(
+ mDispatch.setLayerCount, GRALLOC1_FUNCTION_SET_LAYER_COUNT);
+ }
initDispatch(mDispatch.setConsumerUsage,
GRALLOC1_FUNCTION_SET_CONSUMER_USAGE);
initDispatch(mDispatch.setProducerUsage,
@@ -191,6 +196,11 @@
err = mDispatch.setFormat(mDevice, descriptor,
static_cast<int32_t>(descriptorInfo.format));
}
+ if (err == GRALLOC1_ERROR_NONE &&
+ hasCapability(Capability::LAYERED_BUFFERS)) {
+ err = mDispatch.setLayerCount(mDevice, descriptor,
+ descriptorInfo.layerCount);
+ }
if (err == GRALLOC1_ERROR_NONE) {
uint64_t producerUsageMask = descriptorInfo.producerUsageMask;
if (producerUsageMask & GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN) {