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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3175>
This commit is contained in:
Georges Basile Stavracas Neto 2023-08-11 15:51:28 -03:00
parent 14ed29e7b2
commit fdc3f3fec3
7 changed files with 38 additions and 19 deletions

View File

@ -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])

View File

@ -747,6 +747,7 @@ cogl_renderer_foreach_output (CoglRenderer *renderer,
CoglDmaBufHandle *
cogl_renderer_create_dma_buf (CoglRenderer *renderer,
CoglPixelFormat format,
int width,
int height,
GError **error)
@ -754,7 +755,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, 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");

View File

@ -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 <glib-object.h>
@ -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
@ -379,6 +381,7 @@ cogl_renderer_foreach_output (CoglRenderer *renderer,
*/
COGL_EXPORT CoglDmaBufHandle *
cogl_renderer_create_dma_buf (CoglRenderer *renderer,
CoglPixelFormat format,
int width,
int height,
GError **error);

View File

@ -94,6 +94,7 @@ typedef struct _CoglWinsysVtable
CoglDmaBufHandle *
(*renderer_create_dma_buf) (CoglRenderer *renderer,
CoglPixelFormat format,
int width,
int height,
GError **error);

View File

@ -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)

View File

@ -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)

View File

@ -930,6 +930,7 @@ unset_disabled_crtcs (MetaRendererNative *renderer_native)
static CoglDmaBufHandle *
meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer,
CoglPixelFormat format,
int width,
int height,
GError **error)
@ -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;