Merge "gralloc: Add the support of RAW data in getComponentSizeAndOffset"
diff --git a/gralloc/gr_buf_mgr.cpp b/gralloc/gr_buf_mgr.cpp
index dd9a029..0d5d376 100644
--- a/gralloc/gr_buf_mgr.cpp
+++ b/gralloc/gr_buf_mgr.cpp
@@ -567,6 +567,31 @@
         return Error::BAD_VALUE;
       }
       break;
+    case static_cast<int32_t>(HAL_PIXEL_FORMAT_RAW16):
+      if (comp.type.value == android::gralloc4::PlaneLayoutComponentType_RAW.value) {
+        comp.offsetInBits = 0;
+        comp.sizeInBits = 16;
+      } else {
+        return Error::BAD_VALUE;
+      }
+      break;
+    case static_cast<int32_t>(HAL_PIXEL_FORMAT_RAW12):
+    case static_cast<int32_t>(HAL_PIXEL_FORMAT_RAW10):
+      if (comp.type.value == android::gralloc4::PlaneLayoutComponentType_RAW.value) {
+        comp.offsetInBits = 0;
+        comp.sizeInBits = -1;
+      } else {
+        return Error::BAD_VALUE;
+      }
+      break;
+    case static_cast<int32_t>(HAL_PIXEL_FORMAT_RAW8):
+      if (comp.type.value == android::gralloc4::PlaneLayoutComponentType_RAW.value) {
+        comp.offsetInBits = 0;
+        comp.sizeInBits = 8;
+      } else {
+        return Error::BAD_VALUE;
+      }
+      break;
     default:
       ALOGI_IF(DEBUG, "Offset and size in bits unknown for format %d", format);
       return Error::UNSUPPORTED;
@@ -624,8 +649,9 @@
   }
 
   if (in & PLANE_COMPONENT_RAW) {
-    comp.type = qtigralloc::PlaneLayoutComponentType_Raw;
-    components->push_back(comp);
+    comp.type = android::gralloc4::PlaneLayoutComponentType_RAW;
+    if (getComponentSizeAndOffset(format, comp) == Error::NONE)
+      components->push_back(comp);
   }
 
   if (in & PLANE_COMPONENT_META) {
diff --git a/gralloc/gr_utils.cpp b/gralloc/gr_utils.cpp
index 3dc91d5..312058e 100644
--- a/gralloc/gr_utils.cpp
+++ b/gralloc/gr_utils.cpp
@@ -518,15 +518,10 @@
       c_size = (width * height) / 2;
       c_height = height >> 1;
       break;
-    case HAL_PIXEL_FORMAT_RAW16:
     case HAL_PIXEL_FORMAT_Y16:
       c_size = width * height;
       c_height = height;
       break;
-    case HAL_PIXEL_FORMAT_RAW10:
-      c_size = 0;
-      break;
-    case HAL_PIXEL_FORMAT_RAW8:
     case HAL_PIXEL_FORMAT_Y8:
       c_size = 0;
       break;
@@ -631,6 +626,44 @@
   return err;
 }
 
+int GetRawPlaneInfo(int32_t format, int32_t width, int32_t height, PlaneLayoutInfo *plane_info) {
+  int32_t step = 0;
+
+  switch (format) {
+    case HAL_PIXEL_FORMAT_RAW16:
+      step = 2;
+      break;
+    case HAL_PIXEL_FORMAT_RAW8:
+      step = 1;
+      break;
+    case HAL_PIXEL_FORMAT_RAW12:
+    case HAL_PIXEL_FORMAT_RAW10:
+      step = 0;
+      break;
+    default:
+      ALOGW("RawPlaneInfo is unsupported for format 0x%x", format);
+      return -EINVAL;
+  }
+
+  BufferInfo info(width, height, format);
+  uint32_t alignedWidth, alignedHeight;
+  GetAlignedWidthAndHeight(info, &alignedWidth, &alignedHeight);
+
+  uint32_t size = GetSize(info, alignedWidth, alignedHeight);
+
+  plane_info[0].component = (PlaneComponent)PLANE_COMPONENT_RAW;
+  plane_info[0].h_subsampling = 0;
+  plane_info[0].v_subsampling = 0;
+  plane_info[0].offset = 0;
+  plane_info[0].step = step;
+  plane_info[0].stride = width;
+  plane_info[0].stride_bytes = static_cast<int32_t>(alignedWidth);
+  plane_info[0].scanlines = height;
+  plane_info[0].size = size;
+
+  return 0;
+}
+
 // Explicitly defined UBWC formats
 bool IsUBwcFormat(int format) {
   switch (format) {
@@ -1326,10 +1359,7 @@
     case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
     case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
     case HAL_PIXEL_FORMAT_NV21_ZSL:
-    case HAL_PIXEL_FORMAT_RAW16:
     case HAL_PIXEL_FORMAT_Y16:
-    case HAL_PIXEL_FORMAT_RAW10:
-    case HAL_PIXEL_FORMAT_RAW8:
     case HAL_PIXEL_FORMAT_Y8:
       *plane_count = 2;
       GetYuvSPPlaneInfo(info, format, width, height, 1, plane_info);
@@ -1340,6 +1370,15 @@
       plane_info[1].v_subsampling = v_subsampling;
       break;
 
+    case HAL_PIXEL_FORMAT_RAW10:
+    case HAL_PIXEL_FORMAT_RAW8:
+    case HAL_PIXEL_FORMAT_RAW16:
+    case HAL_PIXEL_FORMAT_RAW12:
+      *plane_count = 1;
+      GetRawPlaneInfo(format, info.width, info.height, plane_info);
+      break;
+
+
     case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
       GetYuvSubSamplingFactor(format, &h_subsampling, &v_subsampling);
       if (flags & LAYOUT_INTERLACED_FLAG) {
@@ -1548,10 +1587,7 @@
       *h_subsampling = 1;
       *v_subsampling = 0;
       break;
-    case HAL_PIXEL_FORMAT_RAW16:
     case HAL_PIXEL_FORMAT_Y16:
-    case HAL_PIXEL_FORMAT_RAW12:
-    case HAL_PIXEL_FORMAT_RAW10:
     case HAL_PIXEL_FORMAT_Y8:
     case HAL_PIXEL_FORMAT_BLOB:
     case HAL_PIXEL_FORMAT_RAW_OPAQUE: