From 82f63b0d64cbf9a0bc646174e339bc60e20e013b Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Mon, 22 Aug 2022 16:33:23 -0400 Subject: [PATCH] opengl: Fix usage of eglCreate/DestroyImage The implementation was inconsistent between create and destroy. EGLImage creation and destruction is requires for EGL 1.5 and up, while otherwise the KHR version is only available if EGL_KHR_image_base feature is set. Not doing these check may lead to getting a function pointer to a stub, which is notably the case when using apitrace. Fixes #1389 Part-of: --- .../gst-libs/gst/gl/egl/gsteglimage.c | 37 ++++++++++++++++------ 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gsteglimage.c b/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gsteglimage.c index cee66ac..756ecc0 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gsteglimage.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gsteglimage.c @@ -311,10 +311,8 @@ _gst_egl_image_create (GstGLContext * context, guint target, EGLContext egl_context = EGL_NO_CONTEXT; EGLImageKHR img = EGL_NO_IMAGE_KHR; GstGLDisplayEGL *display_egl; - gint plat_major, plat_minor; guint attrib_len = 0; - gst_gl_context_get_gl_platform_version (context, &plat_major, &plat_minor); display_egl = gst_gl_display_egl_from_gl_display (context->display); if (!display_egl) { @@ -333,6 +331,9 @@ _gst_egl_image_create (GstGLContext * context, guint target, while (attribs[attrib_len++] != EGL_NONE) { } #ifdef EGL_VERSION_1_5 + gint plat_major, plat_minor; + gst_gl_context_get_gl_platform_version (context, &plat_major, &plat_minor); + if (GST_GL_CHECK_GL_VERSION (plat_major, plat_minor, 1, 5)) { EGLImageKHR (*gst_eglCreateImage) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib * attrib_list); @@ -359,7 +360,7 @@ _gst_egl_image_create (GstGLContext * context, guint target, g_free (egl_attribs); } else #endif - { + if (gst_gl_context_check_feature (context, "EGL_KHR_image_base")) { EGLImageKHR (*gst_eglCreateImageKHR) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint * attrib_list); EGLint *egl_attribs = NULL; @@ -368,8 +369,8 @@ _gst_egl_image_create (GstGLContext * context, guint target, gst_eglCreateImageKHR = gst_gl_context_get_proc_address (context, "eglCreateImageKHR"); if (!gst_eglCreateImageKHR) { - GST_WARNING_OBJECT (context, "\"eglCreateImageKHR\" not exposed by the " - "implementation"); + GST_ERROR_OBJECT (context, "\"eglCreateImageKHR\" not exposed by the " + "implementation as required by EGL_KHR_image_base"); return EGL_NO_IMAGE_KHR; } @@ -383,6 +384,9 @@ _gst_egl_image_create (GstGLContext * context, guint target, egl_attribs); g_free (egl_attribs); + } else { + GST_INFO_OBJECT (context, "EGLImage creation not supported"); + return EGL_NO_IMAGE_KHR; } return img; @@ -395,16 +399,31 @@ _gst_egl_image_destroy (GstGLContext * context, EGLImageKHR image) EGLDisplay egl_display = EGL_DEFAULT_DISPLAY; GstGLDisplayEGL *display_egl; - gst_eglDestroyImage = gst_gl_context_get_proc_address (context, - "eglDestroyImage"); - if (!gst_eglDestroyImage) { +#ifdef EGL_VERSION_1_5 + gint plat_major, plat_minor; + gst_gl_context_get_gl_platform_version (context, &plat_major, &plat_minor); + + if (GST_GL_CHECK_GL_VERSION (plat_major, plat_minor, 1, 5)) { + gst_eglDestroyImage = gst_gl_context_get_proc_address (context, + "eglDestroyImage"); + if (!gst_eglDestroyImage) { + GST_ERROR_OBJECT (context, "\"eglDestroyImage\" not exposed by the " + "implementation as required by EGL >= 1.5"); + return; + } + } else +#endif + if (gst_gl_context_check_feature (context, "EGL_KHR_image_base")) { gst_eglDestroyImage = gst_gl_context_get_proc_address (context, "eglDestroyImageKHR"); if (!gst_eglDestroyImage) { GST_ERROR_OBJECT (context, "\"eglDestroyImage\" not exposed by the " - "implementation"); + "implementation as required by EGL_KHR_image_base"); return; } + } else { + GST_ERROR_OBJECT (context, "Destruction of EGLImage not supported."); + return; } display_egl = gst_gl_display_egl_from_gl_display (context->display); -- 2.7.4