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 *);
diff --git a/libgralloc1/gr_buf_mgr.h b/libgralloc1/gr_buf_mgr.h
index 861a7a7..e021afd 100644
--- a/libgralloc1/gr_buf_mgr.h
+++ b/libgralloc1/gr_buf_mgr.h
@@ -73,8 +73,8 @@
   BufferManager();
   gralloc1_error_t MapBuffer(private_handle_t const *hnd);
   int GetBufferType(int format);
-  int AllocateBuffer(const BufferDescriptor &descriptor, buffer_handle_t *handle,
-                     unsigned int bufferSize = 0);
+  int AllocateBufferLocked(const BufferDescriptor &descriptor, buffer_handle_t *handle,
+                           unsigned int bufferSize = 0);
   uint32_t GetDataAlignment(int format, gralloc1_producer_usage_t prod_usage,
                        gralloc1_consumer_usage_t cons_usage);
   int GetHandleFlags(int format, gralloc1_producer_usage_t prod_usage,
diff --git a/libgralloc1/gralloc_priv.h b/libgralloc1/gralloc_priv.h
index cec4af0..ef1bbc3 100644
--- a/libgralloc1/gralloc_priv.h
+++ b/libgralloc1/gralloc_priv.h
@@ -99,8 +99,7 @@
 #define GRALLOC_MODULE_PERFORM_SET_IGC 12
 #define GRALLOC_MODULE_PERFORM_SET_SINGLE_BUFFER_MODE 13
 #define GRALLOC1_MODULE_PERFORM_GET_BUFFER_SIZE_AND_DIMENSIONS 14
-#define GRALLOC1_MODULE_PERFORM_ALLOCATE_BUFFER 15
-#define GRALLOC1_MODULE_PERFORM_GET_INTERLACE_FLAG 16
+#define GRALLOC1_MODULE_PERFORM_GET_INTERLACE_FLAG 15
 
 // OEM specific HAL formats
 #define HAL_PIXEL_FORMAT_RGBA_5551 6