gralloc: Return aligned w,h for UPDATE_BUFFER_GEOMETRY

Return aligned width and height in case meta operation is
UPDATE_BUFFER_GEOMETRY.

CRs-Fixed: 880373
Change-Id: I3b263518d509f4de68c93692eace3cb0b2c69808
diff --git a/libgralloc/alloc_controller.cpp b/libgralloc/alloc_controller.cpp
index a7e00c5..0070fa1 100644
--- a/libgralloc/alloc_controller.cpp
+++ b/libgralloc/alloc_controller.cpp
@@ -149,6 +149,26 @@
     return 0;
 }
 
+void AdrenoMemInfo::getAlignedWidthAndHeight(const private_handle_t *hnd, int& aligned_w,
+                          int& aligned_h) {
+    MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
+    if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
+        int w = metadata->bufferDim.sliceWidth;
+        int h = metadata->bufferDim.sliceHeight;
+        int f = hnd->format;
+        int usage = 0;
+
+        if (hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED) {
+            usage = GRALLOC_USAGE_PRIVATE_ALLOC_UBWC;
+        }
+
+        getAlignedWidthAndHeight(w, h, f, usage, aligned_w, aligned_h);
+    } else {
+        aligned_w = hnd->width;
+        aligned_h = hnd->height;
+    }
+
+}
 
 void AdrenoMemInfo::getAlignedWidthAndHeight(int width, int height, int format,
                             int usage, int& aligned_w, int& aligned_h)
@@ -158,8 +178,7 @@
     // Currently surface padding is only computed for RGB* surfaces.
     if (format <= HAL_PIXEL_FORMAT_BGRA_8888) {
         int tileEnabled = ubwc_enabled || isMacroTileEnabled(format, usage);
-        AdrenoMemInfo::getInstance().getGpuAlignedWidthHeight(width,
-            height, format, tileEnabled, aligned_w, aligned_h);
+        getGpuAlignedWidthHeight(width, height, format, tileEnabled, aligned_w, aligned_h);
         return;
     }
 
@@ -649,6 +668,7 @@
     int width = hnd->width;
     int height = hnd->height;
     int format = hnd->format;
+
     unsigned int ystride, cstride;
     unsigned int alignment = 4096;
 
@@ -662,8 +682,14 @@
 
     // Check metadata if the geometry has been updated.
     if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
+        int usage = 0;
+
+        if (hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED) {
+            usage = GRALLOC_USAGE_PRIVATE_ALLOC_UBWC;
+        }
+
         AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(metadata->bufferDim.sliceWidth,
-                   metadata->bufferDim.sliceHeight, format, 0, width, height);
+                   metadata->bufferDim.sliceHeight, format, usage, width, height);
     }
 
     // Get the chroma offsets from the handle width/height. We take advantage
diff --git a/libgralloc/gr.h b/libgralloc/gr.h
index e27203a..6d7f4a7 100644
--- a/libgralloc/gr.h
+++ b/libgralloc/gr.h
@@ -120,6 +120,14 @@
                             int usage, int& aligned_w, int& aligned_h);
 
     /*
+     * Function to compute aligned width and aligned height based on
+     * private handle
+     *
+     * @return aligned width, aligned height
+     */
+    void getAlignedWidthAndHeight(const private_handle_t *hnd, int& aligned_w, int& aligned_h);
+
+    /*
      * Function to compute the adreno aligned width and aligned height
      * based on the width and format.
      *
diff --git a/libgralloc/mapper.cpp b/libgralloc/mapper.cpp
index 3cfdc55..a5d3e69 100644
--- a/libgralloc/mapper.cpp
+++ b/libgralloc/mapper.cpp
@@ -344,36 +344,33 @@
 
         case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE:
             {
-                private_handle_t* hnd =  va_arg(args, private_handle_t*);
+                const private_handle_t* hnd =  va_arg(args, private_handle_t*);
                 int *stride = va_arg(args, int *);
                 if (private_handle_t::validate(hnd)) {
                     return res;
                 }
-                MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
-                if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
-                    *stride = metadata->bufferDim.sliceWidth;
-                } else {
-                    *stride = hnd->width;
-                }
+
+                int alignedw = 0, alignedh = 0;
+                AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(hnd, alignedw, alignedh);
+                *stride = alignedw;
+
                 res = 0;
             } break;
 
         case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE:
             {
-                private_handle_t* hnd =  va_arg(args, private_handle_t*);
+                const private_handle_t* hnd =  va_arg(args, private_handle_t*);
                 int *stride = va_arg(args, int *);
                 int *height = va_arg(args, int *);
                 if (private_handle_t::validate(hnd)) {
                     return res;
                 }
-                MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
-                if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
-                    *stride = metadata->bufferDim.sliceWidth;
-                    *height = metadata->bufferDim.sliceHeight;
-                } else {
-                    *stride = hnd->width;
-                    *height = hnd->height;
-                }
+
+                int alignedw = 0, alignedh = 0;
+                AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(hnd, alignedw, alignedh);
+                *stride = alignedw;
+                *height = alignedh;
+
                 res = 0;
             } break;