]> git.cworth.org Git - fips/blobdiff - glxwrap.c
Move metrics-tracking code from glwrap.c to new metrics.c
[fips] / glxwrap.c
index 51b5faf58f83f8017c822d7d287f7eb72dbb12d0..885f679c860bed17b0004c89e27986bb21515742 100644 (file)
--- a/glxwrap.c
+++ b/glxwrap.c
  * THE SOFTWARE.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <dlfcn.h>
+#include "fips.h"
 
 #include <X11/Xlib.h>
 #include <GL/gl.h>
 #include <GL/glx.h>
-#include <GL/glext.h>
 
-#include <sys/time.h>
+#include "dlwrap.h"
 
-typedef void (* fips_glXSwapBuffers_t)(Display *dpy, GLXDrawable drawable);
+#include "glwrap.h"
 
-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 = dlopen (libgl_filename, RTLD_NOW);
-               if (! libgl_handle) {
-                       fprintf (stderr, "Error: Failed to dlopen %s\n",
-                                libgl_filename);
-                       exit (1);
-               }
-       }
+       GLWRAP_DEFER (glXSwapBuffers, dpy, drawable);
 
-       return dlsym (libgl_handle, name);
+       glwrap_end_frame ();
 }
 
-static void
-call_glXSwapBuffers (Display *dpy, GLXDrawable drawable)
+
+typedef __GLXextFuncPtr (* fips_glXGetProcAddressARB_t)(const GLubyte *func);
+__GLXextFuncPtr
+glXGetProcAddressARB (const GLubyte *func)
 {
-       static fips_glXSwapBuffers_t real_glXSwapBuffers = NULL;
-       const char *name = "glXSwapBuffers";
+       __GLXextFuncPtr ptr;
+       static fips_glXGetProcAddressARB_t real_glXGetProcAddressARB = NULL;
+       char *name = "glXGetProcAddressARB";
 
-       if (! real_glXSwapBuffers) {
-               real_glXSwapBuffers = (fips_glXSwapBuffers_t) lookup (name);
-               if (! real_glXSwapBuffers) {
+       if (! real_glXGetProcAddressARB) {
+               real_glXGetProcAddressARB = glwrap_lookup (name);
+               if (! real_glXGetProcAddressARB) {
                        fprintf (stderr, "Error: Failed to find function %s.\n",
                                 name);
-                       return;
+                       return NULL;
                }
        }
-       real_glXSwapBuffers (dpy, drawable);
-}      
-
-void
-glXSwapBuffers (Display *dpy, GLXDrawable drawable)
-{
-       static int initialized = 0;
-       static int frames;
-       static struct timeval tv_start, tv_now;
-
-       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);
+       /* 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;
 
-               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);
-       }
+       /* Otherwise, just defer to the real glXGetProcAddressARB. */
+       return real_glXGetProcAddressARB (func);
 }