hwc2: Use GRALLOC1_PFN_ALLOCATE to allocate buffer
1. Define gralloc1 function pointers needed to allocate buffer
2. Use the gralloc1 function pointers to allocate buffer instead of
perform function to avoid any synchronization issues.
3. Remove functionality to allocate buffer from perform function
Change-Id: If686181409a179d3d911dfbd0f0c0eab7a7ffa99
CRs-Fixed: 2115331
diff --git a/libgralloc1/gr_buf_mgr.cpp b/libgralloc1/gr_buf_mgr.cpp
index 3c00ca7..59afe19 100644
--- a/libgralloc1/gr_buf_mgr.cpp
+++ b/libgralloc1/gr_buf_mgr.cpp
@@ -124,7 +124,7 @@
std::lock_guard<std::mutex> buffer_lock(buffer_lock_);
if (shared && (max_buf_index >= 0)) {
// Allocate one and duplicate/copy the handles for each descriptor
- if (AllocateBuffer(*descriptors[UINT(max_buf_index)], &out_buffers[max_buf_index])) {
+ if (AllocateBufferLocked(*descriptors[UINT(max_buf_index)], &out_buffers[max_buf_index])) {
return GRALLOC1_ERROR_NO_RESOURCES;
}
@@ -140,7 +140,7 @@
// Buffer sharing is not feasible.
// Allocate separate buffer for each descriptor
for (i = 0; i < num_descriptors; i++) {
- if (AllocateBuffer(*descriptors[i], &out_buffers[i])) {
+ if (AllocateBufferLocked(*descriptors[i], &out_buffers[i])) {
return GRALLOC1_ERROR_NO_RESOURCES;
}
}
@@ -447,8 +447,8 @@
return buffer_type;
}
-int BufferManager::AllocateBuffer(const BufferDescriptor &descriptor, buffer_handle_t *handle,
- unsigned int bufferSize) {
+int BufferManager::AllocateBufferLocked(const BufferDescriptor &descriptor, buffer_handle_t *handle,
+ unsigned int bufferSize) {
if (!handle)
return -EINVAL;
@@ -739,22 +739,6 @@
// TODO(user): Break out similar functionality, preferably moving to a common lib.
- case GRALLOC1_MODULE_PERFORM_ALLOCATE_BUFFER: {
- int width = va_arg(args, int);
- int height = va_arg(args, int);
- int format = va_arg(args, int);
- uint64_t p_usage = va_arg(args, uint64_t);
- uint64_t c_usage = va_arg(args, uint64_t);
- buffer_handle_t *hnd = va_arg(args, buffer_handle_t*);
- gralloc1_producer_usage_t producer_usage = static_cast<gralloc1_producer_usage_t>(p_usage);
- gralloc1_consumer_usage_t consumer_usage = static_cast<gralloc1_consumer_usage_t>(c_usage);
- BufferDescriptor descriptor(width, height, format, producer_usage, consumer_usage);
- unsigned int size;
- unsigned int alignedw, alignedh;
- GetBufferSizeAndDimensions(GetBufferInfo(descriptor), &size, &alignedw, &alignedh);
- AllocateBuffer(descriptor, hnd, size);
- } break;
-
case GRALLOC1_MODULE_PERFORM_GET_INTERLACE_FLAG: {
private_handle_t *hnd = va_arg(args, private_handle_t *);
int *flag = va_arg(args, int *);