[gtk/wip/otte/memoryformat: 5/7] gltexture: Determine format in current thread




commit 52e88ed4c882f4979dbf812607ddd0e2b0603363
Author: Benjamin Otte <otte redhat com>
Date:   Wed Oct 13 00:36:38 2021 +0200

    gltexture: Determine format in current thread
    
    Close widget-factory and observe:
    
    Thread 1:
     * acquire main loop
     * handle close button
     * close window
     * dispose video and media stream
     * stop GstPlayer
    WAIT on pipeline stopping
    
    Thread 2:
     * prepare next image in pipeline
     * hand image to GtkGstSink
     * create GdkTexture from image
     * gdk_gl_texture_new() determines format
    WAIT on acquiring main loop
    
    Sounds like a deadlock?
    
    Indeed, so don't do that.

 gdk/gdkgltexture.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/gdk/gdkgltexture.c b/gdk/gdkgltexture.c
index d734dbc4b9..b20534801a 100644
--- a/gdk/gdkgltexture.c
+++ b/gdk/gdkgltexture.c
@@ -298,12 +298,24 @@ gdk_gl_texture_release (GdkGLTexture *self)
 }
 
 static void
-gdk_gl_texture_do_determine_format (gpointer texture_,
-                                    gpointer unused)
+gdk_gl_texture_determine_format (GdkGLTexture *self)
 {
-  GdkTexture *texture = texture_;
+  GdkTexture *texture = GDK_TEXTURE (self);
+  GLint active_texture;
   GLint internal_format;
 
+  if (self->context != gdk_gl_context_get_current ())
+    {
+      /* Somebody else is GL-ing here, abort! */
+      texture->format = GDK_MEMORY_DEFAULT;
+      return;
+    }
+
+  /* We need to be careful about modifying the GL context, as this is not
+   * expected during construction */
+  glGetIntegerv (GL_TEXTURE_BINDING_2D, &active_texture);
+  glBindTexture (GL_TEXTURE_2D, self->id);
+
   glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &internal_format);
 
   switch (internal_format)
@@ -347,6 +359,8 @@ gdk_gl_texture_do_determine_format (gpointer texture_,
       texture->format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
       break;
   }
+
+  glBindTexture (GL_TEXTURE_2D, active_texture);
 }
 
 /**
@@ -392,7 +406,7 @@ gdk_gl_texture_new (GdkGLContext   *context,
   self->destroy = destroy;
   self->data = data;
 
-  gdk_gl_texture_run (self, gdk_gl_texture_do_determine_format, NULL);
+  gdk_gl_texture_determine_format (self);
 
   return GDK_TEXTURE (self);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]