[819/906] make gen_texture/del_texture threadsafe
authorMatthew Waters <ystreet00@gmail.com>
Thu, 26 Sep 2013 15:15:25 +0000 (01:15 +1000)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 9 Dec 2017 19:31:31 +0000 (19:31 +0000)
Use stack allocated instead of static variables

Conflicts:
gst-libs/gst/gl/gstglutils.c

gst-libs/gst/gl/gstglmemory.c
gst-libs/gst/gl/gstglutils.c
gst-libs/gst/gl/gstglutils.h

index 3578db9dbc49b3744a302b005781e1930b7a5caf..31305998c484114399d50d0a1958a711a4c253c2 100644 (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);
index 64ac0c5d8503e65f7294a411db9ce36d5a074540..82d17338d43fac7b4608563f164a7c590c39961c 100644 (file)
 #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
index 037c8951d31724b6481c75da0e33b7fc1924a967..35717c0b30a3e8d76d332d56b1540d9b29c11b71 100644 (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,