dmabuf: Reject the INVALID modifier

Trying to use it is a programming error, applications should have code
that uses real modifiers.

Also add a check to the formatsbuilder so our code doesn't include the
invalid modifier by accident.

We don't really know how to deal with it, so better force applications
to figure out what to do.
This commit is contained in:
Benjamin Otte 2023-10-22 16:51:02 +02:00
parent 13848969f4
commit 98f02f6221
3 changed files with 31 additions and 1 deletions

View File

@ -484,6 +484,14 @@ gdk_dmabuf_sanitize (GdkDmabuf *dest,
return FALSE;
}
if (src->modifier == DRM_FORMAT_MOD_INVALID)
{
g_set_error (error,
GDK_DMABUF_ERROR, GDK_DMABUF_ERROR_UNSUPPORTED_FORMAT,
"GTK does not support the INVALID modifier.");
return FALSE;
}
info = get_drm_format_info (src->fourcc);
if (info == NULL)
@ -497,7 +505,7 @@ gdk_dmabuf_sanitize (GdkDmabuf *dest,
*dest = *src;
if (src->modifier && src->modifier != DRM_FORMAT_MOD_INVALID)
if (src->modifier)
return TRUE;
switch (dest->fourcc)

View File

@ -22,6 +22,10 @@
#include "gdkdmabufformatsprivate.h"
#ifdef HAVE_LINUX_DMA_BUF_H
#include <drm/drm_fourcc.h>
#endif
#define GDK_ARRAY_NAME gdk_dmabuf_formats_builder
#define GDK_ARRAY_TYPE_NAME GdkDmabufFormatsBuilder
#define GDK_ARRAY_ELEMENT_TYPE GdkDmabufFormat
@ -117,6 +121,12 @@ gdk_dmabuf_formats_builder_add_format (GdkDmabufFormatsBuilder *self,
guint32 fourcc,
guint64 modifier)
{
#ifdef HAVE_LINUX_DMA_BUF_H
g_return_if_fail (modifier != DRM_FORMAT_MOD_INVALID);
#else
g_return_if_reached ();
#endif
gdk_dmabuf_formats_builder_append (self, &(GdkDmabufFormat) { fourcc, modifier });
}

View File

@ -27,6 +27,11 @@
#include "gdkdmabuftextureprivate.h"
#include <cairo-gobject.h>
#ifdef HAVE_LINUX_DMA_BUF_H
#include <drm/drm_fourcc.h>
#else
#define DRM_FORMAT_MOD_INVALID ((1ULL << 56) - 1)
#endif
struct _GdkDmabufTextureBuilder
@ -598,6 +603,13 @@ gdk_dmabuf_texture_builder_set_modifier (GdkDmabufTextureBuilder *self,
guint64 modifier)
{
g_return_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self));
if (modifier == DRM_FORMAT_MOD_INVALID)
{
g_critical ("GTK does not support the INVALID modifier. "
"If you use code that produces it, it should include "
"instructions how to transform it into a regular modifier.");
return;
}
if (self->dmabuf.modifier == modifier)
return;