From 3461561ccf3fe10aa6d7e9b74a0a27ad76380410 Mon Sep 17 00:00:00 2001 From: Eino-Ville Talvala Date: Wed, 11 Jul 2012 17:20:06 -0700 Subject: [PATCH] gralloc: Support HAL_PIXEL_FORMAT_YCrCb_420_SP (NV21) This is needed for Camera HAL2 video recording. Bug: 6243944 Change-Id: I47a3e65117881612fb95068a80f811cc8378fbc6 --- .../emulator/opengl/system/gralloc/gralloc.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tools/emulator/opengl/system/gralloc/gralloc.cpp b/tools/emulator/opengl/system/gralloc/gralloc.cpp index 90781f1ae..3953f9c33 100644 --- a/tools/emulator/opengl/system/gralloc/gralloc.cpp +++ b/tools/emulator/opengl/system/gralloc/gralloc.cpp @@ -145,6 +145,7 @@ static int gralloc_alloc(alloc_device_t* dev, return -EINVAL; } bool sw_read = (0 != (usage & GRALLOC_USAGE_SW_READ_MASK)); + bool yuv_format = false; int ashmem_size = 0; int stride = w; @@ -203,6 +204,11 @@ static int gralloc_alloc(alloc_device_t* dev, glFormat = GL_LUMINANCE; glType = GL_UNSIGNED_BYTE; break; + case HAL_PIXEL_FORMAT_YCrCb_420_SP: + bpp = 0; // Chroma-subsampled format has fractional bpp + yuv_format = true; + // Not expecting to actually create any GL surfaces for this + break; default: return -EINVAL; } @@ -215,9 +221,15 @@ static int gralloc_alloc(alloc_device_t* dev, if (sw_read || sw_write) { // keep space for image on guest memory if SW access is needed - size_t bpr = (w*bpp + (align-1)) & ~(align-1); - ashmem_size += (bpr * h); - stride = bpr / bpp; + if (yuv_format) { + // For NV21 + ashmem_size += w * h * 3 / 2; + stride = w; + } else { + size_t bpr = (w*bpp + (align-1)) & ~(align-1); + ashmem_size += (bpr * h); + stride = bpr / bpp; + } } D("gralloc_alloc ashmem_size=%d, stride=%d, tid %d\n", ashmem_size, stride,