1 | /* Copyright (c) 2001-2003, Stanford University
|
---|
2 | All rights reserved.
|
---|
3 |
|
---|
4 | See the file LICENSE.txt for information on redistributing this software. */
|
---|
5 |
|
---|
6 | #include "server_dispatch.h"
|
---|
7 | #include "server.h"
|
---|
8 | #include "cr_mem.h"
|
---|
9 |
|
---|
10 |
|
---|
11 | /*
|
---|
12 | * Notes on ID translation:
|
---|
13 | *
|
---|
14 | * If a server has multiple clients (in the case of parallel applications)
|
---|
15 | * and N of the clients all create a display list with ID K, does K name
|
---|
16 | * one display list or N different display lists?
|
---|
17 | *
|
---|
18 | * By default, there is one display list named K. If the clients put
|
---|
19 | * identical commands into list K, then this is fine. But if the clients
|
---|
20 | * each put something different into list K when they created it, then this
|
---|
21 | * is a serious problem.
|
---|
22 | *
|
---|
23 | * By zeroing the 'shared_display_lists' configuration option, we can tell
|
---|
24 | * the server to make list K be unique for all N clients. We do this by
|
---|
25 | * translating K into a new, unique ID dependant on which client we're
|
---|
26 | * talking to (curClient->number).
|
---|
27 | *
|
---|
28 | * Same story for texture objects, vertex programs, etc.
|
---|
29 | *
|
---|
30 | * The application can also dynamically switch between shared and private
|
---|
31 | * display lists with:
|
---|
32 | * glChromiumParameteri(GL_SHARED_DISPLAY_LISTS_CR, GL_TRUE)
|
---|
33 | * and
|
---|
34 | * glChromiumParameteri(GL_SHARED_DISPLAY_LISTS_CR, GL_FALSE)
|
---|
35 | *
|
---|
36 | */
|
---|
37 |
|
---|
38 |
|
---|
39 |
|
---|
40 | static GLuint TranslateListID( GLuint id )
|
---|
41 | {
|
---|
42 | if (!cr_server.sharedDisplayLists) {
|
---|
43 | int client = cr_server.curClient->number;
|
---|
44 | return id + client * 100000;
|
---|
45 | }
|
---|
46 | return id;
|
---|
47 | }
|
---|
48 |
|
---|
49 |
|
---|
50 | GLuint crServerTranslateTextureID( GLuint id )
|
---|
51 | {
|
---|
52 | if (!cr_server.sharedTextureObjects && id) {
|
---|
53 | int client = cr_server.curClient->number;
|
---|
54 | return id + client * 100000;
|
---|
55 | }
|
---|
56 | return id;
|
---|
57 | }
|
---|
58 |
|
---|
59 | /* XXXX Note: shared/separate Program ID numbers aren't totally implemented! */
|
---|
60 | GLuint crServerTranslateProgramID( GLuint id )
|
---|
61 | {
|
---|
62 | if (!cr_server.sharedPrograms && id) {
|
---|
63 | int client = cr_server.curClient->number;
|
---|
64 | return id + client * 100000;
|
---|
65 | }
|
---|
66 | return id;
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | void SERVER_DISPATCH_APIENTRY
|
---|
71 | crServerDispatchNewList( GLuint list, GLenum mode )
|
---|
72 | {
|
---|
73 | if (mode == GL_COMPILE_AND_EXECUTE)
|
---|
74 | crWarning("using glNewList(GL_COMPILE_AND_EXECUTE) can confuse the crserver");
|
---|
75 |
|
---|
76 | list = TranslateListID( list );
|
---|
77 | crStateNewList( list, mode );
|
---|
78 | cr_server.head_spu->dispatch_table.NewList( list, mode );
|
---|
79 | }
|
---|
80 |
|
---|
81 |
|
---|
82 | void SERVER_DISPATCH_APIENTRY
|
---|
83 | crServerDispatchCallList( GLuint list )
|
---|
84 | {
|
---|
85 | list = TranslateListID( list );
|
---|
86 |
|
---|
87 | if (cr_server.curClient->currentCtx->lists.mode == 0) {
|
---|
88 | /* we're not compiling, so execute the list now */
|
---|
89 | CRMuralInfo *mural = cr_server.curClient->currentMural;
|
---|
90 | int i;
|
---|
91 |
|
---|
92 | if (!mural->viewportValidated) {
|
---|
93 | crServerComputeViewportBounds(&(cr_server.curClient->currentCtx->viewport), mural);
|
---|
94 | }
|
---|
95 |
|
---|
96 | if (mural->numExtents == 0) {
|
---|
97 | /* Issue the list as-is */
|
---|
98 | cr_server.head_spu->dispatch_table.CallList( list );
|
---|
99 | }
|
---|
100 | else {
|
---|
101 | /* Loop over the extents (tiles) calling glCallList() */
|
---|
102 | for ( i = 0; i < mural->numExtents; i++ ) {
|
---|
103 | if (cr_server.run_queue->client->currentCtx)
|
---|
104 | crServerSetOutputBounds( mural, i );
|
---|
105 | cr_server.head_spu->dispatch_table.CallList( list );
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|
109 | else {
|
---|
110 | /* we're compiling glCallList into another list - just pass it through */
|
---|
111 | cr_server.head_spu->dispatch_table.CallList( list );
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Translate an array of display list IDs from various datatypes to GLuint
|
---|
118 | * IDs while adding the per-client offset.
|
---|
119 | */
|
---|
120 | static void
|
---|
121 | TranslateListIDs(GLsizei n, GLenum type, const GLvoid *lists, GLuint *newLists)
|
---|
122 | {
|
---|
123 | int offset = cr_server.curClient->number * 100000;
|
---|
124 | GLsizei i;
|
---|
125 | switch (type) {
|
---|
126 | case GL_UNSIGNED_BYTE:
|
---|
127 | {
|
---|
128 | const GLubyte *src = (const GLubyte *) lists;
|
---|
129 | for (i = 0; i < n; i++) {
|
---|
130 | newLists[i] = src[i] + offset;
|
---|
131 | }
|
---|
132 | }
|
---|
133 | break;
|
---|
134 | case GL_BYTE:
|
---|
135 | {
|
---|
136 | const GLbyte *src = (const GLbyte *) lists;
|
---|
137 | for (i = 0; i < n; i++) {
|
---|
138 | newLists[i] = src[i] + offset;
|
---|
139 | }
|
---|
140 | }
|
---|
141 | break;
|
---|
142 | case GL_UNSIGNED_SHORT:
|
---|
143 | {
|
---|
144 | const GLushort *src = (const GLushort *) lists;
|
---|
145 | for (i = 0; i < n; i++) {
|
---|
146 | newLists[i] = src[i] + offset;
|
---|
147 | }
|
---|
148 | }
|
---|
149 | break;
|
---|
150 | case GL_SHORT:
|
---|
151 | {
|
---|
152 | const GLshort *src = (const GLshort *) lists;
|
---|
153 | for (i = 0; i < n; i++) {
|
---|
154 | newLists[i] = src[i] + offset;
|
---|
155 | }
|
---|
156 | }
|
---|
157 | break;
|
---|
158 | case GL_UNSIGNED_INT:
|
---|
159 | {
|
---|
160 | const GLuint *src = (const GLuint *) lists;
|
---|
161 | for (i = 0; i < n; i++) {
|
---|
162 | newLists[i] = src[i] + offset;
|
---|
163 | }
|
---|
164 | }
|
---|
165 | break;
|
---|
166 | case GL_INT:
|
---|
167 | {
|
---|
168 | const GLint *src = (const GLint *) lists;
|
---|
169 | for (i = 0; i < n; i++) {
|
---|
170 | newLists[i] = src[i] + offset;
|
---|
171 | }
|
---|
172 | }
|
---|
173 | break;
|
---|
174 | case GL_FLOAT:
|
---|
175 | {
|
---|
176 | const GLfloat *src = (const GLfloat *) lists;
|
---|
177 | for (i = 0; i < n; i++) {
|
---|
178 | newLists[i] = (GLuint) src[i] + offset;
|
---|
179 | }
|
---|
180 | }
|
---|
181 | break;
|
---|
182 | case GL_2_BYTES:
|
---|
183 | {
|
---|
184 | const GLubyte *src = (const GLubyte *) lists;
|
---|
185 | for (i = 0; i < n; i++) {
|
---|
186 | newLists[i] = (src[i*2+0] * 256 +
|
---|
187 | src[i*2+1]) + offset;
|
---|
188 | }
|
---|
189 | }
|
---|
190 | break;
|
---|
191 | case GL_3_BYTES:
|
---|
192 | {
|
---|
193 | const GLubyte *src = (const GLubyte *) lists;
|
---|
194 | for (i = 0; i < n; i++) {
|
---|
195 | newLists[i] = (src[i*3+0] * 256 * 256 +
|
---|
196 | src[i*3+1] * 256 +
|
---|
197 | src[i*3+2]) + offset;
|
---|
198 | }
|
---|
199 | }
|
---|
200 | break;
|
---|
201 | case GL_4_BYTES:
|
---|
202 | {
|
---|
203 | const GLubyte *src = (const GLubyte *) lists;
|
---|
204 | for (i = 0; i < n; i++) {
|
---|
205 | newLists[i] = (src[i*4+0] * 256 * 256 * 256 +
|
---|
206 | src[i*4+1] * 256 * 256 +
|
---|
207 | src[i*4+2] * 256 +
|
---|
208 | src[i*4+3]) + offset;
|
---|
209 | }
|
---|
210 | }
|
---|
211 | break;
|
---|
212 | default:
|
---|
213 | crWarning("CRServer: invalid display list datatype 0x%x", type);
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 |
|
---|
218 | void SERVER_DISPATCH_APIENTRY
|
---|
219 | crServerDispatchCallLists( GLsizei n, GLenum type, const GLvoid *lists )
|
---|
220 | {
|
---|
221 | if (!cr_server.sharedDisplayLists) {
|
---|
222 | /* need to translate IDs */
|
---|
223 | GLuint *newLists = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
224 | if (newLists) {
|
---|
225 | TranslateListIDs(n, type, lists, newLists);
|
---|
226 | }
|
---|
227 | lists = newLists;
|
---|
228 | type = GL_UNSIGNED_INT;
|
---|
229 | }
|
---|
230 |
|
---|
231 | if (cr_server.curClient->currentCtx->lists.mode == 0) {
|
---|
232 | /* we're not compiling, so execute the list now */
|
---|
233 | CRMuralInfo *mural = cr_server.curClient->currentMural;
|
---|
234 | int i;
|
---|
235 |
|
---|
236 | if (!mural->viewportValidated) {
|
---|
237 | crServerComputeViewportBounds(&(cr_server.curClient->currentCtx->viewport), mural);
|
---|
238 | }
|
---|
239 |
|
---|
240 | if (mural->numExtents == 0) {
|
---|
241 | /* Issue the list as-is */
|
---|
242 | cr_server.head_spu->dispatch_table.CallLists( n, type, lists );
|
---|
243 | }
|
---|
244 | else {
|
---|
245 | /* Loop over the extents (tiles) calling glCallList() */
|
---|
246 | for ( i = 0; i < mural->numExtents; i++ ) {
|
---|
247 | if (cr_server.run_queue->client->currentCtx)
|
---|
248 | crServerSetOutputBounds( mural, i );
|
---|
249 | cr_server.head_spu->dispatch_table.CallLists( n, type, lists );
|
---|
250 | }
|
---|
251 | }
|
---|
252 | }
|
---|
253 | else {
|
---|
254 | /* we're compiling glCallList into another list - just pass it through */
|
---|
255 | cr_server.head_spu->dispatch_table.CallLists( n, type, lists );
|
---|
256 | }
|
---|
257 |
|
---|
258 | if (!cr_server.sharedDisplayLists) {
|
---|
259 | crFree((void *) lists); /* malloc'd above */
|
---|
260 | }
|
---|
261 | }
|
---|
262 |
|
---|
263 |
|
---|
264 | GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsList( GLuint list )
|
---|
265 | {
|
---|
266 | GLboolean retval;
|
---|
267 | list = TranslateListID( list );
|
---|
268 | retval = cr_server.head_spu->dispatch_table.IsList( list );
|
---|
269 | crServerReturnValue( &retval, sizeof(retval) );
|
---|
270 | return retval;
|
---|
271 | }
|
---|
272 |
|
---|
273 |
|
---|
274 | void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteLists( GLuint list, GLsizei range )
|
---|
275 | {
|
---|
276 | list = TranslateListID( list );
|
---|
277 | crStateDeleteLists( list, range );
|
---|
278 | cr_server.head_spu->dispatch_table.DeleteLists( list, range );
|
---|
279 | }
|
---|
280 |
|
---|
281 |
|
---|
282 | void SERVER_DISPATCH_APIENTRY crServerDispatchBindTexture( GLenum target, GLuint texture )
|
---|
283 | {
|
---|
284 | texture = crServerTranslateTextureID( texture );
|
---|
285 | crStateBindTexture( target, texture );
|
---|
286 | cr_server.head_spu->dispatch_table.BindTexture( target, texture );
|
---|
287 | }
|
---|
288 |
|
---|
289 |
|
---|
290 | void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteTextures( GLsizei n, const GLuint *textures)
|
---|
291 | {
|
---|
292 | if (!cr_server.sharedTextureObjects) {
|
---|
293 | GLuint *newTextures = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
294 | GLint i;
|
---|
295 | if (!newTextures) {
|
---|
296 | crError("crServerDispatchDeleteTextures: out of memory");
|
---|
297 | return;
|
---|
298 | }
|
---|
299 | for (i = 0; i < n; i++) {
|
---|
300 | newTextures[i] = crServerTranslateTextureID( textures[i] );
|
---|
301 | }
|
---|
302 | crStateDeleteTextures( n, newTextures );
|
---|
303 | cr_server.head_spu->dispatch_table.DeleteTextures( n, newTextures );
|
---|
304 | crFree(newTextures);
|
---|
305 | }
|
---|
306 | else {
|
---|
307 | crStateDeleteTextures( n, textures );
|
---|
308 | cr_server.head_spu->dispatch_table.DeleteTextures( n, textures );
|
---|
309 | }
|
---|
310 | }
|
---|
311 |
|
---|
312 | void SERVER_DISPATCH_APIENTRY crServerDispatchPrioritizeTextures( GLsizei n, const GLuint * textures, const GLclampf * priorities )
|
---|
313 | {
|
---|
314 | if (!cr_server.sharedTextureObjects)
|
---|
315 | {
|
---|
316 | GLuint *newTextures = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
317 | GLint i;
|
---|
318 | if (!newTextures) {
|
---|
319 | crError("crServerDispatchDeleteTextures: out of memory");
|
---|
320 | return;
|
---|
321 | }
|
---|
322 | for (i = 0; i < n; i++) {
|
---|
323 | newTextures[i] = crServerTranslateTextureID( textures[i] );
|
---|
324 | }
|
---|
325 | crStatePrioritizeTextures(n, newTextures, priorities);
|
---|
326 | cr_server.head_spu->dispatch_table.PrioritizeTextures(n, newTextures, priorities);
|
---|
327 | crFree(newTextures);
|
---|
328 | }
|
---|
329 | else
|
---|
330 | {
|
---|
331 | crStatePrioritizeTextures(n, textures, priorities);
|
---|
332 | cr_server.head_spu->dispatch_table.PrioritizeTextures(n, textures, priorities);
|
---|
333 | }
|
---|
334 | }
|
---|
335 |
|
---|
336 | void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteProgramsARB(GLsizei n, const GLuint * programs)
|
---|
337 | {
|
---|
338 | GLuint *pLocalProgs = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
339 | GLint i;
|
---|
340 | if (!pLocalProgs) {
|
---|
341 | crError("crServerDispatchDeleteProgramsARB: out of memory");
|
---|
342 | return;
|
---|
343 | }
|
---|
344 | for (i = 0; i < n; i++) {
|
---|
345 | pLocalProgs[i] = crServerTranslateProgramID(programs[i]);
|
---|
346 | }
|
---|
347 | crStateDeleteProgramsARB(n, pLocalProgs);
|
---|
348 | cr_server.head_spu->dispatch_table.DeleteProgramsARB(n, pLocalProgs);
|
---|
349 | crFree(pLocalProgs);
|
---|
350 | }
|
---|
351 |
|
---|
352 | /*@todo will fail for textures loaded from snapshot */
|
---|
353 | GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsTexture( GLuint texture )
|
---|
354 | {
|
---|
355 | GLboolean retval;
|
---|
356 | texture = crServerTranslateTextureID( texture );
|
---|
357 | retval = cr_server.head_spu->dispatch_table.IsTexture( texture );
|
---|
358 | crServerReturnValue( &retval, sizeof(retval) );
|
---|
359 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
360 | }
|
---|
361 |
|
---|
362 | /*@todo will fail for progs loaded from snapshot */
|
---|
363 | GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsProgramARB( GLuint program )
|
---|
364 | {
|
---|
365 | GLboolean retval;
|
---|
366 | program = crServerTranslateTextureID(program);
|
---|
367 | retval = cr_server.head_spu->dispatch_table.IsProgramARB( program );
|
---|
368 | crServerReturnValue( &retval, sizeof(retval) );
|
---|
369 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
370 | }
|
---|
371 |
|
---|
372 | GLboolean SERVER_DISPATCH_APIENTRY
|
---|
373 | crServerDispatchAreTexturesResident(GLsizei n, const GLuint *textures,
|
---|
374 | GLboolean *residences)
|
---|
375 | {
|
---|
376 | GLboolean retval;
|
---|
377 | GLboolean *res = (GLboolean *) crAlloc(n * sizeof(GLboolean));
|
---|
378 | GLsizei i;
|
---|
379 |
|
---|
380 | (void) residences;
|
---|
381 |
|
---|
382 | if (!cr_server.sharedTextureObjects) {
|
---|
383 | GLuint *textures2 = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
384 | for (i = 0; i < n; i++)
|
---|
385 | textures2[i] = crServerTranslateTextureID(textures[i]);
|
---|
386 | retval = cr_server.head_spu->dispatch_table.AreTexturesResident(n, textures2, res);
|
---|
387 | crFree(textures2);
|
---|
388 | }
|
---|
389 | else {
|
---|
390 | retval = cr_server.head_spu->dispatch_table.AreTexturesResident(n, textures, res);
|
---|
391 | }
|
---|
392 | crServerReturnValue(res, n * sizeof(GLboolean));
|
---|
393 |
|
---|
394 | crFree(res);
|
---|
395 |
|
---|
396 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
397 | }
|
---|
398 |
|
---|
399 |
|
---|
400 | GLboolean SERVER_DISPATCH_APIENTRY
|
---|
401 | crServerDispatchAreProgramsResidentNV(GLsizei n, const GLuint *programs,
|
---|
402 | GLboolean *residences)
|
---|
403 | {
|
---|
404 | GLboolean retval;
|
---|
405 | GLboolean *res = (GLboolean *) crAlloc(n * sizeof(GLboolean));
|
---|
406 | GLsizei i;
|
---|
407 |
|
---|
408 | (void) residences;
|
---|
409 |
|
---|
410 | if (!cr_server.sharedTextureObjects) {
|
---|
411 | GLuint *programs2 = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
412 | for (i = 0; i < n; i++)
|
---|
413 | programs2[i] = crServerTranslateProgramID(programs[i]);
|
---|
414 | retval = cr_server.head_spu->dispatch_table.AreProgramsResidentNV(n, programs2, res);
|
---|
415 | crFree(programs2);
|
---|
416 | }
|
---|
417 | else {
|
---|
418 | retval = cr_server.head_spu->dispatch_table.AreProgramsResidentNV(n, programs, res);
|
---|
419 | }
|
---|
420 |
|
---|
421 | crServerReturnValue(res, n * sizeof(GLboolean));
|
---|
422 | crFree(res);
|
---|
423 |
|
---|
424 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
425 | }
|
---|