[276/906] better deal with last pending custom cb and destroy_context_cb

This commit is contained in:
Julien Isorce 2008-11-21 19:11:11 +01:00 committed by Tim-Philipp Müller
parent 128315ae60
commit 312d0f588a
3 changed files with 32 additions and 14 deletions

View file

@ -343,18 +343,14 @@ gst_gl_display_finalize (GObject* object)
{
gst_gl_display_lock (display);
GST_INFO ("send message thread destroy context");
gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (gst_gl_display_thread_destroy_context), display);
gst_gl_window_set_resize_callback (display->gl_window, NULL, NULL);
gst_gl_window_set_draw_callback (display->gl_window, NULL, NULL);
gst_gl_window_set_close_callback (display->gl_window, NULL, NULL);
//leave gl window loop
GST_INFO ("send quit gl window loop");
gst_gl_window_quit_loop (display->gl_window);
gst_gl_window_quit_loop (display->gl_window, GST_GL_WINDOW_CB (gst_gl_display_thread_destroy_context), display);
GST_INFO ("quit sent to gl window loop");
@ -367,13 +363,15 @@ gst_gl_display_finalize (GObject* object)
{
gpointer ret = g_thread_join (display->gl_thread);
GST_INFO ("gl thread joined");
g_assert (ret == NULL);
if (ret != NULL)
GST_ERROR ("gl thread returned a not null pointer");
display->gl_thread = NULL;
}
if (display->texture_pool) {
//texture pool is empty after destroying the gl context
g_assert (g_hash_table_size (display->texture_pool) == 0);
if (g_hash_table_size (display->texture_pool) != 0)
GST_ERROR ("texture pool is not empty");
g_hash_table_unref (display->texture_pool);
display->texture_pool = NULL;
}
@ -597,6 +595,8 @@ gst_gl_display_thread_destroy_context (GstGLDisplay *display)
display->upload_intex = 0;
}
GST_INFO ("Cleaning texture pool");
//clean up the texture pool
g_hash_table_foreach_remove (display->texture_pool, gst_gl_display_texture_pool_func_clean,
NULL);
@ -1397,6 +1397,7 @@ void gst_gl_display_on_draw(GstGLDisplay* display)
void gst_gl_display_on_close (GstGLDisplay* display)
{
GST_INFO ("on close");
display->isAlive = FALSE;
}
@ -1544,6 +1545,7 @@ gboolean gst_gl_display_texture_pool_func_clean (gpointer key, gpointer value, g
while (g_queue_get_length (sub_texture_pool) > 0)
{
GstGLDisplayTex* tex = g_queue_pop_head (sub_texture_pool);
GST_INFO ("trying to delete texture id: %d deleted", tex->texture);
glDeleteTextures (1, &tex->texture);
GST_INFO ("texture id: %d deleted", tex->texture);
g_free (tex);

View file

@ -74,7 +74,7 @@ void gst_gl_window_set_close_callback (GstGLWindow *window, GstGLWindowCB callba
void gst_gl_window_visible (GstGLWindow *window, gboolean visible);
void gst_gl_window_draw (GstGLWindow *window);
void gst_gl_window_run_loop (GstGLWindow *window);
void gst_gl_window_quit_loop (GstGLWindow *window);
void gst_gl_window_quit_loop (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
void gst_gl_window_send_message (GstGLWindow *window, GstGLWindowCB callback, gpointer data);

View file

@ -565,6 +565,9 @@ gst_gl_window_run_loop (GstGLWindow *window)
if (!custom_cb || !custom_data)
g_debug ("custom cb not initialized\n");
if (glXGetCurrentContext () != priv->gl_context)
g_warning ("current gl context has changed\n");
custom_cb (custom_data);
}
@ -590,19 +593,21 @@ gst_gl_window_run_loop (GstGLWindow *window)
else if (wm_quit_loop != None && event.xclient.message_type == wm_quit_loop)
{
XEvent event;
XEvent pending_event;
GstGLWindowCB destroy_cb = (GstGLWindowCB) event.xclient.data.l[0];
gpointer destroy_data = (gpointer) event.xclient.data.l[1];
g_debug ("Quit loop message %lld\n", (guint64) priv->internal_win_id);
priv->running = FALSE;
XFlush (priv->device);
while (XCheckTypedEvent (priv->device, ClientMessage, &event))
while (XCheckTypedEvent (priv->device, ClientMessage, &pending_event))
{
GstGLWindowCB custom_cb = (GstGLWindowCB) event.xclient.data.l[0];
gpointer custom_data = (gpointer) event.xclient.data.l[1];
GstGLWindowCB custom_cb = (GstGLWindowCB) pending_event.xclient.data.l[0];
gpointer custom_data = (gpointer) pending_event.xclient.data.l[1];
g_debug ("discared custom x event\n");
g_debug ("execute last pending custom x events\n");
if (!custom_cb || !custom_data)
g_debug ("custom cb not initialized\n");
@ -611,6 +616,15 @@ gst_gl_window_run_loop (GstGLWindow *window)
g_cond_signal (priv->cond_send_message);
}
if (!destroy_cb || !destroy_data)
g_debug ("destroy cb not initialized\n");
if (glXGetCurrentContext () != priv->gl_context)
g_warning ("current gl context has changed\n");
destroy_cb (destroy_data);
}
else
{
@ -680,7 +694,7 @@ gst_gl_window_run_loop (GstGLWindow *window)
/* Thread safe */
void
gst_gl_window_quit_loop (GstGLWindow *window)
gst_gl_window_quit_loop (GstGLWindow *window, GstGLWindowCB callback, gpointer data)
{
if (window)
{
@ -701,6 +715,8 @@ gst_gl_window_quit_loop (GstGLWindow *window)
event.xclient.window = priv->internal_win_id;
event.xclient.message_type = XInternAtom (disp, "WM_QUIT_LOOP", True);;
event.xclient.format = 32;
event.xclient.data.l[0] = (long) callback;
event.xclient.data.l[1] = (long) data;
XSendEvent (disp, priv->internal_win_id, FALSE, NoEventMask, &event);
XSync (disp, FALSE);