Gralloc: Implement getCustomFormatFlags API

Implement API to get custom format and private handle flags
based on a given combination of input format and usage flags.

Change-Id: Id87e9abe834fb17c6304262cc486a84131c8809a
CRs-Fixed: 2255171
diff --git a/gralloc/gr_buf_mgr.cpp b/gralloc/gr_buf_mgr.cpp
index 12fd13f..7aa4b05 100644
--- a/gralloc/gr_buf_mgr.cpp
+++ b/gralloc/gr_buf_mgr.cpp
@@ -85,7 +85,7 @@
 
 Error BufferManager::ValidateBufferSize(private_handle_t const *hnd, BufferInfo info) {
   unsigned int size, alignedw, alignedh;
-  info.format = allocator_->GetImplDefinedFormat(info.usage, info.format);
+  info.format = GetImplDefinedFormat(info.usage, info.format);
   GetBufferSizeAndDimensions(info, &size, &alignedw, &alignedh);
   auto ion_fd_size = static_cast<unsigned int>(lseek(hnd->fd, 0, SEEK_END));
   if (size != ion_fd_size) {
@@ -254,52 +254,6 @@
   return status;
 }
 
-int BufferManager::GetHandleFlags(int format, uint64_t usage) {
-  int flags = 0;
-  if (usage & BufferUsage::VIDEO_ENCODER) {
-    flags |= private_handle_t::PRIV_FLAGS_VIDEO_ENCODER;
-  }
-
-  if (usage & BufferUsage::CAMERA_OUTPUT) {
-    flags |= private_handle_t::PRIV_FLAGS_CAMERA_WRITE;
-  }
-
-  if (usage & BufferUsage::CAMERA_INPUT) {
-    flags |= private_handle_t::PRIV_FLAGS_CAMERA_READ;
-  }
-
-  if (usage & BufferUsage::COMPOSER_OVERLAY) {
-    flags |= private_handle_t::PRIV_FLAGS_DISP_CONSUMER;
-  }
-
-  if (usage & BufferUsage::GPU_TEXTURE) {
-    flags |= private_handle_t::PRIV_FLAGS_HW_TEXTURE;
-  }
-
-  if (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY) {
-    flags |= private_handle_t::PRIV_FLAGS_SECURE_DISPLAY;
-  }
-
-  if (IsUBwcEnabled(format, usage)) {
-    flags |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
-  }
-
-  if (usage & (BufferUsage::CPU_READ_MASK | BufferUsage::CPU_WRITE_MASK)) {
-    flags |= private_handle_t::PRIV_FLAGS_CPU_RENDERED;
-  }
-
-  if ((usage & (BufferUsage::VIDEO_ENCODER | BufferUsage::VIDEO_DECODER |
-                BufferUsage::CAMERA_OUTPUT | BufferUsage::GPU_RENDER_TARGET))) {
-    flags |= private_handle_t::PRIV_FLAGS_NON_CPU_WRITER;
-  }
-
-  if (!allocator_->UseUncached(format, usage)) {
-    flags |= private_handle_t::PRIV_FLAGS_CACHED;
-  }
-
-  return flags;
-}
-
 int BufferManager::GetBufferType(int inputFormat) {
   int buffer_type = BUFFER_TYPE_UI;
   if (IsYuvFormat(inputFormat)) {
@@ -317,7 +271,7 @@
   std::lock_guard<std::mutex> buffer_lock(buffer_lock_);
 
   uint64_t usage = descriptor.GetUsage();
-  int format = allocator_->GetImplDefinedFormat(usage, descriptor.GetFormat());
+  int format = GetImplDefinedFormat(usage, descriptor.GetFormat());
   uint32_t layer_count = descriptor.GetLayerCount();
 
   unsigned int size;
@@ -340,13 +294,13 @@
 
   size = (bufferSize >= size) ? bufferSize : size;
   int err = 0;
-  int flags = 0;
+  uint64_t flags = 0;
   auto page_size = UINT(getpagesize());
   AllocData data;
   data.align = GetDataAlignment(format, usage);
   data.size = size;
   data.handle = (uintptr_t)handle;
-  data.uncached = allocator_->UseUncached(format, usage);
+  data.uncached = UseUncached(format, usage);
 
   // Allocate buffer memory
   err = allocator_->AllocateMem(&data, usage, format);
@@ -372,7 +326,7 @@
 
   // Create handle
   private_handle_t *hnd = new private_handle_t(
-      data.fd, e_data.fd, flags, INT(alignedw), INT(alignedh), descriptor.GetWidth(),
+      data.fd, e_data.fd, INT(flags), INT(alignedw), INT(alignedh), descriptor.GetWidth(),
       descriptor.GetHeight(), format, buffer_type, data.size, usage);
 
   hnd->id = ++next_id_;