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 <string.h>
|
---|
8 | #include "cr_mem.h"
|
---|
9 | #include "cr_environment.h"
|
---|
10 | #include "cr_string.h"
|
---|
11 | #include "cr_error.h"
|
---|
12 | #include "cr_glstate.h"
|
---|
13 | #include "server.h"
|
---|
14 |
|
---|
15 | #ifdef WINDOWS
|
---|
16 | #pragma warning( disable: 4706 )
|
---|
17 | #endif
|
---|
18 |
|
---|
19 | static void
|
---|
20 | setDefaults(void)
|
---|
21 | {
|
---|
22 | if (!cr_server.tcpip_port)
|
---|
23 | cr_server.tcpip_port = DEFAULT_SERVER_PORT;
|
---|
24 | cr_server.run_queue = NULL;
|
---|
25 | cr_server.optimizeBucket = 1;
|
---|
26 | cr_server.useL2 = 0;
|
---|
27 | cr_server.maxBarrierCount = 0;
|
---|
28 | cr_server.ignore_papi = 0;
|
---|
29 | cr_server.only_swap_once = 0;
|
---|
30 | cr_server.overlapBlending = 0;
|
---|
31 | cr_server.debug_barriers = 0;
|
---|
32 | cr_server.sharedDisplayLists = 0;
|
---|
33 | cr_server.sharedTextureObjects = 0;
|
---|
34 | cr_server.sharedPrograms = 0;
|
---|
35 | cr_server.sharedWindows = 0;
|
---|
36 | cr_server.useDMX = 0;
|
---|
37 | cr_server.vpProjectionMatrixParameter = -1;
|
---|
38 | cr_server.vpProjectionMatrixVariable = NULL;
|
---|
39 | cr_server.currentProgram = 0;
|
---|
40 |
|
---|
41 | cr_server.num_overlap_intens = 0;
|
---|
42 | cr_server.overlap_intens = 0;
|
---|
43 | crMemset(&cr_server.MainContextInfo, 0, sizeof (cr_server.MainContextInfo));
|
---|
44 |
|
---|
45 | crMatrixInit(&cr_server.viewMatrix[0]);
|
---|
46 | crMatrixInit(&cr_server.viewMatrix[1]);
|
---|
47 | crMatrixInit(&cr_server.projectionMatrix[0]);
|
---|
48 | crMatrixInit(&cr_server.projectionMatrix[1]);
|
---|
49 | cr_server.currentEye = -1;
|
---|
50 |
|
---|
51 | cr_server.uniqueWindows = 0;
|
---|
52 |
|
---|
53 | cr_server.screenCount = 0;
|
---|
54 | cr_server.bUsePBOForReadback = GL_FALSE;
|
---|
55 | cr_server.bWindowsInitiallyHidden = GL_FALSE;
|
---|
56 |
|
---|
57 | cr_server.pfnNotifyEventCB = NULL;
|
---|
58 | }
|
---|
59 |
|
---|
60 | int crServerVBoxParseNumerics(const char *pszStr, const int defaultVal)
|
---|
61 | {
|
---|
62 | int result = 0;
|
---|
63 | bool neg = false;
|
---|
64 | unsigned char iDigit = 0;
|
---|
65 | if (!pszStr || pszStr[0] == '\0')
|
---|
66 | return defaultVal;
|
---|
67 |
|
---|
68 | for (;;)
|
---|
69 | {
|
---|
70 | if (pszStr[0] == '\0')
|
---|
71 | return defaultVal;
|
---|
72 |
|
---|
73 | if (pszStr[0] == ' ' || pszStr[0] == '\t' || pszStr[0] == '\n')
|
---|
74 | {
|
---|
75 | ++pszStr;
|
---|
76 | continue;
|
---|
77 | }
|
---|
78 |
|
---|
79 | if (pszStr[0] == '-')
|
---|
80 | {
|
---|
81 | if (neg)
|
---|
82 | return defaultVal;
|
---|
83 |
|
---|
84 | neg = true;
|
---|
85 | ++pszStr;
|
---|
86 | continue;
|
---|
87 | }
|
---|
88 |
|
---|
89 | break;
|
---|
90 | }
|
---|
91 |
|
---|
92 | for (;;)
|
---|
93 | {
|
---|
94 | unsigned char digit;
|
---|
95 | if (pszStr[0] == '\0')
|
---|
96 | {
|
---|
97 | if (!iDigit)
|
---|
98 | return defaultVal;
|
---|
99 | break;
|
---|
100 | }
|
---|
101 |
|
---|
102 | digit = pszStr[0] - '0';
|
---|
103 | if (digit > 9)
|
---|
104 | return defaultVal;
|
---|
105 |
|
---|
106 | result *= 10;
|
---|
107 | result += digit;
|
---|
108 | ++iDigit;
|
---|
109 |
|
---|
110 | ++pszStr;
|
---|
111 | }
|
---|
112 |
|
---|
113 | return !neg ? result : -result;
|
---|
114 | }
|
---|
115 |
|
---|
116 | void crServerSetVBoxConfiguration()
|
---|
117 | {
|
---|
118 | CRMuralInfo *defaultMural;
|
---|
119 | char response[8096];
|
---|
120 |
|
---|
121 | char **spuchain;
|
---|
122 | int num_spus;
|
---|
123 | int *spu_ids;
|
---|
124 | char **spu_names;
|
---|
125 | char *spu_dir = NULL;
|
---|
126 | int i;
|
---|
127 | /* Quadrics defaults */
|
---|
128 | int my_rank = 0;
|
---|
129 | int low_context = CR_QUADRICS_DEFAULT_LOW_CONTEXT;
|
---|
130 | int high_context = CR_QUADRICS_DEFAULT_HIGH_CONTEXT;
|
---|
131 | unsigned char key[16]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
---|
132 | char hostname[1024];
|
---|
133 | char **clientchain, **clientlist;
|
---|
134 | GLint dims[4];
|
---|
135 | const char * env;
|
---|
136 |
|
---|
137 | defaultMural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, 0);
|
---|
138 | CRASSERT(defaultMural);
|
---|
139 |
|
---|
140 | setDefaults();
|
---|
141 |
|
---|
142 | /*
|
---|
143 | * Get my hostname
|
---|
144 | */
|
---|
145 | if (crGetHostname(hostname, sizeof(hostname)))
|
---|
146 | {
|
---|
147 | crError("CRServer: Couldn't get my own hostname?");
|
---|
148 | }
|
---|
149 |
|
---|
150 | strcpy(response, "1 0 render");
|
---|
151 | crDebug("CRServer: my SPU chain: %s", response);
|
---|
152 |
|
---|
153 | /* response will describe the SPU chain.
|
---|
154 | * Example "2 5 wet 6 render"
|
---|
155 | */
|
---|
156 | spuchain = crStrSplit(response, " ");
|
---|
157 | num_spus = crStrToInt(spuchain[0]);
|
---|
158 | spu_ids = (int *) crAlloc(num_spus * sizeof(*spu_ids));
|
---|
159 | spu_names = (char **) crAlloc((num_spus + 1) * sizeof(*spu_names));
|
---|
160 | for (i = 0; i < num_spus; i++)
|
---|
161 | {
|
---|
162 | spu_ids[i] = crStrToInt(spuchain[2 * i + 1]);
|
---|
163 | spu_names[i] = crStrdup(spuchain[2 * i + 2]);
|
---|
164 | crDebug("SPU %d/%d: (%d) \"%s\"", i + 1, num_spus, spu_ids[i],
|
---|
165 | spu_names[i]);
|
---|
166 | }
|
---|
167 | spu_names[i] = NULL;
|
---|
168 |
|
---|
169 | //spu_dir = crStrdup(response);
|
---|
170 | crNetSetRank(0);
|
---|
171 | crNetSetContextRange(32, 35);
|
---|
172 | crNetSetNodeRange("iam0", "iamvis20");
|
---|
173 | crNetSetKey(key,sizeof(key));
|
---|
174 | crNetSetKey(key,sizeof(key));
|
---|
175 | cr_server.tcpip_port = 7000;
|
---|
176 |
|
---|
177 | /*cr_server.optimizeBucket = crStrToInt(response);
|
---|
178 | cr_server.localTileSpec = crStrToInt(response);
|
---|
179 | cr_server.useL2 = crStrToInt(response);
|
---|
180 | cr_server.ignore_papi = crStrToInt(response);
|
---|
181 | if (crMothershipGetServerParam(conn, response, "overlap_blending"))
|
---|
182 | {
|
---|
183 | if (!crStrcmp(response, "blend"))
|
---|
184 | cr_server.overlapBlending = 1;
|
---|
185 | else if (!crStrcmp(response, "knockout"))
|
---|
186 | cr_server.overlapBlending = 2;
|
---|
187 | }
|
---|
188 | if (crMothershipGetServerParam(conn, response, "overlap_levels"))
|
---|
189 | cr_server.only_swap_once = crStrToInt(response);
|
---|
190 | cr_server.debug_barriers = crStrToInt(response);
|
---|
191 | cr_server.sharedDisplayLists = crStrToInt(response);
|
---|
192 | cr_server.sharedTextureObjects = crStrToInt(response);
|
---|
193 | cr_server.sharedPrograms = crStrToInt(response);
|
---|
194 | cr_server.sharedWindows = crStrToInt(response);
|
---|
195 | cr_server.uniqueWindows = crStrToInt(response);
|
---|
196 | cr_server.useDMX = crStrToInt(response);
|
---|
197 | if (crMothershipGetServerParam(conn, response, "vertprog_projection_param"))
|
---|
198 | if (crMothershipGetServerParam(conn, response, "stereo_view"))
|
---|
199 | if (crMothershipGetServerParam(conn, response, "view_matrix"))
|
---|
200 | if (crMothershipGetServerParam(conn, response, "right_view_matrix"))
|
---|
201 | if (crMothershipGetServerParam(conn, response, "projection_matrix"))
|
---|
202 | if (crMothershipGetServerParam(conn, response, "right_projection_matrix"))*/
|
---|
203 |
|
---|
204 | crDebug("CRServer: my port number is %d", cr_server.tcpip_port);
|
---|
205 |
|
---|
206 | /*
|
---|
207 | * Load the SPUs
|
---|
208 | */
|
---|
209 | cr_server.head_spu =
|
---|
210 | crSPULoadChain(num_spus, spu_ids, spu_names, spu_dir, &cr_server);
|
---|
211 |
|
---|
212 | env = crGetenv( "CR_SERVER_DEFAULT_VISUAL_BITS" );
|
---|
213 | if (env != NULL && env[0] != '\0')
|
---|
214 | {
|
---|
215 | unsigned int bits = (unsigned int)crServerVBoxParseNumerics(env, 0);
|
---|
216 | if (bits <= CR_ALL_BITS)
|
---|
217 | cr_server.fVisualBitsDefault = bits;
|
---|
218 | else
|
---|
219 | crWarning("invalid bits option %c", bits);
|
---|
220 | }
|
---|
221 | else
|
---|
222 | cr_server.fVisualBitsDefault = CR_RGB_BIT | CR_ALPHA_BIT | CR_DOUBLE_BIT;
|
---|
223 |
|
---|
224 | env = crGetenv("CR_SERVER_CAPS");
|
---|
225 | if (env && env[0] != '\0')
|
---|
226 | {
|
---|
227 | cr_server.u32Caps = crServerVBoxParseNumerics(env, 0);
|
---|
228 | cr_server.u32Caps &= ~(CR_VBOX_CAP_TEX_PRESENT | CR_VBOX_CAP_CMDVBVA | CR_VBOX_CAP_CMDBLOCKS);
|
---|
229 | }
|
---|
230 | else
|
---|
231 | {
|
---|
232 | cr_server.u32Caps = CR_VBOX_CAP_TEX_PRESENT
|
---|
233 | | CR_VBOX_CAP_CMDVBVA | CR_VBOX_CAP_CMDBLOCKS
|
---|
234 | ;
|
---|
235 |
|
---|
236 | }
|
---|
237 |
|
---|
238 | crInfo("Cfg: u32Caps(%#x), fVisualBitsDefault(%#x)",
|
---|
239 | cr_server.u32Caps,
|
---|
240 | cr_server.fVisualBitsDefault);
|
---|
241 |
|
---|
242 | /* Need to do this as early as possible */
|
---|
243 |
|
---|
244 | cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_POSITION_CR, 0, GL_INT, 2, &dims[0]);
|
---|
245 | cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, 0, GL_INT, 2, &dims[2]);
|
---|
246 |
|
---|
247 | defaultMural->gX = dims[0];
|
---|
248 | defaultMural->gY = dims[1];
|
---|
249 | defaultMural->width = dims[2];
|
---|
250 | defaultMural->height = dims[3];
|
---|
251 |
|
---|
252 | crFree(spu_ids);
|
---|
253 | crFreeStrings(spu_names);
|
---|
254 | crFreeStrings(spuchain);
|
---|
255 | if (spu_dir)
|
---|
256 | crFree(spu_dir);
|
---|
257 |
|
---|
258 | cr_server.mtu = 1024 * 30;
|
---|
259 |
|
---|
260 | /*
|
---|
261 | * Get a list of all the clients talking to me.
|
---|
262 | */
|
---|
263 | if (cr_server.vncMode) {
|
---|
264 | /* we're inside a vnc viewer */
|
---|
265 | /*if (!crMothershipSendString( conn, response, "getvncclient %s", hostname ))
|
---|
266 | crError( "Bad Mothership response: %s", response );*/
|
---|
267 | }
|
---|
268 | else {
|
---|
269 | //crMothershipGetClients(conn, response);
|
---|
270 | strcpy(response, "1 tcpip 1");
|
---|
271 | }
|
---|
272 |
|
---|
273 | crDebug("CRServer: my clients: %s", response);
|
---|
274 |
|
---|
275 | /*
|
---|
276 | * 'response' will now contain a number indicating the number of clients
|
---|
277 | * of this server, followed by a comma-separated list of protocol/SPU ID
|
---|
278 | * pairs.
|
---|
279 | * Example: "3 tcpip 1,gm 2,via 10"
|
---|
280 | */
|
---|
281 | clientchain = crStrSplitn(response, " ", 1);
|
---|
282 | cr_server.numClients = crStrToInt(clientchain[0]);
|
---|
283 | if (cr_server.numClients == 0)
|
---|
284 | {
|
---|
285 | crError("I have no clients! What's a poor server to do?");
|
---|
286 | }
|
---|
287 | clientlist = crStrSplit(clientchain[1], ",");
|
---|
288 |
|
---|
289 | /*
|
---|
290 | * Connect to initial set of clients.
|
---|
291 | * Call crNetAcceptClient() for each client.
|
---|
292 | * Also, look for a client that's _not_ using the file: protocol.
|
---|
293 | */
|
---|
294 | for (i = 0; i < cr_server.numClients; i++)
|
---|
295 | {
|
---|
296 | CRClient *newClient = (CRClient *) crCalloc(sizeof(CRClient));
|
---|
297 | #ifdef VBOX
|
---|
298 | sscanf(clientlist[i], "%1023s %d", cr_server.protocol, &(newClient->spu_id));
|
---|
299 | #else
|
---|
300 | sscanf(clientlist[i], "%s %d", cr_server.protocol, &(newClient->spu_id));
|
---|
301 | #endif
|
---|
302 | newClient->conn = crNetAcceptClient(cr_server.protocol, NULL,
|
---|
303 | cr_server.tcpip_port,
|
---|
304 | cr_server.mtu, 0);
|
---|
305 | newClient->currentCtxInfo = &cr_server.MainContextInfo;
|
---|
306 | crServerAddToRunQueue(newClient);
|
---|
307 |
|
---|
308 | cr_server.clients[i] = newClient;
|
---|
309 | }
|
---|
310 |
|
---|
311 | /* set default client and mural */
|
---|
312 | if (cr_server.numClients > 0) {
|
---|
313 | cr_server.curClient = cr_server.clients[0];
|
---|
314 | cr_server.curClient->currentMural = defaultMural;
|
---|
315 | cr_server.client_spu_id =cr_server.clients[0]->spu_id;
|
---|
316 | }
|
---|
317 |
|
---|
318 | crFreeStrings(clientchain);
|
---|
319 | crFreeStrings(clientlist);
|
---|
320 |
|
---|
321 | /* Ask the mothership for the tile info */
|
---|
322 | //crServerGetTileInfoFromMothership(conn, defaultMural);
|
---|
323 |
|
---|
324 | if (cr_server.vncMode) {
|
---|
325 | /* In vnc mode, we reset the mothership configuration so that it can be
|
---|
326 | * used by subsequent OpenGL apps without having to spawn a new mothership
|
---|
327 | * on a new port.
|
---|
328 | */
|
---|
329 | crDebug("CRServer: Resetting mothership to initial state");
|
---|
330 | //crMothershipReset(conn);
|
---|
331 | }
|
---|
332 |
|
---|
333 | //crMothershipDisconnect(conn);
|
---|
334 | }
|
---|
335 |
|
---|
336 | void crServerSetVBoxConfigurationHGCM()
|
---|
337 | {
|
---|
338 | CRMuralInfo *defaultMural;
|
---|
339 |
|
---|
340 | int spu_ids[1] = {0};
|
---|
341 | char *spu_names[1] = {"render"};
|
---|
342 | char *spu_dir = NULL;
|
---|
343 | int i;
|
---|
344 | GLint dims[4];
|
---|
345 | const char * env;
|
---|
346 |
|
---|
347 | defaultMural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, 0);
|
---|
348 | CRASSERT(defaultMural);
|
---|
349 |
|
---|
350 | //@todo should be moved to addclient so we have a chain for each client
|
---|
351 |
|
---|
352 | setDefaults();
|
---|
353 |
|
---|
354 | /* Load the SPUs */
|
---|
355 | cr_server.head_spu = crSPULoadChain(1, spu_ids, spu_names, spu_dir, &cr_server);
|
---|
356 |
|
---|
357 | if (!cr_server.head_spu)
|
---|
358 | return;
|
---|
359 |
|
---|
360 |
|
---|
361 | env = crGetenv( "CR_SERVER_DEFAULT_VISUAL_BITS" );
|
---|
362 | if (env != NULL && env[0] != '\0')
|
---|
363 | {
|
---|
364 | unsigned int bits = (unsigned int)crServerVBoxParseNumerics(env, 0);
|
---|
365 | if (bits <= CR_ALL_BITS)
|
---|
366 | cr_server.fVisualBitsDefault = bits;
|
---|
367 | else
|
---|
368 | crWarning("invalid bits option %c", bits);
|
---|
369 | }
|
---|
370 | else
|
---|
371 | cr_server.fVisualBitsDefault = CR_RGB_BIT | CR_ALPHA_BIT | CR_DOUBLE_BIT;
|
---|
372 |
|
---|
373 | env = crGetenv("CR_SERVER_CAPS");
|
---|
374 | if (env && env[0] != '\0')
|
---|
375 | {
|
---|
376 | cr_server.u32Caps = crServerVBoxParseNumerics(env, 0);
|
---|
377 | cr_server.u32Caps &= ~(CR_VBOX_CAP_TEX_PRESENT | CR_VBOX_CAP_CMDVBVA | CR_VBOX_CAP_CMDBLOCKS);
|
---|
378 | }
|
---|
379 | else
|
---|
380 | {
|
---|
381 | cr_server.u32Caps = CR_VBOX_CAP_TEX_PRESENT
|
---|
382 | | CR_VBOX_CAP_CMDVBVA | CR_VBOX_CAP_CMDBLOCKS
|
---|
383 | ;
|
---|
384 | }
|
---|
385 |
|
---|
386 | crInfo("Cfg: u32Caps(%#x), fVisualBitsDefault(%#x)",
|
---|
387 | cr_server.u32Caps,
|
---|
388 | cr_server.fVisualBitsDefault);
|
---|
389 |
|
---|
390 | cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_POSITION_CR, 0, GL_INT, 2, &dims[0]);
|
---|
391 | cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, 0, GL_INT, 2, &dims[2]);
|
---|
392 |
|
---|
393 | defaultMural->gX = dims[0];
|
---|
394 | defaultMural->gY = dims[1];
|
---|
395 | defaultMural->width = dims[2];
|
---|
396 | defaultMural->height = dims[3];
|
---|
397 |
|
---|
398 | cr_server.mtu = 1024 * 250;
|
---|
399 |
|
---|
400 | cr_server.numClients = 0;
|
---|
401 | strcpy(cr_server.protocol, "vboxhgcm");
|
---|
402 |
|
---|
403 | for (i = 0; i < cr_server.numClients; i++)
|
---|
404 | {
|
---|
405 | CRClient *newClient = (CRClient *) crCalloc(sizeof(CRClient));
|
---|
406 | newClient->spu_id = 0;
|
---|
407 | newClient->conn = crNetAcceptClient(cr_server.protocol, NULL,
|
---|
408 | cr_server.tcpip_port,
|
---|
409 | cr_server.mtu, 0);
|
---|
410 | newClient->currentCtxInfo = &cr_server.MainContextInfo;
|
---|
411 | crServerAddToRunQueue(newClient);
|
---|
412 |
|
---|
413 | cr_server.clients[i] = newClient;
|
---|
414 | }
|
---|
415 |
|
---|
416 | /* set default client and mural */
|
---|
417 | if (cr_server.numClients > 0) {
|
---|
418 | cr_server.curClient = cr_server.clients[0];
|
---|
419 | cr_server.curClient->currentMural = defaultMural;
|
---|
420 | cr_server.client_spu_id =cr_server.clients[0]->spu_id;
|
---|
421 | }
|
---|
422 | }
|
---|