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 """GL retracer generator."""
30 from dllretrace import DllRetracer as Retracer
31 import specs.stdapi as stdapi
32 from specs.d3d9 import d3d9
35 class D3DRetracer(Retracer):
37 table_name = 'd3dretrace::d3d9_callbacks'
39 bufferInterfaceNames = [
40 'IDirect3DVertexBuffer9',
41 'IDirect3DIndexBuffer9',
44 def invokeInterfaceMethod(self, interface, method):
45 if interface.name == 'IDirect3D9' and method.name == 'CreateDevice':
46 print 'HWND hWnd = createWindow(pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);'
47 print 'pPresentationParameters->hDeviceWindow = hWnd;'
48 print 'hFocusWindow = hWnd;'
50 Retracer.invokeInterfaceMethod(self, interface, method)
52 if str(method.type) == 'HRESULT':
53 print r' if (_result != S_OK) {'
54 print r' retrace::warning(call) << "failed\n";'
57 if interface.name in self.bufferInterfaceNames and method.name == 'Lock':
58 getDescMethod = interface.getMethodByName('GetDesc')
59 descArg = getDescMethod.args[0]
61 descType = getDescMethod.args[0].type.type
63 print ' if (!SizeToLock) {'
64 print ' %s Desc;' % descType
65 print ' _this->GetDesc(&Desc);'
66 print ' SizeToLock = Desc.Size;'
70 if __name__ == '__main__':
76 #include "d3d9imports.hpp"
77 #include "d3dretrace.hpp"
80 // XXX: Don't duplicate this code.
82 static LRESULT CALLBACK
83 WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
87 case WM_GETMINMAXINFO:
88 // Allow to create a window bigger than the desktop
89 pMMI = (MINMAXINFO *)lParam;
90 pMMI->ptMaxSize.x = 60000;
91 pMMI->ptMaxSize.y = 60000;
92 pMMI->ptMaxTrackSize.x = 60000;
93 pMMI->ptMaxTrackSize.y = 60000;
99 return DefWindowProc(hWnd, uMsg, wParam, lParam);
104 createWindow(int width, int height) {
105 static bool first = TRUE;
110 memset(&wc, 0, sizeof wc);
111 wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
112 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
113 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
114 wc.lpfnWndProc = WndProc;
115 wc.lpszClassName = "d3dretrace";
116 wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
126 dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW;
132 rect.right = rect.left + width;
133 rect.bottom = rect.top + height;
135 AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle);
137 hWnd = CreateWindowEx(dwExStyle,
138 "d3dretrace", /* wc.lpszClassName */
143 rect.right - rect.left, /* width */
144 rect.bottom - rect.top, /* height */
149 ShowWindow(hWnd, SW_SHOW);
154 retracer = D3DRetracer()
155 retracer.retraceApi(d3d9)