VirtualBox

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

最後變更 在這個檔案從45248是 45248,由 vboxsync 提交於 12 年 前

crOpenGL/VRDP: always show 3D window unles in Headles mode

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

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