VirtualBox

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

Last change on this file since 44444 was 44290, checked in by vboxsync, 12 years ago

crOpenGL: saved state fixes & improvements

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.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.bForceOffscreenRendering = CR_SERVER_REDIR_NONE;
55 cr_server.bOffscreenRenderingDefault = cr_server.bForceOffscreenRendering;
56 cr_server.bUsePBOForReadback = GL_FALSE;
57 cr_server.bUseOutputRedirect = GL_FALSE;
58}
59
60void 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 //spu_dir = crStrdup(response);
114 crNetSetRank(0);
115 crNetSetContextRange(32, 35);
116 crNetSetNodeRange("iam0", "iamvis20");
117 crNetSetKey(key,sizeof(key));
118 crNetSetKey(key,sizeof(key));
119 cr_server.tcpip_port = 7000;
120
121 /*cr_server.optimizeBucket = crStrToInt(response);
122 cr_server.localTileSpec = crStrToInt(response);
123 cr_server.useL2 = crStrToInt(response);
124 cr_server.ignore_papi = crStrToInt(response);
125 if (crMothershipGetServerParam(conn, response, "overlap_blending"))
126 {
127 if (!crStrcmp(response, "blend"))
128 cr_server.overlapBlending = 1;
129 else if (!crStrcmp(response, "knockout"))
130 cr_server.overlapBlending = 2;
131 }
132 if (crMothershipGetServerParam(conn, response, "overlap_levels"))
133 cr_server.only_swap_once = crStrToInt(response);
134 cr_server.debug_barriers = crStrToInt(response);
135 cr_server.sharedDisplayLists = crStrToInt(response);
136 cr_server.sharedTextureObjects = crStrToInt(response);
137 cr_server.sharedPrograms = crStrToInt(response);
138 cr_server.sharedWindows = crStrToInt(response);
139 cr_server.uniqueWindows = crStrToInt(response);
140 cr_server.useDMX = crStrToInt(response);
141 if (crMothershipGetServerParam(conn, response, "vertprog_projection_param"))
142 if (crMothershipGetServerParam(conn, response, "stereo_view"))
143 if (crMothershipGetServerParam(conn, response, "view_matrix"))
144 if (crMothershipGetServerParam(conn, response, "right_view_matrix"))
145 if (crMothershipGetServerParam(conn, response, "projection_matrix"))
146 if (crMothershipGetServerParam(conn, response, "right_projection_matrix"))*/
147
148 crDebug("CRServer: my port number is %d", cr_server.tcpip_port);
149
150 /*
151 * Load the SPUs
152 */
153 cr_server.head_spu =
154 crSPULoadChain(num_spus, spu_ids, spu_names, spu_dir, &cr_server);
155
156 env = crGetenv( "CR_SERVER_DEFAULT_RENDER_TYPE" );
157 if (env != NULL)
158 {
159 GLubyte redir = (env[0] - 0x30);
160 if (redir <= CR_SERVER_REDIR_MAXVAL)
161 {
162 int rc = crServerSetOffscreenRenderingMode(redir);
163 if (!RT_SUCCESS(rc))
164 crWarning("offscreen rendering unsupported, no offscreen rendering will be used..");
165 }
166 else
167 crWarning("invalid redir option %c", redir);
168 }
169 cr_server.bOffscreenRenderingDefault = cr_server.bForceOffscreenRendering;
170
171 /* Need to do this as early as possible */
172
173 cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_POSITION_CR, 0, GL_INT, 2, &dims[0]);
174 cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, 0, GL_INT, 2, &dims[2]);
175
176 defaultMural->gX = dims[0];
177 defaultMural->gY = dims[1];
178 defaultMural->width = dims[2];
179 defaultMural->height = dims[3];
180
181 crFree(spu_ids);
182 crFreeStrings(spu_names);
183 crFreeStrings(spuchain);
184 if (spu_dir)
185 crFree(spu_dir);
186
187 cr_server.mtu = 1024 * 30;
188
189 /*
190 * Get a list of all the clients talking to me.
191 */
192 if (cr_server.vncMode) {
193 /* we're inside a vnc viewer */
194 /*if (!crMothershipSendString( conn, response, "getvncclient %s", hostname ))
195 crError( "Bad Mothership response: %s", response );*/
196 }
197 else {
198 //crMothershipGetClients(conn, response);
199 strcpy(response, "1 tcpip 1");
200 }
201
202 crDebug("CRServer: my clients: %s", response);
203
204 /*
205 * 'response' will now contain a number indicating the number of clients
206 * of this server, followed by a comma-separated list of protocol/SPU ID
207 * pairs.
208 * Example: "3 tcpip 1,gm 2,via 10"
209 */
210 clientchain = crStrSplitn(response, " ", 1);
211 cr_server.numClients = crStrToInt(clientchain[0]);
212 if (cr_server.numClients == 0)
213 {
214 crError("I have no clients! What's a poor server to do?");
215 }
216 clientlist = crStrSplit(clientchain[1], ",");
217
218 /*
219 * Connect to initial set of clients.
220 * Call crNetAcceptClient() for each client.
221 * Also, look for a client that's _not_ using the file: protocol.
222 */
223 for (i = 0; i < cr_server.numClients; i++)
224 {
225 CRClient *newClient = (CRClient *) crCalloc(sizeof(CRClient));
226#ifdef VBOX
227 sscanf(clientlist[i], "%1023s %d", cr_server.protocol, &(newClient->spu_id));
228#else
229 sscanf(clientlist[i], "%s %d", cr_server.protocol, &(newClient->spu_id));
230#endif
231 newClient->conn = crNetAcceptClient(cr_server.protocol, NULL,
232 cr_server.tcpip_port,
233 cr_server.mtu, 0);
234 newClient->currentCtxInfo = &cr_server.MainContextInfo;
235 crServerAddToRunQueue(newClient);
236
237 cr_server.clients[i] = newClient;
238 }
239
240 /* set default client and mural */
241 if (cr_server.numClients > 0) {
242 cr_server.curClient = cr_server.clients[0];
243 cr_server.curClient->currentMural = defaultMural;
244 cr_server.client_spu_id =cr_server.clients[0]->spu_id;
245 }
246
247 crFreeStrings(clientchain);
248 crFreeStrings(clientlist);
249
250 /* Ask the mothership for the tile info */
251 //crServerGetTileInfoFromMothership(conn, defaultMural);
252
253 if (cr_server.vncMode) {
254 /* In vnc mode, we reset the mothership configuration so that it can be
255 * used by subsequent OpenGL apps without having to spawn a new mothership
256 * on a new port.
257 */
258 crDebug("CRServer: Resetting mothership to initial state");
259 //crMothershipReset(conn);
260 }
261
262 //crMothershipDisconnect(conn);
263}
264
265void crServerSetVBoxConfigurationHGCM()
266{
267 CRMuralInfo *defaultMural;
268
269 int spu_ids[1] = {0};
270 char *spu_names[1] = {"render"};
271 char *spu_dir = NULL;
272 int i;
273 GLint dims[4];
274 const char * env;
275
276 defaultMural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, 0);
277 CRASSERT(defaultMural);
278
279 //@todo should be moved to addclient so we have a chain for each client
280
281 setDefaults();
282
283 /* Load the SPUs */
284 cr_server.head_spu = crSPULoadChain(1, spu_ids, spu_names, spu_dir, &cr_server);
285
286 if (!cr_server.head_spu)
287 return;
288
289 env = crGetenv( "CR_SERVER_DEFAULT_RENDER_TYPE" );
290 if (env != NULL)
291 {
292 GLubyte redir = (env[0] - 0x30);
293 if (redir <= CR_SERVER_REDIR_MAXVAL)
294 {
295 int rc = crServerSetOffscreenRenderingMode(redir);
296 if (!RT_SUCCESS(rc))
297 crWarning("offscreen rendering unsupported, no offscreen rendering will be used..");
298 }
299 else
300 crWarning("invalid redir option %c", redir);
301 }
302 cr_server.bOffscreenRenderingDefault = cr_server.bForceOffscreenRendering;
303
304 cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_POSITION_CR, 0, GL_INT, 2, &dims[0]);
305 cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, 0, GL_INT, 2, &dims[2]);
306
307 defaultMural->gX = dims[0];
308 defaultMural->gY = dims[1];
309 defaultMural->width = dims[2];
310 defaultMural->height = dims[3];
311
312 cr_server.mtu = 1024 * 250;
313
314 cr_server.numClients = 0;
315 strcpy(cr_server.protocol, "vboxhgcm");
316
317 for (i = 0; i < cr_server.numClients; i++)
318 {
319 CRClient *newClient = (CRClient *) crCalloc(sizeof(CRClient));
320 newClient->spu_id = 0;
321 newClient->conn = crNetAcceptClient(cr_server.protocol, NULL,
322 cr_server.tcpip_port,
323 cr_server.mtu, 0);
324 newClient->currentCtxInfo = &cr_server.MainContextInfo;
325 crServerAddToRunQueue(newClient);
326
327 cr_server.clients[i] = newClient;
328 }
329
330 /* set default client and mural */
331 if (cr_server.numClients > 0) {
332 cr_server.curClient = cr_server.clients[0];
333 cr_server.curClient->currentMural = defaultMural;
334 cr_server.client_spu_id =cr_server.clients[0]->spu_id;
335 }
336}
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