VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_config.c@ 20175

Last change on this file since 20175 was 15532, checked in by vboxsync, 16 years ago

crOpenGL: export to OSE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.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 "renderspu.h"
8
9#include "cr_string.h"
10#include "cr_mem.h"
11#include "cr_error.h"
12#include "cr_environment.h"
13#include "cr_url.h"
14
15
16static void set_window_geometry( RenderSPU *render_spu, const char *response )
17{
18 float x, y, w, h;
19 CRASSERT(response[0] == '[');
20 sscanf( response, "[ %f, %f, %f, %f ]", &x, &y, &w, &h );
21 render_spu->defaultX = (int) x;
22 render_spu->defaultY = (int) y;
23 render_spu->defaultWidth = (int) w;
24 render_spu->defaultHeight = (int) h;
25}
26
27static void set_default_visual( RenderSPU *render_spu, const char *response )
28{
29 if (crStrlen(response) > 0) {
30 if (crStrstr(response, "rgb"))
31 render_spu->default_visual |= CR_RGB_BIT;
32 if (crStrstr(response, "alpha"))
33 render_spu->default_visual |= CR_ALPHA_BIT;
34 if (crStrstr(response, "z") || crStrstr(response, "depth"))
35 render_spu->default_visual |= CR_DEPTH_BIT;
36 if (crStrstr(response, "stencil"))
37 render_spu->default_visual |= CR_STENCIL_BIT;
38 if (crStrstr(response, "accum"))
39 render_spu->default_visual |= CR_ACCUM_BIT;
40 if (crStrstr(response, "stereo"))
41 render_spu->default_visual |= CR_STEREO_BIT;
42 if (crStrstr(response, "multisample"))
43 render_spu->default_visual |= CR_MULTISAMPLE_BIT;
44 if (crStrstr(response, "double"))
45 render_spu->default_visual |= CR_DOUBLE_BIT;
46 if (crStrstr(response, "pbuffer"))
47 render_spu->default_visual |= CR_PBUFFER_BIT;
48 }
49}
50
51static void set_display_string( RenderSPU *render_spu, const char *response )
52{
53 if (!crStrcmp(response, "DEFAULT")) {
54 const char *display = crGetenv("DISPLAY");
55 if (display)
56 crStrncpy(render_spu->display_string,
57 display,
58 sizeof(render_spu->display_string));
59 else
60 crStrcpy(render_spu->display_string, ""); /* empty string */
61 }
62 else {
63 crStrncpy(render_spu->display_string,
64 response,
65 sizeof(render_spu->display_string));
66 }
67}
68
69static void set_fullscreen( RenderSPU *render_spu, const char *response )
70{
71 sscanf( response, "%d", &(render_spu->fullscreen) );
72}
73
74static void set_on_top( RenderSPU *render_spu, const char *response )
75{
76 sscanf( response, "%d", &(render_spu->ontop) );
77}
78
79static void set_system_gl_path( RenderSPU *render_spu, const char *response )
80{
81 if (crStrlen(response) > 0)
82 crSetenv( "CR_SYSTEM_GL_PATH", response );
83}
84
85static void set_title( RenderSPU *render_spu, const char *response )
86{
87 crFree( render_spu->window_title );
88 render_spu->window_title = crStrdup( response );
89}
90
91#if defined(GLX)
92static void set_try_direct( RenderSPU *render_spu, const char *response )
93{
94 sscanf( response, "%d", &(render_spu->try_direct) );
95}
96
97static void set_force_direct( RenderSPU *render_spu, const char *response )
98{
99 sscanf( response, "%d", &(render_spu->force_direct) );
100}
101#endif /* GLX */
102
103static void render_to_app_window( RenderSPU *render_spu, const char *response )
104{
105 sscanf( response, "%d", &(render_spu->render_to_app_window) );
106}
107
108static void render_to_crut_window( RenderSPU *render_spu, const char *response )
109{
110 sscanf( response, "%d", &(render_spu->render_to_crut_window) );
111}
112
113static void resizable( RenderSPU *render_spu, const char *response )
114{
115 sscanf( response, "%d", &(render_spu->resizable) );
116}
117
118static void set_borderless( RenderSPU *render_spu, const char *response )
119{
120 sscanf( response, "%d", &(render_spu->borderless) );
121}
122
123static void set_cursor( RenderSPU *render_spu, const char *response )
124{
125 sscanf( response, "%d", &(render_spu->drawCursor) );
126}
127
128static void gather_url( RenderSPU *render_spu, const char *response )
129{
130 char protocol[4096], hostname[4096];
131 unsigned short port;
132
133 if (!crParseURL(response, protocol, hostname, &port, 0))
134 {
135 crError( "Malformed URL: \"%s\"", response );
136 }
137
138 render_spu->gather_port = port;
139}
140
141static void gather_userbuf( RenderSPU *render_spu, const char *response )
142{
143 sscanf( response, "%d", &(render_spu->gather_userbuf_size) );
144}
145
146static void set_lut8( RenderSPU *render_spu, const char *response )
147{
148 int a;
149 char **lut;
150
151 if (!response[0]) return;
152
153 lut = crStrSplit(response, ",");
154 if (!lut) return;
155
156 for (a=0; a<256; a++)
157 {
158 render_spu->lut8[0][a] = crStrToInt(lut[a]);
159 render_spu->lut8[1][a] = crStrToInt(lut[256+a]);
160 render_spu->lut8[2][a] = crStrToInt(lut[512+a]);
161 }
162
163 crFreeStrings(lut);
164
165 render_spu->use_lut8 = 1;
166}
167
168static void set_master_url ( RenderSPU *render_spu, char *response )
169{
170 if (response[0])
171 render_spu->swap_master_url = crStrdup( response );
172 else
173 render_spu->swap_master_url = NULL;
174}
175
176static void set_is_master ( RenderSPU *render_spu, char *response )
177{
178 render_spu->is_swap_master = crStrToInt( response );
179}
180
181static void set_num_clients ( RenderSPU *render_spu, char *response )
182{
183 render_spu->num_swap_clients = crStrToInt( response );
184}
185
186static void set_use_osmesa ( RenderSPU *render_spu, char *response )
187{
188 int val = crStrToInt( response );
189#ifdef USE_OSMESA
190 render_spu->use_osmesa = val;
191#else
192 if (val != 0)
193 crError( "renderspu with Conf(use_osmesa, 1) but not compiled with -DUSE_OSMESA");
194#endif
195}
196
197static void set_nv_swap_group( RenderSPU *render_spu, char *response )
198{
199 render_spu->nvSwapGroup = crStrToInt( response );
200 if (render_spu->nvSwapGroup < 0)
201 render_spu->nvSwapGroup = 0;
202}
203
204static void set_ignore_papi( RenderSPU *render_spu, char *response )
205{
206 render_spu->ignore_papi = crStrToInt( response );
207}
208
209static void set_ignore_window_moves( RenderSPU *render_spu, char *response )
210{
211 render_spu->ignore_window_moves = crStrToInt( response );
212}
213
214static void set_pbuffer_size( RenderSPU *render_spu, const char *response )
215{
216 CRASSERT(response[0] == '[');
217 sscanf( response, "[ %d, %d ]",
218 &render_spu->pbufferWidth, &render_spu->pbufferHeight);
219}
220
221static void set_use_glxchoosevisual( RenderSPU *render_spu, char *response )
222{
223 render_spu->use_glxchoosevisual = crStrToInt( response );
224}
225
226static void set_draw_bbox( RenderSPU *render_spu, char *response )
227{
228 render_spu->draw_bbox = crStrToInt( response );
229}
230
231
232
233/* option, type, nr, default, min, max, title, callback
234 */
235SPUOptions renderSPUOptions[] = {
236 { "title", CR_STRING, 1, "Chromium Render SPU", NULL, NULL,
237 "Window Title", (SPUOptionCB)set_title },
238
239 { "window_geometry", CR_INT, 4, "[0, 0, 256, 256]", "[0, 0, 1, 1]", NULL,
240 "Default Window Geometry (x,y,w,h)", (SPUOptionCB)set_window_geometry },
241
242 { "fullscreen", CR_BOOL, 1, "0", NULL, NULL,
243 "Full-screen Window", (SPUOptionCB)set_fullscreen },
244
245 { "resizable", CR_BOOL, 1, "0", NULL, NULL,
246 "Resizable Window", (SPUOptionCB)resizable },
247
248 { "on_top", CR_BOOL, 1, "0", NULL, NULL,
249 "Display on Top", (SPUOptionCB)set_on_top },
250
251 { "borderless", CR_BOOL, 1, "0", NULL, NULL,
252 "Borderless Window", (SPUOptionCB) set_borderless },
253
254 { "default_visual", CR_STRING, 1, "rgb, double, depth", NULL, NULL,
255 "Default GL Visual", (SPUOptionCB) set_default_visual },
256
257#if defined(GLX)
258 { "try_direct", CR_BOOL, 1, "1", NULL, NULL,
259 "Try Direct Rendering", (SPUOptionCB)set_try_direct },
260
261 { "force_direct", CR_BOOL, 1, "0", NULL, NULL,
262 "Force Direct Rendering", (SPUOptionCB)set_force_direct },
263#endif
264
265 { "render_to_app_window", CR_BOOL, 1, "0", NULL, NULL,
266 "Render to Application window", (SPUOptionCB)render_to_app_window },
267
268 { "render_to_crut_window", CR_BOOL, 1, "0", NULL, NULL,
269 "Render to CRUT window", (SPUOptionCB)render_to_crut_window },
270
271 { "show_cursor", CR_BOOL, 1, "0", NULL, NULL,
272 "Show Software Cursor", (SPUOptionCB) set_cursor },
273
274 { "system_gl_path", CR_STRING, 1, "", NULL, NULL,
275 "System GL Path", (SPUOptionCB)set_system_gl_path },
276
277 { "display_string", CR_STRING, 1, "DEFAULT", NULL, NULL,
278 "X Display String", (SPUOptionCB)set_display_string },
279
280 { "gather_url", CR_STRING, 1, "", NULL, NULL,
281 "Gatherer URL", (SPUOptionCB)gather_url},
282
283 { "gather_userbuf_size", CR_INT, 1, "0", NULL, NULL,
284 "Size of Buffer to Allocate for Gathering", (SPUOptionCB)gather_userbuf},
285
286 { "lut8", CR_STRING, 1, "", NULL, NULL,
287 "8 bit RGB LUT", (SPUOptionCB)set_lut8},
288
289 { "swap_master_url", CR_STRING, 1, "", NULL, NULL,
290 "The URL to the master swapper", (SPUOptionCB)set_master_url },
291
292 { "is_swap_master", CR_BOOL, 1, "0", NULL, NULL,
293 "Is this the swap master", (SPUOptionCB)set_is_master },
294
295 { "num_swap_clients", CR_INT, 1, "1", NULL, NULL,
296 "How many swaps to wait on", (SPUOptionCB)set_num_clients },
297
298 { "use_osmesa", CR_BOOL, 1, "0", NULL, NULL,
299 "Use offscreen rendering with Mesa", (SPUOptionCB)set_use_osmesa },
300
301 { "nv_swap_group", CR_INT, 1, "0", NULL, NULL,
302 "NVIDIA Swap Group Number", (SPUOptionCB) set_nv_swap_group },
303
304 { "ignore_papi", CR_BOOL, 1, "0", NULL, NULL,
305 "Ignore Barrier and Semaphore calls", (SPUOptionCB) set_ignore_papi },
306
307 { "ignore_window_moves", CR_BOOL, 1, "0", NULL, NULL,
308 "Ignore crWindowPosition calls", (SPUOptionCB) set_ignore_window_moves },
309
310 { "pbuffer_size", CR_INT, 2, "[0, 0]", "[0, 0]", NULL,
311 "Maximum PBuffer Size", (SPUOptionCB) set_pbuffer_size },
312
313 { "use_glxchoosevisual", CR_BOOL, 1, "1", NULL, NULL,
314 "Use glXChooseVisual", (SPUOptionCB) set_use_glxchoosevisual },
315
316 { "draw_bbox", CR_BOOL, 1, "0", NULL, NULL,
317 "Draw Bounding Boxes", (SPUOptionCB) set_draw_bbox },
318 { NULL, CR_BOOL, 0, NULL, NULL, NULL, NULL, NULL },
319};
320
321
322void renderspuSetVBoxConfiguration( RenderSPU *render_spu )
323{
324 CRConnection *conn;
325 int a;
326
327 for (a=0; a<256; a++)
328 {
329 render_spu->lut8[0][a] =
330 render_spu->lut8[1][a] =
331 render_spu->lut8[2][a] = a;
332 }
333 render_spu->use_lut8 = 0;
334
335 set_title(render_spu, "Chromium Render SPU");
336 set_window_geometry(render_spu, "[0, 0, 0, 0]");
337 set_fullscreen(render_spu, "0");
338 resizable(render_spu, "0");
339 set_on_top(render_spu, "1");
340 set_borderless(render_spu, "1");
341 set_default_visual(render_spu, "rgb, double, depth");
342#if defined(GLX)
343 set_try_direct(render_spu, "1");
344 set_force_direct(render_spu, "0");
345#endif
346 render_to_app_window(render_spu, "0");
347 render_to_crut_window(render_spu, "0");
348 set_cursor(render_spu, "0");
349 set_system_gl_path(render_spu, "");
350 set_display_string(render_spu, "DEFAULT");
351 gather_url(render_spu, "");
352 gather_userbuf(render_spu, "0");
353 set_lut8(render_spu, "");
354 set_master_url(render_spu, "");
355 set_is_master(render_spu, "0");
356 set_num_clients(render_spu, "1");
357 set_use_osmesa(render_spu, "0");
358 set_nv_swap_group(render_spu, "0");
359 set_ignore_papi(render_spu, "0");
360 set_ignore_window_moves(render_spu, "0");
361 set_pbuffer_size(render_spu, "[0, 0]");
362 set_use_glxchoosevisual(render_spu, "1");
363 set_draw_bbox(render_spu, "0");
364
365 render_spu->swap_mtu = 1024 * 500;
366
367 /* Some initialization that doesn't really have anything to do
368 * with configuration but which was done here before:
369 */
370 render_spu->use_L2 = 0;
371 render_spu->cursorX = 0;
372 render_spu->cursorY = 0;
373#if defined(GLX)
374 render_spu->sync = 0;
375#endif
376}
377
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