VirtualBox

source: vbox/trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_misc.c@ 31988

Last change on this file since 31988 was 30486, checked in by vboxsync, 15 years ago

crOpenGL: tracking fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.9 KB
Line 
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
11void 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
43GLboolean 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
61void 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
74void 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
105void 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 int i;
124
125 crLockMutex(&_PackMutex);
126 /*Make sure we process commands in order they should appear, so flush thread being injected first*/
127 for (i=0; i<pack_spu.numThreads; ++i)
128 {
129 if ((thread != &pack_spu.thread[i]) && pack_spu.thread[i].netServer.conn
130 && (pack_spu.thread[i].netServer.conn->u32ClientID == thread->netServer.conn->u32InjectClientID)
131 && pack_spu.thread[i].packer && pack_spu.thread[i].packer->currentBuffer)
132 {
133 packspuFlush((void *) &pack_spu.thread[i]);
134 break;
135 }
136 }
137 crUnlockMutex(&_PackMutex);
138
139 packspuFlush((void *) thread);
140 }
141}
142
143GLint PACKSPU_APIENTRY packspu_WindowCreate( const char *dpyName, GLint visBits )
144{
145 GET_THREAD(thread);
146 static int num_calls = 0;
147 int writeback = pack_spu.thread[0].netServer.conn->actual_network;
148 GLint return_val = (GLint) 0;
149
150 if (!thread) {
151 thread = packspuNewThread( crThreadID() );
152 }
153 CRASSERT(thread);
154 CRASSERT(thread->packer);
155
156 crPackSetContext(thread->packer);
157
158 if (pack_spu.swap)
159 {
160 crPackWindowCreateSWAP( dpyName, visBits, &return_val, &writeback );
161 }
162 else
163 {
164 crPackWindowCreate( dpyName, visBits, &return_val, &writeback );
165 }
166 packspuFlush(thread);
167 if (!(thread->netServer.conn->actual_network))
168 {
169 return num_calls++;
170 }
171 else
172 {
173 while (writeback)
174 crNetRecv();
175 if (pack_spu.swap)
176 {
177 return_val = (GLint) SWAP32(return_val);
178 }
179 return return_val;
180 }
181}
182
183
184
185GLboolean PACKSPU_APIENTRY
186packspu_AreTexturesResident( GLsizei n, const GLuint * textures,
187 GLboolean * residences )
188{
189 GET_THREAD(thread);
190 int writeback = 1;
191 GLboolean return_val = GL_TRUE;
192 GLsizei i;
193
194 if (!(pack_spu.thread[0].netServer.conn->actual_network))
195 {
196 crError( "packspu_AreTexturesResident doesn't work when there's no actual network involved!\nTry using the simplequery SPU in your chain!" );
197 }
198
199 if (pack_spu.swap)
200 {
201 crPackAreTexturesResidentSWAP( n, textures, residences, &return_val, &writeback );
202 }
203 else
204 {
205 crPackAreTexturesResident( n, textures, residences, &return_val, &writeback );
206 }
207 packspuFlush( (void *) thread );
208
209 while (writeback)
210 crNetRecv();
211
212 /* Since the Chromium packer/unpacker can't return both 'residences'
213 * and the function's return value, compute the return value here.
214 */
215 for (i = 0; i < n; i++) {
216 if (!residences[i]) {
217 return_val = GL_FALSE;
218 break;
219 }
220 }
221
222 return return_val;
223}
224
225
226GLboolean PACKSPU_APIENTRY
227packspu_AreProgramsResidentNV( GLsizei n, const GLuint * ids,
228 GLboolean * residences )
229{
230 GET_THREAD(thread);
231 int writeback = 1;
232 GLboolean return_val = GL_TRUE;
233 GLsizei i;
234
235 if (!(pack_spu.thread[0].netServer.conn->actual_network))
236 {
237 crError( "packspu_AreProgramsResidentNV doesn't work when there's no actual network involved!\nTry using the simplequery SPU in your chain!" );
238 }
239 if (pack_spu.swap)
240 {
241 crPackAreProgramsResidentNVSWAP( n, ids, residences, &return_val, &writeback );
242 }
243 else
244 {
245 crPackAreProgramsResidentNV( n, ids, residences, &return_val, &writeback );
246 }
247 packspuFlush( (void *) thread );
248
249 while (writeback)
250 crNetRecv();
251
252 /* Since the Chromium packer/unpacker can't return both 'residences'
253 * and the function's return value, compute the return value here.
254 */
255 for (i = 0; i < n; i++) {
256 if (!residences[i]) {
257 return_val = GL_FALSE;
258 break;
259 }
260 }
261
262 return return_val;
263}
264
265void PACKSPU_APIENTRY packspu_GetPolygonStipple( GLubyte * mask )
266{
267 GET_THREAD(thread);
268 int writeback = 1;
269
270 if (pack_spu.swap)
271 {
272 crPackGetPolygonStippleSWAP( mask, &writeback );
273 }
274 else
275 {
276 crPackGetPolygonStipple( mask, &writeback );
277 }
278
279#ifdef CR_ARB_pixel_buffer_object
280 if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
281#endif
282 {
283 packspuFlush( (void *) thread );
284 while (writeback)
285 crNetRecv();
286 }
287}
288
289void PACKSPU_APIENTRY packspu_GetPixelMapfv( GLenum map, GLfloat * values )
290{
291 GET_THREAD(thread);
292 int writeback = 1;
293
294 if (pack_spu.swap)
295 {
296 crPackGetPixelMapfvSWAP( map, values, &writeback );
297 }
298 else
299 {
300 crPackGetPixelMapfv( map, values, &writeback );
301 }
302
303#ifdef CR_ARB_pixel_buffer_object
304 if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
305#endif
306 {
307 packspuFlush( (void *) thread );
308 while (writeback)
309 crNetRecv();
310 }
311}
312
313void PACKSPU_APIENTRY packspu_GetPixelMapuiv( GLenum map, GLuint * values )
314{
315 GET_THREAD(thread);
316 int writeback = 1;
317
318 if (pack_spu.swap)
319 {
320 crPackGetPixelMapuivSWAP( map, values, &writeback );
321 }
322 else
323 {
324 crPackGetPixelMapuiv( map, values, &writeback );
325 }
326
327#ifdef CR_ARB_pixel_buffer_object
328 if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
329#endif
330 {
331 packspuFlush( (void *) thread );
332 while (writeback)
333 crNetRecv();
334 }
335}
336
337void PACKSPU_APIENTRY packspu_GetPixelMapusv( GLenum map, GLushort * values )
338{
339 GET_THREAD(thread);
340 int writeback = 1;
341
342 if (pack_spu.swap)
343 {
344 crPackGetPixelMapusvSWAP( map, values, &writeback );
345 }
346 else
347 {
348 crPackGetPixelMapusv( map, values, &writeback );
349 }
350
351#ifdef CR_ARB_pixel_buffer_object
352 if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
353#endif
354 {
355 packspuFlush( (void *) thread );
356 while (writeback)
357 crNetRecv();
358 }
359}
360
361#ifdef CHROMIUM_THREADSAFE
362void PACKSPU_APIENTRY packspu_VBoxPackSetInjectThread(void)
363{
364 crLockMutex(&_PackMutex);
365 {
366 GET_THREAD(thread);
367 CRASSERT(!thread);
368 CRASSERT((pack_spu.numThreads>0) && (pack_spu.numThreads<MAX_THREADS));
369
370 thread = &(pack_spu.thread[pack_spu.numThreads]);
371 thread->id = crThreadID();
372 thread->currentContext = NULL;
373 thread->bInjectThread = GL_TRUE;
374
375 thread->netServer.name = crStrdup(pack_spu.name);
376 thread->netServer.buffer_size = 64 * 1024;
377
378 crNetNewClient(pack_spu.thread[0].netServer.conn, &(thread->netServer));
379 CRASSERT(thread->netServer.conn);
380
381 CRASSERT(thread->packer == NULL);
382 thread->packer = crPackNewContext( pack_spu.swap );
383 CRASSERT(thread->packer);
384 crPackInitBuffer(&(thread->buffer), crNetAlloc(thread->netServer.conn),
385 thread->netServer.conn->buffer_size, thread->netServer.conn->mtu);
386 thread->buffer.canBarf = thread->netServer.conn->Barf ? GL_TRUE : GL_FALSE;
387
388 crPackSetBuffer( thread->packer, &thread->buffer );
389 crPackFlushFunc( thread->packer, packspuFlush );
390 crPackFlushArg( thread->packer, (void *) thread );
391 crPackSendHugeFunc( thread->packer, packspuHuge );
392 crPackSetContext( thread->packer );
393
394 crSetTSD(&_PackTSD, thread);
395
396 pack_spu.numThreads++;
397 }
398 crUnlockMutex(&_PackMutex);
399}
400
401GLuint PACKSPU_APIENTRY packspu_VBoxPackGetInjectID(void)
402{
403 GLuint ret;
404
405 crLockMutex(&_PackMutex);
406 {
407 GET_THREAD(thread);
408 CRASSERT(thread && thread->netServer.conn && thread->netServer.conn->type==CR_VBOXHGCM);
409 ret = thread->netServer.conn->u32ClientID;
410 }
411 crUnlockMutex(&_PackMutex);
412
413 return ret;
414}
415
416void PACKSPU_APIENTRY packspu_VBoxPackSetInjectID(GLuint id)
417{
418 crLockMutex(&_PackMutex);
419 {
420 GET_THREAD(thread);
421 CRASSERT(thread && thread->netServer.conn && thread->netServer.conn->type==CR_VBOXHGCM);
422 thread->netServer.conn->u32InjectClientID = id;
423 }
424 crUnlockMutex(&_PackMutex);
425}
426#else /*ifdef CHROMIUM_THREADSAFE*/
427void PACKSPU_APIENTRY packspu_VBoxPackSetInjectThread(void)
428{
429}
430
431GLuint PACKSPU_APIENTRY packspu_VBoxPackGetInjectID(void)
432{
433 return 0;
434}
435
436void PACKSPU_APIENTRY packspu_VBoxPackSetInjectID(GLuint id)
437{
438 (void) id;
439}
440#endif /*CHROMIUM_THREADSAFE*/
Note: See TracBrowser for help on using the repository browser.

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