]> git.cworth.org Git - apitrace/blob - retrace/d3dretrace.py
0d6374684f3807324edabdfe25bb17509b8302e7
[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 """GL retracer generator."""
28
29
30 from dllretrace import DllRetracer as Retracer
31 import specs.stdapi as stdapi
32 from specs.d3d9 import d3d9
33
34
35 class D3DRetracer(Retracer):
36
37     table_name = 'd3dretrace::d3d9_callbacks'
38
39     bufferInterfaceNames = [
40         'IDirect3DVertexBuffer9',
41         'IDirect3DIndexBuffer9',
42     ]
43
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;'
49
50         Retracer.invokeInterfaceMethod(self, interface, method)
51
52         if str(method.type) == 'HRESULT':
53             print r'    if (__result != S_OK) {'
54             print r'        retrace::warning(call) << "failed\n";'
55             print r'    }'
56
57         if interface.name in self.bufferInterfaceNames and method.name == 'Lock':
58             getDescMethod = interface.getMethodByName('GetDesc')
59             descArg = getDescMethod.args[0]
60             assert descArg.output
61             descType = getDescMethod.args[0].type.type
62
63             print '        if (!SizeToLock) {'
64             print '            %s Desc;' % descType
65             print '            _this->GetDesc(&Desc);'
66             print '            SizeToLock = Desc.Size;'
67             print '        }'
68
69
70 if __name__ == '__main__':
71     print r'''
72 #include <string.h>
73
74 #include <iostream>
75
76 #include "d3d9imports.hpp"
77 #include "d3dretrace.hpp"
78
79
80 // XXX: Don't duplicate this code.
81
82 static LRESULT CALLBACK
83 WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
84 {
85     MINMAXINFO *pMMI;
86     switch (uMsg) {
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;
94         break;
95     default:
96         break;
97     }
98
99     return DefWindowProc(hWnd, uMsg, wParam, lParam);
100 }
101
102
103 static HWND
104 createWindow(int width, int height) {
105     static bool first = TRUE;
106     RECT rect;
107
108     if (first) {
109         WNDCLASS wc;
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;
117         RegisterClass(&wc);
118         first = FALSE;
119     }
120
121     DWORD dwExStyle;
122     DWORD dwStyle;
123     HWND hWnd;
124
125     dwExStyle = 0;
126     dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW;
127
128     int x = 0, y = 0;
129
130     rect.left = x;
131     rect.top = y;
132     rect.right = rect.left + width;
133     rect.bottom = rect.top + height;
134
135     AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle);
136
137     hWnd = CreateWindowEx(dwExStyle,
138                           "d3dretrace", /* wc.lpszClassName */
139                           NULL,
140                           dwStyle,
141                           0, /* x */
142                           0, /* y */
143                           rect.right - rect.left, /* width */
144                           rect.bottom - rect.top, /* height */
145                           NULL,
146                           NULL,
147                           NULL,
148                           NULL);
149     ShowWindow(hWnd, SW_SHOW);
150     return hWnd;
151 }
152
153 '''
154     retracer = D3DRetracer()
155     retracer.retraceApi(d3d9)