From 270e1863115b44fbd259d06bc83147ea45ed64fb Mon Sep 17 00:00:00 2001 From: Jakub Adam Date: Mon, 2 Sep 2024 20:46:23 +0200 Subject: [PATCH] glcontext_egl: add method to check if format supports a modifier Makes _check_modifier from glupload reusable. Part-of: --- .../gst-libs/gst/gl/egl/gstglcontext_egl.c | 50 +++++++++++++++++++ .../gst-libs/gst/gl/egl/gstglcontext_egl.h | 7 +++ .../gst-libs/gst/gl/gstglupload.c | 35 ------------- 3 files changed, 57 insertions(+), 35 deletions(-) diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gstglcontext_egl.c b/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gstglcontext_egl.c index 0dae00df91..dfd7baaaeb 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gstglcontext_egl.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gstglcontext_egl.c @@ -57,6 +57,14 @@ #include "../viv-fb/gstglwindow_viv_fb_egl.h" #endif +#if GST_GL_HAVE_DMABUF +#ifdef HAVE_LIBDRM +#include +#endif +#else +#define DRM_FORMAT_MOD_LINEAR 0ULL +#endif + #define GST_CAT_DEFAULT gst_gl_context_debug typedef struct _GstGLDmaFormat GstGLDmaFormat; @@ -1830,6 +1838,48 @@ beach: return FALSE; } +/** + * gst_gl_context_egl_format_supports_modifier: (skip) + * @context: an EGL #GstGLContext + * @fourcc: the FourCC format to look up + * @modifier: the format modifier to check + * @include_externam: whether to take external-only modifiers into account + * + * Returns: %TRUE if @fourcc supports @modifier. + * + * Since: 1.26 + */ +gboolean +gst_gl_context_egl_format_supports_modifier (GstGLContext * context, + guint32 fourcc, guint64 modifier, gboolean include_external) +{ +#if GST_GL_HAVE_DMABUF + const GArray *dma_modifiers; + guint i; + + g_return_val_if_fail (GST_IS_GL_CONTEXT_EGL (context), FALSE); + + if (!gst_gl_context_egl_get_format_modifiers (context, fourcc, + &dma_modifiers)) + return FALSE; + + if (!dma_modifiers) { + /* fourcc found, but no modifier info; consider only linear is supported */ + return (modifier == DRM_FORMAT_MOD_LINEAR); + } + + for (i = 0; i < dma_modifiers->len; i++) { + GstGLDmaModifier *mod = &g_array_index (dma_modifiers, GstGLDmaModifier, i); + + if (!mod->external_only || include_external) { + if (mod->modifier == modifier) + return TRUE; + } + } +#endif + return FALSE; +} + /** * gst_gl_context_egl_supports_modifier: (skip) * @context: an EGL #GStGLContext diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gstglcontext_egl.h b/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gstglcontext_egl.h index 7732885b76..4af35a853f 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gstglcontext_egl.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gstglcontext_egl.h @@ -113,6 +113,13 @@ G_GNUC_INTERNAL gboolean gst_gl_context_egl_get_format_modifiers (GstGLContext * context, gint fourcc, const GArray ** modifiers); + +G_GNUC_INTERNAL +gboolean gst_gl_context_egl_format_supports_modifier (GstGLContext * context, + guint32 fourcc, + guint64 modifier, + gboolean include_external); + G_GNUC_INTERNAL gboolean gst_gl_context_egl_supports_modifier (GstGLContext * context); G_END_DECLS diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglupload.c b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglupload.c index 3898e9f390..a6d7378bbe 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglupload.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglupload.c @@ -867,41 +867,6 @@ _dma_buf_upload_new (GstGLUpload * upload) return dmabuf; } -static gboolean -_check_modifier (GstGLContext * context, guint32 fourcc, - guint64 modifier, gboolean include_external) -{ - const GArray *dma_modifiers; - guint i; - - /* If no context provide, no further check. */ - if (!context) - return TRUE; - - if (!gst_gl_context_egl_get_format_modifiers (context, fourcc, - &dma_modifiers)) - return FALSE; - - if (!dma_modifiers) { - /* recognize the fourcc but no modifier info, consider it as linear */ - if (modifier == DRM_FORMAT_MOD_LINEAR) - return TRUE; - - return FALSE; - } - - for (i = 0; i < dma_modifiers->len; i++) { - GstGLDmaModifier *mod = &g_array_index (dma_modifiers, GstGLDmaModifier, i); - - if (!mod->external_only || include_external) { - if (mod->modifier == modifier) - return TRUE; - } - } - - return FALSE; -} - static void _set_default_formats_list (GstStructure * structure) {