From b2a5b4f304a713d46d278a3658df3e114d31c5f2 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Tue, 18 Feb 2025 16:46:15 +1100 Subject: [PATCH] qt/6: mark GstGLDisplayEGLs that would be created as foreign Otherwise, GStreamer may preemptively call eglTerminate() before Qt has finished using the EGLDisplay. Part-of: --- .../gst-plugins-good/ext/qt/gstqtglutility.cc | 13 +++++++++++-- .../gst-plugins-good/ext/qt6/gstqt6glutility.cc | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/subprojects/gst-plugins-good/ext/qt/gstqtglutility.cc b/subprojects/gst-plugins-good/ext/qt/gstqtglutility.cc index a9d2f38fe3..6af87aa859 100644 --- a/subprojects/gst-plugins-good/ext/qt/gstqtglutility.cc +++ b/subprojects/gst-plugins-good/ext/qt/gstqtglutility.cc @@ -102,12 +102,18 @@ gst_qt_get_gl_display (gboolean sink) if (QString::fromUtf8 ("wayland") == app->platformName() || QString::fromUtf8 ("wayland-egl") == app->platformName()){ struct wl_display * wayland_display; + GstGLDisplayEGL *display_egl; QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface(); wayland_display = (struct wl_display *) native->nativeResourceForWindow("display", NULL); display = (GstGLDisplay *) gst_gl_display_wayland_new_with_display (wayland_display); + + display_egl = gst_gl_display_egl_from_gl_display (display); + if (display_egl) + gst_gl_display_egl_set_foreign (display_egl, TRUE); + gst_clear_object (&display_egl); } #endif #if GST_GL_HAVE_PLATFORM_EGL && GST_GL_HAVE_WINDOW_ANDROID @@ -144,8 +150,11 @@ gst_qt_get_gl_display (gboolean sink) QGuiApplication::platformNativeInterface(); EGLDisplay egl_display = (EGLDisplay) native->nativeResourceForWindow("egldisplay", NULL); - if (egl_display != EGL_NO_DISPLAY) - display = (GstGLDisplay *) gst_gl_display_egl_new_with_egl_display (egl_display); + if (egl_display != EGL_NO_DISPLAY) { + GstGLDisplayEGL *display_egl = gst_gl_display_egl_new_with_egl_display (egl_display); + gst_gl_display_egl_set_foreign (display_egl, TRUE); + display = (GstGLDisplay *) display_egl; + } #else EGLDisplay egl_display = (EGLDisplay) gst_gl_display_egl_get_from_native (GST_GL_DISPLAY_TYPE_ANY, 0); display = (GstGLDisplay *) gst_gl_display_egl_new_with_egl_display (egl_display); diff --git a/subprojects/gst-plugins-good/ext/qt6/gstqt6glutility.cc b/subprojects/gst-plugins-good/ext/qt6/gstqt6glutility.cc index e40fcb75f5..c32b3dbe4a 100644 --- a/subprojects/gst-plugins-good/ext/qt6/gstqt6glutility.cc +++ b/subprojects/gst-plugins-good/ext/qt6/gstqt6glutility.cc @@ -102,12 +102,18 @@ gst_qml6_get_gl_display (gboolean sink) if (QString::fromUtf8 ("wayland") == app->platformName() || QString::fromUtf8 ("wayland-egl") == app->platformName()){ struct wl_display * wayland_display; + GstGLDisplayEGL *display_egl; QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface(); wayland_display = (struct wl_display *) native->nativeResourceForWindow("display", NULL); display = (GstGLDisplay *) gst_gl_display_wayland_new_with_display (wayland_display); + + display_egl = gst_gl_display_egl_from_gl_display (display); + if (display_egl) + gst_gl_display_egl_set_foreign (display_egl, TRUE); + gst_clear_object (&display_egl); } #endif #if GST_GL_HAVE_PLATFORM_EGL && GST_GL_HAVE_WINDOW_ANDROID @@ -144,8 +150,11 @@ gst_qml6_get_gl_display (gboolean sink) QGuiApplication::platformNativeInterface(); EGLDisplay egl_display = (EGLDisplay) native->nativeResourceForWindow("egldisplay", NULL); - if (egl_display != EGL_NO_DISPLAY) - display = (GstGLDisplay *) gst_gl_display_egl_new_with_egl_display (egl_display); + if (egl_display != EGL_NO_DISPLAY) { + GstGLDisplayEGL *display_egl = gst_gl_display_egl_new_with_egl_display (egl_display); + gst_gl_display_egl_set_foreign (display_egl, TRUE); + display = (GstGLDisplay *) display_egl; + } #else EGLDisplay egl_display = (EGLDisplay) gst_gl_display_egl_get_from_native (GST_GL_DISPLAY_TYPE_ANY, 0); display = (GstGLDisplay *) gst_gl_display_egl_new_with_egl_display (egl_display);