VirtualBox

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

Last change on this file since 48798 was 48793, checked in by vboxsync, 11 years ago

crOpenGL: adjust & log config bits

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