diff --git a/gst-libs/gst/vaapi/gstvaapiutils_glx.c b/gst-libs/gst/vaapi/gstvaapiutils_glx.c index de6ea3f6be..b7ba744d99 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils_glx.c +++ b/gst-libs/gst/vaapi/gstvaapiutils_glx.c @@ -211,6 +211,21 @@ gl_make_current(Display *dpy, Window win, GLXContext ctx, GLContextState *state) return glXMakeCurrent(dpy, win, ctx); } +/** + * gl_swap_buffers: + * @dpy: an X11 #Display + * @win: an X11 #Window + * + * Promotes the contents of the back buffer of the @win window to + * become the contents of the front buffer. This simply is wrapper + * around glXSwapBuffers(). + */ +void +gl_swap_buffers(Display *dpy, Window win) +{ + glXSwapBuffers(dpy, win); +} + /** * gl_bind_texture: * @ts: a #GLTextureState diff --git a/gst-libs/gst/vaapi/gstvaapiutils_glx.h b/gst-libs/gst/vaapi/gstvaapiutils_glx.h index 1902daa411..69d0048c37 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils_glx.h +++ b/gst-libs/gst/vaapi/gstvaapiutils_glx.h @@ -64,6 +64,10 @@ gboolean gl_make_current(Display *dpy, Window win, GLXContext ctx, GLContextState *state) attribute_hidden; +void +gl_swap_buffers(Display *dpy, Window win) + attribute_hidden; + typedef struct _GLTextureState GLTextureState; struct _GLTextureState { gboolean was_enabled; diff --git a/gst-libs/gst/vaapi/gstvaapiwindow_glx.c b/gst-libs/gst/vaapi/gstvaapiwindow_glx.c index 025bfbda1e..a1f9dc6c8b 100644 --- a/gst-libs/gst/vaapi/gstvaapiwindow_glx.c +++ b/gst-libs/gst/vaapi/gstvaapiwindow_glx.c @@ -50,6 +50,7 @@ struct _GstVaapiWindowGLXPrivate { guint is_constructed : 1; guint foreign_context : 1; guint foreign_window : 1; + guint swapped_buffers : 1; }; enum { @@ -112,8 +113,13 @@ gst_vaapi_window_glx_destroy_context(GstVaapiWindowGLX *window) if (priv->context) { if (!priv->foreign_context) { GST_VAAPI_OBJECT_LOCK_DISPLAY(window); - if (glXGetCurrentContext() == priv->context) + if (glXGetCurrentContext() == priv->context) { + /* XXX: if buffers were never swapped, the application + will crash later with the NVIDIA driver */ + if (!priv->swapped_buffers) + gl_swap_buffers(dpy, GST_VAAPI_OBJECT_ID(window)); gl_make_current(dpy, None, NULL, NULL); + } glXDestroyContext(dpy, priv->context); GST_VAAPI_OBJECT_UNLOCK_DISPLAY(window); } @@ -429,6 +435,7 @@ gst_vaapi_window_glx_init(GstVaapiWindowGLX *window) priv->is_constructed = FALSE; priv->foreign_context = FALSE; priv->foreign_window = FALSE; + priv->swapped_buffers = FALSE; } /** @@ -572,12 +579,14 @@ gst_vaapi_window_glx_swap_buffers(GstVaapiWindowGLX *window) g_return_if_fail(window->priv->is_constructed); GST_VAAPI_OBJECT_LOCK_DISPLAY(window); - glXSwapBuffers( + gl_swap_buffers( GST_VAAPI_OBJECT_XDISPLAY(window), GST_VAAPI_OBJECT_ID(window) ); glClear(GL_COLOR_BUFFER_BIT); GST_VAAPI_OBJECT_UNLOCK_DISPLAY(window); + + window->priv->swapped_buffers = TRUE; } /**