]> git.cworth.org Git - fips/blobdiff - glxwrap.c
Add explicit link to libpthread, to work around debugging issues
[fips] / glxwrap.c
index 6da42e6622abf2a613f373e5db2ef0014c9d80bc..4b87642e08846612d8d3f2ce1739e39db7373cb8 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 "context.h"
 #include "dlwrap.h"
 #include "glwrap.h"
 #include "metrics.h"
@@ -34,35 +37,73 @@ glXSwapBuffers (Display *dpy, GLXDrawable drawable)
 {
        GLWRAP_DEFER (glXSwapBuffers, dpy, drawable);
 
-       metrics_end_frame ();
+       context_counter_stop ();
+
+       context_end_frame ();
+
+       context_counter_start ();
 }
 
 /* glXGetProcAddressARB is a function which accepts a string and
- * returns a generic function pointer (which nominall accepts void 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)
 {
-       void *ptr;
-       static typeof(&glXGetProcAddressARB) glxwrap_real_glXGetProcAddressARB = NULL;
-       char *name = "glXGetProcAddressARB";
-
-       if (! glxwrap_real_glXGetProcAddressARB) {
-               glxwrap_real_glXGetProcAddressARB = glwrap_lookup (name);
-               if (! glxwrap_real_glXGetProcAddressARB) {
-                       fprintf (stderr, "Error: Failed to find function %s.\n",
-                                name);
-                       return NULL;
-               }
-       }
+       static void *libfips_handle = NULL;
+       void *ret;
+
+       if (libfips_handle == NULL)
+               libfips_handle = dlwrap_dlopen_libfips ();
 
        /* 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;
+       ret = dlwrap_real_dlsym (libfips_handle, (const char *) func);
+       if (ret)
+               return ret;
 
        /* Otherwise, just defer to the real glXGetProcAddressARB. */
-       return glxwrap_real_glXGetProcAddressARB (func);
+       GLWRAP_DEFER_WITH_RETURN (ret, glXGetProcAddressARB, func);
+
+       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);
+}
+
+Bool
+glXMakeCurrent (Display *dpy, GLXDrawable drawable, GLXContext ctx)
+{
+       Bool ret;
+
+       context_leave ();
+
+       GLWRAP_DEFER_WITH_RETURN (ret, glXMakeCurrent, dpy, drawable, ctx);
+
+       context_enter (FIPS_API_GLX, ctx);
+
+       return ret;
+}
+
+Bool
+glXMakeContextCurrent (Display *dpy, GLXDrawable drawable, GLXDrawable read, GLXContext ctx)
+{
+       Bool ret;
+
+       context_leave ();
+
+       GLWRAP_DEFER_WITH_RETURN (ret, glXMakeContextCurrent, dpy, drawable, read, ctx);
+
+       context_enter (FIPS_API_GLX, ctx);
+
+       return ret;
 }