diff --git a/gst-libs/gst/vaapi/Makefile.am b/gst-libs/gst/vaapi/Makefile.am index b29adf95c4..491208f92c 100644 --- a/gst-libs/gst/vaapi/Makefile.am +++ b/gst-libs/gst/vaapi/Makefile.am @@ -476,6 +476,7 @@ libgstvaapi_egl_la_CFLAGS = \ $(GMODULE_CFLAGS) \ $(GST_BASE_CFLAGS) \ $(GST_VIDEO_CFLAGS) \ + $(GST_GL_CFLAGS) \ $(LIBVA_CFLAGS) \ $(LIBVA_WAYLAND_CFLAGS) \ $(EGL_CFLAGS) \ @@ -487,6 +488,7 @@ libgstvaapi_egl_la_LIBADD = \ $(GST_LIBS) \ $(GST_BASE_LIBS) \ $(GST_VIDEO_LIBS) \ + $(GST_GL_LIBS) \ $(EGL_LIBS) \ $(NULL) diff --git a/gst-libs/gst/vaapi/gstvaapidisplay_egl.c b/gst-libs/gst/vaapi/gstvaapidisplay_egl.c index c4fdbc240a..884d0090a4 100644 --- a/gst-libs/gst/vaapi/gstvaapidisplay_egl.c +++ b/gst-libs/gst/vaapi/gstvaapidisplay_egl.c @@ -100,6 +100,7 @@ gst_vaapi_display_egl_bind_display (GstVaapiDisplay * base_display, GstVaapiDisplay *native_display = NULL; GstVaapiDisplayEGL *display = GST_VAAPI_DISPLAY_EGL (base_display); EglDisplay *egl_display; + guint gl_platform = EGL_PLATFORM_UNKNOWN; const InitParams *params = (InitParams *) native_params; if (params->display) { @@ -118,7 +119,19 @@ gst_vaapi_display_egl_bind_display (GstVaapiDisplay * base_display, gst_vaapi_display_replace (&display->display, native_display); - egl_display = egl_display_new (GST_VAAPI_DISPLAY_NATIVE (display->display)); + switch (GST_VAAPI_DISPLAY_GET_CLASS_TYPE (display->display)) { + case GST_VAAPI_DISPLAY_TYPE_X11: + gl_platform = EGL_PLATFORM_X11; + break; + case GST_VAAPI_DISPLAY_TYPE_WAYLAND: + gl_platform = EGL_PLATFORM_WAYLAND; + break; + default: + break; + } + + egl_display = egl_display_new (GST_VAAPI_DISPLAY_NATIVE (display->display), + gl_platform); if (!egl_display) return FALSE; diff --git a/gst-libs/gst/vaapi/gstvaapiutils_egl.c b/gst-libs/gst/vaapi/gstvaapiutils_egl.c index 0f0390993a..db570ad943 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils_egl.c +++ b/gst-libs/gst/vaapi/gstvaapiutils_egl.c @@ -22,6 +22,9 @@ #include "sysdeps.h" #include "gstvaapiutils_egl.h" +#if USE_GST_GL_HELPERS +# include +#endif #define DEBUG 1 #include "gstvaapidebug.h" @@ -534,6 +537,31 @@ egl_display_run (EglDisplay * display, EglContextRunFunc func, gpointer args) return TRUE; } +static gpointer +egl_get_display_from_native (guintptr native_display, guint gl_platform) +{ +#if USE_GST_GL_HELPERS + EGLDisplay ret; + GstGLDisplayType display_type = GST_GL_DISPLAY_TYPE_ANY; + + switch (gl_platform) { + case EGL_PLATFORM_X11: + display_type = GST_GL_DISPLAY_TYPE_X11; + break; + case EGL_PLATFORM_WAYLAND: + display_type = GST_GL_DISPLAY_TYPE_WAYLAND; + break; + default: + break; + } + + ret = gst_gl_display_egl_get_from_native (display_type, native_display); + if (ret != EGL_NO_DISPLAY) + return ret; +#endif + return eglGetDisplay ((EGLNativeDisplayType) native_display); +} + static gpointer egl_display_thread (gpointer data) { @@ -543,7 +571,9 @@ egl_display_thread (gpointer data) gchar **gl_apis, **gl_api; if (!display->base.is_wrapped) { - gl_display = display->base.handle.p = eglGetDisplay (gl_display); + gl_display = display->base.handle.p = + egl_get_display_from_native (display->base.handle.u, + display->gl_platform); if (!gl_display) goto error; if (!eglInitialize (gl_display, &major_version, &minor_version)) @@ -643,7 +673,7 @@ egl_display_finalize (EglDisplay * display) } static EglDisplay * -egl_display_new_full (gpointer handle, gboolean is_wrapped) +egl_display_new_full (gpointer handle, gboolean is_wrapped, guint platform) { EglDisplay *display; @@ -653,6 +683,7 @@ egl_display_new_full (gpointer handle, gboolean is_wrapped) display->base.handle.p = handle; display->base.is_wrapped = is_wrapped; + display->gl_platform = platform; if (!egl_display_init (display)) goto error; return display; @@ -666,11 +697,11 @@ error: } EglDisplay * -egl_display_new (gpointer native_display) +egl_display_new (gpointer native_display, guint platform) { g_return_val_if_fail (native_display != NULL, NULL); - return egl_display_new_full (native_display, FALSE); + return egl_display_new_full (native_display, FALSE, platform); } EglDisplay * @@ -678,7 +709,7 @@ egl_display_new_wrapped (EGLDisplay gl_display) { g_return_val_if_fail (gl_display != EGL_NO_DISPLAY, NULL); - return egl_display_new_full (gl_display, TRUE); + return egl_display_new_full (gl_display, TRUE, EGL_PLATFORM_UNKNOWN); } /* ------------------------------------------------------------------------- */ diff --git a/gst-libs/gst/vaapi/gstvaapiutils_egl.h b/gst-libs/gst/vaapi/gstvaapiutils_egl.h index fa0820286b..2dcdf6836b 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils_egl.h +++ b/gst-libs/gst/vaapi/gstvaapiutils_egl.h @@ -51,6 +51,12 @@ typedef struct egl_window_s EglWindow; #define GL_PROTO_END() ; #include "egl_vtable.h" +enum { + EGL_PLATFORM_UNKNOWN, + EGL_PLATFORM_X11, + EGL_PLATFORM_WAYLAND, +}; + union egl_handle_s { gpointer p; @@ -109,6 +115,7 @@ struct egl_display_s gchar *gl_version_string; gchar *gl_apis_string; guint gl_apis; /* EGL_*_BIT mask */ + guint gl_platform; GMutex mutex; GThread *gl_thread; @@ -187,7 +194,7 @@ struct egl_window_s G_GNUC_INTERNAL EglDisplay * -egl_display_new (gpointer native_display); +egl_display_new (gpointer native_display, guint gl_platform); G_GNUC_INTERNAL EglDisplay *