]> git.cworth.org Git - apitrace/blob - retrace/d3dretrace.py
Dump symbolic aliases for internalFormats 1..4.
[apitrace] / retrace / d3dretrace.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 import specs.stdapi as stdapi
32 from specs.d3d9 import *
33
34
35 class D3DRetracer(Retracer):
36
37     def retraceApi(self, api):
38         print 'static const GUID GUID_D3DRETRACE = {0x7D71CAC9,0x7F58,0x432C,{0xA9,0x75,0xA1,0x9F,0xCF,0xCE,0xFD,0x14}};'
39         print
40
41         self.table_name = 'd3dretrace::%s_callbacks' % api.name.lower()
42
43         Retracer.retraceApi(self, api)
44
45     def invokeInterfaceMethod(self, interface, method):
46         # keep track of the last used device for state dumping
47         if interface.name in ('IDirect3DDevice9', 'IDirect3DDevice9Ex'):
48             print r'    d3dretrace::pLastDirect3DDevice9 = _this;'
49
50         # create windows as neccessary
51         if method.name in ('CreateDevice', 'CreateDeviceEx', 'CreateAdditionalSwapChain'):
52             print r'    HWND hWnd = d3dretrace::createWindow(pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);'
53             print r'    pPresentationParameters->hDeviceWindow = hWnd;'
54             if 'hFocusWindow' in method.argNames():
55                 print r'    hFocusWindow = hWnd;'
56
57         if method.name in ('Reset', 'ResetEx'):
58             print r'    if (pPresentationParameters->Windowed) {'
59             print r'        d3dretrace::resizeWindow(pPresentationParameters->hDeviceWindow, pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);'
60             print r'    }'
61
62         # notify frame has been completed
63         if method.name == 'Present':
64             print r'    retrace::frameComplete(call);'
65             print r'    hDestWindowOverride = NULL;'
66
67         if 'pSharedHandle' in method.argNames():
68             print r'    if (pSharedHandle) {'
69             print r'        retrace::warning(call) << "shared surfaces unsupported\n";'
70             print r'        pSharedHandle = NULL;'
71             print r'    }'
72
73         Retracer.invokeInterfaceMethod(self, interface, method)
74
75         # process events after presents
76         if method.name == 'Present':
77             print r'    d3dretrace::processEvents();'
78
79         # check errors
80         if str(method.type) == 'HRESULT':
81             print r'    if (FAILED(_result)) {'
82             print r'        retrace::warning(call) << "failed\n";'
83             print r'    }'
84
85         if method.name in ('Lock', 'LockRect', 'LockBox'):
86             print '    VOID *_pbData = NULL;'
87             print '    size_t _LockedSize = 0;'
88             print '    _getLockInfo(_this, %s, _pbData, _LockedSize);' % ', '.join(method.argNames()[:-1])
89             print '    _this->SetPrivateData(GUID_D3DRETRACE, &_pbData, sizeof _pbData, 0);'
90         
91         if method.name in ('Unlock', 'UnlockRect', 'UnlockBox'):
92             print '    VOID *_pbData = 0;'
93             print '    DWORD dwSizeOfData = sizeof _pbData;'
94             print '    _this->GetPrivateData(GUID_D3DRETRACE, &_pbData, &dwSizeOfData);'
95             print '    if (_pbData) {'
96             print '        retrace::delRegionByPointer(_pbData);'
97             print '    }'
98
99
100 if __name__ == '__main__':
101     print r'''
102 #include <string.h>
103
104 #include <iostream>
105
106 #include "d3d9imports.hpp"
107 #include "d3dsize.hpp"
108 #include "d3dretrace.hpp"
109
110 '''
111
112     retracer = D3DRetracer()
113     retracer.retraceApi(d3d9)