]> git.cworth.org Git - fips/blobdiff - glxwrap.c
util-x11: Rework init_window interface to accept XVisualInfo
[fips] / glxwrap.c
index 78627d42005a223eca6128dd12177d06e8278257..d7d4191ce528ae5b59c5f8a9317b8e99a179d679 100644 (file)
--- a/glxwrap.c
+++ b/glxwrap.c
 
 #include "fips.h"
 
+#include "fips-dispatch.h"
+
 #include <X11/Xlib.h>
 #include <GL/gl.h>
 #include <GL/glx.h>
 
 #include "dlwrap.h"
-
 #include "glwrap.h"
+#include "metrics.h"
 
-typedef void (* fips_glXSwapBuffers_t)(Display *dpy, GLXDrawable drawable);
-
-static void *
-lookup (const char *name)
+void
+glXSwapBuffers (Display *dpy, GLXDrawable drawable)
 {
-       const char *libgl_filename = "libGL.so.1";
-       static void *libgl_handle = NULL;
-
-       if (! libgl_handle) {
-               libgl_handle = dlwrap_real_dlopen (libgl_filename, RTLD_NOW | RTLD_DEEPBIND);
-               if (! libgl_handle) {
-                       fprintf (stderr, "Error: Failed to dlopen %s\n",
-                                libgl_filename);
-                       exit (1);
-               }
-       }
+       GLWRAP_DEFER (glXSwapBuffers, dpy, drawable);
 
-       return dlwrap_real_dlsym (libgl_handle, name);
+       metrics_end_frame ();
 }
 
-static void
-call_glXSwapBuffers (Display *dpy, GLXDrawable drawable)
+/* glXGetProcAddressARB is a function which accepts a string and
+ * returns a generic function pointer (which nominally accepts void and
+ * has void return type). Of course, the user is expected to cast the
+ * returned function pointer to a function pointer of the expected
+ * type.
+ */
+void (*glXGetProcAddressARB (const GLubyte *func))(void)
 {
-       static fips_glXSwapBuffers_t real_glXSwapBuffers = NULL;
-       const char *name = "glXSwapBuffers";
+       void *ret;
 
-       if (! real_glXSwapBuffers) {
-               real_glXSwapBuffers = (fips_glXSwapBuffers_t) lookup (name);
-               if (! real_glXSwapBuffers) {
-                       fprintf (stderr, "Error: Failed to find function %s.\n",
-                                name);
-                       return;
-               }
-       }
-       real_glXSwapBuffers (dpy, drawable);
-}      
+       /* If our library has this symbol, that's what we want to give. */
+       ret = dlwrap_real_dlsym (NULL, (const char *) func);
+       if (ret)
+               return ret;
 
-void
-glXSwapBuffers (Display *dpy, GLXDrawable drawable)
-{
-       call_glXSwapBuffers (dpy, drawable);
+       /* Otherwise, just defer to the real glXGetProcAddressARB. */
+       GLWRAP_DEFER_WITH_RETURN (ret, glXGetProcAddressARB, func);
 
-       glwrap_end_frame ();
+       return ret;
 }
 
+void (*glXGetProcAddress (const GLubyte *func))(void)
+{
+       /* This comment must not be removed. It ensures that the
+        * glXGetProcAddress function ends up in our exported symbol
+        * list even though there's not otherwise any code saying:
+        *
+        * GLWRAP_DEFER_WITH_RETURN (ret, glXGetProcAddress, func);
+        */
+       return glXGetProcAddressARB(func);
+}
 
-typedef __GLXextFuncPtr (* fips_glXGetProcAddressARB_t)(const GLubyte *func);
-__GLXextFuncPtr
-glXGetProcAddressARB (const GLubyte *func)
+Bool
+glXMakeCurrent (Display *dpy, GLXDrawable drawable, GLXContext ctx)
 {
-       __GLXextFuncPtr ptr;
-       static fips_glXGetProcAddressARB_t real_glXGetProcAddressARB = NULL;
-       const char *name = "glXGetProcAddressARB";
+       Bool ret;
 
-       if (! real_glXGetProcAddressARB) {
-               real_glXGetProcAddressARB = (fips_glXGetProcAddressARB_t) lookup (name);
-               if (! real_glXGetProcAddressARB) {
-                       fprintf (stderr, "Error: Failed to find function %s.\n",
-                                name);
-                       return NULL;
-               }
-       }
+       fips_dispatch_init (FIPS_API_GLX);
 
-       /* If our library has this symbol, that's what we want to give. */
-       ptr = dlwrap_real_dlsym (NULL, (const char *) func);
-       if (ptr)
-               return ptr;
+       GLWRAP_DEFER_WITH_RETURN (ret, glXMakeCurrent, dpy, drawable, ctx);
 
-       /* Otherwise, just defer to the real glXGetProcAddressARB. */
-       return real_glXGetProcAddressARB (func);
+       return ret;
 }