Gralloc: Use adreno APIs for buffer size calculations

1) Add support to use adreno APIs for non video layers'
buffer size calculations.
2) Add graphics metadata field to MetaData_t structure.
3) Add bindings for newly introduced formats in
GetGpuPixelFormat.
4) Add support to retrieve the graphics metadata in
Perform API.
5) Modify BUFFER_TYPE determination logic

Change-Id: I7674209b42d7cd39bc8de39e3a10582bb216e6cf
CRs-Fixed: 2226672
diff --git a/gralloc/gr_utils.cpp b/gralloc/gr_utils.cpp
index f7ddac6..0436c2a 100644
--- a/gralloc/gr_utils.cpp
+++ b/gralloc/gr_utils.cpp
@@ -32,7 +32,6 @@
 
 #include "gr_adreno_info.h"
 #include "gr_utils.h"
-#include "qdMetaData.h"
 
 #define ASTC_BLOCK_SIZE 16
 
@@ -42,8 +41,8 @@
 
 namespace gralloc {
 
-bool IsYuvFormat(const private_handle_t *hnd) {
-  switch (hnd->format) {
+bool IsYuvFormat(int format) {
+  switch (format) {
     case HAL_PIXEL_FORMAT_YCbCr_420_SP:
     case HAL_PIXEL_FORMAT_YCbCr_422_SP:
     case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
@@ -64,6 +63,9 @@
     case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
     case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC:
     case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS:
+    // Below formats used by camera and VR
+    case HAL_PIXEL_FORMAT_BLOB:
+    case HAL_PIXEL_FORMAT_RAW_OPAQUE:
       return true;
     default:
       return false;
@@ -943,4 +945,39 @@
   return 0;
 }
 
+void GetGpuResourceSizeAndDimensions(const BufferInfo &info, unsigned int *size,
+                                     unsigned int *alignedw, unsigned int *alignedh,
+                                     GraphicsMetadata *graphics_metadata) {
+  GetAlignedWidthAndHeight(info, alignedw, alignedh);
+  AdrenoMemInfo* adreno_mem_info = AdrenoMemInfo::GetInstance();
+  graphics_metadata->size = adreno_mem_info->AdrenoGetMetadataBlobSize();
+  uint64_t adreno_usage = info.usage;
+  // If gralloc disables UBWC based on any of the checks,
+  // we pass modified usage flag to adreno to convey this.
+  int is_ubwc_enabled = IsUBwcEnabled(info.format, info.usage);
+  if (!is_ubwc_enabled) {
+    adreno_usage &= ~(GRALLOC_USAGE_PRIVATE_ALLOC_UBWC);
+  }
+
+  // Call adreno api for populating metadata blob
+  int ret = adreno_mem_info->AdrenoInitMemoryLayout(graphics_metadata->data, info.width,
+                                                    info.height, 1, info.format, 1,
+                                                    is_ubwc_enabled, adreno_usage, 1);
+  if (ret != 0) {
+    ALOGE("%s Graphics metadata init failed", __FUNCTION__);
+    *size = 0;
+    return;
+  }
+  // Call adreno api with the metadata blob to get buffer size
+  *size = adreno_mem_info->AdrenoGetAlignedGpuBufferSize(graphics_metadata->data);
+}
+
+bool GetAdrenoSizeAPIStatus() {
+  AdrenoMemInfo* adreno_mem_info = AdrenoMemInfo::GetInstance();
+  if (adreno_mem_info) {
+    return adreno_mem_info->AdrenoSizeAPIAvaliable();
+  }
+  return false;
+}
+
 }  // namespace gralloc