VirtualBox

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

Last change on this file since 55998 was 54905, checked in by vboxsync, 10 years ago

Host 3D: Chromium server: add Expando SPU and DLM module in order to record and save OpenGL Display Lists (currently disabled).

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