Allocate enough memory for HAL_PIXL_FORMAT_YV12
authorRebecca Schultz Zavin <rebecca@android.com>
Thu, 1 Nov 2012 00:05:48 +0000 (17:05 -0700)
committerRebecca Schultz Zavin <rebecca@android.com>
Thu, 1 Nov 2012 04:37:01 +0000 (21:37 -0700)
Previously we were not allocating enough memory to align
the uv planes to 16 pixels.
We were allocating:
h * align(w,16) * 3 / 2 bytes
This should be:
h * align(w,16) + h * align(align(w,16)/2, 16)

Bug: 7431048
Change-Id: Iaba969795e8d20c29ee0b703af5dd884a4c88d2e
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
gralloc/gralloc.cpp

index d10dc274af7484b3aa8bfb4785e19e15b25eb3b2..f3610f3625885852f2424d81a160a20ce8ee8139 100644 (file)
@@ -193,16 +193,17 @@ static int gralloc_alloc_framework_yuv(int ionfd, int w, int h, int format,
     switch (format) {
         case HAL_PIXEL_FORMAT_YV12:
             *stride = ALIGN(w, 16);
+            size = (*stride * h) + (ALIGN(*stride / 2, 16) * h);
             break;
         case HAL_PIXEL_FORMAT_YCrCb_420_SP:
             *stride = w;
+            size = *stride * h * 3 / 2;
             break;
         default:
             ALOGE("invalid yuv format %d\n", format);
             return -EINVAL;
     }
 
-    size = *stride * h * 3 / 2;
     err = ion_alloc_fd(ionfd, size, 0, 1 << ION_HEAP_TYPE_SYSTEM,
                        ion_flags, &fd);
     if (err)