dmabuf: Add all formats

Add the matching GdkMemoryFormat for all dmabuf formats.

This way, we don't fall back to RGBA8 for 10- and 16-bit formats that we
don't support natively when EGL or Vulkan use them.

Also includes corrections for a few mixups.
This commit is contained in:
Benjamin Otte 2023-11-23 02:01:56 +01:00
parent 1bf94b045c
commit b6c82c6b54

View File

@ -370,6 +370,56 @@ download_yuyv (guchar *dst_data,
}
static const GdkDrmFormatInfo supported_formats[] = {
#if 0
/* palette formats?! */
{ DRM_FORMAT_C1, GDK_MEMORY_, GDK_MEMORY_, NULL },
{ DRM_FORMAT_C2, GDK_MEMORY_, GDK_MEMORY_, NULL },
{ DRM_FORMAT_C4, GDK_MEMORY_, GDK_MEMORY_, NULL },
{ DRM_FORMAT_C8, GDK_MEMORY_, GDK_MEMORY_, NULL },
#endif
/* darkness */
{ DRM_FORMAT_D1, GDK_MEMORY_G8, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_D2, GDK_MEMORY_G8, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_D4, GDK_MEMORY_G8, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_D8, GDK_MEMORY_G8, GDK_MEMORY_G8, NULL },
/* red only - we treat this as gray */
{ DRM_FORMAT_R1, GDK_MEMORY_G8, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_R2, GDK_MEMORY_G8, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_R4, GDK_MEMORY_G8, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_R8, GDK_MEMORY_G8, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_R10, GDK_MEMORY_G16, GDK_MEMORY_G16, NULL },
{ DRM_FORMAT_R12, GDK_MEMORY_G16, GDK_MEMORY_G16, NULL },
{ DRM_FORMAT_R16, GDK_MEMORY_G16, GDK_MEMORY_G16, NULL },
/* 2 channels - FIXME: Should this be gray + alpha? */
{ DRM_FORMAT_RG88, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_GR88, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_RG1616, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_GR1616, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
/* <8bit per channel RGB(A) */
{ DRM_FORMAT_RGB332, GDK_MEMORY_B8G8R8, GDK_MEMORY_B8G8R8, NULL },
{ DRM_FORMAT_BGR233, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_XRGB4444, GDK_MEMORY_B8G8R8, GDK_MEMORY_B8G8R8, NULL },
{ DRM_FORMAT_XBGR4444, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_RGBX4444, GDK_MEMORY_B8G8R8, GDK_MEMORY_B8G8R8, NULL },
{ DRM_FORMAT_BGRX4444, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_ARGB4444, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, GDK_MEMORY_B8G8R8A8, NULL },
{ DRM_FORMAT_ABGR4444, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, GDK_MEMORY_R8G8B8A8, NULL },
{ DRM_FORMAT_RGBA4444, GDK_MEMORY_A8B8G8R8_PREMULTIPLIED, GDK_MEMORY_A8B8G8R8, NULL },
{ DRM_FORMAT_BGRA4444, GDK_MEMORY_A8R8G8B8_PREMULTIPLIED, GDK_MEMORY_A8R8G8B8, NULL },
{ DRM_FORMAT_XRGB1555, GDK_MEMORY_B8G8R8, GDK_MEMORY_B8G8R8, NULL },
{ DRM_FORMAT_XBGR1555, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_RGBX5551, GDK_MEMORY_B8G8R8, GDK_MEMORY_B8G8R8, NULL },
{ DRM_FORMAT_BGRX5551, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_ARGB1555, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, GDK_MEMORY_B8G8R8A8, NULL },
{ DRM_FORMAT_ABGR1555, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, GDK_MEMORY_R8G8B8A8, NULL },
{ DRM_FORMAT_RGBA5551, GDK_MEMORY_A8B8G8R8_PREMULTIPLIED, GDK_MEMORY_A8B8G8R8, NULL },
{ DRM_FORMAT_BGRA5551, GDK_MEMORY_A8R8G8B8_PREMULTIPLIED, GDK_MEMORY_A8R8G8B8, NULL },
{ DRM_FORMAT_RGB565, GDK_MEMORY_B8G8R8, GDK_MEMORY_B8G8R8, NULL },
{ DRM_FORMAT_BGR565, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
/* 8bit RGB */
{ DRM_FORMAT_RGB888, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_memcpy },
{ DRM_FORMAT_BGR888, GDK_MEMORY_B8G8R8, GDK_MEMORY_B8G8R8, download_memcpy },
/* 8bit RGBA */
{ DRM_FORMAT_BGRA8888, GDK_MEMORY_A8R8G8B8_PREMULTIPLIED, GDK_MEMORY_A8R8G8B8, download_memcpy },
{ DRM_FORMAT_ABGR8888, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, GDK_MEMORY_R8G8B8A8, download_memcpy },
{ DRM_FORMAT_ARGB8888, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, GDK_MEMORY_B8G8R8A8, download_memcpy },
@ -379,24 +429,78 @@ static const GdkDrmFormatInfo supported_formats[] = {
{ DRM_FORMAT_XRGB8888, GDK_MEMORY_B8G8R8X8, GDK_MEMORY_B8G8R8X8, download_memcpy },
{ DRM_FORMAT_RGBX8888, GDK_MEMORY_X8B8G8R8, GDK_MEMORY_X8B8G8R8, download_memcpy },
{ DRM_FORMAT_ABGR16161616F, GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16_FLOAT, download_memcpy },
{ DRM_FORMAT_RGB888, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_memcpy },
{ DRM_FORMAT_BGR888, GDK_MEMORY_B8G8R8, GDK_MEMORY_B8G8R8, download_memcpy },
/* 10bit RGB(A) */
{ DRM_FORMAT_XRGB2101010, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_XBGR2101010, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_RGBX1010102, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_BGRX1010102, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_ARGB2101010, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16, NULL },
{ DRM_FORMAT_ABGR2101010, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16, NULL },
{ DRM_FORMAT_RGBA1010102, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16, NULL },
{ DRM_FORMAT_BGRA1010102, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16, NULL },
/* 16bit RGB(A) */
{ DRM_FORMAT_XRGB16161616, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_XBGR16161616, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_ARGB16161616, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16, NULL },
{ DRM_FORMAT_ABGR16161616, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16, NULL },
{ DRM_FORMAT_XRGB16161616F, GDK_MEMORY_R16G16B16_FLOAT, GDK_MEMORY_R16G16B16_FLOAT, NULL },
{ DRM_FORMAT_XBGR16161616F, GDK_MEMORY_R16G16B16_FLOAT, GDK_MEMORY_R16G16B16_FLOAT, NULL },
{ DRM_FORMAT_ARGB16161616F, GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16_FLOAT, NULL },
{ DRM_FORMAT_ABGR16161616F, GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16_FLOAT, NULL },
{ DRM_FORMAT_AXBXGXRX106106106106, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16, NULL },
/* 1-plane YUV formats */
{ DRM_FORMAT_YUYV, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuyv },
{ DRM_FORMAT_YVYU, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuyv },
{ DRM_FORMAT_VYUY, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuyv },
{ DRM_FORMAT_UYVY, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuyv },
{ DRM_FORMAT_AYUV, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, GDK_MEMORY_R8G8B8A8, NULL },
{ DRM_FORMAT_AVUY8888, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, GDK_MEMORY_R8G8B8A8, NULL },
{ DRM_FORMAT_XYUV8888, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_XVUY8888, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_VUY888, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_VUY101010, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y210, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y212, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y216, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y410, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y412, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y416, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_XVYU2101010, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_XVYU12_16161616, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_XVYU16161616, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
/* tiled YUV */
{ DRM_FORMAT_Y0L0, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_X0L0, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_Y0L2, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_X0L2, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
/* non-linear YUV */
{ DRM_FORMAT_YUV420_8BIT, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_YUV420_10BIT, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
/* 2 plane RGB + A */
{ DRM_FORMAT_BGRX8888_A8, GDK_MEMORY_A8R8G8B8_PREMULTIPLIED, GDK_MEMORY_A8R8G8B8, download_memcpy_3_1 },
{ DRM_FORMAT_RGBX8888_A8, GDK_MEMORY_A8B8G8R8_PREMULTIPLIED, GDK_MEMORY_A8B8G8R8, download_memcpy_3_1 },
{ DRM_FORMAT_XBGR8888_A8, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, GDK_MEMORY_R8G8B8A8, download_memcpy_3_1 },
{ DRM_FORMAT_XRGB8888_A8, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, GDK_MEMORY_B8G8R8A8, download_memcpy_3_1 },
/* YUV formats */
{ DRM_FORMAT_RGB888_A8, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, GDK_MEMORY_R8G8B8A8, NULL },
{ DRM_FORMAT_BGR888_A8, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, GDK_MEMORY_B8G8R8A8, NULL },
{ DRM_FORMAT_RGB565_A8, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, GDK_MEMORY_R8G8B8A8, NULL },
{ DRM_FORMAT_BGR565_A8, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, GDK_MEMORY_B8G8R8A8, NULL },
/* 2-plane YUV formats */
{ DRM_FORMAT_NV12, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_nv12 },
{ DRM_FORMAT_NV21, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_nv12 },
{ DRM_FORMAT_NV16, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_nv12 },
{ DRM_FORMAT_NV61, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_nv12 },
{ DRM_FORMAT_NV24, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_nv12 },
{ DRM_FORMAT_NV42, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_nv12 },
{ DRM_FORMAT_YUYV, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuyv },
{ DRM_FORMAT_YVYU, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuyv },
{ DRM_FORMAT_VYUY, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuyv },
{ DRM_FORMAT_UYVY, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuyv },
{ DRM_FORMAT_NV15, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_P210, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_P010, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_P012, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_P016, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_P030, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
/* 3-plane YUV */
{ DRM_FORMAT_Q410, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Q401, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_YUV410, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YVU410, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YUV411, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuv_3 },
@ -473,7 +577,7 @@ gdk_dmabuf_direct_downloader_supports (const GdkDmabufDownloader *downloader,
info = get_drm_format_info (dmabuf->fourcc);
if (!info)
if (!info || !info->download)
{
g_set_error (error,
GDK_DMABUF_ERROR, GDK_DMABUF_ERROR_UNSUPPORTED_FORMAT,
@ -512,6 +616,7 @@ gdk_dmabuf_direct_downloader_do_download (const GdkDmabufDownloader *downloader,
dmabuf = gdk_dmabuf_texture_get_dmabuf (GDK_DMABUF_TEXTURE (texture));
info = get_drm_format_info (dmabuf->fourcc);
g_return_if_fail (info->download);
GDK_DISPLAY_DEBUG (gdk_dmabuf_texture_get_display (GDK_DMABUF_TEXTURE (texture)), DMABUF,
"Using %s for downloading a dmabuf (format %.4s:%#" G_GINT64_MODIFIER "x)",