[752/906] glwindow: Add destroy notifies for the data of the callbacks

And actually call the close callback when the window is closed.
This commit is contained in:
Sebastian Dröge 2013-07-15 15:58:04 +02:00 committed by Matthew Waters
parent 7dba9d0dce
commit 2b6e54d416
7 changed files with 52 additions and 56 deletions

View 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];

View 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);
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, 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);

View 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);

View 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);

View 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");

View 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);

View 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);