1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 |
|
---|
8 | #define WIN32_LEAN_AND_MEAN
|
---|
9 | #include <windows.h>
|
---|
10 |
|
---|
11 | #include <stdlib.h>
|
---|
12 | #include <stdio.h>
|
---|
13 | #include <memory.h>
|
---|
14 |
|
---|
15 | #include "cr_environment.h"
|
---|
16 | #include "cr_error.h"
|
---|
17 | #include "cr_string.h"
|
---|
18 | #include "renderspu.h"
|
---|
19 | #include "cr_mem.h"
|
---|
20 |
|
---|
21 |
|
---|
22 | /* IAT patcher stuff */
|
---|
23 | #define RVA2PTR(_t, _base, _off) ((_t*)(((uint8_t*)(_base)) + (_off)))
|
---|
24 |
|
---|
25 | int renderspuIatPatcherGetImportAddress(HMODULE hModule, LPCSTR pszLib, LPCSTR pszName, void** ppAdr)
|
---|
26 | {
|
---|
27 | PIMAGE_DOS_HEADER pDosHdr = (PIMAGE_DOS_HEADER)hModule;
|
---|
28 | PIMAGE_NT_HEADERS pNtHdr;
|
---|
29 | PIMAGE_IMPORT_DESCRIPTOR pImportDr;
|
---|
30 | DWORD rvaImport;
|
---|
31 |
|
---|
32 | crDebug("searching entry %s from %s", pszName, pszLib);
|
---|
33 |
|
---|
34 | *ppAdr = 0;
|
---|
35 |
|
---|
36 | if (pDosHdr->e_magic != IMAGE_DOS_SIGNATURE)
|
---|
37 | {
|
---|
38 | crWarning("invalid dos signature");
|
---|
39 | return VERR_INVALID_HANDLE;
|
---|
40 | }
|
---|
41 | pNtHdr = RVA2PTR(IMAGE_NT_HEADERS, pDosHdr, pDosHdr->e_lfanew);
|
---|
42 | if (pNtHdr->Signature != IMAGE_NT_SIGNATURE)
|
---|
43 | {
|
---|
44 | crWarning("invalid nt signature");
|
---|
45 | return VERR_INVALID_HANDLE;
|
---|
46 | }
|
---|
47 | rvaImport = pNtHdr->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
|
---|
48 | if (!rvaImport)
|
---|
49 | {
|
---|
50 | crWarning("no imports found");
|
---|
51 | return VERR_NOT_FOUND;
|
---|
52 | }
|
---|
53 | pImportDr = RVA2PTR(IMAGE_IMPORT_DESCRIPTOR, pDosHdr, rvaImport);
|
---|
54 |
|
---|
55 | for ( ;pImportDr->TimeDateStamp != 0 || pImportDr->Name != 0; ++pImportDr)
|
---|
56 | {
|
---|
57 | DWORD rvaINT, rvaIAT;
|
---|
58 | PIMAGE_THUNK_DATA pINT, pIAT;
|
---|
59 | LPCSTR pszLibCur = RVA2PTR(char, pDosHdr, pImportDr->Name);
|
---|
60 | if (stricmp(pszLibCur, pszLib))
|
---|
61 | continue;
|
---|
62 |
|
---|
63 | /* got the necessary lib! */
|
---|
64 | crDebug("got info for lib");
|
---|
65 |
|
---|
66 | rvaINT = pImportDr->OriginalFirstThunk;
|
---|
67 | rvaIAT = pImportDr->FirstThunk;
|
---|
68 |
|
---|
69 | if (!rvaINT || !rvaIAT)
|
---|
70 | {
|
---|
71 | crWarning("either rvaINT(0x%x) or rvaIAT(0x%x) are NULL, nothing found!", rvaINT, rvaIAT);
|
---|
72 | return VERR_NOT_FOUND;
|
---|
73 | }
|
---|
74 |
|
---|
75 | pINT = RVA2PTR(IMAGE_THUNK_DATA, pDosHdr, rvaINT);
|
---|
76 | pIAT = RVA2PTR(IMAGE_THUNK_DATA, pDosHdr, rvaIAT);
|
---|
77 |
|
---|
78 | for ( ; pINT->u1.AddressOfData; ++pINT, ++pIAT)
|
---|
79 | {
|
---|
80 | PIMAGE_IMPORT_BY_NAME pIbn;
|
---|
81 |
|
---|
82 | if (IMAGE_SNAP_BY_ORDINAL(pINT->u1.Ordinal))
|
---|
83 | continue;
|
---|
84 |
|
---|
85 | pIbn = RVA2PTR(IMAGE_IMPORT_BY_NAME, pDosHdr, pINT->u1.AddressOfData);
|
---|
86 |
|
---|
87 | if (stricmp(pszName, (char*)pIbn->Name))
|
---|
88 | continue;
|
---|
89 |
|
---|
90 | *ppAdr = &pIAT->u1.Function;
|
---|
91 |
|
---|
92 | crDebug("search succeeded!");
|
---|
93 | return VINF_SUCCESS;
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | crDebug("not found");
|
---|
98 | return VERR_NOT_FOUND;
|
---|
99 | }
|
---|
100 |
|
---|
101 | int renderspuIatPatcherPatchEntry(void *pvEntry, void *pvValue, void **ppvOldVal)
|
---|
102 | {
|
---|
103 | void **ppfn = (void**)pvEntry;
|
---|
104 | DWORD dwOldProtect = 0;
|
---|
105 |
|
---|
106 | if (!VirtualProtect(pvEntry, sizeof (pvEntry), PAGE_READWRITE, &dwOldProtect))
|
---|
107 | {
|
---|
108 | crWarning("VirtualProtect 1 failed, %d", GetLastError());
|
---|
109 | return VERR_ACCESS_DENIED;
|
---|
110 | }
|
---|
111 |
|
---|
112 | if (ppvOldVal)
|
---|
113 | *ppvOldVal = *ppfn;
|
---|
114 | *ppfn = pvValue;
|
---|
115 |
|
---|
116 | if (!VirtualProtect(pvEntry, sizeof (pvEntry), dwOldProtect, &dwOldProtect))
|
---|
117 | {
|
---|
118 | crWarning("VirtualProtect 2 failed, %d.. ignoring", GetLastError());
|
---|
119 | }
|
---|
120 |
|
---|
121 | return VINF_SUCCESS;
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | int renderspuIatPatcherPatchFunction(HMODULE hModule, LPCSTR pszLib, LPCSTR pszName, void* pfn)
|
---|
126 | {
|
---|
127 | void* pAdr;
|
---|
128 | int rc = renderspuIatPatcherGetImportAddress(hModule, pszLib, pszName, &pAdr);
|
---|
129 | if (RT_FAILURE(rc))
|
---|
130 | {
|
---|
131 | crDebug("renderspuIatPatcherGetImportAddress failed, %d", rc);
|
---|
132 | return rc;
|
---|
133 | }
|
---|
134 |
|
---|
135 | rc = renderspuIatPatcherPatchEntry(pAdr, pfn, NULL);
|
---|
136 | if (RT_FAILURE(rc))
|
---|
137 | {
|
---|
138 | crWarning("renderspuIatPatcherPatchEntry failed, %d", rc);
|
---|
139 | return rc;
|
---|
140 | }
|
---|
141 |
|
---|
142 | return VINF_SUCCESS;
|
---|
143 | }
|
---|
144 |
|
---|
145 | /* patch */
|
---|
146 | static HWND __stdcall renderspuAtiQuirk_GetForegroundWindow()
|
---|
147 | {
|
---|
148 | crDebug("renderspuAtiQuirk_GetForegroundWindow");
|
---|
149 | return NULL;
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 | #define CRREG_MAXKEYNAME 8
|
---|
154 | static int renderspuAtiQuirk_GetICDDriverList(char *pBuf, DWORD cbBuf, DWORD *pcbResult)
|
---|
155 | {
|
---|
156 | static LPCSTR aValueNames[] = {"OpenGLVendorName", "OpenGLDriverName"};
|
---|
157 | char *pBufPos = pBuf;
|
---|
158 | DWORD cbBufRemain = cbBuf, cbTotal = 0;
|
---|
159 | HKEY hKey, hSubkey;
|
---|
160 | DWORD dwIndex = 0;
|
---|
161 | int i;
|
---|
162 | int rc = VINF_SUCCESS;
|
---|
163 | char NameBuf[CRREG_MAXKEYNAME];
|
---|
164 | LONG lRc;
|
---|
165 |
|
---|
166 | if (pcbResult)
|
---|
167 | *pcbResult = 0;
|
---|
168 |
|
---|
169 | lRc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
---|
170 | "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E968-E325-11CE-BFC1-08002BE10318}",
|
---|
171 | 0, /* reserved*/
|
---|
172 | KEY_READ,
|
---|
173 | &hKey);
|
---|
174 | if (ERROR_SUCCESS != lRc)
|
---|
175 | {
|
---|
176 | crDebug("RegOpenKeyEx 1 failed, %d", lRc);
|
---|
177 | return VERR_OPEN_FAILED;
|
---|
178 | }
|
---|
179 |
|
---|
180 | for ( ; ; ++dwIndex)
|
---|
181 | {
|
---|
182 | lRc = RegEnumKeyA(hKey, dwIndex, NameBuf, CRREG_MAXKEYNAME);
|
---|
183 | if (lRc == ERROR_NO_MORE_ITEMS)
|
---|
184 | break;
|
---|
185 | if (lRc == ERROR_MORE_DATA)
|
---|
186 | continue;
|
---|
187 | if (lRc != ERROR_SUCCESS)
|
---|
188 | {
|
---|
189 | crWarning("RegEnumKeyA failed, %d", lRc);
|
---|
190 | continue;
|
---|
191 | }
|
---|
192 |
|
---|
193 | lRc = RegOpenKeyEx(hKey,
|
---|
194 | NameBuf,
|
---|
195 | 0, /* reserved*/
|
---|
196 | KEY_READ,
|
---|
197 | &hSubkey);
|
---|
198 | if (ERROR_SUCCESS != lRc)
|
---|
199 | {
|
---|
200 | crDebug("RegOpenKeyEx 2 failed, %d", lRc);
|
---|
201 | RegCloseKey(hKey);
|
---|
202 | return VERR_OPEN_FAILED;
|
---|
203 | }
|
---|
204 |
|
---|
205 | for (i = 0; i < RT_ELEMENTS(aValueNames); ++i)
|
---|
206 | {
|
---|
207 | DWORD cbCur = cbBufRemain;
|
---|
208 | DWORD type;
|
---|
209 | lRc = RegQueryValueExA(hSubkey, aValueNames[i], NULL, /* reserved*/
|
---|
210 | &type,
|
---|
211 | (PBYTE)pBufPos, &cbCur);
|
---|
212 | /* exclude second null termination */
|
---|
213 | --cbCur;
|
---|
214 |
|
---|
215 | if (ERROR_MORE_DATA == lRc)
|
---|
216 | {
|
---|
217 | if (REG_MULTI_SZ != type)
|
---|
218 | {
|
---|
219 | crWarning("unexpected data type! %d", type);
|
---|
220 | continue;
|
---|
221 | }
|
---|
222 | rc = VERR_BUFFER_OVERFLOW;
|
---|
223 | pBufPos = NULL;
|
---|
224 | cbBufRemain = 0;
|
---|
225 | CRASSERT(cbCur > 0 && cbCur < UINT32_MAX/2);
|
---|
226 | cbTotal += cbCur;
|
---|
227 | continue;
|
---|
228 | }
|
---|
229 | if (ERROR_SUCCESS != lRc)
|
---|
230 | {
|
---|
231 | crDebug("RegQueryValueExA failed, %d", lRc);
|
---|
232 | continue;
|
---|
233 | }
|
---|
234 |
|
---|
235 | if (REG_MULTI_SZ != type)
|
---|
236 | {
|
---|
237 | crWarning("unexpected data type! %d", type);
|
---|
238 | continue;
|
---|
239 | }
|
---|
240 |
|
---|
241 | /* succeeded */
|
---|
242 | CRASSERT(cbCur > 0 && cbCur < UINT32_MAX/2);
|
---|
243 | pBufPos += cbCur;
|
---|
244 | cbBufRemain -= cbCur;
|
---|
245 | cbTotal += cbCur;
|
---|
246 | CRASSERT(cbBufRemain < UINT32_MAX/2);
|
---|
247 | }
|
---|
248 |
|
---|
249 | RegCloseKey(hSubkey);
|
---|
250 | }
|
---|
251 |
|
---|
252 | RegCloseKey(hKey);
|
---|
253 |
|
---|
254 | if (cbTotal)
|
---|
255 | {
|
---|
256 | /* include second null termination */
|
---|
257 | CRASSERT(!pBufPos || pBufPos[0] == '\0');
|
---|
258 | ++cbTotal;
|
---|
259 | }
|
---|
260 |
|
---|
261 | if (pcbResult)
|
---|
262 | *pcbResult = cbTotal;
|
---|
263 |
|
---|
264 | return rc;
|
---|
265 | }
|
---|
266 |
|
---|
267 | static int renderspuAtiQuirk_ApplyForModule(LPCSTR pszAtiDll)
|
---|
268 | {
|
---|
269 | int rc;
|
---|
270 | HMODULE hAtiDll;
|
---|
271 |
|
---|
272 | crDebug("renderspuAtiQuirk_ApplyForModule (%s)", pszAtiDll);
|
---|
273 |
|
---|
274 | hAtiDll = GetModuleHandleA(pszAtiDll);
|
---|
275 | if (!hAtiDll)
|
---|
276 | {
|
---|
277 | crDebug("GetModuleHandle failed, %d", GetLastError());
|
---|
278 | return VERR_NOT_FOUND;
|
---|
279 | }
|
---|
280 |
|
---|
281 | rc = renderspuIatPatcherPatchFunction(hAtiDll, "user32.dll", "GetForegroundWindow", (void*)renderspuAtiQuirk_GetForegroundWindow);
|
---|
282 | if (RT_FAILURE(rc))
|
---|
283 | {
|
---|
284 | crDebug("renderspuIatPatcherPatchFunction failed, %d", rc);
|
---|
285 | return rc;
|
---|
286 | }
|
---|
287 |
|
---|
288 | crDebug("renderspuAtiQuirk_ApplyForModule SUCCEEDED!");
|
---|
289 | crInfo("ATI Fullscreen qwirk SUCCEEDED!");
|
---|
290 |
|
---|
291 | return VINF_SUCCESS;
|
---|
292 | }
|
---|
293 |
|
---|
294 | static LPCSTR renderspuRegMultiSzNextVal(LPCSTR pszBuf)
|
---|
295 | {
|
---|
296 | pszBuf += strlen(pszBuf) + sizeof (pszBuf[0]);
|
---|
297 |
|
---|
298 | if (pszBuf[0] == '\0')
|
---|
299 | return NULL;
|
---|
300 |
|
---|
301 | return pszBuf;
|
---|
302 | }
|
---|
303 |
|
---|
304 | static LPCSTR renderspuRegMultiSzCurVal(LPCSTR pszBuf)
|
---|
305 | {
|
---|
306 | if (pszBuf[0] == '\0')
|
---|
307 | return NULL;
|
---|
308 |
|
---|
309 | return pszBuf;
|
---|
310 | }
|
---|
311 |
|
---|
312 |
|
---|
313 | static int renderspuAtiQuirk_Apply()
|
---|
314 | {
|
---|
315 | char aBuf[4096];
|
---|
316 | DWORD cbResult = 0;
|
---|
317 | LPCSTR pszVal;
|
---|
318 | int rc;
|
---|
319 |
|
---|
320 | crDebug("renderspuAtiQuirk_Apply..");
|
---|
321 |
|
---|
322 | rc = renderspuAtiQuirk_GetICDDriverList(aBuf, sizeof (aBuf), &cbResult);
|
---|
323 | if (RT_FAILURE(rc))
|
---|
324 | {
|
---|
325 | crDebug("renderspuAtiQuirk_GetICDDriverList failed, rc(%d)", rc);
|
---|
326 | return rc;
|
---|
327 | }
|
---|
328 |
|
---|
329 | for (pszVal = renderspuRegMultiSzCurVal(aBuf);
|
---|
330 | pszVal;
|
---|
331 | pszVal = renderspuRegMultiSzNextVal(pszVal))
|
---|
332 | {
|
---|
333 | renderspuAtiQuirk_ApplyForModule(pszVal);
|
---|
334 | }
|
---|
335 |
|
---|
336 | return VINF_SUCCESS;
|
---|
337 | }
|
---|
338 |
|
---|
339 | static GLboolean renderspuAtiQuirk_Needed()
|
---|
340 | {
|
---|
341 | const char * pszString = render_spu.ws.glGetString(GL_VENDOR);
|
---|
342 | if (pszString && strstr(pszString, "ATI"))
|
---|
343 | return GL_TRUE;
|
---|
344 | pszString = render_spu.ws.glGetString(GL_RENDERER);
|
---|
345 | if (pszString && strstr(pszString, "ATI"))
|
---|
346 | return GL_TRUE;
|
---|
347 | return GL_FALSE;
|
---|
348 | }
|
---|
349 |
|
---|
350 | static void renderspuAtiQuirk_ChkApply()
|
---|
351 | {
|
---|
352 | static GLboolean fChecked = GL_FALSE;
|
---|
353 | if (fChecked)
|
---|
354 | return;
|
---|
355 |
|
---|
356 | fChecked = GL_TRUE;
|
---|
357 | if (!renderspuAtiQuirk_Needed())
|
---|
358 | return;
|
---|
359 |
|
---|
360 | crInfo("This is an ATI card, taking care of fullscreen..");
|
---|
361 |
|
---|
362 | /*
|
---|
363 | * ATI WDDM-based graphics have an issue with rendering fullscreen.
|
---|
364 | * See public tickets #9775 & #9267 .
|
---|
365 | * Namely ATI drivers check whether ogl window is foreground and fullscreen
|
---|
366 | * and if so - do D3DKMTSetDisplayMode for ogl surface,
|
---|
367 | * which prevented any other data from being displayed, no matter what.
|
---|
368 | *
|
---|
369 | * Here we check whether we're using an ATI card and if so, patch the ogl ICD driver's IAT
|
---|
370 | * to replace GetForegroundWindow reference with our renderspuAtiQuirk_GetForegroundWindow,
|
---|
371 | * which always returns NULL.
|
---|
372 | */
|
---|
373 | renderspuAtiQuirk_Apply();
|
---|
374 | }
|
---|
375 |
|
---|
376 | #define WINDOW_NAME window->title
|
---|
377 |
|
---|
378 | static BOOL
|
---|
379 | bSetupPixelFormat( HDC hdc, GLbitfield visAttribs );
|
---|
380 |
|
---|
381 | GLboolean renderspu_SystemInitVisual( VisualInfo *visual )
|
---|
382 | {
|
---|
383 | if (visual->visAttribs & CR_PBUFFER_BIT) {
|
---|
384 | crWarning("Render SPU: PBuffers not support on Windows yet.");
|
---|
385 | }
|
---|
386 |
|
---|
387 | /* In the windows world, we need a window before a context.
|
---|
388 | * Use the device_context as a marker to do just that */
|
---|
389 |
|
---|
390 | return TRUE;
|
---|
391 | }
|
---|
392 |
|
---|
393 | void renderspu_SystemDestroyWindow( WindowInfo *window )
|
---|
394 | {
|
---|
395 | VBOX_RENDERSPU_DESTROY_WINDOW vrdw;
|
---|
396 |
|
---|
397 | CRASSERT(window);
|
---|
398 |
|
---|
399 | /*DestroyWindow( window->hWnd );*/
|
---|
400 |
|
---|
401 | vrdw.hWnd = window->hWnd;
|
---|
402 |
|
---|
403 | if (render_spu.dwWinThreadId)
|
---|
404 | {
|
---|
405 | PostThreadMessage(render_spu.dwWinThreadId, WM_VBOX_RENDERSPU_DESTROY_WINDOW, 0, (LPARAM) &vrdw);
|
---|
406 | WaitForSingleObject(render_spu.hWinThreadReadyEvent, INFINITE);
|
---|
407 | }
|
---|
408 | else
|
---|
409 | {
|
---|
410 | crError("Render SPU: window thread is not running");
|
---|
411 | }
|
---|
412 |
|
---|
413 | window->hWnd = NULL;
|
---|
414 | window->visual = NULL;
|
---|
415 | if (window->hRgn)
|
---|
416 | {
|
---|
417 | DeleteObject(window->hRgn);
|
---|
418 | window->hRgn = NULL;
|
---|
419 | }
|
---|
420 | }
|
---|
421 |
|
---|
422 | static LONG WINAPI
|
---|
423 | MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
|
---|
424 | {
|
---|
425 | /* int w,h; */
|
---|
426 |
|
---|
427 | switch ( uMsg ) {
|
---|
428 | case WM_PAINT:
|
---|
429 | {
|
---|
430 | WindowInfo *pWindow = (WindowInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
|
---|
431 | if (pWindow)
|
---|
432 | {
|
---|
433 | struct VBOXVR_SCR_COMPOSITOR * pCompositor;
|
---|
434 |
|
---|
435 | pCompositor = renderspuVBoxCompositorAcquire(pWindow);
|
---|
436 | if (pCompositor)
|
---|
437 | {
|
---|
438 | HDC hDC;
|
---|
439 | PAINTSTRUCT Paint;
|
---|
440 |
|
---|
441 | Assert(pWindow->device_context);
|
---|
442 | hDC = BeginPaint(pWindow->hWnd, &Paint);
|
---|
443 | if (hDC)
|
---|
444 | {
|
---|
445 | BOOL bRc;
|
---|
446 | pWindow->redraw_device_context = hDC;
|
---|
447 |
|
---|
448 | renderspuVBoxPresentCompositionGeneric(pWindow, pCompositor, NULL, 1);
|
---|
449 | renderspuVBoxCompositorRelease(pWindow);
|
---|
450 |
|
---|
451 | bRc = EndPaint(pWindow->hWnd, &Paint);
|
---|
452 | if (!bRc)
|
---|
453 | {
|
---|
454 | DWORD winEr = GetLastError();
|
---|
455 | crWarning("EndPaint failed, winEr %d", winEr);
|
---|
456 | }
|
---|
457 |
|
---|
458 | pWindow->redraw_device_context = NULL;
|
---|
459 | }
|
---|
460 | else
|
---|
461 | {
|
---|
462 | DWORD winEr = GetLastError();
|
---|
463 | crWarning("BeginPaint failed, winEr %d", winEr);
|
---|
464 | }
|
---|
465 | }
|
---|
466 | }
|
---|
467 | break;
|
---|
468 | }
|
---|
469 | case WM_SIZE:
|
---|
470 | /* w = LOWORD( lParam );
|
---|
471 | * h = HIWORD( lParam ); */
|
---|
472 |
|
---|
473 | /* glViewport( 0, 0, w, h ); */
|
---|
474 | #if 0
|
---|
475 | glViewport( -render_spu.mural_x, -render_spu.mural_y,
|
---|
476 | render_spu.mural_width, render_spu.mural_height );
|
---|
477 | glScissor( -render_spu.mural_x, -render_spu.mural_y,
|
---|
478 | render_spu.mural_width, render_spu.mural_height );
|
---|
479 | #endif
|
---|
480 | break;
|
---|
481 |
|
---|
482 | case WM_CLOSE:
|
---|
483 | crWarning( "Render SPU: caught WM_CLOSE -- quitting." );
|
---|
484 | exit( 0 );
|
---|
485 | break;
|
---|
486 |
|
---|
487 | case WM_DESTROY:
|
---|
488 | crDebug("Render SPU: caught WM_DESTROY for our window %x", hWnd);
|
---|
489 | break;
|
---|
490 |
|
---|
491 | case WM_NCHITTEST:
|
---|
492 | crDebug("WM_NCHITTEST");
|
---|
493 | return HTNOWHERE;
|
---|
494 | }
|
---|
495 |
|
---|
496 | return DefWindowProc( hWnd, uMsg, wParam, lParam );
|
---|
497 | }
|
---|
498 |
|
---|
499 | static BOOL
|
---|
500 | bSetupPixelFormatEXT( HDC hdc, GLbitfield visAttribs)
|
---|
501 | {
|
---|
502 | PIXELFORMATDESCRIPTOR ppfd;
|
---|
503 | int pixelFormat;
|
---|
504 | int attribList[100];
|
---|
505 | float fattribList[] = { 0.0, 0.0 };
|
---|
506 | int numFormats;
|
---|
507 | int i = 0;
|
---|
508 | BOOL vis;
|
---|
509 |
|
---|
510 | CRASSERT(visAttribs & CR_RGB_BIT); /* anybody need color index */
|
---|
511 |
|
---|
512 | crWarning("Render SPU: Using WGL_EXT_pixel_format to select visual ID.");
|
---|
513 |
|
---|
514 | attribList[i++] = WGL_DRAW_TO_WINDOW_EXT;
|
---|
515 | attribList[i++] = GL_TRUE;
|
---|
516 | attribList[i++] = WGL_ACCELERATION_EXT;
|
---|
517 | attribList[i++] = WGL_FULL_ACCELERATION_EXT;
|
---|
518 | attribList[i++] = WGL_COLOR_BITS_EXT;
|
---|
519 | attribList[i++] = 24;
|
---|
520 | attribList[i++] = WGL_RED_BITS_EXT;
|
---|
521 | attribList[i++] = 1;
|
---|
522 | attribList[i++] = WGL_GREEN_BITS_EXT;
|
---|
523 | attribList[i++] = 1;
|
---|
524 | attribList[i++] = WGL_BLUE_BITS_EXT;
|
---|
525 | attribList[i++] = 1;
|
---|
526 |
|
---|
527 | crWarning("Render SPU: Visual chosen is... RGB");
|
---|
528 |
|
---|
529 | if (visAttribs & CR_ALPHA_BIT)
|
---|
530 | {
|
---|
531 | attribList[i++] = WGL_ALPHA_BITS_EXT;
|
---|
532 | attribList[i++] = 1;
|
---|
533 | crWarning("A");
|
---|
534 | }
|
---|
535 |
|
---|
536 | crWarning(", ");
|
---|
537 |
|
---|
538 | if (visAttribs & CR_DOUBLE_BIT) {
|
---|
539 | attribList[i++] = WGL_DOUBLE_BUFFER_EXT;
|
---|
540 | attribList[i++] = GL_TRUE;
|
---|
541 | crWarning("DB, ");
|
---|
542 | }
|
---|
543 |
|
---|
544 | if (visAttribs & CR_STEREO_BIT) {
|
---|
545 | attribList[i++] = WGL_STEREO_EXT;
|
---|
546 | attribList[i++] = GL_TRUE;
|
---|
547 | crWarning("Stereo, ");
|
---|
548 | }
|
---|
549 |
|
---|
550 | if (visAttribs & CR_DEPTH_BIT)
|
---|
551 | {
|
---|
552 | attribList[i++] = WGL_DEPTH_BITS_EXT;
|
---|
553 | attribList[i++] = 1;
|
---|
554 | crWarning("Z, ");
|
---|
555 | }
|
---|
556 |
|
---|
557 | if (visAttribs & CR_STENCIL_BIT)
|
---|
558 | {
|
---|
559 | attribList[i++] = WGL_STENCIL_BITS_EXT;
|
---|
560 | attribList[i++] = 1;
|
---|
561 | crWarning("Stencil, ");
|
---|
562 | }
|
---|
563 |
|
---|
564 | if (visAttribs & CR_ACCUM_BIT)
|
---|
565 | {
|
---|
566 | attribList[i++] = WGL_ACCUM_RED_BITS_EXT;
|
---|
567 | attribList[i++] = 1;
|
---|
568 | attribList[i++] = WGL_ACCUM_GREEN_BITS_EXT;
|
---|
569 | attribList[i++] = 1;
|
---|
570 | attribList[i++] = WGL_ACCUM_BLUE_BITS_EXT;
|
---|
571 | attribList[i++] = 1;
|
---|
572 | crWarning("Accum, ");
|
---|
573 | if (visAttribs & CR_ALPHA_BIT)
|
---|
574 | {
|
---|
575 | attribList[i++] = WGL_ACCUM_ALPHA_BITS_EXT;
|
---|
576 | attribList[i++] = 1;
|
---|
577 | crWarning("Accum Alpha, ");
|
---|
578 | }
|
---|
579 | }
|
---|
580 |
|
---|
581 | if (visAttribs & CR_MULTISAMPLE_BIT)
|
---|
582 | {
|
---|
583 | attribList[i++] = WGL_SAMPLE_BUFFERS_EXT;
|
---|
584 | attribList[i++] = 1;
|
---|
585 | attribList[i++] = WGL_SAMPLES_EXT;
|
---|
586 | attribList[i++] = 4;
|
---|
587 | crWarning("Multisample, ");
|
---|
588 | }
|
---|
589 |
|
---|
590 | crWarning("\n");
|
---|
591 |
|
---|
592 | /* End the list */
|
---|
593 | attribList[i++] = 0;
|
---|
594 | attribList[i++] = 0;
|
---|
595 |
|
---|
596 | vis = render_spu.ws.wglChoosePixelFormatEXT( hdc, attribList, fattribList, 1, &pixelFormat, &numFormats);
|
---|
597 |
|
---|
598 | crDebug("Render SPU: wglChoosePixelFormatEXT (vis 0x%x, LastError 0x%x, pixelFormat 0x%x", vis, GetLastError(), pixelFormat);
|
---|
599 |
|
---|
600 | #ifdef VBOX_CR_SERVER_FORCE_WGL
|
---|
601 | render_spu.ws.wglSetPixelFormat( hdc, pixelFormat, &ppfd );
|
---|
602 | #else
|
---|
603 | SetPixelFormat( hdc, pixelFormat, &ppfd );
|
---|
604 | #endif
|
---|
605 |
|
---|
606 | crDebug("Render SPU: wglSetPixelFormat (Last error 0x%x)", GetLastError());
|
---|
607 |
|
---|
608 | return vis;
|
---|
609 | }
|
---|
610 |
|
---|
611 | static BOOL
|
---|
612 | bSetupPixelFormatNormal( HDC hdc, GLbitfield visAttribs )
|
---|
613 | {
|
---|
614 | PIXELFORMATDESCRIPTOR pfd = {
|
---|
615 | sizeof(PIXELFORMATDESCRIPTOR), /* size of this pfd */
|
---|
616 | 1, /* version number */
|
---|
617 | PFD_DRAW_TO_WINDOW | /* support window */
|
---|
618 | PFD_SUPPORT_OPENGL, /* support OpenGL */
|
---|
619 | PFD_TYPE_RGBA, /* RGBA type */
|
---|
620 | 24, /* 24-bit color depth */
|
---|
621 | 0, 0, 0, 0, 0, 0, /* color bits ignored */
|
---|
622 | 0, /* no alpha buffer */
|
---|
623 | 0, /* shift bit ignored */
|
---|
624 | 0, /* no accumulation buffer */
|
---|
625 | 0, 0, 0, 0, /* accum bits ignored */
|
---|
626 | 0, /* set depth buffer */
|
---|
627 | 0, /* set stencil buffer */
|
---|
628 | 0, /* no auxiliary buffer */
|
---|
629 | PFD_MAIN_PLANE, /* main layer */
|
---|
630 | 0, /* reserved */
|
---|
631 | 0, 0, 0 /* layer masks ignored */
|
---|
632 | };
|
---|
633 | PIXELFORMATDESCRIPTOR *ppfd = &pfd;
|
---|
634 | char s[1000];
|
---|
635 | GLbitfield b = 0;
|
---|
636 | int pixelformat;
|
---|
637 |
|
---|
638 | renderspuMakeVisString( visAttribs, s );
|
---|
639 |
|
---|
640 | crDebug( "Render SPU: WGL wants these visual capabilities: %s", s);
|
---|
641 |
|
---|
642 | /* These really come into play with sort-last configs */
|
---|
643 | if (visAttribs & CR_DEPTH_BIT)
|
---|
644 | ppfd->cDepthBits = 24;
|
---|
645 | if (visAttribs & CR_ACCUM_BIT)
|
---|
646 | ppfd->cAccumBits = 16;
|
---|
647 | if (visAttribs & CR_RGB_BIT)
|
---|
648 | ppfd->cColorBits = 24;
|
---|
649 | if (visAttribs & CR_STENCIL_BIT)
|
---|
650 | ppfd->cStencilBits = 8;
|
---|
651 | if (visAttribs & CR_ALPHA_BIT)
|
---|
652 | ppfd->cAlphaBits = 8;
|
---|
653 | if (visAttribs & CR_DOUBLE_BIT)
|
---|
654 | ppfd->dwFlags |= PFD_DOUBLEBUFFER;
|
---|
655 | if (visAttribs & CR_STEREO_BIT)
|
---|
656 | ppfd->dwFlags |= PFD_STEREO;
|
---|
657 |
|
---|
658 | /*
|
---|
659 | * We call the wgl functions directly if the SPU was loaded
|
---|
660 | * by our faker library, otherwise we have to call the GDI
|
---|
661 | * versions.
|
---|
662 | */
|
---|
663 | #ifdef VBOX_CR_SERVER_FORCE_WGL
|
---|
664 | if (crGetenv( "CR_WGL_DO_NOT_USE_GDI" ) != NULL)
|
---|
665 | {
|
---|
666 | pixelformat = render_spu.ws.wglChoosePixelFormat( hdc, ppfd );
|
---|
667 | /* doing this twice is normal Win32 magic */
|
---|
668 | pixelformat = render_spu.ws.wglChoosePixelFormat( hdc, ppfd );
|
---|
669 | if ( pixelformat == 0 )
|
---|
670 | {
|
---|
671 | crError( "render_spu.ws.wglChoosePixelFormat failed" );
|
---|
672 | }
|
---|
673 | if ( !render_spu.ws.wglSetPixelFormat( hdc, pixelformat, ppfd ) )
|
---|
674 | {
|
---|
675 | crError( "render_spu.ws.wglSetPixelFormat failed" );
|
---|
676 | }
|
---|
677 |
|
---|
678 | render_spu.ws.wglDescribePixelFormat( hdc, pixelformat, sizeof(*ppfd), ppfd );
|
---|
679 | }
|
---|
680 | else
|
---|
681 | #endif
|
---|
682 | {
|
---|
683 | /* Okay, we were loaded manually. Call the GDI functions. */
|
---|
684 | pixelformat = ChoosePixelFormat( hdc, ppfd );
|
---|
685 | /* doing this twice is normal Win32 magic */
|
---|
686 | pixelformat = ChoosePixelFormat( hdc, ppfd );
|
---|
687 | if ( pixelformat == 0 )
|
---|
688 | {
|
---|
689 | crError( "ChoosePixelFormat failed" );
|
---|
690 | }
|
---|
691 | if ( !SetPixelFormat( hdc, pixelformat, ppfd ) )
|
---|
692 | {
|
---|
693 | crError( "SetPixelFormat failed (Error 0x%x)", GetLastError() );
|
---|
694 | }
|
---|
695 |
|
---|
696 | DescribePixelFormat( hdc, pixelformat, sizeof(*ppfd), ppfd );
|
---|
697 | }
|
---|
698 |
|
---|
699 |
|
---|
700 | if (ppfd->cDepthBits > 0)
|
---|
701 | b |= CR_DEPTH_BIT;
|
---|
702 | if (ppfd->cAccumBits > 0)
|
---|
703 | b |= CR_ACCUM_BIT;
|
---|
704 | if (ppfd->cColorBits > 8)
|
---|
705 | b |= CR_RGB_BIT;
|
---|
706 | if (ppfd->cStencilBits > 0)
|
---|
707 | b |= CR_STENCIL_BIT;
|
---|
708 | if (ppfd->cAlphaBits > 0)
|
---|
709 | b |= CR_ALPHA_BIT;
|
---|
710 | if (ppfd->dwFlags & PFD_DOUBLEBUFFER)
|
---|
711 | b |= CR_DOUBLE_BIT;
|
---|
712 | if (ppfd->dwFlags & PFD_STEREO)
|
---|
713 | b |= CR_STEREO_BIT;
|
---|
714 |
|
---|
715 | renderspuMakeVisString( b, s );
|
---|
716 |
|
---|
717 | crDebug( "Render SPU: WGL chose these visual capabilities: %s", s);
|
---|
718 | return TRUE;
|
---|
719 | }
|
---|
720 |
|
---|
721 | static BOOL
|
---|
722 | bSetupPixelFormat( HDC hdc, GLbitfield visAttribs )
|
---|
723 | {
|
---|
724 | /* According to http://www.opengl.org/resources/faq/technical/mswindows.htm
|
---|
725 | we shouldn't be using wgl functions to setup pixel formats unless we're loading ICD driver.
|
---|
726 | In particular, bSetupPixelFormatEXT bugs with Intel drivers.
|
---|
727 | */
|
---|
728 | return bSetupPixelFormatNormal(hdc, visAttribs);
|
---|
729 | }
|
---|
730 |
|
---|
731 | GLboolean renderspu_SystemCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window )
|
---|
732 | {
|
---|
733 | HDESK desktop;
|
---|
734 | HINSTANCE hinstance;
|
---|
735 | WNDCLASS wc;
|
---|
736 | DWORD window_style;
|
---|
737 | int window_plus_caption_width;
|
---|
738 | int window_plus_caption_height;
|
---|
739 |
|
---|
740 | window->hRgn = NULL;
|
---|
741 | window->visual = visual;
|
---|
742 | window->nativeWindow = 0;
|
---|
743 |
|
---|
744 | if ( render_spu.use_L2 )
|
---|
745 | {
|
---|
746 | crWarning( "Going fullscreen because we think we're using Lightning-2." );
|
---|
747 | render_spu.fullscreen = 1;
|
---|
748 | }
|
---|
749 |
|
---|
750 | /*
|
---|
751 | * Begin Windows / WGL code
|
---|
752 | */
|
---|
753 |
|
---|
754 | hinstance = GetModuleHandle( NULL );
|
---|
755 | if (!hinstance)
|
---|
756 | {
|
---|
757 | crError( "Render SPU: Couldn't get a handle to my module." );
|
---|
758 | return GL_FALSE;
|
---|
759 | }
|
---|
760 | crDebug( "Render SPU: Got the module handle: 0x%x", hinstance );
|
---|
761 |
|
---|
762 | /* If we were launched from a service, telnet, or rsh, we need to
|
---|
763 | * get the input desktop. */
|
---|
764 |
|
---|
765 | desktop = OpenInputDesktop( 0, FALSE,
|
---|
766 | DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
|
---|
767 | DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
|
---|
768 | DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
|
---|
769 | DESKTOP_SWITCHDESKTOP | GENERIC_WRITE );
|
---|
770 |
|
---|
771 | if ( !desktop )
|
---|
772 | {
|
---|
773 | crError( "Render SPU: Couldn't acquire input desktop" );
|
---|
774 | return GL_FALSE;
|
---|
775 | }
|
---|
776 | crDebug( "Render SPU: Got the desktop: 0x%x", desktop );
|
---|
777 |
|
---|
778 | if ( !SetThreadDesktop( desktop ) )
|
---|
779 | {
|
---|
780 | /* If this function fails, it's probably because
|
---|
781 | * it's already been called (i.e., the render SPU
|
---|
782 | * is bolted to an application?) */
|
---|
783 |
|
---|
784 | /*crError( "Couldn't set thread to input desktop" ); */
|
---|
785 | }
|
---|
786 | crDebug( "Render SPU: Set the thread desktop -- this might have failed." );
|
---|
787 |
|
---|
788 | if ( !GetClassInfo(hinstance, WINDOW_NAME, &wc) )
|
---|
789 | {
|
---|
790 | wc.style = CS_OWNDC;
|
---|
791 | wc.lpfnWndProc = (WNDPROC) MainWndProc;
|
---|
792 | wc.cbClsExtra = 0;
|
---|
793 | wc.cbWndExtra = 0;
|
---|
794 | wc.hInstance = hinstance;
|
---|
795 | wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
|
---|
796 | wc.hCursor = LoadCursor( NULL, IDC_ARROW );
|
---|
797 | wc.hbrBackground = NULL;
|
---|
798 | wc.lpszMenuName = NULL;
|
---|
799 | wc.lpszClassName = WINDOW_NAME;
|
---|
800 |
|
---|
801 | if ( !RegisterClass( &wc ) )
|
---|
802 | {
|
---|
803 | crError( "Render SPU: Couldn't register window class -- you're not trying "
|
---|
804 | "to do multi-pipe stuff on windows, are you?\n\nNote --"
|
---|
805 | "This error message is from 1997 and probably doesn't make"
|
---|
806 | "any sense any more, but it's nostalgic for Humper." );
|
---|
807 | return GL_FALSE;
|
---|
808 | }
|
---|
809 | crDebug( "Render SPU: Registered the class" );
|
---|
810 | }
|
---|
811 | crDebug( "Render SPU: Got the class information" );
|
---|
812 |
|
---|
813 | /* Full screen window should be a popup (undecorated) window */
|
---|
814 | #if 1
|
---|
815 | window_style = ( render_spu.fullscreen ? WS_POPUP : WS_CAPTION );
|
---|
816 | #else
|
---|
817 | window_style = ( WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN );
|
---|
818 | window_style |= WS_SYSMENU;
|
---|
819 | #endif
|
---|
820 |
|
---|
821 | crDebug( "Render SPU: Fullscreen: %s", render_spu.fullscreen ? "yes" : "no");
|
---|
822 |
|
---|
823 | if ( render_spu.fullscreen )
|
---|
824 | {
|
---|
825 | #if 0
|
---|
826 |
|
---|
827 | int smCxFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME );
|
---|
828 | int smCyFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME ) + 1;
|
---|
829 | int smCyCaption = GetSystemMetrics( SM_CYCAPTION );
|
---|
830 |
|
---|
831 | window->BltInfo.width = GetSystemMetrics( SM_CXSCREEN ) ;
|
---|
832 | window->BltInfo.height = GetSystemMetrics( SM_CYSCREEN ) ;
|
---|
833 |
|
---|
834 | crDebug( "Render SPU: Window Dims: %d, %d", window->BltInfo.width, window->BltInfo.height );
|
---|
835 |
|
---|
836 | window->x = render_spu->defaultX - smCxFixedFrame - 1;
|
---|
837 | window->y = render_spu->defaultY - smCyFixedFrame - smCyCaption;
|
---|
838 |
|
---|
839 | window_plus_caption_width = window->BltInfo.width + 2 * smCxFixedFrame;
|
---|
840 | window_plus_caption_height = window->BltInfo.height + 2 * smCyFixedFrame + smCyCaption;
|
---|
841 |
|
---|
842 | #else
|
---|
843 | /* Since it's undecorated, we don't have to do anything fancy
|
---|
844 | * with these parameters. */
|
---|
845 |
|
---|
846 | window->BltInfo.width = GetSystemMetrics( SM_CXSCREEN ) ;
|
---|
847 | window->BltInfo.height = GetSystemMetrics( SM_CYSCREEN ) ;
|
---|
848 | window->x = 0;
|
---|
849 | window->y = 0;
|
---|
850 | window_plus_caption_width = window->BltInfo.width;
|
---|
851 | window_plus_caption_height = window->BltInfo.height;
|
---|
852 |
|
---|
853 | #endif
|
---|
854 | }
|
---|
855 | else
|
---|
856 | {
|
---|
857 | /* CreateWindow takes the size of the entire window, so we add
|
---|
858 | * in the size necessary for the frame and the caption. */
|
---|
859 |
|
---|
860 | int smCxFixedFrame, smCyFixedFrame, smCyCaption;
|
---|
861 | smCxFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME );
|
---|
862 | crDebug( "Render SPU: Got the X fixed frame" );
|
---|
863 | smCyFixedFrame = GetSystemMetrics( SM_CYFIXEDFRAME );
|
---|
864 | crDebug( "Render SPU: Got the Y fixed frame" );
|
---|
865 | smCyCaption = GetSystemMetrics( SM_CYCAPTION );
|
---|
866 | crDebug( "Render SPU: Got the Caption " );
|
---|
867 |
|
---|
868 | window_plus_caption_width = window->BltInfo.width + 2 * smCxFixedFrame;
|
---|
869 | window_plus_caption_height = window->BltInfo.height + 2 * smCyFixedFrame + smCyCaption;
|
---|
870 |
|
---|
871 | window->x = render_spu.defaultX - smCxFixedFrame;
|
---|
872 | window->y = render_spu.defaultY - smCyFixedFrame - smCyCaption;
|
---|
873 | }
|
---|
874 |
|
---|
875 | crDebug( "Render SPU: Creating the window: (%d,%d), (%d,%d)", render_spu.defaultX, render_spu.defaultY, window_plus_caption_width, window_plus_caption_height );
|
---|
876 | window->hWnd = CreateWindow( WINDOW_NAME, WINDOW_NAME,
|
---|
877 | window_style,
|
---|
878 | window->x, window->y,
|
---|
879 | window_plus_caption_width,
|
---|
880 | window_plus_caption_height,
|
---|
881 | NULL, NULL, hinstance, &render_spu );
|
---|
882 |
|
---|
883 | if ( !window->hWnd )
|
---|
884 | {
|
---|
885 | crError( "Render SPU: Create Window failed! That's almost certainly terrible." );
|
---|
886 | return GL_FALSE;
|
---|
887 | }
|
---|
888 |
|
---|
889 | window->visible = showIt;
|
---|
890 |
|
---|
891 | if (!showIt)
|
---|
892 | {
|
---|
893 | renderspu_SystemShowWindow( window, 0 );
|
---|
894 | if (window->BltInfo.height <= 0 || window->BltInfo.width <= 0)
|
---|
895 | {
|
---|
896 | renderspu_SystemWindowSize(window,
|
---|
897 | window->BltInfo.width > 0 ? window->BltInfo.width : 4,
|
---|
898 | window->BltInfo.height > 0 ? window->BltInfo.height : 4);
|
---|
899 | }
|
---|
900 | }
|
---|
901 | else
|
---|
902 | {
|
---|
903 | crDebug( "Render SPU: Showing the window" );
|
---|
904 | crDebug("renderspu_SystemCreateWindow: showwindow: %x", window->hWnd);
|
---|
905 | }
|
---|
906 |
|
---|
907 | CRASSERT(!window->visible == !showIt);
|
---|
908 |
|
---|
909 | /* Intel drivers require a window to be visible for proper 3D rendering,
|
---|
910 | * so set it visible and handle the visibility with visible regions (see below) */
|
---|
911 | ShowWindow( window->hWnd, SW_SHOWNORMAL );
|
---|
912 |
|
---|
913 | SetForegroundWindow( window->hWnd );
|
---|
914 |
|
---|
915 | SetWindowPos( window->hWnd, HWND_TOP, window->x, window->y,
|
---|
916 | window_plus_caption_width, window_plus_caption_height,
|
---|
917 | ( render_spu.fullscreen ? (SWP_SHOWWINDOW |
|
---|
918 | SWP_NOSENDCHANGING |
|
---|
919 | SWP_NOREDRAW |
|
---|
920 | SWP_NOACTIVATE ) :
|
---|
921 | 0 ) );
|
---|
922 |
|
---|
923 | if ( render_spu.fullscreen )
|
---|
924 | ShowCursor( FALSE );
|
---|
925 |
|
---|
926 | window->device_context = GetDC( window->hWnd );
|
---|
927 | if (!window->device_context)
|
---|
928 | {
|
---|
929 | DWORD winEr = GetLastError();
|
---|
930 | crWarning("GetDC failed, winEr %d", winEr);
|
---|
931 | }
|
---|
932 |
|
---|
933 | crDebug( "Render SPU: Got the DC: 0x%x", window->device_context );
|
---|
934 |
|
---|
935 | if ( !bSetupPixelFormat( window->device_context, visual->visAttribs ) )
|
---|
936 | {
|
---|
937 | crError( "Render SPU: Couldn't set up the device context! Yikes!" );
|
---|
938 | return GL_FALSE;
|
---|
939 | }
|
---|
940 |
|
---|
941 | return GL_TRUE;
|
---|
942 | }
|
---|
943 |
|
---|
944 | GLboolean renderspu_SystemVBoxCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window )
|
---|
945 | {
|
---|
946 | #if 0
|
---|
947 | HDESK desktop;
|
---|
948 | #endif
|
---|
949 | HINSTANCE hinstance;
|
---|
950 | WNDCLASS wc;
|
---|
951 | DWORD window_style;
|
---|
952 | int window_plus_caption_width;
|
---|
953 | int window_plus_caption_height;
|
---|
954 |
|
---|
955 | window->hRgn = NULL;
|
---|
956 | window->visual = visual;
|
---|
957 | window->nativeWindow = 0;
|
---|
958 |
|
---|
959 | if ( render_spu.use_L2 )
|
---|
960 | {
|
---|
961 | crWarning( "Going fullscreen because we think we're using Lightning-2." );
|
---|
962 | render_spu.fullscreen = 1;
|
---|
963 | }
|
---|
964 |
|
---|
965 | /*
|
---|
966 | * Begin Windows / WGL code
|
---|
967 | */
|
---|
968 |
|
---|
969 | hinstance = GetModuleHandle( NULL );
|
---|
970 | if (!hinstance)
|
---|
971 | {
|
---|
972 | crError( "Render SPU: Couldn't get a handle to my module." );
|
---|
973 | return GL_FALSE;
|
---|
974 | }
|
---|
975 | crDebug( "Render SPU: Got the module handle: 0x%x", hinstance );
|
---|
976 |
|
---|
977 | #if 0
|
---|
978 | /* If we were launched from a service, telnet, or rsh, we need to
|
---|
979 | * get the input desktop. */
|
---|
980 |
|
---|
981 | desktop = OpenInputDesktop( 0, FALSE,
|
---|
982 | DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
|
---|
983 | DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
|
---|
984 | DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
|
---|
985 | DESKTOP_SWITCHDESKTOP | GENERIC_WRITE );
|
---|
986 |
|
---|
987 | if ( !desktop )
|
---|
988 | {
|
---|
989 | crError( "Render SPU: Couldn't acquire input desktop" );
|
---|
990 | return GL_FALSE;
|
---|
991 | }
|
---|
992 | crDebug( "Render SPU: Got the desktop: 0x%x", desktop );
|
---|
993 |
|
---|
994 | if ( !SetThreadDesktop( desktop ) )
|
---|
995 | {
|
---|
996 | /* If this function fails, it's probably because
|
---|
997 | * it's already been called (i.e., the render SPU
|
---|
998 | * is bolted to an application?) */
|
---|
999 |
|
---|
1000 | /*crError( "Couldn't set thread to input desktop" ); */
|
---|
1001 | }
|
---|
1002 | crDebug( "Render SPU: Set the thread desktop -- this might have failed." );
|
---|
1003 | #endif
|
---|
1004 |
|
---|
1005 | if ( !GetClassInfo(hinstance, WINDOW_NAME, &wc) )
|
---|
1006 | {
|
---|
1007 | wc.style = CS_OWNDC; // | CS_PARENTDC;
|
---|
1008 | wc.lpfnWndProc = (WNDPROC) MainWndProc;
|
---|
1009 | wc.cbClsExtra = 0;
|
---|
1010 | wc.cbWndExtra = 0;
|
---|
1011 | wc.hInstance = hinstance;
|
---|
1012 | wc.hIcon = NULL; //LoadIcon( NULL, IDI_APPLICATION );
|
---|
1013 | wc.hCursor = NULL; //LoadCursor( NULL, IDC_ARROW );
|
---|
1014 | wc.hbrBackground = NULL;
|
---|
1015 | wc.lpszMenuName = NULL;
|
---|
1016 | wc.lpszClassName = WINDOW_NAME;
|
---|
1017 |
|
---|
1018 | if ( !RegisterClass( &wc ) )
|
---|
1019 | {
|
---|
1020 | crError( "Render SPU: Couldn't register window class -- you're not trying "
|
---|
1021 | "to do multi-pipe stuff on windows, are you?\n\nNote --"
|
---|
1022 | "This error message is from 1997 and probably doesn't make"
|
---|
1023 | "any sense any more, but it's nostalgic for Humper." );
|
---|
1024 | return GL_FALSE;
|
---|
1025 | }
|
---|
1026 | crDebug( "Render SPU: Registered the class" );
|
---|
1027 | }
|
---|
1028 | crDebug( "Render SPU: Got the class information" );
|
---|
1029 |
|
---|
1030 | /* Full screen window should be a popup (undecorated) window */
|
---|
1031 | #if 1
|
---|
1032 | window_style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_DISABLED;
|
---|
1033 | if (render_spu_parent_window_id)
|
---|
1034 | {
|
---|
1035 | window_style |= WS_CHILD;
|
---|
1036 | }
|
---|
1037 | #else
|
---|
1038 | window_style = ( WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN );
|
---|
1039 | window_style |= WS_SYSMENU;
|
---|
1040 | #endif
|
---|
1041 |
|
---|
1042 | crDebug( "Render SPU: Fullscreen: %s", render_spu.fullscreen ? "yes" : "no");
|
---|
1043 |
|
---|
1044 | if ( render_spu.fullscreen )
|
---|
1045 | {
|
---|
1046 | #if 0
|
---|
1047 |
|
---|
1048 | int smCxFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME );
|
---|
1049 | int smCyFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME ) + 1;
|
---|
1050 | int smCyCaption = GetSystemMetrics( SM_CYCAPTION );
|
---|
1051 |
|
---|
1052 | window->BltInfo.width = GetSystemMetrics( SM_CXSCREEN ) ;
|
---|
1053 | window->BltInfo.height = GetSystemMetrics( SM_CYSCREEN ) ;
|
---|
1054 |
|
---|
1055 | crDebug( "Render SPU: Window Dims: %d, %d", window->BltInfo.width, window->BltInfo.height );
|
---|
1056 |
|
---|
1057 | window->x = render_spu->defaultX - smCxFixedFrame - 1;
|
---|
1058 | window->y = render_spu->defaultY - smCyFixedFrame - smCyCaption;
|
---|
1059 |
|
---|
1060 | window_plus_caption_width = window->BltInfo.width + 2 * smCxFixedFrame;
|
---|
1061 | window_plus_caption_height = window->BltInfo.height + 2 * smCyFixedFrame + smCyCaption;
|
---|
1062 |
|
---|
1063 | #else
|
---|
1064 | /* Since it's undecorated, we don't have to do anything fancy
|
---|
1065 | * with these parameters. */
|
---|
1066 |
|
---|
1067 | window->BltInfo.width = GetSystemMetrics( SM_CXSCREEN ) ;
|
---|
1068 | window->BltInfo.height = GetSystemMetrics( SM_CYSCREEN ) ;
|
---|
1069 | window->x = 0;
|
---|
1070 | window->y = 0;
|
---|
1071 | window_plus_caption_width = window->BltInfo.width;
|
---|
1072 | window_plus_caption_height = window->BltInfo.height;
|
---|
1073 |
|
---|
1074 | #endif
|
---|
1075 | }
|
---|
1076 | else
|
---|
1077 | {
|
---|
1078 | /* CreateWindow takes the size of the entire window, so we add
|
---|
1079 | * in the size necessary for the frame and the caption. */
|
---|
1080 | int smCxFixedFrame, smCyFixedFrame, smCyCaption;
|
---|
1081 | smCxFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME );
|
---|
1082 | crDebug( "Render SPU: Got the X fixed frame" );
|
---|
1083 | smCyFixedFrame = GetSystemMetrics( SM_CYFIXEDFRAME );
|
---|
1084 | crDebug( "Render SPU: Got the Y fixed frame" );
|
---|
1085 | smCyCaption = GetSystemMetrics( SM_CYCAPTION );
|
---|
1086 | crDebug( "Render SPU: Got the Caption " );
|
---|
1087 |
|
---|
1088 | window_plus_caption_width = window->BltInfo.width + 2 * smCxFixedFrame;
|
---|
1089 | window_plus_caption_height = window->BltInfo.height + 2 * smCyFixedFrame + smCyCaption;
|
---|
1090 |
|
---|
1091 | window->x = render_spu.defaultX;
|
---|
1092 | window->y = render_spu.defaultY;
|
---|
1093 | }
|
---|
1094 |
|
---|
1095 | crDebug( "Render SPU: Creating the window: (%d,%d), (%d,%d)", render_spu.defaultX, render_spu.defaultY, window_plus_caption_width, window_plus_caption_height );
|
---|
1096 | /*window->hWnd = CreateWindowEx( WS_EX_NOACTIVATE | WS_EX_NOPARENTNOTIFY,
|
---|
1097 | WINDOW_NAME, WINDOW_NAME,
|
---|
1098 | window_style,
|
---|
1099 | window->x, window->y,
|
---|
1100 | window->BltInfo.width,
|
---|
1101 | window->BltInfo.height,
|
---|
1102 | (void*) render_spu_parent_window_id, NULL, hinstance, &render_spu );*/
|
---|
1103 | {
|
---|
1104 | CREATESTRUCT cs;
|
---|
1105 |
|
---|
1106 | cs.lpCreateParams = window;
|
---|
1107 |
|
---|
1108 | cs.dwExStyle = WS_EX_NOACTIVATE | WS_EX_NOPARENTNOTIFY;
|
---|
1109 | cs.lpszName = WINDOW_NAME;
|
---|
1110 | cs.lpszClass = WINDOW_NAME;
|
---|
1111 | cs.style = window_style;
|
---|
1112 | cs.x = window->x;
|
---|
1113 | cs.y = window->y;
|
---|
1114 | cs.cx = window->BltInfo.width;
|
---|
1115 | cs.cy = window->BltInfo.height;
|
---|
1116 | cs.hwndParent = (void*) render_spu_parent_window_id;
|
---|
1117 | cs.hMenu = NULL;
|
---|
1118 | cs.hInstance = hinstance;
|
---|
1119 |
|
---|
1120 | if (render_spu.dwWinThreadId)
|
---|
1121 | {
|
---|
1122 | DWORD res;
|
---|
1123 | int cnt=0;
|
---|
1124 |
|
---|
1125 | if (!PostThreadMessage(render_spu.dwWinThreadId, WM_VBOX_RENDERSPU_CREATE_WINDOW, 0, (LPARAM) &cs))
|
---|
1126 | {
|
---|
1127 | crError("Render SPU: PostThreadMessage failed with %i", GetLastError());
|
---|
1128 | return GL_FALSE;
|
---|
1129 | }
|
---|
1130 |
|
---|
1131 | do
|
---|
1132 | {
|
---|
1133 | res = WaitForSingleObject(render_spu.hWinThreadReadyEvent, 1000);
|
---|
1134 | cnt++;
|
---|
1135 | }
|
---|
1136 | while ((res!=WAIT_OBJECT_0) && (cnt<10));
|
---|
1137 |
|
---|
1138 | crDebug("Render SPU: window thread waited %i secs", cnt);
|
---|
1139 |
|
---|
1140 | if (res!=WAIT_OBJECT_0)
|
---|
1141 | {
|
---|
1142 | crError("Render SPU: window thread not responded after %i tries", cnt);
|
---|
1143 | return GL_FALSE;
|
---|
1144 | }
|
---|
1145 | }
|
---|
1146 | else
|
---|
1147 | {
|
---|
1148 | crError("Render SPU: window thread is not running");
|
---|
1149 | return GL_FALSE;
|
---|
1150 | }
|
---|
1151 | }
|
---|
1152 |
|
---|
1153 | if ( !window->hWnd )
|
---|
1154 | {
|
---|
1155 | crError( "Render SPU: Create Window failed! That's almost certainly terrible." );
|
---|
1156 | return GL_FALSE;
|
---|
1157 | }
|
---|
1158 |
|
---|
1159 | window->visible = 1;
|
---|
1160 |
|
---|
1161 | if (!showIt)
|
---|
1162 | {
|
---|
1163 | renderspu_SystemShowWindow( window, 0 );
|
---|
1164 | if (window->BltInfo.height <= 0 || window->BltInfo.width <= 0)
|
---|
1165 | {
|
---|
1166 | renderspu_SystemWindowSize(window,
|
---|
1167 | window->BltInfo.width > 0 ? window->BltInfo.width : 4,
|
---|
1168 | window->BltInfo.height > 0 ? window->BltInfo.height : 4);
|
---|
1169 | }
|
---|
1170 | }
|
---|
1171 | else
|
---|
1172 | {
|
---|
1173 | crDebug( "Render SPU: Showing the window" );
|
---|
1174 | crDebug("renderspu_SystemCreateWindow: showwindow: %x", window->hWnd);
|
---|
1175 | }
|
---|
1176 |
|
---|
1177 | CRASSERT(!window->visible == !showIt);
|
---|
1178 |
|
---|
1179 | /* Intel drivers require a window to be visible for proper 3D rendering,
|
---|
1180 | * so set it visible and handle the visibility with visible regions (see below) */
|
---|
1181 | if (window->BltInfo.Base.id)
|
---|
1182 | {
|
---|
1183 | ShowWindow( window->hWnd, SW_SHOWNORMAL );
|
---|
1184 | }
|
---|
1185 | else
|
---|
1186 | {
|
---|
1187 | CRASSERT(!showIt);
|
---|
1188 | /* dummy window is always hidden in any way */
|
---|
1189 | }
|
---|
1190 |
|
---|
1191 | //SetForegroundWindow( visual->hWnd );
|
---|
1192 |
|
---|
1193 | SetWindowPos( window->hWnd, HWND_TOP, window->x, window->y,
|
---|
1194 | window->BltInfo.width, window->BltInfo.height,
|
---|
1195 | ( render_spu.fullscreen ?
|
---|
1196 | (SWP_SHOWWINDOW | SWP_NOSENDCHANGING | SWP_NOREDRAW | SWP_NOACTIVATE ) : SWP_NOACTIVATE
|
---|
1197 | ) );
|
---|
1198 | crDebug("Render SPU: SetWindowPos (%x, %d, %d, %d, %d)", window->hWnd,
|
---|
1199 | window->x, window->y, window->BltInfo.width, window->BltInfo.height);
|
---|
1200 |
|
---|
1201 | if ( render_spu.fullscreen )
|
---|
1202 | ShowCursor( FALSE );
|
---|
1203 |
|
---|
1204 | window->device_context = GetDC( window->hWnd );
|
---|
1205 | if (!window->device_context)
|
---|
1206 | {
|
---|
1207 | DWORD winEr = GetLastError();
|
---|
1208 | crWarning("GetDC failed, winEr %d", winEr);
|
---|
1209 | }
|
---|
1210 |
|
---|
1211 | crDebug( "Render SPU: Got the DC: 0x%x", window->device_context );
|
---|
1212 |
|
---|
1213 | if ( !bSetupPixelFormat( window->device_context, visual->visAttribs ) )
|
---|
1214 | {
|
---|
1215 | crError( "Render SPU: Couldn't set up the device context! Yikes!" );
|
---|
1216 | return GL_FALSE;
|
---|
1217 | }
|
---|
1218 |
|
---|
1219 | /* set the window pointer data at the last step to ensure our WM_PAINT callback does not do anything until we are fully initialized */
|
---|
1220 | {
|
---|
1221 | LONG_PTR oldVal = SetWindowLongPtr(window->hWnd, GWLP_USERDATA, (LONG_PTR)window);
|
---|
1222 | Assert(!oldVal && GetLastError() == NO_ERROR);
|
---|
1223 | }
|
---|
1224 |
|
---|
1225 | return GL_TRUE;
|
---|
1226 | }
|
---|
1227 |
|
---|
1228 | /* Either show or hide the render SPU's window. */
|
---|
1229 | void renderspu_SystemShowWindow( WindowInfo *window, GLboolean showIt )
|
---|
1230 | {
|
---|
1231 | if (showIt)
|
---|
1232 | {
|
---|
1233 | crDebug("SHOW renderspu_SystemShowWindow: %x", window->hWnd);
|
---|
1234 | SetWindowRgn(window->hWnd, window->hRgn, true);
|
---|
1235 | }
|
---|
1236 | else
|
---|
1237 | {
|
---|
1238 | HRGN hRgn;
|
---|
1239 | crDebug("HIDE renderspu_SystemShowWindow: %x", window->hWnd);
|
---|
1240 | hRgn = CreateRectRgn(0, 0, 0, 0);
|
---|
1241 | SetWindowRgn(window->hWnd, hRgn, true);
|
---|
1242 | DeleteObject(hRgn);
|
---|
1243 | }
|
---|
1244 | window->visible = showIt;
|
---|
1245 | }
|
---|
1246 |
|
---|
1247 | void renderspu_SystemVBoxPresentComposition( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry )
|
---|
1248 | {
|
---|
1249 | /* the CR_RENDER_FORCE_PRESENT_MAIN_THREAD is actually inherited from cocoa backend impl,
|
---|
1250 | * here it forces rendering in WinCmd thread rather than a Main thread.
|
---|
1251 | * it is used for debugging only in any way actually.
|
---|
1252 | * @todo: change to some more generic macro name */
|
---|
1253 | #ifndef CR_RENDER_FORCE_PRESENT_MAIN_THREAD
|
---|
1254 | struct VBOXVR_SCR_COMPOSITOR *pCompositor;
|
---|
1255 | /* we do not want to be blocked with the GUI thread here, so only draw her eif we are really able to do that w/o bllocking */
|
---|
1256 | int rc = renderspuVBoxCompositorTryAcquire(window, &pCompositor);
|
---|
1257 | if (RT_SUCCESS(rc))
|
---|
1258 | {
|
---|
1259 | renderspuVBoxPresentCompositionGeneric(window, pCompositor, pChangedEntry, 0);
|
---|
1260 | renderspuVBoxCompositorRelease(window);
|
---|
1261 | }
|
---|
1262 | else if (rc == VERR_SEM_BUSY)
|
---|
1263 | #endif
|
---|
1264 | {
|
---|
1265 | render_spu.self.Flush();
|
---|
1266 | renderspuVBoxPresentBlitterEnsureCreated(window, 0);
|
---|
1267 | RedrawWindow(window->hWnd, NULL, NULL, RDW_INTERNALPAINT);
|
---|
1268 | }
|
---|
1269 | #ifndef CR_RENDER_FORCE_PRESENT_MAIN_THREAD
|
---|
1270 | else
|
---|
1271 | {
|
---|
1272 | /* this is somewhat we do not expect */
|
---|
1273 | crWarning("renderspuVBoxCompositorTryAcquire failed rc %d", rc);
|
---|
1274 | }
|
---|
1275 | #endif
|
---|
1276 | }
|
---|
1277 |
|
---|
1278 | GLboolean renderspu_SystemCreateContext( VisualInfo *visual, ContextInfo *context, ContextInfo *sharedContext )
|
---|
1279 | {
|
---|
1280 | (void) sharedContext;
|
---|
1281 | context->visual = visual;
|
---|
1282 |
|
---|
1283 | /* Found a visual, so we're o.k. to create the context now */
|
---|
1284 | if (0/*visual->device_context*/) {
|
---|
1285 |
|
---|
1286 | //crDebug( "Render SPU: Using the DC: 0x%x", visual->device_context );
|
---|
1287 |
|
---|
1288 | //context->hRC = render_spu.ws.wglCreateContext( visual->device_context );
|
---|
1289 | if (!context->hRC)
|
---|
1290 | {
|
---|
1291 | crError( "Render SPU: wglCreateContext failed (error 0x%x)", GetLastError() );
|
---|
1292 | return GL_FALSE;
|
---|
1293 | }
|
---|
1294 | } else {
|
---|
1295 | crDebug( "Render SPU: Delaying DC creation " );
|
---|
1296 | context->hRC = NULL; /* create it later in makecurrent */
|
---|
1297 | }
|
---|
1298 |
|
---|
1299 |
|
---|
1300 | return GL_TRUE;
|
---|
1301 | }
|
---|
1302 |
|
---|
1303 | void renderspu_SystemDestroyContext( ContextInfo *context )
|
---|
1304 | {
|
---|
1305 | render_spu.ws.wglDeleteContext( context->hRC );
|
---|
1306 | context->hRC = NULL;
|
---|
1307 | }
|
---|
1308 |
|
---|
1309 | static GLboolean renderspuChkActivateSharedContext(ContextInfo *sharedContext)
|
---|
1310 | {
|
---|
1311 | GLint crWindow;
|
---|
1312 | WindowInfo *window;
|
---|
1313 |
|
---|
1314 | if (sharedContext->hRC)
|
---|
1315 | return GL_TRUE;
|
---|
1316 |
|
---|
1317 | CRASSERT(sharedContext->BltInfo.Base.id);
|
---|
1318 |
|
---|
1319 | if (sharedContext->shared)
|
---|
1320 | renderspuChkActivateSharedContext(sharedContext->shared);
|
---|
1321 |
|
---|
1322 | crWindow = renderspuWindowCreate(sharedContext->visual->displayName, sharedContext->visual->visAttribs);
|
---|
1323 | if (!crWindow)
|
---|
1324 | {
|
---|
1325 | crError("renderspuChkActivateSharedContext: renderspuWindowCreate failed!");
|
---|
1326 | return GL_FALSE;
|
---|
1327 | }
|
---|
1328 |
|
---|
1329 | window = (WindowInfo *) crHashtableSearch(render_spu.windowTable, crWindow);
|
---|
1330 | if (!window)
|
---|
1331 | {
|
---|
1332 | crError("renderspuChkActivateSharedContext: crHashtableSearch failed!");
|
---|
1333 | renderspuWindowDestroy(crWindow);
|
---|
1334 | return GL_FALSE;
|
---|
1335 | }
|
---|
1336 |
|
---|
1337 | CRASSERT(window->device_context);
|
---|
1338 |
|
---|
1339 | crDebug( "Render SPU: renderspuChkActivateSharedContext: made the DC: 0x%x", window->device_context );
|
---|
1340 |
|
---|
1341 | sharedContext->hRC = render_spu.ws.wglCreateContext(window->device_context);
|
---|
1342 | if (!sharedContext->hRC)
|
---|
1343 | {
|
---|
1344 | crError( "Render SPU: (renderspuChkActivateSharedContext) Couldn't create the context for the window (error 0x%x)", GetLastError() );
|
---|
1345 | renderspuWindowDestroy(crWindow);
|
---|
1346 | return GL_FALSE;
|
---|
1347 | }
|
---|
1348 |
|
---|
1349 | return GL_TRUE;
|
---|
1350 | }
|
---|
1351 |
|
---|
1352 | void renderspu_SystemMakeCurrent( WindowInfo *window, GLint nativeWindow, ContextInfo *context )
|
---|
1353 | {
|
---|
1354 | CRASSERT(render_spu.ws.wglMakeCurrent);
|
---|
1355 |
|
---|
1356 | if (context && window) {
|
---|
1357 | if (window->visual != context->visual) {
|
---|
1358 | /*
|
---|
1359 | * XXX have to revisit this issue!!!
|
---|
1360 | *
|
---|
1361 | * But for now we destroy the current window
|
---|
1362 | * and re-create it with the context's visual abilities
|
---|
1363 | */
|
---|
1364 |
|
---|
1365 | /*@todo Chromium has no correct code to remove window ids and associated info from
|
---|
1366 | * various tables. This is hack which just hides the root case.
|
---|
1367 | */
|
---|
1368 | crWarning("Recreating window in renderspu_SystemMakeCurrent\n");
|
---|
1369 | renderspu_SystemDestroyWindow( window );
|
---|
1370 | renderspu_SystemVBoxCreateWindow( context->visual, window->visible, window );
|
---|
1371 | }
|
---|
1372 |
|
---|
1373 | if (0/*render_spu.render_to_app_window && nativeWindow*/)
|
---|
1374 | {
|
---|
1375 | /* The render_to_app_window option
|
---|
1376 | * is set and we've got a nativeWindow
|
---|
1377 | * handle, save the handle for
|
---|
1378 | * later calls to swapbuffers().
|
---|
1379 | *
|
---|
1380 | * NOTE: This doesn't work, except
|
---|
1381 | * for software driven Mesa.
|
---|
1382 | * We'd need to object link the
|
---|
1383 | * crappfaker and crserver to be able to share
|
---|
1384 | * the HDC values between processes.. FIXME!
|
---|
1385 | */
|
---|
1386 | if (context->shared)
|
---|
1387 | {
|
---|
1388 | /* first make sure we have shared context created */
|
---|
1389 | renderspuChkActivateSharedContext(context->shared);
|
---|
1390 | }
|
---|
1391 |
|
---|
1392 | window->nativeWindow = (HDC) nativeWindow;
|
---|
1393 | if (context->hRC == 0) {
|
---|
1394 | context->hRC = render_spu.ws.wglCreateContext( window->nativeWindow );
|
---|
1395 | if (!context->hRC)
|
---|
1396 | {
|
---|
1397 | crError( "(MakeCurrent) Couldn't create the context for the window (error 0x%x)", GetLastError() );
|
---|
1398 | }
|
---|
1399 | }
|
---|
1400 |
|
---|
1401 | if (context->shared
|
---|
1402 | && context->shared->hRC
|
---|
1403 | && context->hRC)
|
---|
1404 | {
|
---|
1405 | /* share lists */
|
---|
1406 | render_spu.ws.wglShareLists(context->shared->hRC, context->hRC);
|
---|
1407 | }
|
---|
1408 |
|
---|
1409 | render_spu.ws.wglMakeCurrent( window->nativeWindow, context->hRC );
|
---|
1410 | }
|
---|
1411 | else
|
---|
1412 | {
|
---|
1413 | if (!context->hRC) {
|
---|
1414 | CRASSERT(!nativeWindow);
|
---|
1415 | if (context->shared)
|
---|
1416 | {
|
---|
1417 | /* first make sure we have shared context created */
|
---|
1418 | renderspuChkActivateSharedContext(context->shared);
|
---|
1419 | }
|
---|
1420 |
|
---|
1421 | context->hRC = render_spu.ws.wglCreateContext(window->device_context);
|
---|
1422 | if (!context->hRC)
|
---|
1423 | {
|
---|
1424 | crError( "Render SPU: (MakeCurrent) Couldn't create the context for the window (error 0x%x)", GetLastError() );
|
---|
1425 | }
|
---|
1426 |
|
---|
1427 | if (context->shared
|
---|
1428 | && context->shared->hRC
|
---|
1429 | && context->hRC)
|
---|
1430 | {
|
---|
1431 | /* share lists */
|
---|
1432 | BOOL bRc = render_spu.ws.wglShareLists(context->shared->hRC, context->hRC);
|
---|
1433 | if (!bRc)
|
---|
1434 | {
|
---|
1435 | DWORD winEr = GetLastError();
|
---|
1436 | crWarning("wglShareLists failed, winEr %d", winEr);
|
---|
1437 | }
|
---|
1438 | }
|
---|
1439 |
|
---|
1440 | /*Requery ext function pointers, we skip dummy ctx as it should never be used with ext functions*/
|
---|
1441 | if (0 && context->BltInfo.Base.id)
|
---|
1442 | {
|
---|
1443 | int numFuncs, i;
|
---|
1444 | SPUNamedFunctionTable ext_table[1000];
|
---|
1445 |
|
---|
1446 |
|
---|
1447 | crDebug("Default server ctx created, requerying ext functions");
|
---|
1448 | /*requery ext functions*/
|
---|
1449 | numFuncs = renderspuCreateFunctions(ext_table);
|
---|
1450 | numFuncs += crLoadOpenGLExtensions( &render_spu.ws, ext_table+numFuncs);
|
---|
1451 | CRASSERT(numFuncs < 1000);
|
---|
1452 |
|
---|
1453 | /*change spu dispatch*/
|
---|
1454 | crSPUChangeDispatch(&render_spu.self, ext_table);
|
---|
1455 |
|
---|
1456 |
|
---|
1457 | /*cleanup temp table*/
|
---|
1458 | for (i=0; i<numFuncs; ++i)
|
---|
1459 | {
|
---|
1460 | if (ext_table[i].name) crFree(ext_table[i].name);
|
---|
1461 | }
|
---|
1462 | }
|
---|
1463 | }
|
---|
1464 |
|
---|
1465 | /*crDebug("MakeCurrent 0x%x, 0x%x", window->device_context, context->hRC);*/
|
---|
1466 | if (!render_spu.ws.wglMakeCurrent(!nativeWindow ? window->device_context : window->redraw_device_context, context->hRC))
|
---|
1467 | {
|
---|
1468 | DWORD err = GetLastError();
|
---|
1469 | crError("Render SPU: (MakeCurrent) failed to make 0x%x, 0x%x current with 0x%x error.", window->device_context, context->hRC, err);
|
---|
1470 | }
|
---|
1471 | }
|
---|
1472 |
|
---|
1473 | renderspuAtiQuirk_ChkApply();
|
---|
1474 | }
|
---|
1475 | else {
|
---|
1476 | render_spu.ws.wglMakeCurrent( 0, 0 );
|
---|
1477 | }
|
---|
1478 | }
|
---|
1479 |
|
---|
1480 | void renderspu_SystemWindowSize( WindowInfo *window, GLint w, GLint h )
|
---|
1481 | {
|
---|
1482 | int winprop;
|
---|
1483 | CRASSERT(window);
|
---|
1484 | CRASSERT(window->visual);
|
---|
1485 | if ( render_spu.fullscreen )
|
---|
1486 | winprop = SWP_SHOWWINDOW | SWP_NOSENDCHANGING |
|
---|
1487 | SWP_NOREDRAW | SWP_NOACTIVATE;
|
---|
1488 | else
|
---|
1489 | winprop = SWP_NOACTIVATE | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_NOZORDER; //SWP_SHOWWINDOW;
|
---|
1490 |
|
---|
1491 | /*SetWindowRgn(window->hWnd, NULL, false);*/
|
---|
1492 |
|
---|
1493 | if (!SetWindowPos( window->hWnd, HWND_TOP,
|
---|
1494 | window->x, window->y, w, h, winprop )) {
|
---|
1495 | crWarning("!!!FAILED!!! Render SPU: SetWindowPos (%x, %d, %d, %d, %d)", window->hWnd, window->x, window->y, w, h);
|
---|
1496 | } else {
|
---|
1497 | crDebug("Render SPU: SetWindowSize (%x, %d, %d, %d, %d)", window->hWnd, window->x, window->y, w, h);
|
---|
1498 | }
|
---|
1499 | /* save the new size */
|
---|
1500 | window->BltInfo.width = w;
|
---|
1501 | window->BltInfo.height = h;
|
---|
1502 | }
|
---|
1503 |
|
---|
1504 |
|
---|
1505 | void renderspu_SystemGetWindowGeometry( WindowInfo *window, GLint *x, GLint *y, GLint *w, GLint *h )
|
---|
1506 | {
|
---|
1507 | RECT rect;
|
---|
1508 |
|
---|
1509 | CRASSERT(window);
|
---|
1510 | CRASSERT(window->visual);
|
---|
1511 |
|
---|
1512 | GetClientRect( window->hWnd, &rect );
|
---|
1513 | *x = rect.left;
|
---|
1514 | *y = rect.top;
|
---|
1515 | *w = rect.right - rect.left;
|
---|
1516 | *h = rect.bottom - rect.top;
|
---|
1517 | }
|
---|
1518 |
|
---|
1519 |
|
---|
1520 | void renderspu_SystemGetMaxWindowSize( WindowInfo *window, GLint *w, GLint *h )
|
---|
1521 | {
|
---|
1522 | /* XXX fix this */
|
---|
1523 | (void) window;
|
---|
1524 | *w = 1600;
|
---|
1525 | *h = 1200;
|
---|
1526 | }
|
---|
1527 |
|
---|
1528 |
|
---|
1529 | void renderspu_SystemWindowPosition( WindowInfo *window, GLint x, GLint y )
|
---|
1530 | {
|
---|
1531 | int winprop;
|
---|
1532 | CRASSERT(window);
|
---|
1533 | CRASSERT(window->visual);
|
---|
1534 | if ( render_spu.fullscreen )
|
---|
1535 | winprop = SWP_SHOWWINDOW | SWP_NOSENDCHANGING |
|
---|
1536 | SWP_NOREDRAW | SWP_NOACTIVATE;
|
---|
1537 | else
|
---|
1538 | winprop = SWP_NOACTIVATE | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_NOZORDER; //SWP_SHOWWINDOW;
|
---|
1539 |
|
---|
1540 | /*SetWindowRgn(window->visual->hWnd, NULL, false);*/
|
---|
1541 |
|
---|
1542 | if (!SetWindowPos( window->hWnd, HWND_TOP,
|
---|
1543 | x, y, window->BltInfo.width, window->BltInfo.height, winprop )) {
|
---|
1544 | crWarning("!!!FAILED!!! Render SPU: SetWindowPos (%x, %d, %d, %d, %d)", window->hWnd, x, y, window->BltInfo.width, window->BltInfo.height);
|
---|
1545 | } else {
|
---|
1546 | crDebug("Render SPU: SetWindowPos (%x, %d, %d, %d, %d)", window->hWnd,
|
---|
1547 | x, y, window->BltInfo.width, window->BltInfo.height);
|
---|
1548 | }
|
---|
1549 | /* save the new position */
|
---|
1550 | window->x = x;
|
---|
1551 | window->y = y;
|
---|
1552 | }
|
---|
1553 |
|
---|
1554 | void renderspu_SystemWindowVisibleRegion(WindowInfo *window, GLint cRects, const GLint* pRects)
|
---|
1555 | {
|
---|
1556 | GLint i;
|
---|
1557 | HRGN hRgn, hTmpRgn;
|
---|
1558 |
|
---|
1559 | CRASSERT(window);
|
---|
1560 | CRASSERT(window->visual);
|
---|
1561 |
|
---|
1562 | if (window->hRgn)
|
---|
1563 | {
|
---|
1564 | DeleteObject(window->hRgn);
|
---|
1565 | window->hRgn = NULL;
|
---|
1566 | }
|
---|
1567 |
|
---|
1568 | hRgn = CreateRectRgn(0, 0, 0, 0);
|
---|
1569 |
|
---|
1570 | for (i=0; i<cRects; i++)
|
---|
1571 | {
|
---|
1572 | hTmpRgn = CreateRectRgn(pRects[4*i], pRects[4*i+1], pRects[4*i+2], pRects[4*i+3]);
|
---|
1573 | CombineRgn(hRgn, hRgn, hTmpRgn, RGN_OR);
|
---|
1574 | DeleteObject(hTmpRgn);
|
---|
1575 | }
|
---|
1576 |
|
---|
1577 | if (window->visible)
|
---|
1578 | SetWindowRgn(window->hWnd, hRgn, true);
|
---|
1579 |
|
---|
1580 | crDebug("Render SPU: SetWindowRgn (%x, cRects=%i)", window->hWnd, cRects);
|
---|
1581 |
|
---|
1582 | window->hRgn = hRgn;
|
---|
1583 | }
|
---|
1584 |
|
---|
1585 | static void renderspuHandleWindowMessages( HWND hWnd )
|
---|
1586 | {
|
---|
1587 | MSG msg;
|
---|
1588 | while ( PeekMessage( &msg, hWnd, 0, 0xffffffff, PM_REMOVE ) )
|
---|
1589 | {
|
---|
1590 | TranslateMessage( &msg );
|
---|
1591 | DispatchMessage( &msg );
|
---|
1592 | }
|
---|
1593 |
|
---|
1594 | //BringWindowToTop( hWnd );
|
---|
1595 | }
|
---|
1596 |
|
---|
1597 | void renderspu_SystemSwapBuffers( WindowInfo *w, GLint flags )
|
---|
1598 | {
|
---|
1599 | int return_value;
|
---|
1600 |
|
---|
1601 | /* peek at the windows message queue */
|
---|
1602 | // renderspuHandleWindowMessages( w->hWnd );
|
---|
1603 |
|
---|
1604 | /* render_to_app_window:
|
---|
1605 | * w->nativeWindow will only be non-zero if the
|
---|
1606 | * render_spu.render_to_app_window option is true and
|
---|
1607 | * MakeCurrent() recorded the nativeWindow handle in the WindowInfo
|
---|
1608 | * structure.
|
---|
1609 | */
|
---|
1610 | if (render_spu.render_to_app_window && w->nativeWindow) {
|
---|
1611 | #ifdef VBOX_CR_SERVER_FORCE_WGL
|
---|
1612 | return_value = render_spu.ws.wglSwapBuffers( w->nativeWindow );
|
---|
1613 | #else
|
---|
1614 | return_value = SwapBuffers( w->nativeWindow );
|
---|
1615 | #endif
|
---|
1616 | } else {
|
---|
1617 | /*
|
---|
1618 | HRGN hRgn1, hRgn2, hRgn3;
|
---|
1619 | HWND hWndParent;
|
---|
1620 | LONG ws;
|
---|
1621 |
|
---|
1622 | hRgn1 = CreateRectRgn(0, 0, w->BltInfo.width, w->BltInfo.height);
|
---|
1623 | hRgn2 = CreateRectRgn(50, 50, 100, 100);
|
---|
1624 | hRgn3 = CreateRectRgn(0, 0, 0, 0);
|
---|
1625 | CombineRgn(hRgn3, hRgn1, hRgn2, RGN_DIFF);
|
---|
1626 | SetWindowRgn(w->visual->hWnd, hRgn3, true);
|
---|
1627 | DeleteObject(hRgn1);
|
---|
1628 | DeleteObject(hRgn2);
|
---|
1629 |
|
---|
1630 | hWndParent = GetParent(w->visual->hWnd);
|
---|
1631 | ws = GetWindowLong(hWndParent, GWL_STYLE);
|
---|
1632 | ws &= ~WS_CLIPCHILDREN;
|
---|
1633 | SetWindowLong(hWndParent, GWL_STYLE, ws);
|
---|
1634 |
|
---|
1635 | RECT rcClip;
|
---|
1636 |
|
---|
1637 | rcClip.left = 50;
|
---|
1638 | rcClip.top = 50;
|
---|
1639 | rcClip.right = 100;
|
---|
1640 | rcClip.bottom = 100;
|
---|
1641 | ValidateRect(w->visual->hWnd, &rcClip);
|
---|
1642 |
|
---|
1643 | return_value = GetClipBox(w->visual->device_context, &rcClip);
|
---|
1644 | crDebug("GetClipBox returned %d (NR=%d,SR=%d,CR=%d,ERR=%d)",
|
---|
1645 | return_value, NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR);
|
---|
1646 |
|
---|
1647 | crDebug("rcClip(%d, %d, %d, %d)", rcClip.left, rcClip.top, rcClip.right, rcClip.bottom);
|
---|
1648 |
|
---|
1649 | return_value = ExcludeClipRect(w->visual->device_context, 50, 50, 100, 100);
|
---|
1650 | crDebug("ExcludeClipRect returned %d (NR=%d,SR=%d,CR=%d,ERR=%d)",
|
---|
1651 | return_value, NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR);
|
---|
1652 |
|
---|
1653 | return_value = GetClipBox(w->visual->device_context, &rcClip);
|
---|
1654 | crDebug("GetClipBox returned %d (NR=%d,SR=%d,CR=%d,ERR=%d)",
|
---|
1655 | return_value, NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR);
|
---|
1656 | crDebug("rcClip(%d, %d, %d, %d)", rcClip.left, rcClip.top, rcClip.right, rcClip.bottom);
|
---|
1657 | */
|
---|
1658 | #ifdef VBOX_CR_SERVER_FORCE_WGL
|
---|
1659 | return_value = render_spu.ws.wglSwapBuffers( w->device_context );
|
---|
1660 | #else
|
---|
1661 | return_value = SwapBuffers( w->device_context );
|
---|
1662 | #endif
|
---|
1663 | }
|
---|
1664 | if (!return_value)
|
---|
1665 | {
|
---|
1666 | /* GOD DAMN IT. The latest versions of the NVIDIA drivers
|
---|
1667 | * return failure from wglSwapBuffers, but it works just fine.
|
---|
1668 | * WHAT THE HELL?! */
|
---|
1669 |
|
---|
1670 | crWarning( "wglSwapBuffers failed: return value of %d!", return_value);
|
---|
1671 | }
|
---|
1672 | }
|
---|
1673 |
|
---|
1674 | void renderspu_SystemReparentWindow(WindowInfo *window)
|
---|
1675 | {
|
---|
1676 | SetParent(window->hWnd, (HWND)render_spu_parent_window_id);
|
---|
1677 | }
|
---|