From 2cfa02c89ce8779e328aecdcc4eeecce6c9a2dbf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Mon, 10 Jun 2013 08:05:29 +0100 Subject: [PATCH] gltrace: Expose marker functions when tracing is disabled. Matches the output of change proposed by Peter Lohrmann in issue #138, but with slightly less new code. This is achieved by adding a new hook point, doInvokeFunction (could not think of a better name), used to generate the call to the real function, both when trace is enabled or disabled. --- wrappers/gltrace.py | 35 +++++++++++++++++++++++------------ wrappers/trace.py | 8 ++++++-- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/wrappers/gltrace.py b/wrappers/gltrace.py index e9169ce..e73c591 100644 --- a/wrappers/gltrace.py +++ b/wrappers/gltrace.py @@ -700,12 +700,24 @@ class GlTracer(Tracer): # These functions have been dispatched already return + Tracer.invokeFunction(self, function) + + def doInvokeFunction(self, function): + # Same as invokeFunction() but called both when trace is enabled or disabled. + # + # Used to modify the behavior of GL entry-points. + + # Override GL extensions + if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'): + Tracer.doInvokeFunction(self, function, prefix = 'gltrace::_', suffix = '_override') + return + # We implement GL_EXT_debug_marker, GL_GREMEDY_*, etc., and not the # driver if function.name in self.marker_functions: return - if function.name in ('glXGetProcAddress', 'glXGetProcAddressARB', 'wglGetProcAddress'): + if function.name in self.getProcAddressFunctionNames: else_ = '' for marker_function in self.marker_functions: if self.api.getFunctionByName(marker_function): @@ -714,16 +726,19 @@ class GlTracer(Tracer): print ' }' else_ = 'else ' print ' %s{' % else_ - Tracer.invokeFunction(self, function) - print ' }' - return + Tracer.doInvokeFunction(self, function) - # Override GL extensions - if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'): - Tracer.invokeFunction(self, function, prefix = 'gltrace::_', suffix = '_override') + # Replace function addresses with ours + # XXX: Doing this here instead of wrapRet means that the trace will + # contain the addresses of the wrapper functions, and not the real + # functions, but in practice this should make no difference. + if function.name in self.getProcAddressFunctionNames: + print ' _result = _wrapProcAddress(%s, _result);' % (function.args[0].name,) + + print ' }' return - Tracer.invokeFunction(self, function) + Tracer.doInvokeFunction(self, function) buffer_targets = [ 'ARRAY_BUFFER', @@ -742,10 +757,6 @@ class GlTracer(Tracer): def wrapRet(self, function, instance): Tracer.wrapRet(self, function, instance) - # Replace function addresses with ours - if function.name in self.getProcAddressFunctionNames: - print ' %s = _wrapProcAddress(%s, %s);' % (instance, function.args[0].name, instance) - # Keep track of buffer mappings if function.name in ('glMapBuffer', 'glMapBufferARB'): print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' diff --git a/wrappers/trace.py b/wrappers/trace.py index 4abd20e..31087e9 100644 --- a/wrappers/trace.py +++ b/wrappers/trace.py @@ -474,7 +474,7 @@ class Tracer: # No-op if tracing is disabled print ' if (!trace::isTracingEnabled()) {' - Tracer.invokeFunction(self, function) + self.doInvokeFunction(function) if function.type is not stdapi.Void: print ' return _result;' else: @@ -512,7 +512,11 @@ class Tracer: self.wrapRet(function, "_result") print ' trace::localWriter.endLeave();' - def invokeFunction(self, function, prefix='_', suffix=''): + def invokeFunction(self, function): + self.doInvokeFunction(function) + + def doInvokeFunction(self, function, prefix='_', suffix=''): + # Same as invokeFunction() but called both when trace is enabled or disabled. if function.type is stdapi.Void: result = '' else: -- 2.43.0