wpe: Don't crash when running on X11.

Don't assume the available EGL display is a wayland display -
instead, check the the GStreamer GL context is EGL, and then
use gst_gl_display_egl_from_gl_display to create a
GstGLDisplayEGL from that, which also adds refcounting
around the underlying EGLDisplay.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/issues/1385

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1752>
This commit is contained in:
Jan Schmidt 2020-08-15 02:02:44 +10:00 committed by GStreamer Merge Bot
parent c118ae11ab
commit 92472ef088
2 changed files with 22 additions and 8 deletions

View file

@ -214,18 +214,25 @@ WPEView::WPEView(WebKitWebContext* web_context, GstWpeSrc* src, GstGLContext* co
g_mutex_init(&images_mutex);
if (context)
gst.context = GST_GL_CONTEXT(gst_object_ref(context));
if (display)
if (display) {
gst.display = GST_GL_DISPLAY(gst_object_ref(display));
}
wpe.width = width;
wpe.height = height;
EGLDisplay eglDisplay = EGL_NO_DISPLAY;
if (context && display)
eglDisplay = gst_gl_display_egl_get_from_native(GST_GL_DISPLAY_TYPE_WAYLAND, gst_gl_display_get_handle(display));
GST_DEBUG("eglDisplay %p", eglDisplay);
if (context && display) {
if (gst_gl_context_get_gl_platform(context) == GST_GL_PLATFORM_EGL) {
gst.display_egl = gst_gl_display_egl_from_gl_display (gst.display);
} else {
GST_DEBUG ("Available GStreamer GL Context is not EGL - not creating an EGL display from it");
}
}
if (gst.display_egl) {
EGLDisplay eglDisplay = (EGLDisplay)gst_gl_display_get_handle (GST_GL_DISPLAY(gst.display_egl));
GST_DEBUG("eglDisplay %p", eglDisplay);
if (eglDisplay) {
m_isValid = wpe_fdo_initialize_for_egl_display(eglDisplay);
GST_DEBUG("FDO EGL display initialisation result: %d", m_isValid);
} else {
@ -239,7 +246,7 @@ WPEView::WPEView(WebKitWebContext* web_context, GstWpeSrc* src, GstGLContext* co
if (!m_isValid)
return;
if (eglDisplay) {
if (gst.display_egl) {
wpe.exportable = wpe_view_backend_exportable_fdo_egl_create(&s_exportableEGLClient, this, wpe.width, wpe.height);
} else {
#if ENABLE_SHM_BUFFER_SUPPORT
@ -305,6 +312,11 @@ WPEView::~WPEView()
}
});
if (gst.display_egl) {
gst_object_unref(gst.display_egl);
gst.display_egl = nullptr;
}
if (gst.display) {
gst_object_unref(gst.display);
gst.display = nullptr;

View file

@ -22,6 +22,7 @@
#include <EGL/egl.h>
#include <glib.h>
#include <gst/gl/gstglfuncs.h>
#include <gst/gl/egl/gstgldisplay_egl.h>
#include <wpe/fdo.h>
#include <wpe/fdo-egl.h>
#include <wpe/webkit.h>
@ -82,7 +83,8 @@ private:
struct {
GstGLContext* context;
GstGLDisplay* display;
} gst { nullptr, nullptr };
GstGLDisplayEGL* display_egl;
} gst { nullptr, nullptr, nullptr };
static struct wpe_view_backend_exportable_fdo_egl_client s_exportableEGLClient;
#if ENABLE_SHM_BUFFER_SUPPORT