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 | void crServerSetVBoxConfiguration()
|
---|
61 | {
|
---|
62 | CRMuralInfo *defaultMural;
|
---|
63 | char response[8096];
|
---|
64 |
|
---|
65 | char **spuchain;
|
---|
66 | int num_spus;
|
---|
67 | int *spu_ids;
|
---|
68 | char **spu_names;
|
---|
69 | char *spu_dir = NULL;
|
---|
70 | int i;
|
---|
71 | /* Quadrics defaults */
|
---|
72 | int my_rank = 0;
|
---|
73 | int low_context = CR_QUADRICS_DEFAULT_LOW_CONTEXT;
|
---|
74 | int high_context = CR_QUADRICS_DEFAULT_HIGH_CONTEXT;
|
---|
75 | unsigned char key[16]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
---|
76 | char hostname[1024];
|
---|
77 | char **clientchain, **clientlist;
|
---|
78 | GLint dims[4];
|
---|
79 | const char * env;
|
---|
80 |
|
---|
81 | defaultMural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, 0);
|
---|
82 | CRASSERT(defaultMural);
|
---|
83 |
|
---|
84 | setDefaults();
|
---|
85 |
|
---|
86 | /*
|
---|
87 | * Get my hostname
|
---|
88 | */
|
---|
89 | if (crGetHostname(hostname, sizeof(hostname)))
|
---|
90 | {
|
---|
91 | crError("CRServer: Couldn't get my own hostname?");
|
---|
92 | }
|
---|
93 |
|
---|
94 | strcpy(response, "1 0 render");
|
---|
95 | crDebug("CRServer: my SPU chain: %s", response);
|
---|
96 |
|
---|
97 | /* response will describe the SPU chain.
|
---|
98 | * Example "2 5 wet 6 render"
|
---|
99 | */
|
---|
100 | spuchain = crStrSplit(response, " ");
|
---|
101 | num_spus = crStrToInt(spuchain[0]);
|
---|
102 | spu_ids = (int *) crAlloc(num_spus * sizeof(*spu_ids));
|
---|
103 | spu_names = (char **) crAlloc((num_spus + 1) * sizeof(*spu_names));
|
---|
104 | for (i = 0; i < num_spus; i++)
|
---|
105 | {
|
---|
106 | spu_ids[i] = crStrToInt(spuchain[2 * i + 1]);
|
---|
107 | spu_names[i] = crStrdup(spuchain[2 * i + 2]);
|
---|
108 | crDebug("SPU %d/%d: (%d) \"%s\"", i + 1, num_spus, spu_ids[i],
|
---|
109 | spu_names[i]);
|
---|
110 | }
|
---|
111 | spu_names[i] = NULL;
|
---|
112 |
|
---|
113 | crNetSetRank(0);
|
---|
114 | crNetSetContextRange(32, 35);
|
---|
115 | crNetSetNodeRange("iam0", "iamvis20");
|
---|
116 | crNetSetKey(key,sizeof(key));
|
---|
117 | crNetSetKey(key,sizeof(key));
|
---|
118 | cr_server.tcpip_port = 7000;
|
---|
119 |
|
---|
120 | crDebug("CRServer: my port number is %d", cr_server.tcpip_port);
|
---|
121 |
|
---|
122 | /*
|
---|
123 | * Load the SPUs
|
---|
124 | */
|
---|
125 | cr_server.head_spu =
|
---|
126 | crSPULoadChain(num_spus, spu_ids, spu_names, spu_dir, &cr_server);
|
---|
127 |
|
---|
128 | env = crGetenv( "CR_SERVER_DEFAULT_VISUAL_BITS" );
|
---|
129 | if (env != NULL && env[0] != '\0')
|
---|
130 | {
|
---|
131 | unsigned int bits = (unsigned int)crStrParseI32(env, 0);
|
---|
132 | if (bits <= CR_ALL_BITS)
|
---|
133 | cr_server.fVisualBitsDefault = bits;
|
---|
134 | else
|
---|
135 | crWarning("invalid bits option %c", bits);
|
---|
136 | }
|
---|
137 | else
|
---|
138 | cr_server.fVisualBitsDefault = CR_RGB_BIT | CR_ALPHA_BIT | CR_DOUBLE_BIT;
|
---|
139 |
|
---|
140 | env = crGetenv("CR_SERVER_CAPS");
|
---|
141 | if (env && env[0] != '\0')
|
---|
142 | {
|
---|
143 | cr_server.u32Caps = crStrParseI32(env, 0);
|
---|
144 | cr_server.u32Caps &= CR_VBOX_CAPS_ALL;
|
---|
145 | }
|
---|
146 | else
|
---|
147 | {
|
---|
148 | cr_server.u32Caps = CR_VBOX_CAP_TEX_PRESENT
|
---|
149 | | CR_VBOX_CAP_CMDVBVA
|
---|
150 | | CR_VBOX_CAP_CMDBLOCKS
|
---|
151 | | CR_VBOX_CAP_GETATTRIBSLOCATIONS
|
---|
152 | | CR_VBOX_CAP_CMDBLOCKS_FLUSH
|
---|
153 | ;
|
---|
154 | }
|
---|
155 |
|
---|
156 | crInfo("Cfg: u32Caps(%#x), fVisualBitsDefault(%#x)",
|
---|
157 | cr_server.u32Caps,
|
---|
158 | cr_server.fVisualBitsDefault);
|
---|
159 |
|
---|
160 | /* Need to do this as early as possible */
|
---|
161 |
|
---|
162 | cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_POSITION_CR, 0, GL_INT, 2, &dims[0]);
|
---|
163 | cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, 0, GL_INT, 2, &dims[2]);
|
---|
164 |
|
---|
165 | defaultMural->gX = dims[0];
|
---|
166 | defaultMural->gY = dims[1];
|
---|
167 | defaultMural->width = dims[2];
|
---|
168 | defaultMural->height = dims[3];
|
---|
169 |
|
---|
170 | crFree(spu_ids);
|
---|
171 | crFreeStrings(spu_names);
|
---|
172 | crFreeStrings(spuchain);
|
---|
173 | if (spu_dir)
|
---|
174 | crFree(spu_dir);
|
---|
175 |
|
---|
176 | cr_server.mtu = 1024 * 30;
|
---|
177 |
|
---|
178 | /*
|
---|
179 | * Get a list of all the clients talking to me.
|
---|
180 | */
|
---|
181 | if (cr_server.vncMode) {
|
---|
182 | /* we're inside a vnc viewer */
|
---|
183 | /*if (!crMothershipSendString( conn, response, "getvncclient %s", hostname ))
|
---|
184 | crError( "Bad Mothership response: %s", response );*/
|
---|
185 | }
|
---|
186 | else {
|
---|
187 | //crMothershipGetClients(conn, response);
|
---|
188 | strcpy(response, "1 tcpip 1");
|
---|
189 | }
|
---|
190 |
|
---|
191 | crDebug("CRServer: my clients: %s", response);
|
---|
192 |
|
---|
193 | /*
|
---|
194 | * 'response' will now contain a number indicating the number of clients
|
---|
195 | * of this server, followed by a comma-separated list of protocol/SPU ID
|
---|
196 | * pairs.
|
---|
197 | * Example: "3 tcpip 1,gm 2,via 10"
|
---|
198 | */
|
---|
199 | clientchain = crStrSplitn(response, " ", 1);
|
---|
200 | cr_server.numClients = crStrToInt(clientchain[0]);
|
---|
201 | if (cr_server.numClients == 0)
|
---|
202 | {
|
---|
203 | crError("I have no clients! What's a poor server to do?");
|
---|
204 | }
|
---|
205 | clientlist = crStrSplit(clientchain[1], ",");
|
---|
206 |
|
---|
207 | /*
|
---|
208 | * Connect to initial set of clients.
|
---|
209 | * Call crNetAcceptClient() for each client.
|
---|
210 | * Also, look for a client that's _not_ using the file: protocol.
|
---|
211 | */
|
---|
212 | for (i = 0; i < cr_server.numClients; i++)
|
---|
213 | {
|
---|
214 | CRClient *newClient = (CRClient *) crCalloc(sizeof(CRClient));
|
---|
215 | #ifdef VBOX
|
---|
216 | sscanf(clientlist[i], "%1023s %d", cr_server.protocol, &(newClient->spu_id));
|
---|
217 | #else
|
---|
218 | sscanf(clientlist[i], "%s %d", cr_server.protocol, &(newClient->spu_id));
|
---|
219 | #endif
|
---|
220 | newClient->conn = crNetAcceptClient(cr_server.protocol, NULL,
|
---|
221 | cr_server.tcpip_port,
|
---|
222 | cr_server.mtu, 0);
|
---|
223 | newClient->currentCtxInfo = &cr_server.MainContextInfo;
|
---|
224 | crServerAddToRunQueue(newClient);
|
---|
225 |
|
---|
226 | cr_server.clients[i] = newClient;
|
---|
227 | }
|
---|
228 |
|
---|
229 | /* set default client and mural */
|
---|
230 | if (cr_server.numClients > 0) {
|
---|
231 | cr_server.curClient = cr_server.clients[0];
|
---|
232 | cr_server.curClient->currentMural = defaultMural;
|
---|
233 | cr_server.client_spu_id =cr_server.clients[0]->spu_id;
|
---|
234 | }
|
---|
235 |
|
---|
236 | crFreeStrings(clientchain);
|
---|
237 | crFreeStrings(clientlist);
|
---|
238 |
|
---|
239 | /* Ask the mothership for the tile info */
|
---|
240 | //crServerGetTileInfoFromMothership(conn, defaultMural);
|
---|
241 |
|
---|
242 | if (cr_server.vncMode) {
|
---|
243 | /* In vnc mode, we reset the mothership configuration so that it can be
|
---|
244 | * used by subsequent OpenGL apps without having to spawn a new mothership
|
---|
245 | * on a new port.
|
---|
246 | */
|
---|
247 | crDebug("CRServer: Resetting mothership to initial state");
|
---|
248 | //crMothershipReset(conn);
|
---|
249 | }
|
---|
250 |
|
---|
251 | //crMothershipDisconnect(conn);
|
---|
252 | }
|
---|
253 |
|
---|
254 | void crServerSetVBoxConfigurationHGCM()
|
---|
255 | {
|
---|
256 | CRMuralInfo *defaultMural;
|
---|
257 |
|
---|
258 | int spu_ids[1] = {0};
|
---|
259 | char *spu_names[1] = {"render"};
|
---|
260 | char *spu_dir = NULL;
|
---|
261 | int i;
|
---|
262 | GLint dims[4];
|
---|
263 | const char * env;
|
---|
264 |
|
---|
265 | defaultMural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, 0);
|
---|
266 | CRASSERT(defaultMural);
|
---|
267 |
|
---|
268 | //@todo should be moved to addclient so we have a chain for each client
|
---|
269 |
|
---|
270 | setDefaults();
|
---|
271 |
|
---|
272 | /* Load the SPUs */
|
---|
273 | cr_server.head_spu = crSPULoadChain(1, spu_ids, spu_names, spu_dir, &cr_server);
|
---|
274 |
|
---|
275 | if (!cr_server.head_spu)
|
---|
276 | return;
|
---|
277 |
|
---|
278 |
|
---|
279 | env = crGetenv( "CR_SERVER_DEFAULT_VISUAL_BITS" );
|
---|
280 | if (env != NULL && env[0] != '\0')
|
---|
281 | {
|
---|
282 | unsigned int bits = (unsigned int)crStrParseI32(env, 0);
|
---|
283 | if (bits <= CR_ALL_BITS)
|
---|
284 | cr_server.fVisualBitsDefault = bits;
|
---|
285 | else
|
---|
286 | crWarning("invalid bits option %c", bits);
|
---|
287 | }
|
---|
288 | else
|
---|
289 | cr_server.fVisualBitsDefault = CR_RGB_BIT | CR_ALPHA_BIT | CR_DOUBLE_BIT;
|
---|
290 |
|
---|
291 |
|
---|
292 | env = crGetenv("CR_SERVER_CAPS");
|
---|
293 | if (env && env[0] != '\0')
|
---|
294 | {
|
---|
295 | cr_server.u32Caps = crStrParseI32(env, 0);
|
---|
296 | cr_server.u32Caps &= CR_VBOX_CAPS_ALL;
|
---|
297 | }
|
---|
298 | else
|
---|
299 | {
|
---|
300 | cr_server.u32Caps = CR_VBOX_CAP_TEX_PRESENT
|
---|
301 | | CR_VBOX_CAP_CMDVBVA
|
---|
302 | | CR_VBOX_CAP_CMDBLOCKS
|
---|
303 | | CR_VBOX_CAP_GETATTRIBSLOCATIONS
|
---|
304 | | CR_VBOX_CAP_CMDBLOCKS_FLUSH
|
---|
305 | ;
|
---|
306 | }
|
---|
307 |
|
---|
308 | crInfo("Cfg: u32Caps(%#x), fVisualBitsDefault(%#x)",
|
---|
309 | cr_server.u32Caps,
|
---|
310 | cr_server.fVisualBitsDefault);
|
---|
311 |
|
---|
312 | cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_POSITION_CR, 0, GL_INT, 2, &dims[0]);
|
---|
313 | cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, 0, GL_INT, 2, &dims[2]);
|
---|
314 |
|
---|
315 | defaultMural->gX = dims[0];
|
---|
316 | defaultMural->gY = dims[1];
|
---|
317 | defaultMural->width = dims[2];
|
---|
318 | defaultMural->height = dims[3];
|
---|
319 |
|
---|
320 | cr_server.mtu = 1024 * 250;
|
---|
321 |
|
---|
322 | cr_server.numClients = 0;
|
---|
323 | strcpy(cr_server.protocol, "vboxhgcm");
|
---|
324 |
|
---|
325 | for (i = 0; i < cr_server.numClients; i++)
|
---|
326 | {
|
---|
327 | CRClient *newClient = (CRClient *) crCalloc(sizeof(CRClient));
|
---|
328 | newClient->spu_id = 0;
|
---|
329 | newClient->conn = crNetAcceptClient(cr_server.protocol, NULL,
|
---|
330 | cr_server.tcpip_port,
|
---|
331 | cr_server.mtu, 0);
|
---|
332 | newClient->currentCtxInfo = &cr_server.MainContextInfo;
|
---|
333 | crServerAddToRunQueue(newClient);
|
---|
334 |
|
---|
335 | cr_server.clients[i] = newClient;
|
---|
336 | }
|
---|
337 |
|
---|
338 | /* set default client and mural */
|
---|
339 | if (cr_server.numClients > 0) {
|
---|
340 | cr_server.curClient = cr_server.clients[0];
|
---|
341 | cr_server.curClient->currentMural = defaultMural;
|
---|
342 | cr_server.client_spu_id =cr_server.clients[0]->spu_id;
|
---|
343 | }
|
---|
344 | }
|
---|