]> git.cworth.org Git - apitrace/blob - retrace/d3dretrace_ws.cpp
Use skiplist-based FastCallSet within trace::CallSet
[apitrace] / retrace / d3dretrace_ws.cpp
1 /**************************************************************************
2  *
3  * Copyright 2012 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 #include "d3dretrace.hpp"
28
29
30 namespace d3dretrace {
31
32
33 // XXX: Don't duplicate this code.
34
35 static LRESULT CALLBACK
36 WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
37 {
38     MINMAXINFO *pMMI;
39     switch (uMsg) {
40     case WM_KEYDOWN:
41         switch (wParam) {
42         case VK_ESCAPE:
43             PostMessage(hWnd, WM_CLOSE, 0, 0);
44             break;
45         }
46         break;
47     case WM_GETMINMAXINFO:
48         // Allow to create a window bigger than the desktop
49         pMMI = (MINMAXINFO *)lParam;
50         pMMI->ptMaxSize.x = 60000;
51         pMMI->ptMaxSize.y = 60000;
52         pMMI->ptMaxTrackSize.x = 60000;
53         pMMI->ptMaxTrackSize.y = 60000;
54         break;
55     case WM_CLOSE:
56         exit(0);
57         break;
58     default:
59         break;
60     }
61
62     return DefWindowProc(hWnd, uMsg, wParam, lParam);
63 }
64
65
66 HWND
67 createWindow(int width, int height) {
68     static bool first = TRUE;
69     RECT rect;
70
71     if (first) {
72         WNDCLASS wc;
73         memset(&wc, 0, sizeof wc);
74         wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
75         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
76         wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
77         wc.lpfnWndProc = WndProc;
78         wc.lpszClassName = "d3dretrace";
79         wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
80         RegisterClass(&wc);
81         first = FALSE;
82     }
83
84     DWORD dwExStyle;
85     DWORD dwStyle;
86     HWND hWnd;
87
88     dwExStyle = 0;
89     dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW;
90
91     int x = 0, y = 0;
92
93     rect.left = x;
94     rect.top = y;
95     rect.right = rect.left + width;
96     rect.bottom = rect.top + height;
97
98     AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle);
99
100     hWnd = CreateWindowEx(dwExStyle,
101                           "d3dretrace", /* wc.lpszClassName */
102                           NULL,
103                           dwStyle,
104                           0, /* x */
105                           0, /* y */
106                           rect.right - rect.left, /* width */
107                           rect.bottom - rect.top, /* height */
108                           NULL,
109                           NULL,
110                           NULL,
111                           NULL);
112     ShowWindow(hWnd, SW_SHOW);
113     return hWnd;
114 }
115
116
117 void
118 resizeWindow(HWND hWnd, int width, int height) {
119     RECT rClient;
120     GetClientRect(hWnd, &rClient);
121     if (width  == rClient.right  - rClient.left &&
122         height == rClient.bottom - rClient.top) {
123         return;
124     }
125
126     RECT rWindow;
127     GetWindowRect(hWnd, &rWindow);
128     width  += (rWindow.right  - rWindow.left) - rClient.right;
129     height += (rWindow.bottom - rWindow.top)  - rClient.bottom;
130     SetWindowPos(hWnd, NULL, rWindow.left, rWindow.top, width, height, SWP_NOMOVE);
131 }
132
133
134 bool
135 processEvents(void) {
136     MSG uMsg;
137     while (PeekMessage(&uMsg, NULL, 0, 0, PM_REMOVE)) {
138         if (uMsg.message == WM_QUIT) {
139             return false;
140         }
141
142         if (!TranslateAccelerator(uMsg.hwnd, NULL, &uMsg)) {
143             TranslateMessage(&uMsg);
144             DispatchMessage(&uMsg);
145         }
146     }
147     return true;
148 }
149
150
151 } /* namespace d3dretrace */