]> git.cworth.org Git - apitrace/blob - retrace/d3d9retrace.py
cli: Rename replay -> retrace.
[apitrace] / retrace / d3d9retrace.py
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 from specs.stdapi import API
32 from specs.d3d9 import *
33
34
35 class D3DRetracer(Retracer):
36
37     def retraceApi(self, api):
38         print '''static d3dretrace::D3DDumper<IDirect3DDevice9> d3d9Dumper;'''
39         print
40
41         print '// Swizzling mapping for lock addresses'
42         print 'static std::map<void *, void *> _maps;'
43         print
44
45         self.table_name = 'd3dretrace::d3d9_callbacks'
46
47         Retracer.retraceApi(self, api)
48
49     def invokeFunction(self, function):
50         if function.name in ('Direct3DCreate9', 'Direct3DCreate9Ex'):
51             print 'if (retrace::debug && !g_szD3D9DllName) {'
52             print '    /* '
53             print '     * XXX: D3D9D only works for simple things, it often introduces errors'
54             print '     * on complex traces, or traces which use unofficial D3D9 features.'
55             print '     */'
56             print '    if (0) {'
57             print '        g_szD3D9DllName = "d3d9d.dll";'
58             print '    }'
59             print '}'
60
61         Retracer.invokeFunction(self, function)
62
63     def invokeInterfaceMethod(self, interface, method):
64         # keep track of the last used device for state dumping
65         if interface.name in ('IDirect3DDevice9', 'IDirect3DDevice9Ex'):
66             if method.name == 'Release':
67                 print r'    d3d9Dumper.unbindDevice(_this);'
68             else:
69                 print r'    d3d9Dumper.bindDevice(_this);'
70
71         # create windows as neccessary
72         if method.name in ('CreateDevice', 'CreateDeviceEx', 'CreateAdditionalSwapChain'):
73             print r'    HWND hWnd = d3dretrace::createWindow(pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);'
74             print r'    pPresentationParameters->hDeviceWindow = hWnd;'
75             if 'hFocusWindow' in method.argNames():
76                 print r'    hFocusWindow = hWnd;'
77
78         if method.name in ('Reset', 'ResetEx'):
79             print r'    if (pPresentationParameters->Windowed) {'
80             print r'        d3dretrace::resizeWindow(pPresentationParameters->hDeviceWindow, pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);'
81             print r'    }'
82
83         # notify frame has been completed
84         if method.name == 'Present':
85             print r'    retrace::frameComplete(call);'
86             print r'    hDestWindowOverride = NULL;'
87
88         if 'pSharedHandle' in method.argNames():
89             print r'    if (pSharedHandle) {'
90             print r'        retrace::warning(call) << "shared surfaces unsupported\n";'
91             print r'        pSharedHandle = NULL;'
92             print r'    }'
93
94         Retracer.invokeInterfaceMethod(self, interface, method)
95
96         # process events after presents
97         if method.name == 'Present':
98             print r'    d3dretrace::processEvents();'
99
100         if method.name in ('Lock', 'LockRect', 'LockBox'):
101             print '    VOID *_pbData = NULL;'
102             print '    size_t _MappedSize = 0;'
103             print '    _getMapInfo(_this, %s, _pbData, _MappedSize);' % ', '.join(method.argNames()[:-1])
104             print '    _maps[_this] = _pbData;'
105         
106         if method.name in ('Unlock', 'UnlockRect', 'UnlockBox'):
107             print '    VOID *_pbData = 0;'
108             print '    _pbData = _maps[_this];'
109             print '    if (_pbData) {'
110             print '        retrace::delRegionByPointer(_pbData);'
111             print '    }'
112
113
114 if __name__ == '__main__':
115     print r'''
116 #include <string.h>
117
118 #include <iostream>
119
120 #include "d3d9imports.hpp"
121 #include "d3d9size.hpp"
122 #include "d3dretrace.hpp"
123 #include "d3dstate.hpp"
124
125 '''
126
127     api = API()
128     api.addModule(d3d9)
129     retracer = D3DRetracer()
130     retracer.retraceApi(api)