[PATCH v3 03/18] mt trace: cgl: track GL context on a per-thread basis

Imre Deak imre.deak at intel.com
Wed May 23 02:05:17 PDT 2012


Wrap CGL context handling calls and keep our own per-thread basis track
of the context object.

Signed-off-by: Imre Deak <imre.deak at intel.com>
---
 wrappers/cgltrace.py |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/wrappers/cgltrace.py b/wrappers/cgltrace.py
index e9dee97..9dd3253 100644
--- a/wrappers/cgltrace.py
+++ b/wrappers/cgltrace.py
@@ -39,6 +39,39 @@ class CglTracer(GlTracer):
         # all OpenGL symbols are visible on MacOSX
         return True
 
+    def traceFunctionImplBody(self, function):
+        GlTracer.traceFunctionImplBody(self, function)
+
+        if function.name == 'CGLCreateContext':
+            print '    if (_result == kCGLNoError)'
+            print '        gltrace::createContext((uintptr_t)*ctx);'
+
+        if function.name == 'CGLSetCurrentContext':
+            print '    if (_result == kCGLNoError) {'
+            print '        if (ctx != NULL)'
+            print '            gltrace::setContext((uintptr_t)ctx);'
+            print '        else'
+            print '            gltrace::clearContext();'
+            print '    }'
+
+        if function.name == 'CGLRetainContext':
+            print '    gltrace::retainContext((uintptr_t)ctx);'
+
+        if function.name == 'CGLReleaseContext':
+            # Unlike other GL APIs like EGL or GLX, CGL will make the context
+            # not current if it's the current context.
+            print '    if (gltrace::releaseContext((uintptr_t)ctx)) {'
+            print '        if ((uintptr_t)ctx == gltrace::getContext())'
+            print '            gltrace::clearContext();'
+            print '    }'
+
+        if function.name == 'CGLDestroyContext':
+            # The same rule applies here about the  as for CGLReleaseContext.
+            print '    if (gltrace::destroyContext((uintptr_t)ctx)) {'
+            print '        if ((uintptr_t)ctx == gltrace::getContext())'
+            print '            gltrace::clearContext();'
+            print '    }'
+
 
 if __name__ == '__main__':
     print
-- 
1.7.5.4



More information about the apitrace mailing list