X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=glxwrap.c;h=799a0190f794de1a63346c372f17b2148835879d;hb=6b4c98a569784ffe9c0d580daf687cb624708937;hp=51b5faf58f83f8017c822d7d287f7eb72dbb12d0;hpb=1f4014b53a4dc77768f3998a6fd3b67024431fa3;p=fips diff --git a/glxwrap.c b/glxwrap.c index 51b5faf..799a019 100644 --- a/glxwrap.c +++ b/glxwrap.c @@ -19,78 +19,55 @@ * THE SOFTWARE. */ -#include -#include +#include "fips.h" -#include +#include "fips-dispatch.h" #include #include #include -#include -#include +#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; + GLWRAP_DEFER (glXSwapBuffers, dpy, drawable); - 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); - } - } - - return 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 nominall 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) -{ - static int initialized = 0; - static int frames; - static struct timeval tv_start, tv_now; + /* Otherwise, just defer to the real glXGetProcAddressARB. */ + GLWRAP_DEFER_WITH_RETURN (ret, glXGetProcAddressARB, func); - if (! initialized) { - frames = 0; - gettimeofday (&tv_start, NULL); - initialized = 1; - } + return ret; +} - call_glXSwapBuffers (dpy, drawable); +Bool +glXMakeCurrent (Display *dpy, GLXDrawable drawable, GLXContext ctx) +{ + Bool ret; - frames++; - if (frames % 60 == 0) { - double fps; - gettimeofday (&tv_now, NULL); + fips_dispatch_init (FIPS_API_GLX); - fps = (double) frames / (tv_now.tv_sec - tv_start.tv_sec + - (tv_now.tv_usec - tv_start.tv_usec) / 1.0e6); + GLWRAP_DEFER_WITH_RETURN (ret, glXMakeCurrent, dpy, drawable, ctx); - printf("FPS: %.3f\n", fps); - } + return ret; }