]> git.cworth.org Git - fips/blobdiff - glwrap.c
Simplify metrics interface by dropping metrics_counter_new
[fips] / glwrap.c
index 0ae295a87082212b59d764f8b89250c2ab5c68b8..ebe7e54ca67386d1e51d648dde3ba5fcc8b39f1d 100644 (file)
--- a/glwrap.c
+++ b/glwrap.c
@@ -71,14 +71,31 @@ glwrap_lookup (char *name)
         * our dlopen wrapper, which will then call
         * glwrap_set_gl_handle to give us the handle to use here.
         *
-
         * If the application hasn't called dlopen on a "libGL"
         * library, then presumably the application is linked directly
         * to an OpenGL implementation. In this case, we can use
         * RTLD_NEXT to find the symbol.
+        *
+        * But just in case, we also let the user override that by
+        * specifying the FIPS_LIBGL environment variable to the path
+        * of the real libGL.so library that fips should dlopen here.
         */
-       if (gl_handle == NULL)
-               gl_handle = RTLD_NEXT;
+       if (gl_handle == NULL) {
+               const char *path;
+
+               path = getenv ("FIPS_LIBGL");
+               if (path) {
+                       gl_handle = dlopen (path, RTLD_LAZY);
+
+                       if (gl_handle == NULL) {
+                               fprintf (stderr, "Failed to dlopen FIPS_LIBGL: "
+                                        "%s\n", path);
+                               exit (1);
+                       }
+               } else {
+                       gl_handle = RTLD_NEXT;
+               }
+       }
 
        ret = dlwrap_real_dlsym (gl_handle, name);
 
@@ -94,9 +111,7 @@ glwrap_lookup (char *name)
 /* Execute an OpenGL call and time it with a GPU metrics counter. */
 #define TIMED_DEFER(function,...) do {                                 \
        if (! inside_new_list) {                                        \
-               unsigned counter;                                       \
-               counter = metrics_counter_new ();                       \
-               metrics_counter_start (counter);                        \
+               metrics_counter_start ();                               \
        }                                                               \
        GLWRAP_DEFER(function, __VA_ARGS__);                            \
        if (! inside_new_list) {                                        \
@@ -369,11 +384,7 @@ void
 glBegin (GLenum mode)
 {
        if (! inside_new_list)
-       {
-               unsigned counter;
-               counter = metrics_counter_new ();
-               metrics_counter_start (counter);
-       }
+               metrics_counter_start ();
 
        GLWRAP_DEFER (glBegin, mode);
 }
@@ -383,9 +394,8 @@ glEnd (void)
 {
        GLWRAP_DEFER (glEnd);
 
-       if (! inside_new_list) {
+       if (! inside_new_list)
                metrics_counter_stop ();
-       }
 }
 
 /* And we need to track display lists to avoid inserting queries