From fdc3f3fec3d83cf0fcfa4dbddd507b9f04129480 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Fri, 11 Aug 2023 15:51:28 -0300 Subject: [PATCH] cogl/renderer: Pass pixel format to DMA-BUF constructor In future commits, we will want to create DMA-BUFs with pixel formats other than COGL_PIXEL_FORMAT_BGRX_8888. In preparation for that, let's start passing a new pixel format parameter to this function, and the corresponding winsys vfunc. All callers of this function pass COGL_PIXEL_FORMAT_BGRX_8888 for now. Next commits will change that. Part-of: --- clutter/clutter/clutter-stage-view.c | 2 ++ cogl/cogl/cogl-renderer.c | 13 ++++++++----- cogl/cogl/cogl-renderer.h | 15 +++++++++------ cogl/cogl/winsys/cogl-winsys-private.h | 9 +++++---- src/backends/meta-screen-cast.c | 1 + src/backends/native/meta-backend-native.c | 1 + src/backends/native/meta-renderer-native.c | 16 ++++++++++++---- 7 files changed, 38 insertions(+), 19 deletions(-) diff --git a/clutter/clutter/clutter-stage-view.c b/clutter/clutter/clutter-stage-view.c index 6fab9b87c..2087590ce 100644 --- a/clutter/clutter/clutter-stage-view.c +++ b/clutter/clutter/clutter-stage-view.c @@ -351,12 +351,14 @@ init_dma_buf_shadowfbs (ClutterStageView *view, } priv->shadow.dma_buf.handles[0] = cogl_renderer_create_dma_buf (cogl_renderer, + COGL_PIXEL_FORMAT_BGRX_8888, width, height, error); if (!priv->shadow.dma_buf.handles[0]) return FALSE; priv->shadow.dma_buf.handles[1] = cogl_renderer_create_dma_buf (cogl_renderer, + COGL_PIXEL_FORMAT_BGRX_8888, width, height, error); if (!priv->shadow.dma_buf.handles[1]) diff --git a/cogl/cogl/cogl-renderer.c b/cogl/cogl/cogl-renderer.c index b0dd576ee..a8b54e77d 100644 --- a/cogl/cogl/cogl-renderer.c +++ b/cogl/cogl/cogl-renderer.c @@ -746,15 +746,18 @@ cogl_renderer_foreach_output (CoglRenderer *renderer, } CoglDmaBufHandle * -cogl_renderer_create_dma_buf (CoglRenderer *renderer, - int width, - int height, - GError **error) +cogl_renderer_create_dma_buf (CoglRenderer *renderer, + CoglPixelFormat format, + int width, + int height, + GError **error) { const CoglWinsysVtable *winsys = _cogl_renderer_get_winsys (renderer); if (winsys->renderer_create_dma_buf) - return winsys->renderer_create_dma_buf (renderer, width, height, error); + return winsys->renderer_create_dma_buf (renderer, format, + width, height, + error); g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "CoglRenderer doesn't support creating DMA buffers"); diff --git a/cogl/cogl/cogl-renderer.h b/cogl/cogl/cogl-renderer.h index 9a1d95ede..385d280f9 100644 --- a/cogl/cogl/cogl-renderer.h +++ b/cogl/cogl/cogl-renderer.h @@ -35,6 +35,7 @@ #include "cogl/cogl-types.h" #include "cogl/cogl-onscreen-template.h" #include "cogl/cogl-output.h" +#include "cogl/cogl-pixel-format.h" #include @@ -365,12 +366,13 @@ cogl_renderer_foreach_output (CoglRenderer *renderer, /** * cogl_renderer_create_dma_buf: (skip) * @renderer: A #CoglRenderer + * @format: A #CoglPixelFormat * @width: width of the new * @height: height of the new * @error: (nullable): return location for a #GError * - * Creates a new #CoglFramebuffer with @width x @height, and format - * hardcoded to XRGB, and exports the new framebuffer's DMA buffer + * Creates a new #CoglFramebuffer with @width x @height, with pixel + * format @format, and exports the new framebuffer's DMA buffer * handle. * * Returns: (nullable)(transfer full): a #CoglDmaBufHandle. The @@ -378,10 +380,11 @@ cogl_renderer_foreach_output (CoglRenderer *renderer, * after use. */ COGL_EXPORT CoglDmaBufHandle * -cogl_renderer_create_dma_buf (CoglRenderer *renderer, - int width, - int height, - GError **error); +cogl_renderer_create_dma_buf (CoglRenderer *renderer, + CoglPixelFormat format, + 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 d415cf5a6..d414cada0 100644 --- a/cogl/cogl/winsys/cogl-winsys-private.h +++ b/cogl/cogl/winsys/cogl-winsys-private.h @@ -93,10 +93,11 @@ typedef struct _CoglWinsysVtable (*display_destroy) (CoglDisplay *display); CoglDmaBufHandle * - (*renderer_create_dma_buf) (CoglRenderer *renderer, - int width, - int height, - GError **error); + (*renderer_create_dma_buf) (CoglRenderer *renderer, + CoglPixelFormat format, + int width, + int height, + GError **error); gboolean (*renderer_is_dma_buf_supported) (CoglRenderer *renderer); diff --git a/src/backends/meta-screen-cast.c b/src/backends/meta-screen-cast.c index 76e8b35ca..8825e27a4 100644 --- a/src/backends/meta-screen-cast.c +++ b/src/backends/meta-screen-cast.c @@ -79,6 +79,7 @@ meta_screen_cast_create_dma_buf_handle (MetaScreenCast *screen_cast, return NULL; dmabuf_handle = cogl_renderer_create_dma_buf (cogl_renderer, + COGL_PIXEL_FORMAT_BGRX_8888, 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 1296e9512..a8f747256 100644 --- a/src/backends/native/meta-backend-native.c +++ b/src/backends/native/meta-backend-native.c @@ -183,6 +183,7 @@ maybe_disable_screen_cast_dma_bufs (MetaBackendNative *native) } dmabuf_handle = cogl_renderer_create_dma_buf (cogl_renderer, + COGL_PIXEL_FORMAT_BGRX_8888, 1, 1, &error); if (!dmabuf_handle) diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c index 0f7f4874b..75ba0c354 100644 --- a/src/backends/native/meta-renderer-native.c +++ b/src/backends/native/meta-renderer-native.c @@ -929,10 +929,11 @@ unset_disabled_crtcs (MetaRendererNative *renderer_native) } static CoglDmaBufHandle * -meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer, - int width, - int height, - GError **error) +meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer, + CoglPixelFormat format, + int width, + int height, + GError **error) { CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys; MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform; @@ -954,6 +955,13 @@ meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer, CoglFramebuffer *dmabuf_fb; CoglDmaBufHandle *dmabuf_handle; + if (format != COGL_PIXEL_FORMAT_BGRX_8888) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, + "Native renderer doesn't support creating DMA buffer with format %s", + cogl_pixel_format_to_string (format)); + return NULL; + } render_device = renderer_gpu_data->render_device; flags = META_DRM_BUFFER_FLAG_NONE;