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 "cr_url.h"
|
---|
12 | #include "cr_environment.h"
|
---|
13 | #include "renderspu.h"
|
---|
14 | #include <stdio.h>
|
---|
15 |
|
---|
16 | #ifdef RT_OS_DARWIN
|
---|
17 | # include <iprt/semaphore.h>
|
---|
18 | #endif /* RT_OS_DARWIN */
|
---|
19 |
|
---|
20 | static SPUNamedFunctionTable _cr_render_table[1000];
|
---|
21 |
|
---|
22 | SPUFunctions render_functions = {
|
---|
23 | NULL, /* CHILD COPY */
|
---|
24 | NULL, /* DATA */
|
---|
25 | _cr_render_table /* THE ACTUAL FUNCTIONS */
|
---|
26 | };
|
---|
27 |
|
---|
28 | RenderSPU render_spu;
|
---|
29 | uint64_t render_spu_parent_window_id = 0;
|
---|
30 |
|
---|
31 | #ifdef CHROMIUM_THREADSAFE
|
---|
32 | CRtsd _RenderTSD;
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | static void swapsyncConnect(void)
|
---|
36 | {
|
---|
37 | char hostname[4096], protocol[4096];
|
---|
38 | unsigned short port;
|
---|
39 |
|
---|
40 | crNetInit(NULL, NULL);
|
---|
41 |
|
---|
42 | if (!crParseURL( render_spu.swap_master_url, protocol, hostname,
|
---|
43 | &port, 9876))
|
---|
44 | crError( "Bad URL: %s", render_spu.swap_master_url );
|
---|
45 |
|
---|
46 | if (render_spu.is_swap_master)
|
---|
47 | {
|
---|
48 | int a;
|
---|
49 |
|
---|
50 | render_spu.swap_conns = (CRConnection **)crAlloc(
|
---|
51 | render_spu.num_swap_clients*sizeof(CRConnection *));
|
---|
52 | for (a=0; a<render_spu.num_swap_clients; a++)
|
---|
53 | {
|
---|
54 | render_spu.swap_conns[a] = crNetAcceptClient( protocol, hostname, port,
|
---|
55 | render_spu.swap_mtu, 1);
|
---|
56 | }
|
---|
57 | }
|
---|
58 | else
|
---|
59 | {
|
---|
60 | render_spu.swap_conns = (CRConnection **)crAlloc(sizeof(CRConnection *));
|
---|
61 |
|
---|
62 | render_spu.swap_conns[0] = crNetConnectToServer(render_spu.swap_master_url,
|
---|
63 | port, render_spu.swap_mtu, 1);
|
---|
64 | if (!render_spu.swap_conns[0])
|
---|
65 | crError("Failed connection");
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | #ifdef RT_OS_WINDOWS
|
---|
70 | static DWORD WINAPI renderSPUWindowThreadProc(void* unused)
|
---|
71 | {
|
---|
72 | MSG msg;
|
---|
73 | bool bRet;
|
---|
74 |
|
---|
75 | (void) unused;
|
---|
76 |
|
---|
77 | /* Force system to create the message queue.
|
---|
78 | * Else, there's a chance that render spu will issue PostThreadMessage
|
---|
79 | * before this thread calls GetMessage for first time.
|
---|
80 | */
|
---|
81 | PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
|
---|
82 |
|
---|
83 | crDebug("RenderSPU: Window thread started (%x)", crThreadID());
|
---|
84 | SetEvent(render_spu.hWinThreadReadyEvent);
|
---|
85 |
|
---|
86 | while( (bRet = GetMessage( &msg, 0, 0, 0 )) != 0)
|
---|
87 | {
|
---|
88 | if (bRet == -1)
|
---|
89 | {
|
---|
90 | crError("RenderSPU: Window thread GetMessage failed (%x)", GetLastError());
|
---|
91 | break;
|
---|
92 | }
|
---|
93 | else
|
---|
94 | {
|
---|
95 | if (msg.message == WM_VBOX_RENDERSPU_CREATE_WINDOW)
|
---|
96 | {
|
---|
97 | LPCREATESTRUCT pCS = (LPCREATESTRUCT) msg.lParam;
|
---|
98 | HWND hWnd;
|
---|
99 | WindowInfo *pWindow = (WindowInfo *)pCS->lpCreateParams;
|
---|
100 |
|
---|
101 | CRASSERT(msg.lParam && !msg.wParam && pCS->lpCreateParams);
|
---|
102 |
|
---|
103 | hWnd = CreateWindowEx(pCS->dwExStyle, pCS->lpszName, pCS->lpszClass, pCS->style,
|
---|
104 | pCS->x, pCS->y, pCS->cx, pCS->cy,
|
---|
105 | pCS->hwndParent, pCS->hMenu, pCS->hInstance, &render_spu);
|
---|
106 |
|
---|
107 | pWindow->hWnd = hWnd;
|
---|
108 |
|
---|
109 | SetEvent(render_spu.hWinThreadReadyEvent);
|
---|
110 | }
|
---|
111 | else if (msg.message == WM_VBOX_RENDERSPU_DESTROY_WINDOW)
|
---|
112 | {
|
---|
113 | CRASSERT(msg.lParam && !msg.wParam);
|
---|
114 |
|
---|
115 | DestroyWindow(((VBOX_RENDERSPU_DESTROY_WINDOW*) msg.lParam)->hWnd);
|
---|
116 |
|
---|
117 | SetEvent(render_spu.hWinThreadReadyEvent);
|
---|
118 | }
|
---|
119 | else
|
---|
120 | {
|
---|
121 | TranslateMessage(&msg);
|
---|
122 | DispatchMessage(&msg);
|
---|
123 | }
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | render_spu.dwWinThreadId = 0;
|
---|
128 |
|
---|
129 | crDebug("RenderSPU: Window thread stopped (%x)", crThreadID());
|
---|
130 | SetEvent(render_spu.hWinThreadReadyEvent);
|
---|
131 |
|
---|
132 | return 0;
|
---|
133 | }
|
---|
134 | #endif
|
---|
135 |
|
---|
136 | int renderspuDefaultCtxInit()
|
---|
137 | {
|
---|
138 | GLint defaultWin, defaultCtx;
|
---|
139 | WindowInfo *windowInfo;
|
---|
140 |
|
---|
141 | /*
|
---|
142 | * Create the default window and context. Their indexes are zero and
|
---|
143 | * a client can use them without calling CreateContext or WindowCreate.
|
---|
144 | */
|
---|
145 | crDebug("Render SPU: Creating default window (visBits=0x%x, id=0)",
|
---|
146 | render_spu.default_visual);
|
---|
147 | defaultWin = renderspuWindowCreateEx( NULL, render_spu.default_visual, CR_RENDER_DEFAULT_WINDOW_ID );
|
---|
148 | if (defaultWin != CR_RENDER_DEFAULT_WINDOW_ID) {
|
---|
149 | crError("Render SPU: Couldn't get a double-buffered, RGB visual with Z!");
|
---|
150 | return VERR_GENERAL_FAILURE;
|
---|
151 | }
|
---|
152 | crDebug( "Render SPU: WindowCreate returned %d (0=normal)", defaultWin );
|
---|
153 |
|
---|
154 | crDebug("Render SPU: Creating default context, visBits=0x%x",
|
---|
155 | render_spu.default_visual );
|
---|
156 | defaultCtx = renderspuCreateContextEx( NULL, render_spu.default_visual, CR_RENDER_DEFAULT_CONTEXT_ID, 0 );
|
---|
157 | if (defaultCtx != CR_RENDER_DEFAULT_CONTEXT_ID) {
|
---|
158 | crError("Render SPU: failed to create default context!");
|
---|
159 | return VERR_GENERAL_FAILURE;
|
---|
160 | }
|
---|
161 |
|
---|
162 | renderspuMakeCurrent( defaultWin, 0, defaultCtx );
|
---|
163 |
|
---|
164 | /* Get windowInfo for the default window */
|
---|
165 | windowInfo = (WindowInfo *) crHashtableSearch(render_spu.windowTable, CR_RENDER_DEFAULT_WINDOW_ID);
|
---|
166 | CRASSERT(windowInfo);
|
---|
167 | windowInfo->mapPending = GL_TRUE;
|
---|
168 |
|
---|
169 | return VINF_SUCCESS;
|
---|
170 | }
|
---|
171 |
|
---|
172 | static SPUFunctions *
|
---|
173 | renderSPUInit( int id, SPU *child, SPU *self,
|
---|
174 | unsigned int context_id, unsigned int num_contexts )
|
---|
175 | {
|
---|
176 | int numFuncs, numSpecial;
|
---|
177 |
|
---|
178 | const char * pcpwSetting;
|
---|
179 | int rc;
|
---|
180 |
|
---|
181 | (void) child;
|
---|
182 | (void) context_id;
|
---|
183 | (void) num_contexts;
|
---|
184 |
|
---|
185 | self->privatePtr = (void *) &render_spu;
|
---|
186 |
|
---|
187 | #ifdef CHROMIUM_THREADSAFE
|
---|
188 | crDebug("Render SPU: thread-safe");
|
---|
189 | #endif
|
---|
190 |
|
---|
191 | crMemZero(&render_spu, sizeof(render_spu));
|
---|
192 |
|
---|
193 | render_spu.id = id;
|
---|
194 | renderspuSetVBoxConfiguration(&render_spu);
|
---|
195 |
|
---|
196 | if (render_spu.swap_master_url)
|
---|
197 | swapsyncConnect();
|
---|
198 |
|
---|
199 |
|
---|
200 | /* Get our special functions. */
|
---|
201 | numSpecial = renderspuCreateFunctions( _cr_render_table );
|
---|
202 |
|
---|
203 | #ifdef RT_OS_WINDOWS
|
---|
204 | /* Start thread to create windows and process window messages */
|
---|
205 | crDebug("RenderSPU: Starting windows serving thread");
|
---|
206 | render_spu.hWinThreadReadyEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
---|
207 | if (!render_spu.hWinThreadReadyEvent)
|
---|
208 | {
|
---|
209 | crError("RenderSPU: Failed to create WinThreadReadyEvent! (%x)", GetLastError());
|
---|
210 | return NULL;
|
---|
211 | }
|
---|
212 |
|
---|
213 | if (!CreateThread(NULL, 0, renderSPUWindowThreadProc, 0, 0, &render_spu.dwWinThreadId))
|
---|
214 | {
|
---|
215 | crError("RenderSPU: Failed to start windows thread! (%x)", GetLastError());
|
---|
216 | return NULL;
|
---|
217 | }
|
---|
218 | WaitForSingleObject(render_spu.hWinThreadReadyEvent, INFINITE);
|
---|
219 | #endif
|
---|
220 |
|
---|
221 | /* Get the OpenGL functions. */
|
---|
222 | numFuncs = crLoadOpenGL( &render_spu.ws, _cr_render_table + numSpecial );
|
---|
223 | if (numFuncs == 0) {
|
---|
224 | crError("The render SPU was unable to load the native OpenGL library");
|
---|
225 | return NULL;
|
---|
226 | }
|
---|
227 |
|
---|
228 | numFuncs += numSpecial;
|
---|
229 |
|
---|
230 | render_spu.contextTable = crAllocHashtableEx(1, INT32_MAX);
|
---|
231 | render_spu.windowTable = crAllocHashtableEx(1, INT32_MAX);
|
---|
232 |
|
---|
233 | render_spu.dummyWindowTable = crAllocHashtable();
|
---|
234 |
|
---|
235 | pcpwSetting = crGetenv("CR_RENDER_ENABLE_SINGLE_PRESENT_CONTEXT");
|
---|
236 | if (pcpwSetting)
|
---|
237 | {
|
---|
238 | if (pcpwSetting[0] == '0')
|
---|
239 | pcpwSetting = NULL;
|
---|
240 | }
|
---|
241 |
|
---|
242 | if (pcpwSetting)
|
---|
243 | {
|
---|
244 | /* TODO: need proper blitter synchronization, do not use so far!
|
---|
245 | * the problem is that rendering can be done in multiple thread: the main command (hgcm) thread and the redraw thread
|
---|
246 | * we currently use per-window synchronization, while we'll need a per-blitter synchronization if one blitter is used for multiple windows
|
---|
247 | * this is not done currently */
|
---|
248 | crWarning("TODO: need proper blitter synchronization, do not use so far!");
|
---|
249 | render_spu.blitterTable = crAllocHashtable();
|
---|
250 | CRASSERT(render_spu.blitterTable);
|
---|
251 | }
|
---|
252 | else
|
---|
253 | render_spu.blitterTable = NULL;
|
---|
254 |
|
---|
255 | CRASSERT(render_spu.default_visual & CR_RGB_BIT);
|
---|
256 |
|
---|
257 | rc = renderspu_SystemInit();
|
---|
258 | if (!RT_SUCCESS(rc))
|
---|
259 | {
|
---|
260 | crError("renderspu_SystemInit failed rc %d", rc);
|
---|
261 | return NULL;
|
---|
262 | }
|
---|
263 | #ifdef USE_OSMESA
|
---|
264 | if (render_spu.use_osmesa) {
|
---|
265 | if (!crLoadOSMesa(&render_spu.OSMesaCreateContext,
|
---|
266 | &render_spu.OSMesaMakeCurrent,
|
---|
267 | &render_spu.OSMesaDestroyContext)) {
|
---|
268 | crError("Unable to load OSMesa library");
|
---|
269 | }
|
---|
270 | }
|
---|
271 | #endif
|
---|
272 |
|
---|
273 | #ifdef DARWIN
|
---|
274 | # ifdef VBOX_WITH_COCOA_QT
|
---|
275 | # else /* VBOX_WITH_COCOA_QT */
|
---|
276 | render_spu.hRootVisibleRegion = 0;
|
---|
277 | render_spu.currentBufferName = 1;
|
---|
278 | render_spu.uiDockUpdateTS = 0;
|
---|
279 | /* Create a mutex for synchronizing events from the main Qt thread & this
|
---|
280 | thread */
|
---|
281 | RTSemFastMutexCreate(&render_spu.syncMutex);
|
---|
282 | /* Create our window groups */
|
---|
283 | CreateWindowGroup(kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrSharedActivation | kWindowGroupAttrHideOnCollapse | kWindowGroupAttrFixedLevel, &render_spu.pMasterGroup);
|
---|
284 | CreateWindowGroup(kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrSharedActivation | kWindowGroupAttrHideOnCollapse | kWindowGroupAttrFixedLevel, &render_spu.pParentGroup);
|
---|
285 | /* Make the correct z-layering */
|
---|
286 | SendWindowGroupBehind (render_spu.pParentGroup, render_spu.pMasterGroup);
|
---|
287 | /* and set the gParentGroup as parent for gMasterGroup. */
|
---|
288 | SetWindowGroupParent (render_spu.pMasterGroup, render_spu.pParentGroup);
|
---|
289 | /* Install the event handlers */
|
---|
290 | EventTypeSpec eventList[] =
|
---|
291 | {
|
---|
292 | {kEventClassVBox, kEventVBoxUpdateContext}, /* Update the context after show/size/move events */
|
---|
293 | {kEventClassVBox, kEventVBoxBoundsChanged} /* Clip/Pos the OpenGL windows when the main window is changed in pos/size */
|
---|
294 | };
|
---|
295 | /* We need to process events from our main window */
|
---|
296 | render_spu.hParentEventHandler = NewEventHandlerUPP(windowEvtHndlr);
|
---|
297 | InstallApplicationEventHandler (render_spu.hParentEventHandler,
|
---|
298 | GetEventTypeCount(eventList), eventList,
|
---|
299 | NULL, NULL);
|
---|
300 | render_spu.fInit = true;
|
---|
301 | # endif /* VBOX_WITH_COCOA_QT */
|
---|
302 | #endif /* DARWIN */
|
---|
303 |
|
---|
304 | rc = renderspuDefaultCtxInit();
|
---|
305 | if (!RT_SUCCESS(rc))
|
---|
306 | {
|
---|
307 | WARN(("renderspuDefaultCtxInit failed %d", rc));
|
---|
308 | return NULL;
|
---|
309 | }
|
---|
310 |
|
---|
311 | /*
|
---|
312 | * Get the OpenGL extension functions.
|
---|
313 | * SIGH -- we have to wait until the very bitter end to load the
|
---|
314 | * extensions, because the context has to be bound before
|
---|
315 | * wglGetProcAddress will work correctly. No such issue with GLX though.
|
---|
316 | */
|
---|
317 | numFuncs += crLoadOpenGLExtensions( &render_spu.ws, _cr_render_table + numFuncs );
|
---|
318 | CRASSERT(numFuncs < 1000);
|
---|
319 |
|
---|
320 | #ifdef WINDOWS
|
---|
321 | /*
|
---|
322 | * Same problem as above, these are extensions so we need to
|
---|
323 | * load them after a context has been bound. As they're WGL
|
---|
324 | * extensions too, we can't simply tag them into the spu_loader.
|
---|
325 | * So we do them here for now.
|
---|
326 | * Grrr, NVIDIA driver uses EXT for GetExtensionsStringEXT,
|
---|
327 | * but ARB for others. Need further testing here....
|
---|
328 | */
|
---|
329 | render_spu.ws.wglGetExtensionsStringEXT =
|
---|
330 | (wglGetExtensionsStringEXTFunc_t)
|
---|
331 | render_spu.ws.wglGetProcAddress( "wglGetExtensionsStringEXT" );
|
---|
332 | render_spu.ws.wglChoosePixelFormatEXT =
|
---|
333 | (wglChoosePixelFormatEXTFunc_t)
|
---|
334 | render_spu.ws.wglGetProcAddress( "wglChoosePixelFormatARB" );
|
---|
335 | render_spu.ws.wglGetPixelFormatAttribivEXT =
|
---|
336 | (wglGetPixelFormatAttribivEXTFunc_t)
|
---|
337 | render_spu.ws.wglGetProcAddress( "wglGetPixelFormatAttribivARB" );
|
---|
338 | render_spu.ws.wglGetPixelFormatAttribfvEXT =
|
---|
339 | (wglGetPixelFormatAttribfvEXTFunc_t)
|
---|
340 | render_spu.ws.wglGetProcAddress( "wglGetPixelFormatAttribfvARB" );
|
---|
341 |
|
---|
342 | if (render_spu.ws.wglGetProcAddress("glCopyTexSubImage3D"))
|
---|
343 | {
|
---|
344 | _cr_render_table[numFuncs].name = crStrdup("CopyTexSubImage3D");
|
---|
345 | _cr_render_table[numFuncs].fn = (SPUGenericFunction) render_spu.ws.wglGetProcAddress("glCopyTexSubImage3D");
|
---|
346 | ++numFuncs;
|
---|
347 | crDebug("Render SPU: Found glCopyTexSubImage3D function");
|
---|
348 | }
|
---|
349 |
|
---|
350 | if (render_spu.ws.wglGetProcAddress("glDrawRangeElements"))
|
---|
351 | {
|
---|
352 | _cr_render_table[numFuncs].name = crStrdup("DrawRangeElements");
|
---|
353 | _cr_render_table[numFuncs].fn = (SPUGenericFunction) render_spu.ws.wglGetProcAddress("glDrawRangeElements");
|
---|
354 | ++numFuncs;
|
---|
355 | crDebug("Render SPU: Found glDrawRangeElements function");
|
---|
356 | }
|
---|
357 |
|
---|
358 | if (render_spu.ws.wglGetProcAddress("glTexSubImage3D"))
|
---|
359 | {
|
---|
360 | _cr_render_table[numFuncs].name = crStrdup("TexSubImage3D");
|
---|
361 | _cr_render_table[numFuncs].fn = (SPUGenericFunction) render_spu.ws.wglGetProcAddress("glTexSubImage3D");
|
---|
362 | ++numFuncs;
|
---|
363 | crDebug("Render SPU: Found glTexSubImage3D function");
|
---|
364 | }
|
---|
365 |
|
---|
366 | if (render_spu.ws.wglGetProcAddress("glTexImage3D"))
|
---|
367 | {
|
---|
368 | _cr_render_table[numFuncs].name = crStrdup("TexImage3D");
|
---|
369 | _cr_render_table[numFuncs].fn = (SPUGenericFunction) render_spu.ws.wglGetProcAddress("glTexImage3D");
|
---|
370 | ++numFuncs;
|
---|
371 | crDebug("Render SPU: Found glTexImage3D function");
|
---|
372 | }
|
---|
373 |
|
---|
374 | if (render_spu.ws.wglGetExtensionsStringEXT) {
|
---|
375 | crDebug("WGL - found wglGetExtensionsStringEXT\n");
|
---|
376 | }
|
---|
377 | if (render_spu.ws.wglChoosePixelFormatEXT) {
|
---|
378 | crDebug("WGL - found wglChoosePixelFormatEXT\n");
|
---|
379 | }
|
---|
380 | #endif
|
---|
381 |
|
---|
382 | render_spu.barrierHash = crAllocHashtable();
|
---|
383 |
|
---|
384 | render_spu.cursorX = 0;
|
---|
385 | render_spu.cursorY = 0;
|
---|
386 | render_spu.use_L2 = 0;
|
---|
387 |
|
---|
388 | render_spu.gather_conns = NULL;
|
---|
389 |
|
---|
390 | numFuncs = renderspu_SystemPostprocessFunctions(_cr_render_table, numFuncs, RT_ELEMENTS(_cr_render_table));
|
---|
391 |
|
---|
392 | crDebug("Render SPU: ---------- End of Init -------------");
|
---|
393 |
|
---|
394 | return &render_functions;
|
---|
395 | }
|
---|
396 |
|
---|
397 | static void renderSPUSelfDispatch(SPUDispatchTable *self)
|
---|
398 | {
|
---|
399 | crSPUInitDispatchTable( &(render_spu.self) );
|
---|
400 | crSPUCopyDispatchTable( &(render_spu.self), self );
|
---|
401 |
|
---|
402 | crSPUInitDispatchTable( &(render_spu.blitterDispatch) );
|
---|
403 | crSPUCopyDispatchTable( &(render_spu.blitterDispatch), self );
|
---|
404 |
|
---|
405 | render_spu.server = (CRServer *)(self->server);
|
---|
406 |
|
---|
407 | {
|
---|
408 | GLfloat version;
|
---|
409 | version = crStrToFloat((const char *) render_spu.ws.glGetString(GL_VERSION));
|
---|
410 |
|
---|
411 | if (version>=2.f || crStrstr((const char*)render_spu.ws.glGetString(GL_EXTENSIONS), "GL_ARB_vertex_shader"))
|
---|
412 | {
|
---|
413 | GLint mu=0;
|
---|
414 | render_spu.self.GetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &mu);
|
---|
415 | crInfo("Render SPU: GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB=%i", mu);
|
---|
416 | }
|
---|
417 | }
|
---|
418 | }
|
---|
419 |
|
---|
420 |
|
---|
421 | static void DeleteContextCallback( void *data )
|
---|
422 | {
|
---|
423 | ContextInfo *context = (ContextInfo *) data;
|
---|
424 | renderspuContextMarkDeletedAndRelease(context);
|
---|
425 | }
|
---|
426 |
|
---|
427 | static void DeleteWindowCallback( void *data )
|
---|
428 | {
|
---|
429 | WindowInfo *window = (WindowInfo *) data;
|
---|
430 | renderspuWinTermOnShutdown(window);
|
---|
431 | renderspuWinRelease(window);
|
---|
432 | }
|
---|
433 |
|
---|
434 | static void DeleteBlitterCallback( void *data )
|
---|
435 | {
|
---|
436 | PCR_BLITTER pBlitter = (PCR_BLITTER) data;
|
---|
437 | CrBltTerm(pBlitter);
|
---|
438 | crFree(pBlitter);
|
---|
439 | }
|
---|
440 |
|
---|
441 | static void renderspuBlitterCleanupCB(unsigned long key, void *data1, void *data2)
|
---|
442 | {
|
---|
443 | WindowInfo *window = (WindowInfo *) data1;
|
---|
444 | CRASSERT(window);
|
---|
445 |
|
---|
446 | renderspuVBoxPresentBlitterCleanup( window );
|
---|
447 | }
|
---|
448 |
|
---|
449 |
|
---|
450 | static void renderspuDeleteBlitterCB(unsigned long key, void *data1, void *data2)
|
---|
451 | {
|
---|
452 | CRHashTable *pTbl = (CRHashTable*)data2;
|
---|
453 |
|
---|
454 | crHashtableDelete( pTbl, key, NULL );
|
---|
455 |
|
---|
456 | DeleteBlitterCallback(data1);
|
---|
457 | }
|
---|
458 |
|
---|
459 |
|
---|
460 | static void renderspuDeleteWindowCB(unsigned long key, void *data1, void *data2)
|
---|
461 | {
|
---|
462 | CRHashTable *pTbl = (CRHashTable*)data2;
|
---|
463 |
|
---|
464 | crHashtableDelete( pTbl, key, NULL );
|
---|
465 |
|
---|
466 | DeleteWindowCallback(data1);
|
---|
467 | }
|
---|
468 |
|
---|
469 | static void renderspuDeleteBarierCB(unsigned long key, void *data1, void *data2)
|
---|
470 | {
|
---|
471 | CRHashTable *pTbl = (CRHashTable*)data2;
|
---|
472 |
|
---|
473 | crHashtableDelete( pTbl, key, NULL );
|
---|
474 |
|
---|
475 | crFree(data1);
|
---|
476 | }
|
---|
477 |
|
---|
478 |
|
---|
479 | static void renderspuDeleteContextCB(unsigned long key, void *data1, void *data2)
|
---|
480 | {
|
---|
481 | CRHashTable *pTbl = (CRHashTable*)data2;
|
---|
482 |
|
---|
483 | crHashtableDelete( pTbl, key, NULL );
|
---|
484 |
|
---|
485 | DeleteContextCallback(data1);
|
---|
486 | }
|
---|
487 |
|
---|
488 | void renderspuCleanupBase(bool fDeleteTables)
|
---|
489 | {
|
---|
490 | renderspuVBoxCompositorClearAll();
|
---|
491 |
|
---|
492 | if (render_spu.blitterTable)
|
---|
493 | {
|
---|
494 | if (fDeleteTables)
|
---|
495 | {
|
---|
496 | crFreeHashtable(render_spu.blitterTable, DeleteBlitterCallback);
|
---|
497 | render_spu.blitterTable = NULL;
|
---|
498 | }
|
---|
499 | else
|
---|
500 | {
|
---|
501 | crHashtableWalk(render_spu.blitterTable, renderspuDeleteBlitterCB, render_spu.contextTable);
|
---|
502 | }
|
---|
503 | }
|
---|
504 | else
|
---|
505 | {
|
---|
506 | crHashtableWalk(render_spu.windowTable, renderspuBlitterCleanupCB, NULL);
|
---|
507 |
|
---|
508 | crHashtableWalk(render_spu.dummyWindowTable, renderspuBlitterCleanupCB, NULL);
|
---|
509 | }
|
---|
510 |
|
---|
511 | renderspuSetDefaultSharedContext(NULL);
|
---|
512 |
|
---|
513 | if (fDeleteTables)
|
---|
514 | {
|
---|
515 | crFreeHashtable(render_spu.contextTable, DeleteContextCallback);
|
---|
516 | render_spu.contextTable = NULL;
|
---|
517 | crFreeHashtable(render_spu.windowTable, DeleteWindowCallback);
|
---|
518 | render_spu.windowTable = NULL;
|
---|
519 | crFreeHashtable(render_spu.dummyWindowTable, DeleteWindowCallback);
|
---|
520 | render_spu.dummyWindowTable = NULL;
|
---|
521 | crFreeHashtable(render_spu.barrierHash, crFree);
|
---|
522 | render_spu.barrierHash = NULL;
|
---|
523 | }
|
---|
524 | else
|
---|
525 | {
|
---|
526 | crHashtableWalk(render_spu.contextTable, renderspuDeleteContextCB, render_spu.contextTable);
|
---|
527 | crHashtableWalk(render_spu.windowTable, renderspuDeleteWindowCB, render_spu.windowTable);
|
---|
528 | crHashtableWalk(render_spu.dummyWindowTable, renderspuDeleteWindowCB, render_spu.dummyWindowTable);
|
---|
529 | crHashtableWalk(render_spu.barrierHash, renderspuDeleteBarierCB, render_spu.barrierHash);
|
---|
530 | }
|
---|
531 | }
|
---|
532 |
|
---|
533 | static int renderSPUCleanup(void)
|
---|
534 | {
|
---|
535 | renderspuCleanupBase(true);
|
---|
536 |
|
---|
537 | #ifdef RT_OS_DARWIN
|
---|
538 | # ifndef VBOX_WITH_COCOA_QT
|
---|
539 | render_spu.fInit = false;
|
---|
540 | DisposeEventHandlerUPP(render_spu.hParentEventHandler);
|
---|
541 | ReleaseWindowGroup(render_spu.pMasterGroup);
|
---|
542 | ReleaseWindowGroup(render_spu.pParentGroup);
|
---|
543 | if (render_spu.hRootVisibleRegion)
|
---|
544 | {
|
---|
545 | DisposeRgn(render_spu.hRootVisibleRegion);
|
---|
546 | render_spu.hRootVisibleRegion = 0;
|
---|
547 | }
|
---|
548 | render_spu.currentBufferName = 1;
|
---|
549 | render_spu.uiDockUpdateTS = 0;
|
---|
550 | RTSemFastMutexDestroy(render_spu.syncMutex);
|
---|
551 | # else /* VBOX_WITH_COCOA_QT */
|
---|
552 | # endif /* VBOX_WITH_COCOA_QT */
|
---|
553 | #endif /* RT_OS_DARWIN */
|
---|
554 |
|
---|
555 | #ifdef RT_OS_WINDOWS
|
---|
556 | if (render_spu.dwWinThreadId)
|
---|
557 | {
|
---|
558 | HANDLE hNative;
|
---|
559 |
|
---|
560 | hNative = OpenThread(SYNCHRONIZE|THREAD_QUERY_INFORMATION|THREAD_TERMINATE,
|
---|
561 | false, render_spu.dwWinThreadId);
|
---|
562 | if (!hNative)
|
---|
563 | {
|
---|
564 | crWarning("Failed to get handle for window thread(%#x)", GetLastError());
|
---|
565 | }
|
---|
566 |
|
---|
567 | if (PostThreadMessage(render_spu.dwWinThreadId, WM_QUIT, 0, 0))
|
---|
568 | {
|
---|
569 | WaitForSingleObject(render_spu.hWinThreadReadyEvent, INFINITE);
|
---|
570 |
|
---|
571 | /*wait for os thread to actually finish*/
|
---|
572 | if (hNative && WaitForSingleObject(hNative, 3000)==WAIT_TIMEOUT)
|
---|
573 | {
|
---|
574 | crDebug("Wait failed, terminating");
|
---|
575 | if (!TerminateThread(hNative, 1))
|
---|
576 | {
|
---|
577 | crWarning("TerminateThread failed");
|
---|
578 | }
|
---|
579 | }
|
---|
580 | }
|
---|
581 |
|
---|
582 | if (hNative)
|
---|
583 | {
|
---|
584 | CloseHandle(hNative);
|
---|
585 | }
|
---|
586 | }
|
---|
587 | CloseHandle(render_spu.hWinThreadReadyEvent);
|
---|
588 | render_spu.hWinThreadReadyEvent = NULL;
|
---|
589 | #endif
|
---|
590 |
|
---|
591 | crUnloadOpenGL();
|
---|
592 |
|
---|
593 | #ifdef CHROMIUM_THREADSAFE
|
---|
594 | crFreeTSD(&_RenderTSD);
|
---|
595 | #endif
|
---|
596 |
|
---|
597 | return 1;
|
---|
598 | }
|
---|
599 |
|
---|
600 |
|
---|
601 | extern SPUOptions renderSPUOptions[];
|
---|
602 |
|
---|
603 | int SPULoad( char **name, char **super, SPUInitFuncPtr *init,
|
---|
604 | SPUSelfDispatchFuncPtr *self, SPUCleanupFuncPtr *cleanup,
|
---|
605 | SPUOptionsPtr *options, int *flags )
|
---|
606 | {
|
---|
607 | *name = "render";
|
---|
608 | *super = NULL;
|
---|
609 | *init = renderSPUInit;
|
---|
610 | *self = renderSPUSelfDispatch;
|
---|
611 | *cleanup = renderSPUCleanup;
|
---|
612 | *options = renderSPUOptions;
|
---|
613 | *flags = (SPU_NO_PACKER|SPU_IS_TERMINAL|SPU_MAX_SERVERS_ZERO);
|
---|
614 |
|
---|
615 | return 1;
|
---|
616 | }
|
---|
617 |
|
---|
618 | DECLEXPORT(void) renderspuSetWindowId(uint64_t winId)
|
---|
619 | {
|
---|
620 | render_spu_parent_window_id = winId;
|
---|
621 | }
|
---|