memoryformat: Put dmabuf fourccs into the big format table

I'm concentrating the data about memory formats, and this part was
missing.
This commit is contained in:
Benjamin Otte 2023-12-16 10:27:24 +01:00
parent 00566261b2
commit cccec91b66
4 changed files with 133 additions and 96 deletions

View File

@ -1170,100 +1170,6 @@ gdk_dmabuf_get_memory_format (guint32 fourcc,
return TRUE;
}
gboolean
gdk_dmabuf_get_fourcc (GdkMemoryFormat format,
guint32 *out_fourcc)
{
/* we're not walking the list on purpose, so that we can keep track
* of exact matches here. Certain DRM formats map to the same memory
* format and we don't want the list to accidentally get mixed up.
*/
switch (format)
{
case GDK_MEMORY_B8G8R8A8_PREMULTIPLIED:
case GDK_MEMORY_B8G8R8A8:
*out_fourcc = DRM_FORMAT_ARGB8888;
return TRUE;
case GDK_MEMORY_A8R8G8B8_PREMULTIPLIED:
case GDK_MEMORY_A8R8G8B8:
*out_fourcc = DRM_FORMAT_BGRA8888;
return TRUE;
case GDK_MEMORY_A8B8G8R8_PREMULTIPLIED:
case GDK_MEMORY_A8B8G8R8:
*out_fourcc = DRM_FORMAT_RGBA8888;
return TRUE;
case GDK_MEMORY_R8G8B8A8_PREMULTIPLIED:
case GDK_MEMORY_R8G8B8A8:
*out_fourcc = DRM_FORMAT_ABGR8888;
return TRUE;
case GDK_MEMORY_R8G8B8:
*out_fourcc = DRM_FORMAT_BGR888;
return TRUE;
case GDK_MEMORY_B8G8R8:
*out_fourcc = DRM_FORMAT_RGB888;
return TRUE;
case GDK_MEMORY_B8G8R8X8:
*out_fourcc = DRM_FORMAT_XRGB8888;
return TRUE;
case GDK_MEMORY_X8R8G8B8:
*out_fourcc = DRM_FORMAT_BGRX8888;
return TRUE;
case GDK_MEMORY_R8G8B8X8:
*out_fourcc = DRM_FORMAT_XBGR8888;
return TRUE;
case GDK_MEMORY_X8B8G8R8:
*out_fourcc = DRM_FORMAT_RGBX8888;
return TRUE;
case GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED:
case GDK_MEMORY_R16G16B16A16_FLOAT:
*out_fourcc = DRM_FORMAT_ABGR16161616F;
return TRUE;
case GDK_MEMORY_R16G16B16A16_PREMULTIPLIED:
case GDK_MEMORY_R16G16B16A16:
*out_fourcc = DRM_FORMAT_ABGR16161616;
return TRUE;
case GDK_MEMORY_G8:
*out_fourcc = DRM_FORMAT_R8;
return TRUE;
case GDK_MEMORY_G16:
*out_fourcc = DRM_FORMAT_R16;
return TRUE;
case GDK_MEMORY_R16G16B16:
case GDK_MEMORY_R16G16B16_FLOAT:
case GDK_MEMORY_R32G32B32_FLOAT:
case GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED:
case GDK_MEMORY_R32G32B32A32_FLOAT:
case GDK_MEMORY_G8A8_PREMULTIPLIED:
case GDK_MEMORY_G8A8:
case GDK_MEMORY_G16A16_PREMULTIPLIED:
case GDK_MEMORY_G16A16:
case GDK_MEMORY_A8:
case GDK_MEMORY_A16:
case GDK_MEMORY_A16_FLOAT:
case GDK_MEMORY_A32_FLOAT:
return FALSE;
case GDK_MEMORY_N_FORMATS:
default:
g_assert_not_reached ();
return FALSE;
}
}
GdkDmabufFormats *
gdk_dmabuf_get_mmap_formats (void)
{

View File

@ -70,7 +70,5 @@ gboolean gdk_dmabuf_fourcc_is_yuv (guint32
gboolean gdk_dmabuf_get_memory_format (guint32 fourcc,
gboolean premultiplied,
GdkMemoryFormat *out_format);
gboolean gdk_dmabuf_get_fourcc (GdkMemoryFormat format,
guint32 *out_fourcc);
#endif

View File

@ -20,6 +20,8 @@
#include "config.h"
#include "gdkmemoryformatprivate.h"
#include "gdkdmabuffourccprivate.h"
#include "gdkglcontextprivate.h"
#include "gsk/gl/fp16private.h"
@ -344,6 +346,9 @@ struct _GdkMemoryFormatDescription
} gl;
#ifdef GDK_RENDERING_VULKAN
VkFormat vk_format;
#endif
#ifdef HAVE_DMABUF
guint32 dmabuf_fourcc;
#endif
/* no premultiplication going on here */
void (* to_float) (float *, const guchar*, gsize);
@ -379,6 +384,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_B8G8R8A8_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_ARGB8888,
#endif
.to_float = b8g8r8a8_premultiplied_to_float,
.from_float = b8g8r8a8_premultiplied_from_float,
@ -403,6 +411,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_UNDEFINED,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_BGRA8888,
#endif
.to_float = a8r8g8b8_premultiplied_to_float,
.from_float = a8r8g8b8_premultiplied_from_float,
@ -426,6 +437,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R8G8B8A8_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_ABGR8888,
#endif
.to_float = r8g8b8a8_premultiplied_to_float,
.from_float = r8g8b8a8_premultiplied_from_float,
@ -450,6 +464,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_UNDEFINED,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_RGBA8888,
#endif
.to_float = a8b8g8r8_premultiplied_to_float,
.from_float = a8b8g8r8_premultiplied_from_float,
@ -474,6 +491,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_B8G8R8A8_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_ARGB8888,
#endif
.to_float = b8g8r8a8_to_float,
.from_float = b8g8r8a8_from_float,
@ -498,6 +518,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_UNDEFINED,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_BGRA8888,
#endif
.to_float = a8r8g8b8_to_float,
.from_float = a8r8g8b8_from_float,
@ -521,6 +544,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R8G8B8A8_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_ABGR8888,
#endif
.to_float = r8g8b8a8_to_float,
.from_float = r8g8b8a8_from_float,
@ -545,6 +571,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_UNDEFINED,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_RGBA8888,
#endif
.to_float = a8b8g8r8_to_float,
.from_float = a8b8g8r8_from_float,
@ -570,6 +599,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_B8G8R8A8_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_XRGB8888,
#endif
.to_float = b8g8r8x8_to_float,
.from_float = b8g8r8x8_from_float,
@ -595,6 +627,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_UNDEFINED,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_BGRX8888,
#endif
.to_float = x8r8g8b8_to_float,
.from_float = x8r8g8b8_from_float,
@ -619,6 +654,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R8G8B8A8_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_XBGR8888,
#endif
.to_float = r8g8b8x8_to_float,
.from_float = r8g8b8x8_from_float,
@ -644,6 +682,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_UNDEFINED,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_RGBX8888,
#endif
.to_float = x8b8g8r8_to_float,
.from_float = x8b8g8r8_from_float,
@ -668,6 +709,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R8G8B8_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_BGR888,
#endif
.to_float = r8g8b8_to_float,
.from_float = r8g8b8_from_float,
@ -693,6 +737,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_B8G8R8_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_RGB888,
#endif
.to_float = b8g8r8_to_float,
.from_float = b8g8r8_from_float,
@ -720,6 +767,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16G16B16_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = 0,
#endif
.to_float = r16g16b16_to_float,
.from_float = r16g16b16_from_float,
@ -746,6 +796,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16G16B16A16_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_ABGR16161616,
#endif
.to_float = r16g16b16a16_to_float,
.from_float = r16g16b16a16_from_float,
@ -772,6 +825,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16G16B16A16_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_ABGR16161616,
#endif
.to_float = r16g16b16a16_to_float,
.from_float = r16g16b16a16_from_float,
@ -798,6 +854,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16G16B16_SFLOAT,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = 0,
#endif
.to_float = r16g16b16_float_to_float,
.from_float = r16g16b16_float_from_float,
@ -823,6 +882,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16G16B16A16_SFLOAT,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_ABGR16161616F,
#endif
.to_float = r16g16b16a16_float_to_float,
.from_float = r16g16b16a16_float_from_float,
@ -848,6 +910,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16G16B16A16_SFLOAT,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_ABGR16161616F,
#endif
.to_float = r16g16b16a16_float_to_float,
.from_float = r16g16b16a16_float_from_float,
@ -874,6 +939,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R32G32B32_SFLOAT,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = 0,
#endif
.to_float = r32g32b32_float_to_float,
.from_float = r32g32b32_float_from_float,
@ -899,6 +967,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R32G32B32A32_SFLOAT,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = 0,
#endif
.to_float = r32g32b32a32_float_to_float,
.from_float = r32g32b32a32_float_from_float,
@ -924,6 +995,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R32G32B32A32_SFLOAT,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = 0,
#endif
.to_float = r32g32b32a32_float_to_float,
.from_float = r32g32b32a32_float_from_float,
@ -948,6 +1022,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R8G8_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = 0,
#endif
.to_float = g8a8_premultiplied_to_float,
.from_float = g8a8_premultiplied_from_float,
@ -972,6 +1049,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R8G8_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = 0,
#endif
.to_float = g8a8_to_float,
.from_float = g8a8_from_float,
@ -996,6 +1076,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R8_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_R8,
#endif
.to_float = g8_to_float,
.from_float = g8_from_float,
@ -1023,6 +1106,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16G16_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = 0,
#endif
.to_float = g16a16_premultiplied_to_float,
.from_float = g16a16_premultiplied_from_float,
@ -1050,6 +1136,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16G16_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = 0,
#endif
.to_float = g16a16_to_float,
.from_float = g16a16_from_float,
@ -1077,6 +1166,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = DRM_FORMAT_R16,
#endif
.to_float = g16_to_float,
.from_float = g16_from_float,
@ -1101,6 +1193,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R8_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = 0,
#endif
.to_float = a8_to_float,
.from_float = a8_from_float,
@ -1128,6 +1223,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16_UNORM,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = 0,
#endif
.to_float = a16_to_float,
.from_float = a16_from_float,
@ -1154,6 +1252,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16_SFLOAT,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = 0,
#endif
.to_float = a16_float_to_float,
.from_float = a16_float_from_float,
@ -1180,6 +1281,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R32_SFLOAT,
#endif
#ifdef HAVE_DMABUF
.dmabuf_fourcc = 0,
#endif
.to_float = a32_float_to_float,
.from_float = a32_float_from_float,
@ -1474,6 +1578,34 @@ gdk_memory_format_vk_rgba_format (GdkMemoryFormat format,
}
#endif
/*
* gdk_memory_format_get_dmabuf_fourcc:
* @format: The memory format
*
* Gets the dmabuf fourcc for a given memory format.
*
* The format is an exact match, so data can be copied between the
* dmabuf and data of the format. This is different from the
* memoryformat returned by a GdkDmabufTexture, which is just the
* closest match.
*
* Not all formats have a corresponding dmabuf format.
* In those cases 0 will be returned.
*
* If dmabuf support is not compiled in, always returns 0.
*
* Returns: the fourcc or 0
**/
guint32
gdk_memory_format_get_dmabuf_fourcc (GdkMemoryFormat format)
{
#ifdef HAVE_DMABUF
return memory_formats[format].dmabuf_fourcc;
#else
return 0;
#endif
}
static void
premultiply (float *rgba,
gsize n)

View File

@ -72,6 +72,7 @@ VkFormat gdk_memory_format_vk_rgba_format (GdkMemoryFormat
GdkMemoryFormat *out_rgba_format,
VkComponentMapping *out_swizzle);
#endif
guint32 gdk_memory_format_get_dmabuf_fourcc (GdkMemoryFormat format);
void gdk_memory_convert (guchar *dest_data,