From 4434a17d0895462f084309627a216de6721cce5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 29 Apr 2020 16:26:52 +0200 Subject: [PATCH] cogl/dma-buf-handle: Pass more metadata to handle constructor Could be useful would one want to mmap the dmabuf and deal with its content manually in CPU space. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1237 --- cogl/cogl/cogl-dma-buf-handle.c | 45 +++++++++++++++++++++ cogl/cogl/cogl-dma-buf-handle.h | 46 +++++++++++++++++++++- src/backends/native/meta-renderer-native.c | 14 +++++-- 3 files changed, 101 insertions(+), 4 deletions(-) diff --git a/cogl/cogl/cogl-dma-buf-handle.c b/cogl/cogl/cogl-dma-buf-handle.c index 4a8f709f2..d8b4e57c5 100644 --- a/cogl/cogl/cogl-dma-buf-handle.c +++ b/cogl/cogl/cogl-dma-buf-handle.c @@ -40,6 +40,11 @@ struct _CoglDmaBufHandle { CoglFramebuffer *framebuffer; int dmabuf_fd; + int width; + int height; + int stride; + int offset; + int bpp; gpointer user_data; GDestroyNotify destroy_func; }; @@ -47,6 +52,11 @@ struct _CoglDmaBufHandle CoglDmaBufHandle * cogl_dma_buf_handle_new (CoglFramebuffer *framebuffer, int dmabuf_fd, + int width, + int height, + int stride, + int offset, + int bpp, gpointer user_data, GDestroyNotify destroy_func) { @@ -61,6 +71,12 @@ cogl_dma_buf_handle_new (CoglFramebuffer *framebuffer, dmabuf_handle->user_data = user_data; dmabuf_handle->destroy_func = destroy_func; + dmabuf_handle->width = width; + dmabuf_handle->height = height; + dmabuf_handle->stride = stride; + dmabuf_handle->offset = offset; + dmabuf_handle->bpp = bpp; + return dmabuf_handle; } @@ -92,3 +108,32 @@ cogl_dma_buf_handle_get_fd (CoglDmaBufHandle *dmabuf_handle) return dmabuf_handle->dmabuf_fd; } +int +cogl_dma_buf_handle_get_width (CoglDmaBufHandle *dmabuf_handle) +{ + return dmabuf_handle->width; +} + +int +cogl_dma_buf_handle_get_height (CoglDmaBufHandle *dmabuf_handle) +{ + return dmabuf_handle->height; +} + +int +cogl_dma_buf_handle_get_stride (CoglDmaBufHandle *dmabuf_handle) +{ + return dmabuf_handle->stride; +} + +int +cogl_dma_buf_handle_get_offset (CoglDmaBufHandle *dmabuf_handle) +{ + return dmabuf_handle->offset; +} + +int +cogl_dma_buf_handle_get_bpp (CoglDmaBufHandle *dmabuf_handle) +{ + return dmabuf_handle->bpp; +} diff --git a/cogl/cogl/cogl-dma-buf-handle.h b/cogl/cogl/cogl-dma-buf-handle.h index 87a2ce2f1..b00c5f36b 100644 --- a/cogl/cogl/cogl-dma-buf-handle.h +++ b/cogl/cogl/cogl-dma-buf-handle.h @@ -46,7 +46,12 @@ COGL_EXPORT CoglDmaBufHandle * cogl_dma_buf_handle_new (CoglFramebuffer *framebuffer, int dmabuf_fd, - gpointer data, + int width, + int height, + int stride, + int offset, + int bpp, + gpointer user_data, GDestroyNotify destroy_func); /** @@ -79,5 +84,44 @@ cogl_dma_buf_handle_get_framebuffer (CoglDmaBufHandle *dmabuf_handle); COGL_EXPORT int cogl_dma_buf_handle_get_fd (CoglDmaBufHandle *dmabuf_handle); +/** + * cogl_dmabuf_handle_get_width: (skip) + * + * Returns: the buffer width + */ +COGL_EXPORT int +cogl_dma_buf_handle_get_width (CoglDmaBufHandle *dmabuf_handle); + +/** + * cogl_dmabuf_handle_get_height: (skip) + * + * Returns: the buffer height + */ +COGL_EXPORT int +cogl_dma_buf_handle_get_height (CoglDmaBufHandle *dmabuf_handle); + +/** + * cogl_dmabuf_handle_get_stride: (skip) + * + * Returns: the buffer stride + */ +COGL_EXPORT int +cogl_dma_buf_handle_get_stride (CoglDmaBufHandle *dmabuf_handle); + +/** + * cogl_dmabuf_handle_get_offset: (skip) + * + * Returns: the buffer offset + */ +COGL_EXPORT int +cogl_dma_buf_handle_get_offset (CoglDmaBufHandle *dmabuf_handle); + +/** + * cogl_dmabuf_handle_get_bpp: (skip) + * + * Returns: the number of bytes per pixel + */ +COGL_EXPORT int +cogl_dma_buf_handle_get_bpp (CoglDmaBufHandle *dmabuf_handle); #endif /* __COGL_DMA_BUF_HANDLE_H__ */ diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c index 50e606f7e..a717012ce 100644 --- a/src/backends/native/meta-renderer-native.c +++ b/src/backends/native/meta-renderer-native.c @@ -2169,6 +2169,9 @@ meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer, { CoglFramebuffer *dmabuf_fb; struct gbm_bo *new_bo; + int stride; + int offset; + int bpp; int dmabuf_fd = -1; new_bo = gbm_bo_create (renderer_gpu_data->gbm.device, @@ -2192,11 +2195,14 @@ meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer, return NULL; } + stride = gbm_bo_get_stride (new_bo); + offset = gbm_bo_get_offset (new_bo, 0); + bpp = 4; dmabuf_fb = create_dma_buf_framebuffer (renderer_native, dmabuf_fd, width, height, - gbm_bo_get_stride (new_bo), - gbm_bo_get_offset (new_bo, 0), + stride, + offset, DRM_FORMAT_MOD_LINEAR, DRM_FORMAT_XRGB8888, error); @@ -2204,7 +2210,9 @@ meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer, if (!dmabuf_fb) return NULL; - return cogl_dma_buf_handle_new (dmabuf_fb, dmabuf_fd, new_bo, + return cogl_dma_buf_handle_new (dmabuf_fb, dmabuf_fd, + width, height, stride, offset, bpp, + new_bo, (GDestroyNotify) gbm_bo_destroy); } break;