mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-14 03:15:47 +00:00
display: egl: create VaapiDisplayEGL with native EGL display
gst_vaapi_display_egl_new_with_native_display() has been broken since it wasn't used. Currently it's needed to call this API to create a display providing the EGL display, so it could avoid duplicated calls to the native display (eg. eglTerminate). Signed-off-by: Victor Jaquez <vjaquez@igalia.com> https://bugzilla.gnome.org/show_bug.cgi?id=795391
This commit is contained in:
parent
bb8894aaf9
commit
50470ae89f
2 changed files with 60 additions and 22 deletions
|
@ -50,6 +50,7 @@ typedef struct
|
|||
gpointer display;
|
||||
guint display_type;
|
||||
guint gles_version;
|
||||
gpointer gl_display;
|
||||
} InitParams;
|
||||
|
||||
static gboolean
|
||||
|
@ -97,27 +98,36 @@ static gboolean
|
|||
gst_vaapi_display_egl_bind_display (GstVaapiDisplay * base_display,
|
||||
gpointer native_params)
|
||||
{
|
||||
GstVaapiDisplay *native_display = NULL;
|
||||
GstVaapiDisplay *native_vaapi_display;
|
||||
GstVaapiDisplayEGL *display = GST_VAAPI_DISPLAY_EGL (base_display);
|
||||
EglDisplay *egl_display;
|
||||
EGLDisplay *native_egl_display;
|
||||
guint gl_platform = EGL_PLATFORM_UNKNOWN;
|
||||
const InitParams *params = (InitParams *) native_params;
|
||||
|
||||
if (params->display) {
|
||||
native_display = params->display;
|
||||
} else {
|
||||
native_vaapi_display = params->display;
|
||||
native_egl_display = params->gl_display;
|
||||
|
||||
if (!native_vaapi_display) {
|
||||
#if USE_X11
|
||||
native_display = gst_vaapi_display_x11_new (NULL);
|
||||
if (params->display_type == GST_VAAPI_DISPLAY_TYPE_ANY
|
||||
|| params->display_type == GST_VAAPI_DISPLAY_TYPE_X11
|
||||
|| params->display_type == GST_VAAPI_DISPLAY_TYPE_EGL)
|
||||
native_vaapi_display = gst_vaapi_display_x11_new (NULL);
|
||||
#endif
|
||||
#if USE_WAYLAND
|
||||
if (!native_display)
|
||||
native_display = gst_vaapi_display_wayland_new (NULL);
|
||||
if (!native_vaapi_display)
|
||||
native_vaapi_display = gst_vaapi_display_wayland_new (NULL);
|
||||
#endif
|
||||
} else {
|
||||
/* thus it could be unrefed */
|
||||
gst_object_ref (native_vaapi_display);
|
||||
}
|
||||
if (!native_display)
|
||||
if (!native_vaapi_display)
|
||||
return FALSE;
|
||||
|
||||
gst_vaapi_display_replace (&display->display, native_display);
|
||||
gst_vaapi_display_replace (&display->display, native_vaapi_display);
|
||||
gst_object_unref (native_vaapi_display);
|
||||
|
||||
switch (GST_VAAPI_DISPLAY_GET_CLASS_TYPE (display->display)) {
|
||||
case GST_VAAPI_DISPLAY_TYPE_X11:
|
||||
|
@ -130,8 +140,12 @@ gst_vaapi_display_egl_bind_display (GstVaapiDisplay * base_display,
|
|||
break;
|
||||
}
|
||||
|
||||
egl_display = egl_display_new (GST_VAAPI_DISPLAY_NATIVE (display->display),
|
||||
gl_platform);
|
||||
if (native_egl_display) {
|
||||
egl_display = egl_display_new_wrapped (native_egl_display);
|
||||
} else {
|
||||
egl_display = egl_display_new (GST_VAAPI_DISPLAY_NATIVE (display->display),
|
||||
gl_platform);
|
||||
}
|
||||
if (!egl_display)
|
||||
return FALSE;
|
||||
|
||||
|
@ -385,13 +399,14 @@ GstVaapiDisplay *
|
|||
gst_vaapi_display_egl_new_with_native_display (gpointer native_display,
|
||||
GstVaapiDisplayType display_type, guint gles_version)
|
||||
{
|
||||
InitParams params;
|
||||
InitParams params = { NULL, };
|
||||
|
||||
g_return_val_if_fail (native_display != NULL, NULL);
|
||||
|
||||
params.display = native_display;
|
||||
params.display_type = display_type;
|
||||
params.gles_version = gles_version;
|
||||
params.gl_display = native_display;
|
||||
|
||||
return gst_vaapi_display_new (g_object_new (GST_TYPE_VAAPI_DISPLAY_EGL, NULL),
|
||||
GST_VAAPI_DISPLAY_INIT_FROM_NATIVE_DISPLAY, ¶ms);
|
||||
}
|
||||
|
|
|
@ -41,6 +41,9 @@
|
|||
#endif
|
||||
#if USE_GST_GL_HELPERS
|
||||
# include <gst/gl/gl.h>
|
||||
#if USE_EGL && GST_GL_HAVE_PLATFORM_EGL
|
||||
# include <gst/gl/egl/gstgldisplay_egl.h>
|
||||
#endif
|
||||
#endif
|
||||
#include "gstvaapipluginutil.h"
|
||||
#include "gstvaapipluginbase.h"
|
||||
|
@ -140,7 +143,7 @@ gst_vaapi_create_display_from_gl_context (GstObject * gl_context_object)
|
|||
gpointer native_display =
|
||||
GSIZE_TO_POINTER (gst_gl_display_get_handle (gl_display));
|
||||
GstGLPlatform platform = gst_gl_context_get_gl_platform (gl_context);
|
||||
GstVaapiDisplay *display, *out_display;
|
||||
GstVaapiDisplay *display, *out_display = NULL;
|
||||
GstVaapiDisplayType display_type;
|
||||
|
||||
switch (gst_gl_display_get_handle_type (gl_display)) {
|
||||
|
@ -195,16 +198,25 @@ gst_vaapi_create_display_from_gl_context (GstObject * gl_context_object)
|
|||
display_type = GST_VAAPI_DISPLAY_TYPE_ANY;
|
||||
break;
|
||||
}
|
||||
gst_object_unref (gl_display);
|
||||
|
||||
display = gst_vaapi_create_display_from_handle (display_type, native_display);
|
||||
if (!display)
|
||||
return NULL;
|
||||
goto bail;
|
||||
|
||||
switch (platform) {
|
||||
#if USE_EGL
|
||||
case GST_GL_PLATFORM_EGL:{
|
||||
guint gles_version;
|
||||
guintptr egl_handle = 0;
|
||||
#if GST_GL_HAVE_PLATFORM_EGL
|
||||
GstGLDisplayEGL *egl_display;
|
||||
|
||||
egl_display = gst_gl_display_egl_from_gl_display (gl_display);
|
||||
if (egl_display) {
|
||||
egl_handle = gst_gl_display_get_handle (GST_GL_DISPLAY (egl_display));
|
||||
gst_object_unref (egl_display);
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (gst_gl_context_get_gl_api (gl_context)) {
|
||||
case GST_GL_API_GLES1:
|
||||
|
@ -217,16 +229,21 @@ gst_vaapi_create_display_from_gl_context (GstObject * gl_context_object)
|
|||
case GST_GL_API_OPENGL3:
|
||||
gles_version = 0;
|
||||
create_egl_display:
|
||||
out_display = gst_vaapi_display_egl_new (display, gles_version);
|
||||
if (egl_handle != 0) {
|
||||
out_display =
|
||||
gst_vaapi_display_egl_new_with_native_display
|
||||
(GSIZE_TO_POINTER (egl_handle), display_type, gles_version);
|
||||
} else {
|
||||
out_display = gst_vaapi_display_egl_new (display, gles_version);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
out_display = NULL;
|
||||
break;
|
||||
}
|
||||
if (!out_display) {
|
||||
gst_vaapi_display_unref (display);
|
||||
return NULL;
|
||||
}
|
||||
if (!out_display)
|
||||
goto bail;
|
||||
|
||||
gst_vaapi_display_egl_set_gl_context (GST_VAAPI_DISPLAY_EGL (out_display),
|
||||
GSIZE_TO_POINTER (gst_gl_context_get_gl_context (gl_context)));
|
||||
break;
|
||||
|
@ -236,7 +253,13 @@ gst_vaapi_create_display_from_gl_context (GstObject * gl_context_object)
|
|||
out_display = gst_vaapi_display_ref (display);
|
||||
break;
|
||||
}
|
||||
gst_vaapi_display_unref (display);
|
||||
|
||||
bail:
|
||||
if (display)
|
||||
gst_vaapi_display_unref (display);
|
||||
|
||||
if (gl_display)
|
||||
gst_object_unref (gl_display);
|
||||
return out_display;
|
||||
#endif
|
||||
GST_ERROR ("unsupported GStreamer version %s", GST_API_VERSION_S);
|
||||
|
|
Loading…
Reference in a new issue