]> git.cworth.org Git - apitrace/blob - retrace/d3dretrace.py
Move retracers to their own directory.
[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 retrace import 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     def invokeInterfaceMethod(self, interface, method):
40         if interface.name == 'IDirect3D9' and method.name == 'CreateDevice':
41             print 'HWND hWnd = createWindow(pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);'
42             print 'pPresentationParameters->hDeviceWindow = hWnd;'
43             print 'hFocusWindow = hWnd;'
44
45         Retracer.invokeInterfaceMethod(self, interface, method)
46
47         if str(method.type) == 'HRESULT':
48             print r'    if (__result != S_OK) {'
49             print r'        retrace::warning(call) << "failed\n";'
50             print r'    }'
51
52         if interface.name == 'IDirect3DVertexBuffer9' and method.name == 'Lock':
53             print '        if (!SizeToLock) {'
54             print '            D3DVERTEXBUFFER_DESC Desc;'
55             print '            _this->GetDesc(&Desc);'
56             print '            SizeToLock = Desc.Size;'
57             print '        }'
58
59
60 if __name__ == '__main__':
61     print r'''
62 #include <string.h>
63
64 #include <iostream>
65
66 #include "d3d9imports.hpp"
67 #include "d3dretrace.hpp"
68
69
70 // XXX: Don't duplicate this code.
71
72 static LRESULT CALLBACK
73 WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
74 {
75     MINMAXINFO *pMMI;
76     switch (uMsg) {
77     case WM_GETMINMAXINFO:
78         // Allow to create a window bigger than the desktop
79         pMMI = (MINMAXINFO *)lParam;
80         pMMI->ptMaxSize.x = 60000;
81         pMMI->ptMaxSize.y = 60000;
82         pMMI->ptMaxTrackSize.x = 60000;
83         pMMI->ptMaxTrackSize.y = 60000;
84         break;
85     default:
86         break;
87     }
88
89     return DefWindowProc(hWnd, uMsg, wParam, lParam);
90 }
91
92
93 static HWND
94 createWindow(int width, int height) {
95     static bool first = TRUE;
96     RECT rect;
97
98     if (first) {
99         WNDCLASS wc;
100         memset(&wc, 0, sizeof wc);
101         wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
102         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
103         wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
104         wc.lpfnWndProc = WndProc;
105         wc.lpszClassName = "d3dretrace";
106         wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
107         RegisterClass(&wc);
108         first = FALSE;
109     }
110
111     DWORD dwExStyle;
112     DWORD dwStyle;
113     HWND hWnd;
114
115     dwExStyle = 0;
116     dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW;
117
118     int x = 0, y = 0;
119
120     rect.left = x;
121     rect.top = y;
122     rect.right = rect.left + width;
123     rect.bottom = rect.top + height;
124
125     AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle);
126
127     hWnd = CreateWindowEx(dwExStyle,
128                           "d3dretrace", /* wc.lpszClassName */
129                           NULL,
130                           dwStyle,
131                           0, /* x */
132                           0, /* y */
133                           rect.right - rect.left, /* width */
134                           rect.bottom - rect.top, /* height */
135                           NULL,
136                           NULL,
137                           NULL,
138                           NULL);
139     ShowWindow(hWnd, SW_SHOW);
140     return hWnd;
141 }
142
143 '''
144     retracer = D3DRetracer()
145     retracer.retraceApi(d3d9)