gralloc: Cache maintenance handling updates

- Make buffer allocations for ubwc formats as uncached since
  access from cpu is not expected.
- Bracket each cache maintenance operation with dma buf sync
  start and sync end.

Change-Id: Ic2676ad9fff9a7ca6111f14e24aaec4c3d7f6ef2
CRs-Fixed: 2210256
diff --git a/gralloc/gr_buf_mgr.cpp b/gralloc/gr_buf_mgr.cpp
index 9f7b22e..6b6ec87 100644
--- a/gralloc/gr_buf_mgr.cpp
+++ b/gralloc/gr_buf_mgr.cpp
@@ -229,6 +229,11 @@
       status = Error::BAD_BUFFER;
     }
     hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
+  } else {
+    if (allocator_->CleanBuffer(reinterpret_cast<void *>(hnd->base), hnd->size, hnd->offset,
+                                buf->ion_handle_main, CACHE_READ_DONE, hnd->fd) != 0) {
+      status = Error::BAD_BUFFER;
+    }
   }
 
   return status;
@@ -273,7 +278,7 @@
     flags |= private_handle_t::PRIV_FLAGS_NON_CPU_WRITER;
   }
 
-  if (!allocator_->UseUncached(usage)) {
+  if (!allocator_->UseUncached(format, usage)) {
     flags |= private_handle_t::PRIV_FLAGS_CACHED;
   }
 
@@ -316,10 +321,10 @@
   data.align = GetDataAlignment(format, usage);
   data.size = size;
   data.handle = (uintptr_t)handle;
-  data.uncached = allocator_->UseUncached(usage);
+  data.uncached = allocator_->UseUncached(format, usage);
 
   // Allocate buffer memory
-  err = allocator_->AllocateMem(&data, usage);
+  err = allocator_->AllocateMem(&data, usage, format);
   if (err) {
     ALOGE("gralloc failed to allocate err=%s", strerror(-err));
     return Error::NO_RESOURCES;
@@ -331,7 +336,7 @@
   e_data.handle = data.handle;
   e_data.align = page_size;
 
-  err = allocator_->AllocateMem(&e_data, 0);
+  err = allocator_->AllocateMem(&e_data, 0, 0);
   if (err) {
     ALOGE("gralloc failed to allocate metadata error=%s", strerror(-err));
     return Error::NO_RESOURCES;