From 12971f83cab2f56198bb16f00fbbbabfe84226ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tapani=20P=C3=A4lli?= Date: Wed, 30 May 2012 10:59:29 +0300 Subject: gralloc : use drmModeAddFB2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit start using drmModeAddFB2 API, this is enabler to create framebuffers with YUV pixel formats that can be shown on hardware overlay. Change-Id: I700c752ada119222573ab286a8b231092c3250c0 Signed-off-by: Tapani Pälli --- gralloc_drm_kms.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 6 deletions(-) (limited to 'gralloc_drm_kms.c') diff --git a/gralloc_drm_kms.c b/gralloc_drm_kms.c index 9847811..12bc065 100644 --- a/gralloc_drm_kms.c +++ b/gralloc_drm_kms.c @@ -33,6 +33,8 @@ #include "gralloc_drm.h" #include "gralloc_drm_priv.h" +#include + /* * Return true if a bo needs fb. */ @@ -43,21 +45,72 @@ int gralloc_drm_bo_need_fb(const struct gralloc_drm_bo_t *bo) } /* + * Modify pitches, offsets and handles according to + * the format and return corresponding drm format value + */ +static int resolve_drm_format(struct gralloc_drm_bo_t *bo, + uint32_t *pitches, uint32_t *offsets, uint32_t *handles) +{ + memset(pitches, 0, 4 * sizeof(uint32_t)); + memset(offsets, 0, 4 * sizeof(uint32_t)); + memset(handles, 0, 4 * sizeof(uint32_t)); + + pitches[0] = bo->handle->stride; + handles[0] = bo->fb_handle; + + switch(bo->handle->format) { + case HAL_PIXEL_FORMAT_RGB_888: + case HAL_PIXEL_FORMAT_RGBX_8888: + case HAL_PIXEL_FORMAT_BGRA_8888: + return DRM_FORMAT_ARGB8888; + case HAL_PIXEL_FORMAT_RGBA_8888: + return DRM_FORMAT_RGBA8888; + case HAL_PIXEL_FORMAT_RGB_565: + return DRM_FORMAT_RGB565; + case HAL_PIXEL_FORMAT_YV12: + + // U and V stride are half of Y plane + pitches[2] = pitches[0]/2; + pitches[1] = pitches[0]/2; + + // like I420 but U and V are in reverse order + offsets[2] = offsets[0] + + pitches[0] * bo->handle->height; + offsets[1] = offsets[2] + + pitches[2] * bo->handle->height/2; + + handles[1] = handles[2] = handles[0]; + + return DRM_FORMAT_YUV420; + default: + return 0; + } + return 0; +} + +/* * Add a fb object for a bo. */ int gralloc_drm_bo_add_fb(struct gralloc_drm_bo_t *bo) { - uint8_t bpp; + uint32_t pitches[4]; + uint32_t offsets[4]; + uint32_t handles[4]; if (bo->fb_id) return 0; - bpp = gralloc_drm_get_bpp(bo->handle->format) * 8; + int drm_format = resolve_drm_format(bo, pitches, offsets, handles); + + if (drm_format == 0) { + ALOGE("error resolving drm format"); + return -EINVAL; + } - return drmModeAddFB(bo->drm->fd, - bo->handle->width, bo->handle->height, bpp, bpp, - bo->handle->stride, bo->fb_handle, - (uint32_t *) &bo->fb_id); + return drmModeAddFB2(bo->drm->fd, + bo->handle->width, bo->handle->height, + drm_format, handles, pitches, offsets, + (uint32_t *) &bo->fb_id, 0); } /* -- cgit v1.1