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