Add layered buffer support to libui and libgui.
Bug: 31686534
Test: manual
Change-Id: Ia40270701467f4b785660324cad883e7da08989a
diff --git a/include/gui/GraphicBufferAlloc.h b/include/gui/GraphicBufferAlloc.h
index 62e3877..b19a1ac 100644
--- a/include/gui/GraphicBufferAlloc.h
+++ b/include/gui/GraphicBufferAlloc.h
@@ -34,8 +34,9 @@
GraphicBufferAlloc();
virtual ~GraphicBufferAlloc();
virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t width,
- uint32_t height, PixelFormat format, uint32_t usage,
- std::string requestorName, status_t* error) override;
+ uint32_t height, PixelFormat format, uint32_t layerCount,
+ uint32_t usage, std::string requestorName,
+ status_t* error) override;
};
diff --git a/include/gui/IGraphicBufferAlloc.h b/include/gui/IGraphicBufferAlloc.h
index acc2f30..2a7690a 100644
--- a/include/gui/IGraphicBufferAlloc.h
+++ b/include/gui/IGraphicBufferAlloc.h
@@ -38,12 +38,14 @@
/* Create a new GraphicBuffer for the client to use.
*/
virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t w, uint32_t h,
- PixelFormat format, uint32_t usage, std::string requestorName,
- status_t* error) = 0;
+ PixelFormat format, uint32_t layerCount, uint32_t usage,
+ std::string requestorName, status_t* error) = 0;
sp<GraphicBuffer> createGraphicBuffer(uint32_t w, uint32_t h,
- PixelFormat format, uint32_t usage, status_t* error) {
- return createGraphicBuffer(w, h, format, usage, "<Unknown>", error);
+ PixelFormat format, uint32_t layerCount, uint32_t usage,
+ status_t* error) {
+ return createGraphicBuffer(w, h, format, layerCount, usage, "<Unknown>",
+ error);
}
};
diff --git a/include/ui/Gralloc1.h b/include/ui/Gralloc1.h
index cf8c173..64dacd7 100644
--- a/include/ui/Gralloc1.h
+++ b/include/ui/Gralloc1.h
@@ -49,6 +49,7 @@
mWidth(0),
mHeight(0),
mFormat(static_cast<android_pixel_format_t>(0)),
+ mLayerCount(0),
mProducerUsage(GRALLOC1_PRODUCER_USAGE_NONE),
mConsumerUsage(GRALLOC1_CONSUMER_USAGE_NONE) {}
@@ -58,6 +59,7 @@
gralloc1_error_t setDimensions(uint32_t width, uint32_t height);
gralloc1_error_t setFormat(android_pixel_format_t format);
+ gralloc1_error_t setLayerCount(uint32_t layerCount);
gralloc1_error_t setProducerUsage(gralloc1_producer_usage_t usage);
gralloc1_error_t setConsumerUsage(gralloc1_consumer_usage_t usage);
@@ -68,6 +70,7 @@
uint32_t mWidth;
uint32_t mHeight;
android_pixel_format_t mFormat;
+ uint32_t mLayerCount;
gralloc1_producer_usage_t mProducerUsage;
gralloc1_consumer_usage_t mConsumerUsage;
@@ -178,6 +181,8 @@
GRALLOC1_FUNCTION_SET_DIMENSIONS> setDimensions;
FunctionLoader<GRALLOC1_PFN_SET_FORMAT,
GRALLOC1_FUNCTION_SET_FORMAT> setFormat;
+ FunctionLoader<GRALLOC1_PFN_SET_LAYER_COUNT,
+ GRALLOC1_FUNCTION_SET_LAYER_COUNT> setLayerCount;
FunctionLoader<GRALLOC1_PFN_SET_PRODUCER_USAGE,
GRALLOC1_FUNCTION_SET_PRODUCER_USAGE> setProducerUsage;
FunctionLoader<GRALLOC1_PFN_GET_BACKING_STORE,
@@ -188,6 +193,8 @@
GRALLOC1_FUNCTION_GET_DIMENSIONS> getDimensions;
FunctionLoader<GRALLOC1_PFN_GET_FORMAT,
GRALLOC1_FUNCTION_GET_FORMAT> getFormat;
+ FunctionLoader<GRALLOC1_PFN_GET_LAYER_COUNT,
+ GRALLOC1_FUNCTION_GET_LAYER_COUNT> getLayerCount;
FunctionLoader<GRALLOC1_PFN_GET_PRODUCER_USAGE,
GRALLOC1_FUNCTION_GET_PRODUCER_USAGE> getProducerUsage;
FunctionLoader<GRALLOC1_PFN_GET_STRIDE,
diff --git a/include/ui/Gralloc1On0Adapter.h b/include/ui/Gralloc1On0Adapter.h
index d523c4f..2508ce9 100644
--- a/include/ui/Gralloc1On0Adapter.h
+++ b/include/ui/Gralloc1On0Adapter.h
@@ -131,6 +131,7 @@
width(0),
height(0),
format(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED),
+ layerCount(1),
producerUsage(GRALLOC1_PRODUCER_USAGE_NONE),
consumerUsage(GRALLOC1_CONSUMER_USAGE_NONE) {}
@@ -145,6 +146,11 @@
return GRALLOC1_ERROR_NONE;
}
+ gralloc1_error_t setLayerCount(uint32_t lc) {
+ layerCount = lc;
+ return GRALLOC1_ERROR_NONE;
+ }
+
gralloc1_error_t setProducerUsage(gralloc1_producer_usage_t usage) {
producerUsage = usage;
return GRALLOC1_ERROR_NONE;
@@ -161,6 +167,7 @@
uint32_t width;
uint32_t height;
int32_t format;
+ uint32_t layerCount;
gralloc1_producer_usage_t producerUsage;
gralloc1_consumer_usage_t consumerUsage;
};
@@ -197,6 +204,12 @@
&Descriptor::setFormat, format);
}
+ static int32_t setLayerCountHook(gralloc1_device_t* device,
+ gralloc1_buffer_descriptor_t descriptorId, uint32_t layerCount) {
+ return callDescriptorFunction(device, descriptorId,
+ &Descriptor::setLayerCount, layerCount);
+ }
+
static int32_t setProducerUsageHook(gralloc1_device_t* device,
gralloc1_buffer_descriptor_t descriptorId, uint64_t intUsage) {
auto usage = static_cast<gralloc1_producer_usage_t>(intUsage);
@@ -246,6 +259,11 @@
return GRALLOC1_ERROR_NONE;
}
+ gralloc1_error_t getLayerCount(uint32_t* outLayerCount) const {
+ *outLayerCount = mDescriptor.layerCount;
+ return GRALLOC1_ERROR_NONE;
+ }
+
gralloc1_error_t getNumFlexPlanes(uint32_t* outNumPlanes) const {
// TODO: This is conservative, and we could do better by examining
// the format, but it won't hurt anything for now
diff --git a/include/ui/GrallocMapper.h b/include/ui/GrallocMapper.h
index 5517449..868fd14 100644
--- a/include/ui/GrallocMapper.h
+++ b/include/ui/GrallocMapper.h
@@ -63,6 +63,11 @@
return mMapper->getFormat(mDevice, handle, &format);
}
+ Error getLayerCount(buffer_handle_t handle, uint32_t& layerCount) const
+ {
+ return mMapper->getLayerCount(mDevice, handle, &layerCount);
+ }
+
Error getProducerUsageMask(buffer_handle_t handle,
uint64_t& usageMask) const
{
diff --git a/include/ui/GraphicBuffer.h b/include/ui/GraphicBuffer.h
index 3e127a1..1bbcee2 100644
--- a/include/ui/GraphicBuffer.h
+++ b/include/ui/GraphicBuffer.h
@@ -76,10 +76,15 @@
GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
uint32_t inUsage, std::string requestorName = "<Unknown>");
+ // creates w * h buffer with a layer count
+ GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
+ uint32_t inLayerCount, uint32_t inUsage,
+ std::string requestorName = "<Unknown>");
+
// create a buffer from an existing handle
GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
- uint32_t inUsage, uint32_t inStride, native_handle_t* inHandle,
- bool keepOwnership);
+ uint32_t inLayerCount, uint32_t inUsage, uint32_t inStride,
+ native_handle_t* inHandle, bool keepOwnership);
// create a buffer from an existing ANativeWindowBuffer
GraphicBuffer(ANativeWindowBuffer* buffer, bool keepOwnership);
@@ -92,6 +97,7 @@
uint32_t getStride() const { return static_cast<uint32_t>(stride); }
uint32_t getUsage() const { return static_cast<uint32_t>(usage); }
PixelFormat getPixelFormat() const { return format; }
+ uint32_t getLayerCount() const { return static_cast<uint32_t>(layerCount); }
Rect getBounds() const { return Rect(width, height); }
uint64_t getId() const { return mId; }
@@ -101,10 +107,10 @@
}
status_t reallocate(uint32_t inWidth, uint32_t inHeight,
- PixelFormat inFormat, uint32_t inUsage);
+ PixelFormat inFormat, uint32_t inLayerCount, uint32_t inUsage);
bool needsReallocation(uint32_t inWidth, uint32_t inHeight,
- PixelFormat inFormat, uint32_t inUsage);
+ PixelFormat inFormat, uint32_t inLayerCount, uint32_t inUsage);
status_t lock(uint32_t inUsage, void** vaddr);
status_t lock(uint32_t inUsage, const Rect& rect, void** vaddr);
@@ -160,7 +166,7 @@
const GraphicBuffer& operator = (const GraphicBuffer& rhs) const;
status_t initSize(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
- uint32_t inUsage, std::string requestorName);
+ uint32_t inLayerCount, uint32_t inUsage, std::string requestorName);
void free_handle();
diff --git a/include/ui/GraphicBufferAllocator.h b/include/ui/GraphicBufferAllocator.h
index 9cc5806..16967d4 100644
--- a/include/ui/GraphicBufferAllocator.h
+++ b/include/ui/GraphicBufferAllocator.h
@@ -65,8 +65,9 @@
static inline GraphicBufferAllocator& get() { return getInstance(); }
status_t allocate(uint32_t w, uint32_t h, PixelFormat format,
- uint32_t usage, buffer_handle_t* handle, uint32_t* stride,
- uint64_t graphicBufferId, std::string requestorName);
+ uint32_t layerCount, uint32_t usage, buffer_handle_t* handle,
+ uint32_t* stride, uint64_t graphicBufferId,
+ std::string requestorName);
status_t free(buffer_handle_t handle);
@@ -79,6 +80,7 @@
uint32_t height;
uint32_t stride;
PixelFormat format;
+ uint32_t layerCount;
uint32_t usage;
size_t size;
std::string requestorName;