#
raise NotImplementedError
- def dispatchApi(self, api):
- for function in api.functions:
- self.dispatchFunction(api, function)
+ def dispatchModule(self, module):
+ for function in module.functions:
+ self.dispatchFunction(module, function)
# define standard name aliases for convenience, but only when not
# tracing, as that would cause symbol clashing with the tracing
# functions
print '#ifdef RETRACE'
- for function in api.functions:
+ for function in module.functions:
print '#define %s _%s' % (function.name, function.name)
print '#endif /* RETRACE */'
print
- def dispatchFunction(self, api, function):
+ def dispatchFunction(self, module, function):
ptype = function_pointer_type(function)
pvalue = function_pointer_value(function)
print 'typedef ' + function.prototype('* %s' % ptype) + ';'
ret = ''
else:
ret = 'return '
- self.invokeGetProcAddress(api, function)
+ self.invokeGetProcAddress(module, function)
print ' %s%s(%s);' % (ret, pvalue, ', '.join([str(arg.name) for arg in function.args]))
print '}'
print
- def isFunctionPublic(self, api, function):
+ def isFunctionPublic(self, module, function):
return True
- def getProcAddressName(self, api, function):
- if self.isFunctionPublic(api, function):
+ def getProcAddressName(self, module, function):
+ if self.isFunctionPublic(module, function):
return '_getPublicProcAddress'
else:
return '_getPrivateProcAddress'
- def invokeGetProcAddress(self, api, function):
+ def invokeGetProcAddress(self, module, function):
ptype = function_pointer_type(function)
pvalue = function_pointer_value(function)
- getProcAddressName = self.getProcAddressName(api, function)
+ getProcAddressName = self.getProcAddressName(module, function)
print ' if (!%s) {' % (pvalue,)
print ' %s = (%s)%s(_name);' % (pvalue, ptype, getProcAddressName)
print ' if (!%s) {' % (pvalue,)
void * _getPrivateProcAddress(const char *procName);
'''
- def isFunctionPublic(self, api, function):
+ def isFunctionPublic(self, module, function):
return function.name in public_symbols or function.name.startswith('CGL')
print
dispatcher.header()
print
- dispatcher.dispatchApi(eglapi)
+ dispatcher.dispatchModule(eglapi)
print
print '#if defined(_WIN32)'
print
- dispatcher.dispatchApi(wglapi)
+ dispatcher.dispatchModule(wglapi)
print
print '#elif defined(__APPLE__)'
print
- dispatcher.dispatchApi(cglapi)
+ dispatcher.dispatchModule(cglapi)
print
print '#elif defined(HAVE_X11)'
print
- dispatcher.dispatchApi(glxapi)
+ dispatcher.dispatchModule(glxapi)
print
print '#endif'
print
- dispatcher.dispatchApi(glapi)
+ dispatcher.dispatchModule(glapi)
print
- dispatcher.dispatchApi(glesapi)
+ dispatcher.dispatchModule(glesapi)
print
print '#endif /* !_GLPROC_HPP_ */'
'''
retracer = D3DRetracer()
- retracer.retraceApi(d3d10_1)
+ retracer.retraceModule(d3d10_1)
'''
retracer = D3DRetracer()
- retracer.retraceApi(d3d10)
+ retracer.retraceModule(d3d10)
'''
retracer = D3DRetracer()
- retracer.retraceApi(d3d11)
+ retracer.retraceModule(d3d11)
class D3DRetracer(Retracer):
- def retraceApi(self, api):
+ def retraceModule(self, api):
print '// Swizzling mapping for lock addresses'
print 'static std::map<void *, void *> _locks;'
print
self.table_name = 'd3dretrace::d3d_callbacks'
- Retracer.retraceApi(self, api)
+ Retracer.retraceModule(self, api)
def invokeFunction(self, function):
if function.name in ('Direct3DCreate9', 'Direct3DCreate9Ex'):
'''
retracer = D3DRetracer()
- retracer.retraceApi(d3d9)
+ retracer.retraceModule(d3d9)
class D3DRetracer(Retracer):
- def retraceApi(self, api):
+ def retraceModule(self, api):
print '// Swizzling mapping for lock addresses'
print 'static std::map<void *, void *> _maps;'
print
self.table_name = 'd3dretrace::d3d_callbacks'
- Retracer.retraceApi(self, api)
+ Retracer.retraceModule(self, api)
def invokeFunction(self, function):
# create windows as neccessary
from retrace import Retracer
from dispatch import Dispatcher
+from specs.stdapi import API
class DllDispatcher(Dispatcher):
- def dispatchApi(self, api):
- tag = api.name.upper()
+ def dispatchModule(self, module):
+ tag = module.name.upper()
print r'const char *g_sz%sDllName = NULL;' % (tag,)
print r'HMODULE g_h%sModule = NULL;' % (tag,)
print r''
print r' }'
print r' }'
print r' if (!g_h%sModule) {' % tag
- print r' g_h%sModule = LoadLibraryA("%s.dll");' % (tag, api.name)
+ print r' g_h%sModule = LoadLibraryA("%s.dll");' % (tag, module.name)
print r' }'
print r' if (!g_h%sModule) {' % tag
- print r' os::log("error: failed to load %s.dll\n");' % api.name
+ print r' os::log("error: failed to load %s.dll\n");' % module.name
print r' exit(1);'
print r' }'
print r' }'
print r'}'
print r''
- Dispatcher.dispatchApi(self, api)
+ Dispatcher.dispatchModule(self, module)
class DllRetracer(Retracer):
def retraceApi(self, api):
- dispatcher = DllDispatcher()
- dispatcher.dispatchApi(api)
+ for module in api.modules:
+ dispatcher = DllDispatcher()
+ dispatcher.dispatchModule(module)
Retracer.retraceApi(self, api)
+ def retraceModule(self, module):
+ api = API()
+ api.addModule(module)
+ self.retraceApi(api)
static bool _pipelineHasBeenBound = false;
'''
- api = glapi.glapi
- api.addApi(glesapi.glesapi)
+ api = stdapi.API()
+ api.addModule(glapi.glapi)
+ api.addModule(glesapi.glesapi)
retracer = GlRetracer()
retracer.retraceApi(api)
handle_names.add(handle.name)
print
- functions = filter(self.filterFunction, api.functions)
+ functions = filter(self.filterFunction, api.getAllFunctions())
for function in functions:
if function.sideeffects and not function.internal:
self.retraceFunction(function)
CGLContextObj = Opaque("CGLContextObj")
-cglapi = API("CGL")
+cglapi = Module("CGL")
cglapi.addFunctions([
# CGLCurrent.h, libGL.dylib
StdMethod(HRESULT, "CreateDCRenderTarget", [(Pointer(Const(D2D1_RENDER_TARGET_PROPERTIES)), "renderTargetProperties"), Out(Pointer(ObjPointer(ID2D1DCRenderTarget)), "dcRenderTarget")]),
]
-d2d1 = API("d2d1")
-d2d1.addInterface(ID2D1Factory)
+d2d1 = Module("d2d1")
+d2d1.addInterfaces([
+ ID2D1Factory
+])
d2d1.addFunctions([
StdFunction(HRESULT, "D2D1CreateFactory", [(D2D1_FACTORY_TYPE, "factoryType"), (REFIID, "riid"), (Pointer(Const(D2D1_FACTORY_OPTIONS)), "pFactoryOptions"), Out(Pointer(OpaquePointer(Void)), "ppIFactory")]),
StdFunction(Void, "D2D1MakeRotateMatrix", [(FLOAT, "angle"), (D2D1_POINT_2F, "center"), Out(Pointer(D2D1_MATRIX_3X2_F), "matrix")]),
]
-d3d10 = API("d3d10")
+d3d10 = Module("d3d10")
from d3d10sdklayers import *
StdMethod(D3D10_FEATURE_LEVEL1, "GetFeatureLevel", [], sideeffects=False),
]
-d3d10_1 = API("d3d10_1")
+d3d10_1 = Module("d3d10_1")
d3d10_1.addFunctions([
StdFunction(HRESULT, "D3D10CreateDevice1", [(ObjPointer(IDXGIAdapter), "pAdapter"), (D3D10_DRIVER_TYPE, "DriverType"), (HMODULE, "Software"), (D3D10_CREATE_DEVICE_FLAG, "Flags"), (D3D10_FEATURE_LEVEL1, "HardwareLevel"), (UINT, "SDKVersion"), Out(Pointer(ObjPointer(ID3D10Device1)), "ppDevice")]),
StdFunction(HRESULT, "D3D10CreateDeviceAndSwapChain1", [(ObjPointer(IDXGIAdapter), "pAdapter"), (D3D10_DRIVER_TYPE, "DriverType"), (HMODULE, "Software"), (D3D10_CREATE_DEVICE_FLAG, "Flags"), (D3D10_FEATURE_LEVEL1, "HardwareLevel"), (UINT, "SDKVersion"), (Pointer(DXGI_SWAP_CHAIN_DESC), "pSwapChainDesc"), Out(Pointer(ObjPointer(IDXGISwapChain)), "ppSwapChain"), Out(Pointer(ObjPointer(ID3D10Device1)), "ppDevice")]),
StdMethod(UINT, "GetExceptionMode", [], sideeffects=False),
]
-d3d11 = API("d3d11")
+d3d11 = Module("d3d11")
d3d11.addFunctions([
StdFunction(HRESULT, "D3D11CreateDevice", [(ObjPointer(IDXGIAdapter), "pAdapter"), (D3D_DRIVER_TYPE, "DriverType"), (HMODULE, "Software"), (D3D11_CREATE_DEVICE_FLAG, "Flags"), (Array(Const(D3D_FEATURE_LEVEL), "FeatureLevels"), "pFeatureLevels"), (UINT, "FeatureLevels"), (UINT, "SDKVersion"), Out(Pointer(ObjPointer(ID3D11Device)), "ppDevice"), Out(Pointer(D3D_FEATURE_LEVEL), "pFeatureLevel"), Out(Pointer(ObjPointer(ID3D11DeviceContext)), "ppImmediateContext")]),
StdMethod(HRESULT, "UnlockBox", []),
]
-d3d8 = API("d3d8")
+d3d8 = Module("d3d8")
d3d8.addFunctions([
StdFunction(PDIRECT3D8, "Direct3DCreate8", [(UINT, "SDKVersion")]),
])
StdMethod(HRESULT, "GetDisplayModeEx", [Out(Pointer(D3DDISPLAYMODEEX), "pMode"), Out(Pointer(D3DDISPLAYROTATION), "pRotation")], sideeffects=False),
]
-d3d9 = API("d3d9")
+d3d9 = Module("d3d9")
d3d9.addFunctions([
StdFunction(PDIRECT3D9, "Direct3DCreate9", [(UINT, "SDKVersion")], fail='NULL'),
StdFunction(HRESULT, "Direct3DCreate9Ex", [(UINT, "SDKVersion"), Out(Pointer(PDIRECT3D9EX), "ppD3D")], fail='D3DERR_NOTAVAILABLE'),
"DDCREATE_EMULATIONONLY",
])
-ddraw = API("ddraw")
+ddraw = Module("ddraw")
ddraw.addFunctions([
StdFunction(HRESULT, "DirectDrawEnumerateW", [(LPDDENUMCALLBACKW, "lpCallback"), (LPVOID, "lpContext")]),
StdFunction(HRESULT, "DirectDrawEnumerateA", [(LPDDENUMCALLBACKA, "lpCallback"), (LPVOID, "lpContext")]),
StdMethod(HRESULT, "CreateGlyphRunAnalysis", [(Pointer(Const(DWRITE_GLYPH_RUN)), "glyphRun"), (FLOAT, "pixelsPerDip"), (Pointer(Const(DWRITE_MATRIX)), "transform"), (DWRITE_RENDERING_MODE, "renderingMode"), (DWRITE_MEASURING_MODE, "measuringMode"), (FLOAT, "baselineOriginX"), (FLOAT, "baselineOriginY"), Out(Pointer(ObjPointer(IDWriteGlyphRunAnalysis)), "glyphRunAnalysis")]),
]
-dwrite = API("dwrite")
-dwrite.addInterface(IDWriteFactory)
+dwrite = Module("dwrite")
+dwrite.addInterfaces([
+ IDWriteFactory
+])
dwrite.addFunctions([
StdFunction(HRESULT, "DWriteCreateFactory", [(DWRITE_FACTORY_TYPE, "factoryType"), (REFIID, "iid"), Out(Pointer(ObjPointer(IUnknown)), "factory")]),
])
StdMethod(HRESULT, "GetMaximumFrameLatency", [Out(Pointer(UINT), "pMaxLatency")], sideeffects=False),
]
-dxgi = API('dxgi')
+dxgi = Module('dxgi')
dxgi.addFunctions([
StdFunction(HRESULT, "CreateDXGIFactory", [(REFIID, "riid"), Out(Pointer(ObjPointer(Void)), "ppFactory")]),
StdFunction(HRESULT, "CreateDXGIFactory1", [(REFIID, "riid"), Out(Pointer(ObjPointer(Void)), "ppFactory")]),
# EGL_NV_system_time
EGLuint64NV = Alias("EGLuint64NV", UInt64)
-eglapi = API("EGL")
+eglapi = Module("EGL")
EGLAttribList = Array(Const(EGLattrib), "_AttribPairList_size(attrib_list, EGL_NONE)")
return Function(*args, **kwargs)
-glapi = API('GL')
+glapi = Module('GL')
glapi.addFunctions([
return Function(*args, **kwargs)
-glesapi = API('GLES')
+glesapi = Module('GLES')
# OpenGL ES specific functions
"GLX_PBUFFER_CLOBBER_MASK",
])
-glxapi = API("GLX")
+glxapi = Module("GLX")
PROC = Opaque("__GLXextFuncPtr")
-class API:
- '''API abstraction.
-
- Essentially, a collection of types, functions, and interfaces.
- '''
+class Module:
+ '''A collection of functions.'''
def __init__(self, name = None):
self.name = name
self.functions = []
self.interfaces = []
+ def addFunctions(self, functions):
+ self.functions.extend(functions)
+
+ def addInterfaces(self, interfaces):
+ self.interfaces.extend(interfaces)
+
+ def mergeModule(self, module):
+ self.headers.extend(module.headers)
+ self.functions.extend(module.functions)
+ self.interfaces.extend(module.interfaces)
+
+ def getFunctionByName(self, name):
+ for function in self.functions:
+ if function.name == name:
+ return function
+ return None
+
+
+class API:
+ '''API abstraction.
+
+ Essentially, a collection of types, functions, and interfaces.
+ '''
+
+ def __init__(self, modules = None):
+ self.modules = []
+ if modules is not None:
+ self.modules.extend(modules)
+
def getAllTypes(self):
collector = Collector()
- for function in self.functions:
- for arg in function.args:
- collector.visit(arg.type)
- collector.visit(function.type)
- for interface in self.interfaces:
- collector.visit(interface)
- for method in interface.iterMethods():
- for arg in method.args:
+ for module in self.modules:
+ for function in module.functions:
+ for arg in function.args:
collector.visit(arg.type)
- collector.visit(method.type)
+ collector.visit(function.type)
+ for interface in module.interfaces:
+ collector.visit(interface)
+ for method in interface.iterMethods():
+ for arg in method.args:
+ collector.visit(arg.type)
+ collector.visit(method.type)
return collector.types
+ def getAllFunctions(self):
+ functions = []
+ for module in self.modules:
+ functions.extend(module.functions)
+ return functions
+
def getAllInterfaces(self):
types = self.getAllTypes()
interfaces = [type for type in types if isinstance(type, Interface)]
- for interface in self.interfaces:
- if interface not in interfaces:
- interfaces.append(interface)
+ for module in self.modules:
+ for interface in module.interfaces:
+ if interface not in interfaces:
+ interfaces.append(interface)
return interfaces
- def addFunction(self, function):
- self.functions.append(function)
-
- def addFunctions(self, functions):
- for function in functions:
- self.addFunction(function)
-
- def addInterface(self, interface):
- self.interfaces.append(interface)
-
- def addInterfaces(self, interfaces):
- self.interfaces.extend(interfaces)
-
- def addApi(self, api):
- self.headers.extend(api.headers)
- self.addFunctions(api.functions)
- self.addInterfaces(api.interfaces)
+ def addModule(self, module):
+ self.modules.append(module)
def getFunctionByName(self, name):
- for function in self.functions:
- if function.name == name:
- return function
+ for module in self.modules:
+ for function in module.functions:
+ if function.name == name:
+ return function
return None
from wglenum import *
-wglapi = API("WGL")
+wglapi = Module("WGL")
HGLRC = Alias("HGLRC", HANDLE)
from gltrace import GlTracer
-from specs.stdapi import API
+from specs.stdapi import Module, API
from specs.glapi import glapi
from specs.cglapi import cglapi
print '#include "glsize.hpp"'
print
+ module = Module()
+ module.mergeModule(cglapi)
+ module.mergeModule(glapi)
api = API()
- api.addApi(cglapi)
- api.addApi(glapi)
+ api.addModule(module)
tracer = CglTracer()
tracer.traceApi(api)
print
tracer = D2D1Tracer('d2d1.dll')
- tracer.traceApi(d2d1)
+ tracer.traceModule(d2d1)
print '#include "d3d10size.hpp"'
print
tracer = D3DCommonTracer('d3d10_1.dll')
- tracer.traceApi(d3d10_1)
+ tracer.traceModule(d3d10_1)
print '#include "d3d10size.hpp"'
print
tracer = D3DCommonTracer('d3d10.dll')
- tracer.traceApi(d3d10)
+ tracer.traceModule(d3d10)
print '#include "d3d11size.hpp"'
print
tracer = D3DCommonTracer('d3d11.dll')
- tracer.traceApi(d3d11)
+ tracer.traceModule(d3d11)
print '#include "os.hpp"'
print
tracer = D3D8Tracer('d3d8.dll')
- tracer.traceApi(d3d8)
+ tracer.traceModule(d3d8)
}
'''
tracer = D3D9Tracer('d3d9.dll')
- tracer.traceApi(d3d9)
+ tracer.traceModule(d3d9)
print '#include "os.hpp"'
print
tracer = DDrawTracer('ddraw.dll')
- tracer.traceApi(ddraw)
+ tracer.traceModule(ddraw)
from trace import Tracer
from dispatch import Dispatcher
+from specs.stdapi import API
class DllTracer(Tracer):
''' % self.dllname
- dispatcher = Dispatcher()
- dispatcher.dispatchApi(api)
+ for module in api.modules:
+ dispatcher = Dispatcher()
+ dispatcher.dispatchModule(module)
Tracer.header(self, api)
+ def traceModule(self, module):
+ api = API()
+ api.addModule(module)
+ self.traceApi(api)
print
tracer = DWriteTracer('dwrite.dll')
- tracer.traceApi(dwrite)
+ tracer.traceModule(dwrite)
from gltrace import GlTracer
-from specs.stdapi import API
+from specs.stdapi import Module, API
from specs.glapi import glapi
from specs.eglapi import eglapi
from specs.glesapi import glesapi
print '#include "eglsize.hpp"'
print
+ module = Module()
+ module.mergeModule(eglapi)
+ module.mergeModule(glapi)
+ module.mergeModule(glesapi)
api = API()
- api.addApi(eglapi)
- api.addApi(glapi)
- api.addApi(glesapi)
+ api.addModule(module)
tracer = EglTracer()
tracer.traceApi(api)
print ' if (!procPtr) {'
print ' return procPtr;'
print ' }'
- for function in api.functions:
+ for function in api.getAllFunctions():
ptype = function_pointer_type(function)
pvalue = function_pointer_value(function)
print ' if (strcmp("%s", (const char *)procName) == 0) {' % function.name
from gltrace import GlTracer
-from specs.stdapi import API
+from specs.stdapi import Module, API
from specs.glapi import glapi
from specs.glxapi import glxapi
print '#include "glsize.hpp"'
print
+ module = Module()
+ module.mergeModule(glxapi)
+ module.mergeModule(glapi)
api = API()
- api.addApi(glxapi)
- api.addApi(glapi)
+ api.addModule(module)
tracer = GlxTracer()
tracer.traceApi(api)
self.header(api)
# Includes
- for header in api.headers:
- print header
+ for module in api.modules:
+ for header in module.headers:
+ print header
print
# Generate the serializer functions
# Function wrappers
self.interface = None
self.base = None
- map(self.traceFunctionDecl, api.functions)
- map(self.traceFunctionImpl, api.functions)
+ for function in api.getAllFunctions():
+ self.traceFunctionDecl(function)
+ for function in api.getAllFunctions():
+ self.traceFunctionImpl(function)
print
self.footer(api)
from gltrace import GlTracer
-from specs.stdapi import API
+from specs.stdapi import Module, API
from specs.glapi import glapi
from specs.wglapi import wglapi
print '#include "glproc.hpp"'
print '#include "glsize.hpp"'
print
+ module = Module()
+ module.mergeModule(glapi)
+ module.mergeModule(wglapi)
api = API()
- api.addApi(glapi)
- api.addApi(wglapi)
+ api.addModule(module)
tracer = WglTracer()
tracer.traceApi(api)