[819/906] make gen_texture/del_texture threadsafe

Use stack allocated instead of static variables

Conflicts:
	gst-libs/gst/gl/gstglutils.c
This commit is contained in:
Matthew Waters 2013-09-27 01:15:25 +10:00
parent db1c7a242b
commit 2313cea524
4 changed files with 45 additions and 76 deletions

View file

@ -225,8 +225,7 @@ _gl_mem_copy_thread (GstGLContext * context, gpointer data)
goto error;
}
gst_gl_context_gen_texture_thread (src->context, &tex_id, v_format, width,
height);
gst_gl_context_gen_texture (src->context, &tex_id, v_format, width, height);
if (!tex_id) {
GST_CAT_WARNING (GST_CAT_GL_MEMORY,
"Could not create GL texture with context:%p", src->context);

View file

@ -50,57 +50,8 @@
#define USING_GLES2(context) (gst_gl_context_get_gl_apie (context)->gl_api & GST_GL_API_GLES2)
#define USING_GLES3(context) (gst_gl_context_get_gl_apie (context) & GST_GL_API_GLES3)
static GLuint gen_texture;
static GLuint gen_texture_width;
static GLuint gen_texture_height;
static GstVideoFormat gen_texture_video_format;
static GLuint *del_texture;
static gchar *error_message;
static void
gst_gl_context_gen_texture_window_cb (GstGLContext * context)
{
gst_gl_context_gen_texture_thread (context, &gen_texture,
gen_texture_video_format, gen_texture_width, gen_texture_height);
}
/* Generate a texture if no one is available in the pool
* Called in the gl thread */
void
gst_gl_context_gen_texture_thread (GstGLContext * context, GLuint * pTexture,
GstVideoFormat v_format, GLint width, GLint height)
{
const GstGLFuncs *gl = context->gl_vtable;
GST_TRACE ("Generating texture format:%u dimensions:%ux%u", v_format,
width, height);
gl->GenTextures (1, pTexture);
gl->BindTexture (GL_TEXTURE_RECTANGLE_ARB, *pTexture);
gl->TexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, width, height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
gl->TexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
GL_LINEAR);
gl->TexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
GL_LINEAR);
gl->TexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
gl->TexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
GST_LOG ("generated texture id:%d", *pTexture);
}
void
gst_gl_context_del_texture_window_cb (GstGLContext * context)
{
const GstGLFuncs *gl = context->gl_vtable;
gl->DeleteTextures (1, del_texture);
}
/* called in the gl thread */
gboolean
gst_gl_context_check_framebuffer_status (GstGLContext * context)
@ -139,40 +90,61 @@ gst_gl_context_check_framebuffer_status (GstGLContext * context)
return FALSE;
}
typedef struct _GenTexture
{
guint width, height;
GstVideoFormat format;
guint result;
} GenTexture;
static void
_gen_texture (GstGLContext * context, GenTexture * data)
{
const GstGLFuncs *gl = context->gl_vtable;
GST_TRACE ("Generating texture format:%u dimensions:%ux%u", data->format,
data->width, data->height);
gl->GenTextures (1, &data->result);
gl->BindTexture (GL_TEXTURE_RECTANGLE_ARB, data->result);
gl->TexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, data->width,
data->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
gl->TexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
GL_LINEAR);
gl->TexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
GL_LINEAR);
gl->TexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
gl->TexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
GST_LOG ("generated texture id:%d", data->result);
}
void
gst_gl_context_gen_texture (GstGLContext * context, GLuint * pTexture,
GstVideoFormat v_format, GLint width, GLint height)
{
GstGLWindow *window;
GenTexture data = { width, height, v_format, 0 };
window = gst_gl_context_get_window (context);
gst_gl_context_thread_add (context, (GstGLContextThreadFunc) _gen_texture,
&data);
if (gst_gl_window_is_running (window)) {
gen_texture_width = width;
gen_texture_height = height;
gen_texture_video_format = v_format;
gst_gl_window_send_message (window,
GST_GL_WINDOW_CB (gst_gl_context_gen_texture_window_cb), context);
*pTexture = gen_texture;
} else
*pTexture = 0;
*pTexture = data.result;
}
gst_object_unref (window);
void
_del_texture (GstGLContext * context, guint * texture)
{
glDeleteTextures (1, texture);
}
void
gst_gl_context_del_texture (GstGLContext * context, GLuint * pTexture)
{
GstGLWindow *window;
window = gst_gl_context_get_window (context);
if (gst_gl_window_is_running (window) && *pTexture) {
del_texture = pTexture;
gst_gl_window_send_message (window,
GST_GL_WINDOW_CB (gst_gl_context_del_texture_window_cb), context);
}
gst_object_unref (window);
gst_gl_context_thread_add (context, (GstGLContextThreadFunc) _del_texture,
pTexture);
}
typedef struct _GenFBO

View file

@ -76,8 +76,6 @@ typedef void (*GLCB_V2) (gpointer stuff);
void gst_gl_context_gen_texture (GstGLContext * context, GLuint * pTexture,
GstVideoFormat v_format, GLint width, GLint height);
void gst_gl_context_gen_texture_thread (GstGLContext * context, GLuint * pTexture,
GstVideoFormat v_format, GLint width, GLint height);
void gst_gl_context_del_texture (GstGLContext * context, GLuint * pTexture);
gboolean gst_gl_context_gen_fbo (GstGLContext * context, gint width, gint height,

View file

@ -293,7 +293,7 @@ gst_gl_deinterlace_callback (gint width, gint height, guint texture,
gl->Enable (GL_TEXTURE_RECTANGLE_ARB);
if (G_UNLIKELY (deinterlace_filter->prev_tex == 0)) {
gst_gl_context_gen_texture_thread (filter->context,
gst_gl_context_gen_texture (filter->context,
&deinterlace_filter->prev_tex,
GST_VIDEO_INFO_FORMAT (&filter->out_info),
GST_VIDEO_INFO_WIDTH (&filter->out_info),