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 specs.glesapi import glesapi
39 from gltrace import GlTracer
40 from dispatch import function_pointer_type, function_pointer_value
43 class EglTracer(GlTracer):
45 def is_public_function(self, function):
46 # The symbols visible in libEGL.so can vary, so expose them all
49 def trace_function_impl_body(self, function):
50 GlTracer.trace_function_impl_body(self, function)
52 if function.name == 'eglMakeCurrent':
53 print ' // update the profile'
54 print ' if (ctx != EGL_NO_CONTEXT) {'
55 print ' EGLint api = EGL_OPENGL_ES_API, version = 1;'
56 print ' tracer_context *tr = __get_context();'
57 print ' __eglQueryContext(dpy, ctx, EGL_CONTEXT_CLIENT_TYPE, &api);'
58 print ' __eglQueryContext(dpy, ctx, EGL_CONTEXT_CLIENT_VERSION, &version);'
59 print ' if (api == EGL_OPENGL_API)'
60 print ' tr->profile = PROFILE_COMPAT;'
61 print ' else if (version == 1)'
62 print ' tr->profile = PROFILE_ES1;'
64 print ' tr->profile = PROFILE_ES2;'
67 def wrap_ret(self, function, instance):
68 GlTracer.wrap_ret(self, function, instance)
70 if function.name == "eglGetProcAddress":
71 print ' %s = __unwrap_proc_addr(procname, %s);' % (instance, instance)
74 if __name__ == '__main__':
75 print '#include <stdlib.h>'
76 print '#include <string.h>'
77 print '#include <dlfcn.h>'
79 print '#include "trace_writer.hpp"'
81 print '// To validate our prototypes'
82 print '#define GL_GLEXT_PROTOTYPES'
83 print '#define EGL_EGLEXT_PROTOTYPES'
85 print '#include "glproc.hpp"'
86 print '#include "glsize.hpp"'
88 print 'static __eglMustCastToProperFunctionPointerType __unwrap_proc_addr(const char * procname, __eglMustCastToProperFunctionPointerType procPtr);'
98 print 'static __eglMustCastToProperFunctionPointerType __unwrap_proc_addr(const char * procname, __eglMustCastToProperFunctionPointerType procPtr) {'
99 print ' if (!procPtr) {'
100 print ' return procPtr;'
102 for f in api.functions:
103 ptype = function_pointer_type(f)
104 pvalue = function_pointer_value(f)
105 print ' if (!strcmp("%s", procname)) {' % f.name
106 print ' %s = (%s)procPtr;' % (pvalue, ptype)
107 print ' return (__eglMustCastToProperFunctionPointerType)&%s;' % (f.name,)
109 print ' os::log("apitrace: warning: unknown function \\"%s\\"\\n", procname);'
110 print ' return procPtr;'