VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/spu_loader/choosevisual.c@ 78263

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

Config.kmk,GuestHost\OpenGL,HostServices\SharedOpenGL: Fix a bunch of compiler warnings and enable them again

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id Revision
檔案大小: 7.6 KB
 
1
2#include "chromium.h"
3#include "cr_spu.h"
4#include "cr_error.h"
5#include "cr_string.h"
6
7
8/**
9 * Wrappers for glXChooseVisual/etc.
10 *
11 * By using this function, the fake GLX, render SPU, tilesort SPU,
12 * etc can be assured of getting the same GLX visual for a set of CR_*_BIT
13 * visual flags. This helps ensure that render_to_app_window will work
14 * properly.
15 */
16
17
18#if defined(WINDOWS)
19int
20crChooseVisual(const crOpenGLInterface *ws, int visBits)
21{
22 /* placeholder */
23 RT_NOREF(ws, visBits);
24 return 0;
25}
26#endif
27
28
29#if defined(DARWIN)
30int
31crChooseVisual(const crOpenGLInterface *ws, int visBits)
32{
33 /* placeholder */
34 return 0;
35}
36#endif
37
38
39#if defined(GLX)
40
41XVisualInfo *
42crChooseVisual(const crOpenGLInterface *ws, Display *dpy, int screen,
43 GLboolean directColor, int visBits)
44{
45 XVisualInfo *vis;
46 int errorBase, eventBase;
47
48 if (ws->glXQueryExtension(dpy, &errorBase, &eventBase))
49 {
50
51 if (ws->glXChooseVisual)
52 {
53 /* Use the real OpenGL's glXChooseVisual function */
54 int attribList[100];
55 int i = 0;
56
57 /* Build the attribute list */
58 if (visBits & CR_RGB_BIT)
59 {
60 attribList[i++] = GLX_RGBA;
61 attribList[i++] = GLX_RED_SIZE;
62 attribList[i++] = 1;
63 attribList[i++] = GLX_GREEN_SIZE;
64 attribList[i++] = 1;
65 attribList[i++] = GLX_BLUE_SIZE;
66 attribList[i++] = 1;
67 }
68
69 if (visBits & CR_ALPHA_BIT)
70 {
71 attribList[i++] = GLX_ALPHA_SIZE;
72 attribList[i++] = 1;
73 }
74
75 if (visBits & CR_DOUBLE_BIT)
76 {
77 attribList[i++] = GLX_DOUBLEBUFFER;
78 }
79
80 if (visBits & CR_STEREO_BIT)
81 {
82 attribList[i++] = GLX_STEREO;
83 }
84
85 if (visBits & CR_DEPTH_BIT)
86 {
87 attribList[i++] = GLX_DEPTH_SIZE;
88 attribList[i++] = 1;
89 }
90
91 if (visBits & CR_STENCIL_BIT)
92 {
93 attribList[i++] = GLX_STENCIL_SIZE;
94 attribList[i++] = 1;
95 }
96
97 if (visBits & CR_ACCUM_BIT)
98 {
99 attribList[i++] = GLX_ACCUM_RED_SIZE;
100 attribList[i++] = 1;
101 attribList[i++] = GLX_ACCUM_GREEN_SIZE;
102 attribList[i++] = 1;
103 attribList[i++] = GLX_ACCUM_BLUE_SIZE;
104 attribList[i++] = 1;
105 if (visBits & CR_ALPHA_BIT)
106 {
107 attribList[i++] = GLX_ACCUM_ALPHA_SIZE;
108 attribList[i++] = 1;
109 }
110 }
111
112 if (visBits & CR_MULTISAMPLE_BIT)
113 {
114 attribList[i++] = GLX_SAMPLE_BUFFERS_SGIS;
115 attribList[i++] = 1;
116 attribList[i++] = GLX_SAMPLES_SGIS;
117 attribList[i++] = 4;
118 }
119
120 if (visBits & CR_OVERLAY_BIT)
121 {
122 attribList[i++] = GLX_LEVEL;
123 attribList[i++] = 1;
124 }
125
126 if (directColor)
127 {
128 /*
129 * See if we have have GLX_EXT_visual_info so we
130 * can grab a Direct Color visual
131 */
132#ifdef GLX_EXT_visual_info
133 if (crStrstr(ws->glXQueryExtensionsString(dpy, screen),
134 "GLX_EXT_visual_info"))
135 {
136 attribList[i++] = GLX_X_VISUAL_TYPE_EXT;
137 attribList[i++] = GLX_DIRECT_COLOR_EXT;
138 }
139#endif
140 }
141
142 /* End the list */
143 attribList[i++] = None;
144
145 vis = ws->glXChooseVisual(dpy, screen, attribList);
146 return vis;
147 }
148 else
149 {
150 /* Don't use glXChooseVisual, use glXGetConfig.
151 *
152 * Here's the deal:
153 * Some (all?) versions of the libGL.so that's shipped with ATI's
154 * drivers aren't built with the -Bsymbolic flag. That's bad.
155 *
156 * If we call the glXChooseVisual() function that's built into ATI's
157 * libGL, it in turn calls the glXGetConfig() function. Now, there's
158 * a glXGetConfig function in libGL.so **AND** there's a glXGetConfig
159 * function in Chromium's libcrfaker.so library. Unfortunately, the
160 * later one gets called instead of the former. At this point, things
161 * go haywire. If -Bsymbolic were used, this would not happen.
162 */
163 XVisualInfo templateVis;
164 long templateFlags;
165 int count, i, visType;
166
167 visType = directColor ? DirectColor : TrueColor;
168
169 /* Get list of candidate visuals */
170 templateFlags = VisualScreenMask | VisualClassMask;
171 templateVis.screen = screen;
172#if defined(__cplusplus) || defined(c_plusplus)
173 templateVis.c_class = visType;
174#else
175 templateVis.class = visType;
176#endif
177
178 vis = XGetVisualInfo(dpy, templateFlags, &templateVis, &count);
179 /* find first visual that's good enough */
180 for (i = 0; i < count; i++)
181 {
182 int val;
183
184 /* Need exact match on RGB, DOUBLEBUFFER, STEREO, LEVEL, MULTISAMPLE */
185 ws->glXGetConfig(dpy, vis + i, GLX_RGBA, &val);
186 if (((visBits & CR_RGB_BIT) && !val) ||
187 (((visBits & CR_RGB_BIT) == 0) && val))
188 {
189 continue;
190 }
191
192 ws->glXGetConfig(dpy, vis + i, GLX_DOUBLEBUFFER, &val);
193 if (((visBits & CR_DOUBLE_BIT) && !val) ||
194 (((visBits & CR_DOUBLE_BIT) == 0) && val))
195 {
196 continue;
197 }
198
199 ws->glXGetConfig(dpy, vis + i, GLX_STEREO, &val);
200 if (((visBits & CR_STEREO_BIT) && !val) ||
201 (((visBits & CR_STEREO_BIT) == 0) && val))
202 {
203 continue;
204 }
205
206 ws->glXGetConfig(dpy, vis + i, GLX_LEVEL, &val);
207 if (((visBits & CR_OVERLAY_BIT) && !val) ||
208 (((visBits & CR_OVERLAY_BIT) == 0) && val))
209 {
210 continue;
211 }
212
213 ws->glXGetConfig(dpy, vis + i, GLX_SAMPLE_BUFFERS_SGIS, &val);
214 if (visBits & CR_MULTISAMPLE_BIT)
215 {
216 if (!val)
217 continue;
218 ws->glXGetConfig(dpy, vis + i, GLX_SAMPLES_SGIS, &val);
219 if (val < 4)
220 continue;
221 }
222 else {
223 /* don't want multisample */
224 if (val)
225 continue;
226 }
227
228 /* Need good enough for ALPHA, DEPTH, STENCIL, ACCUM */
229 if (visBits & CR_ALPHA_BIT)
230 {
231 ws->glXGetConfig(dpy, vis + i, GLX_ALPHA_SIZE, &val);
232 if (!val)
233 continue;
234 }
235
236 if (visBits & CR_DEPTH_BIT)
237 {
238 ws->glXGetConfig(dpy, vis + i, GLX_DEPTH_SIZE, &val);
239 if (!val)
240 continue;
241 }
242
243 if (visBits & CR_STENCIL_BIT)
244 {
245 ws->glXGetConfig(dpy, vis + i, GLX_STENCIL_SIZE, &val);
246 if (!val)
247 continue;
248 }
249
250 if (visBits & CR_ACCUM_BIT)
251 {
252 ws->glXGetConfig(dpy, vis + i, GLX_ACCUM_RED_SIZE, &val);
253 if (!val)
254 continue;
255 if (visBits & CR_ALPHA_BIT)
256 {
257 ws->glXGetConfig(dpy, vis + i, GLX_ACCUM_ALPHA_SIZE, &val);
258 if (!val)
259 continue;
260 }
261 }
262
263 /* If we get here, we found a good visual.
264 * Now, we need to get a new XVisualInfo pointer in case the caller
265 * calls XFree on it.
266 */
267 templateFlags = VisualScreenMask | VisualIDMask;
268 templateVis.screen = screen;
269 templateVis.visualid = vis[i].visual->visualid;
270 XFree(vis); /* free the list */
271 vis = XGetVisualInfo(dpy, templateFlags, &templateVis, &count);
272 return vis;
273 }
274
275 /* if we get here, we failed to find a sufficient visual */
276 return NULL;
277 }
278 }
279 else
280 {
281 /* use Xlib instead of GLX */
282 XVisualInfo templateVis, *best;
283 long templateFlags;
284 int i, count, visType;
285
286 if (visBits & CR_RGB_BIT)
287 visType = directColor ? DirectColor : TrueColor;
288 else
289 visType = PseudoColor;
290
291 /* Get list of candidate visuals */
292 templateFlags = VisualScreenMask | VisualClassMask;
293 templateVis.screen = screen;
294#if defined(__cplusplus) || defined(c_plusplus)
295 templateVis.c_class = visType;
296#else
297 templateVis.class = visType;
298#endif
299
300 vis = XGetVisualInfo(dpy, templateFlags, &templateVis, &count);
301 if (!vis)
302 return NULL;
303
304 /* okay, select the RGB visual with the most depth */
305 best = vis + 0;
306 for (i = 1; i < count; i++)
307 {
308 if (vis[i].depth > best->depth &&
309 vis[i].bits_per_rgb > best->bits_per_rgb )
310 best = vis + i;
311 }
312
313 if (best)
314 {
315 /* If we get here, we found a good visual.
316 * Now, we need to get a new XVisualInfo pointer in case the caller
317 * calls XFree on it.
318 */
319 templateFlags = VisualScreenMask | VisualIDMask;
320 templateVis.screen = screen;
321 templateVis.visualid = best->visualid;
322 XFree(vis); /* free the list */
323 best = XGetVisualInfo(dpy, templateFlags, &templateVis, &count);
324 }
325
326 return best;
327 }
328}
329
330#endif /* GLX */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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