VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_config.c@ 50101

Last change on this file since 50101 was 50095, checked in by vboxsync, 11 years ago

crOpenGL: presentation infrastructure rework (still work in progress)

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette