mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-27 10:40:34 +00:00
gldisplay: Add gst_gl_display_ensure_context
See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/439 Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3843>
This commit is contained in:
parent
06b778e0a1
commit
0da0da69aa
2 changed files with 59 additions and 1 deletions
|
@ -1014,3 +1014,57 @@ gst_gl_display_remove_context (GstGLDisplay * display, GstGLContext * needle)
|
|||
GST_WARNING_OBJECT (display, "%" GST_PTR_FORMAT " was not found in this "
|
||||
"display", needle);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* gst_gl_display_ensure_context:
|
||||
* @display: a #GstGLDisplay
|
||||
* @other_context: (transfer none)(nullable): other #GstGLContext to share resources with.
|
||||
* @context: (inout)(transfer full)(nullable): the resulting #GstGLContext
|
||||
* @error: (out)(transfer full)(nullable): possible error
|
||||
*
|
||||
* Ensures that the display has a valid GL context for the current thread. If
|
||||
* @context already contains a valid context, this does nothing.
|
||||
*
|
||||
* Returns: wether @context contains a valid context.
|
||||
*
|
||||
* Since: 1.24
|
||||
*/
|
||||
gboolean
|
||||
gst_gl_display_ensure_context (GstGLDisplay * display,
|
||||
GstGLContext * other_context, GstGLContext ** context, GError ** error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
|
||||
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), FALSE);
|
||||
g_return_val_if_fail (other_context == NULL
|
||||
|| GST_IS_GL_CONTEXT (other_context), FALSE);
|
||||
g_return_val_if_fail (context != NULL, FALSE);
|
||||
g_return_val_if_fail (*context == NULL
|
||||
|| GST_IS_GL_CONTEXT (*context), FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
if (*context && (*context)->display == display) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GST_OBJECT_LOCK (display);
|
||||
do {
|
||||
if (*context) {
|
||||
gst_object_unref (*context);
|
||||
*context = NULL;
|
||||
}
|
||||
/* just get a GL context. we don't care */
|
||||
*context = gst_gl_display_get_gl_context_for_thread (display, NULL);
|
||||
if (!*context) {
|
||||
if (!gst_gl_display_create_context (display, other_context, &*context,
|
||||
error)) {
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
} while (!gst_gl_display_add_context (display, *context));
|
||||
ret = TRUE;
|
||||
out:
|
||||
GST_OBJECT_UNLOCK (display);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -175,7 +175,11 @@ gboolean gst_gl_display_add_context (GstGLDisplay * display,
|
|||
GST_GL_API
|
||||
void gst_gl_display_remove_context (GstGLDisplay * display,
|
||||
GstGLContext * context);
|
||||
|
||||
GST_GL_API
|
||||
gboolean gst_gl_display_ensure_context (GstGLDisplay * display,
|
||||
GstGLContext * other_context,
|
||||
GstGLContext ** context,
|
||||
GError ** error);
|
||||
GST_GL_API
|
||||
GstGLWindow * gst_gl_display_create_window (GstGLDisplay * display);
|
||||
GST_GL_API
|
||||
|
|
Loading…
Reference in a new issue