libgralloc: Add Perform function to get the stride.

- Introduce a new class to Get the Adreno computed stride information.
This class has been added to allow adreno library computed strides to
be propagated to the allocation function as well as those clients
requesting it.
- Add a new Perform function to get the stride. The width and the format
can be passed from the calling functions (like EGL) to get the stride of
the buffer.

Change-Id: I4c2b4a02deff327f0ea5558c478997527fe9d3cf
diff --git a/libgralloc/alloc_controller.cpp b/libgralloc/alloc_controller.cpp
index 6003688..5aca758 100644
--- a/libgralloc/alloc_controller.cpp
+++ b/libgralloc/alloc_controller.cpp
@@ -47,6 +47,8 @@
 using namespace gralloc;
 using namespace qdutils;
 
+ANDROID_SINGLETON_STATIC_INSTANCE(AdrenoMemInfo);
+
 //Common functions
 static bool canFallback(int usage, bool triedSystem)
 {
@@ -81,6 +83,35 @@
     return false;
 }
 
+//-------------- AdrenoMemInfo-----------------------//
+int AdrenoMemInfo::getStride(int width, int format)
+{
+    int stride = ALIGN(width, 32);
+    switch (format)
+    {
+        case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
+            stride = ALIGN(width, 32);
+            break;
+        case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
+            stride = ALIGN(width, 128);
+            break;
+        case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
+        case HAL_PIXEL_FORMAT_YCbCr_420_SP:
+        case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+        case HAL_PIXEL_FORMAT_YV12:
+        case HAL_PIXEL_FORMAT_YCbCr_422_SP:
+        case HAL_PIXEL_FORMAT_YCrCb_422_SP:
+            stride = ALIGN(width, 16);
+            break;
+        case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
+            stride = VENUS_Y_STRIDE(COLOR_FMT_NV12, width);
+            break;
+        default: break;
+    }
+    return stride;
+}
+
+//-------------- IAllocController-----------------------//
 IAllocController* IAllocController::sController = NULL;
 IAllocController* IAllocController::getInstance(void)
 {
@@ -176,7 +207,7 @@
 {
     size_t size;
 
-    alignedw = ALIGN(width, 32);
+    alignedw = AdrenoMemInfo::getInstance().getStride(width, format);
     alignedh = ALIGN(height, 32);
     switch (format) {
         case HAL_PIXEL_FORMAT_RGBA_8888:
@@ -202,7 +233,6 @@
             // The chroma plane is subsampled,
             // but the pitch in bytes is unchanged
             // The GPU needs 4K alignment, but the video decoder needs 8K
-            alignedw = ALIGN(width, 128);
             size  = ALIGN( alignedw * alignedh, 8192);
             size += ALIGN( alignedw * ALIGN(height/2, 32), 8192);
             break;
@@ -214,7 +244,6 @@
                 ALOGE("w or h is odd for the YV12 format");
                 return -EINVAL;
             }
-            alignedw = ALIGN(width, 16);
             alignedh = height;
             if (HAL_PIXEL_FORMAT_NV12_ENCODEABLE == format) {
                 // The encoder requires a 2K aligned chroma offset.
@@ -232,12 +261,10 @@
                 ALOGE("width is odd for the YUV422_SP format");
                 return -EINVAL;
             }
-            alignedw = ALIGN(width, 16);
             alignedh = height;
             size = ALIGN(alignedw * alignedh * 2, 4096);
             break;
         case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
-            alignedw = VENUS_Y_STRIDE(COLOR_FMT_NV12, width);
             alignedh = VENUS_Y_SCANLINES(COLOR_FMT_NV12, height);
             size = VENUS_BUFFER_SIZE(COLOR_FMT_NV12, width, height);
             break;