native/cogl-utils: Add MetaMultiTextureFormat section

So they can be derived from the DRM format as well.

While updating the users, ensure we don't announce support for
DRM formats in zwp_linux_dmabuf_v1 if the MetaMultiTextureFormat is
INVALID. This will be used for YUV subformats in following commits.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2191>
This commit is contained in:
Robert Mader 2023-06-11 00:45:31 +02:00 committed by Marge Bot
parent 3dd9f15eba
commit b15e14e027
6 changed files with 49 additions and 36 deletions

View File

@ -279,7 +279,9 @@ meta_drm_buffer_gbm_blit_to_framebuffer (CoglScanout *scanout,
} }
drm_format = gbm_bo_get_format (buffer_gbm->bo); drm_format = gbm_bo_get_format (buffer_gbm->bo);
result = meta_cogl_pixel_format_from_drm_format (drm_format, &cogl_format); result = meta_cogl_pixel_format_from_drm_format (drm_format,
&cogl_format,
NULL);
g_assert (result); g_assert (result);
width = gbm_bo_get_width (buffer_gbm->bo); width = gbm_bo_get_width (buffer_gbm->bo);

View File

@ -746,7 +746,7 @@ copy_shared_framebuffer_primary_gpu (CoglOnscreen *onscre
g_assert (cogl_framebuffer_get_width (framebuffer) == width); g_assert (cogl_framebuffer_get_width (framebuffer) == width);
g_assert (cogl_framebuffer_get_height (framebuffer) == height); g_assert (cogl_framebuffer_get_height (framebuffer) == height);
ret = meta_cogl_pixel_format_from_drm_format (drm_format, &cogl_format); ret = meta_cogl_pixel_format_from_drm_format (drm_format, &cogl_format, NULL);
g_assert (ret); g_assert (ret);
dmabuf_fd = meta_drm_buffer_dumb_ensure_dmabuf_fd (buffer_dumb, &error); dmabuf_fd = meta_drm_buffer_dumb_ensure_dmabuf_fd (buffer_dumb, &error);
@ -848,7 +848,7 @@ copy_shared_framebuffer_cpu (CoglOnscreen *onscreen,
g_assert (cogl_framebuffer_get_width (framebuffer) == width); g_assert (cogl_framebuffer_get_width (framebuffer) == width);
g_assert (cogl_framebuffer_get_height (framebuffer) == height); g_assert (cogl_framebuffer_get_height (framebuffer) == height);
ret = meta_cogl_pixel_format_from_drm_format (drm_format, &cogl_format); ret = meta_cogl_pixel_format_from_drm_format (drm_format, &cogl_format, NULL);
g_assert (ret); g_assert (ret);
dumb_bitmap = cogl_bitmap_new_for_data (cogl_context, dumb_bitmap = cogl_bitmap_new_for_data (cogl_context,
@ -2111,6 +2111,7 @@ pick_secondary_gpu_framebuffer_format_for_cpu (CoglOnscreen *onscreen)
for (k = 0; k < G_N_ELEMENTS (preferred_formats); k++) for (k = 0; k < G_N_ELEMENTS (preferred_formats); k++)
{ {
g_assert (meta_cogl_pixel_format_from_drm_format (preferred_formats[k], g_assert (meta_cogl_pixel_format_from_drm_format (preferred_formats[k],
NULL,
NULL)); NULL));
for (i = 0; i < formats->len; i++) for (i = 0; i < formats->len; i++)
@ -2131,7 +2132,7 @@ pick_secondary_gpu_framebuffer_format_for_cpu (CoglOnscreen *onscreen)
{ {
drm_format = g_array_index (formats, uint32_t, i); drm_format = g_array_index (formats, uint32_t, i);
if (meta_cogl_pixel_format_from_drm_format (drm_format, NULL)) if (meta_cogl_pixel_format_from_drm_format (drm_format, NULL, NULL))
return drm_format; return drm_format;
} }

View File

@ -615,7 +615,7 @@ meta_renderer_native_create_dma_buf_framebuffer (MetaRendererNative *renderer_n
CoglOffscreen *cogl_fbo; CoglOffscreen *cogl_fbo;
int ret; int ret;
ret = meta_cogl_pixel_format_from_drm_format (drm_format, &cogl_format); ret = meta_cogl_pixel_format_from_drm_format (drm_format, &cogl_format, NULL);
g_assert (ret); g_assert (ret);
strides[0] = stride; strides[0] = stride;

View File

@ -27,8 +27,9 @@
#include "common/meta-cogl-drm-formats.h" #include "common/meta-cogl-drm-formats.h"
gboolean gboolean
meta_cogl_pixel_format_from_drm_format (uint32_t drm_format, meta_cogl_pixel_format_from_drm_format (uint32_t drm_format,
CoglPixelFormat *out_format) CoglPixelFormat *out_format,
MetaMultiTextureFormat *out_multi_texture_format)
{ {
const size_t n = G_N_ELEMENTS (meta_cogl_drm_format_map); const size_t n = G_N_ELEMENTS (meta_cogl_drm_format_map);
size_t i; size_t i;
@ -45,5 +46,8 @@ meta_cogl_pixel_format_from_drm_format (uint32_t drm_format,
if (out_format) if (out_format)
*out_format = meta_cogl_drm_format_map[i].cogl_format; *out_format = meta_cogl_drm_format_map[i].cogl_format;
if (out_multi_texture_format)
*out_multi_texture_format = meta_cogl_drm_format_map[i].multi_texture_format;
return TRUE; return TRUE;
} }

View File

@ -28,6 +28,7 @@
#include <drm_fourcc.h> #include <drm_fourcc.h>
#include "cogl/cogl.h" #include "cogl/cogl.h"
#include "meta/meta-multi-texture-format.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -35,44 +36,46 @@ typedef struct _CoglDrmFormatMap
{ {
uint32_t drm_format; uint32_t drm_format;
CoglPixelFormat cogl_format; CoglPixelFormat cogl_format;
MetaMultiTextureFormat multi_texture_format;
} CoglDrmFormatMap; } CoglDrmFormatMap;
static const CoglDrmFormatMap meta_cogl_drm_format_map[] = { static const CoglDrmFormatMap meta_cogl_drm_format_map[] = {
/* DRM formats are defined as little-endian, not machine endian. */ /* DRM formats are defined as little-endian, not machine endian. */
#if G_BYTE_ORDER == G_LITTLE_ENDIAN #if G_BYTE_ORDER == G_LITTLE_ENDIAN
{ DRM_FORMAT_RGB565, COGL_PIXEL_FORMAT_RGB_565 }, { DRM_FORMAT_RGB565, COGL_PIXEL_FORMAT_RGB_565, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_RGBX8888, COGL_PIXEL_FORMAT_XBGR_8888 }, { DRM_FORMAT_RGBX8888, COGL_PIXEL_FORMAT_XBGR_8888, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_RGBA8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE }, { DRM_FORMAT_RGBA8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_BGRX8888, COGL_PIXEL_FORMAT_XRGB_8888 }, { DRM_FORMAT_BGRX8888, COGL_PIXEL_FORMAT_XRGB_8888, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_BGRA8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE }, { DRM_FORMAT_BGRA8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_XRGB8888, COGL_PIXEL_FORMAT_BGRX_8888 }, { DRM_FORMAT_XRGB8888, COGL_PIXEL_FORMAT_BGRX_8888, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_ARGB8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE }, { DRM_FORMAT_ARGB8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_XBGR8888, COGL_PIXEL_FORMAT_RGBX_8888 }, { DRM_FORMAT_XBGR8888, COGL_PIXEL_FORMAT_RGBX_8888, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_ABGR8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE }, { DRM_FORMAT_ABGR8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_XRGB2101010, COGL_PIXEL_FORMAT_XRGB_2101010 }, { DRM_FORMAT_XRGB2101010, COGL_PIXEL_FORMAT_XRGB_2101010, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_ARGB2101010, COGL_PIXEL_FORMAT_ARGB_2101010_PRE }, { DRM_FORMAT_ARGB2101010, COGL_PIXEL_FORMAT_ARGB_2101010_PRE, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_XBGR2101010, COGL_PIXEL_FORMAT_XBGR_2101010 }, { DRM_FORMAT_XBGR2101010, COGL_PIXEL_FORMAT_XBGR_2101010, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_ABGR2101010, COGL_PIXEL_FORMAT_ABGR_2101010_PRE }, { DRM_FORMAT_ABGR2101010, COGL_PIXEL_FORMAT_ABGR_2101010_PRE, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_XRGB16161616F, COGL_PIXEL_FORMAT_BGRX_FP_16161616 }, { DRM_FORMAT_XRGB16161616F, COGL_PIXEL_FORMAT_BGRX_FP_16161616, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_ARGB16161616F, COGL_PIXEL_FORMAT_BGRA_FP_16161616_PRE }, { DRM_FORMAT_ARGB16161616F, COGL_PIXEL_FORMAT_BGRA_FP_16161616_PRE, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_XBGR16161616F, COGL_PIXEL_FORMAT_RGBX_FP_16161616 }, { DRM_FORMAT_XBGR16161616F, COGL_PIXEL_FORMAT_RGBX_FP_16161616, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_ABGR16161616F, COGL_PIXEL_FORMAT_RGBA_FP_16161616_PRE }, { DRM_FORMAT_ABGR16161616F, COGL_PIXEL_FORMAT_RGBA_FP_16161616_PRE, META_MULTI_TEXTURE_FORMAT_SIMPLE },
#elif G_BYTE_ORDER == G_BIG_ENDIAN #elif G_BYTE_ORDER == G_BIG_ENDIAN
{ DRM_FORMAT_RGBX8888, COGL_PIXEL_FORMAT_RGBX_8888 }, { DRM_FORMAT_RGBX8888, COGL_PIXEL_FORMAT_RGBX_8888, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_RGBA8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE }, { DRM_FORMAT_RGBA8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_BGRX8888, COGL_PIXEL_FORMAT_BGRX_8888 }, { DRM_FORMAT_BGRX8888, COGL_PIXEL_FORMAT_BGRX_8888, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_BGRA8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE }, { DRM_FORMAT_BGRA8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_XRGB8888, COGL_PIXEL_FORMAT_XRGB_8888 }, { DRM_FORMAT_XRGB8888, COGL_PIXEL_FORMAT_XRGB_8888, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_ARGB8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE }, { DRM_FORMAT_ARGB8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_XBGR8888, COGL_PIXEL_FORMAT_XBGR_8888 }, { DRM_FORMAT_XBGR8888, COGL_PIXEL_FORMAT_XBGR_8888, META_MULTI_TEXTURE_FORMAT_SIMPLE },
{ DRM_FORMAT_ABGR8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE }, { DRM_FORMAT_ABGR8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE, META_MULTI_TEXTURE_FORMAT_SIMPLE },
#else #else
#error "unexpected G_BYTE_ORDER" #error "unexpected G_BYTE_ORDER"
#endif #endif
}; };
gboolean meta_cogl_pixel_format_from_drm_format (uint32_t drm_format, gboolean meta_cogl_pixel_format_from_drm_format (uint32_t drm_format,
CoglPixelFormat *out_format); CoglPixelFormat *out_format,
MetaMultiTextureFormat *out_multi_texture_format);
G_END_DECLS G_END_DECLS

View File

@ -357,7 +357,8 @@ meta_wayland_dma_buf_realize_texture (MetaWaylandBuffer *buffer,
return TRUE; return TRUE;
if (!meta_cogl_pixel_format_from_drm_format (dma_buf->drm_format, if (!meta_cogl_pixel_format_from_drm_format (dma_buf->drm_format,
&cogl_format)) &cogl_format,
NULL))
{ {
g_set_error (error, G_IO_ERROR, g_set_error (error, G_IO_ERROR,
G_IO_ERROR_FAILED, G_IO_ERROR_FAILED,
@ -1562,7 +1563,9 @@ init_formats (MetaWaylandDmaBufManager *dma_buf_manager,
{ {
for (j = 0; j < num_formats; j++) for (j = 0; j < num_formats; j++)
{ {
if (meta_cogl_drm_format_map[i].drm_format == driver_formats[j]) if ((meta_cogl_drm_format_map[i].drm_format == driver_formats[j]) &&
(meta_cogl_drm_format_map[i].multi_texture_format !=
META_MULTI_TEXTURE_FORMAT_INVALID))
add_format (dma_buf_manager, egl_display, driver_formats[j]); add_format (dma_buf_manager, egl_display, driver_formats[j]);
} }
} }