gralloc: Support camera and video encoder flags

- Set private flags for these formats so that the camera HAL
can differentiate between the allocated buffers.
- Usage flags define format

Change-Id: Ib3cfad12ab2ba79662207609138633769b1504e6
diff --git a/libgralloc/gpu.cpp b/libgralloc/gpu.cpp
index 2db6274..6759b55 100644
--- a/libgralloc/gpu.cpp
+++ b/libgralloc/gpu.cpp
@@ -152,6 +152,18 @@
         }
     }
 
+    if (usage & GRALLOC_USAGE_HW_VIDEO_ENCODER ) {
+        flags |= private_handle_t::PRIV_FLAGS_VIDEO_ENCODER;
+    }
+
+    if (usage & GRALLOC_USAGE_HW_CAMERA_WRITE) {
+        flags |= private_handle_t::PRIV_FLAGS_CAMERA_WRITE;
+    }
+
+    if (usage & GRALLOC_USAGE_HW_CAMERA_READ) {
+        flags |= private_handle_t::PRIV_FLAGS_CAMERA_READ;
+    }
+
     if (err == 0) {
         flags |= data.allocType;
         private_handle_t* hnd = new private_handle_t(data.fd, size, flags,
@@ -168,19 +180,15 @@
 }
 
 void gpu_context_t::getGrallocInformationFromFormat(int inputFormat,
-                                                    int *colorFormat,
                                                     int *bufferType)
 {
     *bufferType = BUFFER_TYPE_VIDEO;
-    *colorFormat = inputFormat;
 
     if (inputFormat < 0x7) {
         // RGB formats
-        *colorFormat = inputFormat;
         *bufferType = BUFFER_TYPE_UI;
     } else if ((inputFormat == HAL_PIXEL_FORMAT_R_8) ||
                (inputFormat == HAL_PIXEL_FORMAT_RG_88)) {
-        *colorFormat = inputFormat;
         *bufferType = BUFFER_TYPE_UI;
     }
 }
@@ -193,9 +201,20 @@
 
     size_t size;
     int alignedw, alignedh;
-    int colorFormat, bufferType;
-    getGrallocInformationFromFormat(format, &colorFormat, &bufferType);
-    size = getBufferSizeAndDimensions(w, h, colorFormat, alignedw, alignedh);
+    int grallocFormat = format;
+    int bufferType;
+    getGrallocInformationFromFormat(format, &bufferType);
+
+    //XXX: This should only be done if format is
+    // HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED
+    if(usage & GRALLOC_USAGE_HW_VIDEO_ENCODER)
+        grallocFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP; //NV12
+    if(usage & GRALLOC_USAGE_HW_CAMERA_READ)
+        grallocFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP; //NV21
+    if(usage & GRALLOC_USAGE_HW_CAMERA_WRITE)
+        grallocFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP; //NV21
+
+    size = getBufferSizeAndDimensions(w, h, grallocFormat, alignedw, alignedh);
 
     if ((ssize_t)size <= 0)
         return -EINVAL;
@@ -213,7 +232,7 @@
         err = gralloc_alloc_framebuffer(size, usage, pHandle);
     } else {
         err = gralloc_alloc_buffer(size, usage, pHandle, bufferType,
-                                   format, alignedw, alignedh);
+                                   grallocFormat, alignedw, alignedh);
     }
 
     if (err < 0) {
diff --git a/libgralloc/gpu.h b/libgralloc/gpu.h
index 5a6c0ea..2920d5f 100644
--- a/libgralloc/gpu.h
+++ b/libgralloc/gpu.h
@@ -70,7 +70,6 @@
     private:
    IAllocController* mAllocCtrl;
     void getGrallocInformationFromFormat(int inputFormat,
-                                         int *colorFormat,
                                          int *bufferType);
 };
 }
diff --git a/libgralloc/gralloc_priv.h b/libgralloc/gralloc_priv.h
index fa1fe6e..b9e2f92 100644
--- a/libgralloc/gralloc_priv.h
+++ b/libgralloc/gralloc_priv.h
@@ -157,6 +157,9 @@
             PRIV_FLAGS_EXTERNAL_BLOCK     = 0x00004000,
             // Display this buffer on external as close caption
             PRIV_FLAGS_EXTERNAL_CC        = 0x00008000,
+            PRIV_FLAGS_VIDEO_ENCODER      = 0x00010000,
+            PRIV_FLAGS_CAMERA_WRITE       = 0x00020000,
+            PRIV_FLAGS_CAMERA_READ        = 0x00040000,
         };
 
         // file-descriptors