José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 1 | ########################################################################## |
| 2 | # |
| 3 | # Copyright 2011 Jose Fonseca |
| 4 | # All Rights Reserved. |
| 5 | # |
| 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: |
| 12 | # |
| 13 | # The above copyright notice and this permission notice shall be included in |
| 14 | # all copies or substantial portions of the Software. |
| 15 | # |
| 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 |
| 22 | # THE SOFTWARE. |
| 23 | # |
| 24 | ##########################################################################/ |
| 25 | |
| 26 | |
| 27 | """D3D retracer generator.""" |
| 28 | |
| 29 | |
| 30 | from dllretrace import DllRetracer as Retracer |
| 31 | import specs.stdapi as stdapi |
| 32 | |
| 33 | |
| 34 | class D3DRetracer(Retracer): |
| 35 | |
José Fonseca | e381485 | 2012-11-11 09:45:06 +0000 | [diff] [blame^] | 36 | def retraceApi(self, api): |
| 37 | print ''' |
| 38 | image::Image * |
| 39 | retrace::getSnapshot(void) { |
| 40 | return NULL; |
| 41 | } |
| 42 | |
| 43 | |
| 44 | bool |
| 45 | retrace::dumpState(std::ostream &os) |
| 46 | { |
| 47 | return false; |
| 48 | } |
| 49 | ''' |
| 50 | |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 51 | print '// Swizzling mapping for lock addresses' |
| 52 | print 'static std::map<void *, void *> _maps;' |
| 53 | print |
| 54 | |
| 55 | self.table_name = 'd3dretrace::d3d_callbacks' |
| 56 | |
José Fonseca | e381485 | 2012-11-11 09:45:06 +0000 | [diff] [blame^] | 57 | Retracer.retraceApi(self, api) |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 58 | |
| 59 | def invokeFunction(self, function): |
| 60 | # create windows as neccessary |
| 61 | if function.name in ('D3D10CreateDeviceAndSwapChain', 'D3D10CreateDeviceAndSwapChain1', 'D3D11CreateDeviceAndSwapChain'): |
| 62 | print r' pSwapChainDesc->OutputWindow = d3dretrace::createWindow(512, 512);' |
| 63 | |
| 64 | Retracer.invokeFunction(self, function) |
| 65 | |
| 66 | def invokeInterfaceMethod(self, interface, method): |
| 67 | # keep track of the last used device for state dumping |
| 68 | #if interface.name in ('IDirect3DDevice9', 'IDirect3DDevice9Ex'): |
| 69 | # print r' d3dretrace::pLastDirect3DDevice9 = _this;' |
| 70 | |
| 71 | # create windows as neccessary |
| 72 | if method.name == 'CreateSwapChain': |
| 73 | print r' pDesc->OutputWindow = d3dretrace::createWindow(512, 512);' |
| 74 | |
| 75 | # notify frame has been completed |
| 76 | if method.name == 'Present': |
| 77 | print r' retrace::frameComplete(call);' |
| 78 | |
| 79 | if 'pSharedResource' in method.argNames(): |
| 80 | print r' if (pSharedResource) {' |
| 81 | print r' retrace::warning(call) << "shared surfaces unsupported\n";' |
| 82 | print r' pSharedResource = NULL;' |
| 83 | print r' }' |
| 84 | |
| 85 | Retracer.invokeInterfaceMethod(self, interface, method) |
| 86 | |
| 87 | # process events after presents |
| 88 | if method.name == 'Present': |
| 89 | print r' d3dretrace::processEvents();' |
| 90 | |
| 91 | # check errors |
| 92 | if str(method.type) == 'HRESULT': |
| 93 | print r' if (FAILED(_result)) {' |
| 94 | print r' retrace::warning(call) << "failed\n";' |
| 95 | print r' }' |
| 96 | |
| 97 | if method.name == 'Map': |
| 98 | print ' VOID *_pbData = NULL;' |
| 99 | print ' size_t _MappedSize = 0;' |
| 100 | print ' _getMapInfo(_this, %s, _pbData, _MappedSize);' % ', '.join(method.argNames()) |
| 101 | print ' _maps[_this] = _pbData;' |
| 102 | |
| 103 | if method.name == 'Unmap': |
| 104 | print ' VOID *_pbData = 0;' |
| 105 | print ' _pbData = _maps[_this];' |
| 106 | print ' if (_pbData) {' |
| 107 | print ' retrace::delRegionByPointer(_pbData);' |
| 108 | print ' }' |