[gtkglext] Directly store the GLX/WGL context in hashtable instead of a pointer to it



commit 711297768b5771a18d4c89db5ba3c963588230a1
Author: Mukund Sivaraman <muks banu com>
Date:   Sun Sep 27 11:16:03 2009 +0530

    Directly store the GLX/WGL context in hashtable instead of a pointer to it
    
    This patch:
    
     - Uses glib direct hash functions instead of local implementations
     - Fixes a bug where context lookups would have always failed

 gdk/win32/gdkglcontext-win32.c |   29 ++++++++---------------------
 gdk/x11/gdkglcontext-x11.c     |   31 ++++++++++---------------------
 2 files changed, 18 insertions(+), 42 deletions(-)
---
diff --git a/gdk/win32/gdkglcontext-win32.c b/gdk/win32/gdkglcontext-win32.c
index 408e080..2dae1a9 100644
--- a/gdk/win32/gdkglcontext-win32.c
+++ b/gdk/win32/gdkglcontext-win32.c
@@ -24,9 +24,6 @@
 static void          gdk_gl_context_insert (GdkGLContext *glcontext);
 static void          gdk_gl_context_remove (GdkGLContext *glcontext);
 static GdkGLContext *gdk_gl_context_lookup (HGLRC         hglrc);
-static guint         gdk_gl_context_hash   (HGLRC        *hglrc);
-static gboolean      gdk_gl_context_equal  (HGLRC        *a,
-                                            HGLRC        *b);
 
 static void gdk_gl_context_impl_win32_class_init (GdkGLContextImplWin32Class *klass);
 static void gdk_gl_context_impl_win32_finalize   (GObject                    *object);
@@ -432,13 +429,16 @@ gdk_gl_context_insert (GdkGLContext *glcontext)
   if (gl_context_ht == NULL)
     {
       GDK_GL_NOTE (MISC, g_message (" -- Create GL context hash table."));
-      gl_context_ht = g_hash_table_new ((GHashFunc) gdk_gl_context_hash,
-                                        (GEqualFunc) gdk_gl_context_equal);
+
+      /* We do not know the storage type of HGLRC. We assume that it is
+         a pointer as NULL values are specified for this type. */
+      gl_context_ht = g_hash_table_new (g_direct_hash,
+                                        g_direct_equal);
     }
 
   impl = GDK_GL_CONTEXT_IMPL_WIN32 (glcontext);
 
-  g_hash_table_insert (gl_context_ht, &(impl->hglrc), glcontext);
+  g_hash_table_insert (gl_context_ht, impl->hglrc, glcontext);
 }
 
 static void
@@ -455,7 +455,7 @@ gdk_gl_context_remove (GdkGLContext *glcontext)
 
   impl = GDK_GL_CONTEXT_IMPL_WIN32 (glcontext);
 
-  g_hash_table_remove (gl_context_ht, &(impl->hglrc));
+  g_hash_table_remove (gl_context_ht, impl->hglrc);
 
   if (g_hash_table_size (gl_context_ht) == 0)
     {
@@ -473,18 +473,5 @@ gdk_gl_context_lookup (HGLRC hglrc)
   if (gl_context_ht == NULL)
     return NULL;
 
-  return g_hash_table_lookup (gl_context_ht, &hglrc);
-}
-
-static guint
-gdk_gl_context_hash (HGLRC *hglrc)
-{
-  return (guint) *hglrc;
-}
-
-static gboolean
-gdk_gl_context_equal (HGLRC *a,
-                      HGLRC *b)
-{
-  return (*a == *b);
+  return g_hash_table_lookup (gl_context_ht, hglrc);
 }
diff --git a/gdk/x11/gdkglcontext-x11.c b/gdk/x11/gdkglcontext-x11.c
index 9f772cb..eae794e 100644
--- a/gdk/x11/gdkglcontext-x11.c
+++ b/gdk/x11/gdkglcontext-x11.c
@@ -27,9 +27,6 @@
 static void          gdk_gl_context_insert (GdkGLContext *glcontext);
 static void          gdk_gl_context_remove (GdkGLContext *glcontext);
 static GdkGLContext *gdk_gl_context_lookup (GLXContext    glxcontext);
-static guint         gdk_gl_context_hash   (GLXContext   *glxcontext);
-static gboolean      gdk_gl_context_equal  (GLXContext   *a,
-                                            GLXContext   *b);
 
 static void gdk_gl_context_impl_x11_class_init (GdkGLContextImplX11Class *klass);
 static void gdk_gl_context_impl_x11_finalize   (GObject                  *object);
@@ -545,13 +542,18 @@ gdk_gl_context_insert (GdkGLContext *glcontext)
   if (gl_context_ht == NULL)
     {
       GDK_GL_NOTE (MISC, g_message (" -- Create GL context hash table."));
-      gl_context_ht = g_hash_table_new ((GHashFunc) gdk_gl_context_hash,
-                                        (GEqualFunc) gdk_gl_context_equal);
+
+      /* We do not know the storage type of GLXContext from the GLX
+         specification. We assume that it is a pointer as NULL values
+         are specified for this type---this is consistent with the SGI
+         and Mesa GLX implementations. */
+      gl_context_ht = g_hash_table_new (g_direct_hash,
+                                        g_direct_equal);
     }
 
   impl = GDK_GL_CONTEXT_IMPL_X11 (glcontext);
 
-  g_hash_table_insert (gl_context_ht, &(impl->glxcontext), glcontext);
+  g_hash_table_insert (gl_context_ht, impl->glxcontext, glcontext);
 }
 
 static void
@@ -566,7 +568,7 @@ gdk_gl_context_remove (GdkGLContext *glcontext)
 
   impl = GDK_GL_CONTEXT_IMPL_X11 (glcontext);
 
-  g_hash_table_remove (gl_context_ht, &(impl->glxcontext));
+  g_hash_table_remove (gl_context_ht, impl->glxcontext);
 
   if (g_hash_table_size (gl_context_ht) == 0)
     {
@@ -584,18 +586,5 @@ gdk_gl_context_lookup (GLXContext glxcontext)
   if (gl_context_ht == NULL)
     return NULL;
 
-  return g_hash_table_lookup (gl_context_ht, &glxcontext);
-}
-
-static guint
-gdk_gl_context_hash (GLXContext *glxcontext)
-{
-  return (guint) *glxcontext;
-}
-
-static gboolean
-gdk_gl_context_equal (GLXContext *a,
-                      GLXContext *b)
-{
-  return (*a == *b);
+  return g_hash_table_lookup (gl_context_ht, glxcontext);
 }



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