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 |
|
---|
50 | GLuint SERVER_DISPATCH_APIENTRY crServerDispatchGenLists( GLsizei range )
|
---|
51 | {
|
---|
52 | GLuint retval;
|
---|
53 | retval = cr_server.head_spu->dispatch_table.GenLists( range );
|
---|
54 | crServerReturnValue( &retval, sizeof(retval) );
|
---|
55 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | void SERVER_DISPATCH_APIENTRY
|
---|
60 | crServerDispatchNewList( GLuint list, GLenum mode )
|
---|
61 | {
|
---|
62 | if (mode == GL_COMPILE_AND_EXECUTE)
|
---|
63 | crWarning("using glNewList(GL_COMPILE_AND_EXECUTE) can confuse the crserver");
|
---|
64 |
|
---|
65 | list = TranslateListID( list );
|
---|
66 | crStateNewList( list, mode );
|
---|
67 | cr_server.head_spu->dispatch_table.NewList( list, mode );
|
---|
68 | }
|
---|
69 |
|
---|
70 | static void crServerQueryHWState()
|
---|
71 | {
|
---|
72 | if (!cr_server.bUseMultipleContexts)
|
---|
73 | {
|
---|
74 | GLuint fbFbo, bbFbo;
|
---|
75 | CRClient *client = cr_server.curClient;
|
---|
76 | CRMuralInfo *mural = client ? client->currentMural : NULL;
|
---|
77 | if (mural && mural->fRedirected)
|
---|
78 | {
|
---|
79 | fbFbo = mural->aidFBOs[CR_SERVER_FBO_FB_IDX(mural)];
|
---|
80 | bbFbo = mural->aidFBOs[CR_SERVER_FBO_BB_IDX(mural)];
|
---|
81 | }
|
---|
82 | else
|
---|
83 | {
|
---|
84 | fbFbo = bbFbo = 0;
|
---|
85 | }
|
---|
86 | crStateQueryHWState(fbFbo, bbFbo);
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | void SERVER_DISPATCH_APIENTRY crServerDispatchEndList(void)
|
---|
91 | {
|
---|
92 | CRContext *g = crStateGetCurrent();
|
---|
93 | CRListsState *l = &(g->lists);
|
---|
94 |
|
---|
95 | cr_server.head_spu->dispatch_table.EndList();
|
---|
96 | crStateEndList();
|
---|
97 |
|
---|
98 | #ifndef IN_GUEST
|
---|
99 | if (l->mode==GL_COMPILE)
|
---|
100 | {
|
---|
101 | crServerQueryHWState();
|
---|
102 | }
|
---|
103 | #endif
|
---|
104 | }
|
---|
105 |
|
---|
106 | void SERVER_DISPATCH_APIENTRY
|
---|
107 | crServerDispatchCallList( GLuint list )
|
---|
108 | {
|
---|
109 | list = TranslateListID( list );
|
---|
110 |
|
---|
111 | if (cr_server.curClient->currentCtxInfo->pContext->lists.mode == 0) {
|
---|
112 | /* we're not compiling, so execute the list now */
|
---|
113 | /* Issue the list as-is */
|
---|
114 | cr_server.head_spu->dispatch_table.CallList( list );
|
---|
115 | crServerQueryHWState();
|
---|
116 | }
|
---|
117 | else {
|
---|
118 | /* we're compiling glCallList into another list - just pass it through */
|
---|
119 | cr_server.head_spu->dispatch_table.CallList( list );
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | /**
|
---|
125 | * Translate an array of display list IDs from various datatypes to GLuint
|
---|
126 | * IDs while adding the per-client offset.
|
---|
127 | */
|
---|
128 | static void
|
---|
129 | TranslateListIDs(GLsizei n, GLenum type, const GLvoid *lists, GLuint *newLists)
|
---|
130 | {
|
---|
131 | int offset = cr_server.curClient->number * 100000;
|
---|
132 | GLsizei i;
|
---|
133 | switch (type) {
|
---|
134 | case GL_UNSIGNED_BYTE:
|
---|
135 | {
|
---|
136 | const GLubyte *src = (const GLubyte *) lists;
|
---|
137 | for (i = 0; i < n; i++) {
|
---|
138 | newLists[i] = src[i] + offset;
|
---|
139 | }
|
---|
140 | }
|
---|
141 | break;
|
---|
142 | case GL_BYTE:
|
---|
143 | {
|
---|
144 | const GLbyte *src = (const GLbyte *) lists;
|
---|
145 | for (i = 0; i < n; i++) {
|
---|
146 | newLists[i] = src[i] + offset;
|
---|
147 | }
|
---|
148 | }
|
---|
149 | break;
|
---|
150 | case GL_UNSIGNED_SHORT:
|
---|
151 | {
|
---|
152 | const GLushort *src = (const GLushort *) lists;
|
---|
153 | for (i = 0; i < n; i++) {
|
---|
154 | newLists[i] = src[i] + offset;
|
---|
155 | }
|
---|
156 | }
|
---|
157 | break;
|
---|
158 | case GL_SHORT:
|
---|
159 | {
|
---|
160 | const GLshort *src = (const GLshort *) lists;
|
---|
161 | for (i = 0; i < n; i++) {
|
---|
162 | newLists[i] = src[i] + offset;
|
---|
163 | }
|
---|
164 | }
|
---|
165 | break;
|
---|
166 | case GL_UNSIGNED_INT:
|
---|
167 | {
|
---|
168 | const GLuint *src = (const GLuint *) lists;
|
---|
169 | for (i = 0; i < n; i++) {
|
---|
170 | newLists[i] = src[i] + offset;
|
---|
171 | }
|
---|
172 | }
|
---|
173 | break;
|
---|
174 | case GL_INT:
|
---|
175 | {
|
---|
176 | const GLint *src = (const GLint *) lists;
|
---|
177 | for (i = 0; i < n; i++) {
|
---|
178 | newLists[i] = src[i] + offset;
|
---|
179 | }
|
---|
180 | }
|
---|
181 | break;
|
---|
182 | case GL_FLOAT:
|
---|
183 | {
|
---|
184 | const GLfloat *src = (const GLfloat *) lists;
|
---|
185 | for (i = 0; i < n; i++) {
|
---|
186 | newLists[i] = (GLuint) src[i] + offset;
|
---|
187 | }
|
---|
188 | }
|
---|
189 | break;
|
---|
190 | case GL_2_BYTES:
|
---|
191 | {
|
---|
192 | const GLubyte *src = (const GLubyte *) lists;
|
---|
193 | for (i = 0; i < n; i++) {
|
---|
194 | newLists[i] = (src[i*2+0] * 256 +
|
---|
195 | src[i*2+1]) + offset;
|
---|
196 | }
|
---|
197 | }
|
---|
198 | break;
|
---|
199 | case GL_3_BYTES:
|
---|
200 | {
|
---|
201 | const GLubyte *src = (const GLubyte *) lists;
|
---|
202 | for (i = 0; i < n; i++) {
|
---|
203 | newLists[i] = (src[i*3+0] * 256 * 256 +
|
---|
204 | src[i*3+1] * 256 +
|
---|
205 | src[i*3+2]) + offset;
|
---|
206 | }
|
---|
207 | }
|
---|
208 | break;
|
---|
209 | case GL_4_BYTES:
|
---|
210 | {
|
---|
211 | const GLubyte *src = (const GLubyte *) lists;
|
---|
212 | for (i = 0; i < n; i++) {
|
---|
213 | newLists[i] = (src[i*4+0] * 256 * 256 * 256 +
|
---|
214 | src[i*4+1] * 256 * 256 +
|
---|
215 | src[i*4+2] * 256 +
|
---|
216 | src[i*4+3]) + offset;
|
---|
217 | }
|
---|
218 | }
|
---|
219 | break;
|
---|
220 | default:
|
---|
221 | crWarning("CRServer: invalid display list datatype 0x%x", type);
|
---|
222 | }
|
---|
223 | }
|
---|
224 |
|
---|
225 | void SERVER_DISPATCH_APIENTRY
|
---|
226 | crServerDispatchCallLists( GLsizei n, GLenum type, const GLvoid *lists )
|
---|
227 | {
|
---|
228 | if (n <= 0 || n >= INT32_MAX / sizeof(GLuint))
|
---|
229 | {
|
---|
230 | crError("crServerDispatchCallLists: parameter 'n' is out of range");
|
---|
231 | return;
|
---|
232 | }
|
---|
233 |
|
---|
234 | if (!cr_server.sharedDisplayLists) {
|
---|
235 | /* need to translate IDs */
|
---|
236 | GLuint *newLists = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
237 | if (newLists) {
|
---|
238 | TranslateListIDs(n, type, lists, newLists);
|
---|
239 | }
|
---|
240 | lists = newLists;
|
---|
241 | type = GL_UNSIGNED_INT;
|
---|
242 | }
|
---|
243 |
|
---|
244 | if (cr_server.curClient->currentCtxInfo->pContext->lists.mode == 0) {
|
---|
245 | /* we're not compiling, so execute the list now */
|
---|
246 | /* Issue the list as-is */
|
---|
247 | cr_server.head_spu->dispatch_table.CallLists( n, type, lists );
|
---|
248 | crServerQueryHWState();
|
---|
249 | }
|
---|
250 | else {
|
---|
251 | /* we're compiling glCallList into another list - just pass it through */
|
---|
252 | cr_server.head_spu->dispatch_table.CallLists( n, type, lists );
|
---|
253 | }
|
---|
254 |
|
---|
255 | if (!cr_server.sharedDisplayLists) {
|
---|
256 | crFree((void *) lists); /* malloc'd above */
|
---|
257 | }
|
---|
258 | }
|
---|
259 |
|
---|
260 |
|
---|
261 | GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsList( GLuint list )
|
---|
262 | {
|
---|
263 | GLboolean retval;
|
---|
264 | list = TranslateListID( list );
|
---|
265 | retval = cr_server.head_spu->dispatch_table.IsList( list );
|
---|
266 | crServerReturnValue( &retval, sizeof(retval) );
|
---|
267 | return retval;
|
---|
268 | }
|
---|
269 |
|
---|
270 |
|
---|
271 | void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteLists( GLuint list, GLsizei range )
|
---|
272 | {
|
---|
273 | list = TranslateListID( list );
|
---|
274 | crStateDeleteLists( list, range );
|
---|
275 | cr_server.head_spu->dispatch_table.DeleteLists( list, range );
|
---|
276 | }
|
---|