gldisplay: add a list of glwindow's
authorMatthew Waters <matthew@centricular.com>
Thu, 30 Jun 2016 13:12:33 +0000 (23:12 +1000)
committerMatthew Waters <matthew@centricular.com>
Tue, 8 Nov 2016 04:14:26 +0000 (15:14 +1100)
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.

docs/libs/gst-plugins-bad-libs-sections.txt
gst-libs/gst/gl/gstglcontext.c
gst-libs/gst/gl/gstgldisplay.c
gst-libs/gst/gl/gstgldisplay.h

index cf98424..61e06b2 100644 (file)
@@ -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
 <SUBSECTION Standard>
index 85051ba..af5b25e 100644 (file)
@@ -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);
 
index a7ac596..b96e1b5 100644 (file)
@@ -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)
 {
index 5428a8e..5c0cc9e 100644 (file)
@@ -79,6 +79,7 @@ struct _GstGLDisplay
   GstGLDisplayType      type;
 
   /* <protected> */
+  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);
 
   /* <private> */
   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__ */