From 34d00d769e29a393c23696979151ee329d0478d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fukan=20Korkmazt=C3=BCrk?= Date: Fri, 19 Jan 2024 17:28:15 -0500 Subject: [PATCH] render-device: Update DMA-BUF allocation API to allow modifiers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Part-of: --- cogl/cogl/cogl-renderer.c | 6 ++- cogl/cogl/cogl-renderer.h | 7 +++ cogl/cogl/winsys/cogl-winsys-private.h | 2 + src/backends/meta-screen-cast.c | 1 + src/backends/native/meta-backend-native.c | 1 + src/backends/native/meta-onscreen-native.c | 4 +- src/backends/native/meta-render-device-gbm.c | 20 +++++++-- .../native/meta-render-device-private.h | 2 + src/backends/native/meta-render-device.c | 6 ++- src/backends/native/meta-render-device.h | 2 + .../native/meta-renderer-native-private.h | 2 +- src/backends/native/meta-renderer-native.c | 45 ++++++++++++------- 12 files changed, 76 insertions(+), 22 deletions(-) diff --git a/cogl/cogl/cogl-renderer.c b/cogl/cogl/cogl-renderer.c index 6c5fa4db1..96cc0e4b0 100644 --- a/cogl/cogl/cogl-renderer.c +++ b/cogl/cogl/cogl-renderer.c @@ -758,6 +758,8 @@ cogl_renderer_foreach_output (CoglRenderer *renderer, CoglDmaBufHandle * cogl_renderer_create_dma_buf (CoglRenderer *renderer, CoglPixelFormat format, + uint64_t *modifiers, + int n_modifiers, int width, int height, GError **error) @@ -765,7 +767,9 @@ cogl_renderer_create_dma_buf (CoglRenderer *renderer, const CoglWinsysVtable *winsys = _cogl_renderer_get_winsys (renderer); 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, error); diff --git a/cogl/cogl/cogl-renderer.h b/cogl/cogl/cogl-renderer.h index a14b70bc4..fe169dd01 100644 --- a/cogl/cogl/cogl-renderer.h +++ b/cogl/cogl/cogl-renderer.h @@ -347,6 +347,8 @@ cogl_renderer_foreach_output (CoglRenderer *renderer, * cogl_renderer_create_dma_buf: (skip) * @renderer: A #CoglRenderer * @format: A #CoglPixelFormat + * @modifiers: array of DRM format modifiers + * @n_modifiers: length of modifiers array * @width: width of the new * @height: height of the new * @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 * handle. * + * Passing an empty modifier array (passing a 0 n_modifiers) means implicit + * modifiers will be used. + * * Returns: (nullable)(transfer full): a #CoglDmaBufHandle. The * return result must be released with cogl_dma_buf_handle_free() * after use. @@ -362,6 +367,8 @@ cogl_renderer_foreach_output (CoglRenderer *renderer, COGL_EXPORT CoglDmaBufHandle * cogl_renderer_create_dma_buf (CoglRenderer *renderer, CoglPixelFormat format, + uint64_t *modifiers, + int n_modifiers, int width, int height, GError **error); diff --git a/cogl/cogl/winsys/cogl-winsys-private.h b/cogl/cogl/winsys/cogl-winsys-private.h index 502ac4cb2..f8fc0fc91 100644 --- a/cogl/cogl/winsys/cogl-winsys-private.h +++ b/cogl/cogl/winsys/cogl-winsys-private.h @@ -91,6 +91,8 @@ typedef struct _CoglWinsysVtable CoglDmaBufHandle * (*renderer_create_dma_buf) (CoglRenderer *renderer, CoglPixelFormat format, + uint64_t *modifiers, + int n_modifiers, int width, int height, GError **error); diff --git a/src/backends/meta-screen-cast.c b/src/backends/meta-screen-cast.c index 271bb0c03..8be4fa4dd 100644 --- a/src/backends/meta-screen-cast.c +++ b/src/backends/meta-screen-cast.c @@ -129,6 +129,7 @@ meta_screen_cast_create_dma_buf_handle (MetaScreenCast *screen_cast, dmabuf_handle = cogl_renderer_create_dma_buf (cogl_renderer, format, + NULL, 0, width, height, &error); if (!dmabuf_handle) diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c index b0b129de8..a1eb44f29 100644 --- a/src/backends/native/meta-backend-native.c +++ b/src/backends/native/meta-backend-native.c @@ -186,6 +186,7 @@ maybe_disable_screen_cast_dma_bufs (MetaBackendNative *native) dmabuf_handle = cogl_renderer_create_dma_buf (cogl_renderer, COGL_PIXEL_FORMAT_BGRX_8888, + NULL, 0, 1, 1, &error); if (!dmabuf_handle) diff --git a/src/backends/native/meta-onscreen-native.c b/src/backends/native/meta-onscreen-native.c index 24d7c04a1..b8d8d2808 100644 --- a/src/backends/native/meta-onscreen-native.c +++ b/src/backends/native/meta-onscreen-native.c @@ -941,6 +941,7 @@ copy_shared_framebuffer_primary_gpu (CoglOnscreen *onscre int dmabuf_fd; g_autoptr (GError) error = NULL; const MetaFormatInfo *format_info; + uint64_t modifier; COGL_TRACE_BEGIN_SCOPED (CopySharedFramebufferPrimaryGpu, "copy_shared_framebuffer_primary_gpu()"); @@ -977,13 +978,14 @@ copy_shared_framebuffer_primary_gpu (CoglOnscreen *onscre return NULL; } + modifier = DRM_FORMAT_MOD_LINEAR; dmabuf_fb = meta_renderer_native_create_dma_buf_framebuffer (renderer_native, dmabuf_fd, width, height, stride, - 0, DRM_FORMAT_MOD_LINEAR, + 0, &modifier, drm_format, &error); diff --git a/src/backends/native/meta-render-device-gbm.c b/src/backends/native/meta-render-device-gbm.c index bd7284051..7a381b98e 100644 --- a/src/backends/native/meta-render-device-gbm.c +++ b/src/backends/native/meta-render-device-gbm.c @@ -150,6 +150,8 @@ meta_render_device_gbm_allocate_dma_buf (MetaRenderDevice *render_device, int width, int height, uint32_t format, + uint64_t *modifiers, + int n_modifiers, MetaDrmBufferFlags flags, GError **error) { @@ -159,9 +161,21 @@ meta_render_device_gbm_allocate_dma_buf (MetaRenderDevice *render_device, struct gbm_bo *gbm_bo; MetaDrmBufferGbm *buffer_gbm; - gbm_bo = gbm_bo_create (render_device_gbm->gbm_device, - width, height, format, - GBM_BO_USE_RENDERING | GBM_BO_USE_LINEAR); + if (n_modifiers == 0) + { + 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) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, diff --git a/src/backends/native/meta-render-device-private.h b/src/backends/native/meta-render-device-private.h index 56004defe..321d57a5a 100644 --- a/src/backends/native/meta-render-device-private.h +++ b/src/backends/native/meta-render-device-private.h @@ -37,6 +37,8 @@ struct _MetaRenderDeviceClass int width, int height, uint32_t format, + uint64_t *modifiers, + int n_modifiers, MetaDrmBufferFlags flags, GError **error); MetaDrmBuffer * (* import_dma_buf) (MetaRenderDevice *render_device, diff --git a/src/backends/native/meta-render-device.c b/src/backends/native/meta-render-device.c index f786b77a7..8141cf9c4 100644 --- a/src/backends/native/meta-render-device.c +++ b/src/backends/native/meta-render-device.c @@ -345,6 +345,8 @@ meta_render_device_allocate_dma_buf (MetaRenderDevice *render_device, int width, int height, uint32_t format, + uint64_t *modifiers, + int n_modifiers, MetaDrmBufferFlags flags, GError **error) { @@ -353,7 +355,9 @@ meta_render_device_allocate_dma_buf (MetaRenderDevice *render_device, if (klass->allocate_dma_buf) { return klass->allocate_dma_buf (render_device, - width, height, format, + width, height, + format, + modifiers, n_modifiers, flags, error); } diff --git a/src/backends/native/meta-render-device.h b/src/backends/native/meta-render-device.h index 2aec82446..90c2de911 100644 --- a/src/backends/native/meta-render-device.h +++ b/src/backends/native/meta-render-device.h @@ -42,6 +42,8 @@ MetaDrmBuffer * meta_render_device_allocate_dma_buf (MetaRenderDevice *render int width, int height, uint32_t format, + uint64_t *modifiers, + int n_modifiers, MetaDrmBufferFlags flags, GError **error); diff --git a/src/backends/native/meta-renderer-native-private.h b/src/backends/native/meta-renderer-native-private.h index 66b987a5c..997fe6f69 100644 --- a/src/backends/native/meta-renderer-native-private.h +++ b/src/backends/native/meta-renderer-native-private.h @@ -97,7 +97,7 @@ CoglFramebuffer * meta_renderer_native_create_dma_buf_framebuffer (MetaRendererN uint32_t height, uint32_t stride, uint32_t offset, - uint64_t modifier, + uint64_t *modifier, uint32_t drm_format, GError **error); diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c index 6aaf93ae0..7b64ff3f4 100644 --- a/src/backends/native/meta-renderer-native.c +++ b/src/backends/native/meta-renderer-native.c @@ -633,7 +633,7 @@ meta_renderer_native_create_dma_buf_framebuffer (MetaRendererNative *renderer_n uint32_t height, uint32_t stride, uint32_t offset, - uint64_t modifier, + uint64_t *modifier, uint32_t drm_format, GError **error) { @@ -647,7 +647,6 @@ meta_renderer_native_create_dma_buf_framebuffer (MetaRendererNative *renderer_n EGLImageKHR egl_image; uint32_t strides[1]; uint32_t offsets[1]; - uint64_t modifiers[1]; CoglPixelFormat cogl_format; CoglEglImageFlags flags; CoglTexture *cogl_tex; @@ -660,7 +659,6 @@ meta_renderer_native_create_dma_buf_framebuffer (MetaRendererNative *renderer_n strides[0] = stride; offsets[0] = offset; - modifiers[0] = modifier; egl_image = meta_egl_create_dmabuf_image (egl, egl_display, width, @@ -670,7 +668,7 @@ meta_renderer_native_create_dma_buf_framebuffer (MetaRendererNative *renderer_n &dmabuf_fd, strides, offsets, - modifiers, + modifier, error); if (egl_image == EGL_NO_IMAGE_KHR) return NULL; @@ -945,6 +943,8 @@ meta_renderer_native_queue_mode_set_update (MetaRendererNative *renderer_native, static CoglDmaBufHandle * meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer, CoglPixelFormat format, + uint64_t *modifiers, + int n_modifiers, int width, int height, GError **error) @@ -964,7 +964,6 @@ meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer, uint32_t stride; uint32_t offset; uint32_t bpp; - uint64_t modifier; uint32_t drm_format; CoglFramebuffer *dmabuf_fb; 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, width, height, drm_format, + modifiers, n_modifiers, flags, error); if (!buffer) @@ -997,17 +997,32 @@ meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer, stride = meta_drm_buffer_get_stride (buffer); offset = meta_drm_buffer_get_offset (buffer, 0); 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 = - meta_renderer_native_create_dma_buf_framebuffer (renderer_native, - dmabuf_fd, - width, height, - stride, - offset, - modifier, - drm_format, - error); + dmabuf_fb = + meta_renderer_native_create_dma_buf_framebuffer (renderer_native, + dmabuf_fd, + width, height, + stride, + offset, + &modifier, + drm_format, + 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) {