mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-05 15:08:53 +00:00
[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:
parent
db1c7a242b
commit
2313cea524
4 changed files with 45 additions and 76 deletions
|
@ -225,8 +225,7 @@ _gl_mem_copy_thread (GstGLContext * context, gpointer data)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_gl_context_gen_texture_thread (src->context, &tex_id, v_format, width,
|
gst_gl_context_gen_texture (src->context, &tex_id, v_format, width, height);
|
||||||
height);
|
|
||||||
if (!tex_id) {
|
if (!tex_id) {
|
||||||
GST_CAT_WARNING (GST_CAT_GL_MEMORY,
|
GST_CAT_WARNING (GST_CAT_GL_MEMORY,
|
||||||
"Could not create GL texture with context:%p", src->context);
|
"Could not create GL texture with context:%p", src->context);
|
||||||
|
|
|
@ -50,57 +50,8 @@
|
||||||
#define USING_GLES2(context) (gst_gl_context_get_gl_apie (context)->gl_api & GST_GL_API_GLES2)
|
#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)
|
#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 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 */
|
/* called in the gl thread */
|
||||||
gboolean
|
gboolean
|
||||||
gst_gl_context_check_framebuffer_status (GstGLContext * context)
|
gst_gl_context_check_framebuffer_status (GstGLContext * context)
|
||||||
|
@ -139,40 +90,61 @@ gst_gl_context_check_framebuffer_status (GstGLContext * context)
|
||||||
return FALSE;
|
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
|
void
|
||||||
gst_gl_context_gen_texture (GstGLContext * context, GLuint * pTexture,
|
gst_gl_context_gen_texture (GstGLContext * context, GLuint * pTexture,
|
||||||
GstVideoFormat v_format, GLint width, GLint height)
|
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)) {
|
*pTexture = data.result;
|
||||||
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;
|
|
||||||
|
|
||||||
gst_object_unref (window);
|
void
|
||||||
|
_del_texture (GstGLContext * context, guint * texture)
|
||||||
|
{
|
||||||
|
glDeleteTextures (1, texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gst_gl_context_del_texture (GstGLContext * context, GLuint * pTexture)
|
gst_gl_context_del_texture (GstGLContext * context, GLuint * pTexture)
|
||||||
{
|
{
|
||||||
GstGLWindow *window;
|
gst_gl_context_thread_add (context, (GstGLContextThreadFunc) _del_texture,
|
||||||
|
pTexture);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct _GenFBO
|
typedef struct _GenFBO
|
||||||
|
|
|
@ -76,8 +76,6 @@ typedef void (*GLCB_V2) (gpointer stuff);
|
||||||
|
|
||||||
void gst_gl_context_gen_texture (GstGLContext * context, GLuint * pTexture,
|
void gst_gl_context_gen_texture (GstGLContext * context, GLuint * pTexture,
|
||||||
GstVideoFormat v_format, GLint width, GLint height);
|
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);
|
void gst_gl_context_del_texture (GstGLContext * context, GLuint * pTexture);
|
||||||
|
|
||||||
gboolean gst_gl_context_gen_fbo (GstGLContext * context, gint width, gint height,
|
gboolean gst_gl_context_gen_fbo (GstGLContext * context, gint width, gint height,
|
||||||
|
|
|
@ -293,7 +293,7 @@ gst_gl_deinterlace_callback (gint width, gint height, guint texture,
|
||||||
gl->Enable (GL_TEXTURE_RECTANGLE_ARB);
|
gl->Enable (GL_TEXTURE_RECTANGLE_ARB);
|
||||||
|
|
||||||
if (G_UNLIKELY (deinterlace_filter->prev_tex == 0)) {
|
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,
|
&deinterlace_filter->prev_tex,
|
||||||
GST_VIDEO_INFO_FORMAT (&filter->out_info),
|
GST_VIDEO_INFO_FORMAT (&filter->out_info),
|
||||||
GST_VIDEO_INFO_WIDTH (&filter->out_info),
|
GST_VIDEO_INFO_WIDTH (&filter->out_info),
|
||||||
|
|
Loading…
Reference in a new issue