From f4bfdbaee1fa0212928b83c839a178872bd7f688 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Marchesin?= Date: Thu, 5 Nov 2015 11:43:59 -0800 Subject: [PATCH] Implement gbm_bo_import MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit We only support GBM_BO_IMPORT_FD for now. BUG=chromium:541558 TEST=run unit test (graphics_Gbm) Change-Id: I1232cfdb57efdbbe9c3243b74c4fc5bf20cd8c08 Signed-off-by: Stphane Marchesin Reviewed-on: https://chromium-review.googlesource.com/311203 Commit-Ready: Ilja Friedel Tested-by: Stéphane Marchesin Reviewed-by: Ilja Friedel Reviewed-by: David Reveman Reviewed-by: Haixia Shi --- gbm.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/gbm.c b/gbm.c index 861c174..10b0bcd 100644 --- a/gbm.c +++ b/gbm.c @@ -4,13 +4,15 @@ * found in the LICENSE file. */ -#include +#include #include +#include +#include #include -#include #include #include "gbm_priv.h" +#include "helpers.h" #include "util.h" extern struct gbm_driver gbm_driver_cirrus; @@ -177,12 +179,11 @@ PUBLIC void gbm_surface_release_buffer(struct gbm_surface *surface, { } -PUBLIC struct gbm_bo *gbm_bo_create(struct gbm_device *gbm, uint32_t width, - uint32_t height, uint32_t format, - uint32_t flags) +static struct gbm_bo *gbm_bo_new(struct gbm_device *gbm, + uint32_t width, uint32_t height, + uint32_t format, uint32_t stride) { struct gbm_bo *bo; - int ret; bo = (struct gbm_bo*) malloc(sizeof(*bo)); if (!bo) @@ -191,12 +192,27 @@ PUBLIC struct gbm_bo *gbm_bo_create(struct gbm_device *gbm, uint32_t width, bo->gbm = gbm; bo->width = width; bo->height = height; - bo->stride = 0; + bo->stride = stride; bo->format = format; bo->handle.u32 = 0; bo->destroy_user_data = NULL; bo->user_data = NULL; + return bo; +} + +PUBLIC struct gbm_bo *gbm_bo_create(struct gbm_device *gbm, uint32_t width, + uint32_t height, uint32_t format, + uint32_t flags) +{ + struct gbm_bo *bo; + int ret; + + bo = gbm_bo_new(gbm, width, height, format, + width * gbm_bytes_from_format(format)); + if (!bo) + return NULL; + ret = gbm->driver->bo_create(bo, width, height, format, flags); if (ret) { free(bo); @@ -218,6 +234,41 @@ PUBLIC void gbm_bo_destroy(struct gbm_bo *bo) free(bo); } +PUBLIC struct gbm_bo * +gbm_bo_import(struct gbm_device *gbm, uint32_t type, + void *buffer, uint32_t usage) +{ + struct gbm_import_fd_data *fd_data = buffer; + struct gbm_bo *bo; + struct drm_prime_handle prime_handle; + int ret; + + if (type != GBM_BO_IMPORT_FD) + return NULL; + + if (!gbm_device_is_format_supported(gbm, fd_data->format, usage)) + return NULL; + + bo = gbm_bo_new(gbm, fd_data->width, fd_data->height, fd_data->format, + fd_data->stride); + if (!bo) + return NULL; + + prime_handle.fd = fd_data->fd; + + ret = drmIoctl(bo->gbm->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &prime_handle); + if (ret) { + fprintf(stderr, "minigbm: DRM_IOCTL_PRIME_FD_TO_HANDLE failed " + "(fd=%u)\n", prime_handle.fd); + free(bo); + return NULL; + } + + bo->handle.u32 = prime_handle.handle; + + return bo; +} + PUBLIC uint32_t gbm_bo_get_width(struct gbm_bo *bo) { -- 2.11.0