diff --git a/docs/libs/gst-plugins-bad-libs-sections.txt b/docs/libs/gst-plugins-bad-libs-sections.txt index cf98424aee..61e06b20ff 100644 --- a/docs/libs/gst-plugins-bad-libs-sections.txt +++ b/docs/libs/gst-plugins-bad-libs-sections.txt @@ -1039,6 +1039,9 @@ gst_gl_display_add_context gst_gl_display_get_gl_context_for_thread gst_gl_display_get_handle gst_gl_display_create_context +gst_gl_display_create_window +gst_gl_display_find_window +gst_gl_display_remove_window gst_context_get_gl_display gst_context_set_gl_display diff --git a/gst-libs/gst/gl/gstglcontext.c b/gst-libs/gst/gl/gstglcontext.c index 85051ba082..af5b25e9a8 100644 --- a/gst-libs/gst/gl/gstglcontext.c +++ b/gst-libs/gst/gl/gstglcontext.c @@ -255,7 +255,7 @@ _ensure_window (GstGLContext * context) if (context->window) return; - window = gst_gl_window_new (context->display); + window = gst_gl_display_create_window (context->display); gst_gl_context_set_window (context, window); diff --git a/gst-libs/gst/gl/gstgldisplay.c b/gst-libs/gst/gl/gstgldisplay.c index a7ac59625e..b96e1b592a 100644 --- a/gst-libs/gst/gl/gstgldisplay.c +++ b/gst-libs/gst/gl/gstgldisplay.c @@ -98,6 +98,8 @@ static guint gst_gl_display_signals[LAST_SIGNAL] = { 0 }; static void gst_gl_display_dispose (GObject * object); static void gst_gl_display_finalize (GObject * object); static guintptr gst_gl_display_default_get_handle (GstGLDisplay * display); +static GstGLWindow *gst_gl_display_default_create_window (GstGLDisplay * + display); struct _GstGLDisplayPrivate { @@ -169,6 +171,7 @@ gst_gl_display_class_init (GstGLDisplayClass * klass) GST_TYPE_GL_CONTEXT, 1, GST_TYPE_GL_CONTEXT); klass->get_handle = gst_gl_display_default_get_handle; + klass->create_window = gst_gl_display_default_create_window; G_OBJECT_CLASS (klass)->finalize = gst_gl_display_finalize; G_OBJECT_CLASS (klass)->dispose = gst_gl_display_dispose; @@ -512,6 +515,94 @@ gst_gl_display_create_context (GstGLDisplay * display, return ret; } +/** + * gst_gl_display_create_window: + * @display: a #GstGLDisplay + * + * It requires the display's object lock to be held. + * + * Returns: a new #GstGLWindow for @display or %NULL. + */ +GstGLWindow * +gst_gl_display_create_window (GstGLDisplay * display) +{ + GstGLDisplayClass *klass; + GstGLWindow *window; + + g_return_val_if_fail (GST_IS_GL_DISPLAY (display), NULL); + klass = GST_GL_DISPLAY_GET_CLASS (display); + g_return_val_if_fail (klass->create_window != NULL, NULL); + + window = klass->create_window (display); + + if (window) + display->windows = g_list_prepend (display->windows, window); + + return window; +} + +static GstGLWindow * +gst_gl_display_default_create_window (GstGLDisplay * display) +{ + return gst_gl_window_new (display); +} + +/** + * gst_gl_display_remove_window: + * @display: a #GstGLDisplay + * @window: a #GstGLWindow to remove + * + * Returns: if @window could be removed from @display + * + * Since: 1.12 + */ +gboolean +gst_gl_display_remove_window (GstGLDisplay * display, GstGLWindow * window) +{ + gboolean ret = FALSE; + GList *l; + + GST_OBJECT_LOCK (display); + l = g_list_find (display->windows, window); + if (l) { + display->windows = g_list_delete_link (display->windows, l); + ret = TRUE; + } + GST_OBJECT_UNLOCK (display); + + return ret; +} + +/** + * gst_gl_display_find_window: + * @display: a #GstGLDisplay + * @data: some data to pass to @compare_func + * @compare_func: a comparison function to run + * + * Execute @compare_func over the list of windows stored by @display. The + * first argment to @compare_func is the #GstGLWindow being checked and the + * second argument is @data. + * + * Returns: The first #GstGLWindow that causes a match from @compare_func + * + * Since: 1.12 + */ +GstGLWindow * +gst_gl_display_find_window (GstGLDisplay * display, gpointer data, + GCompareFunc compare_func) +{ + GstGLWindow *ret = NULL; + GList *l; + + GST_OBJECT_LOCK (display); + l = g_list_find_custom (display->windows, data, compare_func); + if (l) + ret = l->data; + GST_OBJECT_UNLOCK (display); + + return ret; +} + static GstGLContext * _get_gl_context_for_thread_unlocked (GstGLDisplay * display, GThread * thread) { diff --git a/gst-libs/gst/gl/gstgldisplay.h b/gst-libs/gst/gl/gstgldisplay.h index 5428a8e3f8..5c0cc9ea15 100644 --- a/gst-libs/gst/gl/gstgldisplay.h +++ b/gst-libs/gst/gl/gstgldisplay.h @@ -79,6 +79,7 @@ struct _GstGLDisplay GstGLDisplayType type; /* */ + GList *windows; /* OBJECT lock */ GMainContext *main_context; GMainLoop *main_loop; GSource *event_source; @@ -90,7 +91,8 @@ struct _GstGLDisplayClass { GstObjectClass object_class; - guintptr (*get_handle) (GstGLDisplay * display); + guintptr (*get_handle) (GstGLDisplay * display); + GstGLWindow * (*create_window) (GstGLDisplay * display); /* */ gpointer _padding[GST_PADDING]; @@ -130,6 +132,10 @@ GST_EXPORT gboolean gst_gl_display_add_context (GstGLDisplay * display, GstGLContext * context); +GstGLWindow * gst_gl_display_create_window (GstGLDisplay * display); +gboolean gst_gl_display_remove_window (GstGLDisplay * display, GstGLWindow * window); +GstGLWindow * gst_gl_display_find_window (GstGLDisplay * display, gpointer data, GCompareFunc compar_func); + G_END_DECLS #endif /* __GST_GL_DISPLAY_H__ */