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 |
|
---|
11 | void PACKSPU_APIENTRY packspu_ChromiumParametervCR(GLenum target, GLenum type, GLsizei count, const GLvoid *values)
|
---|
12 | {
|
---|
13 |
|
---|
14 | CRMessage msg;
|
---|
15 | int len;
|
---|
16 |
|
---|
17 | GET_THREAD(thread);
|
---|
18 |
|
---|
19 |
|
---|
20 | switch(target)
|
---|
21 | {
|
---|
22 | case GL_GATHER_PACK_CR:
|
---|
23 | /* flush the current pack buffer */
|
---|
24 | packspuFlush( (void *) thread );
|
---|
25 |
|
---|
26 | /* the connection is thread->server.conn */
|
---|
27 | msg.header.type = CR_MESSAGE_GATHER;
|
---|
28 | msg.gather.offset = 69;
|
---|
29 | len = sizeof(CRMessageGather);
|
---|
30 | crNetSend(thread->netServer.conn, NULL, &msg, len);
|
---|
31 | break;
|
---|
32 |
|
---|
33 | default:
|
---|
34 | if (pack_spu.swap)
|
---|
35 | crPackChromiumParametervCRSWAP(target, type, count, values);
|
---|
36 | else
|
---|
37 | crPackChromiumParametervCR(target, type, count, values);
|
---|
38 | }
|
---|
39 |
|
---|
40 |
|
---|
41 | }
|
---|
42 |
|
---|
43 | GLboolean packspuSyncOnFlushes()
|
---|
44 | {
|
---|
45 | GLint buffer;
|
---|
46 |
|
---|
47 | /*Seems to still cause issues, always sync for now*/
|
---|
48 | return 1;
|
---|
49 |
|
---|
50 | crStateGetIntegerv(GL_DRAW_BUFFER, &buffer);
|
---|
51 | /*Usually buffer==GL_BACK, so put this extra check to simplify boolean eval on runtime*/
|
---|
52 | return (buffer != GL_BACK)
|
---|
53 | && (buffer == GL_FRONT_LEFT
|
---|
54 | || buffer == GL_FRONT_RIGHT
|
---|
55 | || buffer == GL_FRONT
|
---|
56 | || buffer == GL_FRONT_AND_BACK
|
---|
57 | || buffer == GL_LEFT
|
---|
58 | || buffer == GL_RIGHT);
|
---|
59 | }
|
---|
60 |
|
---|
61 | void PACKSPU_APIENTRY packspu_DrawBuffer(GLenum mode)
|
---|
62 | {
|
---|
63 | GLboolean hadtoflush;
|
---|
64 |
|
---|
65 | hadtoflush = packspuSyncOnFlushes();
|
---|
66 |
|
---|
67 | crStateDrawBuffer(mode);
|
---|
68 | crPackDrawBuffer(mode);
|
---|
69 |
|
---|
70 | if (hadtoflush && !packspuSyncOnFlushes())
|
---|
71 | packspu_Flush();
|
---|
72 | }
|
---|
73 |
|
---|
74 | void PACKSPU_APIENTRY packspu_Finish( void )
|
---|
75 | {
|
---|
76 | GET_THREAD(thread);
|
---|
77 | GLint writeback = pack_spu.thread[0].netServer.conn->actual_network;
|
---|
78 |
|
---|
79 | if (pack_spu.swap)
|
---|
80 | {
|
---|
81 | crPackFinishSWAP();
|
---|
82 | }
|
---|
83 | else
|
---|
84 | {
|
---|
85 | crPackFinish();
|
---|
86 | }
|
---|
87 |
|
---|
88 | if (packspuSyncOnFlushes())
|
---|
89 | {
|
---|
90 | if (writeback)
|
---|
91 | {
|
---|
92 | if (pack_spu.swap)
|
---|
93 | crPackWritebackSWAP(&writeback);
|
---|
94 | else
|
---|
95 | crPackWriteback(&writeback);
|
---|
96 |
|
---|
97 | packspuFlush( (void *) thread );
|
---|
98 |
|
---|
99 | while (writeback)
|
---|
100 | crNetRecv();
|
---|
101 | }
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | void PACKSPU_APIENTRY packspu_Flush( void )
|
---|
106 | {
|
---|
107 | GET_THREAD(thread);
|
---|
108 | int writeback = 1;
|
---|
109 |
|
---|
110 | if (!thread->bInjectThread)
|
---|
111 | {
|
---|
112 | crPackFlush();
|
---|
113 | if (packspuSyncOnFlushes())
|
---|
114 | {
|
---|
115 | crPackWriteback(&writeback);
|
---|
116 | packspuFlush( (void *) thread );
|
---|
117 | while (writeback)
|
---|
118 | crNetRecv();
|
---|
119 | }
|
---|
120 | }
|
---|
121 | else
|
---|
122 | {
|
---|
123 | packspuFlush( (void *) thread );
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | GLint PACKSPU_APIENTRY packspu_WindowCreate( const char *dpyName, GLint visBits )
|
---|
128 | {
|
---|
129 | GET_THREAD(thread);
|
---|
130 | static int num_calls = 0;
|
---|
131 | int writeback = pack_spu.thread[0].netServer.conn->actual_network;
|
---|
132 | GLint return_val = (GLint) 0;
|
---|
133 |
|
---|
134 | if (!thread) {
|
---|
135 | thread = packspuNewThread( crThreadID() );
|
---|
136 | }
|
---|
137 | CRASSERT(thread);
|
---|
138 | CRASSERT(thread->packer);
|
---|
139 |
|
---|
140 | crPackSetContext(thread->packer);
|
---|
141 |
|
---|
142 | if (pack_spu.swap)
|
---|
143 | {
|
---|
144 | crPackWindowCreateSWAP( dpyName, visBits, &return_val, &writeback );
|
---|
145 | }
|
---|
146 | else
|
---|
147 | {
|
---|
148 | crPackWindowCreate( dpyName, visBits, &return_val, &writeback );
|
---|
149 | }
|
---|
150 | packspuFlush(thread);
|
---|
151 | if (!(thread->netServer.conn->actual_network))
|
---|
152 | {
|
---|
153 | return num_calls++;
|
---|
154 | }
|
---|
155 | else
|
---|
156 | {
|
---|
157 | while (writeback)
|
---|
158 | crNetRecv();
|
---|
159 | if (pack_spu.swap)
|
---|
160 | {
|
---|
161 | return_val = (GLint) SWAP32(return_val);
|
---|
162 | }
|
---|
163 | return return_val;
|
---|
164 | }
|
---|
165 | }
|
---|
166 |
|
---|
167 |
|
---|
168 |
|
---|
169 | GLboolean PACKSPU_APIENTRY
|
---|
170 | packspu_AreTexturesResident( GLsizei n, const GLuint * textures,
|
---|
171 | GLboolean * residences )
|
---|
172 | {
|
---|
173 | GET_THREAD(thread);
|
---|
174 | int writeback = 1;
|
---|
175 | GLboolean return_val = GL_TRUE;
|
---|
176 | GLsizei i;
|
---|
177 |
|
---|
178 | if (!(pack_spu.thread[0].netServer.conn->actual_network))
|
---|
179 | {
|
---|
180 | crError( "packspu_AreTexturesResident doesn't work when there's no actual network involved!\nTry using the simplequery SPU in your chain!" );
|
---|
181 | }
|
---|
182 |
|
---|
183 | if (pack_spu.swap)
|
---|
184 | {
|
---|
185 | crPackAreTexturesResidentSWAP( n, textures, residences, &return_val, &writeback );
|
---|
186 | }
|
---|
187 | else
|
---|
188 | {
|
---|
189 | crPackAreTexturesResident( n, textures, residences, &return_val, &writeback );
|
---|
190 | }
|
---|
191 | packspuFlush( (void *) thread );
|
---|
192 |
|
---|
193 | while (writeback)
|
---|
194 | crNetRecv();
|
---|
195 |
|
---|
196 | /* Since the Chromium packer/unpacker can't return both 'residences'
|
---|
197 | * and the function's return value, compute the return value here.
|
---|
198 | */
|
---|
199 | for (i = 0; i < n; i++) {
|
---|
200 | if (!residences[i]) {
|
---|
201 | return_val = GL_FALSE;
|
---|
202 | break;
|
---|
203 | }
|
---|
204 | }
|
---|
205 |
|
---|
206 | return return_val;
|
---|
207 | }
|
---|
208 |
|
---|
209 |
|
---|
210 | GLboolean PACKSPU_APIENTRY
|
---|
211 | packspu_AreProgramsResidentNV( GLsizei n, const GLuint * ids,
|
---|
212 | GLboolean * residences )
|
---|
213 | {
|
---|
214 | GET_THREAD(thread);
|
---|
215 | int writeback = 1;
|
---|
216 | GLboolean return_val = GL_TRUE;
|
---|
217 | GLsizei i;
|
---|
218 |
|
---|
219 | if (!(pack_spu.thread[0].netServer.conn->actual_network))
|
---|
220 | {
|
---|
221 | crError( "packspu_AreProgramsResidentNV doesn't work when there's no actual network involved!\nTry using the simplequery SPU in your chain!" );
|
---|
222 | }
|
---|
223 | if (pack_spu.swap)
|
---|
224 | {
|
---|
225 | crPackAreProgramsResidentNVSWAP( n, ids, residences, &return_val, &writeback );
|
---|
226 | }
|
---|
227 | else
|
---|
228 | {
|
---|
229 | crPackAreProgramsResidentNV( n, ids, residences, &return_val, &writeback );
|
---|
230 | }
|
---|
231 | packspuFlush( (void *) thread );
|
---|
232 |
|
---|
233 | while (writeback)
|
---|
234 | crNetRecv();
|
---|
235 |
|
---|
236 | /* Since the Chromium packer/unpacker can't return both 'residences'
|
---|
237 | * and the function's return value, compute the return value here.
|
---|
238 | */
|
---|
239 | for (i = 0; i < n; i++) {
|
---|
240 | if (!residences[i]) {
|
---|
241 | return_val = GL_FALSE;
|
---|
242 | break;
|
---|
243 | }
|
---|
244 | }
|
---|
245 |
|
---|
246 | return return_val;
|
---|
247 | }
|
---|
248 |
|
---|
249 | void PACKSPU_APIENTRY packspu_GetPolygonStipple( GLubyte * mask )
|
---|
250 | {
|
---|
251 | GET_THREAD(thread);
|
---|
252 | int writeback = 1;
|
---|
253 |
|
---|
254 | if (pack_spu.swap)
|
---|
255 | {
|
---|
256 | crPackGetPolygonStippleSWAP( mask, &writeback );
|
---|
257 | }
|
---|
258 | else
|
---|
259 | {
|
---|
260 | crPackGetPolygonStipple( mask, &writeback );
|
---|
261 | }
|
---|
262 |
|
---|
263 | #ifdef CR_ARB_pixel_buffer_object
|
---|
264 | if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
|
---|
265 | #endif
|
---|
266 | {
|
---|
267 | packspuFlush( (void *) thread );
|
---|
268 | while (writeback)
|
---|
269 | crNetRecv();
|
---|
270 | }
|
---|
271 | }
|
---|
272 |
|
---|
273 | void PACKSPU_APIENTRY packspu_GetPixelMapfv( GLenum map, GLfloat * values )
|
---|
274 | {
|
---|
275 | GET_THREAD(thread);
|
---|
276 | int writeback = 1;
|
---|
277 |
|
---|
278 | if (pack_spu.swap)
|
---|
279 | {
|
---|
280 | crPackGetPixelMapfvSWAP( map, values, &writeback );
|
---|
281 | }
|
---|
282 | else
|
---|
283 | {
|
---|
284 | crPackGetPixelMapfv( map, values, &writeback );
|
---|
285 | }
|
---|
286 |
|
---|
287 | #ifdef CR_ARB_pixel_buffer_object
|
---|
288 | if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
|
---|
289 | #endif
|
---|
290 | {
|
---|
291 | packspuFlush( (void *) thread );
|
---|
292 | while (writeback)
|
---|
293 | crNetRecv();
|
---|
294 | }
|
---|
295 | }
|
---|
296 |
|
---|
297 | void PACKSPU_APIENTRY packspu_GetPixelMapuiv( GLenum map, GLuint * values )
|
---|
298 | {
|
---|
299 | GET_THREAD(thread);
|
---|
300 | int writeback = 1;
|
---|
301 |
|
---|
302 | if (pack_spu.swap)
|
---|
303 | {
|
---|
304 | crPackGetPixelMapuivSWAP( map, values, &writeback );
|
---|
305 | }
|
---|
306 | else
|
---|
307 | {
|
---|
308 | crPackGetPixelMapuiv( map, values, &writeback );
|
---|
309 | }
|
---|
310 |
|
---|
311 | #ifdef CR_ARB_pixel_buffer_object
|
---|
312 | if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
|
---|
313 | #endif
|
---|
314 | {
|
---|
315 | packspuFlush( (void *) thread );
|
---|
316 | while (writeback)
|
---|
317 | crNetRecv();
|
---|
318 | }
|
---|
319 | }
|
---|
320 |
|
---|
321 | void PACKSPU_APIENTRY packspu_GetPixelMapusv( GLenum map, GLushort * values )
|
---|
322 | {
|
---|
323 | GET_THREAD(thread);
|
---|
324 | int writeback = 1;
|
---|
325 |
|
---|
326 | if (pack_spu.swap)
|
---|
327 | {
|
---|
328 | crPackGetPixelMapusvSWAP( map, values, &writeback );
|
---|
329 | }
|
---|
330 | else
|
---|
331 | {
|
---|
332 | crPackGetPixelMapusv( map, values, &writeback );
|
---|
333 | }
|
---|
334 |
|
---|
335 | #ifdef CR_ARB_pixel_buffer_object
|
---|
336 | if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
|
---|
337 | #endif
|
---|
338 | {
|
---|
339 | packspuFlush( (void *) thread );
|
---|
340 | while (writeback)
|
---|
341 | crNetRecv();
|
---|
342 | }
|
---|
343 | }
|
---|
344 |
|
---|
345 | #ifdef CHROMIUM_THREADSAFE
|
---|
346 | void PACKSPU_APIENTRY packspu_VBoxPackSetInjectThread(void)
|
---|
347 | {
|
---|
348 | crLockMutex(&_PackMutex);
|
---|
349 | {
|
---|
350 | GET_THREAD(thread);
|
---|
351 | CRASSERT(!thread);
|
---|
352 | CRASSERT((pack_spu.numThreads>0) && (pack_spu.numThreads<MAX_THREADS));
|
---|
353 |
|
---|
354 | thread = &(pack_spu.thread[pack_spu.numThreads]);
|
---|
355 | thread->id = crThreadID();
|
---|
356 | thread->currentContext = NULL;
|
---|
357 | thread->bInjectThread = GL_TRUE;
|
---|
358 |
|
---|
359 | thread->netServer.name = crStrdup(pack_spu.name);
|
---|
360 | thread->netServer.buffer_size = 64 * 1024;
|
---|
361 |
|
---|
362 | crNetNewClient(pack_spu.thread[0].netServer.conn, &(thread->netServer));
|
---|
363 | CRASSERT(thread->netServer.conn);
|
---|
364 |
|
---|
365 | CRASSERT(thread->packer == NULL);
|
---|
366 | thread->packer = crPackNewContext( pack_spu.swap );
|
---|
367 | CRASSERT(thread->packer);
|
---|
368 | crPackInitBuffer(&(thread->buffer), crNetAlloc(thread->netServer.conn),
|
---|
369 | thread->netServer.conn->buffer_size, thread->netServer.conn->mtu);
|
---|
370 | thread->buffer.canBarf = thread->netServer.conn->Barf ? GL_TRUE : GL_FALSE;
|
---|
371 |
|
---|
372 | crPackSetBuffer( thread->packer, &thread->buffer );
|
---|
373 | crPackFlushFunc( thread->packer, packspuFlush );
|
---|
374 | crPackFlushArg( thread->packer, (void *) thread );
|
---|
375 | crPackSendHugeFunc( thread->packer, packspuHuge );
|
---|
376 | crPackSetContext( thread->packer );
|
---|
377 |
|
---|
378 | crSetTSD(&_PackTSD, thread);
|
---|
379 |
|
---|
380 | pack_spu.numThreads++;
|
---|
381 | }
|
---|
382 | crUnlockMutex(&_PackMutex);
|
---|
383 | }
|
---|
384 |
|
---|
385 | GLuint PACKSPU_APIENTRY packspu_VBoxPackGetInjectID(void)
|
---|
386 | {
|
---|
387 | GLuint ret;
|
---|
388 |
|
---|
389 | crLockMutex(&_PackMutex);
|
---|
390 | {
|
---|
391 | GET_THREAD(thread);
|
---|
392 | CRASSERT(thread && thread->netServer.conn && thread->netServer.conn->type==CR_VBOXHGCM);
|
---|
393 | ret = thread->netServer.conn->u32ClientID;
|
---|
394 | }
|
---|
395 | crUnlockMutex(&_PackMutex);
|
---|
396 |
|
---|
397 | return ret;
|
---|
398 | }
|
---|
399 |
|
---|
400 | void PACKSPU_APIENTRY packspu_VBoxPackSetInjectID(GLuint id)
|
---|
401 | {
|
---|
402 | crLockMutex(&_PackMutex);
|
---|
403 | {
|
---|
404 | GET_THREAD(thread);
|
---|
405 | CRASSERT(thread && thread->netServer.conn && thread->netServer.conn->type==CR_VBOXHGCM);
|
---|
406 | thread->netServer.conn->u32InjectClientID = id;
|
---|
407 | }
|
---|
408 | crUnlockMutex(&_PackMutex);
|
---|
409 | }
|
---|
410 | #else /*ifdef CHROMIUM_THREADSAFE*/
|
---|
411 | void PACKSPU_APIENTRY packspu_VBoxPackSetInjectThread(void)
|
---|
412 | {
|
---|
413 | }
|
---|
414 |
|
---|
415 | GLuint PACKSPU_APIENTRY packspu_VBoxPackGetInjectID(void)
|
---|
416 | {
|
---|
417 | return 0;
|
---|
418 | }
|
---|
419 |
|
---|
420 | void PACKSPU_APIENTRY packspu_VBoxPackSetInjectID(GLuint id)
|
---|
421 | {
|
---|
422 | (void) id;
|
---|
423 | }
|
---|
424 | #endif /*CHROMIUM_THREADSAFE*/
|
---|