dmabuf: Allow implicit modifiers

Remove all the roadblocks we've put up to keep implicit modifiers
out. Our importing code already handles them as a signal that says
'No modifiers, please!'. Now we just hope for the best and pass
things along.

This is necessary since some drivers won't produce any explicit
modifiers.
This commit is contained in:
Matthias Clasen 2023-10-24 01:08:17 -04:00
parent 8f90ddb906
commit eb048c91be
5 changed files with 17 additions and 30 deletions

View File

@ -559,11 +559,10 @@ gdk_dmabuf_get_direct_downloader (void)
*
* 1. Disallow any dmabuf format that we do not know.
*
* 1. Reject the INVALID modifier, accept the LINEAR one.
* 2. Ignore non-linear modifiers.
*
* 2. Ignore all other modifiers.
*
* 3. Try and fix various inconsistencies between V4L and Mesa, like NV12.
* 3. Try and fix various inconsistencies between V4L and Mesa
* for linear modifiers, like the e.g. single-plane NV12.
*
* *** WARNING ***
*
@ -592,14 +591,6 @@ 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)

View File

@ -113,6 +113,12 @@ gdk_dmabuf_egl_downloader_collect_formats (const GdkDmabufDownloader *downloader
if (external_only[j])
gdk_dmabuf_formats_builder_add_format (external, fourccs[i], modifiers[j]);
}
/* Accept implicit modifiers as long as we accept the format at all.
* This is a bit of a crapshot, but unfortunately needed for a bunch
* of drivers.
*/
gdk_dmabuf_formats_builder_add_format (formats, fourccs[i], DRM_FORMAT_MOD_INVALID);
}
g_free (modifiers);

View File

@ -37,6 +37,10 @@
* The list of supported formats is sorted by preference,
* with the best formats coming first.
*
* The list may contains (format, modfier) pairs where the modifier
* is `DMA_FORMAT_MOD_INVALID`, indicating that **_implicit modifiers_**
* may be used with this format.
*
* See [class@Gdk.DmabufTextureBuilder] for more information
* about DMA buffers.
*

View File

@ -22,9 +22,6 @@
#include "gdkdmabufformatsprivate.h"
#ifdef HAVE_DMABUF
#include <drm_fourcc.h>
#endif
#define GDK_ARRAY_NAME gdk_dmabuf_formats_builder
#define GDK_ARRAY_TYPE_NAME GdkDmabufFormatsBuilder
@ -121,12 +118,6 @@ gdk_dmabuf_formats_builder_add_format (GdkDmabufFormatsBuilder *self,
guint32 fourcc,
guint64 modifier)
{
#ifdef HAVE_DMABUF
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

@ -29,8 +29,6 @@
#include <cairo-gobject.h>
#ifdef HAVE_DMABUF
#include <drm_fourcc.h>
#else
#define DRM_FORMAT_MOD_INVALID ((1ULL << 56) - 1)
#endif
@ -90,6 +88,10 @@ struct _GdkDmabufTextureBuilderClass
* characters. Additionally, each DMA buffer has a **_modifier_**, which is a 64-bit integer
* that describes driver-specific details of the memory layout, such as tiling or compression.
*
* For historical reasons, some producers of dma-bufs don't provide an explicit modifier, but
* instead return `DMA_FORMAT_MOD_INVALID` to indicate that their modifier is **_impliict_**.
* GTK tries to accomodate this situation by accepting `DMA_FORMAT_MOD_INVALID` as modifier.
*
* The operation of `GdkDmabufTextureBuilder` is quite simple: Create a texture builder,
* set all the necessary properties, and then call [method@Gdk.DmabufTextureBuilder.build]
* to create the new texture.
@ -611,13 +613,6 @@ 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;