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_packfunctions.h"
|
---|
8 | #include "packspu.h"
|
---|
9 | #include "packspu_proto.h"
|
---|
10 | #include "cr_mem.h"
|
---|
11 |
|
---|
12 | void PACKSPU_APIENTRY packspu_ChromiumParametervCR(GLenum target, GLenum type, GLsizei count, const GLvoid *values)
|
---|
13 | {
|
---|
14 |
|
---|
15 | CRMessage msg;
|
---|
16 | int len;
|
---|
17 | GLint ai32ServerValues[2];
|
---|
18 | GLboolean fFlush = GL_FALSE;
|
---|
19 | GET_THREAD(thread);
|
---|
20 |
|
---|
21 |
|
---|
22 | switch(target)
|
---|
23 | {
|
---|
24 | case GL_GATHER_PACK_CR:
|
---|
25 | /* flush the current pack buffer */
|
---|
26 | packspuFlush( (void *) thread );
|
---|
27 |
|
---|
28 | /* the connection is thread->server.conn */
|
---|
29 | msg.header.type = CR_MESSAGE_GATHER;
|
---|
30 | msg.gather.offset = 69;
|
---|
31 | len = sizeof(CRMessageGather);
|
---|
32 | crNetSend(thread->netServer.conn, NULL, &msg, len);
|
---|
33 | return;
|
---|
34 |
|
---|
35 | case GL_SHARE_LISTS_CR:
|
---|
36 | {
|
---|
37 | ContextInfo *pCtx[2];
|
---|
38 | GLint *ai32Values;
|
---|
39 | int i;
|
---|
40 | if (count != 2)
|
---|
41 | {
|
---|
42 | WARN(("GL_SHARE_LISTS_CR invalid cound %d", count));
|
---|
43 | return;
|
---|
44 | }
|
---|
45 |
|
---|
46 | if (type != GL_UNSIGNED_INT && type != GL_INT)
|
---|
47 | {
|
---|
48 | WARN(("GL_SHARE_LISTS_CR invalid type %d", type));
|
---|
49 | return;
|
---|
50 | }
|
---|
51 |
|
---|
52 | ai32Values = (GLint*)values;
|
---|
53 |
|
---|
54 | for (i = 0; i < 2; ++i)
|
---|
55 | {
|
---|
56 | const int slot = ai32Values[i] - MAGIC_OFFSET;
|
---|
57 |
|
---|
58 | if (slot < 0 || slot >= pack_spu.numContexts)
|
---|
59 | {
|
---|
60 | WARN(("GL_SHARE_LISTS_CR invalid value[%d] %d", i, ai32Values[i]));
|
---|
61 | return;
|
---|
62 | }
|
---|
63 |
|
---|
64 | pCtx[i] = &pack_spu.context[slot];
|
---|
65 | if (!pCtx[i]->clientState)
|
---|
66 | {
|
---|
67 | WARN(("GL_SHARE_LISTS_CR invalid pCtx1 for value[%d] %d", i, ai32Values[i]));
|
---|
68 | return;
|
---|
69 | }
|
---|
70 |
|
---|
71 | ai32ServerValues[i] = pCtx[i]->serverCtx;
|
---|
72 | }
|
---|
73 |
|
---|
74 | crStateShareLists(pCtx[0]->clientState, pCtx[1]->clientState);
|
---|
75 |
|
---|
76 | values = ai32ServerValues;
|
---|
77 |
|
---|
78 | fFlush = GL_TRUE;
|
---|
79 |
|
---|
80 | break;
|
---|
81 | }
|
---|
82 |
|
---|
83 | default:
|
---|
84 | break;
|
---|
85 | }
|
---|
86 |
|
---|
87 | crPackChromiumParametervCR(target, type, count, values);
|
---|
88 |
|
---|
89 | if (fFlush)
|
---|
90 | packspuFlush( (void *) thread );
|
---|
91 | }
|
---|
92 |
|
---|
93 | GLboolean packspuSyncOnFlushes(void)
|
---|
94 | {
|
---|
95 | #if 1 /*Seems to still cause issues, always sync for now*/
|
---|
96 | return 1;
|
---|
97 | #else
|
---|
98 | GLint buffer;
|
---|
99 |
|
---|
100 | crStateGetIntegerv(&pack_spu.StateTracker, GL_DRAW_BUFFER, &buffer);
|
---|
101 | /*Usually buffer==GL_BACK, so put this extra check to simplify boolean eval on runtime*/
|
---|
102 | return (buffer != GL_BACK)
|
---|
103 | && (buffer == GL_FRONT_LEFT
|
---|
104 | || buffer == GL_FRONT_RIGHT
|
---|
105 | || buffer == GL_FRONT
|
---|
106 | || buffer == GL_FRONT_AND_BACK
|
---|
107 | || buffer == GL_LEFT
|
---|
108 | || buffer == GL_RIGHT);
|
---|
109 | #endif
|
---|
110 | }
|
---|
111 |
|
---|
112 | void PACKSPU_APIENTRY packspu_DrawBuffer(GLenum mode)
|
---|
113 | {
|
---|
114 | GLboolean hadtoflush;
|
---|
115 |
|
---|
116 | hadtoflush = packspuSyncOnFlushes();
|
---|
117 |
|
---|
118 | crStateDrawBuffer(&pack_spu.StateTracker, mode);
|
---|
119 | crPackDrawBuffer(mode);
|
---|
120 |
|
---|
121 | if (hadtoflush && !packspuSyncOnFlushes())
|
---|
122 | packspu_Flush();
|
---|
123 | }
|
---|
124 |
|
---|
125 | void PACKSPU_APIENTRY packspu_Finish( void )
|
---|
126 | {
|
---|
127 | GET_THREAD(thread);
|
---|
128 | GLint writeback = CRPACKSPU_IS_WDDM_CRHGSMI() ? 1 : pack_spu.thread[pack_spu.idxThreadInUse].netServer.conn->actual_network;
|
---|
129 |
|
---|
130 | crPackFinish();
|
---|
131 | if (packspuSyncOnFlushes())
|
---|
132 | {
|
---|
133 | if (writeback)
|
---|
134 | {
|
---|
135 | crPackWriteback(&writeback);
|
---|
136 |
|
---|
137 | packspuFlush( (void *) thread );
|
---|
138 |
|
---|
139 | CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
|
---|
140 | }
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | void PACKSPU_APIENTRY packspu_Flush( void )
|
---|
145 | {
|
---|
146 | GET_THREAD(thread);
|
---|
147 | int writeback=1;
|
---|
148 | int found=0;
|
---|
149 |
|
---|
150 | if (!thread->bInjectThread)
|
---|
151 | {
|
---|
152 | crPackFlush();
|
---|
153 | if (packspuSyncOnFlushes())
|
---|
154 | {
|
---|
155 | crPackWriteback(&writeback);
|
---|
156 | packspuFlush( (void *) thread );
|
---|
157 | CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
|
---|
158 | }
|
---|
159 | }
|
---|
160 | else
|
---|
161 | {
|
---|
162 | int i;
|
---|
163 |
|
---|
164 | crLockMutex(&_PackMutex);
|
---|
165 |
|
---|
166 | /*Make sure we process commands in order they should appear, so flush other threads first*/
|
---|
167 | for (i=0; i<MAX_THREADS; ++i)
|
---|
168 | {
|
---|
169 | if (pack_spu.thread[i].inUse
|
---|
170 | && (thread != &pack_spu.thread[i]) && pack_spu.thread[i].netServer.conn
|
---|
171 | && pack_spu.thread[i].packer && pack_spu.thread[i].packer->currentBuffer)
|
---|
172 | {
|
---|
173 | packspuFlush((void *) &pack_spu.thread[i]);
|
---|
174 |
|
---|
175 | if (pack_spu.thread[i].netServer.conn->u32ClientID == thread->netServer.conn->u32InjectClientID)
|
---|
176 | {
|
---|
177 | found=1;
|
---|
178 | }
|
---|
179 |
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | if (!found)
|
---|
184 | {
|
---|
185 | /*Thread we're supposed to inject commands for has been detached,
|
---|
186 | so there's nothing to sync with and we should just pass commands through our own connection.
|
---|
187 | */
|
---|
188 | thread->netServer.conn->u32InjectClientID=0;
|
---|
189 | }
|
---|
190 |
|
---|
191 | packspuFlush((void *) thread);
|
---|
192 |
|
---|
193 | crUnlockMutex(&_PackMutex);
|
---|
194 | }
|
---|
195 | }
|
---|
196 |
|
---|
197 | void PACKSPU_APIENTRY packspu_NewList(GLuint list, GLenum mode)
|
---|
198 | {
|
---|
199 | crStateNewList(&pack_spu.StateTracker, list, mode);
|
---|
200 | crPackNewList(list, mode);
|
---|
201 | }
|
---|
202 |
|
---|
203 | void PACKSPU_APIENTRY packspu_EndList()
|
---|
204 | {
|
---|
205 | crStateEndList(&pack_spu.StateTracker);
|
---|
206 | crPackEndList();
|
---|
207 | }
|
---|
208 |
|
---|
209 | void PACKSPU_APIENTRY packspu_VBoxWindowDestroy( GLint con, GLint window )
|
---|
210 | {
|
---|
211 | if (CRPACKSPU_IS_WDDM_CRHGSMI())
|
---|
212 | {
|
---|
213 | GET_THREAD(thread);
|
---|
214 | if (con)
|
---|
215 | {
|
---|
216 | CRPackContext * curPacker = crPackGetContext();
|
---|
217 | CRASSERT(!thread || !thread->bInjectThread);
|
---|
218 | thread = GET_THREAD_VAL_ID(con);
|
---|
219 | crPackSetContext(thread->packer);
|
---|
220 | crPackWindowDestroy(window);
|
---|
221 | if (curPacker != thread->packer)
|
---|
222 | crPackSetContext(curPacker);
|
---|
223 | return;
|
---|
224 | }
|
---|
225 | CRASSERT(thread);
|
---|
226 | CRASSERT(thread->bInjectThread);
|
---|
227 | }
|
---|
228 | crPackWindowDestroy(window);
|
---|
229 | }
|
---|
230 |
|
---|
231 | GLint PACKSPU_APIENTRY packspu_VBoxWindowCreate( GLint con, const char *dpyName, GLint visBits )
|
---|
232 | {
|
---|
233 | GET_THREAD(thread);
|
---|
234 | static int num_calls = 0;
|
---|
235 | int writeback = CRPACKSPU_IS_WDDM_CRHGSMI() ? 1 : pack_spu.thread[pack_spu.idxThreadInUse].netServer.conn->actual_network;
|
---|
236 | GLint return_val = (GLint) 0;
|
---|
237 | ThreadInfo *curThread = thread;
|
---|
238 | GLint retVal;
|
---|
239 |
|
---|
240 | if (CRPACKSPU_IS_WDDM_CRHGSMI())
|
---|
241 | {
|
---|
242 | if (!con)
|
---|
243 | {
|
---|
244 | crError("connection expected!");
|
---|
245 | return 0;
|
---|
246 | }
|
---|
247 | thread = GET_THREAD_VAL_ID(con);
|
---|
248 | }
|
---|
249 | else
|
---|
250 | {
|
---|
251 | CRASSERT(!con);
|
---|
252 | if (!thread) {
|
---|
253 | thread = packspuNewThread(
|
---|
254 | #if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
|
---|
255 | NULL
|
---|
256 | #endif
|
---|
257 | );
|
---|
258 | }
|
---|
259 | }
|
---|
260 | CRASSERT(thread);
|
---|
261 | CRASSERT(thread->packer);
|
---|
262 | CRASSERT(crPackGetContext() == (curThread ? curThread->packer : NULL));
|
---|
263 |
|
---|
264 | crPackSetContext(thread->packer);
|
---|
265 | crPackWindowCreate( dpyName, visBits, &return_val, &writeback );
|
---|
266 | packspuFlush(thread);
|
---|
267 | if (!(thread->netServer.conn->actual_network))
|
---|
268 | {
|
---|
269 | retVal = num_calls++;
|
---|
270 | }
|
---|
271 | else
|
---|
272 | {
|
---|
273 | CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
|
---|
274 | retVal = return_val;
|
---|
275 | }
|
---|
276 |
|
---|
277 | if (CRPACKSPU_IS_WDDM_CRHGSMI())
|
---|
278 | {
|
---|
279 | if (thread != curThread)
|
---|
280 | {
|
---|
281 | if (curThread)
|
---|
282 | crPackSetContext(curThread->packer);
|
---|
283 | else
|
---|
284 | crPackSetContext(NULL);
|
---|
285 | }
|
---|
286 | }
|
---|
287 |
|
---|
288 | return retVal;
|
---|
289 | }
|
---|
290 |
|
---|
291 | GLint PACKSPU_APIENTRY packspu_WindowCreate( const char *dpyName, GLint visBits )
|
---|
292 | {
|
---|
293 | return packspu_VBoxWindowCreate( 0, dpyName, visBits );
|
---|
294 | }
|
---|
295 |
|
---|
296 | GLboolean PACKSPU_APIENTRY
|
---|
297 | packspu_AreTexturesResident( GLsizei n, const GLuint * textures,
|
---|
298 | GLboolean * residences )
|
---|
299 | {
|
---|
300 | GET_THREAD(thread);
|
---|
301 | int writeback = 1;
|
---|
302 | GLboolean return_val = GL_TRUE;
|
---|
303 | GLsizei i;
|
---|
304 |
|
---|
305 | if (!CRPACKSPU_IS_WDDM_CRHGSMI() && !(pack_spu.thread[pack_spu.idxThreadInUse].netServer.conn->actual_network))
|
---|
306 | {
|
---|
307 | crError( "packspu_AreTexturesResident doesn't work when there's no actual network involved!\nTry using the simplequery SPU in your chain!" );
|
---|
308 | }
|
---|
309 |
|
---|
310 | crPackAreTexturesResident( n, textures, residences, &return_val, &writeback );
|
---|
311 | packspuFlush( (void *) thread );
|
---|
312 |
|
---|
313 | CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
|
---|
314 |
|
---|
315 | /* Since the Chromium packer/unpacker can't return both 'residences'
|
---|
316 | * and the function's return value, compute the return value here.
|
---|
317 | */
|
---|
318 | for (i = 0; i < n; i++) {
|
---|
319 | if (!residences[i]) {
|
---|
320 | return_val = GL_FALSE;
|
---|
321 | break;
|
---|
322 | }
|
---|
323 | }
|
---|
324 |
|
---|
325 | return return_val;
|
---|
326 | }
|
---|
327 |
|
---|
328 |
|
---|
329 | GLboolean PACKSPU_APIENTRY
|
---|
330 | packspu_AreProgramsResidentNV( GLsizei n, const GLuint * ids,
|
---|
331 | GLboolean * residences )
|
---|
332 | {
|
---|
333 | GET_THREAD(thread);
|
---|
334 | int writeback = 1;
|
---|
335 | GLboolean return_val = GL_TRUE;
|
---|
336 | GLsizei i;
|
---|
337 |
|
---|
338 | if (!CRPACKSPU_IS_WDDM_CRHGSMI() && !(pack_spu.thread[pack_spu.idxThreadInUse].netServer.conn->actual_network))
|
---|
339 | {
|
---|
340 | crError( "packspu_AreProgramsResidentNV doesn't work when there's no actual network involved!\nTry using the simplequery SPU in your chain!" );
|
---|
341 | }
|
---|
342 |
|
---|
343 | crPackAreProgramsResidentNV( n, ids, residences, &return_val, &writeback );
|
---|
344 | packspuFlush( (void *) thread );
|
---|
345 |
|
---|
346 | CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
|
---|
347 |
|
---|
348 | /* Since the Chromium packer/unpacker can't return both 'residences'
|
---|
349 | * and the function's return value, compute the return value here.
|
---|
350 | */
|
---|
351 | for (i = 0; i < n; i++) {
|
---|
352 | if (!residences[i]) {
|
---|
353 | return_val = GL_FALSE;
|
---|
354 | break;
|
---|
355 | }
|
---|
356 | }
|
---|
357 |
|
---|
358 | return return_val;
|
---|
359 | }
|
---|
360 |
|
---|
361 | void PACKSPU_APIENTRY packspu_GetPolygonStipple( GLubyte * mask )
|
---|
362 | {
|
---|
363 | GET_THREAD(thread);
|
---|
364 | int writeback = 1;
|
---|
365 |
|
---|
366 | crPackGetPolygonStipple( mask, &writeback );
|
---|
367 | #ifdef CR_ARB_pixel_buffer_object
|
---|
368 | if (!crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
|
---|
369 | #endif
|
---|
370 | {
|
---|
371 | packspuFlush( (void *) thread );
|
---|
372 | CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
|
---|
373 | }
|
---|
374 | }
|
---|
375 |
|
---|
376 | void PACKSPU_APIENTRY packspu_GetPixelMapfv( GLenum map, GLfloat * values )
|
---|
377 | {
|
---|
378 | GET_THREAD(thread);
|
---|
379 | int writeback = 1;
|
---|
380 |
|
---|
381 | crPackGetPixelMapfv( map, values, &writeback );
|
---|
382 | #ifdef CR_ARB_pixel_buffer_object
|
---|
383 | if (!crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
|
---|
384 | #endif
|
---|
385 | {
|
---|
386 | packspuFlush( (void *) thread );
|
---|
387 | CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
|
---|
388 | }
|
---|
389 | }
|
---|
390 |
|
---|
391 | void PACKSPU_APIENTRY packspu_GetPixelMapuiv( GLenum map, GLuint * values )
|
---|
392 | {
|
---|
393 | GET_THREAD(thread);
|
---|
394 | int writeback = 1;
|
---|
395 |
|
---|
396 | crPackGetPixelMapuiv( map, values, &writeback );
|
---|
397 |
|
---|
398 | #ifdef CR_ARB_pixel_buffer_object
|
---|
399 | if (!crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
|
---|
400 | #endif
|
---|
401 | {
|
---|
402 | packspuFlush( (void *) thread );
|
---|
403 | CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
|
---|
404 | }
|
---|
405 | }
|
---|
406 |
|
---|
407 | void PACKSPU_APIENTRY packspu_GetPixelMapusv( GLenum map, GLushort * values )
|
---|
408 | {
|
---|
409 | GET_THREAD(thread);
|
---|
410 | int writeback = 1;
|
---|
411 |
|
---|
412 | crPackGetPixelMapusv( map, values, &writeback );
|
---|
413 | #ifdef CR_ARB_pixel_buffer_object
|
---|
414 | if (!crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
|
---|
415 | #endif
|
---|
416 | {
|
---|
417 | packspuFlush( (void *) thread );
|
---|
418 | CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
|
---|
419 | }
|
---|
420 | }
|
---|
421 |
|
---|
422 | static void packspuFluchOnThreadSwitch(GLboolean fEnable)
|
---|
423 | {
|
---|
424 | GET_THREAD(thread);
|
---|
425 | if (thread->currentContext->fAutoFlush == fEnable)
|
---|
426 | return;
|
---|
427 |
|
---|
428 | thread->currentContext->fAutoFlush = fEnable;
|
---|
429 | thread->currentContext->currentThread = fEnable ? thread : NULL;
|
---|
430 | }
|
---|
431 |
|
---|
432 | static void packspuCheckZerroVertAttr(GLboolean fEnable)
|
---|
433 | {
|
---|
434 | GET_THREAD(thread);
|
---|
435 |
|
---|
436 | thread->currentContext->fCheckZerroVertAttr = fEnable;
|
---|
437 | }
|
---|
438 |
|
---|
439 | void PACKSPU_APIENTRY packspu_ChromiumParameteriCR(GLenum target, GLint value)
|
---|
440 | {
|
---|
441 | switch (target)
|
---|
442 | {
|
---|
443 | case GL_FLUSH_ON_THREAD_SWITCH_CR:
|
---|
444 | /* this is a pure packspu state, don't propagate it any further */
|
---|
445 | packspuFluchOnThreadSwitch(value);
|
---|
446 | return;
|
---|
447 | case GL_CHECK_ZERO_VERT_ARRT:
|
---|
448 | packspuCheckZerroVertAttr(value);
|
---|
449 | return;
|
---|
450 | case GL_SHARE_CONTEXT_RESOURCES_CR:
|
---|
451 | crStateShareContext(&pack_spu.StateTracker, value);
|
---|
452 | break;
|
---|
453 | case GL_RCUSAGE_TEXTURE_SET_CR:
|
---|
454 | {
|
---|
455 | Assert(value);
|
---|
456 | crStateSetTextureUsed(&pack_spu.StateTracker, value, GL_TRUE);
|
---|
457 | break;
|
---|
458 | }
|
---|
459 | case GL_RCUSAGE_TEXTURE_CLEAR_CR:
|
---|
460 | {
|
---|
461 | Assert(value);
|
---|
462 | #ifdef DEBUG
|
---|
463 | {
|
---|
464 | CRContext *pCurState = crStateGetCurrent(&pack_spu.StateTracker);
|
---|
465 | CRTextureObj *tobj = (CRTextureObj*)crHashtableSearch(pCurState->shared->textureTable, value);
|
---|
466 | Assert(tobj);
|
---|
467 | }
|
---|
468 | #endif
|
---|
469 | crStateSetTextureUsed(&pack_spu.StateTracker, value, GL_FALSE);
|
---|
470 | break;
|
---|
471 | }
|
---|
472 | default:
|
---|
473 | break;
|
---|
474 | }
|
---|
475 | crPackChromiumParameteriCR(target, value);
|
---|
476 | }
|
---|
477 |
|
---|
478 | GLenum PACKSPU_APIENTRY packspu_GetError( void )
|
---|
479 | {
|
---|
480 | GET_THREAD(thread);
|
---|
481 | int writeback = 1;
|
---|
482 | GLenum return_val = (GLenum) 0;
|
---|
483 | CRContext *pCurState = crStateGetCurrent(&pack_spu.StateTracker);
|
---|
484 | NOREF(pCurState); /* it's unused, but I don't know about side effects.. */
|
---|
485 |
|
---|
486 | if (!CRPACKSPU_IS_WDDM_CRHGSMI() && !(pack_spu.thread[pack_spu.idxThreadInUse].netServer.conn->actual_network))
|
---|
487 | {
|
---|
488 | crError( "packspu_GetError doesn't work when there's no actual network involved!\nTry using the simplequery SPU in your chain!" );
|
---|
489 | }
|
---|
490 |
|
---|
491 | crPackGetError( &return_val, &writeback );
|
---|
492 | packspuFlush( (void *) thread );
|
---|
493 | CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
|
---|
494 | return return_val;
|
---|
495 | }
|
---|
496 |
|
---|
497 | GLint PACKSPU_APIENTRY packspu_VBoxPackSetInjectThread(struct VBOXUHGSMI *pHgsmi)
|
---|
498 | {
|
---|
499 | GLint con = 0;
|
---|
500 | int i;
|
---|
501 | GET_THREAD(thread);
|
---|
502 | CRASSERT(!thread);
|
---|
503 | RT_NOREF(pHgsmi);
|
---|
504 | crLockMutex(&_PackMutex);
|
---|
505 | {
|
---|
506 | CRASSERT(CRPACKSPU_IS_WDDM_CRHGSMI() || (pack_spu.numThreads>0));
|
---|
507 | CRASSERT(pack_spu.numThreads<MAX_THREADS);
|
---|
508 | for (i=0; i<MAX_THREADS; ++i)
|
---|
509 | {
|
---|
510 | if (!pack_spu.thread[i].inUse)
|
---|
511 | {
|
---|
512 | thread = &pack_spu.thread[i];
|
---|
513 | break;
|
---|
514 | }
|
---|
515 | }
|
---|
516 | CRASSERT(thread);
|
---|
517 |
|
---|
518 | thread->inUse = GL_TRUE;
|
---|
519 | if (!CRPACKSPU_IS_WDDM_CRHGSMI())
|
---|
520 | thread->id = crThreadID();
|
---|
521 | else
|
---|
522 | thread->id = THREAD_OFFSET_MAGIC + i;
|
---|
523 | thread->currentContext = NULL;
|
---|
524 | thread->bInjectThread = GL_TRUE;
|
---|
525 |
|
---|
526 | thread->netServer.name = crStrdup(pack_spu.name);
|
---|
527 | thread->netServer.buffer_size = 64 * 1024;
|
---|
528 |
|
---|
529 | packspuConnectToServer(&(thread->netServer)
|
---|
530 | #if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
|
---|
531 | , pHgsmi
|
---|
532 | #endif
|
---|
533 | );
|
---|
534 | CRASSERT(thread->netServer.conn);
|
---|
535 |
|
---|
536 | CRASSERT(thread->packer == NULL);
|
---|
537 | thread->packer = crPackNewContext();
|
---|
538 | CRASSERT(thread->packer);
|
---|
539 | crPackInitBuffer(&(thread->buffer), crNetAlloc(thread->netServer.conn),
|
---|
540 | thread->netServer.conn->buffer_size, thread->netServer.conn->mtu);
|
---|
541 | thread->buffer.canBarf = thread->netServer.conn->Barf ? GL_TRUE : GL_FALSE;
|
---|
542 |
|
---|
543 | crPackSetBuffer( thread->packer, &thread->buffer );
|
---|
544 | crPackFlushFunc( thread->packer, packspuFlush );
|
---|
545 | crPackFlushArg( thread->packer, (void *) thread );
|
---|
546 | crPackSendHugeFunc( thread->packer, packspuHuge );
|
---|
547 | crPackSetContext( thread->packer );
|
---|
548 |
|
---|
549 | crSetTSD(&_PackTSD, thread);
|
---|
550 |
|
---|
551 | pack_spu.numThreads++;
|
---|
552 | }
|
---|
553 | crUnlockMutex(&_PackMutex);
|
---|
554 |
|
---|
555 | if (CRPACKSPU_IS_WDDM_CRHGSMI())
|
---|
556 | {
|
---|
557 | CRASSERT(thread->id - THREAD_OFFSET_MAGIC < RT_ELEMENTS(pack_spu.thread)
|
---|
558 | && GET_THREAD_VAL_ID(thread->id) == thread);
|
---|
559 | con = thread->id;
|
---|
560 | }
|
---|
561 | return con;
|
---|
562 | }
|
---|
563 |
|
---|
564 | GLuint PACKSPU_APIENTRY packspu_VBoxPackGetInjectID(GLint con)
|
---|
565 | {
|
---|
566 | GLuint ret;
|
---|
567 |
|
---|
568 | crLockMutex(&_PackMutex);
|
---|
569 | {
|
---|
570 | ThreadInfo *thread = NULL;
|
---|
571 | if (CRPACKSPU_IS_WDDM_CRHGSMI())
|
---|
572 | {
|
---|
573 | if (!con)
|
---|
574 | {
|
---|
575 | crError("connection expected!");
|
---|
576 | return 0;
|
---|
577 | }
|
---|
578 | thread = GET_THREAD_VAL_ID(con);
|
---|
579 | }
|
---|
580 | else
|
---|
581 | {
|
---|
582 | CRASSERT(!con);
|
---|
583 | thread = GET_THREAD_VAL();
|
---|
584 | }
|
---|
585 | CRASSERT(thread && thread->netServer.conn && thread->netServer.conn->type==CR_VBOXHGCM);
|
---|
586 | ret = thread->netServer.conn->u32ClientID;
|
---|
587 | }
|
---|
588 | crUnlockMutex(&_PackMutex);
|
---|
589 |
|
---|
590 | return ret;
|
---|
591 | }
|
---|
592 |
|
---|
593 | void PACKSPU_APIENTRY packspu_VBoxPackSetInjectID(GLuint id)
|
---|
594 | {
|
---|
595 | crLockMutex(&_PackMutex);
|
---|
596 | {
|
---|
597 | GET_THREAD(thread);
|
---|
598 |
|
---|
599 | CRASSERT(thread && thread->netServer.conn && thread->netServer.conn->type==CR_VBOXHGCM && thread->bInjectThread);
|
---|
600 | thread->netServer.conn->u32InjectClientID = id;
|
---|
601 | }
|
---|
602 | crUnlockMutex(&_PackMutex);
|
---|
603 | }
|
---|
604 |
|
---|
605 | void PACKSPU_APIENTRY packspu_VBoxAttachThread()
|
---|
606 | {
|
---|
607 | #if 0
|
---|
608 | int i;
|
---|
609 | GET_THREAD(thread);
|
---|
610 |
|
---|
611 | for (i=0; i<MAX_THREADS; ++i)
|
---|
612 | {
|
---|
613 | if (pack_spu.thread[i].inUse && thread==&pack_spu.thread[i] && thread->id==crThreadID())
|
---|
614 | {
|
---|
615 | crError("2nd attach to same thread");
|
---|
616 | }
|
---|
617 | }
|
---|
618 | #endif
|
---|
619 |
|
---|
620 | crSetTSD(&_PackTSD, NULL);
|
---|
621 |
|
---|
622 | crStateVBoxAttachThread(&pack_spu.StateTracker);
|
---|
623 | }
|
---|
624 |
|
---|
625 | void PACKSPU_APIENTRY packspu_VBoxDetachThread()
|
---|
626 | {
|
---|
627 | if (CRPACKSPU_IS_WDDM_CRHGSMI())
|
---|
628 | {
|
---|
629 | crPackSetContext(NULL);
|
---|
630 | crSetTSD(&_PackTSD, NULL);
|
---|
631 | }
|
---|
632 | else
|
---|
633 | {
|
---|
634 | int i;
|
---|
635 | GET_THREAD(thread);
|
---|
636 | if (thread)
|
---|
637 | {
|
---|
638 | crLockMutex(&_PackMutex);
|
---|
639 |
|
---|
640 | for (i=0; i<MAX_THREADS; ++i)
|
---|
641 | {
|
---|
642 | if (pack_spu.thread[i].inUse && thread==&pack_spu.thread[i]
|
---|
643 | && thread->id==crThreadID() && thread->netServer.conn)
|
---|
644 | {
|
---|
645 | CRASSERT(pack_spu.numThreads>0);
|
---|
646 |
|
---|
647 | packspuFlush((void *) thread);
|
---|
648 |
|
---|
649 | if (pack_spu.thread[i].packer)
|
---|
650 | {
|
---|
651 | CR_LOCK_PACKER_CONTEXT(thread->packer);
|
---|
652 | crPackSetContext(NULL);
|
---|
653 | CR_UNLOCK_PACKER_CONTEXT(thread->packer);
|
---|
654 | crPackDeleteContext(pack_spu.thread[i].packer);
|
---|
655 |
|
---|
656 | if (pack_spu.thread[i].buffer.pack)
|
---|
657 | {
|
---|
658 | crNetFree(pack_spu.thread[i].netServer.conn, pack_spu.thread[i].buffer.pack);
|
---|
659 | pack_spu.thread[i].buffer.pack = NULL;
|
---|
660 | }
|
---|
661 | }
|
---|
662 | crNetFreeConnection(pack_spu.thread[i].netServer.conn);
|
---|
663 |
|
---|
664 | if (pack_spu.thread[i].netServer.name)
|
---|
665 | crFree(pack_spu.thread[i].netServer.name);
|
---|
666 |
|
---|
667 | pack_spu.numThreads--;
|
---|
668 | /*note can't shift the array here, because other threads have TLS references to array elements*/
|
---|
669 | crMemZero(&pack_spu.thread[i], sizeof(ThreadInfo));
|
---|
670 |
|
---|
671 | crSetTSD(&_PackTSD, NULL);
|
---|
672 |
|
---|
673 | if (i==pack_spu.idxThreadInUse)
|
---|
674 | {
|
---|
675 | for (i=0; i<MAX_THREADS; ++i)
|
---|
676 | {
|
---|
677 | if (pack_spu.thread[i].inUse)
|
---|
678 | {
|
---|
679 | pack_spu.idxThreadInUse=i;
|
---|
680 | break;
|
---|
681 | }
|
---|
682 | }
|
---|
683 | }
|
---|
684 |
|
---|
685 | break;
|
---|
686 | }
|
---|
687 | }
|
---|
688 |
|
---|
689 | for (i=0; i<CR_MAX_CONTEXTS; ++i)
|
---|
690 | {
|
---|
691 | ContextInfo *ctx = &pack_spu.context[i];
|
---|
692 | if (ctx->currentThread == thread)
|
---|
693 | {
|
---|
694 | CRASSERT(ctx->fAutoFlush);
|
---|
695 | ctx->currentThread = NULL;
|
---|
696 | }
|
---|
697 | }
|
---|
698 |
|
---|
699 | crUnlockMutex(&_PackMutex);
|
---|
700 | }
|
---|
701 | }
|
---|
702 |
|
---|
703 | crStateVBoxDetachThread(&pack_spu.StateTracker);
|
---|
704 | }
|
---|
705 |
|
---|
706 | #ifdef WINDOWS
|
---|
707 | #define WIN32_LEAN_AND_MEAN
|
---|
708 | #include <windows.h>
|
---|
709 | BOOL WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
|
---|
710 | {
|
---|
711 | (void) lpvReserved;
|
---|
712 |
|
---|
713 | switch (fdwReason)
|
---|
714 | {
|
---|
715 | case DLL_PROCESS_ATTACH:
|
---|
716 | {
|
---|
717 | crInitMutex(&_PackMutex);
|
---|
718 | break;
|
---|
719 | }
|
---|
720 |
|
---|
721 | case DLL_PROCESS_DETACH:
|
---|
722 | {
|
---|
723 | crFreeMutex(&_PackMutex);
|
---|
724 | crNetTearDown();
|
---|
725 | break;
|
---|
726 | }
|
---|
727 |
|
---|
728 | case DLL_THREAD_ATTACH:
|
---|
729 | case DLL_THREAD_DETACH:
|
---|
730 | default:
|
---|
731 | break;
|
---|
732 | }
|
---|
733 |
|
---|
734 | return TRUE;
|
---|
735 | }
|
---|
736 | #endif
|
---|
737 |
|
---|
738 | void PACKSPU_APIENTRY packspu_VBoxPresentComposition(GLint win, const struct VBOXVR_SCR_COMPOSITOR * pCompositor,
|
---|
739 | const struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry)
|
---|
740 | {
|
---|
741 | RT_NOREF(win, pCompositor, pChangedEntry);
|
---|
742 | }
|
---|
743 |
|
---|
744 | void PACKSPU_APIENTRY packspu_StringMarkerGREMEDY(GLsizei len, const GLvoid *string)
|
---|
745 | {
|
---|
746 | RT_NOREF(len, string);
|
---|
747 | }
|
---|
748 |
|
---|