]> git.cworth.org Git - fips/commitdiff
Add support for OpenGL ES by conditionally compiling wrapper for eglSwapBuffers
authorCarl Worth <cworth@cworth.org>
Mon, 6 May 2013 18:30:06 +0000 (11:30 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 6 May 2013 18:36:56 +0000 (11:36 -0700)
The configure script now looks for EGL/egl.h, (via pkg-config or directly),
and if present, will compile a wrapper for eglSwapBuffers.

This allows fips to report metrics for OpenGL ES programs.

Makefile.local
configure
eglwrap.c [new file with mode: 0644]
glxwrap.c
libfips.sym

index 2f9b5f0a19e2e8d10aafafeeb63b055c19fa903f..c81b0768c489b92553da20207b58ffaf67faddad 100644 (file)
@@ -85,6 +85,10 @@ libfips_srcs = \
        glxwrap.c \
        metrics.c
 
        glxwrap.c \
        metrics.c
 
+ifeq ($(HAVE_EGL),Yes)
+libfips_srcs += eglwrap.c
+endif
+
 libfips_32_modules = $(libfips_srcs:.c=-32.o)
 
 libfips_64_modules = $(libfips_srcs:.c=-64.o)
 libfips_32_modules = $(libfips_srcs:.c=-32.o)
 
 libfips_64_modules = $(libfips_srcs:.c=-64.o)
index 121aec4d2604add06e3454a46f15f63ab15dfdb6..a79960700aeb0fa44ebdcd20da0452fd296e75a4 100755 (executable)
--- a/configure
+++ b/configure
@@ -251,18 +251,37 @@ printf "Checking for GL window-system-binding headers:\n"
 have_gl_winsys=0
 
 printf "    Checking for GL/glx.h... "
 have_gl_winsys=0
 
 printf "    Checking for GL/glx.h... "
-have_glx=0
+have_glx=No
 printf "#include <GL/glx.h>\nint main(void){return 0;}\n" > glx-minimal.c
 if ${CC} -o glx-minimal glx-minimal.c ${gl_cflags} > /dev/null 2>&1
 then
     printf "Yes.\n"
     have_gl_winsys=1
 printf "#include <GL/glx.h>\nint main(void){return 0;}\n" > glx-minimal.c
 if ${CC} -o glx-minimal glx-minimal.c ${gl_cflags} > /dev/null 2>&1
 then
     printf "Yes.\n"
     have_gl_winsys=1
-    have_glx=1
+    have_glx=Yes
 else
     printf "No.\n"
 fi
 rm -f glx-minimal glx-minimal.c
 
 else
     printf "No.\n"
 fi
 rm -f glx-minimal glx-minimal.c
 
+printf "    Checking for GL/egl.h... "
+have_egl=No
+if pkg-config --exists egl; then
+    printf "Yes.\n"
+    have_egl=Yes
+    egl_cflags=$(pkg-config --cflags egl)
+else
+    printf "#include <GL/egl.h>\nint main(void){return 0;}\n" > egl-minimal.c
+    if ${CC} -o egl-minimal egl-minimal.c ${gl_cflags} > /dev/null 2>&1
+    then
+       printf "Yes.\n"
+       have_gl_winsys=1
+       have_egl=1
+    else
+       printf "No.\n"
+    fi
+    rm -f egl-minimal egl-minimal.c
+fi
+
 if [ $have_gl_winsys -eq 0 ]; then
     errors=$((errors + 1))
 fi
 if [ $have_gl_winsys -eq 0 ]; then
     errors=$((errors + 1))
 fi
@@ -291,7 +310,7 @@ EOF
        echo
     fi
     if [ $have_gl_winsys -eq 0 ]; then
        echo
     fi
     if [ $have_gl_winsys -eq 0 ]; then
-       echo "  OpenGL window-system-bindings header files (GL/glx.h)"
+       echo "  OpenGL window-system-bindings header files (GL/glx.h and/or GL/egl.h)"
        echo "  http://www.mesa3d.org/"
        echo
     fi
        echo "  http://www.mesa3d.org/"
        echo
     fi
@@ -303,12 +322,12 @@ case a simple command will install everything you need. For example:
 On Debian and similar systems:
 
        sudo apt-get install libtalloc-dev libelf-dev \\
 On Debian and similar systems:
 
        sudo apt-get install libtalloc-dev libelf-dev \\
-       libgl1-mesa-dev
+       libgl1-mesa-dev libgles2-mesa-dev
 
 Or on Fedora and similar systems:
 
        sudo yum install libtalloc-devel libelf-devel \\
 
 Or on Fedora and similar systems:
 
        sudo yum install libtalloc-devel libelf-devel \\
-       mesa-libGL-devel
+       mesa-libGL-devel mesa-libGLES-devel
 
 On other systems, similar commands can be used, but the details of the
 package names may be different.
 
 On other systems, similar commands can be used, but the details of the
 package names may be different.
@@ -357,8 +376,14 @@ rm -f minimal minimal.c
 
 cat <<EOF
 
 
 cat <<EOF
 
-All required packages were found. You may now run the following
-commands to compile and install ${PROJECT}:
+All required packages were found.
+
+The following OpenGL window-system bindings will be supported:
+
+       GLX: ${have_glx}
+       EGL: ${have_egl}
+
+You may now run the following commands to compile and install ${PROJECT}:
 
        make
        sudo make install
 
        make
        sudo make install
@@ -432,14 +457,23 @@ TALLOC_LDFLAGS = ${talloc_ldflags}
 LIBELF_CFLAGS = ${libelf_cflags}
 LIBELF_LDFLAGS = ${libelf_ldflags}
 
 LIBELF_CFLAGS = ${libelf_cflags}
 LIBELF_LDFLAGS = ${libelf_ldflags}
 
+# Whether GLX headers are available
+HAVE_GLX = ${have_glx}
+
 # Flags needed to find GL and GLX header files (GL/gl.h and GL/glx.h)
 GL_CFLAGS = ${gl_cflags}
 
 # Flags needed to find GL and GLX header files (GL/gl.h and GL/glx.h)
 GL_CFLAGS = ${gl_cflags}
 
+# Whether EGL headers are available
+HAVE_EGL = ${have_egl}
+
+# Flags needed to find EGL header files (EGL/egl.h)
+EGL_CFLAGS = ${egl_cflags}
+
 # Flags needed to have linker link only to necessary libraries
 AS_NEEDED_LDFLAGS = ${as_needed_ldflags}
 
 # Combined flags for compiling and linking against all of the above
 # Flags needed to have linker link only to necessary libraries
 AS_NEEDED_LDFLAGS = ${as_needed_ldflags}
 
 # Combined flags for compiling and linking against all of the above
-CONFIGURE_CFLAGS = \$(TALLOC_CFLAGS) \$(LIBELF_CFLAGS) \$(GL_CFLAGS)
+CONFIGURE_CFLAGS = \$(TALLOC_CFLAGS) \$(LIBELF_CFLAGS) \$(GL_CFLAGS) \$(EGL_CFLAGS)
 CONFIGURE_LDFLAGS = \$(TALLOC_LDFLAGS) \$(LIBELF_LDFLAGS)
 EOF
 
 CONFIGURE_LDFLAGS = \$(TALLOC_LDFLAGS) \$(LIBELF_LDFLAGS)
 EOF
 
diff --git a/eglwrap.c b/eglwrap.c
new file mode 100644 (file)
index 0000000..aaa8cb7
--- /dev/null
+++ b/eglwrap.c
@@ -0,0 +1,61 @@
+/* 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.
+ */
+
+#include "fips.h"
+
+#include <EGL/egl.h>
+
+#include "dlwrap.h"
+#include "metrics.h"
+
+static void *
+eglwrap_lookup (char *name)
+{
+       const char *libegl_filename = "libEGL.so.1";
+       static void *libegl_handle = NULL;
+
+       if (! libegl_handle) {
+               libegl_handle = dlwrap_real_dlopen (libegl_filename, RTLD_NOW | RTLD_DEEPBIND);
+               if (! libegl_handle) {
+                       fprintf (stderr, "Error: Failed to dlopen %s\n",
+                                libegl_filename);
+                       exit (1);
+               }
+       }
+
+       return dlwrap_real_dlsym (libegl_handle, name);
+}
+
+EGLBoolean
+eglSwapBuffers (EGLDisplay dpy, EGLSurface surface)
+{
+       EGLBoolean ret;
+       static typeof(&eglSwapBuffers) real_eglSwapBuffers;
+
+       if (! real_eglSwapBuffers)
+               real_eglSwapBuffers = eglwrap_lookup ("eglSwapBuffers");
+
+       ret = real_eglSwapBuffers (dpy, surface);
+
+       metrics_end_frame ();
+
+       return ret;
+}
index 885f679c860bed17b0004c89e27986bb21515742..d7670a79a28a1e3bf90bc3b6cc8b53d08bb1f486 100644 (file)
--- a/glxwrap.c
+++ b/glxwrap.c
 #include <GL/glx.h>
 
 #include "dlwrap.h"
 #include <GL/glx.h>
 
 #include "dlwrap.h"
-
 #include "glwrap.h"
 #include "glwrap.h"
+#include "metrics.h"
 
 void
 glXSwapBuffers (Display *dpy, GLXDrawable drawable)
 {
        GLWRAP_DEFER (glXSwapBuffers, dpy, drawable);
 
 
 void
 glXSwapBuffers (Display *dpy, GLXDrawable drawable)
 {
        GLWRAP_DEFER (glXSwapBuffers, dpy, drawable);
 
-       glwrap_end_frame ();
+       metrics_end_frame ();
 }
 
 
 }
 
 
index 65567cfa4c22291c50cc3c094c1c0d796f176c19..15342a555c4c60646941f231c9de3efe0521d9ea 100644 (file)
@@ -35,6 +35,7 @@ global:
        glUseProgramObjectARB;
        glXSwapBuffers;
        glXGetProcAddressARB;
        glUseProgramObjectARB;
        glXSwapBuffers;
        glXGetProcAddressARB;
+       eglSwapBuffers;
 local:
        *;
 };
 local:
        *;
 };