gldisplay: add a list of glwindow's
With the event thread on the display, for a particular winsys event
we need to be able to retreive the window that the event matches.
diff --git a/docs/libs/gst-plugins-bad-libs-sections.txt b/docs/libs/gst-plugins-bad-libs-sections.txt
index cf98424..61e06b2 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_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
<SUBSECTION Standard>
diff --git a/gst-libs/gst/gl/gstglcontext.c b/gst-libs/gst/gl/gstglcontext.c
index 85051ba..af5b25e 100644
--- a/gst-libs/gst/gl/gstglcontext.c
+++ b/gst-libs/gst/gl/gstglcontext.c
@@ -255,7 +255,7 @@
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 a7ac596..b96e1b5 100644
--- a/gst-libs/gst/gl/gstgldisplay.c
+++ b/gst-libs/gst/gl/gstgldisplay.c
@@ -98,6 +98,8 @@
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_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 @@
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 5428a8e..5c0cc9e 100644
--- a/gst-libs/gst/gl/gstgldisplay.h
+++ b/gst-libs/gst/gl/gstgldisplay.h
@@ -79,6 +79,7 @@
GstGLDisplayType type;
/* <protected> */
+ GList *windows; /* OBJECT lock */
GMainContext *main_context;
GMainLoop *main_loop;
GSource *event_source;
@@ -90,7 +91,8 @@
{
GstObjectClass object_class;
- guintptr (*get_handle) (GstGLDisplay * display);
+ guintptr (*get_handle) (GstGLDisplay * display);
+ GstGLWindow * (*create_window) (GstGLDisplay * display);
/* <private> */
gpointer _padding[GST_PADDING];
@@ -130,6 +132,10 @@
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__ */