OSDN Git Service

drm_gralloc: Implement lock_ycbcr method
authorTomasz Figa <tfiga@google.com>
Tue, 8 Sep 2015 06:19:37 +0000 (15:19 +0900)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Wed, 23 Aug 2017 08:33:55 +0000 (16:33 +0800)
It is needed for flexible YUV formats. Currently only flexible YUV420 is
supported and always maps to NV12 format.

Change-Id: I4b2f2d1cdd3f2495b63d84438130dc7ab99fbf8c

gralloc.c

index b338ab9..b458ac2 100644 (file)
--- a/gralloc.c
+++ b/gralloc.c
@@ -156,6 +156,46 @@ unlock:
        return err;
 }
 
+static int drm_mod_lock_ycbcr(const gralloc_module_t *mod, buffer_handle_t bhandle,
+               int usage, int x, int y, int w, int h, struct android_ycbcr *ycbcr)
+{
+       struct gralloc_drm_handle_t *handle;
+       struct gralloc_drm_bo_t *bo;
+       void *ptr;
+       int err;
+
+       bo = gralloc_drm_bo_from_handle(bhandle);
+       if (!bo)
+               return -EINVAL;
+       handle = bo->handle;
+
+       switch(handle->format) {
+       case HAL_PIXEL_FORMAT_YCbCr_420_888:
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       err = gralloc_drm_bo_lock(bo, usage, x, y, w, h, &ptr);
+       if (err)
+               return err;
+
+       switch(handle->format) {
+       case HAL_PIXEL_FORMAT_YCbCr_420_888:
+               ycbcr->y = ptr;
+               ycbcr->cb = (uint8_t *)ptr + handle->stride * handle->height;
+               ycbcr->cr = (uint8_t *)ycbcr->cb + 1;
+               ycbcr->ystride = handle->stride;
+               ycbcr->cstride = handle->stride;
+               ycbcr->chroma_step = 2;
+               break;
+       default:
+               break;
+       }
+
+       return 0;
+}
+
 static int drm_mod_unlock(const gralloc_module_t *mod, buffer_handle_t handle)
 {
        struct drm_module_t *dmod = (struct drm_module_t *) mod;
@@ -390,7 +430,8 @@ struct drm_module_t HAL_MODULE_INFO_SYM = {
                .unregisterBuffer = drm_mod_unregister_buffer,
                .lock = drm_mod_lock,
                .unlock = drm_mod_unlock,
-               .perform = drm_mod_perform
+               .perform = drm_mod_perform,
+               .lock_ycbcr = drm_mod_lock_ycbcr,
        },
        .hwc_reserve_plane = gralloc_drm_reserve_plane,
        .hwc_disable_planes = gralloc_drm_disable_planes,