]> git.cworth.org Git - apitrace/blobdiff - wrappers/egltrace.py
egl: EGL image trace support
[apitrace] / wrappers / egltrace.py
index 4972528fe0e09ed21ff35307696824d0864215cb..505ca797442c4f354847d0394ef47ec7bf4c4a0e 100644 (file)
@@ -52,21 +52,55 @@ class EglTracer(GlTracer):
     def traceFunctionImplBody(self, function):
         GlTracer.traceFunctionImplBody(self, function)
 
+        if function.name == 'eglCreateContext':
+            print '    if (_result != EGL_NO_CONTEXT)'
+            print '        gltrace::createContext((uintptr_t)_result);'
+
         if function.name == 'eglMakeCurrent':
-            print '    // update the profile'
-            print '    if (ctx != EGL_NO_CONTEXT) {'
-            print '        EGLint api = EGL_OPENGL_ES_API, version = 1;'
-            print '        gltrace::Context *tr = gltrace::getContext();'
-            print '        __eglQueryContext(dpy, ctx, EGL_CONTEXT_CLIENT_TYPE, &api);'
-            print '        __eglQueryContext(dpy, ctx, EGL_CONTEXT_CLIENT_VERSION, &version);'
-            print '        if (api == EGL_OPENGL_API)'
-            print '            tr->profile = gltrace::PROFILE_COMPAT;'
-            print '        else if (version == 1)'
-            print '            tr->profile = gltrace::PROFILE_ES1;'
-            print '        else'
-            print '            tr->profile = gltrace::PROFILE_ES2;'
+            print '    if (_result) {'
+            print '        // update the profile'
+            print '        if (ctx != EGL_NO_CONTEXT) {'
+            print '            EGLint api = EGL_OPENGL_ES_API, version = 1;'
+            print '            gltrace::setContext((uintptr_t)ctx);'
+            print '            gltrace::Context *tr = gltrace::getContext();'
+            print '            _eglQueryContext(dpy, ctx, EGL_CONTEXT_CLIENT_TYPE, &api);'
+            print '            _eglQueryContext(dpy, ctx, EGL_CONTEXT_CLIENT_VERSION, &version);'
+            print '            if (api == EGL_OPENGL_API)'
+            print '                tr->profile = gltrace::PROFILE_COMPAT;'
+            print '            else if (version == 1)'
+            print '                tr->profile = gltrace::PROFILE_ES1;'
+            print '            else'
+            print '                tr->profile = gltrace::PROFILE_ES2;'
+            print '        } else {'
+            print '            gltrace::clearContext();'
+            print '        }'
+            print '    }'
+
+        if function.name == 'eglDestroyContext':
+            print '    if (_result) {'
+            print '        gltrace::releaseContext((uintptr_t)ctx);'
             print '    }'
 
+        if function.name == 'eglCreateImageKHR':
+            print '    _eglCreateImageKHR_epilog(dpy, ctx, target, buffer,'
+            print '                              attrib_list, _result);'
+
+        if function.name == 'eglDestroyImageKHR':
+            print '    _eglDestroyImageKHR_epilog(image);'
+
+    def serializeArgValue(self, function, arg):
+        if function.name == 'glEGLImageTargetTexture2DOES' and \
+          arg.name == 'image':
+            print '    GLsizei blob_size;'
+            print '    GLvoid *blob_ptr;'
+            print '    blob_size = _glEGLImageTargetTexture2DOES_size(target, image);'
+            print '    blob_ptr = _glEGLImageTargetTexture2DOES_get_ptr(target, image);'
+            print '    trace::localWriter.writeBlob(blob_ptr, blob_size);'
+            print '    _glEGLImageTargetTexture2DOES_put_ptr(blob_ptr);'
+
+            return
+
+        GlTracer.serializeArgValue(self, function, arg)
 
 if __name__ == '__main__':
     print '#include <stdlib.h>'
@@ -81,6 +115,7 @@ if __name__ == '__main__':
     print
     print '#include "glproc.hpp"'
     print '#include "glsize.hpp"'
+    print '#include "eglsize.hpp"'
     print
     
     api = API()
@@ -102,13 +137,13 @@ if __name__ == '__main__':
 /*
  * Invoke the true dlopen() function.
  */
-static void *__dlopen(const char *filename, int flag)
+static void *_dlopen(const char *filename, int flag)
 {
-    typedef void * (*PFNDLOPEN)(const char *, int);
-    static PFNDLOPEN dlopen_ptr = NULL;
+    typedef void * (*PFN_DLOPEN)(const char *, int);
+    static PFN_DLOPEN dlopen_ptr = NULL;
 
     if (!dlopen_ptr) {
-        dlopen_ptr = (PFNDLOPEN)dlsym(RTLD_NEXT, "dlopen");
+        dlopen_ptr = (PFN_DLOPEN)dlsym(RTLD_NEXT, "dlopen");
         if (!dlopen_ptr) {
             os::log("apitrace: error: dlsym(RTLD_NEXT, \"dlopen\") failed\n");
             return NULL;
@@ -155,14 +190,14 @@ void * dlopen(const char *filename, int flag)
         }
     }
 
-    void *handle = __dlopen(filename, flag);
+    void *handle = _dlopen(filename, flag);
 
     if (intercept) {
         // Get the file path for our shared object, and use it instead
         static int dummy = 0xdeedbeef;
         Dl_info info;
         if (dladdr(&dummy, &info)) {
-            handle = __dlopen(info.dli_fname, flag);
+            handle = _dlopen(info.dli_fname, flag);
         } else {
             os::log("apitrace: warning: dladdr() failed\n");
         }
@@ -175,5 +210,65 @@ void * dlopen(const char *filename, int flag)
 #endif /* !ANDROID */
 
 
+#if defined(ANDROID)
+
+/*
+ * Undocumented Android extensions used by Dalvik which have bound information
+ * passed to it, but is currently ignored, so probably unreliable.
+ *
+ * See:
+ * https://github.com/android/platform_frameworks_base/blob/master/opengl/libs/GLES_CM/gl.cpp
+ */
+
+extern "C" PUBLIC
+void APIENTRY glColorPointerBounds(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer, GLsizei count) {
+    (void)count;
+    glColorPointer(size, type, stride, pointer);
+}
+
+extern "C" PUBLIC
+void APIENTRY glNormalPointerBounds(GLenum type, GLsizei stride, const GLvoid * pointer, GLsizei count) {
+    (void)count;
+    glNormalPointer(type, stride, pointer);
+}
+
+extern "C" PUBLIC
+void APIENTRY glTexCoordPointerBounds(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer, GLsizei count) {
+    (void)count;
+    glTexCoordPointer(size, type, stride, pointer);
+}
+
+extern "C" PUBLIC
+void APIENTRY glVertexPointerBounds(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer, GLsizei count) {
+    (void)count;
+    glVertexPointer(size, type, stride, pointer);
+}
+
+extern "C" PUBLIC
+void GL_APIENTRY glPointSizePointerOESBounds(GLenum type, GLsizei stride, const GLvoid *pointer, GLsizei count) {
+    (void)count;
+    glPointSizePointerOES(type, stride, pointer);
+}
+
+extern "C" PUBLIC
+void APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLsizei count) {
+    (void)count;
+    glMatrixIndexPointerOES(size, type, stride, pointer);
+}
+
+extern "C" PUBLIC
+void APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLsizei count) {
+    (void)count;
+    glWeightPointerOES(size, type, stride, pointer);
+}
+
+/*
+ * There is also a glVertexAttribPointerBounds in
+ * https://github.com/android/platform_frameworks_base/blob/master/opengl/tools/glgen/stubs/gles11/GLES20cHeader.cpp
+ * but is it not exported.
+ */
+
+#endif /* ANDROID */
+
 
 '''