[752/906] glwindow: Add destroy notifies for the data of the callbacks
authorSebastian Dröge <slomo@circular-chaos.org>
Mon, 15 Jul 2013 13:58:04 +0000 (15:58 +0200)
committerMatthew Waters <ystreet00@gmail.com>
Sat, 15 Mar 2014 17:36:58 +0000 (18:36 +0100)
And actually call the close callback when the window is closed.

gst-libs/gst/gl/cocoa/gstglwindow_cocoa.m
gst-libs/gst/gl/gstglwindow.c
gst-libs/gst/gl/gstglwindow.h
gst-libs/gst/gl/wayland/gstglwindow_wayland_egl.c
gst-libs/gst/gl/win32/gstglwindow_win32.c
gst-libs/gst/gl/x11/gstglwindow_x11.c
gst/gl/gstglimagesink.c

index 29606f8..a6e9937 100644 (file)
@@ -120,8 +120,7 @@ void gst_gl_window_cocoa_draw_unlocked (GstGLWindow * window, guint width,
     guint height);
 void gst_gl_window_cocoa_draw (GstGLWindow * window, guint width, guint height);
 void gst_gl_window_cocoa_run (GstGLWindow * window);
-void gst_gl_window_cocoa_quit (GstGLWindow * window, GstGLWindowCB callback,
-    gpointer data);
+void gst_gl_window_cocoa_quit (GstGLWindow * window);
 void gst_gl_window_cocoa_send_message (GstGLWindow * window,
     GstGLWindowCB callback, gpointer data);
 GstGLAPI gst_gl_window_cocoa_get_gl_api (GstGLWindow * window);
@@ -408,8 +407,7 @@ gst_gl_window_cocoa_run (GstGLWindow * window)
 
 /* Thread safe */
 void
-gst_gl_window_cocoa_quit (GstGLWindow * window, GstGLWindowCB callback,
-    gpointer data)
+gst_gl_window_cocoa_quit (GstGLWindow * window)
 {
   GstGLWindowCocoa *window_cocoa;
   GstGLWindowCocoaPrivate *priv;
@@ -421,9 +419,6 @@ gst_gl_window_cocoa_quit (GstGLWindow * window, GstGLWindowCB callback,
     if (GSRegisterCurrentThread() || 1) {
       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
       
-      AppThreadPerformer* app_thread_performer = [[AppThreadPerformer alloc]
-          initWithAll:window_cocoa callback:callback userData:data];
-        
       [app_thread_performer performSelector:@selector(stopApp) onThread:priv->thread 
         withObject:nil waitUntilDone:YES];
 
index 6ac8c3b..fe28edb 100644 (file)
@@ -167,17 +167,16 @@ gst_gl_window_finalize (GObject * object)
 {
   GstGLWindow *window = GST_GL_WINDOW (object);
 
-  if (window) {
-    gst_gl_window_set_resize_callback (window, NULL, NULL);
-    gst_gl_window_set_draw_callback (window, NULL, NULL);
-    gst_gl_window_set_close_callback (window, NULL, NULL);
-
-    if (window->priv->alive) {
-      GST_INFO ("send quit gl window loop");
-      gst_gl_window_quit (window, NULL, NULL);
-    }
+  gst_gl_window_set_resize_callback (window, NULL, NULL, NULL);
+  gst_gl_window_set_draw_callback (window, NULL, NULL, NULL);
+
+  if (window->priv->alive) {
+    GST_INFO ("send quit gl window loop");
+    gst_gl_window_quit (window);
   }
 
+  gst_gl_window_set_close_callback (window, NULL, NULL, NULL);
+
   if (window->priv->gl_thread) {
     gpointer ret = g_thread_join (window->priv->gl_thread);
     GST_INFO ("gl thread joined");
@@ -284,7 +283,7 @@ gst_gl_window_run (GstGLWindow * window)
 }
 
 void
-gst_gl_window_quit (GstGLWindow * window, GstGLWindowCB callback, gpointer data)
+gst_gl_window_quit (GstGLWindow * window)
 {
   GstGLWindowClass *window_class;
 
@@ -296,9 +295,7 @@ gst_gl_window_quit (GstGLWindow * window, GstGLWindowCB callback, gpointer data)
 
   window->priv->alive = FALSE;
 
-  window->close = callback;
-  window->close_data = data;
-  window_class->quit (window, callback, data);
+  window_class->quit (window);
 
   GST_INFO ("quit sent to gl window loop");
 
@@ -343,42 +340,54 @@ gst_gl_window_set_need_lock (GstGLWindow * window, gboolean need_lock)
 
 void
 gst_gl_window_set_draw_callback (GstGLWindow * window, GstGLWindowCB callback,
-    gpointer data)
+    gpointer data, GDestroyNotify destroy_notify)
 {
   g_return_if_fail (GST_GL_IS_WINDOW (window));
 
   GST_GL_WINDOW_LOCK (window);
 
+  if (window->draw_notify)
+    window->draw_notify (window->draw_data);
+
   window->draw = callback;
   window->draw_data = data;
+  window->draw_notify = destroy_notify;
 
   GST_GL_WINDOW_UNLOCK (window);
 }
 
 void
 gst_gl_window_set_resize_callback (GstGLWindow * window,
-    GstGLWindowResizeCB callback, gpointer data)
+    GstGLWindowResizeCB callback, gpointer data, GDestroyNotify destroy_notify)
 {
   g_return_if_fail (GST_GL_IS_WINDOW (window));
 
   GST_GL_WINDOW_LOCK (window);
 
+  if (window->resize_notify)
+    window->resize_notify (window->resize_data);
+
   window->resize = callback;
   window->resize_data = data;
+  window->resize_notify = destroy_notify;
 
   GST_GL_WINDOW_UNLOCK (window);
 }
 
 void
 gst_gl_window_set_close_callback (GstGLWindow * window, GstGLWindowCB callback,
-    gpointer data)
+    gpointer data, GDestroyNotify destroy_notify)
 {
   g_return_if_fail (GST_GL_IS_WINDOW (window));
 
   GST_GL_WINDOW_LOCK (window);
 
+  if (window->close_notify)
+    window->close_notify (window->close_data);
+
   window->close = callback;
   window->close_data = data;
+  window->close_notify = destroy_notify;
 
   GST_GL_WINDOW_UNLOCK (window);
 }
@@ -732,6 +741,8 @@ _gst_gl_window_thread_create_context (GstGLWindow * window)
 
   if (window_class->close) {
     window_class->close (window);
+    if (window->close)
+      window->close (window->close_data);
   }
 
   g_cond_signal (&window->priv->cond_destroy_context);
index 88450b0..e19e75c 100644 (file)
@@ -79,10 +79,13 @@ struct _GstGLWindow {
 
   GstGLWindowCB         draw;
   gpointer              draw_data;
+  GDestroyNotify        draw_notify;
   GstGLWindowCB         close;
   gpointer              close_data;
+  GDestroyNotify        close_notify;
   GstGLWindowResizeCB   resize;
   gpointer              resize_data;
+  GDestroyNotify        resize_notify;
 
   /*< private >*/
   gpointer _reserved[GST_PADDING];
@@ -105,7 +108,7 @@ struct _GstGLWindowClass {
   void     (*draw_unlocked)      (GstGLWindow *window, guint width, guint height);
   void     (*draw)               (GstGLWindow *window, guint width, guint height);
   void     (*run)                (GstGLWindow *window);
-  void     (*quit)               (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
+  void     (*quit)               (GstGLWindow *window);
   void     (*send_message)       (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
 
   gboolean (*open)               (GstGLWindow *window, GError **error);
@@ -122,9 +125,9 @@ GType gst_gl_window_get_type     (void);
 
 GstGLWindow * gst_gl_window_new  (GstGLDisplay *display);
 
-void     gst_gl_window_set_draw_callback    (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
-void     gst_gl_window_set_resize_callback  (GstGLWindow *window, GstGLWindowResizeCB callback, gpointer data);
-void     gst_gl_window_set_close_callback   (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
+void     gst_gl_window_set_draw_callback    (GstGLWindow *window, GstGLWindowCB callback, gpointer data, GDestroyNotify destroy_notify);
+void     gst_gl_window_set_resize_callback  (GstGLWindow *window, GstGLWindowResizeCB callback, gpointer data, GDestroyNotify destroy_notify);
+void     gst_gl_window_set_close_callback   (GstGLWindow *window, GstGLWindowCB callback, gpointer data, GDestroyNotify destroy_notify);
 void     gst_gl_window_set_need_lock        (GstGLWindow *window, gboolean need_lock);
 
 guintptr gst_gl_window_get_gl_context       (GstGLWindow *window);
@@ -134,7 +137,7 @@ guintptr gst_gl_window_get_window_handle    (GstGLWindow *window);
 void     gst_gl_window_draw_unlocked        (GstGLWindow *window, guint width, guint height);
 void     gst_gl_window_draw                 (GstGLWindow *window, guint width, guint height);
 void     gst_gl_window_run                  (GstGLWindow *window);
-void     gst_gl_window_quit                 (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
+void     gst_gl_window_quit                 (GstGLWindow *window);
 void     gst_gl_window_send_message         (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
 
 gpointer      gst_gl_window_get_proc_address (GstGLWindow *window, const gchar *name);
index 36068e0..2c9b174 100644 (file)
@@ -45,8 +45,7 @@ static void gst_gl_window_wayland_egl_set_window_handle (GstGLWindow * window,
 static void gst_gl_window_wayland_egl_draw (GstGLWindow * window, guint width,
     guint height);
 static void gst_gl_window_wayland_egl_run (GstGLWindow * window);
-static void gst_gl_window_wayland_egl_quit (GstGLWindow * window,
-    GstGLWindowCB callback, gpointer data);
+static void gst_gl_window_wayland_egl_quit (GstGLWindow * window);
 static void gst_gl_window_wayland_egl_send_message (GstGLWindow * window,
     GstGLWindowCB callback, gpointer data);
 static void gst_gl_window_wayland_egl_destroy_context (GstGLWindowWaylandEGL *
@@ -445,16 +444,12 @@ gst_gl_window_wayland_egl_run (GstGLWindow * window)
 }
 
 static void
-gst_gl_window_wayland_egl_quit (GstGLWindow * window, GstGLWindowCB callback,
-    gpointer data)
+gst_gl_window_wayland_egl_quit (GstGLWindow * window)
 {
   GstGLWindowWaylandEGL *window_egl;
 
   window_egl = GST_GL_WINDOW_WAYLAND_EGL (window);
 
-  if (callback)
-    gst_gl_window_wayland_egl_send_message (window, callback, data);
-
   GST_LOG ("sending quit");
 
   g_main_loop_quit (window_egl->loop);
index 7817f31..3b0fc2f 100644 (file)
@@ -79,8 +79,7 @@ void gst_gl_window_win32_draw_unlocked (GstGLWindow * window, guint width,
     guint height);
 void gst_gl_window_win32_draw (GstGLWindow * window, guint width, guint height);
 void gst_gl_window_win32_run (GstGLWindow * window);
-void gst_gl_window_win32_quit (GstGLWindow * window, GstGLWindowCB callback,
-    gpointer data);
+void gst_gl_window_win32_quit (GstGLWindow * window);
 void gst_gl_window_win32_send_message (GstGLWindow * window,
     GstGLWindowCB callback, gpointer data);
 
@@ -384,8 +383,7 @@ gst_gl_window_win32_run (GstGLWindow * window)
 
 /* Thread safe */
 void
-gst_gl_window_win32_quit (GstGLWindow * window, GstGLWindowCB callback,
-    gpointer data)
+gst_gl_window_win32_quit (GstGLWindow * window)
 {
   GstGLWindowWin32 *window_win32;
 
@@ -394,7 +392,7 @@ gst_gl_window_win32_quit (GstGLWindow * window, GstGLWindowCB callback,
   if (window_win32 && window_win32->internal_win_id) {
     LRESULT res =
         PostMessage (window_win32->internal_win_id, WM_GST_GL_WINDOW_QUIT,
-        (WPARAM) data, (LPARAM) callback);
+        (WPARAM) 0, (LPARAM) 0);
     GST_DEBUG ("end loop requested");
     g_return_if_fail (SUCCEEDED (res));
   }
@@ -526,13 +524,9 @@ window_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
       case WM_GST_GL_WINDOW_QUIT:
       {
         HWND parent_id = 0;
-        GstGLWindowCB destroy_cb = (GstGLWindowCB) lParam;
 
         GST_DEBUG ("WM_GST_GL_WINDOW_QUIT\n");
 
-        if (destroy_cb)
-          destroy_cb ((gpointer) wParam);
-
         parent_id = window_win32->parent_win_id;
         if (parent_id) {
           WNDPROC parent_proc = GetProp (parent_id, "gl_window_parent_proc");
index 0c09560..582a4ff 100644 (file)
@@ -70,8 +70,7 @@ void gst_gl_window_x11_draw_unlocked (GstGLWindow * window, guint width,
     guint height);
 void gst_gl_window_x11_draw (GstGLWindow * window, guint width, guint height);
 void gst_gl_window_x11_run (GstGLWindow * window);
-void gst_gl_window_x11_quit (GstGLWindow * window, GstGLWindowCB callback,
-    gpointer data);
+void gst_gl_window_x11_quit (GstGLWindow * window);
 void gst_gl_window_x11_send_message (GstGLWindow * window,
     GstGLWindowCB callback, gpointer data);
 gboolean gst_gl_window_x11_create_context (GstGLWindow * window,
@@ -703,16 +702,12 @@ gst_gl_window_x11_handle_event (GstGLWindowX11 * window_x11)
 
 /* Not called by the gl thread */
 void
-gst_gl_window_x11_quit (GstGLWindow * window, GstGLWindowCB callback,
-    gpointer data)
+gst_gl_window_x11_quit (GstGLWindow * window)
 {
   GstGLWindowX11 *window_x11;
 
   window_x11 = GST_GL_WINDOW_X11 (window);
 
-  if (callback)
-    gst_gl_window_x11_send_message (window, callback, data);
-
   GST_LOG ("sending quit");
 
   g_main_loop_quit (window_x11->loop);
index b2dcebc..5d45983 100644 (file)
@@ -446,11 +446,14 @@ gst_glimage_sink_change_state (GstElement * element, GstStateChange transition)
 
         /* setup callbacks */
         gst_gl_window_set_resize_callback (window,
-            GST_GL_WINDOW_RESIZE_CB (gst_glimage_sink_on_resize), glimage_sink);
+            GST_GL_WINDOW_RESIZE_CB (gst_glimage_sink_on_resize),
+            gst_object_ref (glimage_sink), (GDestroyNotify) gst_object_unref);
         gst_gl_window_set_draw_callback (window,
-            GST_GL_WINDOW_CB (gst_glimage_sink_on_draw), glimage_sink);
+            GST_GL_WINDOW_CB (gst_glimage_sink_on_draw),
+            gst_object_ref (glimage_sink), (GDestroyNotify) gst_object_unref);
         gst_gl_window_set_close_callback (window,
-            GST_GL_WINDOW_CB (gst_glimage_sink_on_close), glimage_sink);
+            GST_GL_WINDOW_CB (gst_glimage_sink_on_close),
+            gst_object_ref (glimage_sink), (GDestroyNotify) gst_object_unref);
 
         gst_object_unref (window);
       }
@@ -487,9 +490,9 @@ gst_glimage_sink_change_state (GstElement * element, GstStateChange transition)
       if (glimage_sink->display) {
         GstGLWindow *window = gst_gl_display_get_window (glimage_sink->display);
 
-        gst_gl_window_set_resize_callback (window, NULL, NULL);
-        gst_gl_window_set_draw_callback (window, NULL, NULL);
-        gst_gl_window_set_close_callback (window, NULL, NULL);
+        gst_gl_window_set_resize_callback (window, NULL, NULL, NULL);
+        gst_gl_window_set_draw_callback (window, NULL, NULL, NULL);
+        gst_gl_window_set_close_callback (window, NULL, NULL, NULL);
 
         gst_object_unref (window);
         gst_object_unref (glimage_sink->display);