]> git.cworth.org Git - glfps/blobdiff - glfps.c
Add a license to the glfps.c file
[glfps] / glfps.c
diff --git a/glfps.c b/glfps.c
index 6c9cd4988bfb46c055f7fcd8922e72d75f985535..3b5c2fab2e78659fa0b69ab29d6ffd617a22f1b8 100644 (file)
--- a/glfps.c
+++ b/glfps.c
@@ -1,3 +1,24 @@
+/* Copyright © 2013, Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
 #define _GNU_SOURCE /* For RTLD_NEXT */
 #include <dlfcn.h>
 
@@ -11,6 +32,8 @@
 #include <sys/time.h>
 #include <string.h>
 
+#include <glaze.h>
+
 /* How many frames between reports. */
 #define REPORT_FREQ 60
 
@@ -36,88 +59,10 @@ on_each_frame (void)
        count++;
 }
 
-static void *do_real_dlsym (void *handle, const char *symbol);
-
-static typeof(&glXSwapBuffers) real_glXSwapBuffers;
-
 void
 glXSwapBuffers (Display *dpy, GLXDrawable drawable)
 {
-       if (real_glXSwapBuffers == NULL)
-               real_glXSwapBuffers = do_real_dlsym (RTLD_NEXT, "glXSwapBuffers");
-
        on_each_frame ();
 
-       real_glXSwapBuffers (dpy, drawable);
-}
-
-static typeof(&glXGetProcAddressARB) real_glXGetProcAddressARB;
-
-void
-(*glXGetProcAddressARB (const GLubyte *func))(void)
-{
-       if (strcmp((char *) func, "glXSwapBuffers") == 0)
-               return (void*) glXSwapBuffers;
-
-       if (real_glXGetProcAddressARB == NULL)
-               real_glXGetProcAddressARB = do_real_dlsym (RTLD_NEXT, "glXGetProcAddressARB");
-
-       return real_glXGetProcAddressARB (func);
-}
-
-static typeof(&glXGetProcAddress) real_glXGetProcAddress;
-
-void
-(*glXGetProcAddress (const GLubyte *func))(void)
-{
-       if (strcmp((char *) func, "glXSwapBuffers") == 0)
-               return (void*) glXSwapBuffers;
-
-       if (real_glXGetProcAddress == NULL)
-               real_glXGetProcAddress = do_real_dlsym (RTLD_NEXT, "glXGetProcAddress");
-
-       return real_glXGetProcAddress (func);
-}
-
-/* We rely on an internal symbol within glibc in order to be able to
- * get a handle on the real dlsym function, (we can't call dlsym to
- * find the address of dlsym itself of course). */
-void * __libc_dlsym(void *, const char *);
-
-static void *
-do_real_dlsym (void *handle, const char *symbol)
-{
-       static typeof(&dlsym) real_dlsym = NULL;
-
-       if (real_dlsym == NULL) {
-               void *libdl_handle = dlopen ("libdl.so.2", RTLD_LAZY);
-               real_dlsym = __libc_dlsym(libdl_handle, "dlsym");
-       }
-
-       return real_dlsym (handle, symbol);
-}
-
-void *
-dlsym (void *handle, const char *symbol)
-{
-       void *ret;
-
-       ret = do_real_dlsym (handle, symbol);
-
-       if (strcmp (symbol, "glXSwapBuffers") == 0) {
-               real_glXSwapBuffers = ret;
-               return &glXSwapBuffers;
-       }
-
-       if (strcmp (symbol, "glXGetProcAddressARB") == 0) {
-               real_glXGetProcAddressARB = ret;
-               return &glXGetProcAddressARB;
-       }
-
-       if (strcmp (symbol, "glXGetProcAddress") == 0) {
-               real_glXGetProcAddress = ret;
-               return &glXGetProcAddress;
-       }
-
-       return ret;
+       GLAZE_DEFER (glXSwapBuffers, dpy, drawable);
 }