]> git.cworth.org Git - apitrace/blob - d3dretrace.py
Create window on d3dretrace.
[apitrace] / 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 import specs.stdapi as stdapi
31 from specs.d3d9 import d3d9
32 from retrace import Retracer
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
53 if __name__ == '__main__':
54     print r'''
55 #include <string.h>
56
57 #include <iostream>
58
59 #include "d3d9imports.hpp"
60 #include "d3dretrace.hpp"
61
62
63 // XXX: Don't duplicate this code.
64
65 static LRESULT CALLBACK
66 WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
67 {
68     MINMAXINFO *pMMI;
69     switch (uMsg) {
70     case WM_GETMINMAXINFO:
71         // Allow to create a window bigger than the desktop
72         pMMI = (MINMAXINFO *)lParam;
73         pMMI->ptMaxSize.x = 60000;
74         pMMI->ptMaxSize.y = 60000;
75         pMMI->ptMaxTrackSize.x = 60000;
76         pMMI->ptMaxTrackSize.y = 60000;
77         break;
78     default:
79         break;
80     }
81
82     return DefWindowProc(hWnd, uMsg, wParam, lParam);
83 }
84
85
86 static HWND
87 createWindow(int width, int height) {
88     static bool first = TRUE;
89     RECT rect;
90
91     if (first) {
92         WNDCLASS wc;
93         memset(&wc, 0, sizeof wc);
94         wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
95         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
96         wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
97         wc.lpfnWndProc = WndProc;
98         wc.lpszClassName = "d3dretrace";
99         wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
100         RegisterClass(&wc);
101         first = FALSE;
102     }
103
104     DWORD dwExStyle;
105     DWORD dwStyle;
106     HWND hWnd;
107
108     dwExStyle = 0;
109     dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW;
110
111     int x = 0, y = 0;
112
113     rect.left = x;
114     rect.top = y;
115     rect.right = rect.left + width;
116     rect.bottom = rect.top + height;
117
118     AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle);
119
120     hWnd = CreateWindowEx(dwExStyle,
121                           "d3dretrace", /* wc.lpszClassName */
122                           NULL,
123                           dwStyle,
124                           0, /* x */
125                           0, /* y */
126                           rect.right - rect.left, /* width */
127                           rect.bottom - rect.top, /* height */
128                           NULL,
129                           NULL,
130                           NULL,
131                           NULL);
132     ShowWindow(hWnd, SW_SHOW);
133     return hWnd;
134 }
135
136 '''
137     retracer = D3DRetracer()
138     retracer.retraceApi(d3d9)