3 * Copyright (C) 2007 David A. Schleef <ds@schleef.org>
4 * Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
5 * Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
6 * Copyright (C) 2013 Matthew Waters <ystreet00@gmail.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
25 * SECTION:gstgldisplay
26 * @short_description: window system display connection abstraction
27 * @title: GstGLDisplay
28 * @see_also: #GstContext, #GstGLContext, #GstGLWindow
30 * #GstGLDisplay represents a connection to the underlying windowing system.
31 * Elements are required to make use of #GstContext to share and propagate
34 * There are a number of environment variables that influence the choice of
35 * platform and window system specific functionality.
36 * - GST_GL_WINDOW influences the window system to use. Common values are
37 * 'x11', 'wayland', 'win32' or 'cocoa'.
38 * - GST_GL_PLATFORM influences the OpenGL platform to use. Common values are
39 * 'egl', 'glx', 'wgl' or 'cgl'.
40 * - GST_GL_API influences the OpenGL API requested by the OpenGL platform.
41 * Common values are 'opengl', 'opengl3' and 'gles2'.
43 * > Certain window systems require a special function to be called to
44 * > initialize threading support. As this GStreamer GL library does not preclude
45 * > concurrent access to the windowing system, it is strongly advised that
46 * > applications ensure that threading support has been initialized before any
47 * > other toolkit/library functionality is accessed. Failure to do so could
48 * > result in sudden application abortion during execution. The most notably
49 * > example of such a function is X11's XInitThreads\().
57 #include "gstgldisplay.h"
59 #if GST_GL_HAVE_WINDOW_COCOA
60 #include <gst/gl/cocoa/gstgldisplay_cocoa.h>
62 #if GST_GL_HAVE_WINDOW_X11
63 #include <gst/gl/x11/gstgldisplay_x11.h>
65 #if GST_GL_HAVE_WINDOW_WAYLAND
66 #include <gst/gl/wayland/gstgldisplay_wayland.h>
68 #if GST_GL_HAVE_PLATFORM_EGL
69 #include <gst/gl/egl/gstgldisplay_egl.h>
70 #include <gst/gl/egl/gstgldisplay_egl_device.h>
71 #include <gst/gl/egl/gsteglimage.h>
72 #include <gst/gl/egl/gstglmemoryegl.h>
74 #if GST_GL_HAVE_WINDOW_VIV_FB
75 #include <gst/gl/viv-fb/gstgldisplay_viv_fb.h>
77 #if GST_GL_HAVE_WINDOW_GBM
78 #include <gst/gl/gbm/gstgldisplay_gbm.h>
81 GST_DEBUG_CATEGORY_STATIC (gst_context);
82 GST_DEBUG_CATEGORY_STATIC (gst_gl_display_debug);
83 #define GST_CAT_DEFAULT gst_gl_display_debug
92 static guint gst_gl_display_signals[LAST_SIGNAL] = { 0 };
95 static void gst_gl_display_dispose (GObject * object);
96 static void gst_gl_display_finalize (GObject * object);
97 static guintptr gst_gl_display_default_get_handle (GstGLDisplay * display);
98 static GstGLWindow *gst_gl_display_default_create_window (GstGLDisplay *
101 struct _GstGLDisplayPrivate
107 GThread *event_thread;
116 GST_DEBUG_CATEGORY_INIT (gst_gl_display_debug, "gldisplay", 0, "opengl display"); \
117 GST_DEBUG_CATEGORY_GET (gst_context, "GST_CONTEXT");
119 G_DEFINE_TYPE_WITH_CODE (GstGLDisplay, gst_gl_display, GST_TYPE_OBJECT,
120 G_ADD_PRIVATE (GstGLDisplay)
124 _unlock_main_thread (GstGLDisplay * display)
126 g_mutex_unlock (&display->priv->thread_lock);
128 return G_SOURCE_REMOVE;
132 _event_thread_main (GstGLDisplay * display)
134 g_mutex_lock (&display->priv->thread_lock);
136 display->main_context = g_main_context_new ();
137 display->main_loop = g_main_loop_new (display->main_context, FALSE);
139 g_main_context_invoke (display->main_context,
140 (GSourceFunc) _unlock_main_thread, display);
142 g_cond_broadcast (&display->priv->thread_cond);
144 g_main_loop_run (display->main_loop);
146 g_mutex_lock (&display->priv->thread_lock);
147 g_main_loop_unref (display->main_loop);
148 g_main_context_unref (display->main_context);
150 display->main_loop = NULL;
151 display->main_context = NULL;
153 g_cond_broadcast (&display->priv->thread_cond);
154 g_mutex_unlock (&display->priv->thread_lock);
160 gst_gl_display_class_init (GstGLDisplayClass * klass)
163 * GstGLDisplay::create-context:
164 * @object: the #GstGLDisplay
165 * @context: (transfer none): other context to share resources with.
167 * Overrides the @GstGLContext creation mechanism.
168 * It can be called in any thread and it is emitted with
169 * display's object lock held.
171 * Returns: (transfer full): the new context.
173 gst_gl_display_signals[CREATE_CONTEXT] =
174 g_signal_new ("create-context", G_TYPE_FROM_CLASS (klass),
175 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, GST_TYPE_GL_CONTEXT, 1,
176 GST_TYPE_GL_CONTEXT);
178 klass->get_handle = gst_gl_display_default_get_handle;
179 klass->create_window = gst_gl_display_default_create_window;
181 G_OBJECT_CLASS (klass)->finalize = gst_gl_display_finalize;
182 G_OBJECT_CLASS (klass)->dispose = gst_gl_display_dispose;
186 gst_gl_display_init (GstGLDisplay * display)
188 display->priv = gst_gl_display_get_instance_private (display);
190 display->type = GST_GL_DISPLAY_TYPE_ANY;
191 display->priv->gl_api = GST_GL_API_ANY;
193 g_mutex_init (&display->priv->thread_lock);
194 g_cond_init (&display->priv->thread_cond);
196 g_mutex_init (&display->priv->window_lock);
198 display->priv->event_thread = g_thread_new ("gldisplay-event",
199 (GThreadFunc) _event_thread_main, display);
201 g_mutex_lock (&display->priv->thread_lock);
202 while (!display->main_loop)
203 g_cond_wait (&display->priv->thread_cond, &display->priv->thread_lock);
204 g_mutex_unlock (&display->priv->thread_lock);
206 GST_TRACE ("init %p", display);
208 gst_gl_buffer_init_once ();
209 gst_gl_memory_pbo_init_once ();
210 gst_gl_renderbuffer_init_once ();
212 #if GST_GL_HAVE_PLATFORM_EGL
213 gst_gl_memory_egl_init_once ();
218 gst_gl_display_dispose (GObject * object)
220 GstGLDisplay *display = GST_GL_DISPLAY (object);
222 if (display->main_loop)
223 g_main_loop_quit (display->main_loop);
225 if (display->priv->event_thread) {
226 /* can't use g_thread_join() as we could lose the last ref from a user
228 g_mutex_lock (&display->priv->thread_lock);
229 while (display->main_loop)
230 g_cond_wait (&display->priv->thread_cond, &display->priv->thread_lock);
231 g_mutex_unlock (&display->priv->thread_lock);
232 g_thread_unref (display->priv->event_thread);
234 display->priv->event_thread = NULL;
236 if (display->event_source) {
237 g_source_destroy (display->event_source);
238 g_source_unref (display->event_source);
240 display->event_source = NULL;
242 G_OBJECT_CLASS (gst_gl_display_parent_class)->dispose (object);
246 gst_gl_display_finalize (GObject * object)
248 GstGLDisplay *display = GST_GL_DISPLAY (object);
251 GST_TRACE_OBJECT (object, "finalizing");
253 for (l = display->priv->contexts; l; l = l->next) {
254 g_weak_ref_clear ((GWeakRef *) l->data);
258 g_list_free (display->windows);
259 g_list_free (display->priv->contexts);
261 g_cond_clear (&display->priv->thread_cond);
262 g_mutex_clear (&display->priv->thread_lock);
263 g_mutex_clear (&display->priv->window_lock);
265 G_OBJECT_CLASS (gst_gl_display_parent_class)->finalize (object);
269 * gst_gl_display_new:
271 * Returns: (transfer full): a new #GstGLDisplay
276 gst_gl_display_new (void)
278 GstGLDisplay *display = NULL;
279 const gchar *user_choice, *platform_choice;
280 static volatile gsize _init = 0;
282 if (g_once_init_enter (&_init)) {
283 GST_DEBUG_CATEGORY_INIT (gst_gl_display_debug, "gldisplay", 0,
284 "gldisplay element");
285 g_once_init_leave (&_init, 1);
288 user_choice = g_getenv ("GST_GL_WINDOW");
289 platform_choice = g_getenv ("GST_GL_PLATFORM");
290 GST_INFO ("creating a display, user choice:%s (platform: %s)",
291 GST_STR_NULL (user_choice), GST_STR_NULL (platform_choice));
293 #if GST_GL_HAVE_WINDOW_COCOA
294 if (!display && (!user_choice || g_strstr_len (user_choice, 5, "cocoa"))) {
295 display = GST_GL_DISPLAY (gst_gl_display_cocoa_new ());
300 #if GST_GL_HAVE_WINDOW_WAYLAND
301 if (!display && (!user_choice || g_strstr_len (user_choice, 7, "wayland")))
302 display = GST_GL_DISPLAY (gst_gl_display_wayland_new (NULL));
304 #if GST_GL_HAVE_WINDOW_X11
305 if (!display && (!user_choice || g_strstr_len (user_choice, 3, "x11")))
306 display = GST_GL_DISPLAY (gst_gl_display_x11_new (NULL));
308 #if GST_GL_HAVE_WINDOW_VIV_FB
309 if (!display && (!user_choice || g_strstr_len (user_choice, 6, "viv-fb"))) {
310 const gchar *disp_idx_str = NULL;
312 disp_idx_str = g_getenv ("GST_GL_VIV_FB");
314 gint64 v = g_ascii_strtoll (disp_idx_str, NULL, 10);
315 if (v >= G_MININT && v <= G_MAXINT)
318 display = GST_GL_DISPLAY (gst_gl_display_viv_fb_new (disp_idx));
321 #if GST_GL_HAVE_WINDOW_GBM
322 if (!display && (!user_choice || g_strstr_len (user_choice, 3, "gbm"))) {
323 display = GST_GL_DISPLAY (gst_gl_display_gbm_new ());
326 #if GST_GL_HAVE_PLATFORM_EGL
327 if (!display && (user_choice && g_strstr_len (user_choice, 10, "egl-device"))) {
328 display = GST_GL_DISPLAY (gst_gl_display_egl_device_new (0));
331 if (!display && (!platform_choice
332 || g_strstr_len (platform_choice, 3, "egl"))) {
333 display = GST_GL_DISPLAY (gst_gl_display_egl_new ());
337 GST_INFO ("Could not create platform/winsys display. user specified %s "
338 "(platform: %s), creating dummy",
339 GST_STR_NULL (user_choice), GST_STR_NULL (platform_choice));
341 display = g_object_new (GST_TYPE_GL_DISPLAY, NULL);
342 gst_object_ref_sink (display);
349 * gst_gl_display_get_handle:
350 * @display: a #GstGLDisplay
352 * Returns: the native handle for the display
357 gst_gl_display_get_handle (GstGLDisplay * display)
359 GstGLDisplayClass *klass;
361 g_return_val_if_fail (GST_IS_GL_DISPLAY (display), 0);
362 klass = GST_GL_DISPLAY_GET_CLASS (display);
363 g_return_val_if_fail (klass->get_handle != NULL, 0);
365 return klass->get_handle (display);
369 gst_gl_display_default_get_handle (GstGLDisplay * display)
375 * gst_gl_display_filter_gl_api:
376 * @display: a #GstGLDisplay
377 * @gl_api: a #GstGLAPI to filter with
379 * limit the use of OpenGL to the requested @gl_api. This is intended to allow
380 * application and elements to request a specific set of OpenGL API's based on
381 * what they support. See gst_gl_context_get_gl_api() for the retrieving the
382 * API supported by a #GstGLContext.
385 gst_gl_display_filter_gl_api (GstGLDisplay * display, GstGLAPI gl_api)
389 g_return_if_fail (GST_IS_GL_DISPLAY (display));
391 gl_api_s = gst_gl_api_to_string (gl_api);
392 GST_TRACE_OBJECT (display, "filtering with api %s", gl_api_s);
395 GST_OBJECT_LOCK (display);
396 display->priv->gl_api &= gl_api;
397 GST_OBJECT_UNLOCK (display);
401 gst_gl_display_get_gl_api_unlocked (GstGLDisplay * display)
403 g_return_val_if_fail (GST_IS_GL_DISPLAY (display), GST_GL_API_NONE);
405 return display->priv->gl_api;
409 * gst_gl_display_get_gl_api:
410 * @display: a #GstGLDisplay
412 * see gst_gl_display_filter_gl_api() for what the returned value represents
414 * Returns: the #GstGLAPI configured for @display
417 gst_gl_display_get_gl_api (GstGLDisplay * display)
421 g_return_val_if_fail (GST_IS_GL_DISPLAY (display), GST_GL_API_NONE);
423 GST_OBJECT_LOCK (display);
424 ret = display->priv->gl_api;
425 GST_OBJECT_UNLOCK (display);
431 * gst_gl_display_get_handle_type:
432 * @display: a #GstGLDisplay
434 * Returns: the #GstGLDisplayType of @display
439 gst_gl_display_get_handle_type (GstGLDisplay * display)
441 g_return_val_if_fail (GST_IS_GL_DISPLAY (display), GST_GL_DISPLAY_TYPE_NONE);
443 return display->type;
447 * gst_context_set_gl_display:
448 * @context: a #GstContext
449 * @display: (transfer none): resulting #GstGLDisplay
451 * Sets @display on @context
456 gst_context_set_gl_display (GstContext * context, GstGLDisplay * display)
460 g_return_if_fail (context != NULL);
463 GST_CAT_LOG (gst_context,
464 "setting GstGLDisplay(%" GST_PTR_FORMAT ") on context(%" GST_PTR_FORMAT
465 ")", display, context);
467 s = gst_context_writable_structure (context);
468 gst_structure_set (s, GST_GL_DISPLAY_CONTEXT_TYPE, GST_TYPE_GL_DISPLAY,
473 * gst_context_get_gl_display:
474 * @context: a #GstContext
475 * @display: (out) (transfer full): resulting #GstGLDisplay
477 * Returns: Whether @display was in @context
482 gst_context_get_gl_display (GstContext * context, GstGLDisplay ** display)
484 const GstStructure *s;
487 g_return_val_if_fail (display != NULL, FALSE);
488 g_return_val_if_fail (context != NULL, FALSE);
490 s = gst_context_get_structure (context);
491 ret = gst_structure_get (s, GST_GL_DISPLAY_CONTEXT_TYPE,
492 GST_TYPE_GL_DISPLAY, display, NULL);
494 GST_CAT_LOG (gst_context, "got GstGLDisplay(%p) from context(%p)", *display,
501 * gst_gl_display_create_context:
502 * @display: a #GstGLDisplay
503 * @other_context: (transfer none): other #GstGLContext to share resources with.
504 * @p_context: (transfer full) (out): resulting #GstGLContext
505 * @error: (allow-none): resulting #GError
507 * It requires the display's object lock to be held.
509 * Returns: whether a new context could be created.
514 gst_gl_display_create_context (GstGLDisplay * display,
515 GstGLContext * other_context, GstGLContext ** p_context, GError ** error)
517 GstGLContext *context = NULL;
518 gboolean ret = FALSE;
520 g_return_val_if_fail (display != NULL, FALSE);
521 g_return_val_if_fail (p_context != NULL, FALSE);
522 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
524 g_signal_emit (display, gst_gl_display_signals[CREATE_CONTEXT], 0,
525 other_context, &context);
528 *p_context = context;
532 context = gst_gl_context_new (display);
534 g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
535 "Failed to create GL context");
539 GST_DEBUG_OBJECT (display,
540 "creating context %" GST_PTR_FORMAT " from other context %"
541 GST_PTR_FORMAT, context, other_context);
543 ret = gst_gl_context_create (context, other_context, error);
546 *p_context = context;
548 gst_object_unref (context);
554 * gst_gl_display_create_window:
555 * @display: a #GstGLDisplay
557 * Returns: (transfer full): a new #GstGLWindow for @display or %NULL.
559 /* XXX: previous versions had documentation requiring the OBJECT lock to be
560 * held when this fuction is called so that needs to always work. */
562 gst_gl_display_create_window (GstGLDisplay * display)
564 GstGLDisplayClass *klass;
567 g_return_val_if_fail (GST_IS_GL_DISPLAY (display), NULL);
568 klass = GST_GL_DISPLAY_GET_CLASS (display);
569 g_return_val_if_fail (klass->create_window != NULL, NULL);
571 g_mutex_lock (&display->priv->window_lock);
572 window = klass->create_window (display);
575 display->windows = g_list_prepend (display->windows, window);
577 g_mutex_unlock (&display->priv->window_lock);
578 GST_DEBUG_OBJECT (display, "Adding window %" GST_PTR_FORMAT
579 " (%p) to internal list", window, window);
585 gst_gl_display_default_create_window (GstGLDisplay * display)
587 return gst_gl_window_new (display);
591 * gst_gl_display_remove_window:
592 * @display: a #GstGLDisplay
593 * @window: a #GstGLWindow to remove
595 * Returns: if @window could be removed from @display
600 gst_gl_display_remove_window (GstGLDisplay * display, GstGLWindow * window)
602 gboolean ret = FALSE;
605 g_mutex_lock (&display->priv->window_lock);
606 l = g_list_find (display->windows, window);
608 display->windows = g_list_delete_link (display->windows, l);
611 GST_DEBUG_OBJECT (display, "Removing window %" GST_PTR_FORMAT
612 " (%p) from internal list", window, window);
613 g_mutex_unlock (&display->priv->window_lock);
619 * gst_gl_display_find_window:
620 * @display: a #GstGLDisplay
621 * @data: (closure): some data to pass to @compare_func
622 * @compare_func: (scope call): a comparison function to run
624 * Deprecated for gst_gl_display_retrieve_window().
626 * Execute @compare_func over the list of windows stored by @display. The
627 * first argument to @compare_func is the #GstGLWindow being checked and the
628 * second argument is @data.
630 * Returns: (transfer none): The first #GstGLWindow that causes a match
636 gst_gl_display_find_window (GstGLDisplay * display, gpointer data,
637 GCompareFunc compare_func)
641 ret = gst_gl_display_retrieve_window (display, data, compare_func);
643 gst_object_unref (ret);
649 * gst_gl_display_retrieve_window:
650 * @display: a #GstGLDisplay
651 * @data: (closure): some data to pass to @compare_func
652 * @compare_func: (scope call): a comparison function to run
654 * Execute @compare_func over the list of windows stored by @display. The
655 * first argument to @compare_func is the #GstGLWindow being checked and the
656 * second argument is @data.
658 * Returns: (transfer full): The first #GstGLWindow that causes a match
664 gst_gl_display_retrieve_window (GstGLDisplay * display, gpointer data,
665 GCompareFunc compare_func)
667 GstGLWindow *ret = NULL;
670 g_mutex_lock (&display->priv->window_lock);
671 l = g_list_find_custom (display->windows, data, compare_func);
673 ret = gst_object_ref (l->data);
675 GST_DEBUG_OBJECT (display, "Found window %" GST_PTR_FORMAT
676 " (%p) in internal list", ret, ret);
677 g_mutex_unlock (&display->priv->window_lock);
682 static GstGLContext *
683 _get_gl_context_for_thread_unlocked (GstGLDisplay * display, GThread * thread)
685 GstGLContext *context = NULL;
686 GList *prev = NULL, *l = display->priv->contexts;
689 GWeakRef *ref = l->data;
690 GThread *context_thread;
692 context = g_weak_ref_get (ref);
694 /* remove dead contexts */
695 g_weak_ref_clear (l->data);
697 display->priv->contexts = g_list_delete_link (display->priv->contexts, l);
698 l = prev ? prev->next : display->priv->contexts;
702 if (thread == NULL) {
703 GST_DEBUG_OBJECT (display, "Returning GL context %" GST_PTR_FORMAT " for "
704 "NULL thread", context);
708 context_thread = gst_gl_context_get_thread (context);
709 if (thread != context_thread) {
710 g_thread_unref (context_thread);
711 gst_object_unref (context);
718 g_thread_unref (context_thread);
720 GST_DEBUG_OBJECT (display, "Returning GL context %" GST_PTR_FORMAT " for "
721 "thread %p", context, thread);
725 GST_DEBUG_OBJECT (display, "No GL context for thread %p", thread);
730 * gst_gl_display_get_gl_context_for_thread:
731 * @display: a #GstGLDisplay
732 * @thread: a #GThread
734 * Returns: (transfer full): the #GstGLContext current on @thread or %NULL
736 * Must be called with the object lock held.
741 gst_gl_display_get_gl_context_for_thread (GstGLDisplay * display,
744 GstGLContext *context;
746 g_return_val_if_fail (GST_IS_GL_DISPLAY (display), NULL);
748 context = _get_gl_context_for_thread_unlocked (display, thread);
749 GST_DEBUG_OBJECT (display, "returning context %" GST_PTR_FORMAT " for thread "
750 "%p", context, thread);
756 _check_collision (GstGLContext * context, GstGLContext * collision)
758 GThread *thread, *collision_thread;
759 gboolean ret = FALSE;
761 if (!context || !collision)
764 thread = gst_gl_context_get_thread (context);
765 collision_thread = gst_gl_context_get_thread (collision);
767 if (!thread || !collision_thread) {
772 if (thread == collision_thread) {
779 g_thread_unref (thread);
780 if (collision_thread)
781 g_thread_unref (collision_thread);
787 * gst_gl_display_add_context:
788 * @display: a #GstGLDisplay
789 * @context: (transfer none): a #GstGLContext
791 * Returns: whether @context was successfully added. %FALSE may be returned
792 * if there already exists another context for @context's active thread.
794 * Must be called with the object lock held.
799 gst_gl_display_add_context (GstGLDisplay * display, GstGLContext * context)
801 GstGLContext *collision = NULL;
802 GstGLDisplay *context_display;
807 g_return_val_if_fail (GST_IS_GL_DISPLAY (display), FALSE);
808 g_return_val_if_fail (GST_IS_GL_CONTEXT (context), FALSE);
810 context_display = gst_gl_context_get_display (context);
811 g_assert (context_display == display);
812 gst_object_unref (context_display);
814 thread = gst_gl_context_get_thread (context);
816 collision = _get_gl_context_for_thread_unlocked (display, thread);
817 g_thread_unref (thread);
819 /* adding the same context is a no-op */
820 if (context == collision) {
821 GST_LOG_OBJECT (display, "Attempting to add the same GL context %"
822 GST_PTR_FORMAT ". Ignoring", context);
827 if (_check_collision (context, collision)) {
828 GST_DEBUG_OBJECT (display, "Collision detected adding GL context "
829 "%" GST_PTR_FORMAT, context);
835 ref = g_new0 (GWeakRef, 1);
836 g_weak_ref_init (ref, context);
838 GST_DEBUG_OBJECT (display, "Adding GL context %" GST_PTR_FORMAT, context);
839 display->priv->contexts = g_list_prepend (display->priv->contexts, ref);
843 gst_object_unref (collision);
845 GST_DEBUG_OBJECT (display, "%ssuccessfully inserted context %" GST_PTR_FORMAT,
846 ret ? "" : "un", context);
852 * gst_gl_display_remove_context:
853 * @display: a #GstGLDisplay
854 * @context: (transfer none): the #GstGLContext to remove
856 * Must be called with the object lock held.
861 gst_gl_display_remove_context (GstGLDisplay * display, GstGLContext * needle)
863 GstGLContext *context;
864 GList *prev = NULL, *l;
866 g_return_if_fail (GST_IS_GL_DISPLAY (display));
867 g_return_if_fail (GST_IS_GL_CONTEXT (needle));
869 l = display->priv->contexts;
872 GWeakRef *ref = l->data;
874 context = g_weak_ref_get (ref);
875 if (!context || context == needle) {
876 /* remove dead contexts */
877 g_weak_ref_clear (l->data);
879 display->priv->contexts = g_list_delete_link (display->priv->contexts, l);
881 GST_INFO_OBJECT (display, "removed context %" GST_PTR_FORMAT
882 " from internal list", context);
883 gst_object_unref (context);
886 l = prev ? prev->next : display->priv->contexts;
893 GST_WARNING_OBJECT (display, "%" GST_PTR_FORMAT " was not found in this "