VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_wgl.c@ 40432

最後變更 在這個檔案從40432是 39757,由 vboxsync 提交於 13 年 前

crOpenGL: remove unnecessary warning

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 44.4 KB
 
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
25int 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
101int 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
125int 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 */
146static HWND __stdcall renderspuAtiQuirk_GetForegroundWindow()
147{
148 crDebug("renderspuAtiQuirk_GetForegroundWindow");
149 return NULL;
150}
151
152
153#define CRREG_MAXKEYNAME 8
154static 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
267static 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
294static 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
304static LPCSTR renderspuRegMultiSzCurVal(LPCSTR pszBuf)
305{
306 if (pszBuf[0] == '\0')
307 return NULL;
308
309 return pszBuf;
310}
311
312
313static 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
339static 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
350static 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
378static BOOL
379bSetupPixelFormat( HDC hdc, GLbitfield visAttribs );
380
381GLboolean 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 visual->device_context = 0;
390
391 return TRUE;
392}
393
394void renderspu_SystemDestroyWindow( WindowInfo *window )
395{
396 VBOX_RENDERSPU_DESTROY_WINDOW vrdw;
397
398 CRASSERT(window);
399
400 /*DestroyWindow( window->hWnd );*/
401
402 vrdw.hWnd = window->hWnd;
403
404 if (render_spu.dwWinThreadId)
405 {
406 PostThreadMessage(render_spu.dwWinThreadId, WM_VBOX_RENDERSPU_DESTROY_WINDOW, 0, (LPARAM) &vrdw);
407 WaitForSingleObject(render_spu.hWinThreadReadyEvent, INFINITE);
408 }
409 else
410 {
411 crError("Render SPU: window thread is not running");
412 }
413
414 window->hWnd = NULL;
415 window->visual = NULL;
416}
417
418static LONG WINAPI
419MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
420{
421 /* int w,h; */
422
423 switch ( uMsg ) {
424
425 case WM_SIZE:
426 /* w = LOWORD( lParam );
427 * h = HIWORD( lParam ); */
428
429 /* glViewport( 0, 0, w, h ); */
430#if 0
431 glViewport( -render_spu.mural_x, -render_spu.mural_y,
432 render_spu.mural_width, render_spu.mural_height );
433 glScissor( -render_spu.mural_x, -render_spu.mural_y,
434 render_spu.mural_width, render_spu.mural_height );
435#endif
436 break;
437
438 case WM_CLOSE:
439 crWarning( "Render SPU: caught WM_CLOSE -- quitting." );
440 exit( 0 );
441 break;
442
443 case WM_DESTROY:
444 crDebug("Render SPU: caught WM_DESTROY for our window %x", hWnd);
445 break;
446
447 case WM_NCHITTEST:
448 crDebug("WM_NCHITTEST");
449 return HTNOWHERE;
450 }
451
452 return DefWindowProc( hWnd, uMsg, wParam, lParam );
453}
454
455static BOOL
456bSetupPixelFormatEXT( HDC hdc, GLbitfield visAttribs)
457{
458 PIXELFORMATDESCRIPTOR ppfd;
459 int pixelFormat;
460 int attribList[100];
461 float fattribList[] = { 0.0, 0.0 };
462 int numFormats;
463 int i = 0;
464 BOOL vis;
465
466 CRASSERT(visAttribs & CR_RGB_BIT); /* anybody need color index */
467
468 crWarning("Render SPU: Using WGL_EXT_pixel_format to select visual ID.");
469
470 attribList[i++] = WGL_DRAW_TO_WINDOW_EXT;
471 attribList[i++] = GL_TRUE;
472 attribList[i++] = WGL_ACCELERATION_EXT;
473 attribList[i++] = WGL_FULL_ACCELERATION_EXT;
474 attribList[i++] = WGL_COLOR_BITS_EXT;
475 attribList[i++] = 24;
476 attribList[i++] = WGL_RED_BITS_EXT;
477 attribList[i++] = 1;
478 attribList[i++] = WGL_GREEN_BITS_EXT;
479 attribList[i++] = 1;
480 attribList[i++] = WGL_BLUE_BITS_EXT;
481 attribList[i++] = 1;
482
483 crWarning("Render SPU: Visual chosen is... RGB");
484
485 if (visAttribs & CR_ALPHA_BIT)
486 {
487 attribList[i++] = WGL_ALPHA_BITS_EXT;
488 attribList[i++] = 1;
489 crWarning("A");
490 }
491
492 crWarning(", ");
493
494 if (visAttribs & CR_DOUBLE_BIT) {
495 attribList[i++] = WGL_DOUBLE_BUFFER_EXT;
496 attribList[i++] = GL_TRUE;
497 crWarning("DB, ");
498 }
499
500 if (visAttribs & CR_STEREO_BIT) {
501 attribList[i++] = WGL_STEREO_EXT;
502 attribList[i++] = GL_TRUE;
503 crWarning("Stereo, ");
504 }
505
506 if (visAttribs & CR_DEPTH_BIT)
507 {
508 attribList[i++] = WGL_DEPTH_BITS_EXT;
509 attribList[i++] = 1;
510 crWarning("Z, ");
511 }
512
513 if (visAttribs & CR_STENCIL_BIT)
514 {
515 attribList[i++] = WGL_STENCIL_BITS_EXT;
516 attribList[i++] = 1;
517 crWarning("Stencil, ");
518 }
519
520 if (visAttribs & CR_ACCUM_BIT)
521 {
522 attribList[i++] = WGL_ACCUM_RED_BITS_EXT;
523 attribList[i++] = 1;
524 attribList[i++] = WGL_ACCUM_GREEN_BITS_EXT;
525 attribList[i++] = 1;
526 attribList[i++] = WGL_ACCUM_BLUE_BITS_EXT;
527 attribList[i++] = 1;
528 crWarning("Accum, ");
529 if (visAttribs & CR_ALPHA_BIT)
530 {
531 attribList[i++] = WGL_ACCUM_ALPHA_BITS_EXT;
532 attribList[i++] = 1;
533 crWarning("Accum Alpha, ");
534 }
535 }
536
537 if (visAttribs & CR_MULTISAMPLE_BIT)
538 {
539 attribList[i++] = WGL_SAMPLE_BUFFERS_EXT;
540 attribList[i++] = 1;
541 attribList[i++] = WGL_SAMPLES_EXT;
542 attribList[i++] = 4;
543 crWarning("Multisample, ");
544 }
545
546 crWarning("\n");
547
548 /* End the list */
549 attribList[i++] = 0;
550 attribList[i++] = 0;
551
552 vis = render_spu.ws.wglChoosePixelFormatEXT( hdc, attribList, fattribList, 1, &pixelFormat, &numFormats);
553
554 crDebug("Render SPU: wglChoosePixelFormatEXT (vis 0x%x, LastError 0x%x, pixelFormat 0x%x", vis, GetLastError(), pixelFormat);
555
556 render_spu.ws.wglSetPixelFormat( hdc, pixelFormat, &ppfd );
557
558 crDebug("Render SPU: wglSetPixelFormat (Last error 0x%x)", GetLastError());
559
560 return vis;
561}
562
563static BOOL
564bSetupPixelFormatNormal( HDC hdc, GLbitfield visAttribs )
565{
566 PIXELFORMATDESCRIPTOR pfd = {
567 sizeof(PIXELFORMATDESCRIPTOR), /* size of this pfd */
568 1, /* version number */
569 PFD_DRAW_TO_WINDOW | /* support window */
570 PFD_SUPPORT_OPENGL, /* support OpenGL */
571 PFD_TYPE_RGBA, /* RGBA type */
572 24, /* 24-bit color depth */
573 0, 0, 0, 0, 0, 0, /* color bits ignored */
574 0, /* no alpha buffer */
575 0, /* shift bit ignored */
576 0, /* no accumulation buffer */
577 0, 0, 0, 0, /* accum bits ignored */
578 0, /* set depth buffer */
579 0, /* set stencil buffer */
580 0, /* no auxiliary buffer */
581 PFD_MAIN_PLANE, /* main layer */
582 0, /* reserved */
583 0, 0, 0 /* layer masks ignored */
584 };
585 PIXELFORMATDESCRIPTOR *ppfd = &pfd;
586 char s[1000];
587 GLbitfield b = 0;
588 int pixelformat;
589
590 renderspuMakeVisString( visAttribs, s );
591
592 crDebug( "Render SPU: WGL wants these visual capabilities: %s", s);
593
594 /* These really come into play with sort-last configs */
595 if (visAttribs & CR_DEPTH_BIT)
596 ppfd->cDepthBits = 24;
597 if (visAttribs & CR_ACCUM_BIT)
598 ppfd->cAccumBits = 16;
599 if (visAttribs & CR_RGB_BIT)
600 ppfd->cColorBits = 24;
601 if (visAttribs & CR_STENCIL_BIT)
602 ppfd->cStencilBits = 8;
603 if (visAttribs & CR_ALPHA_BIT)
604 ppfd->cAlphaBits = 8;
605 if (visAttribs & CR_DOUBLE_BIT)
606 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
607 if (visAttribs & CR_STEREO_BIT)
608 ppfd->dwFlags |= PFD_STEREO;
609
610 /*
611 * We call the wgl functions directly if the SPU was loaded
612 * by our faker library, otherwise we have to call the GDI
613 * versions.
614 */
615 if (crGetenv( "CR_WGL_DO_NOT_USE_GDI" ) != NULL)
616 {
617 pixelformat = render_spu.ws.wglChoosePixelFormat( hdc, ppfd );
618 /* doing this twice is normal Win32 magic */
619 pixelformat = render_spu.ws.wglChoosePixelFormat( hdc, ppfd );
620 if ( pixelformat == 0 )
621 {
622 crError( "render_spu.ws.wglChoosePixelFormat failed" );
623 }
624 if ( !render_spu.ws.wglSetPixelFormat( hdc, pixelformat, ppfd ) )
625 {
626 crError( "render_spu.ws.wglSetPixelFormat failed" );
627 }
628
629 render_spu.ws.wglDescribePixelFormat( hdc, pixelformat, sizeof(*ppfd), ppfd );
630 }
631 else
632 {
633 /* Okay, we were loaded manually. Call the GDI functions. */
634 pixelformat = ChoosePixelFormat( hdc, ppfd );
635 /* doing this twice is normal Win32 magic */
636 pixelformat = ChoosePixelFormat( hdc, ppfd );
637 if ( pixelformat == 0 )
638 {
639 crError( "ChoosePixelFormat failed" );
640 }
641 if ( !SetPixelFormat( hdc, pixelformat, ppfd ) )
642 {
643 crError( "SetPixelFormat failed (Error 0x%x)", GetLastError() );
644 }
645
646 DescribePixelFormat( hdc, pixelformat, sizeof(*ppfd), ppfd );
647 }
648
649
650 if (ppfd->cDepthBits > 0)
651 b |= CR_DEPTH_BIT;
652 if (ppfd->cAccumBits > 0)
653 b |= CR_ACCUM_BIT;
654 if (ppfd->cColorBits > 8)
655 b |= CR_RGB_BIT;
656 if (ppfd->cStencilBits > 0)
657 b |= CR_STENCIL_BIT;
658 if (ppfd->cAlphaBits > 0)
659 b |= CR_ALPHA_BIT;
660 if (ppfd->dwFlags & PFD_DOUBLEBUFFER)
661 b |= CR_DOUBLE_BIT;
662 if (ppfd->dwFlags & PFD_STEREO)
663 b |= CR_STEREO_BIT;
664
665 renderspuMakeVisString( b, s );
666
667 crDebug( "Render SPU: WGL chose these visual capabilities: %s", s);
668 return TRUE;
669}
670
671static BOOL
672bSetupPixelFormat( HDC hdc, GLbitfield visAttribs )
673{
674 /* According to http://www.opengl.org/resources/faq/technical/mswindows.htm
675 we shouldn't be using wgl functions to setup pixel formats unless we're loading ICD driver.
676 In particular, bSetupPixelFormatEXT bugs with Intel drivers.
677 */
678 return bSetupPixelFormatNormal(hdc, visAttribs);
679}
680
681GLboolean renderspu_SystemCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window )
682{
683 HDESK desktop;
684 HINSTANCE hinstance;
685 WNDCLASS wc;
686 DWORD window_style;
687 int window_plus_caption_width;
688 int window_plus_caption_height;
689
690 window->visual = visual;
691 window->nativeWindow = 0;
692
693 if ( render_spu.use_L2 )
694 {
695 crWarning( "Going fullscreen because we think we're using Lightning-2." );
696 render_spu.fullscreen = 1;
697 }
698
699 /*
700 * Begin Windows / WGL code
701 */
702
703 hinstance = GetModuleHandle( NULL );
704 if (!hinstance)
705 {
706 crError( "Render SPU: Couldn't get a handle to my module." );
707 return GL_FALSE;
708 }
709 crDebug( "Render SPU: Got the module handle: 0x%x", hinstance );
710
711 /* If we were launched from a service, telnet, or rsh, we need to
712 * get the input desktop. */
713
714 desktop = OpenInputDesktop( 0, FALSE,
715 DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
716 DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
717 DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
718 DESKTOP_SWITCHDESKTOP | GENERIC_WRITE );
719
720 if ( !desktop )
721 {
722 crError( "Render SPU: Couldn't acquire input desktop" );
723 return GL_FALSE;
724 }
725 crDebug( "Render SPU: Got the desktop: 0x%x", desktop );
726
727 if ( !SetThreadDesktop( desktop ) )
728 {
729 /* If this function fails, it's probably because
730 * it's already been called (i.e., the render SPU
731 * is bolted to an application?) */
732
733 /*crError( "Couldn't set thread to input desktop" ); */
734 }
735 crDebug( "Render SPU: Set the thread desktop -- this might have failed." );
736
737 if ( !GetClassInfo(hinstance, WINDOW_NAME, &wc) )
738 {
739 wc.style = CS_OWNDC;
740 wc.lpfnWndProc = (WNDPROC) MainWndProc;
741 wc.cbClsExtra = 0;
742 wc.cbWndExtra = 0;
743 wc.hInstance = hinstance;
744 wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
745 wc.hCursor = LoadCursor( NULL, IDC_ARROW );
746 wc.hbrBackground = NULL;
747 wc.lpszMenuName = NULL;
748 wc.lpszClassName = WINDOW_NAME;
749
750 if ( !RegisterClass( &wc ) )
751 {
752 crError( "Render SPU: Couldn't register window class -- you're not trying "
753 "to do multi-pipe stuff on windows, are you?\n\nNote --"
754 "This error message is from 1997 and probably doesn't make"
755 "any sense any more, but it's nostalgic for Humper." );
756 return GL_FALSE;
757 }
758 crDebug( "Render SPU: Registered the class" );
759 }
760 crDebug( "Render SPU: Got the class information" );
761
762 /* Full screen window should be a popup (undecorated) window */
763#if 1
764 window_style = ( render_spu.fullscreen ? WS_POPUP : WS_CAPTION );
765#else
766 window_style = ( WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN );
767 window_style |= WS_SYSMENU;
768#endif
769
770 crDebug( "Render SPU: Fullscreen: %s", render_spu.fullscreen ? "yes" : "no");
771
772 if ( render_spu.fullscreen )
773 {
774#if 0
775
776 int smCxFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME );
777 int smCyFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME ) + 1;
778 int smCyCaption = GetSystemMetrics( SM_CYCAPTION );
779
780 window->width = GetSystemMetrics( SM_CXSCREEN ) ;
781 window->height = GetSystemMetrics( SM_CYSCREEN ) ;
782
783 crDebug( "Render SPU: Window Dims: %d, %d", window->width, window->height );
784
785 window->x = render_spu->defaultX - smCxFixedFrame - 1;
786 window->y = render_spu->defaultY - smCyFixedFrame - smCyCaption;
787
788 window_plus_caption_width = window->width + 2 * smCxFixedFrame;
789 window_plus_caption_height = window->height + 2 * smCyFixedFrame + smCyCaption;
790
791#else
792 /* Since it's undecorated, we don't have to do anything fancy
793 * with these parameters. */
794
795 window->width = GetSystemMetrics( SM_CXSCREEN ) ;
796 window->height = GetSystemMetrics( SM_CYSCREEN ) ;
797 window->x = 0;
798 window->y = 0;
799 window_plus_caption_width = window->width;
800 window_plus_caption_height = window->height;
801
802#endif
803 }
804 else
805 {
806 /* CreateWindow takes the size of the entire window, so we add
807 * in the size necessary for the frame and the caption. */
808
809 int smCxFixedFrame, smCyFixedFrame, smCyCaption;
810 smCxFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME );
811 crDebug( "Render SPU: Got the X fixed frame" );
812 smCyFixedFrame = GetSystemMetrics( SM_CYFIXEDFRAME );
813 crDebug( "Render SPU: Got the Y fixed frame" );
814 smCyCaption = GetSystemMetrics( SM_CYCAPTION );
815 crDebug( "Render SPU: Got the Caption " );
816
817 window_plus_caption_width = window->width + 2 * smCxFixedFrame;
818 window_plus_caption_height = window->height + 2 * smCyFixedFrame + smCyCaption;
819
820 window->x = render_spu.defaultX - smCxFixedFrame;
821 window->y = render_spu.defaultY - smCyFixedFrame - smCyCaption;
822 }
823
824 crDebug( "Render SPU: Creating the window: (%d,%d), (%d,%d)", render_spu.defaultX, render_spu.defaultY, window_plus_caption_width, window_plus_caption_height );
825 window->hWnd = CreateWindow( WINDOW_NAME, WINDOW_NAME,
826 window_style,
827 window->x, window->y,
828 window_plus_caption_width,
829 window_plus_caption_height,
830 NULL, NULL, hinstance, &render_spu );
831
832 if ( !window->hWnd )
833 {
834 crError( "Render SPU: Create Window failed! That's almost certainly terrible." );
835 return GL_FALSE;
836 }
837
838 if (showIt) {
839 /* NO ERROR CODE FOR SHOWWINDOW */
840 crDebug( "Render SPU: Showing the window" );
841 crDebug("renderspu_SystemCreateWindow: showwindow: %x", window->hWnd);
842 ShowWindow( window->hWnd, SW_SHOWNORMAL );
843 }
844
845 SetForegroundWindow( window->hWnd );
846
847 SetWindowPos( window->hWnd, HWND_TOP, window->x, window->y,
848 window_plus_caption_width, window_plus_caption_height,
849 ( render_spu.fullscreen ? (SWP_SHOWWINDOW |
850 SWP_NOSENDCHANGING |
851 SWP_NOREDRAW |
852 SWP_NOACTIVATE ) :
853 0 ) );
854
855 if ( render_spu.fullscreen )
856 ShowCursor( FALSE );
857
858 window->device_context = GetDC( window->hWnd );
859
860 crDebug( "Render SPU: Got the DC: 0x%x", window->device_context );
861
862 if ( !bSetupPixelFormat( window->device_context, visual->visAttribs ) )
863 {
864 crError( "Render SPU: Couldn't set up the device context! Yikes!" );
865 return GL_FALSE;
866 }
867
868 return GL_TRUE;
869}
870
871GLboolean renderspu_SystemVBoxCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window )
872{
873#if 0
874 HDESK desktop;
875#endif
876 HINSTANCE hinstance;
877 WNDCLASS wc;
878 DWORD window_style;
879 int window_plus_caption_width;
880 int window_plus_caption_height;
881
882 window->visual = visual;
883 window->nativeWindow = 0;
884
885 if ( render_spu.use_L2 )
886 {
887 crWarning( "Going fullscreen because we think we're using Lightning-2." );
888 render_spu.fullscreen = 1;
889 }
890
891 /*
892 * Begin Windows / WGL code
893 */
894
895 hinstance = GetModuleHandle( NULL );
896 if (!hinstance)
897 {
898 crError( "Render SPU: Couldn't get a handle to my module." );
899 return GL_FALSE;
900 }
901 crDebug( "Render SPU: Got the module handle: 0x%x", hinstance );
902
903#if 0
904 /* If we were launched from a service, telnet, or rsh, we need to
905 * get the input desktop. */
906
907 desktop = OpenInputDesktop( 0, FALSE,
908 DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
909 DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
910 DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
911 DESKTOP_SWITCHDESKTOP | GENERIC_WRITE );
912
913 if ( !desktop )
914 {
915 crError( "Render SPU: Couldn't acquire input desktop" );
916 return GL_FALSE;
917 }
918 crDebug( "Render SPU: Got the desktop: 0x%x", desktop );
919
920 if ( !SetThreadDesktop( desktop ) )
921 {
922 /* If this function fails, it's probably because
923 * it's already been called (i.e., the render SPU
924 * is bolted to an application?) */
925
926 /*crError( "Couldn't set thread to input desktop" ); */
927 }
928 crDebug( "Render SPU: Set the thread desktop -- this might have failed." );
929#endif
930
931 if ( !GetClassInfo(hinstance, WINDOW_NAME, &wc) )
932 {
933 wc.style = CS_OWNDC; // | CS_PARENTDC;
934 wc.lpfnWndProc = (WNDPROC) MainWndProc;
935 wc.cbClsExtra = 0;
936 wc.cbWndExtra = 0;
937 wc.hInstance = hinstance;
938 wc.hIcon = NULL; //LoadIcon( NULL, IDI_APPLICATION );
939 wc.hCursor = NULL; //LoadCursor( NULL, IDC_ARROW );
940 wc.hbrBackground = NULL;
941 wc.lpszMenuName = NULL;
942 wc.lpszClassName = WINDOW_NAME;
943
944 if ( !RegisterClass( &wc ) )
945 {
946 crError( "Render SPU: Couldn't register window class -- you're not trying "
947 "to do multi-pipe stuff on windows, are you?\n\nNote --"
948 "This error message is from 1997 and probably doesn't make"
949 "any sense any more, but it's nostalgic for Humper." );
950 return GL_FALSE;
951 }
952 crDebug( "Render SPU: Registered the class" );
953 }
954 crDebug( "Render SPU: Got the class information" );
955
956 /* Full screen window should be a popup (undecorated) window */
957#if 1
958 window_style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_DISABLED;
959 if (render_spu_parent_window_id)
960 {
961 window_style |= WS_CHILD;
962 }
963#else
964 window_style = ( WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN );
965 window_style |= WS_SYSMENU;
966#endif
967
968 crDebug( "Render SPU: Fullscreen: %s", render_spu.fullscreen ? "yes" : "no");
969
970 if ( render_spu.fullscreen )
971 {
972#if 0
973
974 int smCxFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME );
975 int smCyFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME ) + 1;
976 int smCyCaption = GetSystemMetrics( SM_CYCAPTION );
977
978 window->width = GetSystemMetrics( SM_CXSCREEN ) ;
979 window->height = GetSystemMetrics( SM_CYSCREEN ) ;
980
981 crDebug( "Render SPU: Window Dims: %d, %d", window->width, window->height );
982
983 window->x = render_spu->defaultX - smCxFixedFrame - 1;
984 window->y = render_spu->defaultY - smCyFixedFrame - smCyCaption;
985
986 window_plus_caption_width = window->width + 2 * smCxFixedFrame;
987 window_plus_caption_height = window->height + 2 * smCyFixedFrame + smCyCaption;
988
989#else
990 /* Since it's undecorated, we don't have to do anything fancy
991 * with these parameters. */
992
993 window->width = GetSystemMetrics( SM_CXSCREEN ) ;
994 window->height = GetSystemMetrics( SM_CYSCREEN ) ;
995 window->x = 0;
996 window->y = 0;
997 window_plus_caption_width = window->width;
998 window_plus_caption_height = window->height;
999
1000#endif
1001 }
1002 else
1003 {
1004 /* CreateWindow takes the size of the entire window, so we add
1005 * in the size necessary for the frame and the caption. */
1006 int smCxFixedFrame, smCyFixedFrame, smCyCaption;
1007 smCxFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME );
1008 crDebug( "Render SPU: Got the X fixed frame" );
1009 smCyFixedFrame = GetSystemMetrics( SM_CYFIXEDFRAME );
1010 crDebug( "Render SPU: Got the Y fixed frame" );
1011 smCyCaption = GetSystemMetrics( SM_CYCAPTION );
1012 crDebug( "Render SPU: Got the Caption " );
1013
1014 window_plus_caption_width = window->width + 2 * smCxFixedFrame;
1015 window_plus_caption_height = window->height + 2 * smCyFixedFrame + smCyCaption;
1016
1017 window->x = render_spu.defaultX;
1018 window->y = render_spu.defaultY;
1019 }
1020
1021 crDebug( "Render SPU: Creating the window: (%d,%d), (%d,%d)", render_spu.defaultX, render_spu.defaultY, window_plus_caption_width, window_plus_caption_height );
1022 /*window->hWnd = CreateWindowEx( WS_EX_NOACTIVATE | WS_EX_NOPARENTNOTIFY,
1023 WINDOW_NAME, WINDOW_NAME,
1024 window_style,
1025 window->x, window->y,
1026 window->width,
1027 window->height,
1028 (void*) render_spu_parent_window_id, NULL, hinstance, &render_spu );*/
1029 {
1030 CREATESTRUCT cs;
1031
1032 cs.lpCreateParams = &window->hWnd;
1033
1034 cs.dwExStyle = WS_EX_NOACTIVATE | WS_EX_NOPARENTNOTIFY;
1035 cs.lpszName = WINDOW_NAME;
1036 cs.lpszClass = WINDOW_NAME;
1037 cs.style = window_style;
1038 cs.x = window->x;
1039 cs.y = window->y;
1040 cs.cx = window->width;
1041 cs.cy = window->height;
1042 cs.hwndParent = (void*) render_spu_parent_window_id;
1043 cs.hMenu = NULL;
1044 cs.hInstance = hinstance;
1045
1046 if (render_spu.dwWinThreadId)
1047 {
1048 DWORD res;
1049 int cnt=0;
1050
1051 if (!PostThreadMessage(render_spu.dwWinThreadId, WM_VBOX_RENDERSPU_CREATE_WINDOW, 0, (LPARAM) &cs))
1052 {
1053 crError("Render SPU: PostThreadMessage failed with %i", GetLastError());
1054 return GL_FALSE;
1055 }
1056
1057 do
1058 {
1059 res = WaitForSingleObject(render_spu.hWinThreadReadyEvent, 1000);
1060 cnt++;
1061 }
1062 while ((res!=WAIT_OBJECT_0) && (cnt<10));
1063
1064 crDebug("Render SPU: window thread waited %i secs", cnt);
1065
1066 if (res!=WAIT_OBJECT_0)
1067 {
1068 crError("Render SPU: window thread not responded after %i tries", cnt);
1069 return GL_FALSE;
1070 }
1071 }
1072 else
1073 {
1074 crError("Render SPU: window thread is not running");
1075 return GL_FALSE;
1076 }
1077 }
1078
1079 if ( !window->hWnd )
1080 {
1081 crError( "Render SPU: Create Window failed! That's almost certainly terrible." );
1082 return GL_FALSE;
1083 }
1084
1085 if (showIt) {
1086 /* NO ERROR CODE FOR SHOWWINDOW */
1087 crDebug( "Render SPU: Showing the window" );
1088 crDebug("renderspu_SystemVBoxCreateWindow: showwindow: %x", window->hWnd);
1089 ShowWindow( window->hWnd, SW_SHOWNORMAL );
1090 }
1091
1092 //SetForegroundWindow( visual->hWnd );
1093
1094 SetWindowPos( window->hWnd, HWND_TOP, window->x, window->y,
1095 window->width, window->height,
1096 ( render_spu.fullscreen ?
1097 (SWP_SHOWWINDOW | SWP_NOSENDCHANGING | SWP_NOREDRAW | SWP_NOACTIVATE ) : SWP_NOACTIVATE
1098 ) );
1099 crDebug("Render SPU: SetWindowPos (%x, %d, %d, %d, %d)", window->hWnd,
1100 window->x, window->y, window->width, window->height);
1101
1102 if ( render_spu.fullscreen )
1103 ShowCursor( FALSE );
1104
1105 window->device_context = GetDC( window->hWnd );
1106
1107 crDebug( "Render SPU: Got the DC: 0x%x", window->device_context );
1108
1109 if ( !bSetupPixelFormat( window->device_context, visual->visAttribs ) )
1110 {
1111 crError( "Render SPU: Couldn't set up the device context! Yikes!" );
1112 return GL_FALSE;
1113 }
1114
1115 return GL_TRUE;
1116}
1117
1118
1119/* Either show or hide the render SPU's window. */
1120void renderspu_SystemShowWindow( WindowInfo *window, GLboolean showIt )
1121{
1122 if (showIt)
1123 {
1124 crDebug("SHOW renderspu_SystemShowWindow: %x", window->hWnd);
1125 ShowWindow( window->hWnd, SW_SHOWNORMAL );
1126 }
1127 else
1128 {
1129 crDebug("HIDE renderspu_SystemShowWindow: %x", window->hWnd);
1130 ShowWindow( window->hWnd, SW_HIDE );
1131 }
1132}
1133
1134GLboolean renderspu_SystemCreateContext( VisualInfo *visual, ContextInfo *context, ContextInfo *sharedContext )
1135{
1136 (void) sharedContext;
1137 context->visual = visual;
1138
1139 /* Found a visual, so we're o.k. to create the context now */
1140 if (0/*visual->device_context*/) {
1141
1142 //crDebug( "Render SPU: Using the DC: 0x%x", visual->device_context );
1143
1144 //context->hRC = render_spu.ws.wglCreateContext( visual->device_context );
1145 if (!context->hRC)
1146 {
1147 crError( "Render SPU: wglCreateContext failed (error 0x%x)", GetLastError() );
1148 return GL_FALSE;
1149 }
1150 } else {
1151 crDebug( "Render SPU: Delaying DC creation " );
1152 context->hRC = NULL; /* create it later in makecurrent */
1153 }
1154
1155
1156 return GL_TRUE;
1157}
1158
1159void renderspu_SystemDestroyContext( ContextInfo *context )
1160{
1161 render_spu.ws.wglDeleteContext( context->hRC );
1162 context->hRC = NULL;
1163}
1164
1165void renderspu_SystemMakeCurrent( WindowInfo *window, GLint nativeWindow, ContextInfo *context )
1166{
1167 CRASSERT(render_spu.ws.wglMakeCurrent);
1168
1169 if (context && window) {
1170 if (window->visual != context->visual) {
1171 /*
1172 * XXX have to revisit this issue!!!
1173 *
1174 * But for now we destroy the current window
1175 * and re-create it with the context's visual abilities
1176 */
1177
1178 /*@todo Chromium has no correct code to remove window ids and associated info from
1179 * various tables. This is hack which just hides the root case.
1180 */
1181 crDebug("Recreating window in renderspu_SystemMakeCurrent\n");
1182 renderspu_SystemDestroyWindow( window );
1183 renderspu_SystemVBoxCreateWindow( context->visual, window->visible, window );
1184 }
1185
1186 if (render_spu.render_to_app_window && nativeWindow)
1187 {
1188 /* The render_to_app_window option
1189 * is set and we've got a nativeWindow
1190 * handle, save the handle for
1191 * later calls to swapbuffers().
1192 *
1193 * NOTE: This doesn't work, except
1194 * for software driven Mesa.
1195 * We'd need to object link the
1196 * crappfaker and crserver to be able to share
1197 * the HDC values between processes.. FIXME!
1198 */
1199 window->nativeWindow = (HDC) nativeWindow;
1200 if (context->hRC == 0) {
1201 context->hRC = render_spu.ws.wglCreateContext( window->nativeWindow );
1202 if (!context->hRC)
1203 {
1204 crError( "(MakeCurrent) Couldn't create the context for the window (error 0x%x)", GetLastError() );
1205 }
1206 }
1207 render_spu.ws.wglMakeCurrent( window->nativeWindow, context->hRC );
1208 }
1209 else
1210 {
1211 if (!context->visual->device_context) {
1212 context->visual->device_context = GetDC( window->hWnd );
1213
1214 crDebug( "Render SPU: MakeCurrent made the DC: 0x%x", context->visual->device_context );
1215
1216 if ( !bSetupPixelFormat( context->visual->device_context, context->visual->visAttribs ) )
1217 {
1218 crError( "Render SPU: (MakeCurrent) Couldn't set up the device context! Yikes!" );
1219 }
1220 }
1221
1222 if (!context->hRC) {
1223 context->hRC = render_spu.ws.wglCreateContext(context->visual->device_context);
1224 if (!context->hRC)
1225 {
1226 crError( "Render SPU: (MakeCurrent) Couldn't create the context for the window (error 0x%x)", GetLastError() );
1227 }
1228
1229 /*Requery ext function pointers, we skip dummy ctx as it should never be used with ext functions*/
1230 if (0 && context->id)
1231 {
1232 int numFuncs, i;
1233 SPUNamedFunctionTable ext_table[1000];
1234
1235
1236 crDebug("Default server ctx created, requerying ext functions");
1237 /*requery ext functions*/
1238 numFuncs = renderspuCreateFunctions(ext_table);
1239 numFuncs += crLoadOpenGLExtensions( &render_spu.ws, ext_table+numFuncs);
1240 CRASSERT(numFuncs < 1000);
1241
1242 /*change spu dispatch*/
1243 crSPUChangeDispatch(&render_spu.self, ext_table);
1244
1245
1246 /*cleanup temp table*/
1247 for (i=0; i<numFuncs; ++i)
1248 {
1249 if (ext_table[i].name) crFree(ext_table[i].name);
1250 }
1251 }
1252 }
1253
1254 /*crDebug("MakeCurrent 0x%x, 0x%x", window->device_context, context->hRC);*/
1255 if (!render_spu.ws.wglMakeCurrent(window->device_context, context->hRC))
1256 {
1257 DWORD err = GetLastError();
1258 crError("Render SPU: (MakeCurrent) failed to make 0x%x, 0x%x current with 0x%x error.", window->device_context, context->hRC, err);
1259 }
1260 }
1261
1262 renderspuAtiQuirk_ChkApply();
1263 }
1264 else {
1265 render_spu.ws.wglMakeCurrent( 0, 0 );
1266 }
1267}
1268
1269void renderspu_SystemWindowSize( WindowInfo *window, GLint w, GLint h )
1270{
1271 int winprop;
1272 CRASSERT(window);
1273 CRASSERT(window->visual);
1274 if ( render_spu.fullscreen )
1275 winprop = SWP_SHOWWINDOW | SWP_NOSENDCHANGING |
1276 SWP_NOREDRAW | SWP_NOACTIVATE;
1277 else
1278 winprop = SWP_NOACTIVATE | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_NOZORDER; //SWP_SHOWWINDOW;
1279
1280 /*SetWindowRgn(window->hWnd, NULL, false);*/
1281
1282 if (!SetWindowPos( window->hWnd, HWND_TOP,
1283 window->x, window->y, w, h, winprop )) {
1284 crWarning("!!!FAILED!!! Render SPU: SetWindowPos (%x, %d, %d, %d, %d)", window->hWnd, window->x, window->y, w, h);
1285 } else {
1286 crDebug("Render SPU: SetWindowSize (%x, %d, %d, %d, %d)", window->hWnd, window->x, window->y, w, h);
1287 }
1288 /* save the new size */
1289 window->width = w;
1290 window->height = h;
1291}
1292
1293
1294void renderspu_SystemGetWindowGeometry( WindowInfo *window, GLint *x, GLint *y, GLint *w, GLint *h )
1295{
1296 RECT rect;
1297
1298 CRASSERT(window);
1299 CRASSERT(window->visual);
1300
1301 GetClientRect( window->hWnd, &rect );
1302 *x = rect.left;
1303 *y = rect.top;
1304 *w = rect.right - rect.left;
1305 *h = rect.bottom - rect.top;
1306}
1307
1308
1309void renderspu_SystemGetMaxWindowSize( WindowInfo *window, GLint *w, GLint *h )
1310{
1311 /* XXX fix this */
1312 (void) window;
1313 *w = 1600;
1314 *h = 1200;
1315}
1316
1317
1318void renderspu_SystemWindowPosition( WindowInfo *window, GLint x, GLint y )
1319{
1320 int winprop;
1321 CRASSERT(window);
1322 CRASSERT(window->visual);
1323 if ( render_spu.fullscreen )
1324 winprop = SWP_SHOWWINDOW | SWP_NOSENDCHANGING |
1325 SWP_NOREDRAW | SWP_NOACTIVATE;
1326 else
1327 winprop = SWP_NOACTIVATE | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_NOZORDER; //SWP_SHOWWINDOW;
1328
1329 /*SetWindowRgn(window->visual->hWnd, NULL, false);*/
1330
1331 if (!SetWindowPos( window->hWnd, HWND_TOP,
1332 x, y, window->width, window->height, winprop )) {
1333 crWarning("!!!FAILED!!! Render SPU: SetWindowPos (%x, %d, %d, %d, %d)", window->hWnd, x, y, window->width, window->height);
1334 } else {
1335 crDebug("Render SPU: SetWindowPos (%x, %d, %d, %d, %d)", window->hWnd,
1336 x, y, window->width, window->height);
1337 }
1338}
1339
1340void renderspu_SystemWindowVisibleRegion(WindowInfo *window, GLint cRects, GLint* pRects)
1341{
1342 GLint i;
1343 HRGN hRgn, hTmpRgn;
1344
1345 CRASSERT(window);
1346 CRASSERT(window->visual);
1347
1348 hRgn = CreateRectRgn(0, 0, 0, 0);
1349
1350 for (i=0; i<cRects; i++)
1351 {
1352 hTmpRgn = CreateRectRgn(pRects[4*i], pRects[4*i+1], pRects[4*i+2], pRects[4*i+3]);
1353 CombineRgn(hRgn, hRgn, hTmpRgn, RGN_OR);
1354 DeleteObject(hTmpRgn);
1355 }
1356
1357 SetWindowRgn(window->hWnd, hRgn, true);
1358 crDebug("Render SPU: SetWindowRgn (%x, cRects=%i)", window->hWnd, cRects);
1359}
1360
1361static void renderspuHandleWindowMessages( HWND hWnd )
1362{
1363 MSG msg;
1364 while ( PeekMessage( &msg, hWnd, 0, 0xffffffff, PM_REMOVE ) )
1365 {
1366 TranslateMessage( &msg );
1367 DispatchMessage( &msg );
1368 }
1369
1370 //BringWindowToTop( hWnd );
1371}
1372
1373void renderspu_SystemSwapBuffers( WindowInfo *w, GLint flags )
1374{
1375 int return_value;
1376
1377 /* peek at the windows message queue */
1378 renderspuHandleWindowMessages( w->hWnd );
1379
1380 /* render_to_app_window:
1381 * w->nativeWindow will only be non-zero if the
1382 * render_spu.render_to_app_window option is true and
1383 * MakeCurrent() recorded the nativeWindow handle in the WindowInfo
1384 * structure.
1385 */
1386 if (render_spu.render_to_app_window && w->nativeWindow) {
1387 return_value = render_spu.ws.wglSwapBuffers( w->nativeWindow );
1388 } else {
1389 /*
1390 HRGN hRgn1, hRgn2, hRgn3;
1391 HWND hWndParent;
1392 LONG ws;
1393
1394 hRgn1 = CreateRectRgn(0, 0, w->width, w->height);
1395 hRgn2 = CreateRectRgn(50, 50, 100, 100);
1396 hRgn3 = CreateRectRgn(0, 0, 0, 0);
1397 CombineRgn(hRgn3, hRgn1, hRgn2, RGN_DIFF);
1398 SetWindowRgn(w->visual->hWnd, hRgn3, true);
1399 DeleteObject(hRgn1);
1400 DeleteObject(hRgn2);
1401
1402 hWndParent = GetParent(w->visual->hWnd);
1403 ws = GetWindowLong(hWndParent, GWL_STYLE);
1404 ws &= ~WS_CLIPCHILDREN;
1405 SetWindowLong(hWndParent, GWL_STYLE, ws);
1406
1407 RECT rcClip;
1408
1409 rcClip.left = 50;
1410 rcClip.top = 50;
1411 rcClip.right = 100;
1412 rcClip.bottom = 100;
1413 ValidateRect(w->visual->hWnd, &rcClip);
1414
1415 return_value = GetClipBox(w->visual->device_context, &rcClip);
1416 crDebug("GetClipBox returned %d (NR=%d,SR=%d,CR=%d,ERR=%d)",
1417 return_value, NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR);
1418
1419 crDebug("rcClip(%d, %d, %d, %d)", rcClip.left, rcClip.top, rcClip.right, rcClip.bottom);
1420
1421 return_value = ExcludeClipRect(w->visual->device_context, 50, 50, 100, 100);
1422 crDebug("ExcludeClipRect returned %d (NR=%d,SR=%d,CR=%d,ERR=%d)",
1423 return_value, NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR);
1424
1425 return_value = GetClipBox(w->visual->device_context, &rcClip);
1426 crDebug("GetClipBox returned %d (NR=%d,SR=%d,CR=%d,ERR=%d)",
1427 return_value, NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR);
1428 crDebug("rcClip(%d, %d, %d, %d)", rcClip.left, rcClip.top, rcClip.right, rcClip.bottom);
1429 */
1430 return_value = render_spu.ws.wglSwapBuffers( w->device_context );
1431 }
1432 if (!return_value)
1433 {
1434 /* GOD DAMN IT. The latest versions of the NVIDIA drivers
1435 * return failure from wglSwapBuffers, but it works just fine.
1436 * WHAT THE HELL?! */
1437
1438 crWarning( "wglSwapBuffers failed: return value of %d!", return_value);
1439 }
1440}
1441
1442void renderspu_SystemReparentWindow(WindowInfo *window)
1443{
1444 SetParent(window->hWnd, (HWND)render_spu_parent_window_id);
1445}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette