From: Chia-I Wu Date: Wed, 2 Nov 2011 10:11:53 +0000 (+0800) Subject: egl: add EGL tracer X-Git-Tag: 2.0_alpha^2~504 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=42fb3e489fc3468c8748fefd3bc65e5e8866e7c5;p=tools%2Fapitrace.git egl: add EGL tracer 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, --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e0fc01..5462a5b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,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 () @@ -426,6 +432,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 ' + print '#include ' + print '#include ' + 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 @@ -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) {