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 gltrace import GlTracer
36 from specs.stdapi import API
37 from specs.glapi import glapi
38 from specs.eglapi import eglapi
39 from specs.glesapi import glesapi
42 class EglTracer(GlTracer):
44 def isFunctionPublic(self, function):
45 # The symbols visible in libEGL.so can vary, so expose them all
48 getProcAddressFunctionNames = [
52 def traceFunctionImplBody(self, function):
53 GlTracer.traceFunctionImplBody(self, function)
55 if function.name == 'eglCreateContext':
56 print ' if (_result != EGL_NO_CONTEXT)'
57 print ' gltrace::createContext((uintptr_t)_result);'
59 if function.name == 'eglMakeCurrent':
60 print ' if (_result) {'
61 print ' // update the profile'
62 print ' if (ctx != EGL_NO_CONTEXT) {'
63 print ' EGLint api = EGL_OPENGL_ES_API, version = 1;'
64 print ' gltrace::setContext((uintptr_t)ctx);'
65 print ' gltrace::Context *tr = gltrace::getContext();'
66 print ' _eglQueryContext(dpy, ctx, EGL_CONTEXT_CLIENT_TYPE, &api);'
67 print ' _eglQueryContext(dpy, ctx, EGL_CONTEXT_CLIENT_VERSION, &version);'
68 print ' if (api == EGL_OPENGL_API)'
69 print ' tr->profile = gltrace::PROFILE_COMPAT;'
70 print ' else if (version == 1)'
71 print ' tr->profile = gltrace::PROFILE_ES1;'
73 print ' tr->profile = gltrace::PROFILE_ES2;'
75 print ' gltrace::clearContext();'
79 if function.name == 'eglDestroyContext':
81 print ' gltrace::destroyContext((uintptr_t)ctx);'
83 if __name__ == '__main__':
84 print '#include <stdlib.h>'
85 print '#include <string.h>'
86 print '#include <dlfcn.h>'
88 print '#include "trace_writer_local.hpp"'
90 print '// To validate our prototypes'
91 print '#define GL_GLEXT_PROTOTYPES'
92 print '#define EGL_EGLEXT_PROTOTYPES'
94 print '#include "glproc.hpp"'
95 print '#include "glsize.hpp"'
109 * Android does not support LD_PRELOAD.
111 #if !defined(ANDROID)
115 * Invoke the true dlopen() function.
117 static void *_dlopen(const char *filename, int flag)
119 typedef void * (*PFN_DLOPEN)(const char *, int);
120 static PFN_DLOPEN dlopen_ptr = NULL;
123 dlopen_ptr = (PFN_DLOPEN)dlsym(RTLD_NEXT, "dlopen");
125 os::log("apitrace: error: dlsym(RTLD_NEXT, \"dlopen\") failed\n");
130 return dlopen_ptr(filename, flag);
135 * Several applications, such as Quake3, use dlopen("libGL.so.1"), but
136 * LD_PRELOAD does not intercept symbols obtained via dlopen/dlsym, therefore
137 * we need to intercept the dlopen() call here, and redirect to our wrapper
141 void * dlopen(const char *filename, int flag)
143 bool intercept = false;
147 strcmp(filename, "libEGL.so") == 0 ||
148 strcmp(filename, "libEGL.so.1") == 0 ||
149 strcmp(filename, "libGLESv1_CM.so") == 0 ||
150 strcmp(filename, "libGLESv1_CM.so.1") == 0 ||
151 strcmp(filename, "libGLESv2.so") == 0 ||
152 strcmp(filename, "libGLESv2.so.2") == 0 ||
153 strcmp(filename, "libGL.so") == 0 ||
154 strcmp(filename, "libGL.so.1") == 0;
157 os::log("apitrace: redirecting dlopen(\"%s\", 0x%x)\n", filename, flag);
159 /* The current dispatch implementation relies on core entry-points to be globally available, so force this.
161 * TODO: A better approach would be note down the entry points here and
162 * use them latter. Another alternative would be to reopen the library
163 * with RTLD_NOLOAD | RTLD_GLOBAL.
170 void *handle = _dlopen(filename, flag);
173 // Get the file path for our shared object, and use it instead
174 static int dummy = 0xdeedbeef;
176 if (dladdr(&dummy, &info)) {
177 handle = _dlopen(info.dli_fname, flag);
179 os::log("apitrace: warning: dladdr() failed\n");
187 #endif /* !ANDROID */
193 * Undocumented Android extensions used by Dalvik which have bound information
194 * passed to it, but is currently ignored, so probably unreliable.
197 * https://github.com/android/platform_frameworks_base/blob/master/opengl/libs/GLES_CM/gl.cpp
201 void APIENTRY glColorPointerBounds(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer, GLsizei count) {
203 glColorPointer(size, type, stride, pointer);
207 void APIENTRY glNormalPointerBounds(GLenum type, GLsizei stride, const GLvoid * pointer, GLsizei count) {
209 glNormalPointer(type, stride, pointer);
213 void APIENTRY glTexCoordPointerBounds(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer, GLsizei count) {
215 glTexCoordPointer(size, type, stride, pointer);
219 void APIENTRY glVertexPointerBounds(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer, GLsizei count) {
221 glVertexPointer(size, type, stride, pointer);
225 void GL_APIENTRY glPointSizePointerOESBounds(GLenum type, GLsizei stride, const GLvoid *pointer, GLsizei count) {
227 glPointSizePointerOES(type, stride, pointer);
231 void APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLsizei count) {
233 glMatrixIndexPointerOES(size, type, stride, pointer);
237 void APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLsizei count) {
239 glWeightPointerOES(size, type, stride, pointer);
243 * There is also a glVertexAttribPointerBounds in
244 * https://github.com/android/platform_frameworks_base/blob/master/opengl/tools/glgen/stubs/gles11/GLES20cHeader.cpp
245 * but is it not exported.