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
This commit is contained in:
Jonas Ådahl 2020-04-29 16:26:52 +02:00 committed by Georges Basile Stavracas Neto
parent c65f63b647
commit 4434a17d08
3 changed files with 101 additions and 4 deletions

View File

@ -40,6 +40,11 @@ struct _CoglDmaBufHandle
{ {
CoglFramebuffer *framebuffer; CoglFramebuffer *framebuffer;
int dmabuf_fd; int dmabuf_fd;
int width;
int height;
int stride;
int offset;
int bpp;
gpointer user_data; gpointer user_data;
GDestroyNotify destroy_func; GDestroyNotify destroy_func;
}; };
@ -47,6 +52,11 @@ struct _CoglDmaBufHandle
CoglDmaBufHandle * CoglDmaBufHandle *
cogl_dma_buf_handle_new (CoglFramebuffer *framebuffer, cogl_dma_buf_handle_new (CoglFramebuffer *framebuffer,
int dmabuf_fd, int dmabuf_fd,
int width,
int height,
int stride,
int offset,
int bpp,
gpointer user_data, gpointer user_data,
GDestroyNotify destroy_func) GDestroyNotify destroy_func)
{ {
@ -61,6 +71,12 @@ cogl_dma_buf_handle_new (CoglFramebuffer *framebuffer,
dmabuf_handle->user_data = user_data; dmabuf_handle->user_data = user_data;
dmabuf_handle->destroy_func = destroy_func; 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; return dmabuf_handle;
} }
@ -92,3 +108,32 @@ cogl_dma_buf_handle_get_fd (CoglDmaBufHandle *dmabuf_handle)
return dmabuf_handle->dmabuf_fd; 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;
}

View File

@ -46,7 +46,12 @@
COGL_EXPORT CoglDmaBufHandle * COGL_EXPORT CoglDmaBufHandle *
cogl_dma_buf_handle_new (CoglFramebuffer *framebuffer, cogl_dma_buf_handle_new (CoglFramebuffer *framebuffer,
int dmabuf_fd, int dmabuf_fd,
gpointer data, int width,
int height,
int stride,
int offset,
int bpp,
gpointer user_data,
GDestroyNotify destroy_func); GDestroyNotify destroy_func);
/** /**
@ -79,5 +84,44 @@ cogl_dma_buf_handle_get_framebuffer (CoglDmaBufHandle *dmabuf_handle);
COGL_EXPORT int COGL_EXPORT int
cogl_dma_buf_handle_get_fd (CoglDmaBufHandle *dmabuf_handle); 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__ */ #endif /* __COGL_DMA_BUF_HANDLE_H__ */

View File

@ -2169,6 +2169,9 @@ meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer,
{ {
CoglFramebuffer *dmabuf_fb; CoglFramebuffer *dmabuf_fb;
struct gbm_bo *new_bo; struct gbm_bo *new_bo;
int stride;
int offset;
int bpp;
int dmabuf_fd = -1; int dmabuf_fd = -1;
new_bo = gbm_bo_create (renderer_gpu_data->gbm.device, 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; 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_fb = create_dma_buf_framebuffer (renderer_native,
dmabuf_fd, dmabuf_fd,
width, height, width, height,
gbm_bo_get_stride (new_bo), stride,
gbm_bo_get_offset (new_bo, 0), offset,
DRM_FORMAT_MOD_LINEAR, DRM_FORMAT_MOD_LINEAR,
DRM_FORMAT_XRGB8888, DRM_FORMAT_XRGB8888,
error); error);
@ -2204,7 +2210,9 @@ meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer,
if (!dmabuf_fb) if (!dmabuf_fb)
return NULL; 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); (GDestroyNotify) gbm_bo_destroy);
} }
break; break;