]> git.cworth.org Git - apitrace/blob - egltrace.py
Fix fetching of the data for uniform arrays.
[apitrace] / egltrace.py
1 ##########################################################################
2 #
3 # Copyright 2011 LunarG, Inc.
4 # All Rights Reserved.
5 #
6 # Based on glxtrace.py, which has
7 #
8 #   Copyright 2011 Jose Fonseca
9 #   Copyright 2008-2010 VMware, Inc.
10 #
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:
17 #
18 # The above copyright notice and this permission notice shall be included in
19 # all copies or substantial portions of the Software.
20 #
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
27 # THE SOFTWARE.
28 #
29 ##########################################################################/
30
31
32 """EGL tracing generator."""
33
34
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
40
41
42 class EglTracer(GlTracer):
43
44     def is_public_function(self, function):
45         # The symbols visible in libEGL.so can vary, so expose them all
46         return True
47
48     def trace_function_impl_body(self, function):
49         GlTracer.trace_function_impl_body(self, function)
50
51         # Take snapshots
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);'
62             print '        }'
63             print '    }'
64
65     def wrap_ret(self, function, instance):
66         GlTracer.wrap_ret(self, function, instance)
67
68         if function.name == "eglGetProcAddress":
69             print '    %s = __unwrap_proc_addr(procname, %s);' % (instance, instance)
70
71
72 if __name__ == '__main__':
73     print '#include <stdlib.h>'
74     print '#include <string.h>'
75     print '#include <dlfcn.h>'
76     print
77     print '#include "trace_writer.hpp"'
78     print
79     print '// To validate our prototypes'
80     print '#define GL_GLEXT_PROTOTYPES'
81     print '#define EGL_EGLEXT_PROTOTYPES'
82     print
83     print '#include "glproc.hpp"'
84     print '#include "glsize.hpp"'
85     print '#include "glsnapshot.hpp"'
86     print
87     print 'static __eglMustCastToProperFunctionPointerType __unwrap_proc_addr(const char * procname, __eglMustCastToProperFunctionPointerType procPtr);'
88     print
89
90     api = API()
91     api.add_api(eglapi)
92     api.add_api(glapi)
93     tracer = EglTracer()
94     tracer.trace_api(api)
95
96     print 'static __eglMustCastToProperFunctionPointerType __unwrap_proc_addr(const char * procname, __eglMustCastToProperFunctionPointerType procPtr) {'
97     print '    if (!procPtr) {'
98     print '        return procPtr;'
99     print '    }'
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,)
106         print '    }'
107     print '    os::log("apitrace: warning: unknown function \\"%s\\"\\n", procname);'
108     print '    return procPtr;'
109     print '}'
110     print
111     print r'''
112
113 /*
114  * Lookup a EGL or GLES symbol
115  */
116 void * __libegl_sym(const char *symbol, bool pub)
117 {
118     void *proc;
119
120     /*
121      * Public symbols are EGL core functions and those defined in dekstop GL
122      * ABI.  Troubles come from the latter.
123      */
124     if (pub) {
125         proc = dlsym(RTLD_NEXT, symbol);
126         if (!proc && symbol[0] == 'g' && symbol[1] == 'l')
127             proc = (void *) __eglGetProcAddress(symbol);
128     }
129     else {
130         proc = (void *) __eglGetProcAddress(symbol);
131         if (!proc && symbol[0] == 'g' && symbol[1] == 'l')
132             proc = dlsym(RTLD_NEXT, symbol);
133     }
134
135     return proc;
136 }
137 '''