VirtualBox

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

Last change on this file since 48079 was 47577, checked in by vboxsync, 11 years ago

crOpenGL: postpone event notification until data is presented (needed for OSX hosts)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 13.5 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 /* Need to do this as early as possible */
246
247 cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_POSITION_CR, 0, GL_INT, 2, &dims[0]);
248 cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, 0, GL_INT, 2, &dims[2]);
249
250 defaultMural->gX = dims[0];
251 defaultMural->gY = dims[1];
252 defaultMural->width = dims[2];
253 defaultMural->height = dims[3];
254
255 crFree(spu_ids);
256 crFreeStrings(spu_names);
257 crFreeStrings(spuchain);
258 if (spu_dir)
259 crFree(spu_dir);
260
261 cr_server.mtu = 1024 * 30;
262
263 /*
264 * Get a list of all the clients talking to me.
265 */
266 if (cr_server.vncMode) {
267 /* we're inside a vnc viewer */
268 /*if (!crMothershipSendString( conn, response, "getvncclient %s", hostname ))
269 crError( "Bad Mothership response: %s", response );*/
270 }
271 else {
272 //crMothershipGetClients(conn, response);
273 strcpy(response, "1 tcpip 1");
274 }
275
276 crDebug("CRServer: my clients: %s", response);
277
278 /*
279 * 'response' will now contain a number indicating the number of clients
280 * of this server, followed by a comma-separated list of protocol/SPU ID
281 * pairs.
282 * Example: "3 tcpip 1,gm 2,via 10"
283 */
284 clientchain = crStrSplitn(response, " ", 1);
285 cr_server.numClients = crStrToInt(clientchain[0]);
286 if (cr_server.numClients == 0)
287 {
288 crError("I have no clients! What's a poor server to do?");
289 }
290 clientlist = crStrSplit(clientchain[1], ",");
291
292 /*
293 * Connect to initial set of clients.
294 * Call crNetAcceptClient() for each client.
295 * Also, look for a client that's _not_ using the file: protocol.
296 */
297 for (i = 0; i < cr_server.numClients; i++)
298 {
299 CRClient *newClient = (CRClient *) crCalloc(sizeof(CRClient));
300#ifdef VBOX
301 sscanf(clientlist[i], "%1023s %d", cr_server.protocol, &(newClient->spu_id));
302#else
303 sscanf(clientlist[i], "%s %d", cr_server.protocol, &(newClient->spu_id));
304#endif
305 newClient->conn = crNetAcceptClient(cr_server.protocol, NULL,
306 cr_server.tcpip_port,
307 cr_server.mtu, 0);
308 newClient->currentCtxInfo = &cr_server.MainContextInfo;
309 crServerAddToRunQueue(newClient);
310
311 cr_server.clients[i] = newClient;
312 }
313
314 /* set default client and mural */
315 if (cr_server.numClients > 0) {
316 cr_server.curClient = cr_server.clients[0];
317 cr_server.curClient->currentMural = defaultMural;
318 cr_server.client_spu_id =cr_server.clients[0]->spu_id;
319 }
320
321 crFreeStrings(clientchain);
322 crFreeStrings(clientlist);
323
324 /* Ask the mothership for the tile info */
325 //crServerGetTileInfoFromMothership(conn, defaultMural);
326
327 if (cr_server.vncMode) {
328 /* In vnc mode, we reset the mothership configuration so that it can be
329 * used by subsequent OpenGL apps without having to spawn a new mothership
330 * on a new port.
331 */
332 crDebug("CRServer: Resetting mothership to initial state");
333 //crMothershipReset(conn);
334 }
335
336 //crMothershipDisconnect(conn);
337}
338
339void crServerSetVBoxConfigurationHGCM()
340{
341 CRMuralInfo *defaultMural;
342
343 int spu_ids[1] = {0};
344 char *spu_names[1] = {"render"};
345 char *spu_dir = NULL;
346 int i;
347 GLint dims[4];
348 const char * env;
349
350 defaultMural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, 0);
351 CRASSERT(defaultMural);
352
353 //@todo should be moved to addclient so we have a chain for each client
354
355 setDefaults();
356
357 /* Load the SPUs */
358 cr_server.head_spu = crSPULoadChain(1, spu_ids, spu_names, spu_dir, &cr_server);
359
360 if (!cr_server.head_spu)
361 return;
362
363 env = crGetenv( "CR_SERVER_DEFAULT_RENDER_TYPE" );
364 if (env != NULL && env[0] != '\0')
365 {
366 unsigned int redir = (unsigned int)crServerVBoxParseNumerics(env, CR_SERVER_REDIR_F_NONE);
367 if (redir <= CR_SERVER_REDIR_F_ALL)
368 {
369 int rc = crServerSetOffscreenRenderingMode(redir);
370 if (!RT_SUCCESS(rc))
371 crWarning("offscreen rendering unsupported, no offscreen rendering will be used..");
372 }
373 else
374 crWarning("invalid redir option %c", redir);
375 }
376#if defined(RT_OS_DARWIN) || defined(RT_OS_WINDOWS) || defined(GLX)
377 if (cr_server.fPresentMode == CR_SERVER_REDIR_F_NONE)
378 {
379 /* the CR_SERVER_REDIR_F_FBO_BLT is set only if parent window is received, which means we are not in headles */
380 int rc = crServerSetOffscreenRenderingMode(CR_SERVER_REDIR_F_FBO | CR_SERVER_REDIR_F_DISPLAY);
381 if (!RT_SUCCESS(rc))
382 crWarning("offscreen rendering unsupported, no offscreen rendering will be used..");
383
384 }
385#endif
386 cr_server.fPresentModeDefault = cr_server.fPresentMode;
387 cr_server.fVramPresentModeDefault = CR_SERVER_REDIR_F_FBO_RAM/* | CR_SERVER_REDIR_F_FBO_RPW*/;
388
389 cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_POSITION_CR, 0, GL_INT, 2, &dims[0]);
390 cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, 0, GL_INT, 2, &dims[2]);
391
392 defaultMural->gX = dims[0];
393 defaultMural->gY = dims[1];
394 defaultMural->width = dims[2];
395 defaultMural->height = dims[3];
396
397 cr_server.mtu = 1024 * 250;
398
399 cr_server.numClients = 0;
400 strcpy(cr_server.protocol, "vboxhgcm");
401
402 for (i = 0; i < cr_server.numClients; i++)
403 {
404 CRClient *newClient = (CRClient *) crCalloc(sizeof(CRClient));
405 newClient->spu_id = 0;
406 newClient->conn = crNetAcceptClient(cr_server.protocol, NULL,
407 cr_server.tcpip_port,
408 cr_server.mtu, 0);
409 newClient->currentCtxInfo = &cr_server.MainContextInfo;
410 crServerAddToRunQueue(newClient);
411
412 cr_server.clients[i] = newClient;
413 }
414
415 /* set default client and mural */
416 if (cr_server.numClients > 0) {
417 cr_server.curClient = cr_server.clients[0];
418 cr_server.curClient->currentMural = defaultMural;
419 cr_server.client_spu_id =cr_server.clients[0]->spu_id;
420 }
421}
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