dmabuf: NV12 is opaque

Getting this wrong matters, since we won't offload textures in
non-opaque formats. Found by Robert Mader. At the same time,
unify the two places we have for mapping from fourcc to memory
format.
This commit is contained in:
Matthias Clasen 2023-11-11 23:56:01 +01:00
parent cc2d3fa7d6
commit 6ae9cbfe0f
3 changed files with 18 additions and 71 deletions

View File

@ -367,6 +367,20 @@ get_drm_format_info (guint32 fourcc)
return NULL;
}
GdkMemoryFormat
gdk_dmabuf_get_memory_format (guint32 fourcc,
gboolean premultiplied)
{
const GdkDrmFormatInfo *info = get_drm_format_info (fourcc);
if (info)
return premultiplied ? info->premultiplied_memory_format
: info->unpremultiplied_memory_format;
return premultiplied ? GDK_MEMORY_A8R8G8B8_PREMULTIPLIED
: GDK_MEMORY_A8R8G8B8;
}
static gboolean
gdk_dmabuf_direct_downloader_add_formats (const GdkDmabufDownloader *downloader,
GdkDisplay *display,

View File

@ -163,76 +163,6 @@ gdk_dmabuf_egl_downloader_add_formats (const GdkDmabufDownloader *downloader,
return retval;
}
static GdkMemoryFormat
get_memory_format (guint32 fourcc,
gboolean premultiplied)
{
switch (fourcc)
{
case DRM_FORMAT_ARGB8888:
case DRM_FORMAT_ABGR8888:
case DRM_FORMAT_XRGB8888_A8:
case DRM_FORMAT_XBGR8888_A8:
return premultiplied ? GDK_MEMORY_A8R8G8B8_PREMULTIPLIED : GDK_MEMORY_A8R8G8B8;
case DRM_FORMAT_RGBA8888:
case DRM_FORMAT_RGBX8888_A8:
return premultiplied ? GDK_MEMORY_R8G8B8A8_PREMULTIPLIED : GDK_MEMORY_R8G8B8A8;
case DRM_FORMAT_BGRA8888:
return premultiplied ? GDK_MEMORY_B8G8R8A8_PREMULTIPLIED : GDK_MEMORY_B8G8R8A8;
case DRM_FORMAT_RGB888:
case DRM_FORMAT_XRGB8888:
case DRM_FORMAT_XBGR8888:
case DRM_FORMAT_RGBX8888:
case DRM_FORMAT_BGRX8888:
return GDK_MEMORY_R8G8B8;
case DRM_FORMAT_BGR888:
return GDK_MEMORY_B8G8R8;
case DRM_FORMAT_XRGB2101010:
case DRM_FORMAT_XBGR2101010:
case DRM_FORMAT_RGBX1010102:
case DRM_FORMAT_BGRX1010102:
case DRM_FORMAT_XRGB16161616:
case DRM_FORMAT_XBGR16161616:
return GDK_MEMORY_R16G16B16;
case DRM_FORMAT_ARGB2101010:
case DRM_FORMAT_ABGR2101010:
case DRM_FORMAT_RGBA1010102:
case DRM_FORMAT_BGRA1010102:
case DRM_FORMAT_ARGB16161616:
case DRM_FORMAT_ABGR16161616:
return premultiplied ? GDK_MEMORY_R16G16B16A16_PREMULTIPLIED : GDK_MEMORY_R16G16B16A16;
case DRM_FORMAT_ARGB16161616F:
case DRM_FORMAT_ABGR16161616F:
return premultiplied ? GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED : GDK_MEMORY_R16G16B16A16_FLOAT;
case DRM_FORMAT_XRGB16161616F:
case DRM_FORMAT_XBGR16161616F:
return GDK_MEMORY_R16G16B16_FLOAT;
case DRM_FORMAT_YUYV:
case DRM_FORMAT_YVYU:
case DRM_FORMAT_UYVY:
case DRM_FORMAT_VYUY:
case DRM_FORMAT_XYUV8888:
#ifdef DRM_FORMAT_XVUY8888
case DRM_FORMAT_XVUY8888:
#endif
case DRM_FORMAT_VUY888:
return GDK_MEMORY_R8G8B8;
/* Add more formats here */
default:
return premultiplied ? GDK_MEMORY_A8R8G8B8_PREMULTIPLIED : GDK_MEMORY_A8R8G8B8;
}
}
static gboolean
gdk_dmabuf_egl_downloader_supports (const GdkDmabufDownloader *downloader,
GdkDisplay *display,
@ -243,7 +173,7 @@ gdk_dmabuf_egl_downloader_supports (const GdkDmabufDownloader *downloader,
{
if (gdk_dmabuf_formats_contains (display->egl_dmabuf_formats, dmabuf->fourcc, dmabuf->modifier))
{
*out_format = get_memory_format (dmabuf->fourcc, premultiplied);
*out_format = gdk_dmabuf_get_memory_format (dmabuf->fourcc, premultiplied);
return TRUE;
}

View File

@ -51,4 +51,7 @@ gboolean gdk_dmabuf_sanitize (GdkDmabuf
gboolean gdk_dmabuf_is_disjoint (const GdkDmabuf *dmabuf);
GdkMemoryFormat gdk_dmabuf_get_memory_format (guint32 fourcc,
gboolean premultiplied);
#endif