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 | /* Issue the list as-is */
|
---|
90 | cr_server.head_spu->dispatch_table.CallList( list );
|
---|
91 | }
|
---|
92 | else {
|
---|
93 | /* we're compiling glCallList into another list - just pass it through */
|
---|
94 | cr_server.head_spu->dispatch_table.CallList( list );
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Translate an array of display list IDs from various datatypes to GLuint
|
---|
101 | * IDs while adding the per-client offset.
|
---|
102 | */
|
---|
103 | static void
|
---|
104 | TranslateListIDs(GLsizei n, GLenum type, const GLvoid *lists, GLuint *newLists)
|
---|
105 | {
|
---|
106 | int offset = cr_server.curClient->number * 100000;
|
---|
107 | GLsizei i;
|
---|
108 | switch (type) {
|
---|
109 | case GL_UNSIGNED_BYTE:
|
---|
110 | {
|
---|
111 | const GLubyte *src = (const GLubyte *) lists;
|
---|
112 | for (i = 0; i < n; i++) {
|
---|
113 | newLists[i] = src[i] + offset;
|
---|
114 | }
|
---|
115 | }
|
---|
116 | break;
|
---|
117 | case GL_BYTE:
|
---|
118 | {
|
---|
119 | const GLbyte *src = (const GLbyte *) lists;
|
---|
120 | for (i = 0; i < n; i++) {
|
---|
121 | newLists[i] = src[i] + offset;
|
---|
122 | }
|
---|
123 | }
|
---|
124 | break;
|
---|
125 | case GL_UNSIGNED_SHORT:
|
---|
126 | {
|
---|
127 | const GLushort *src = (const GLushort *) lists;
|
---|
128 | for (i = 0; i < n; i++) {
|
---|
129 | newLists[i] = src[i] + offset;
|
---|
130 | }
|
---|
131 | }
|
---|
132 | break;
|
---|
133 | case GL_SHORT:
|
---|
134 | {
|
---|
135 | const GLshort *src = (const GLshort *) lists;
|
---|
136 | for (i = 0; i < n; i++) {
|
---|
137 | newLists[i] = src[i] + offset;
|
---|
138 | }
|
---|
139 | }
|
---|
140 | break;
|
---|
141 | case GL_UNSIGNED_INT:
|
---|
142 | {
|
---|
143 | const GLuint *src = (const GLuint *) lists;
|
---|
144 | for (i = 0; i < n; i++) {
|
---|
145 | newLists[i] = src[i] + offset;
|
---|
146 | }
|
---|
147 | }
|
---|
148 | break;
|
---|
149 | case GL_INT:
|
---|
150 | {
|
---|
151 | const GLint *src = (const GLint *) lists;
|
---|
152 | for (i = 0; i < n; i++) {
|
---|
153 | newLists[i] = src[i] + offset;
|
---|
154 | }
|
---|
155 | }
|
---|
156 | break;
|
---|
157 | case GL_FLOAT:
|
---|
158 | {
|
---|
159 | const GLfloat *src = (const GLfloat *) lists;
|
---|
160 | for (i = 0; i < n; i++) {
|
---|
161 | newLists[i] = (GLuint) src[i] + offset;
|
---|
162 | }
|
---|
163 | }
|
---|
164 | break;
|
---|
165 | case GL_2_BYTES:
|
---|
166 | {
|
---|
167 | const GLubyte *src = (const GLubyte *) lists;
|
---|
168 | for (i = 0; i < n; i++) {
|
---|
169 | newLists[i] = (src[i*2+0] * 256 +
|
---|
170 | src[i*2+1]) + offset;
|
---|
171 | }
|
---|
172 | }
|
---|
173 | break;
|
---|
174 | case GL_3_BYTES:
|
---|
175 | {
|
---|
176 | const GLubyte *src = (const GLubyte *) lists;
|
---|
177 | for (i = 0; i < n; i++) {
|
---|
178 | newLists[i] = (src[i*3+0] * 256 * 256 +
|
---|
179 | src[i*3+1] * 256 +
|
---|
180 | src[i*3+2]) + offset;
|
---|
181 | }
|
---|
182 | }
|
---|
183 | break;
|
---|
184 | case GL_4_BYTES:
|
---|
185 | {
|
---|
186 | const GLubyte *src = (const GLubyte *) lists;
|
---|
187 | for (i = 0; i < n; i++) {
|
---|
188 | newLists[i] = (src[i*4+0] * 256 * 256 * 256 +
|
---|
189 | src[i*4+1] * 256 * 256 +
|
---|
190 | src[i*4+2] * 256 +
|
---|
191 | src[i*4+3]) + offset;
|
---|
192 | }
|
---|
193 | }
|
---|
194 | break;
|
---|
195 | default:
|
---|
196 | crWarning("CRServer: invalid display list datatype 0x%x", type);
|
---|
197 | }
|
---|
198 | }
|
---|
199 |
|
---|
200 |
|
---|
201 | void SERVER_DISPATCH_APIENTRY
|
---|
202 | crServerDispatchCallLists( GLsizei n, GLenum type, const GLvoid *lists )
|
---|
203 | {
|
---|
204 | if (!cr_server.sharedDisplayLists) {
|
---|
205 | /* need to translate IDs */
|
---|
206 | GLuint *newLists = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
207 | if (newLists) {
|
---|
208 | TranslateListIDs(n, type, lists, newLists);
|
---|
209 | }
|
---|
210 | lists = newLists;
|
---|
211 | type = GL_UNSIGNED_INT;
|
---|
212 | }
|
---|
213 |
|
---|
214 | if (cr_server.curClient->currentCtx->lists.mode == 0) {
|
---|
215 | /* we're not compiling, so execute the list now */
|
---|
216 | /* Issue the list as-is */
|
---|
217 | cr_server.head_spu->dispatch_table.CallLists( n, type, lists );
|
---|
218 | }
|
---|
219 | else {
|
---|
220 | /* we're compiling glCallList into another list - just pass it through */
|
---|
221 | cr_server.head_spu->dispatch_table.CallLists( n, type, lists );
|
---|
222 | }
|
---|
223 |
|
---|
224 | if (!cr_server.sharedDisplayLists) {
|
---|
225 | crFree((void *) lists); /* malloc'd above */
|
---|
226 | }
|
---|
227 | }
|
---|
228 |
|
---|
229 |
|
---|
230 | GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsList( GLuint list )
|
---|
231 | {
|
---|
232 | GLboolean retval;
|
---|
233 | list = TranslateListID( list );
|
---|
234 | retval = cr_server.head_spu->dispatch_table.IsList( list );
|
---|
235 | crServerReturnValue( &retval, sizeof(retval) );
|
---|
236 | return retval;
|
---|
237 | }
|
---|
238 |
|
---|
239 |
|
---|
240 | void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteLists( GLuint list, GLsizei range )
|
---|
241 | {
|
---|
242 | list = TranslateListID( list );
|
---|
243 | crStateDeleteLists( list, range );
|
---|
244 | cr_server.head_spu->dispatch_table.DeleteLists( list, range );
|
---|
245 | }
|
---|
246 |
|
---|
247 |
|
---|
248 | void SERVER_DISPATCH_APIENTRY crServerDispatchBindTexture( GLenum target, GLuint texture )
|
---|
249 | {
|
---|
250 | texture = crServerTranslateTextureID( texture );
|
---|
251 | crStateBindTexture( target, texture );
|
---|
252 | cr_server.head_spu->dispatch_table.BindTexture( target, texture );
|
---|
253 | }
|
---|
254 |
|
---|
255 |
|
---|
256 | void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteTextures( GLsizei n, const GLuint *textures)
|
---|
257 | {
|
---|
258 | if (!cr_server.sharedTextureObjects) {
|
---|
259 | GLuint *newTextures = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
260 | GLint i;
|
---|
261 | if (!newTextures) {
|
---|
262 | crError("crServerDispatchDeleteTextures: out of memory");
|
---|
263 | return;
|
---|
264 | }
|
---|
265 | for (i = 0; i < n; i++) {
|
---|
266 | newTextures[i] = crServerTranslateTextureID( textures[i] );
|
---|
267 | }
|
---|
268 | crStateDeleteTextures( n, newTextures );
|
---|
269 | cr_server.head_spu->dispatch_table.DeleteTextures( n, newTextures );
|
---|
270 | crFree(newTextures);
|
---|
271 | }
|
---|
272 | else {
|
---|
273 | crStateDeleteTextures( n, textures );
|
---|
274 | cr_server.head_spu->dispatch_table.DeleteTextures( n, textures );
|
---|
275 | }
|
---|
276 | }
|
---|
277 |
|
---|
278 | void SERVER_DISPATCH_APIENTRY crServerDispatchPrioritizeTextures( GLsizei n, const GLuint * textures, const GLclampf * priorities )
|
---|
279 | {
|
---|
280 | if (!cr_server.sharedTextureObjects)
|
---|
281 | {
|
---|
282 | GLuint *newTextures = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
283 | GLint i;
|
---|
284 | if (!newTextures) {
|
---|
285 | crError("crServerDispatchDeleteTextures: out of memory");
|
---|
286 | return;
|
---|
287 | }
|
---|
288 | for (i = 0; i < n; i++) {
|
---|
289 | newTextures[i] = crServerTranslateTextureID( textures[i] );
|
---|
290 | }
|
---|
291 | crStatePrioritizeTextures(n, newTextures, priorities);
|
---|
292 | cr_server.head_spu->dispatch_table.PrioritizeTextures(n, newTextures, priorities);
|
---|
293 | crFree(newTextures);
|
---|
294 | }
|
---|
295 | else
|
---|
296 | {
|
---|
297 | crStatePrioritizeTextures(n, textures, priorities);
|
---|
298 | cr_server.head_spu->dispatch_table.PrioritizeTextures(n, textures, priorities);
|
---|
299 | }
|
---|
300 | }
|
---|
301 |
|
---|
302 | void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteProgramsARB(GLsizei n, const GLuint * programs)
|
---|
303 | {
|
---|
304 | GLuint *pLocalProgs = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
305 | GLint i;
|
---|
306 | if (!pLocalProgs) {
|
---|
307 | crError("crServerDispatchDeleteProgramsARB: out of memory");
|
---|
308 | return;
|
---|
309 | }
|
---|
310 | for (i = 0; i < n; i++) {
|
---|
311 | pLocalProgs[i] = crServerTranslateProgramID(programs[i]);
|
---|
312 | }
|
---|
313 | crStateDeleteProgramsARB(n, pLocalProgs);
|
---|
314 | cr_server.head_spu->dispatch_table.DeleteProgramsARB(n, pLocalProgs);
|
---|
315 | crFree(pLocalProgs);
|
---|
316 | }
|
---|
317 |
|
---|
318 | /*@todo will fail for textures loaded from snapshot */
|
---|
319 | GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsTexture( GLuint texture )
|
---|
320 | {
|
---|
321 | GLboolean retval;
|
---|
322 | texture = crServerTranslateTextureID( texture );
|
---|
323 | retval = cr_server.head_spu->dispatch_table.IsTexture( texture );
|
---|
324 | crServerReturnValue( &retval, sizeof(retval) );
|
---|
325 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
326 | }
|
---|
327 |
|
---|
328 | /*@todo will fail for progs loaded from snapshot */
|
---|
329 | GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsProgramARB( GLuint program )
|
---|
330 | {
|
---|
331 | GLboolean retval;
|
---|
332 | program = crServerTranslateTextureID(program);
|
---|
333 | retval = cr_server.head_spu->dispatch_table.IsProgramARB( program );
|
---|
334 | crServerReturnValue( &retval, sizeof(retval) );
|
---|
335 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
336 | }
|
---|
337 |
|
---|
338 | GLboolean SERVER_DISPATCH_APIENTRY
|
---|
339 | crServerDispatchAreTexturesResident(GLsizei n, const GLuint *textures,
|
---|
340 | GLboolean *residences)
|
---|
341 | {
|
---|
342 | GLboolean retval;
|
---|
343 | GLboolean *res = (GLboolean *) crAlloc(n * sizeof(GLboolean));
|
---|
344 | GLsizei i;
|
---|
345 |
|
---|
346 | (void) residences;
|
---|
347 |
|
---|
348 | if (!cr_server.sharedTextureObjects) {
|
---|
349 | GLuint *textures2 = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
350 | for (i = 0; i < n; i++)
|
---|
351 | textures2[i] = crServerTranslateTextureID(textures[i]);
|
---|
352 | retval = cr_server.head_spu->dispatch_table.AreTexturesResident(n, textures2, res);
|
---|
353 | crFree(textures2);
|
---|
354 | }
|
---|
355 | else {
|
---|
356 | retval = cr_server.head_spu->dispatch_table.AreTexturesResident(n, textures, res);
|
---|
357 | }
|
---|
358 | crServerReturnValue(res, n * sizeof(GLboolean));
|
---|
359 |
|
---|
360 | crFree(res);
|
---|
361 |
|
---|
362 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
363 | }
|
---|
364 |
|
---|
365 |
|
---|
366 | GLboolean SERVER_DISPATCH_APIENTRY
|
---|
367 | crServerDispatchAreProgramsResidentNV(GLsizei n, const GLuint *programs,
|
---|
368 | GLboolean *residences)
|
---|
369 | {
|
---|
370 | GLboolean retval;
|
---|
371 | GLboolean *res = (GLboolean *) crAlloc(n * sizeof(GLboolean));
|
---|
372 | GLsizei i;
|
---|
373 |
|
---|
374 | (void) residences;
|
---|
375 |
|
---|
376 | if (!cr_server.sharedTextureObjects) {
|
---|
377 | GLuint *programs2 = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
378 | for (i = 0; i < n; i++)
|
---|
379 | programs2[i] = crServerTranslateProgramID(programs[i]);
|
---|
380 | retval = cr_server.head_spu->dispatch_table.AreProgramsResidentNV(n, programs2, res);
|
---|
381 | crFree(programs2);
|
---|
382 | }
|
---|
383 | else {
|
---|
384 | retval = cr_server.head_spu->dispatch_table.AreProgramsResidentNV(n, programs, res);
|
---|
385 | }
|
---|
386 |
|
---|
387 | crServerReturnValue(res, n * sizeof(GLboolean));
|
---|
388 | crFree(res);
|
---|
389 |
|
---|
390 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
391 | }
|
---|