From 396afd5ef35c235b025a2bc340070925a1f92325 Mon Sep 17 00:00:00 2001 From: Filippo Argiolas Date: Mon, 11 Aug 2008 09:00:40 +0200 Subject: [PATCH] [142/906] Add a generic action to be able to execute arbitrary gl code within the gl thread with less pain --- gst-libs/gst/gl/gstgldisplay.c | 28 ++++++++++++++++++++++++++++ gst-libs/gst/gl/gstgldisplay.h | 11 +++++++++++ gst/gl/gstglfilterblur.c | 19 +++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/gst-libs/gst/gl/gstgldisplay.c b/gst-libs/gst/gl/gstgldisplay.c index 67aa1032c1..c3d433cfe1 100644 --- a/gst-libs/gst/gl/gstgldisplay.c +++ b/gst-libs/gst/gl/gstgldisplay.c @@ -41,6 +41,7 @@ static void gst_gl_display_thread_change_context (GstGLDisplay* display); static void gst_gl_display_thread_set_visible_context (GstGLDisplay* display); static void gst_gl_display_thread_resize_context (GstGLDisplay* display); static void gst_gl_display_thread_redisplay (GstGLDisplay* display); +static void gst_gl_display_thread_run_generic (GstGLDisplay *display); static void gst_gl_display_thread_gen_texture (GstGLDisplay* display); static void gst_gl_display_thread_del_texture (GstGLDisplay* display); static void gst_gl_display_thread_init_upload (GstGLDisplay* display); @@ -122,6 +123,7 @@ gst_gl_display_init (GstGLDisplay *display, GstGLDisplayClass *klass) display->cond_create_context = g_cond_new (); display->cond_destroy_context = g_cond_new (); display->cond_change_context = g_cond_new (); + display->cond_generic = g_cond_new (); display->cond_gen_texture = g_cond_new (); display->cond_del_texture = g_cond_new (); display->cond_init_upload = g_cond_new (); @@ -419,6 +421,10 @@ gst_gl_display_finalize (GObject* object) g_cond_free (display->cond_gen_texture); display->cond_gen_texture = NULL; } + if (display->cond_gen_texture) { + g_cond_free (display->cond_gen_texture); + display->cond_gen_texture = NULL; + } if (display->cond_change_context) { g_cond_free (display->cond_change_context); display->cond_change_context = NULL; @@ -539,6 +545,9 @@ gst_gl_display_thread_dispatch_action (GstGLDisplayMsg* msg) case GST_GL_DISPLAY_ACTION_REDISPLAY_CONTEXT: gst_gl_display_thread_redisplay (msg->display); break; + case GST_GL_DISPLAY_ACTION_GENERIC: + gst_gl_display_thread_run_generic (msg->display); + break; case GST_GL_DISPLAY_ACTION_GEN_TEXTURE: gst_gl_display_thread_gen_texture (msg->display); break; @@ -598,6 +607,7 @@ gst_gl_display_thread_check_msg_validity (GstGLDisplayMsg *msg) case GST_GL_DISPLAY_ACTION_VISIBLE_CONTEXT: case GST_GL_DISPLAY_ACTION_RESIZE_CONTEXT: case GST_GL_DISPLAY_ACTION_REDISPLAY_CONTEXT: + case GST_GL_DISPLAY_ACTION_GENERIC: case GST_GL_DISPLAY_ACTION_GEN_TEXTURE: case GST_GL_DISPLAY_ACTION_DEL_TEXTURE: case GST_GL_DISPLAY_ACTION_INIT_UPLOAD: @@ -889,6 +899,13 @@ gst_gl_display_thread_redisplay (GstGLDisplay * display) glutPostRedisplay (); } +static void +gst_gl_display_thread_run_generic (GstGLDisplay *display) +{ + glutSetWindow (display->glutWinId); + display->generic_callback (display, display->data); + g_cond_signal (display->cond_generic); +} /* Called in the gl thread */ static void @@ -1870,6 +1887,17 @@ gst_gl_display_redisplay (GstGLDisplay* display, GLuint texture, gint width , gi return isAlive; } +void +gst_gl_display_thread_add (GstGLDisplay *display, + GstGLDisplayThreadFunc func, gpointer data) +{ + gst_gl_display_lock (display); + display->data = data; + display->generic_callback = func; + gst_gl_display_post_message (GST_GL_DISPLAY_ACTION_GENERIC, display); + g_cond_wait (display->cond_generic, display->mutex); + gst_gl_display_unlock (display); +} /* Called by gst_gl_buffer_new */ void diff --git a/gst-libs/gst/gl/gstgldisplay.h b/gst-libs/gst/gl/gstgldisplay.h index 54b4a45d2a..1ff3dbb480 100644 --- a/gst-libs/gst/gl/gstgldisplay.h +++ b/gst-libs/gst/gl/gstgldisplay.h @@ -66,6 +66,7 @@ typedef enum { GST_GL_DISPLAY_ACTION_VISIBLE_CONTEXT, GST_GL_DISPLAY_ACTION_RESIZE_CONTEXT, GST_GL_DISPLAY_ACTION_REDISPLAY_CONTEXT, + GST_GL_DISPLAY_ACTION_GENERIC, GST_GL_DISPLAY_ACTION_GEN_TEXTURE, GST_GL_DISPLAY_ACTION_DEL_TEXTURE, GST_GL_DISPLAY_ACTION_INIT_UPLOAD, @@ -99,6 +100,8 @@ typedef struct _GstGLDisplayTex { typedef void (* CRCB) ( GLuint, GLuint ); typedef gboolean (* CDCB) ( GLuint, GLuint, GLuint); +typedef void (* GstGLDisplayThreadFunc) (GstGLDisplay *display, gpointer data); + //opengl scene callback typedef void (* GLCB) ( gint, gint, guint, gpointer stuff); @@ -122,6 +125,7 @@ struct _GstGLDisplay { GCond* cond_create_context; GCond* cond_destroy_context; GCond* cond_change_context; + GCond* cond_generic; GCond* cond_gen_texture; GCond* cond_del_texture; GCond* cond_init_upload; @@ -134,6 +138,10 @@ struct _GstGLDisplay { GCond* cond_gen_shader; GCond* cond_del_shader; + //generic gl code + GstGLDisplayThreadFunc generic_callback; + gpointer data; + //action redisplay GLuint redisplay_texture; GLuint redisplay_texture_width; @@ -258,6 +266,9 @@ void gst_gl_display_set_visible_context (GstGLDisplay* display, gboolean visible void gst_gl_display_resize_context (GstGLDisplay* display, gint width, gint height); gboolean gst_gl_display_redisplay (GstGLDisplay* display, GLuint texture, gint width, gint height); +void gst_gl_display_thread_add (GstGLDisplay *display, + GstGLDisplayThreadFunc func, gpointer data); + void gst_gl_display_gen_texture (GstGLDisplay* display, GLuint* pTexture); void gst_gl_display_del_texture (GstGLDisplay* display, GLuint texture); diff --git a/gst/gl/gstglfilterblur.c b/gst/gl/gstglfilterblur.c index fd0d43d0cf..8731737c46 100644 --- a/gst/gl/gstglfilterblur.c +++ b/gst/gl/gstglfilterblur.c @@ -196,6 +196,22 @@ gst_gl_filterblur_draw_texture (GstGLFilterBlur * filterblur, GLuint tex) glEnd (); } +static void +change_view (GstGLDisplay *display, gpointer data) +{ +// GstGLFilterBlur *filterblur = GST_GL_FILTERBLUR (data); + + const double mirrormatrix[16] = { + -1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0 + }; + + glMatrixMode (GL_MODELVIEW); + glLoadMatrixd (mirrormatrix); +} + static gboolean gst_gl_filterblur_filter (GstGLFilter* filter, GstGLBuffer* inbuf, GstGLBuffer* outbuf) @@ -208,6 +224,9 @@ gst_gl_filterblur_filter (GstGLFilter* filter, GstGLBuffer* inbuf, gst_gl_filter_render_to_target (filter, inbuf->texture, midtexture, gst_gl_filterblur_hcallback, filterblur); + + gst_gl_display_thread_add (filter->display, change_view, filterblur); + gst_gl_filter_render_to_target (filter, midtexture, outbuf->texture, gst_gl_filterblur_vcallback, filterblur);