Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Factor the proc address wrapping into gltrace.py

  • Loading branch information...
commit 1b6c87507810fe2d72c81fc109110c1ca25ce94f 1 parent 7e351da
@jrfonseca jrfonseca authored
View
2  specs/stdapi.py
@@ -837,7 +837,7 @@ def addApi(self, api):
self.addFunctions(api.functions)
self.addInterfaces(api.interfaces)
- def get_function_by_name(self, name):
+ def getFunctionByName(self, name):
for function in self.functions:
if function.name == name:
return function
View
6 wrappers/cgltrace.py
@@ -24,7 +24,7 @@
##########################################################################/
-"""Cgl tracing generator."""
+"""CGL tracing generator."""
from gltrace import GlTracer
@@ -36,7 +36,7 @@
class CglTracer(GlTracer):
def isFunctionPublic(self, function):
- # The symbols visible in libGL.dylib can vary, so expose them all
+ # all OpenGL symbols are visible on MacOSX
return True
@@ -58,7 +58,7 @@ def isFunctionPublic(self, function):
api.addApi(cglapi)
api.addApi(glapi)
tracer = CglTracer()
- tracer.trace_api(api)
+ tracer.traceApi(api)
print r'''
View
2  wrappers/d3d10_1trace.py
@@ -43,4 +43,4 @@
print '#include <d3dx10.h>'
print
tracer = DllTracer('d3d10_1.dll')
- tracer.trace_api(d3d10_1)
+ tracer.traceApi(d3d10_1)
View
2  wrappers/d3d10trace.py
@@ -43,4 +43,4 @@
print '#include <d3dx10.h>'
print
tracer = DllTracer('d3d10.dll')
- tracer.trace_api(d3d10)
+ tracer.traceApi(d3d10)
View
2  wrappers/d3d11trace.py
@@ -43,4 +43,4 @@
print '#include <d3dx11.h>'
print
tracer = DllTracer('d3d11.dll')
- tracer.trace_api(d3d11)
+ tracer.traceApi(d3d11)
View
2  wrappers/d3d8trace.py
@@ -50,5 +50,5 @@ def serializeArgValue(self, function, arg):
print '#include "os.hpp"'
print
tracer = D3D8Tracer('d3d8.dll')
- tracer.trace_api(d3d8)
+ tracer.traceApi(d3d8)
View
2  wrappers/d3d9trace.py
@@ -90,5 +90,5 @@ def implementWrapperInterfaceMethodBody(self, interface, base, method):
}
'''
tracer = D3D9Tracer('d3d9.dll')
- tracer.trace_api(d3d9)
+ tracer.traceApi(d3d9)
View
2  wrappers/ddrawtrace.py
@@ -67,4 +67,4 @@ def traceFunctionImplBody(self, function):
print '#include "os.hpp"'
print
tracer = DDrawTracer('ddraw.dll')
- tracer.trace_api(ddraw)
+ tracer.traceApi(ddraw)
View
34 wrappers/egltrace.py
@@ -33,7 +33,6 @@
from gltrace import GlTracer
-from dispatch import function_pointer_type, function_pointer_value
from specs.stdapi import API
from specs.glapi import glapi
from specs.eglapi import eglapi
@@ -46,6 +45,10 @@ def isFunctionPublic(self, function):
# The symbols visible in libEGL.so can vary, so expose them all
return True
+ getProcAddressFunctionNames = [
+ "eglGetProcAddress",
+ ]
+
def traceFunctionImplBody(self, function):
GlTracer.traceFunctionImplBody(self, function)
@@ -64,12 +67,6 @@ def traceFunctionImplBody(self, function):
print ' tr->profile = gltrace::PROFILE_ES2;'
print ' }'
- def wrapRet(self, function, instance):
- GlTracer.wrapRet(self, function, instance)
-
- if function.name == "eglGetProcAddress":
- print ' %s = __unwrap_proc_addr(procname, %s);' % (instance, instance)
-
if __name__ == '__main__':
print '#include <stdlib.h>'
@@ -85,31 +82,14 @@ def wrapRet(self, function, instance):
print '#include "glproc.hpp"'
print '#include "glsize.hpp"'
print
- print 'static __eglMustCastToProperFunctionPointerType __unwrap_proc_addr(const char * procname, __eglMustCastToProperFunctionPointerType procPtr);'
- print
-
+
api = API()
api.addApi(eglapi)
api.addApi(glapi)
api.addApi(glesapi)
tracer = EglTracer()
- tracer.trace_api(api)
-
- print 'static __eglMustCastToProperFunctionPointerType __unwrap_proc_addr(const char * procname, __eglMustCastToProperFunctionPointerType procPtr) {'
- print ' if (!procPtr) {'
- print ' return procPtr;'
- print ' }'
- for f in api.functions:
- ptype = function_pointer_type(f)
- pvalue = function_pointer_value(f)
- print ' if (!strcmp("%s", procname)) {' % f.name
- print ' %s = (%s)procPtr;' % (pvalue, ptype)
- print ' return (__eglMustCastToProperFunctionPointerType)&%s;' % (f.name,)
- print ' }'
- print ' os::log("apitrace: warning: unknown function \\"%s\\"\\n", procname);'
- print ' return procPtr;'
- print '}'
- print
+ tracer.traceApi(api)
+
print r'''
View
49 wrappers/gltrace.py
@@ -28,6 +28,7 @@
from trace import Tracer
+from dispatch import function_pointer_type, function_pointer_value
import specs.stdapi as stdapi
import specs.glapi as glapi
import specs.glparams as glparams
@@ -324,6 +325,38 @@ def header(self, api):
print '}'
print
+ getProcAddressFunctionNames = []
+
+ def traceApi(self, api):
+ if self.getProcAddressFunctionNames:
+ # Generate a function to wrap proc addresses
+ getProcAddressFunction = api.getFunctionByName(self.getProcAddressFunctionNames[0])
+ argType = getProcAddressFunction.args[0].type
+ retType = getProcAddressFunction.type
+
+ print 'static %s _wrapProcAddress(%s procName, %s procPtr);' % (retType, argType, retType)
+ print
+
+ Tracer.traceApi(self, api)
+
+ print 'static %s _wrapProcAddress(%s procName, %s procPtr) {' % (retType, argType, retType)
+ print ' if (!procPtr) {'
+ print ' return procPtr;'
+ print ' }'
+ for function in api.functions:
+ ptype = function_pointer_type(function)
+ pvalue = function_pointer_value(function)
+ print ' if (strcmp("%s", (const char *)procName) == 0) {' % function.name
+ print ' %s = (%s)procPtr;' % (pvalue, ptype)
+ print ' return (%s)&%s;' % (retType, function.name,)
+ print ' }'
+ print ' os::log("apitrace: warning: unknown function \\"%s\\"\\n", (const char *)procName);'
+ print ' return procPtr;'
+ print '}'
+ print
+ else:
+ Tracer.traceApi(self, api)
+
array_pointer_function_names = set((
"glVertexPointer",
"glNormalPointer",
@@ -583,7 +616,7 @@ def traceFunctionImplBody(self, function):
print " if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {"
print ' GLint location = __glGetAttribLocation(program, name);'
print ' if (location >= 0) {'
- bind_function = glapi.glapi.get_function_by_name('glBindAttribLocation')
+ bind_function = glapi.glapi.getFunctionByName('glBindAttribLocation')
self.fake_call(bind_function, ['program', 'location', 'name'])
print ' }'
print ' }'
@@ -601,7 +634,7 @@ def traceFunctionImplBody(self, function):
print " if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {"
print ' GLint location = __glGetAttribLocationARB(programObj, name);'
print ' if (location >= 0) {'
- bind_function = glapi.glapi.get_function_by_name('glBindAttribLocationARB')
+ bind_function = glapi.glapi.getFunctionByName('glBindAttribLocationARB')
self.fake_call(bind_function, ['programObj', 'location', 'name'])
print ' }'
print ' }'
@@ -633,7 +666,7 @@ def invokeFunction(self, function):
if function.name in ('glXGetProcAddress', 'glXGetProcAddressARB', 'wglGetProcAddress'):
else_ = ''
for marker_function in self.marker_functions:
- if self.api.get_function_by_name(marker_function):
+ if self.api.getFunctionByName(marker_function):
print ' %sif (strcmp("%s", (const char *)%s) == 0) {' % (else_, marker_function, function.args[0].name)
print ' __result = (%s)&%s;' % (function.type, marker_function)
print ' }'
@@ -667,6 +700,10 @@ def invokeFunction(self, function):
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);'
@@ -816,7 +853,7 @@ def footer(self, api):
function_name = 'gl%sPointer' % camelcase_name
enable_name = 'GL_%s_ARRAY' % uppercase_name
binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name
- function = api.get_function_by_name(function_name)
+ function = api.getFunctionByName(function_name)
print ' // %s' % function.prototype()
print ' if (%s) {' % profile_check
@@ -881,7 +918,7 @@ def footer(self, api):
else:
SUFFIX = suffix
function_name = 'glVertexAttribPointer' + suffix
- function = api.get_function_by_name(function_name)
+ function = api.getFunctionByName(function_name)
print ' // %s' % function.prototype()
print ' if (__vertex_attrib == VERTEX_ATTRIB%s) {' % SUFFIX
@@ -984,7 +1021,7 @@ def array_trace_epilog(self, api, uppercase_name):
print ' }'
def fake_glClientActiveTexture_call(self, api, texture):
- function = api.get_function_by_name('glClientActiveTexture')
+ function = api.getFunctionByName('glClientActiveTexture')
self.fake_call(function, [texture])
def fake_call(self, function, args):
View
31 wrappers/glxtrace.py
@@ -29,7 +29,6 @@
from gltrace import GlTracer
-from dispatch import function_pointer_type, function_pointer_value
from specs.stdapi import API
from specs.glapi import glapi
from specs.glxapi import glxapi
@@ -41,11 +40,10 @@ def isFunctionPublic(self, function):
# The symbols visible in libGL.so can vary, so expose them all
return True
- def wrapRet(self, function, instance):
- GlTracer.wrapRet(self, function, instance)
-
- if function.name in ("glXGetProcAddress", "glXGetProcAddressARB"):
- print ' %s = __unwrap_proc_addr(procName, %s);' % (instance, instance)
+ getProcAddressFunctionNames = [
+ "glXGetProcAddress",
+ "glXGetProcAddressARB",
+ ]
if __name__ == '__main__':
@@ -67,30 +65,13 @@ def wrapRet(self, function, instance):
print '#include "glproc.hpp"'
print '#include "glsize.hpp"'
print
- print 'static __GLXextFuncPtr __unwrap_proc_addr(const GLubyte * procName, __GLXextFuncPtr procPtr);'
- print
api = API()
api.addApi(glxapi)
api.addApi(glapi)
tracer = GlxTracer()
- tracer.trace_api(api)
-
- print 'static __GLXextFuncPtr __unwrap_proc_addr(const GLubyte * procName, __GLXextFuncPtr procPtr) {'
- print ' if (!procPtr) {'
- print ' return procPtr;'
- print ' }'
- for f in api.functions:
- ptype = function_pointer_type(f)
- pvalue = function_pointer_value(f)
- print ' if (strcmp("%s", (const char *)procName) == 0) {' % f.name
- print ' %s = (%s)procPtr;' % (pvalue, ptype)
- print ' return (__GLXextFuncPtr)&%s;' % (f.name,)
- print ' }'
- print ' os::log("apitrace: warning: unknown function \\"%s\\"\\n", (const char *)procName);'
- print ' return procPtr;'
- print '}'
- print
+ tracer.traceApi(api)
+
print r'''
View
2  wrappers/trace.py
@@ -348,7 +348,7 @@ def serializerFactory(self):
return ValueSerializer()
- def trace_api(self, api):
+ def traceApi(self, api):
self.api = api
self.header(api)
View
27 wrappers/wgltrace.py
@@ -28,8 +28,6 @@
from gltrace import GlTracer
-from dispatch import function_pointer_type, function_pointer_value
-from codegen import *
from specs.stdapi import API
from specs.glapi import glapi
from specs.wglapi import wglapi
@@ -37,26 +35,9 @@
class WglTracer(GlTracer):
- def wrapRet(self, function, instance):
- GlTracer.wrapRet(self, function, instance)
-
- if function.name == "wglGetProcAddress":
- print ' if (%s) {' % instance
-
- func_dict = dict([(f.name, f) for f in glapi.functions + wglapi.functions])
-
- def handle_case(function_name):
- f = func_dict[function_name]
- ptype = function_pointer_type(f)
- pvalue = function_pointer_value(f)
- print ' %s = (%s)%s;' % (pvalue, ptype, instance)
- print ' %s = (%s)&%s;' % (instance, function.type, f.name);
-
- def handle_default():
- print ' os::log("apitrace: warning: unknown function \\"%s\\"\\n", lpszProc);'
-
- string_switch('lpszProc', func_dict.keys(), handle_case, handle_default)
- print ' }'
+ getProcAddressFunctionNames = [
+ "wglGetProcAddress",
+ ]
if __name__ == '__main__':
@@ -80,4 +61,4 @@ def handle_default():
api.addApi(glapi)
api.addApi(wglapi)
tracer = WglTracer()
- tracer.trace_api(api)
+ tracer.traceApi(api)
Please sign in to comment.
Something went wrong with that request. Please try again.