1 ##########################################################################
3 # Copyright 2011 LunarG, Inc.
6 # Based on glxtrace.py, which has
8 # Copyright 2011 Jose Fonseca
9 # Copyright 2008-2010 VMware, Inc.
11 # Permission is hereby granted, free of charge, to any person obtaining a copy
12 # of this software and associated documentation files (the "Software"), to deal
13 # in the Software without restriction, including without limitation the rights
14 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 # copies of the Software, and to permit persons to whom the Software is
16 # furnished to do so, subject to the following conditions:
18 # The above copyright notice and this permission notice shall be included in
19 # all copies or substantial portions of the Software.
21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 ##########################################################################/
32 """EGL tracing generator."""
35 from specs.stdapi import API
36 from specs.glapi import glapi
37 from specs.eglapi import eglapi
38 from gltrace import GlTracer
39 from dispatch import function_pointer_type, function_pointer_value
42 class EglTracer(GlTracer):
44 def is_public_function(self, function):
45 # The symbols visible in libEGL.so can vary, so expose them all
48 def trace_function_impl_body(self, function):
49 GlTracer.trace_function_impl_body(self, function)
52 if function.name == 'eglSwapBuffers':
53 print ' glsnapshot::snapshot(__call);'
54 if function.name in ('glFinish', 'glFlush'):
55 print ' GLint __draw_framebuffer = 0;'
56 print ' __glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &__draw_framebuffer);'
57 print ' if (__draw_framebuffer == 0) {'
58 print ' GLint __draw_buffer = GL_NONE;'
59 print ' __glGetIntegerv(GL_DRAW_BUFFER, &__draw_buffer);'
60 print ' if (__draw_buffer == GL_FRONT) {'
61 print ' glsnapshot::snapshot(__call);'
65 def wrap_ret(self, function, instance):
66 GlTracer.wrap_ret(self, function, instance)
68 if function.name == "eglGetProcAddress":
69 print ' %s = __unwrap_proc_addr(procname, %s);' % (instance, instance)
72 if __name__ == '__main__':
73 print '#include <stdlib.h>'
74 print '#include <string.h>'
75 print '#include <dlfcn.h>'
77 print '#include "trace_writer.hpp"'
79 print '// To validate our prototypes'
80 print '#define GL_GLEXT_PROTOTYPES'
81 print '#define EGL_EGLEXT_PROTOTYPES'
83 print '#include "glproc.hpp"'
84 print '#include "glsize.hpp"'
85 print '#include "glsnapshot.hpp"'
87 print 'static __eglMustCastToProperFunctionPointerType __unwrap_proc_addr(const char * procname, __eglMustCastToProperFunctionPointerType procPtr);'
96 print 'static __eglMustCastToProperFunctionPointerType __unwrap_proc_addr(const char * procname, __eglMustCastToProperFunctionPointerType procPtr) {'
97 print ' if (!procPtr) {'
98 print ' return procPtr;'
100 for f in api.functions:
101 ptype = function_pointer_type(f)
102 pvalue = function_pointer_value(f)
103 print ' if (!strcmp("%s", procname)) {' % f.name
104 print ' %s = (%s)procPtr;' % (pvalue, ptype)
105 print ' return (__eglMustCastToProperFunctionPointerType)&%s;' % (f.name,)
107 print ' os::log("apitrace: warning: unknown function \\"%s\\"\\n", procname);'
108 print ' return procPtr;'
114 * Lookup a EGL or GLES symbol
116 void * __libegl_sym(const char *symbol, bool pub)
121 * Public symbols are EGL core functions and those defined in dekstop GL
122 * ABI. Troubles come from the latter.
125 proc = dlsym(RTLD_NEXT, symbol);
126 if (!proc && symbol[0] == 'g' && symbol[1] == 'l')
127 proc = (void *) __eglGetProcAddress(symbol);
130 proc = (void *) __eglGetProcAddress(symbol);
131 if (!proc && symbol[0] == 'g' && symbol[1] == 'l')
132 proc = dlsym(RTLD_NEXT, symbol);