am e8d431e9: am 02bcd398: Merge "Emulator gralloc: Support YV12" into jb-mr1-dev

* commit 'e8d431e98a28ce01444118f729b044e6d746c26c':
  Emulator gralloc: Support YV12
diff --git a/tools/emulator/opengl/system/gralloc/gralloc.cpp b/tools/emulator/opengl/system/gralloc/gralloc.cpp
index dd5e515..515a879 100644
--- a/tools/emulator/opengl/system/gralloc/gralloc.cpp
+++ b/tools/emulator/opengl/system/gralloc/gralloc.cpp
@@ -236,7 +236,14 @@
             glType = GL_UNSIGNED_BYTE;
             break;
         case HAL_PIXEL_FORMAT_YCrCb_420_SP:
-            bpp = 0; // Chroma-subsampled format has fractional bpp
+            align = 1;
+            bpp = 1; // per-channel bpp
+            yuv_format = true;
+            // Not expecting to actually create any GL surfaces for this
+            break;
+        case HAL_PIXEL_FORMAT_YV12:
+            align = 16;
+            bpp = 1; // per-channel bpp
             yuv_format = true;
             // Not expecting to actually create any GL surfaces for this
             break;
@@ -254,9 +261,11 @@
         // keep space for image on guest memory if SW access is needed
         // or if the camera is doing writing
         if (yuv_format) {
-            // For NV21
-            ashmem_size += w * h * 3 / 2;
-            stride = w;
+            size_t yStride = (w*bpp + (align - 1)) & ~(align-1);
+            size_t uvStride = (yStride / 2 + (align - 1)) & ~(align-1);
+            size_t uvHeight = h / 2;
+            ashmem_size += yStride * h + 2 * (uvHeight * uvStride);
+            stride = yStride / bpp;
         } else {
             size_t bpr = (w*bpp + (align-1)) & ~(align-1);
             ashmem_size += (bpr * h);