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.d3d10 import *
35 class D3DRetracer(Retracer):
37 def retraceApi(self, api):
38 print '// Swizzling mapping for lock addresses'
39 print 'static std::map<void *, void *> _maps;'
42 self.table_name = 'd3dretrace::%s_callbacks' % api.name.lower()
44 Retracer.retraceApi(self, api)
46 def invokeFunction(self, function):
47 # create windows as neccessary
48 if function.name == 'D3D10CreateDeviceAndSwapChain':
49 print r' pSwapChainDesc->OutputWindow = d3dretrace::createWindow(512, 512);'
51 Retracer.invokeFunction(self, function)
53 def invokeInterfaceMethod(self, interface, method):
54 # keep track of the last used device for state dumping
55 #if interface.name in ('IDirect3DDevice9', 'IDirect3DDevice9Ex'):
56 # print r' d3dretrace::pLastDirect3DDevice9 = _this;'
58 # create windows as neccessary
59 if method.name == 'CreateSwapChain':
60 print r' pDesc->OutputWindow = d3dretrace::createWindow(512, 512);'
62 # notify frame has been completed
63 if method.name == 'Present':
64 print r' retrace::frameComplete(call);'
66 if 'pSharedResource' in method.argNames():
67 print r' if (pSharedResource) {'
68 print r' retrace::warning(call) << "shared surfaces unsupported\n";'
69 print r' pSharedResource = NULL;'
72 Retracer.invokeInterfaceMethod(self, interface, method)
74 # process events after presents
75 if method.name == 'Present':
76 print r' d3dretrace::processEvents();'
79 if str(method.type) == 'HRESULT':
80 print r' if (FAILED(_result)) {'
81 print r' retrace::warning(call) << "failed\n";'
84 if method.name == 'Map':
85 print ' VOID *_pbData = NULL;'
86 print ' size_t _MappedSize = 0;'
87 print ' _getMapInfo(_this, %s, _pbData, _MappedSize);' % ', '.join(method.argNames())
88 print ' _maps[_this] = _pbData;'
90 if method.name == 'Unmap':
91 print ' VOID *_pbData = 0;'
92 print ' _pbData = _maps[_this];'
93 print ' if (_pbData) {'
94 print ' retrace::delRegionByPointer(_pbData);'
98 if __name__ == '__main__':
104 #include "d3d10imports.hpp"
105 #include "d3d10size.hpp"
106 #include "d3dretrace.hpp"
110 retracer = D3DRetracer()
111 retracer.retraceApi(d3d10)