diff options
author | Varad Gautam <varadgautam@gmail.com> | 2015-07-13 12:44:22 +0530 |
---|---|---|
committer | Varad Gautam <varadgautam@gmail.com> | 2015-07-14 10:51:00 +0530 |
commit | a62ff5d9aa97428cc58290258ff8d1147f7ededf (patch) | |
tree | 7a1bd262e5a8b3a0c36ad71472df95f6538324b0 | |
parent | 160414c862f795bed5298825266fe90dbf28a815 (diff) | |
download | drm_gralloc-a62ff5d9aa97428cc58290258ff8d1147f7ededf.tar.gz |
freedreno: add prime_fd support to bo handles
* registerBuffer(): import handles using dma-buf fd instead of flink
* alloc(): locally created bo-s carry both fd and flink
enabled using DMABUF flag in Android.mk.
Signed-off-by: Varad Gautam <varadgautam@gmail.com>
-rw-r--r-- | Android.mk | 2 | ||||
-rw-r--r-- | gralloc_drm.c | 11 | ||||
-rw-r--r-- | gralloc_drm.h | 1 | ||||
-rw-r--r-- | gralloc_drm_freedreno.c | 24 | ||||
-rw-r--r-- | gralloc_drm_handle.h | 4 |
5 files changed, 40 insertions, 2 deletions
@@ -97,7 +97,7 @@ LOCAL_SHARED_LIBRARIES := \ ifneq ($(filter $(freedreno_drivers), $(DRM_GPU_DRIVERS)),) LOCAL_SRC_FILES += gralloc_drm_freedreno.c -LOCAL_CFLAGS += -DENABLE_FREEDRENO +LOCAL_CFLAGS += -DENABLE_FREEDRENO -DDMABUF LOCAL_SHARED_LIBRARIES += libdrm_freedreno endif diff --git a/gralloc_drm.c b/gralloc_drm.c index 3478dde..4703238 100644 --- a/gralloc_drm.c +++ b/gralloc_drm.c @@ -213,7 +213,11 @@ static struct gralloc_drm_bo_t *validate_handle(buffer_handle_t _handle, return NULL; /* create the struct gralloc_drm_bo_t locally */ +#ifdef DMABUF + if (handle->prime_fd >= 0) +#else if (handle->name) +#endif bo = drm->drv->alloc(drm->drv, handle); else /* an invalid handle */ bo = NULL; @@ -272,6 +276,7 @@ static struct gralloc_drm_handle_t *create_bo_handle(int width, handle->base.numInts = GRALLOC_DRM_HANDLE_NUM_INTS; handle->base.numFds = GRALLOC_DRM_HANDLE_NUM_FDS; + handle->prime_fd = -1; handle->magic = GRALLOC_DRM_HANDLE_MAGIC; handle->width = width; handle->height = height; @@ -366,6 +371,12 @@ buffer_handle_t gralloc_drm_bo_get_handle(struct gralloc_drm_bo_t *bo, int *stri return &bo->handle->base; } +int gralloc_drm_get_prime_fd(buffer_handle_t _handle) +{ + struct gralloc_drm_handle_t *handle = gralloc_drm_handle(_handle); + return (handle) ? handle->prime_fd : -1; +} + int gralloc_drm_get_gem_handle(buffer_handle_t _handle) { struct gralloc_drm_handle_t *handle = gralloc_drm_handle(_handle); diff --git a/gralloc_drm.h b/gralloc_drm.h index e53ecd9..fd291dd 100644 --- a/gralloc_drm.h +++ b/gralloc_drm.h @@ -125,6 +125,7 @@ void gralloc_drm_bo_decref(struct gralloc_drm_bo_t *bo); struct gralloc_drm_bo_t *gralloc_drm_bo_from_handle(buffer_handle_t handle); buffer_handle_t gralloc_drm_bo_get_handle(struct gralloc_drm_bo_t *bo, int *stride); +int gralloc_drm_get_prime_fd(buffer_handle_t _handle); int gralloc_drm_get_gem_handle(buffer_handle_t handle); void gralloc_drm_resolve_format(buffer_handle_t _handle, uint32_t *pitches, uint32_t *offsets, uint32_t *handles); unsigned int planes_for_format(struct gralloc_drm_t *drm, int hal_format); diff --git a/gralloc_drm_freedreno.c b/gralloc_drm_freedreno.c index 9b23ac9..3ab5431 100644 --- a/gralloc_drm_freedreno.c +++ b/gralloc_drm_freedreno.c @@ -83,6 +83,17 @@ fd_alloc(struct gralloc_drm_drv_t *drv, struct gralloc_drm_handle_t *handle) if (!fd_buf) return NULL; +#ifdef DMABUF + if (handle->prime_fd >= 0) { + fd_buf->bo = fd_bo_from_dmabuf(info->dev, handle->prime_fd); + if (!fd_buf->bo) { + ALOGE("failed to create fd bo from dma-buf %u", + handle->prime_fd); + free(fd_buf); + return NULL; + } + } +#else if (handle->name) { fd_buf->bo = fd_bo_from_name(info->dev, handle->name); if (!fd_buf->bo) { @@ -92,6 +103,7 @@ fd_alloc(struct gralloc_drm_drv_t *drv, struct gralloc_drm_handle_t *handle) return NULL; } } +#endif else { int width, height, pitch; width = handle->width; @@ -107,6 +119,18 @@ fd_alloc(struct gralloc_drm_drv_t *drv, struct gralloc_drm_handle_t *handle) return NULL; } +#ifdef DMABUF + int fd = fd_bo_dmabuf(fd_buf->bo); + if(fd >= 0) { + handle->prime_fd = fd; + } + else { + ALOGE("failed to set prime fd"); + fd_bo_del(fd_buf->bo); + free(fd_buf); + return NULL; + } +#endif if (fd_bo_get_name(fd_buf->bo, (uint32_t *) &handle->name)) { ALOGE("failed to flink fd bo"); fd_bo_del(fd_buf->bo); diff --git a/gralloc_drm_handle.h b/gralloc_drm_handle.h index 7fc4746..7e4aa07 100644 --- a/gralloc_drm_handle.h +++ b/gralloc_drm_handle.h @@ -38,7 +38,9 @@ struct gralloc_drm_handle_t { #define GRALLOC_DRM_HANDLE_MAGIC 0x12345678 #define GRALLOC_DRM_HANDLE_NUM_INTS 10 -#define GRALLOC_DRM_HANDLE_NUM_FDS 0 +#define GRALLOC_DRM_HANDLE_NUM_FDS 1 + int prime_fd; + int magic; int width; |