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 dependent 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 | /* XXXX Note: shared/separate Program ID numbers aren't totally implemented! */
|
---|
50 | GLuint crServerTranslateProgramID( GLuint id )
|
---|
51 | {
|
---|
52 | if (!cr_server.sharedPrograms && id) {
|
---|
53 | int client = cr_server.curClient->number;
|
---|
54 | return id + client * 100000;
|
---|
55 | }
|
---|
56 | return id;
|
---|
57 | }
|
---|
58 |
|
---|
59 |
|
---|
60 | void SERVER_DISPATCH_APIENTRY
|
---|
61 | crServerDispatchNewList( GLuint list, GLenum mode )
|
---|
62 | {
|
---|
63 | if (mode == GL_COMPILE_AND_EXECUTE)
|
---|
64 | crWarning("using glNewList(GL_COMPILE_AND_EXECUTE) can confuse the crserver");
|
---|
65 |
|
---|
66 | list = TranslateListID( list );
|
---|
67 | crStateNewList( list, mode );
|
---|
68 | cr_server.head_spu->dispatch_table.NewList( list, mode );
|
---|
69 | }
|
---|
70 |
|
---|
71 | static void crServerQueryHWState()
|
---|
72 | {
|
---|
73 | if (!cr_server.bUseMultipleContexts)
|
---|
74 | {
|
---|
75 | GLuint fbFbo, bbFbo;
|
---|
76 | CRClient *client = cr_server.curClient;
|
---|
77 | CRMuralInfo *mural = client ? client->currentMural : NULL;
|
---|
78 | if (mural && mural->fRedirected)
|
---|
79 | {
|
---|
80 | fbFbo = mural->aidFBOs[CR_SERVER_FBO_FB_IDX(mural)];
|
---|
81 | bbFbo = mural->aidFBOs[CR_SERVER_FBO_BB_IDX(mural)];
|
---|
82 | }
|
---|
83 | else
|
---|
84 | {
|
---|
85 | fbFbo = bbFbo = 0;
|
---|
86 | }
|
---|
87 | crStateQueryHWState(fbFbo, bbFbo);
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | void SERVER_DISPATCH_APIENTRY crServerDispatchEndList(void)
|
---|
92 | {
|
---|
93 | CRContext *g = crStateGetCurrent();
|
---|
94 | CRListsState *l = &(g->lists);
|
---|
95 |
|
---|
96 | cr_server.head_spu->dispatch_table.EndList();
|
---|
97 | crStateEndList();
|
---|
98 |
|
---|
99 | #ifndef IN_GUEST
|
---|
100 | if (l->mode==GL_COMPILE)
|
---|
101 | {
|
---|
102 | crServerQueryHWState();
|
---|
103 | }
|
---|
104 | #endif
|
---|
105 | }
|
---|
106 |
|
---|
107 | void SERVER_DISPATCH_APIENTRY
|
---|
108 | crServerDispatchCallList( GLuint list )
|
---|
109 | {
|
---|
110 | list = TranslateListID( list );
|
---|
111 |
|
---|
112 | if (cr_server.curClient->currentCtxInfo->pContext->lists.mode == 0) {
|
---|
113 | /* we're not compiling, so execute the list now */
|
---|
114 | /* Issue the list as-is */
|
---|
115 | cr_server.head_spu->dispatch_table.CallList( list );
|
---|
116 | crServerQueryHWState();
|
---|
117 | }
|
---|
118 | else {
|
---|
119 | /* we're compiling glCallList into another list - just pass it through */
|
---|
120 | cr_server.head_spu->dispatch_table.CallList( list );
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Translate an array of display list IDs from various datatypes to GLuint
|
---|
127 | * IDs while adding the per-client offset.
|
---|
128 | */
|
---|
129 | static void
|
---|
130 | TranslateListIDs(GLsizei n, GLenum type, const GLvoid *lists, GLuint *newLists)
|
---|
131 | {
|
---|
132 | int offset = cr_server.curClient->number * 100000;
|
---|
133 | GLsizei i;
|
---|
134 | switch (type) {
|
---|
135 | case GL_UNSIGNED_BYTE:
|
---|
136 | {
|
---|
137 | const GLubyte *src = (const GLubyte *) lists;
|
---|
138 | for (i = 0; i < n; i++) {
|
---|
139 | newLists[i] = src[i] + offset;
|
---|
140 | }
|
---|
141 | }
|
---|
142 | break;
|
---|
143 | case GL_BYTE:
|
---|
144 | {
|
---|
145 | const GLbyte *src = (const GLbyte *) lists;
|
---|
146 | for (i = 0; i < n; i++) {
|
---|
147 | newLists[i] = src[i] + offset;
|
---|
148 | }
|
---|
149 | }
|
---|
150 | break;
|
---|
151 | case GL_UNSIGNED_SHORT:
|
---|
152 | {
|
---|
153 | const GLushort *src = (const GLushort *) lists;
|
---|
154 | for (i = 0; i < n; i++) {
|
---|
155 | newLists[i] = src[i] + offset;
|
---|
156 | }
|
---|
157 | }
|
---|
158 | break;
|
---|
159 | case GL_SHORT:
|
---|
160 | {
|
---|
161 | const GLshort *src = (const GLshort *) lists;
|
---|
162 | for (i = 0; i < n; i++) {
|
---|
163 | newLists[i] = src[i] + offset;
|
---|
164 | }
|
---|
165 | }
|
---|
166 | break;
|
---|
167 | case GL_UNSIGNED_INT:
|
---|
168 | {
|
---|
169 | const GLuint *src = (const GLuint *) lists;
|
---|
170 | for (i = 0; i < n; i++) {
|
---|
171 | newLists[i] = src[i] + offset;
|
---|
172 | }
|
---|
173 | }
|
---|
174 | break;
|
---|
175 | case GL_INT:
|
---|
176 | {
|
---|
177 | const GLint *src = (const GLint *) lists;
|
---|
178 | for (i = 0; i < n; i++) {
|
---|
179 | newLists[i] = src[i] + offset;
|
---|
180 | }
|
---|
181 | }
|
---|
182 | break;
|
---|
183 | case GL_FLOAT:
|
---|
184 | {
|
---|
185 | const GLfloat *src = (const GLfloat *) lists;
|
---|
186 | for (i = 0; i < n; i++) {
|
---|
187 | newLists[i] = (GLuint) src[i] + offset;
|
---|
188 | }
|
---|
189 | }
|
---|
190 | break;
|
---|
191 | case GL_2_BYTES:
|
---|
192 | {
|
---|
193 | const GLubyte *src = (const GLubyte *) lists;
|
---|
194 | for (i = 0; i < n; i++) {
|
---|
195 | newLists[i] = (src[i*2+0] * 256 +
|
---|
196 | src[i*2+1]) + offset;
|
---|
197 | }
|
---|
198 | }
|
---|
199 | break;
|
---|
200 | case GL_3_BYTES:
|
---|
201 | {
|
---|
202 | const GLubyte *src = (const GLubyte *) lists;
|
---|
203 | for (i = 0; i < n; i++) {
|
---|
204 | newLists[i] = (src[i*3+0] * 256 * 256 +
|
---|
205 | src[i*3+1] * 256 +
|
---|
206 | src[i*3+2]) + offset;
|
---|
207 | }
|
---|
208 | }
|
---|
209 | break;
|
---|
210 | case GL_4_BYTES:
|
---|
211 | {
|
---|
212 | const GLubyte *src = (const GLubyte *) lists;
|
---|
213 | for (i = 0; i < n; i++) {
|
---|
214 | newLists[i] = (src[i*4+0] * 256 * 256 * 256 +
|
---|
215 | src[i*4+1] * 256 * 256 +
|
---|
216 | src[i*4+2] * 256 +
|
---|
217 | src[i*4+3]) + offset;
|
---|
218 | }
|
---|
219 | }
|
---|
220 | break;
|
---|
221 | default:
|
---|
222 | crWarning("CRServer: invalid display list datatype 0x%x", type);
|
---|
223 | }
|
---|
224 | }
|
---|
225 |
|
---|
226 |
|
---|
227 | void SERVER_DISPATCH_APIENTRY
|
---|
228 | crServerDispatchCallLists( GLsizei n, GLenum type, const GLvoid *lists )
|
---|
229 | {
|
---|
230 | if (!cr_server.sharedDisplayLists) {
|
---|
231 | /* need to translate IDs */
|
---|
232 | GLuint *newLists = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
233 | if (newLists) {
|
---|
234 | TranslateListIDs(n, type, lists, newLists);
|
---|
235 | }
|
---|
236 | lists = newLists;
|
---|
237 | type = GL_UNSIGNED_INT;
|
---|
238 | }
|
---|
239 |
|
---|
240 | if (cr_server.curClient->currentCtxInfo->pContext->lists.mode == 0) {
|
---|
241 | /* we're not compiling, so execute the list now */
|
---|
242 | /* Issue the list as-is */
|
---|
243 | cr_server.head_spu->dispatch_table.CallLists( n, type, lists );
|
---|
244 | crServerQueryHWState();
|
---|
245 | }
|
---|
246 | else {
|
---|
247 | /* we're compiling glCallList into another list - just pass it through */
|
---|
248 | cr_server.head_spu->dispatch_table.CallLists( n, type, lists );
|
---|
249 | }
|
---|
250 |
|
---|
251 | if (!cr_server.sharedDisplayLists) {
|
---|
252 | crFree((void *) lists); /* malloc'd above */
|
---|
253 | }
|
---|
254 | }
|
---|
255 |
|
---|
256 |
|
---|
257 | GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsList( GLuint list )
|
---|
258 | {
|
---|
259 | GLboolean retval;
|
---|
260 | list = TranslateListID( list );
|
---|
261 | retval = cr_server.head_spu->dispatch_table.IsList( list );
|
---|
262 | crServerReturnValue( &retval, sizeof(retval) );
|
---|
263 | return retval;
|
---|
264 | }
|
---|
265 |
|
---|
266 |
|
---|
267 | void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteLists( GLuint list, GLsizei range )
|
---|
268 | {
|
---|
269 | list = TranslateListID( list );
|
---|
270 | crStateDeleteLists( list, range );
|
---|
271 | cr_server.head_spu->dispatch_table.DeleteLists( list, range );
|
---|
272 | }
|
---|
273 |
|
---|
274 |
|
---|
275 | void SERVER_DISPATCH_APIENTRY crServerDispatchBindTexture( GLenum target, GLuint texture )
|
---|
276 | {
|
---|
277 | crStateBindTexture( target, texture );
|
---|
278 | cr_server.head_spu->dispatch_table.BindTexture(target, crStateGetTextureHWID(texture));
|
---|
279 | }
|
---|
280 |
|
---|
281 | void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteTextures( GLsizei n, const GLuint *textures)
|
---|
282 | {
|
---|
283 | GLuint *newTextures = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
284 | GLint i;
|
---|
285 |
|
---|
286 | if (!newTextures)
|
---|
287 | {
|
---|
288 | crError("crServerDispatchDeleteTextures: out of memory");
|
---|
289 | return;
|
---|
290 | }
|
---|
291 |
|
---|
292 | for (i = 0; i < n; i++)
|
---|
293 | {
|
---|
294 | newTextures[i] = crStateGetTextureHWID(textures[i]);
|
---|
295 | }
|
---|
296 |
|
---|
297 | // for (i = 0; i < n; ++i)
|
---|
298 | // {
|
---|
299 | // crDebug("DeleteTexture: %d, pid %d, ctx %d", textures[i], (uint32_t)cr_server.curClient->pid, cr_server.currentCtxInfo->pContext->id);
|
---|
300 | // }
|
---|
301 |
|
---|
302 |
|
---|
303 | crStateDeleteTextures(n, textures);
|
---|
304 | cr_server.head_spu->dispatch_table.DeleteTextures(n, newTextures);
|
---|
305 | crFree(newTextures);
|
---|
306 | }
|
---|
307 |
|
---|
308 | void SERVER_DISPATCH_APIENTRY crServerDispatchPrioritizeTextures( GLsizei n, const GLuint * textures, const GLclampf * priorities )
|
---|
309 | {
|
---|
310 | GLuint *newTextures = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
311 | GLint i;
|
---|
312 |
|
---|
313 | if (!newTextures)
|
---|
314 | {
|
---|
315 | crError("crServerDispatchDeleteTextures: out of memory");
|
---|
316 | return;
|
---|
317 | }
|
---|
318 |
|
---|
319 | crStatePrioritizeTextures(n, textures, priorities);
|
---|
320 |
|
---|
321 | for (i = 0; i < n; i++)
|
---|
322 | {
|
---|
323 | newTextures[i] = crStateGetTextureHWID(textures[i]);
|
---|
324 | }
|
---|
325 |
|
---|
326 | cr_server.head_spu->dispatch_table.PrioritizeTextures(n, newTextures, priorities);
|
---|
327 | crFree(newTextures);
|
---|
328 | }
|
---|
329 |
|
---|
330 | void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteProgramsARB(GLsizei n, const GLuint * programs)
|
---|
331 | {
|
---|
332 | GLuint *pLocalProgs = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
333 | GLint i;
|
---|
334 | if (!pLocalProgs) {
|
---|
335 | crError("crServerDispatchDeleteProgramsARB: out of memory");
|
---|
336 | return;
|
---|
337 | }
|
---|
338 | for (i = 0; i < n; i++) {
|
---|
339 | pLocalProgs[i] = crServerTranslateProgramID(programs[i]);
|
---|
340 | }
|
---|
341 | crStateDeleteProgramsARB(n, pLocalProgs);
|
---|
342 | cr_server.head_spu->dispatch_table.DeleteProgramsARB(n, pLocalProgs);
|
---|
343 | crFree(pLocalProgs);
|
---|
344 | }
|
---|
345 |
|
---|
346 | /*@todo will fail for textures loaded from snapshot */
|
---|
347 | GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsTexture( GLuint texture )
|
---|
348 | {
|
---|
349 | GLboolean retval;
|
---|
350 | retval = cr_server.head_spu->dispatch_table.IsTexture(crStateGetTextureHWID(texture));
|
---|
351 | crServerReturnValue( &retval, sizeof(retval) );
|
---|
352 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
353 | }
|
---|
354 |
|
---|
355 | /*@todo will fail for progs loaded from snapshot */
|
---|
356 | GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsProgramARB( GLuint program )
|
---|
357 | {
|
---|
358 | GLboolean retval;
|
---|
359 | program = crServerTranslateProgramID(program);
|
---|
360 | retval = cr_server.head_spu->dispatch_table.IsProgramARB( program );
|
---|
361 | crServerReturnValue( &retval, sizeof(retval) );
|
---|
362 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
363 | }
|
---|
364 |
|
---|
365 | GLboolean SERVER_DISPATCH_APIENTRY
|
---|
366 | crServerDispatchAreTexturesResident(GLsizei n, const GLuint *textures,
|
---|
367 | GLboolean *residences)
|
---|
368 | {
|
---|
369 | GLboolean retval;
|
---|
370 | GLsizei i;
|
---|
371 | GLboolean *res = (GLboolean *) crAlloc(n * sizeof(GLboolean));
|
---|
372 | GLuint *textures2 = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
373 |
|
---|
374 | (void) residences;
|
---|
375 |
|
---|
376 | for (i = 0; i < n; i++)
|
---|
377 | {
|
---|
378 | textures2[i] = crStateGetTextureHWID(textures[i]);
|
---|
379 | }
|
---|
380 | retval = cr_server.head_spu->dispatch_table.AreTexturesResident(n, textures2, res);
|
---|
381 |
|
---|
382 | crFree(textures2);
|
---|
383 |
|
---|
384 | crServerReturnValue(res, n * sizeof(GLboolean));
|
---|
385 |
|
---|
386 | crFree(res);
|
---|
387 |
|
---|
388 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
389 | }
|
---|
390 |
|
---|
391 |
|
---|
392 | GLboolean SERVER_DISPATCH_APIENTRY
|
---|
393 | crServerDispatchAreProgramsResidentNV(GLsizei n, const GLuint *programs,
|
---|
394 | GLboolean *residences)
|
---|
395 | {
|
---|
396 | GLboolean retval;
|
---|
397 | GLboolean *res = (GLboolean *) crAlloc(n * sizeof(GLboolean));
|
---|
398 | GLsizei i;
|
---|
399 |
|
---|
400 | (void) residences;
|
---|
401 |
|
---|
402 | if (!cr_server.sharedTextureObjects) {
|
---|
403 | GLuint *programs2 = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
404 | for (i = 0; i < n; i++)
|
---|
405 | programs2[i] = crServerTranslateProgramID(programs[i]);
|
---|
406 | retval = cr_server.head_spu->dispatch_table.AreProgramsResidentNV(n, programs2, res);
|
---|
407 | crFree(programs2);
|
---|
408 | }
|
---|
409 | else {
|
---|
410 | retval = cr_server.head_spu->dispatch_table.AreProgramsResidentNV(n, programs, res);
|
---|
411 | }
|
---|
412 |
|
---|
413 | crServerReturnValue(res, n * sizeof(GLboolean));
|
---|
414 | crFree(res);
|
---|
415 |
|
---|
416 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
417 | }
|
---|