OSDN Git Service

add support for YUV formats honeycomb-x86
authorChia-I Wu <olvaffe@gmail.com>
Thu, 27 Oct 2011 10:01:23 +0000 (18:01 +0800)
committerChia-I Wu <olvaffe@gmail.com>
Thu, 27 Oct 2011 10:40:45 +0000 (18:40 +0800)
gralloc_drm.h
gralloc_drm_intel.c
gralloc_drm_nouveau.c
gralloc_drm_pipe.c
gralloc_drm_radeon.c

index b9c0de8..85e3675 100644 (file)
@@ -61,8 +61,15 @@ static inline int gralloc_drm_get_bpp(int format)
        case HAL_PIXEL_FORMAT_RGB_565:
        case HAL_PIXEL_FORMAT_RGBA_5551:
        case HAL_PIXEL_FORMAT_RGBA_4444:
+       case HAL_PIXEL_FORMAT_YCbCr_422_I:
                bpp = 2;
                break;
+       /* planar; only Y is considered */
+       case HAL_PIXEL_FORMAT_YV12:
+       case HAL_PIXEL_FORMAT_YCbCr_422_SP:
+       case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+               bpp = 1;
+               break;
        default:
                bpp = 0;
                break;
@@ -71,6 +78,37 @@ static inline int gralloc_drm_get_bpp(int format)
        return bpp;
 }
 
+static inline void gralloc_drm_align_geometry(int format, int *width, int *height)
+{
+       int align_w = 1, align_h = 1, extra_height_div = 0;
+
+       switch (format) {
+       case HAL_PIXEL_FORMAT_YV12:
+               align_w = 32;
+               align_h = 2;
+               extra_height_div = 2;
+               break;
+       case HAL_PIXEL_FORMAT_YCbCr_422_SP:
+               align_w = 2;
+               extra_height_div = 1;
+               break;
+       case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+               align_w = 2;
+               align_h = 2;
+               extra_height_div = 2;
+               break;
+       case HAL_PIXEL_FORMAT_YCbCr_422_I:
+               align_w = 2;
+               break;
+       }
+
+       *width = (*width + align_w - 1) & ~(align_w - 1);
+       *height = (*height + align_h - 1) & ~(align_h - 1);
+
+       if (extra_height_div)
+               *height += *height / extra_height_div;
+}
+
 int gralloc_drm_handle_register(buffer_handle_t handle, struct gralloc_drm_t *drm);
 int gralloc_drm_handle_unregister(buffer_handle_t handle);
 
index 6185fd4..2bf9524 100644 (file)
@@ -309,6 +309,11 @@ static drm_intel_bo *alloc_ibo(struct intel_info *info,
                return NULL;
        }
 
+       aligned_width = handle->width;
+       aligned_height = handle->height;
+       gralloc_drm_align_geometry(handle->format,
+                       &aligned_width, &aligned_height);
+
        if (handle->usage & GRALLOC_USAGE_HW_FB) {
                unsigned long max_stride;
 
@@ -319,8 +324,7 @@ static drm_intel_bo *alloc_ibo(struct intel_info *info,
                        max_stride /= 2;
 
                name = "gralloc-fb";
-               aligned_width = (handle->width + 63) & ~63;
-               aligned_height = handle->height;
+               aligned_width = (aligned_width + 63) & ~63;
                flags = BO_ALLOC_FOR_RENDER;
 
                *tiling = I915_TILING_X;
@@ -368,13 +372,11 @@ static drm_intel_bo *alloc_ibo(struct intel_info *info,
                if (handle->usage & GRALLOC_USAGE_HW_TEXTURE) {
                        name = "gralloc-texture";
                        /* see 2D texture layout of DRI drivers */
-                       aligned_width = (handle->width + 3) & ~3;
-                       aligned_height = (handle->height + 1) & ~1;
+                       aligned_width = (aligned_width + 3) & ~3;
+                       aligned_height = (aligned_height + 1) & ~1;
                }
                else {
                        name = "gralloc-buffer";
-                       aligned_width = handle->width;
-                       aligned_height = handle->height;
                }
 
                if (handle->usage & GRALLOC_USAGE_HW_RENDER)
index 8f347a1..a3ef333 100644 (file)
@@ -198,9 +198,13 @@ nouveau_alloc(struct gralloc_drm_drv_t *drv, struct gralloc_drm_handle_t *handle
                }
        }
        else {
-               int pitch;
+               int width, height, pitch;
 
-               nb->bo = alloc_bo(info, handle->width, handle->height,
+               width = handle->width;
+               height = handle->height;
+               gralloc_drm_align_geometry(handle->format, &width, &height);
+
+               nb->bo = alloc_bo(info, width, height,
                                cpp, handle->usage, &pitch);
                if (!nb->bo) {
                        LOGE("failed to allocate nouveau bo %dx%dx%d",
index 2b39815..a66ce1a 100644 (file)
@@ -76,6 +76,9 @@ static enum pipe_format get_pipe_format(int format)
                break;
        case HAL_PIXEL_FORMAT_RGBA_5551:
        case HAL_PIXEL_FORMAT_RGBA_4444:
+       case HAL_PIXEL_FORMAT_YV12:
+       case HAL_PIXEL_FORMAT_YCbCr_422_SP:
+       case HAL_PIXEL_FORMAT_YCrCb_420_SP:
        default:
                fmt = PIPE_FORMAT_NONE;
                break;
index c8cfb8c..8d27bf9 100644 (file)
@@ -201,16 +201,17 @@ static struct radeon_bo *radeon_alloc(struct radeon_info *info,
        tiling = radeon_get_tiling(info, handle);
        domain = RADEON_GEM_DOMAIN_VRAM;
 
+       aligned_width = handle->width;
+       aligned_height = handle->height;
+       gralloc_drm_align_geometry(handle->format,
+                       &aligned_width, &aligned_height);
+
        if (handle->usage & (GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_HW_TEXTURE)) {
-               aligned_width = ALIGN(handle->width,
+               aligned_width = ALIGN(aligned_width,
                                radeon_get_pitch_align(info, cpp, tiling));
-               aligned_height = ALIGN(handle->height,
+               aligned_height = ALIGN(aligned_height,
                                radeon_get_height_align(info, tiling));
        }
-       else {
-               aligned_width = handle->width;
-               aligned_height = handle->height;
-       }
 
        if (!(handle->usage & (GRALLOC_USAGE_HW_FB |
                               GRALLOC_USAGE_HW_RENDER)) &&