VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_init.c@ 78237

最後變更 在這個檔案從78237是 78190,由 vboxsync 提交於 6 年 前

Merge first stage of the Chromium cleanup from the branch:

  • r129818 (Remove VBOX_WITH_CR_DISPLAY_LISTS and accompanying code as it was disabled since r108676 and was never brought back (see ​bugref:3456 and ​bugref:8485))
  • r129819 (HostServices/SharedOpenGL: Remove unused main entry point from upstream server process based implementation)
  • r129820 (HostServices/SharedOpenGL: Started eliminating all backends other than HGCM. They are not used and probably wouldn't work anymore anyway)
  • r129821 (HostServices/SharedOpenGL,GuestHost/OpenGLAdditions/common/crOpenGL: Kill crTimer* API as it is not used anywhere)
  • r129822 (HostServices/SharedOpenGL,GuestHost/OpenGLAdditions/common/crOpenGL: Kill most from cr_process.h apart from two used methods)
  • r129823 (HostServices/SharedOpenGL,GuestHost/OpenGLAdditions/common/crOpenGL: Kill crList* API as it is unused)
  • r129824 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Kill crHullInteriorBox API as it is unused)
  • r129825 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Kill crWarpPoint API as it is unused)
  • r129826 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Kill CrSa* API as it is unused and not even compiled in)
  • r129827 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Kill cr_bbox.h as it is unused)
  • r129828 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove a few crParseUrl() two uses)
  • r129829 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove last crParseURL() use)
  • r129830 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove crParseURL())
  • r129831 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove VBOX_WITH_COCOA_QT and related code when not set as it is the default for years now and we don't support anything else anymore)
  • r129832 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused cr_logo.h)
  • r129833 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused crut_api.h and crut_clientapi.h)
  • r129834 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused cr_dmx.h)
  • r129835 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused cr_perf.h)
  • r129836 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove cr_rand.h and friends as it is not actively used anywhere)
  • r129837 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of all the swapped versions in the packer SPU, we never change endianess from guest to host and don't need it)
  • r129838 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove more swapper versions in the packer related code)
  • r129839 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove more swapper versions in the packer related code)
  • r129840 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused pack_pica.c)
  • r129841 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove more swapper versions in the packer related code)
  • r129842 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of cr_endianess.h and friends)
  • r129843 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of unused lowercase.py)
  • r129844 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of unused cr_calllists.h and friends)
  • r129845 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of completely unused idpool.c, not even compiled in)
  • r129846 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of unused cr_debugopcodes.h and friends)
  • r129847 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Make the cr_mem.h API inline and get rid of the implementation in the util library)
  • r129848 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of SPUOptions and related code as it is of no use for us)
  • r129849 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of cr_environment.h and friends and convert usage to RTEnv* APIs)
  • r129850 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of unused renderspu_agl.c)
  • r129851 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused code in cr_htable.h)
  • r129853 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Introduce a state paremeter for the unpacker workers instead of reyling on global variables, work in progress)
  • r129854 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Let the caller of crUnpack set up the initial state. This allows to get rid of the global return_ptr and writeback_ptr as they get supplied in the unpacker state by the server)
  • r129855 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of the cr_lastDispatch and cr_unpackDispatch as they are of no use now)
  • r129856 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of the global cr_unpackData and cr_unpackDataEnd symbols by indtroducing another hack to make it possible for certail server dispatch callbacks to access the data buffer)
  • r129857 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: build fix for release builds)
  • r129858 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Make the pointer to the unpacker state non const (is required for the access verification))
  • r129859 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: First iteration of the buffer size validation to prevent out of bound read access + added todos for places where additional checks are needed)
  • r129860 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129861 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129871 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129872 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Stop as soon as the unpacker encountered an error)
  • r129876 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129880 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129882 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Fixed some offsets in unpack_texture.c, 3DMark03 renders correctly again)
  • r130013 (HostServices/SharedOpenGL: Convert files to C++ so we can use C99 featuers on Windows with cl.exe)
  • r130014 (HostServices/SharedOpenGL,GuestHost/OpenGL: WIndows build fixes)
  • r130015 (HostServices/SharedOpenGL,GuestHost/OpenGL: More Windows build fixes)
  • r130036 (Config.kmk: Fix linker error on Windows by temporarily disabling the use of VBoxGuestR3DllMinW2K)
  • r130094 (src/VBox/GuestHost/OpenGL: Revert inlining the allocation/free functions in R3 completely as it doesn't work on Windows if memory is allocated and freed across different DLLs which don't share a common CRT, causes crashes in RtlValidtaeHeap())
  • r130095 (src/VBox/GuestHost/OpenGL,src/VBox/Additions/common/crOpenGL/pack: Don't use floating point specifiers in packspu_GetString() to avoid R6002 errors (couldn't fully understand why they occur suddenly after the rework but this gets rid of it))
  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id Revision
檔案大小: 16.1 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#include "cr_mem.h"
8#include "cr_spu.h"
9#include "cr_error.h"
10#include "cr_string.h"
11#include "renderspu.h"
12#include <stdio.h>
13
14#include <iprt/env.h>
15
16#ifdef RT_OS_DARWIN
17# include <iprt/semaphore.h>
18#endif /* RT_OS_DARWIN */
19
20static SPUNamedFunctionTable _cr_render_table[1000];
21
22SPUFunctions render_functions = {
23 NULL, /* CHILD COPY */
24 NULL, /* DATA */
25 _cr_render_table /* THE ACTUAL FUNCTIONS */
26};
27
28RenderSPU render_spu;
29uint64_t render_spu_parent_window_id = 0;
30
31#ifdef CHROMIUM_THREADSAFE
32CRtsd _RenderTSD;
33#endif
34
35#ifdef RT_OS_WINDOWS
36static DWORD WINAPI renderSPUWindowThreadProc(void* unused)
37{
38 MSG msg;
39 BOOL bRet;
40
41 (void) unused;
42
43 /* Force system to create the message queue.
44 * Else, there's a chance that render spu will issue PostThreadMessage
45 * before this thread calls GetMessage for first time.
46 */
47 PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
48
49 crDebug("RenderSPU: Window thread started (%x)", crThreadID());
50 SetEvent(render_spu.hWinThreadReadyEvent);
51
52 while( (bRet = GetMessage( &msg, 0, 0, 0 )) != 0)
53 {
54 if (bRet == -1)
55 {
56 crError("RenderSPU: Window thread GetMessage failed (%x)", GetLastError());
57 break;
58 }
59 else
60 {
61 if (msg.message == WM_VBOX_RENDERSPU_CREATE_WINDOW)
62 {
63 LPCREATESTRUCT pCS = (LPCREATESTRUCT) msg.lParam;
64 HWND hWnd;
65 WindowInfo *pWindow = (WindowInfo *)pCS->lpCreateParams;
66
67 CRASSERT(msg.lParam && !msg.wParam && pCS->lpCreateParams);
68
69 hWnd = CreateWindowEx(pCS->dwExStyle, pCS->lpszName, pCS->lpszClass, pCS->style,
70 pCS->x, pCS->y, pCS->cx, pCS->cy,
71 pCS->hwndParent, pCS->hMenu, pCS->hInstance, &render_spu);
72
73 pWindow->hWnd = hWnd;
74
75 SetEvent(render_spu.hWinThreadReadyEvent);
76 }
77 else if (msg.message == WM_VBOX_RENDERSPU_DESTROY_WINDOW)
78 {
79 CRASSERT(msg.lParam && !msg.wParam);
80
81 DestroyWindow(((VBOX_RENDERSPU_DESTROY_WINDOW*) msg.lParam)->hWnd);
82
83 SetEvent(render_spu.hWinThreadReadyEvent);
84 }
85 else
86 {
87 TranslateMessage(&msg);
88 DispatchMessage(&msg);
89 }
90 }
91 }
92
93 render_spu.dwWinThreadId = 0;
94
95 crDebug("RenderSPU: Window thread stopped (%x)", crThreadID());
96 SetEvent(render_spu.hWinThreadReadyEvent);
97
98 return 0;
99}
100#endif
101
102int renderspuDefaultCtxInit()
103{
104 GLint defaultWin, defaultCtx;
105 WindowInfo *windowInfo;
106
107 /*
108 * Create the default window and context. Their indexes are zero and
109 * a client can use them without calling CreateContext or WindowCreate.
110 */
111 crDebug("Render SPU: Creating default window (visBits=0x%x, id=0)",
112 render_spu.default_visual);
113 defaultWin = renderspuWindowCreateEx( NULL, render_spu.default_visual, CR_RENDER_DEFAULT_WINDOW_ID );
114 if (defaultWin != CR_RENDER_DEFAULT_WINDOW_ID) {
115 crError("Render SPU: Couldn't get a double-buffered, RGB visual with Z!");
116 return VERR_GENERAL_FAILURE;
117 }
118 crDebug( "Render SPU: WindowCreate returned %d (0=normal)", defaultWin );
119
120 crDebug("Render SPU: Creating default context, visBits=0x%x",
121 render_spu.default_visual );
122 defaultCtx = renderspuCreateContextEx( NULL, render_spu.default_visual, CR_RENDER_DEFAULT_CONTEXT_ID, 0 );
123 if (defaultCtx != CR_RENDER_DEFAULT_CONTEXT_ID) {
124 crError("Render SPU: failed to create default context!");
125 return VERR_GENERAL_FAILURE;
126 }
127
128 renderspuMakeCurrent( defaultWin, 0, defaultCtx );
129
130 /* Get windowInfo for the default window */
131 windowInfo = (WindowInfo *) crHashtableSearch(render_spu.windowTable, CR_RENDER_DEFAULT_WINDOW_ID);
132 CRASSERT(windowInfo);
133 windowInfo->mapPending = GL_TRUE;
134
135 return VINF_SUCCESS;
136}
137
138static SPUFunctions *
139renderSPUInit( int id, SPU *child, SPU *self,
140 unsigned int context_id, unsigned int num_contexts )
141{
142 int numFuncs, numSpecial;
143
144 const char * pcpwSetting;
145 int rc;
146
147 (void) child;
148 (void) context_id;
149 (void) num_contexts;
150
151 self->privatePtr = (void *) &render_spu;
152
153#ifdef CHROMIUM_THREADSAFE
154 crDebug("Render SPU: thread-safe");
155 crInitTSD(&_RenderTSD);
156#endif
157
158 crMemZero(&render_spu, sizeof(render_spu));
159
160 render_spu.id = id;
161 renderspuSetVBoxConfiguration(&render_spu);
162
163 /* Get our special functions. */
164 numSpecial = renderspuCreateFunctions( _cr_render_table );
165
166#ifdef RT_OS_WINDOWS
167 /* Start thread to create windows and process window messages */
168 crDebug("RenderSPU: Starting windows serving thread");
169 render_spu.hWinThreadReadyEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
170 if (!render_spu.hWinThreadReadyEvent)
171 {
172 crError("RenderSPU: Failed to create WinThreadReadyEvent! (%x)", GetLastError());
173 return NULL;
174 }
175
176 if (!CreateThread(NULL, 0, renderSPUWindowThreadProc, 0, 0, &render_spu.dwWinThreadId))
177 {
178 crError("RenderSPU: Failed to start windows thread! (%x)", GetLastError());
179 return NULL;
180 }
181 WaitForSingleObject(render_spu.hWinThreadReadyEvent, INFINITE);
182#endif
183
184 /* Get the OpenGL functions. */
185 numFuncs = crLoadOpenGL( &render_spu.ws, _cr_render_table + numSpecial );
186 if (numFuncs == 0) {
187 crError("The render SPU was unable to load the native OpenGL library");
188 return NULL;
189 }
190
191 numFuncs += numSpecial;
192
193 render_spu.contextTable = crAllocHashtableEx(1, INT32_MAX);
194 render_spu.windowTable = crAllocHashtableEx(1, INT32_MAX);
195
196 render_spu.dummyWindowTable = crAllocHashtable();
197
198 pcpwSetting = RTEnvGet("CR_RENDER_ENABLE_SINGLE_PRESENT_CONTEXT");
199 if (pcpwSetting)
200 {
201 if (pcpwSetting[0] == '0')
202 pcpwSetting = NULL;
203 }
204
205 if (pcpwSetting)
206 {
207 /** @todo need proper blitter synchronization, do not use so far!
208 * the problem is that rendering can be done in multiple thread: the main command (hgcm) thread and the redraw thread
209 * we currently use per-window synchronization, while we'll need a per-blitter synchronization if one blitter is used for multiple windows
210 * this is not done currently */
211 crWarning("TODO: need proper blitter synchronization, do not use so far!");
212 render_spu.blitterTable = crAllocHashtable();
213 CRASSERT(render_spu.blitterTable);
214 }
215 else
216 render_spu.blitterTable = NULL;
217
218 CRASSERT(render_spu.default_visual & CR_RGB_BIT);
219
220 rc = renderspu_SystemInit();
221 if (!RT_SUCCESS(rc))
222 {
223 crError("renderspu_SystemInit failed rc %d", rc);
224 return NULL;
225 }
226#ifdef USE_OSMESA
227 if (render_spu.use_osmesa) {
228 if (!crLoadOSMesa(&render_spu.OSMesaCreateContext,
229 &render_spu.OSMesaMakeCurrent,
230 &render_spu.OSMesaDestroyContext)) {
231 crError("Unable to load OSMesa library");
232 }
233 }
234#endif
235
236 rc = renderspuDefaultCtxInit();
237 if (!RT_SUCCESS(rc))
238 {
239 WARN(("renderspuDefaultCtxInit failed %d", rc));
240 return NULL;
241 }
242
243 /*
244 * Get the OpenGL extension functions.
245 * SIGH -- we have to wait until the very bitter end to load the
246 * extensions, because the context has to be bound before
247 * wglGetProcAddress will work correctly. No such issue with GLX though.
248 */
249 numFuncs += crLoadOpenGLExtensions( &render_spu.ws, _cr_render_table + numFuncs );
250 CRASSERT(numFuncs < 1000);
251
252#ifdef WINDOWS
253 /*
254 * Same problem as above, these are extensions so we need to
255 * load them after a context has been bound. As they're WGL
256 * extensions too, we can't simply tag them into the spu_loader.
257 * So we do them here for now.
258 * Grrr, NVIDIA driver uses EXT for GetExtensionsStringEXT,
259 * but ARB for others. Need further testing here....
260 */
261 render_spu.ws.wglGetExtensionsStringEXT =
262 (wglGetExtensionsStringEXTFunc_t)
263 render_spu.ws.wglGetProcAddress( "wglGetExtensionsStringEXT" );
264 render_spu.ws.wglChoosePixelFormatEXT =
265 (wglChoosePixelFormatEXTFunc_t)
266 render_spu.ws.wglGetProcAddress( "wglChoosePixelFormatARB" );
267 render_spu.ws.wglGetPixelFormatAttribivEXT =
268 (wglGetPixelFormatAttribivEXTFunc_t)
269 render_spu.ws.wglGetProcAddress( "wglGetPixelFormatAttribivARB" );
270 render_spu.ws.wglGetPixelFormatAttribfvEXT =
271 (wglGetPixelFormatAttribfvEXTFunc_t)
272 render_spu.ws.wglGetProcAddress( "wglGetPixelFormatAttribfvARB" );
273
274 if (render_spu.ws.wglGetProcAddress("glCopyTexSubImage3D"))
275 {
276 _cr_render_table[numFuncs].name = crStrdup("CopyTexSubImage3D");
277 _cr_render_table[numFuncs].fn = (SPUGenericFunction) render_spu.ws.wglGetProcAddress("glCopyTexSubImage3D");
278 ++numFuncs;
279 crDebug("Render SPU: Found glCopyTexSubImage3D function");
280 }
281
282 if (render_spu.ws.wglGetProcAddress("glDrawRangeElements"))
283 {
284 _cr_render_table[numFuncs].name = crStrdup("DrawRangeElements");
285 _cr_render_table[numFuncs].fn = (SPUGenericFunction) render_spu.ws.wglGetProcAddress("glDrawRangeElements");
286 ++numFuncs;
287 crDebug("Render SPU: Found glDrawRangeElements function");
288 }
289
290 if (render_spu.ws.wglGetProcAddress("glTexSubImage3D"))
291 {
292 _cr_render_table[numFuncs].name = crStrdup("TexSubImage3D");
293 _cr_render_table[numFuncs].fn = (SPUGenericFunction) render_spu.ws.wglGetProcAddress("glTexSubImage3D");
294 ++numFuncs;
295 crDebug("Render SPU: Found glTexSubImage3D function");
296 }
297
298 if (render_spu.ws.wglGetProcAddress("glTexImage3D"))
299 {
300 _cr_render_table[numFuncs].name = crStrdup("TexImage3D");
301 _cr_render_table[numFuncs].fn = (SPUGenericFunction) render_spu.ws.wglGetProcAddress("glTexImage3D");
302 ++numFuncs;
303 crDebug("Render SPU: Found glTexImage3D function");
304 }
305
306 if (render_spu.ws.wglGetExtensionsStringEXT) {
307 crDebug("WGL - found wglGetExtensionsStringEXT\n");
308 }
309 if (render_spu.ws.wglChoosePixelFormatEXT) {
310 crDebug("WGL - found wglChoosePixelFormatEXT\n");
311 }
312#endif
313
314 render_spu.barrierHash = crAllocHashtable();
315
316 render_spu.cursorX = 0;
317 render_spu.cursorY = 0;
318 render_spu.use_L2 = 0;
319
320 render_spu.gather_conns = NULL;
321
322 numFuncs = renderspu_SystemPostprocessFunctions(_cr_render_table, numFuncs, RT_ELEMENTS(_cr_render_table));
323
324 crDebug("Render SPU: ---------- End of Init -------------");
325
326 return &render_functions;
327}
328
329static void renderSPUSelfDispatch(SPUDispatchTable *self)
330{
331 crSPUInitDispatchTable( &(render_spu.self) );
332 crSPUCopyDispatchTable( &(render_spu.self), self );
333
334 crSPUInitDispatchTable( &(render_spu.blitterDispatch) );
335 crSPUCopyDispatchTable( &(render_spu.blitterDispatch), self );
336
337 render_spu.server = (CRServer *)(self->server);
338
339 {
340 GLfloat version;
341 version = crStrToFloat((const char *) render_spu.ws.glGetString(GL_VERSION));
342
343 if (version>=2.f || crStrstr((const char*)render_spu.ws.glGetString(GL_EXTENSIONS), "GL_ARB_vertex_shader"))
344 {
345 GLint mu=0;
346 render_spu.self.GetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &mu);
347 crInfo("Render SPU: GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB=%i", mu);
348 }
349 }
350}
351
352
353static void DeleteContextCallback( void *data )
354{
355 ContextInfo *context = (ContextInfo *) data;
356 renderspuContextMarkDeletedAndRelease(context);
357}
358
359static void DeleteWindowCallback( void *data )
360{
361 WindowInfo *window = (WindowInfo *) data;
362 renderspuWinTermOnShutdown(window);
363 renderspuWinRelease(window);
364}
365
366static void DeleteBlitterCallback( void *data )
367{
368 PCR_BLITTER pBlitter = (PCR_BLITTER) data;
369 CrBltTerm(pBlitter);
370 crFree(pBlitter);
371}
372
373static void renderspuBlitterCleanupCB(unsigned long key, void *data1, void *data2)
374{
375 WindowInfo *window = (WindowInfo *) data1;
376 CRASSERT(window);
377
378 renderspuVBoxPresentBlitterCleanup( window );
379}
380
381
382static void renderspuDeleteBlitterCB(unsigned long key, void *data1, void *data2)
383{
384 CRHashTable *pTbl = (CRHashTable*)data2;
385
386 crHashtableDelete( pTbl, key, NULL );
387
388 DeleteBlitterCallback(data1);
389}
390
391
392static void renderspuDeleteWindowCB(unsigned long key, void *data1, void *data2)
393{
394 CRHashTable *pTbl = (CRHashTable*)data2;
395
396 crHashtableDelete( pTbl, key, NULL );
397
398 DeleteWindowCallback(data1);
399}
400
401static void renderspuDeleteBarierCB(unsigned long key, void *data1, void *data2)
402{
403 CRHashTable *pTbl = (CRHashTable*)data2;
404
405 crHashtableDelete( pTbl, key, NULL );
406
407 crFree(data1);
408}
409
410
411static void renderspuDeleteContextCB(unsigned long key, void *data1, void *data2)
412{
413 CRHashTable *pTbl = (CRHashTable*)data2;
414
415 crHashtableDelete( pTbl, key, NULL );
416
417 DeleteContextCallback(data1);
418}
419
420void renderspuCleanupBase(bool fDeleteTables)
421{
422 renderspuVBoxCompositorClearAll();
423
424 if (render_spu.blitterTable)
425 {
426 if (fDeleteTables)
427 {
428 crFreeHashtable(render_spu.blitterTable, DeleteBlitterCallback);
429 render_spu.blitterTable = NULL;
430 }
431 else
432 {
433 crHashtableWalk(render_spu.blitterTable, renderspuDeleteBlitterCB, render_spu.contextTable);
434 }
435 }
436 else
437 {
438 crHashtableWalk(render_spu.windowTable, renderspuBlitterCleanupCB, NULL);
439
440 crHashtableWalk(render_spu.dummyWindowTable, renderspuBlitterCleanupCB, NULL);
441 }
442
443 renderspuSetDefaultSharedContext(NULL);
444
445 if (fDeleteTables)
446 {
447 crFreeHashtable(render_spu.contextTable, DeleteContextCallback);
448 render_spu.contextTable = NULL;
449 crFreeHashtable(render_spu.windowTable, DeleteWindowCallback);
450 render_spu.windowTable = NULL;
451 crFreeHashtable(render_spu.dummyWindowTable, DeleteWindowCallback);
452 render_spu.dummyWindowTable = NULL;
453 crFreeHashtable(render_spu.barrierHash, crFree);
454 render_spu.barrierHash = NULL;
455 }
456 else
457 {
458 crHashtableWalk(render_spu.contextTable, renderspuDeleteContextCB, render_spu.contextTable);
459 crHashtableWalk(render_spu.windowTable, renderspuDeleteWindowCB, render_spu.windowTable);
460 crHashtableWalk(render_spu.dummyWindowTable, renderspuDeleteWindowCB, render_spu.dummyWindowTable);
461 crHashtableWalk(render_spu.barrierHash, renderspuDeleteBarierCB, render_spu.barrierHash);
462 }
463}
464
465static int renderSPUCleanup(void)
466{
467 renderspuCleanupBase(true);
468
469#ifdef RT_OS_WINDOWS
470 if (render_spu.dwWinThreadId)
471 {
472 HANDLE hNative;
473
474 hNative = OpenThread(SYNCHRONIZE|THREAD_QUERY_INFORMATION|THREAD_TERMINATE,
475 false, render_spu.dwWinThreadId);
476 if (!hNative)
477 {
478 crWarning("Failed to get handle for window thread(%#x)", GetLastError());
479 }
480
481 if (PostThreadMessage(render_spu.dwWinThreadId, WM_QUIT, 0, 0))
482 {
483 WaitForSingleObject(render_spu.hWinThreadReadyEvent, INFINITE);
484
485 /*wait for os thread to actually finish*/
486 if (hNative && WaitForSingleObject(hNative, 3000)==WAIT_TIMEOUT)
487 {
488 crDebug("Wait failed, terminating");
489 if (!TerminateThread(hNative, 1))
490 {
491 crWarning("TerminateThread failed");
492 }
493 }
494 }
495
496 if (hNative)
497 {
498 CloseHandle(hNative);
499 }
500 }
501 CloseHandle(render_spu.hWinThreadReadyEvent);
502 render_spu.hWinThreadReadyEvent = NULL;
503#endif
504
505 crUnloadOpenGL();
506
507#ifdef CHROMIUM_THREADSAFE
508 crFreeTSD(&_RenderTSD);
509#endif
510
511 return 1;
512}
513
514
515int SPULoad( char **name, char **super, SPUInitFuncPtr *init,
516 SPUSelfDispatchFuncPtr *self, SPUCleanupFuncPtr *cleanup,
517 int *flags )
518{
519 *name = "render";
520 *super = NULL;
521 *init = renderSPUInit;
522 *self = renderSPUSelfDispatch;
523 *cleanup = renderSPUCleanup;
524 *flags = (SPU_NO_PACKER|SPU_IS_TERMINAL|SPU_MAX_SERVERS_ZERO);
525
526 return 1;
527}
528
529DECLEXPORT(void) renderspuSetWindowId(uint64_t winId)
530{
531 render_spu_parent_window_id = winId;
532 crDebug("Set new parent window %p (no actual reparent performed)", winId);
533}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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