mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 20:21:24 +00:00
[142/906] Add a generic action to be able to execute arbitrary gl code within the gl thread with less pain
This commit is contained in:
parent
77c0b28031
commit
396afd5ef3
3 changed files with 58 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue