gralloc: Introduce custom content metadata region

Introduce a new dynamic memory region to store custom content
metadata that has sizing requirements that exceeds the base
1KB region allocated. This region is dynamic to ensure a layer's
memory requirements are only increased when absolutely needed.

Change-Id: I774197ed0c4ec7a18cc09b24262b6548dc293e72
diff --git a/gralloc/QtiGralloc.h b/gralloc/QtiGralloc.h
index c95368a..ac96e7f 100644
--- a/gralloc/QtiGralloc.h
+++ b/gralloc/QtiGralloc.h
@@ -131,6 +131,8 @@
 static const MetadataType MetadataType_MemHandle = {VENDOR_QTI, QTI_MEM_HANDLE};
 
 static const MetadataType MetadataType_TimedRendering = {VENDOR_QTI, QTI_TIMED_RENDERING};
+static const MetadataType MetadataType_CustomContentMetadata = {VENDOR_QTI,
+                                                                QTI_CUSTOM_CONTENT_METADATA};
 
 // 0 is also used as invalid value in standard metadata
 static const MetadataType MetadataType_Invalid = {VENDOR_QTI, 0};
@@ -165,6 +167,8 @@
 Error encodeYUVPlaneInfoMetadata(qti_ycbcr *in, hidl_vec<uint8_t> *out);
 Error decodeBufferPermission(hidl_vec<uint8_t> &in, BufferPermission *out);
 Error encodeBufferPermission(BufferPermission *in, hidl_vec<uint8_t> *out);
+Error decodeCustomContentMetadata(hidl_vec<uint8_t> &in, void *out);
+Error encodeCustomContentMetadata(const void *in, hidl_vec<uint8_t> *out);
 }  // namespace qtigralloc
 
 #endif  //__QTIGRALLOC_H__
diff --git a/gralloc/QtiGrallocMetadata.h b/gralloc/QtiGrallocMetadata.h
index 506fd2e..ccccaf6 100644
--- a/gralloc/QtiGrallocMetadata.h
+++ b/gralloc/QtiGrallocMetadata.h
@@ -70,6 +70,7 @@
 #define QTI_BUFFER_PERMISSION 10026
 #define QTI_MEM_HANDLE 10027
 #define QTI_TIMED_RENDERING 10028
+#define QTI_CUSTOM_CONTENT_METADATA 10029
 
 // Used to indicate to framework that internal definitions are used instead
 #define COMPRESSION_QTI_UBWC 20001
diff --git a/gralloc/QtiGrallocPriv.h b/gralloc/QtiGrallocPriv.h
index 13d8f8b..688d6df 100644
--- a/gralloc/QtiGrallocPriv.h
+++ b/gralloc/QtiGrallocPriv.h
@@ -174,6 +174,7 @@
   uint64_t base_metadata;
   uint64_t gpuaddr;
   unsigned int reserved_size;
+  unsigned int custom_content_md_reserved_size;
   static const int kNumFds = 2;
   static const int kMagic = 'gmsm';
 
@@ -202,7 +203,8 @@
         base(0),
         base_metadata(0),
         gpuaddr(0),
-        reserved_size(0) {
+        reserved_size(0),
+        custom_content_md_reserved_size(0) {
     version = static_cast<int>(sizeof(native_handle));
     numInts = NumInts();
     numFds = kNumFds;
@@ -236,10 +238,11 @@
   static void Dump(const private_handle_t *hnd) {
     ALOGD("handle id:%" PRIu64
           " wxh:%dx%d uwxuh:%dx%d size: %d fd:%d fd_meta:%d flags:0x%x "
-          "usage:0x%" PRIx64 "  format:0x%x layer_count: %d reserved_size = %d",
+          "usage:0x%" PRIx64 "  format:0x%x layer_count: %d reserved_size = %d "
+          "custom_content_md_reserved_size = %u",
           hnd->id, hnd->width, hnd->height, hnd->unaligned_width, hnd->unaligned_height, hnd->size,
           hnd->fd, hnd->fd_metadata, hnd->flags, hnd->usage, hnd->format, hnd->layer_count,
-          hnd->reserved_size);
+          hnd->reserved_size, hnd->custom_content_md_reserved_size);
   }
 };
 #pragma pack(pop)