1 ##########################################################################
3 # Copyright 2011 Jose Fonseca
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 ##########################################################################/
27 """D3D retracer generator."""
30 from dllretrace import DllRetracer as Retracer
31 import specs.stdapi as stdapi
32 from specs.d3d9 import *
35 class D3DRetracer(Retracer):
37 def retraceModule(self, api):
38 print '// Swizzling mapping for lock addresses'
39 print 'static std::map<void *, void *> _locks;'
42 self.table_name = 'd3dretrace::d3d_callbacks'
44 Retracer.retraceModule(self, api)
46 def invokeFunction(self, function):
47 if function.name in ('Direct3DCreate9', 'Direct3DCreate9Ex'):
48 print 'if (retrace::debug && !g_szD3D9DllName) {'
50 print ' * XXX: D3D9D only works for simple things, it often introduces errors'
51 print ' * on complex traces, or traces which use unofficial D3D9 features.'
54 print ' g_szD3D9DllName = "d3d9d.dll";'
58 Retracer.invokeFunction(self, function)
60 def invokeInterfaceMethod(self, interface, method):
61 # keep track of the last used device for state dumping
62 if interface.name in ('IDirect3DDevice9', 'IDirect3DDevice9Ex'):
63 print r' d3dretrace::pLastDirect3DDevice9 = _this;'
65 # create windows as neccessary
66 if method.name in ('CreateDevice', 'CreateDeviceEx', 'CreateAdditionalSwapChain'):
67 print r' HWND hWnd = d3dretrace::createWindow(pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);'
68 print r' pPresentationParameters->hDeviceWindow = hWnd;'
69 if 'hFocusWindow' in method.argNames():
70 print r' hFocusWindow = hWnd;'
72 if method.name in ('Reset', 'ResetEx'):
73 print r' if (pPresentationParameters->Windowed) {'
74 print r' d3dretrace::resizeWindow(pPresentationParameters->hDeviceWindow, pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);'
77 # notify frame has been completed
78 if method.name == 'Present':
79 print r' retrace::frameComplete(call);'
80 print r' hDestWindowOverride = NULL;'
82 if 'pSharedHandle' in method.argNames():
83 print r' if (pSharedHandle) {'
84 print r' retrace::warning(call) << "shared surfaces unsupported\n";'
85 print r' pSharedHandle = NULL;'
88 Retracer.invokeInterfaceMethod(self, interface, method)
90 # process events after presents
91 if method.name == 'Present':
92 print r' d3dretrace::processEvents();'
95 if str(method.type) == 'HRESULT':
96 print r' if (FAILED(_result)) {'
97 print r' retrace::warning(call) << "failed\n";'
100 if method.name in ('Lock', 'LockRect', 'LockBox'):
101 print ' VOID *_pbData = NULL;'
102 print ' size_t _LockedSize = 0;'
103 print ' _getLockInfo(_this, %s, _pbData, _LockedSize);' % ', '.join(method.argNames()[:-1])
104 print ' _locks[_this] = _pbData;'
106 if method.name in ('Unlock', 'UnlockRect', 'UnlockBox'):
107 print ' VOID *_pbData = 0;'
108 print ' _pbData = _locks[_this];'
109 print ' if (_pbData) {'
110 print ' retrace::delRegionByPointer(_pbData);'
114 if __name__ == '__main__':
120 #include "d3d9imports.hpp"
121 #include "d3d9size.hpp"
122 #include "d3dretrace.hpp"
126 retracer = D3DRetracer()
127 retracer.retraceModule(d3d9)