]> git.cworth.org Git - fips/blobdiff - glxwrap.c
libfips.sym: Sort list in symbol map alphabetically.
[fips] / glxwrap.c
index 4d16e4d6a1b86c093bbad6f4d8b1f35ff337e0f8..18ec3c107ccfad427ce4f694fb798c46bd441ae7 100644 (file)
--- a/glxwrap.c
+++ b/glxwrap.c
 #include <GL/gl.h>
 #include <GL/glx.h>
 
-#include <sys/time.h>
-
 #include "dlwrap.h"
-
-typedef void (* fips_glXSwapBuffers_t)(Display *dpy, GLXDrawable drawable);
-
-static void *
-lookup (const char *name)
-{
-       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);
-               }
-       }
-
-       return dlwrap_real_dlsym (libgl_handle, name);
-}
-
-static void
-call_glXSwapBuffers (Display *dpy, GLXDrawable drawable)
-{
-       static fips_glXSwapBuffers_t real_glXSwapBuffers = NULL;
-       const char *name = "glXSwapBuffers";
-
-       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);
-}      
+#include "glwrap.h"
+#include "metrics.h"
 
 void
 glXSwapBuffers (Display *dpy, GLXDrawable drawable)
 {
-       static int initialized = 0;
-       static int frames;
-       static struct timeval tv_start, tv_now;
+       GLWRAP_DEFER (glXSwapBuffers, dpy, drawable);
 
-       if (! initialized) {
-               frames = 0;
-               gettimeofday (&tv_start, NULL);
-               initialized = 1;
-       }
-
-       call_glXSwapBuffers (dpy, drawable);
-
-       frames++;
-       if (frames % 60 == 0) {
-               double fps;
-               gettimeofday (&tv_now, NULL);
-
-               fps = (double) frames / (tv_now.tv_sec - tv_start.tv_sec +
-                                        (tv_now.tv_usec - tv_start.tv_usec) / 1.0e6);
-
-               printf("FPS: %.3f\n", fps);
-       }
+       metrics_end_frame ();
 }
 
 
@@ -99,12 +43,12 @@ __GLXextFuncPtr
 glXGetProcAddressARB (const GLubyte *func)
 {
        __GLXextFuncPtr ptr;
-       static fips_glXGetProcAddressARB_t real_glXGetProcAddressARB = NULL;
-       const char *name = "glXGetProcAddressARB";
+       static fips_glXGetProcAddressARB_t glxwrap_real_glXGetProcAddressARB = NULL;
+       char *name = "glXGetProcAddressARB";
 
-       if (! real_glXGetProcAddressARB) {
-               real_glXGetProcAddressARB = (fips_glXGetProcAddressARB_t) lookup (name);
-               if (! real_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;
@@ -117,5 +61,5 @@ glXGetProcAddressARB (const GLubyte *func)
                return ptr;
 
        /* Otherwise, just defer to the real glXGetProcAddressARB. */
-       return real_glXGetProcAddressARB (func);
+       return glxwrap_real_glXGetProcAddressARB (func);
 }