[PATCH 6/7] egl: add EGL tracer

Chia-I Wu olvaffe at gmail.com
Thu Nov 3 03:56:58 PDT 2011


This tracer supports EGL/OpenGL applications for now.  Support for GLES is
missing, but can be added later.  There are two new macros defined.  HAVE_EGL
indicates that the system has EGL available.  It will make eglimports.h
include EGL headers.

There is also TRACE_EGL.  It indicates that EGL, instead of the OS-dependent
GLX/CGL/WGL, is the winsys API to trace,
---
 CMakeLists.txt |   43 +++++++++++++++++
 egltrace.py    |  137 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 glsnapshot.cpp |    9 +++-
 3 files changed, 187 insertions(+), 2 deletions(-)
 create mode 100644 egltrace.py

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5c59351..7712140 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,6 +46,12 @@ else ()
     set (X11_GL_LIB ${OPENGL_gl_LIBRARY})
 
     include_directories (${X11_INCLUDE_DIR})
+
+    pkg_check_modules (EGL egl)
+    if (EGL_FOUND)
+        include_directories (${EGL_INCLUDE_DIR})
+        add_definitions (-DHAVE_EGL)
+    endif ()
 endif ()
 
 
@@ -418,6 +424,43 @@ else ()
 endif ()
 
 
+if (EGL_FOUND)
+    # libEGL.so/libGL.so
+    add_custom_command (
+        OUTPUT egltrace.cpp
+        COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/egltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/egltrace.cpp
+        DEPENDS egltrace.py gltrace.py trace.py specs/eglapi.py specs/glapi.py specs/glparams.py specs/gltypes.py specs/stdapi.py
+    )
+
+    add_library (egltrace SHARED
+        ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
+        egltrace.cpp
+        glcaps.cpp
+        glsnapshot.cpp
+    )
+
+    set_property (
+        TARGET egltrace
+        APPEND
+        PROPERTY COMPILE_DEFINITIONS "TRACE_EGL"
+    )
+
+    set_target_properties (egltrace PROPERTIES
+        # avoid the default "lib" prefix
+        PREFIX ""
+    )
+
+    # Prevent symbol relocations internal to our wrapper library to be
+    # overwritten by the application.
+    set_target_properties (egltrace PROPERTIES
+        LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
+    )
+
+    target_link_libraries (egltrace dl)
+
+    install (TARGETS egltrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
+endif ()
+
 ##############################################################################
 # API retracers
 
diff --git a/egltrace.py b/egltrace.py
new file mode 100644
index 0000000..64e5191
--- /dev/null
+++ b/egltrace.py
@@ -0,0 +1,137 @@
+##########################################################################
+#
+# Copyright 2011 LunarG, Inc.
+# All Rights Reserved.
+#
+# Based on glxtrace.py, which has
+#
+#   Copyright 2011 Jose Fonseca
+#   Copyright 2008-2010 VMware, Inc.
+#
+# 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.
+#
+##########################################################################/
+
+
+"""EGL tracing generator."""
+
+
+from specs.stdapi import API
+from specs.glapi import glapi
+from specs.eglapi import eglapi
+from gltrace import GlTracer
+from dispatch import function_pointer_type, function_pointer_value
+
+
+class EglTracer(GlTracer):
+
+    def is_public_function(self, function):
+        # The symbols visible in libEGL.so can vary, so expose them all
+        return True
+
+    def trace_function_impl_body(self, function):
+        GlTracer.trace_function_impl_body(self, function)
+
+        # Take snapshots
+        if function.name == 'eglSwapBuffers':
+            print '    glsnapshot::snapshot(__call);'
+        if function.name in ('glFinish', 'glFlush'):
+            print '    GLint __draw_framebuffer = 0;'
+            print '    __glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &__draw_framebuffer);'
+            print '    if (__draw_framebuffer == 0) {'
+            print '        GLint __draw_buffer = GL_NONE;'
+            print '        __glGetIntegerv(GL_DRAW_BUFFER, &__draw_buffer);'
+            print '        if (__draw_buffer == GL_FRONT) {'
+            print '             glsnapshot::snapshot(__call);'
+            print '        }'
+            print '    }'
+
+    def wrap_ret(self, function, instance):
+        GlTracer.wrap_ret(self, function, instance)
+
+        if function.name == "eglGetProcAddress":
+            print '    %s = __unwrap_proc_addr(procname, %s);' % (instance, instance)
+
+
+if __name__ == '__main__':
+    print '#include <stdlib.h>'
+    print '#include <string.h>'
+    print '#include <dlfcn.h>'
+    print
+    print '#include "trace_writer.hpp"'
+    print
+    print '// To validate our prototypes'
+    print '#define GL_GLEXT_PROTOTYPES'
+    print '#define EGL_EGLEXT_PROTOTYPES'
+    print
+    print '#include "glproc.hpp"'
+    print '#include "glsize.hpp"'
+    print '#include "glsnapshot.hpp"'
+    print
+    print 'static __eglMustCastToProperFunctionPointerType __unwrap_proc_addr(const char * procname, __eglMustCastToProperFunctionPointerType procPtr);'
+    print
+
+    api = API()
+    api.add_api(eglapi)
+    api.add_api(glapi)
+    tracer = EglTracer()
+    tracer.trace_api(api)
+
+    print 'static __eglMustCastToProperFunctionPointerType __unwrap_proc_addr(const char * procname, __eglMustCastToProperFunctionPointerType procPtr) {'
+    print '    if (!procPtr) {'
+    print '        return procPtr;'
+    print '    }'
+    for f in api.functions:
+        ptype = function_pointer_type(f)
+        pvalue = function_pointer_value(f)
+        print '    if (!strcmp("%s", procname)) {' % f.name
+        print '        %s = (%s)procPtr;' % (pvalue, ptype)
+        print '        return (__eglMustCastToProperFunctionPointerType)&%s;' % (f.name,)
+        print '    }'
+    print '    os::log("apitrace: warning: unknown function \\"%s\\"\\n", procname);'
+    print '    return procPtr;'
+    print '}'
+    print
+    print r'''
+
+/*
+ * Lookup a EGL or GLES symbol
+ */
+void * __libegl_sym(const char *symbol, bool pub)
+{
+    void *proc;
+
+    /*
+     * Public symbols are EGL core functions and those defined in dekstop GL
+     * ABI.  Troubles come from the latter.
+     */
+    if (pub) {
+        proc = dlsym(RTLD_NEXT, symbol);
+        if (!proc && symbol[0] == 'g' && symbol[1] == 'l')
+            proc = (void *) __eglGetProcAddress(symbol);
+    }
+    else {
+        proc = (void *) __eglGetProcAddress(symbol);
+        if (!proc && symbol[0] == 'g' && symbol[1] == 'l')
+            proc = dlsym(RTLD_NEXT, symbol);
+    }
+
+    return proc;
+}
+'''
diff --git a/glsnapshot.cpp b/glsnapshot.cpp
index 97bf77e..e37fbcc 100644
--- a/glsnapshot.cpp
+++ b/glsnapshot.cpp
@@ -33,7 +33,7 @@
 #include "glsize.hpp"
 
 
-#if !defined(_WIN32) && !defined(__APPLE__)
+#if !defined(TRACE_EGL) && !defined(_WIN32) && !defined(__APPLE__)
 
 
 #include <X11/Xproto.h>
@@ -66,7 +66,12 @@ namespace glsnapshot {
  */
 static image::Image *
 getDrawableImage(void) {
-#if defined(_WIN32)
+#if defined(TRACE_EGL)
+
+    // TODO
+    return NULL;
+
+#elif defined(_WIN32)
 
     HDC hDC = __wglGetCurrentDC();
     if (!hDC) {
-- 
1.7.6.3



More information about the apitrace mailing list