]> git.cworth.org Git - apitrace/blob - egltrace.py
TODO: Fix typo in the description of the range specification.
[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 specs.glesapi import glesapi
39 from gltrace import GlTracer
40 from dispatch import function_pointer_type, function_pointer_value
41
42
43 class EglTracer(GlTracer):
44
45     def is_public_function(self, function):
46         # The symbols visible in libEGL.so can vary, so expose them all
47         return True
48
49     def trace_function_impl_body(self, function):
50         GlTracer.trace_function_impl_body(self, function)
51
52         # Take snapshots
53         if function.name == 'eglSwapBuffers':
54             print '    glsnapshot::snapshot(__call);'
55         if function.name in ('glFinish', 'glFlush'):
56             print '    tracer_context *ctx = __get_context();'
57             print '    GLint __draw_framebuffer = 0;'
58             print '    __glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &__draw_framebuffer);'
59             print '    if (__draw_framebuffer == 0 && ctx->profile == PROFILE_COMPAT) {'
60             print '        GLint __draw_buffer = GL_NONE;'
61             print '        __glGetIntegerv(GL_DRAW_BUFFER, &__draw_buffer);'
62             print '        if (__draw_buffer == GL_FRONT) {'
63             print '             glsnapshot::snapshot(__call);'
64             print '        }'
65             print '    }'
66         if function.name == 'eglMakeCurrent':
67             print '    // update the profile'
68             print '    if (ctx != EGL_NO_CONTEXT) {'
69             print '        EGLint api = EGL_OPENGL_ES_API, version = 1;'
70             print '        tracer_context *tr = __get_context();'
71             print '        __eglQueryContext(dpy, ctx, EGL_CONTEXT_CLIENT_TYPE, &api);'
72             print '        __eglQueryContext(dpy, ctx, EGL_CONTEXT_CLIENT_VERSION, &version);'
73             print '        if (api == EGL_OPENGL_API)'
74             print '            tr->profile = PROFILE_COMPAT;'
75             print '        else if (version == 1)'
76             print '            tr->profile = PROFILE_ES1;'
77             print '        else'
78             print '            tr->profile = PROFILE_ES2;'
79             print '    }'
80
81     def wrap_ret(self, function, instance):
82         GlTracer.wrap_ret(self, function, instance)
83
84         if function.name == "eglGetProcAddress":
85             print '    %s = __unwrap_proc_addr(procname, %s);' % (instance, instance)
86
87
88 if __name__ == '__main__':
89     print '#include <stdlib.h>'
90     print '#include <string.h>'
91     print '#include <dlfcn.h>'
92     print
93     print '#include "trace_writer.hpp"'
94     print
95     print '// To validate our prototypes'
96     print '#define GL_GLEXT_PROTOTYPES'
97     print '#define EGL_EGLEXT_PROTOTYPES'
98     print
99     print '#include "glproc.hpp"'
100     print '#include "glsize.hpp"'
101     print '#include "glsnapshot.hpp"'
102     print
103     print 'static __eglMustCastToProperFunctionPointerType __unwrap_proc_addr(const char * procname, __eglMustCastToProperFunctionPointerType procPtr);'
104     print
105
106     api = API()
107     api.add_api(eglapi)
108     api.add_api(glapi)
109     api.add_api(glesapi)
110     tracer = EglTracer()
111     tracer.trace_api(api)
112
113     print 'static __eglMustCastToProperFunctionPointerType __unwrap_proc_addr(const char * procname, __eglMustCastToProperFunctionPointerType procPtr) {'
114     print '    if (!procPtr) {'
115     print '        return procPtr;'
116     print '    }'
117     for f in api.functions:
118         ptype = function_pointer_type(f)
119         pvalue = function_pointer_value(f)
120         print '    if (!strcmp("%s", procname)) {' % f.name
121         print '        %s = (%s)procPtr;' % (pvalue, ptype)
122         print '        return (__eglMustCastToProperFunctionPointerType)&%s;' % (f.name,)
123         print '    }'
124     print '    os::log("apitrace: warning: unknown function \\"%s\\"\\n", procname);'
125     print '    return procPtr;'
126     print '}'
127     print
128     print r'''
129
130 /*
131  * Lookup a EGL or GLES symbol
132  */
133 void * __libegl_sym(const char *symbol, bool pub)
134 {
135     void *proc;
136
137     /*
138      * Public symbols are EGL core functions and those defined in dekstop GL
139      * ABI.  Troubles come from the latter.
140      */
141     if (pub) {
142         proc = dlsym(RTLD_NEXT, symbol);
143         if (!proc && symbol[0] == 'g' && symbol[1] == 'l')
144             proc = (void *) __eglGetProcAddress(symbol);
145     }
146     else {
147         proc = (void *) __eglGetProcAddress(symbol);
148         if (!proc && symbol[0] == 'g' && symbol[1] == 'l')
149             proc = dlsym(RTLD_NEXT, symbol);
150     }
151
152     return proc;
153 }
154 '''