render-device: Update DMA-BUF allocation API to allow modifiers

meta_render_device_gbm_allocate_dma_buf() function is updated to take a
list of modifiers. If no modifiers are specified, the modifier is
selected by the allocator, and implicit modifiers are used to import the
created DMA-BUF.

Co-authored-by: Jonas Ådahl <jadahl@gmail.com>
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3537>
This commit is contained in:
Doğukan Korkmaztürk 2024-01-19 17:28:15 -05:00
parent ab1322781d
commit 34d00d769e
12 changed files with 76 additions and 22 deletions

View File

@ -758,6 +758,8 @@ cogl_renderer_foreach_output (CoglRenderer *renderer,
CoglDmaBufHandle * CoglDmaBufHandle *
cogl_renderer_create_dma_buf (CoglRenderer *renderer, cogl_renderer_create_dma_buf (CoglRenderer *renderer,
CoglPixelFormat format, CoglPixelFormat format,
uint64_t *modifiers,
int n_modifiers,
int width, int width,
int height, int height,
GError **error) GError **error)
@ -765,7 +767,9 @@ cogl_renderer_create_dma_buf (CoglRenderer *renderer,
const CoglWinsysVtable *winsys = _cogl_renderer_get_winsys (renderer); const CoglWinsysVtable *winsys = _cogl_renderer_get_winsys (renderer);
if (winsys->renderer_create_dma_buf) if (winsys->renderer_create_dma_buf)
return winsys->renderer_create_dma_buf (renderer, format, return winsys->renderer_create_dma_buf (renderer,
format,
modifiers, n_modifiers,
width, height, width, height,
error); error);

View File

@ -347,6 +347,8 @@ cogl_renderer_foreach_output (CoglRenderer *renderer,
* cogl_renderer_create_dma_buf: (skip) * cogl_renderer_create_dma_buf: (skip)
* @renderer: A #CoglRenderer * @renderer: A #CoglRenderer
* @format: A #CoglPixelFormat * @format: A #CoglPixelFormat
* @modifiers: array of DRM format modifiers
* @n_modifiers: length of modifiers array
* @width: width of the new * @width: width of the new
* @height: height of the new * @height: height of the new
* @error: (nullable): return location for a #GError * @error: (nullable): return location for a #GError
@ -355,6 +357,9 @@ cogl_renderer_foreach_output (CoglRenderer *renderer,
* format @format, and exports the new framebuffer's DMA buffer * format @format, and exports the new framebuffer's DMA buffer
* handle. * handle.
* *
* Passing an empty modifier array (passing a 0 n_modifiers) means implicit
* modifiers will be used.
*
* Returns: (nullable)(transfer full): a #CoglDmaBufHandle. The * Returns: (nullable)(transfer full): a #CoglDmaBufHandle. The
* return result must be released with cogl_dma_buf_handle_free() * return result must be released with cogl_dma_buf_handle_free()
* after use. * after use.
@ -362,6 +367,8 @@ cogl_renderer_foreach_output (CoglRenderer *renderer,
COGL_EXPORT CoglDmaBufHandle * COGL_EXPORT CoglDmaBufHandle *
cogl_renderer_create_dma_buf (CoglRenderer *renderer, cogl_renderer_create_dma_buf (CoglRenderer *renderer,
CoglPixelFormat format, CoglPixelFormat format,
uint64_t *modifiers,
int n_modifiers,
int width, int width,
int height, int height,
GError **error); GError **error);

View File

@ -91,6 +91,8 @@ typedef struct _CoglWinsysVtable
CoglDmaBufHandle * CoglDmaBufHandle *
(*renderer_create_dma_buf) (CoglRenderer *renderer, (*renderer_create_dma_buf) (CoglRenderer *renderer,
CoglPixelFormat format, CoglPixelFormat format,
uint64_t *modifiers,
int n_modifiers,
int width, int width,
int height, int height,
GError **error); GError **error);

View File

@ -129,6 +129,7 @@ meta_screen_cast_create_dma_buf_handle (MetaScreenCast *screen_cast,
dmabuf_handle = cogl_renderer_create_dma_buf (cogl_renderer, dmabuf_handle = cogl_renderer_create_dma_buf (cogl_renderer,
format, format,
NULL, 0,
width, height, width, height,
&error); &error);
if (!dmabuf_handle) if (!dmabuf_handle)

View File

@ -186,6 +186,7 @@ maybe_disable_screen_cast_dma_bufs (MetaBackendNative *native)
dmabuf_handle = cogl_renderer_create_dma_buf (cogl_renderer, dmabuf_handle = cogl_renderer_create_dma_buf (cogl_renderer,
COGL_PIXEL_FORMAT_BGRX_8888, COGL_PIXEL_FORMAT_BGRX_8888,
NULL, 0,
1, 1, 1, 1,
&error); &error);
if (!dmabuf_handle) if (!dmabuf_handle)

View File

@ -941,6 +941,7 @@ copy_shared_framebuffer_primary_gpu (CoglOnscreen *onscre
int dmabuf_fd; int dmabuf_fd;
g_autoptr (GError) error = NULL; g_autoptr (GError) error = NULL;
const MetaFormatInfo *format_info; const MetaFormatInfo *format_info;
uint64_t modifier;
COGL_TRACE_BEGIN_SCOPED (CopySharedFramebufferPrimaryGpu, COGL_TRACE_BEGIN_SCOPED (CopySharedFramebufferPrimaryGpu,
"copy_shared_framebuffer_primary_gpu()"); "copy_shared_framebuffer_primary_gpu()");
@ -977,13 +978,14 @@ copy_shared_framebuffer_primary_gpu (CoglOnscreen *onscre
return NULL; return NULL;
} }
modifier = DRM_FORMAT_MOD_LINEAR;
dmabuf_fb = dmabuf_fb =
meta_renderer_native_create_dma_buf_framebuffer (renderer_native, meta_renderer_native_create_dma_buf_framebuffer (renderer_native,
dmabuf_fd, dmabuf_fd,
width, width,
height, height,
stride, stride,
0, DRM_FORMAT_MOD_LINEAR, 0, &modifier,
drm_format, drm_format,
&error); &error);

View File

@ -150,6 +150,8 @@ meta_render_device_gbm_allocate_dma_buf (MetaRenderDevice *render_device,
int width, int width,
int height, int height,
uint32_t format, uint32_t format,
uint64_t *modifiers,
int n_modifiers,
MetaDrmBufferFlags flags, MetaDrmBufferFlags flags,
GError **error) GError **error)
{ {
@ -159,9 +161,21 @@ meta_render_device_gbm_allocate_dma_buf (MetaRenderDevice *render_device,
struct gbm_bo *gbm_bo; struct gbm_bo *gbm_bo;
MetaDrmBufferGbm *buffer_gbm; MetaDrmBufferGbm *buffer_gbm;
gbm_bo = gbm_bo_create (render_device_gbm->gbm_device, if (n_modifiers == 0)
width, height, format, {
GBM_BO_USE_RENDERING | GBM_BO_USE_LINEAR); gbm_bo = gbm_bo_create (render_device_gbm->gbm_device,
width, height, format,
GBM_BO_USE_RENDERING);
}
else
{
g_warn_if_fail (!(flags & META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS));
gbm_bo = gbm_bo_create_with_modifiers2 (render_device_gbm->gbm_device,
width, height, format,
modifiers, n_modifiers,
GBM_BO_USE_RENDERING);
}
if (!gbm_bo) if (!gbm_bo)
{ {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,

View File

@ -37,6 +37,8 @@ struct _MetaRenderDeviceClass
int width, int width,
int height, int height,
uint32_t format, uint32_t format,
uint64_t *modifiers,
int n_modifiers,
MetaDrmBufferFlags flags, MetaDrmBufferFlags flags,
GError **error); GError **error);
MetaDrmBuffer * (* import_dma_buf) (MetaRenderDevice *render_device, MetaDrmBuffer * (* import_dma_buf) (MetaRenderDevice *render_device,

View File

@ -345,6 +345,8 @@ meta_render_device_allocate_dma_buf (MetaRenderDevice *render_device,
int width, int width,
int height, int height,
uint32_t format, uint32_t format,
uint64_t *modifiers,
int n_modifiers,
MetaDrmBufferFlags flags, MetaDrmBufferFlags flags,
GError **error) GError **error)
{ {
@ -353,7 +355,9 @@ meta_render_device_allocate_dma_buf (MetaRenderDevice *render_device,
if (klass->allocate_dma_buf) if (klass->allocate_dma_buf)
{ {
return klass->allocate_dma_buf (render_device, return klass->allocate_dma_buf (render_device,
width, height, format, width, height,
format,
modifiers, n_modifiers,
flags, flags,
error); error);
} }

View File

@ -42,6 +42,8 @@ MetaDrmBuffer * meta_render_device_allocate_dma_buf (MetaRenderDevice *render
int width, int width,
int height, int height,
uint32_t format, uint32_t format,
uint64_t *modifiers,
int n_modifiers,
MetaDrmBufferFlags flags, MetaDrmBufferFlags flags,
GError **error); GError **error);

View File

@ -97,7 +97,7 @@ CoglFramebuffer * meta_renderer_native_create_dma_buf_framebuffer (MetaRendererN
uint32_t height, uint32_t height,
uint32_t stride, uint32_t stride,
uint32_t offset, uint32_t offset,
uint64_t modifier, uint64_t *modifier,
uint32_t drm_format, uint32_t drm_format,
GError **error); GError **error);

View File

@ -633,7 +633,7 @@ meta_renderer_native_create_dma_buf_framebuffer (MetaRendererNative *renderer_n
uint32_t height, uint32_t height,
uint32_t stride, uint32_t stride,
uint32_t offset, uint32_t offset,
uint64_t modifier, uint64_t *modifier,
uint32_t drm_format, uint32_t drm_format,
GError **error) GError **error)
{ {
@ -647,7 +647,6 @@ meta_renderer_native_create_dma_buf_framebuffer (MetaRendererNative *renderer_n
EGLImageKHR egl_image; EGLImageKHR egl_image;
uint32_t strides[1]; uint32_t strides[1];
uint32_t offsets[1]; uint32_t offsets[1];
uint64_t modifiers[1];
CoglPixelFormat cogl_format; CoglPixelFormat cogl_format;
CoglEglImageFlags flags; CoglEglImageFlags flags;
CoglTexture *cogl_tex; CoglTexture *cogl_tex;
@ -660,7 +659,6 @@ meta_renderer_native_create_dma_buf_framebuffer (MetaRendererNative *renderer_n
strides[0] = stride; strides[0] = stride;
offsets[0] = offset; offsets[0] = offset;
modifiers[0] = modifier;
egl_image = meta_egl_create_dmabuf_image (egl, egl_image = meta_egl_create_dmabuf_image (egl,
egl_display, egl_display,
width, width,
@ -670,7 +668,7 @@ meta_renderer_native_create_dma_buf_framebuffer (MetaRendererNative *renderer_n
&dmabuf_fd, &dmabuf_fd,
strides, strides,
offsets, offsets,
modifiers, modifier,
error); error);
if (egl_image == EGL_NO_IMAGE_KHR) if (egl_image == EGL_NO_IMAGE_KHR)
return NULL; return NULL;
@ -945,6 +943,8 @@ meta_renderer_native_queue_mode_set_update (MetaRendererNative *renderer_native,
static CoglDmaBufHandle * static CoglDmaBufHandle *
meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer, meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer,
CoglPixelFormat format, CoglPixelFormat format,
uint64_t *modifiers,
int n_modifiers,
int width, int width,
int height, int height,
GError **error) GError **error)
@ -964,7 +964,6 @@ meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer,
uint32_t stride; uint32_t stride;
uint32_t offset; uint32_t offset;
uint32_t bpp; uint32_t bpp;
uint64_t modifier;
uint32_t drm_format; uint32_t drm_format;
CoglFramebuffer *dmabuf_fb; CoglFramebuffer *dmabuf_fb;
CoglDmaBufHandle *dmabuf_handle; CoglDmaBufHandle *dmabuf_handle;
@ -985,6 +984,7 @@ meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer,
buffer = meta_render_device_allocate_dma_buf (render_device, buffer = meta_render_device_allocate_dma_buf (render_device,
width, height, width, height,
drm_format, drm_format,
modifiers, n_modifiers,
flags, flags,
error); error);
if (!buffer) if (!buffer)
@ -997,17 +997,32 @@ meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer,
stride = meta_drm_buffer_get_stride (buffer); stride = meta_drm_buffer_get_stride (buffer);
offset = meta_drm_buffer_get_offset (buffer, 0); offset = meta_drm_buffer_get_offset (buffer, 0);
bpp = meta_drm_buffer_get_bpp (buffer); bpp = meta_drm_buffer_get_bpp (buffer);
modifier = meta_drm_buffer_get_modifier (buffer); if (n_modifiers)
{
uint64_t modifier = meta_drm_buffer_get_modifier (buffer);
dmabuf_fb = dmabuf_fb =
meta_renderer_native_create_dma_buf_framebuffer (renderer_native, meta_renderer_native_create_dma_buf_framebuffer (renderer_native,
dmabuf_fd, dmabuf_fd,
width, height, width, height,
stride, stride,
offset, offset,
modifier, &modifier,
drm_format, drm_format,
error); error);
}
else
{
dmabuf_fb =
meta_renderer_native_create_dma_buf_framebuffer (renderer_native,
dmabuf_fd,
width, height,
stride,
offset,
NULL,
drm_format,
error);
}
if (!dmabuf_fb) if (!dmabuf_fb)
{ {