Permalink
Browse files

Fallback to d3d9.dll when d3d9d.dll can't be found.

  • Loading branch information...
1 parent 0655561 commit 0e5d1ff1e54079cdb89b409a5621fc33414244d6 @jrfonseca jrfonseca committed Apr 22, 2012
Showing with 62 additions and 43 deletions.
  1. +14 −11 dispatch/dispatch.py
  2. +7 −7 dispatch/glproc.py
  3. +0 −1 retrace/d3dretrace.py
  4. +6 −0 retrace/d3dretrace_main.cpp
  5. +34 −23 retrace/dllretrace.py
  6. +1 −1 wrappers/dlltrace.py
View
@@ -58,9 +58,9 @@ def header(self):
#
raise NotImplementedError
- def dispatch_api(self, api):
+ def dispatchApi(self, api):
for function in api.functions:
- self.invokeFunction(function)
+ self.dispatchFunction(api, function)
# define standard name aliases for convenience, but only when not
# tracing, as that would cause symbol clashing with the tracing
@@ -71,7 +71,7 @@ def dispatch_api(self, api):
print '#endif /* RETRACE */'
print
- def invokeFunction(self, function):
+ def dispatchFunction(self, api, function):
ptype = function_pointer_type(function)
pvalue = function_pointer_value(function)
print 'typedef ' + function.prototype('* %s' % ptype) + ';'
@@ -83,23 +83,26 @@ def invokeFunction(self, function):
ret = ''
else:
ret = 'return '
- self.get_true_pointer(function)
+ self.invokeGetProcAddress(api, function)
print ' %s%s(%s);' % (ret, pvalue, ', '.join([str(arg.name) for arg in function.args]))
print '}'
print
- def isFunctionPublic(self, function):
+ def isFunctionPublic(self, api, function):
return True
- def get_true_pointer(self, function):
+ def getProcAddressName(self, api, function):
+ if self.isFunctionPublic(api, function):
+ return '_getPublicProcAddress'
+ else:
+ return '_getPrivateProcAddress'
+
+ def invokeGetProcAddress(self, api, function):
ptype = function_pointer_type(function)
pvalue = function_pointer_value(function)
- if self.isFunctionPublic(function):
- get_proc_address = '_getPublicProcAddress'
- else:
- get_proc_address = '_getPrivateProcAddress'
+ getProcAddressName = self.getProcAddressName(api, function)
print ' if (!%s) {' % (pvalue,)
- print ' %s = (%s)%s(_name);' % (pvalue, ptype, get_proc_address)
+ print ' %s = (%s)%s(_name);' % (pvalue, ptype, getProcAddressName)
print ' if (!%s) {' % (pvalue,)
self.failFunction(function)
print ' }'
View
@@ -503,7 +503,7 @@ def header(self):
void * _getPrivateProcAddress(const char *procName);
'''
- def isFunctionPublic(self, function):
+ def isFunctionPublic(self, api, function):
return function.name in public_symbols or function.name.startswith('CGL')
@@ -519,25 +519,25 @@ def isFunctionPublic(self, function):
print
dispatcher.header()
print
- dispatcher.dispatch_api(eglapi)
+ dispatcher.dispatchApi(eglapi)
print
print '#if defined(_WIN32)'
print
- dispatcher.dispatch_api(wglapi)
+ dispatcher.dispatchApi(wglapi)
print
print '#elif defined(__APPLE__)'
print
- dispatcher.dispatch_api(cglapi)
+ dispatcher.dispatchApi(cglapi)
print
print '#elif defined(HAVE_X11)'
print
- dispatcher.dispatch_api(glxapi)
+ dispatcher.dispatchApi(glxapi)
print
print '#endif'
print
- dispatcher.dispatch_api(glapi)
+ dispatcher.dispatchApi(glapi)
print
- dispatcher.dispatch_api(glesapi)
+ dispatcher.dispatchApi(glesapi)
print
print '#endif /* !_GLPROC_HPP_ */'
View
@@ -225,6 +225,5 @@ def invokeInterfaceMethod(self, interface, method):
}
'''
- d3d9.name = 'd3d9d'
retracer = D3DRetracer()
retracer.retraceApi(d3d9)
@@ -31,8 +31,14 @@
#include "d3dretrace.hpp"
+extern const char *g_szD3D9DllName;
+
+
void
retrace::setUp(void) {
+ if (retrace::debug) {
+ g_szD3D9DllName = "d3d9d.dll";
+ }
}
View
@@ -28,32 +28,43 @@
from dispatch import Dispatcher
+class DllDispatcher(Dispatcher):
+
+ def dispatchApi(self, api):
+ tag = api.name.upper()
+ print r'const char *g_sz%sDllName = NULL;' % (tag,)
+ print r'HMODULE g_h%sModule = NULL;' % (tag,)
+ print r''
+ print r'static PROC'
+ print r'_getPublicProcAddress(LPCSTR lpProcName) {'
+ print r' if (!g_h%sModule) {' % tag
+ print r' if (g_sz%sDllName) {' % tag
+ print r' g_h%sModule = LoadLibraryA(g_sz%sDllName);' % (tag, tag)
+ print r' if (!g_h%sModule) {' % tag
+ print r' os::log("warning: failed to load %%s\n", g_sz%sDllName);' % tag
+ print r' }'
+ print r' }'
+ print r' if (!g_h%sModule) {' % tag
+ print r' g_h%sModule = LoadLibraryA("%s.dll");' % (tag, api.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' exit(1);'
+ print r' return NULL;'
+ print r' }'
+ print r' }'
+ print r' return GetProcAddress(g_h%sModule, lpProcName);' % tag
+ print r'}'
+ print r''
+
+ Dispatcher.dispatchApi(self, api)
+
+
class DllRetracer(Retracer):
def retraceApi(self, api):
- print r'''
-static LPCSTR g_szDll = "%s";
-static HMODULE g_hDll = NULL;
-
-static PROC
-_getPublicProcAddress(LPCSTR lpProcName)
-{
- if (!g_hDll) {
- g_hDll = LoadLibraryA(g_szDll);
- if (!g_hDll) {
- os::log("error: failed to load %%s\n", g_szDll);
- exit(1);
- return NULL;
- }
- }
-
- return GetProcAddress(g_hDll, lpProcName);
-}
-
-''' % api.name.upper()
-
- dispatcher = Dispatcher()
- dispatcher.dispatch_api(api)
+ dispatcher = DllDispatcher()
+ dispatcher.dispatchApi(api)
Retracer.retraceApi(self, api)
View
@@ -63,7 +63,7 @@ def header(self, api):
''' % self.dllname
dispatcher = Dispatcher()
- dispatcher.dispatch_api(api)
+ dispatcher.dispatchApi(api)
Tracer.header(self, api)

0 comments on commit 0e5d1ff

Please sign in to comment.