7cf8f4d55143c7f1a68f9fa40863c45bf4249b65
[mesa.git] / src / egl / drivers / glx / egl_glx.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5 * Copyright 2010-2011 LunarG, Inc.
6 * All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 *
28 **************************************************************************/
29
30
31 /**
32 * This is an EGL driver that wraps GLX. This gives the benefit of being
33 * completely agnostic of the direct rendering implementation.
34 *
35 * Authors: Alan Hourihane <alanh@tungstengraphics.com>
36 */
37
38 #include <stdlib.h>
39 #include <string.h>
40 #include <X11/Xlib.h>
41 #include <dlfcn.h>
42 #include "GL/glx.h"
43
44 #include "eglconfig.h"
45 #include "eglcontext.h"
46 #include "egldefines.h"
47 #include "egldisplay.h"
48 #include "egldriver.h"
49 #include "eglcurrent.h"
50 #include "egllog.h"
51 #include "eglsurface.h"
52
53 #define CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))
54
55 #ifndef GLX_VERSION_1_4
56 #error "GL/glx.h must be equal to or greater than GLX 1.4"
57 #endif
58
59 /* GLX 1.0 */
60 typedef GLXContext (*GLXCREATECONTEXTPROC)( Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct );
61 typedef void (*GLXDESTROYCONTEXTPROC)( Display *dpy, GLXContext ctx );
62 typedef Bool (*GLXMAKECURRENTPROC)( Display *dpy, GLXDrawable drawable, GLXContext ctx);
63 typedef void (*GLXSWAPBUFFERSPROC)( Display *dpy, GLXDrawable drawable );
64 typedef GLXPixmap (*GLXCREATEGLXPIXMAPPROC)( Display *dpy, XVisualInfo *visual, Pixmap pixmap );
65 typedef void (*GLXDESTROYGLXPIXMAPPROC)( Display *dpy, GLXPixmap pixmap );
66 typedef Bool (*GLXQUERYVERSIONPROC)( Display *dpy, int *maj, int *min );
67 typedef int (*GLXGETCONFIGPROC)( Display *dpy, XVisualInfo *visual, int attrib, int *value );
68 typedef void (*GLXWAITGLPROC)( void );
69 typedef void (*GLXWAITXPROC)( void );
70
71 /* GLX 1.1 */
72 typedef const char *(*GLXQUERYEXTENSIONSSTRINGPROC)( Display *dpy, int screen );
73 typedef const char *(*GLXQUERYSERVERSTRINGPROC)( Display *dpy, int screen, int name );
74 typedef const char *(*GLXGETCLIENTSTRINGPROC)( Display *dpy, int name );
75
76 /** subclass of _EGLDriver */
77 struct GLX_egl_driver
78 {
79 _EGLDriver Base; /**< base class */
80
81 void *handle;
82
83 /* GLX 1.0 */
84 GLXCREATECONTEXTPROC glXCreateContext;
85 GLXDESTROYCONTEXTPROC glXDestroyContext;
86 GLXMAKECURRENTPROC glXMakeCurrent;
87 GLXSWAPBUFFERSPROC glXSwapBuffers;
88 GLXCREATEGLXPIXMAPPROC glXCreateGLXPixmap;
89 GLXDESTROYGLXPIXMAPPROC glXDestroyGLXPixmap;
90 GLXQUERYVERSIONPROC glXQueryVersion;
91 GLXGETCONFIGPROC glXGetConfig;
92 GLXWAITGLPROC glXWaitGL;
93 GLXWAITXPROC glXWaitX;
94
95 /* GLX 1.1 */
96 GLXQUERYEXTENSIONSSTRINGPROC glXQueryExtensionsString;
97 GLXQUERYSERVERSTRINGPROC glXQueryServerString;
98 GLXGETCLIENTSTRINGPROC glXGetClientString;
99
100 /* GLX 1.3 or (GLX_SGI_make_current_read and GLX_SGIX_fbconfig) */
101 PFNGLXGETFBCONFIGSPROC glXGetFBConfigs;
102 PFNGLXGETFBCONFIGATTRIBPROC glXGetFBConfigAttrib;
103 PFNGLXGETVISUALFROMFBCONFIGPROC glXGetVisualFromFBConfig;
104 PFNGLXCREATEWINDOWPROC glXCreateWindow;
105 PFNGLXDESTROYWINDOWPROC glXDestroyWindow;
106 PFNGLXCREATEPIXMAPPROC glXCreatePixmap;
107 PFNGLXDESTROYPIXMAPPROC glXDestroyPixmap;
108 PFNGLXCREATEPBUFFERPROC glXCreatePbuffer;
109 PFNGLXDESTROYPBUFFERPROC glXDestroyPbuffer;
110 PFNGLXCREATENEWCONTEXTPROC glXCreateNewContext;
111 PFNGLXMAKECONTEXTCURRENTPROC glXMakeContextCurrent;
112
113 /* GLX 1.4 or GLX_ARB_get_proc_address */
114 PFNGLXGETPROCADDRESSPROC glXGetProcAddress;
115
116 /* GLX_SGIX_pbuffer */
117 PFNGLXCREATEGLXPBUFFERSGIXPROC glXCreateGLXPbufferSGIX;
118 PFNGLXDESTROYGLXPBUFFERSGIXPROC glXDestroyGLXPbufferSGIX;
119 };
120
121
122 /** driver data of _EGLDisplay */
123 struct GLX_egl_display
124 {
125 Display *dpy;
126 XVisualInfo *visuals;
127 GLXFBConfig *fbconfigs;
128
129 int glx_maj, glx_min;
130
131 const char *extensions;
132 EGLBoolean have_1_3;
133 EGLBoolean have_make_current_read;
134 EGLBoolean have_fbconfig;
135 EGLBoolean have_pbuffer;
136
137 /* workaround quirks of different GLX implementations */
138 EGLBoolean single_buffered_quirk;
139 EGLBoolean glx_window_quirk;
140 };
141
142
143 /** subclass of _EGLContext */
144 struct GLX_egl_context
145 {
146 _EGLContext Base; /**< base class */
147
148 GLXContext context;
149 };
150
151
152 /** subclass of _EGLSurface */
153 struct GLX_egl_surface
154 {
155 _EGLSurface Base; /**< base class */
156
157 Drawable drawable;
158 GLXDrawable glx_drawable;
159
160 void (*destroy)(Display *, GLXDrawable);
161 };
162
163
164 /** subclass of _EGLConfig */
165 struct GLX_egl_config
166 {
167 _EGLConfig Base; /**< base class */
168 EGLBoolean double_buffered;
169 int index;
170 };
171
172 /* standard typecasts */
173 _EGL_DRIVER_STANDARD_TYPECASTS(GLX_egl)
174
175 static int
176 GLX_egl_config_index(_EGLConfig *conf)
177 {
178 struct GLX_egl_config *GLX_conf = GLX_egl_config(conf);
179 return GLX_conf->index;
180 }
181
182
183 static const struct {
184 int attr;
185 int egl_attr;
186 } fbconfig_attributes[] = {
187 /* table 3.1 of GLX 1.4 */
188 { GLX_FBCONFIG_ID, 0 },
189 { GLX_BUFFER_SIZE, EGL_BUFFER_SIZE },
190 { GLX_LEVEL, EGL_LEVEL },
191 { GLX_DOUBLEBUFFER, 0 },
192 { GLX_STEREO, 0 },
193 { GLX_AUX_BUFFERS, 0 },
194 { GLX_RED_SIZE, EGL_RED_SIZE },
195 { GLX_GREEN_SIZE, EGL_GREEN_SIZE },
196 { GLX_BLUE_SIZE, EGL_BLUE_SIZE },
197 { GLX_ALPHA_SIZE, EGL_ALPHA_SIZE },
198 { GLX_DEPTH_SIZE, EGL_DEPTH_SIZE },
199 { GLX_STENCIL_SIZE, EGL_STENCIL_SIZE },
200 { GLX_ACCUM_RED_SIZE, 0 },
201 { GLX_ACCUM_GREEN_SIZE, 0 },
202 { GLX_ACCUM_BLUE_SIZE, 0 },
203 { GLX_ACCUM_ALPHA_SIZE, 0 },
204 { GLX_SAMPLE_BUFFERS, EGL_SAMPLE_BUFFERS },
205 { GLX_SAMPLES, EGL_SAMPLES },
206 { GLX_RENDER_TYPE, 0 },
207 { GLX_DRAWABLE_TYPE, EGL_SURFACE_TYPE },
208 { GLX_X_RENDERABLE, EGL_NATIVE_RENDERABLE },
209 { GLX_X_VISUAL_TYPE, EGL_NATIVE_VISUAL_TYPE },
210 { GLX_CONFIG_CAVEAT, EGL_CONFIG_CAVEAT },
211 { GLX_TRANSPARENT_TYPE, EGL_TRANSPARENT_TYPE },
212 { GLX_TRANSPARENT_INDEX_VALUE, 0 },
213 { GLX_TRANSPARENT_RED_VALUE, EGL_TRANSPARENT_RED_VALUE },
214 { GLX_TRANSPARENT_GREEN_VALUE, EGL_TRANSPARENT_GREEN_VALUE },
215 { GLX_TRANSPARENT_BLUE_VALUE, EGL_TRANSPARENT_BLUE_VALUE },
216 { GLX_MAX_PBUFFER_WIDTH, EGL_MAX_PBUFFER_WIDTH },
217 { GLX_MAX_PBUFFER_HEIGHT, EGL_MAX_PBUFFER_HEIGHT },
218 { GLX_MAX_PBUFFER_PIXELS, EGL_MAX_PBUFFER_PIXELS },
219 { GLX_VISUAL_ID, EGL_NATIVE_VISUAL_ID }
220 };
221
222
223 static EGLBoolean
224 convert_fbconfig(struct GLX_egl_driver *GLX_drv,
225 struct GLX_egl_display *GLX_dpy, GLXFBConfig fbconfig,
226 struct GLX_egl_config *GLX_conf)
227 {
228 Display *dpy = GLX_dpy->dpy;
229 int err, attr, val;
230 unsigned i;
231
232 /* must have rgba bit */
233 err = GLX_drv->glXGetFBConfigAttrib(dpy, fbconfig, GLX_RENDER_TYPE, &val);
234 if (err || !(val & GLX_RGBA_BIT))
235 return EGL_FALSE;
236
237 /* must know whether it is double-buffered */
238 err = GLX_drv->glXGetFBConfigAttrib(dpy, fbconfig, GLX_DOUBLEBUFFER, &val);
239 if (err)
240 return EGL_FALSE;
241 GLX_conf->double_buffered = val;
242
243 GLX_conf->Base.RenderableType = EGL_OPENGL_BIT;
244 GLX_conf->Base.Conformant = EGL_OPENGL_BIT;
245
246 for (i = 0; i < ARRAY_SIZE(fbconfig_attributes); i++) {
247 EGLint egl_attr, egl_val;
248
249 attr = fbconfig_attributes[i].attr;
250 egl_attr = fbconfig_attributes[i].egl_attr;
251 if (!egl_attr)
252 continue;
253
254 err = GLX_drv->glXGetFBConfigAttrib(dpy, fbconfig, attr, &val);
255 if (err) {
256 if (err == GLX_BAD_ATTRIBUTE) {
257 err = 0;
258 continue;
259 }
260 break;
261 }
262
263 switch (egl_attr) {
264 case EGL_SURFACE_TYPE:
265 egl_val = 0;
266 if (val & GLX_WINDOW_BIT)
267 egl_val |= EGL_WINDOW_BIT;
268 /* pixmap and pbuffer surfaces must be single-buffered in EGL */
269 if (!GLX_conf->double_buffered) {
270 if (val & GLX_PIXMAP_BIT)
271 egl_val |= EGL_PIXMAP_BIT;
272 if (val & GLX_PBUFFER_BIT)
273 egl_val |= EGL_PBUFFER_BIT;
274 }
275 break;
276 case EGL_NATIVE_VISUAL_TYPE:
277 switch (val) {
278 case GLX_TRUE_COLOR:
279 egl_val = TrueColor;
280 break;
281 case GLX_DIRECT_COLOR:
282 egl_val = DirectColor;
283 break;
284 case GLX_PSEUDO_COLOR:
285 egl_val = PseudoColor;
286 break;
287 case GLX_STATIC_COLOR:
288 egl_val = StaticColor;
289 break;
290 case GLX_GRAY_SCALE:
291 egl_val = GrayScale;
292 break;
293 case GLX_STATIC_GRAY:
294 egl_val = StaticGray;
295 break;
296 default:
297 egl_val = EGL_NONE;
298 break;
299 }
300 break;
301 case EGL_CONFIG_CAVEAT:
302 egl_val = EGL_NONE;
303 if (val == GLX_SLOW_CONFIG) {
304 egl_val = EGL_SLOW_CONFIG;
305 }
306 else if (val == GLX_NON_CONFORMANT_CONFIG) {
307 GLX_conf->Base.Conformant &= ~EGL_OPENGL_BIT;
308 egl_val = EGL_NONE;
309 }
310 break;
311 case EGL_TRANSPARENT_TYPE:
312 egl_val = (val == GLX_TRANSPARENT_RGB) ?
313 EGL_TRANSPARENT_RGB : EGL_NONE;
314 break;
315 default:
316 egl_val = val;
317 break;
318 }
319
320 _eglSetConfigKey(&GLX_conf->Base, egl_attr, egl_val);
321 }
322 if (err)
323 return EGL_FALSE;
324
325 if (!GLX_conf->Base.SurfaceType)
326 return EGL_FALSE;
327
328 return EGL_TRUE;
329 }
330
331 static const struct {
332 int attr;
333 int egl_attr;
334 } visual_attributes[] = {
335 /* table 3.7 of GLX 1.4 */
336 { GLX_USE_GL, 0 },
337 { GLX_BUFFER_SIZE, EGL_BUFFER_SIZE },
338 { GLX_LEVEL, EGL_LEVEL },
339 { GLX_RGBA, 0 },
340 { GLX_DOUBLEBUFFER, 0 },
341 { GLX_STEREO, 0 },
342 { GLX_AUX_BUFFERS, 0 },
343 { GLX_RED_SIZE, EGL_RED_SIZE },
344 { GLX_GREEN_SIZE, EGL_GREEN_SIZE },
345 { GLX_BLUE_SIZE, EGL_BLUE_SIZE },
346 { GLX_ALPHA_SIZE, EGL_ALPHA_SIZE },
347 { GLX_DEPTH_SIZE, EGL_DEPTH_SIZE },
348 { GLX_STENCIL_SIZE, EGL_STENCIL_SIZE },
349 { GLX_ACCUM_RED_SIZE, 0 },
350 { GLX_ACCUM_GREEN_SIZE, 0 },
351 { GLX_ACCUM_BLUE_SIZE, 0 },
352 { GLX_ACCUM_ALPHA_SIZE, 0 },
353 { GLX_SAMPLE_BUFFERS, EGL_SAMPLE_BUFFERS },
354 { GLX_SAMPLES, EGL_SAMPLES },
355 { GLX_FBCONFIG_ID, 0 },
356 /* GLX_EXT_visual_rating */
357 { GLX_VISUAL_CAVEAT_EXT, EGL_CONFIG_CAVEAT }
358 };
359
360 static EGLBoolean
361 convert_visual(struct GLX_egl_driver *GLX_drv,
362 struct GLX_egl_display *GLX_dpy, XVisualInfo *vinfo,
363 struct GLX_egl_config *GLX_conf)
364 {
365 Display *dpy = GLX_dpy->dpy;
366 int err, attr, val;
367 unsigned i;
368
369 /* the visual must support OpenGL and RGBA buffer */
370 err = GLX_drv->glXGetConfig(dpy, vinfo, GLX_USE_GL, &val);
371 if (!err && val)
372 err = GLX_drv->glXGetConfig(dpy, vinfo, GLX_RGBA, &val);
373 if (err || !val)
374 return EGL_FALSE;
375
376 /* must know whether it is double-buffered */
377 err = GLX_drv->glXGetConfig(dpy, vinfo, GLX_DOUBLEBUFFER, &val);
378 if (err)
379 return EGL_FALSE;
380 GLX_conf->double_buffered = val;
381
382 GLX_conf->Base.RenderableType = EGL_OPENGL_BIT;
383 GLX_conf->Base.Conformant = EGL_OPENGL_BIT;
384 GLX_conf->Base.SurfaceType = EGL_WINDOW_BIT;
385 /* pixmap surfaces must be single-buffered in EGL */
386 if (!GLX_conf->double_buffered)
387 GLX_conf->Base.SurfaceType |= EGL_PIXMAP_BIT;
388
389 GLX_conf->Base.NativeVisualID = vinfo->visualid;
390 GLX_conf->Base.NativeVisualType = vinfo->class;
391 GLX_conf->Base.NativeRenderable = EGL_TRUE;
392
393 for (i = 0; i < ARRAY_SIZE(visual_attributes); i++) {
394 EGLint egl_attr, egl_val;
395
396 attr = visual_attributes[i].attr;
397 egl_attr = visual_attributes[i].egl_attr;
398 if (!egl_attr)
399 continue;
400
401 err = GLX_drv->glXGetConfig(dpy, vinfo, attr, &val);
402 if (err) {
403 if (err == GLX_BAD_ATTRIBUTE) {
404 err = 0;
405 continue;
406 }
407 break;
408 }
409
410 switch (egl_attr) {
411 case EGL_CONFIG_CAVEAT:
412 egl_val = EGL_NONE;
413 if (val == GLX_SLOW_VISUAL_EXT) {
414 egl_val = EGL_SLOW_CONFIG;
415 }
416 else if (val == GLX_NON_CONFORMANT_VISUAL_EXT) {
417 GLX_conf->Base.Conformant &= ~EGL_OPENGL_BIT;
418 egl_val = EGL_NONE;
419 }
420 break;
421 break;
422 default:
423 egl_val = val;
424 break;
425 }
426 _eglSetConfigKey(&GLX_conf->Base, egl_attr, egl_val);
427 }
428
429 return (err) ? EGL_FALSE : EGL_TRUE;
430 }
431
432
433 static void
434 fix_config(struct GLX_egl_display *GLX_dpy, struct GLX_egl_config *GLX_conf)
435 {
436 _EGLConfig *conf = &GLX_conf->Base;
437
438 if (!GLX_conf->double_buffered && GLX_dpy->single_buffered_quirk) {
439 /* some GLX impls do not like single-buffered window surface */
440 conf->SurfaceType &= ~EGL_WINDOW_BIT;
441 /* pbuffer bit is usually not set */
442 if (GLX_dpy->have_pbuffer)
443 conf->SurfaceType |= EGL_PBUFFER_BIT;
444 }
445
446 /* no visual attribs unless window bit is set */
447 if (!(conf->SurfaceType & EGL_WINDOW_BIT)) {
448 conf->NativeVisualID = 0;
449 conf->NativeVisualType = EGL_NONE;
450 }
451
452 if (conf->TransparentType != EGL_TRANSPARENT_RGB) {
453 /* some impls set them to -1 (GLX_DONT_CARE) */
454 conf->TransparentRedValue = 0;
455 conf->TransparentGreenValue = 0;
456 conf->TransparentBlueValue = 0;
457 }
458
459 /* make sure buffer size is set correctly */
460 conf->BufferSize =
461 conf->RedSize + conf->GreenSize + conf->BlueSize + conf->AlphaSize;
462 }
463
464
465 static EGLBoolean
466 create_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint screen)
467 {
468 struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
469 struct GLX_egl_display *GLX_dpy = GLX_egl_display(dpy);
470 EGLint num_configs = 0, i;
471 EGLint id = 1;
472
473 if (GLX_dpy->have_fbconfig) {
474 GLX_dpy->fbconfigs =
475 GLX_drv->glXGetFBConfigs(GLX_dpy->dpy, screen, &num_configs);
476 }
477 else {
478 XVisualInfo vinfo_template;
479 long mask;
480
481 vinfo_template.screen = screen;
482 mask = VisualScreenMask;
483 GLX_dpy->visuals = XGetVisualInfo(GLX_dpy->dpy, mask, &vinfo_template,
484 &num_configs);
485 }
486
487 if (!num_configs)
488 return EGL_FALSE;
489
490 for (i = 0; i < num_configs; i++) {
491 struct GLX_egl_config *GLX_conf, template;
492 EGLBoolean ok;
493
494 memset(&template, 0, sizeof(template));
495 _eglInitConfig(&template.Base, dpy, id);
496 if (GLX_dpy->have_fbconfig) {
497 ok = convert_fbconfig(GLX_drv, GLX_dpy,
498 GLX_dpy->fbconfigs[i], &template);
499 }
500 else {
501 ok = convert_visual(GLX_drv, GLX_dpy,
502 &GLX_dpy->visuals[i], &template);
503 }
504 if (!ok)
505 continue;
506
507 fix_config(GLX_dpy, &template);
508 if (!_eglValidateConfig(&template.Base, EGL_FALSE)) {
509 _eglLog(_EGL_DEBUG, "GLX: failed to validate config %d", i);
510 continue;
511 }
512
513 GLX_conf = CALLOC_STRUCT(GLX_egl_config);
514 if (GLX_conf) {
515 memcpy(GLX_conf, &template, sizeof(template));
516 GLX_conf->index = i;
517
518 _eglLinkConfig(&GLX_conf->Base);
519 id++;
520 }
521 }
522
523 return EGL_TRUE;
524 }
525
526
527 static void
528 check_extensions(struct GLX_egl_driver *GLX_drv,
529 struct GLX_egl_display *GLX_dpy, EGLint screen)
530 {
531 GLX_dpy->extensions =
532 GLX_drv->glXQueryExtensionsString(GLX_dpy->dpy, screen);
533 if (GLX_dpy->extensions) {
534 if (strstr(GLX_dpy->extensions, "GLX_SGI_make_current_read")) {
535 /* GLX 1.3 entry points are used */
536 GLX_dpy->have_make_current_read = EGL_TRUE;
537 }
538
539 if (strstr(GLX_dpy->extensions, "GLX_SGIX_fbconfig")) {
540 /* GLX 1.3 entry points are used */
541 GLX_dpy->have_fbconfig = EGL_TRUE;
542 }
543
544 if (strstr(GLX_dpy->extensions, "GLX_SGIX_pbuffer")) {
545 if (GLX_drv->glXCreateGLXPbufferSGIX &&
546 GLX_drv->glXDestroyGLXPbufferSGIX &&
547 GLX_dpy->have_fbconfig)
548 GLX_dpy->have_pbuffer = EGL_TRUE;
549 }
550 }
551
552 if (GLX_dpy->glx_maj == 1 && GLX_dpy->glx_min >= 3) {
553 GLX_dpy->have_1_3 = EGL_TRUE;
554 GLX_dpy->have_make_current_read = EGL_TRUE;
555 GLX_dpy->have_fbconfig = EGL_TRUE;
556 GLX_dpy->have_pbuffer = EGL_TRUE;
557 }
558 }
559
560
561 static void
562 check_quirks(struct GLX_egl_driver *GLX_drv,
563 struct GLX_egl_display *GLX_dpy, EGLint screen)
564 {
565 const char *vendor;
566
567 GLX_dpy->single_buffered_quirk = EGL_TRUE;
568 GLX_dpy->glx_window_quirk = EGL_TRUE;
569
570 vendor = GLX_drv->glXGetClientString(GLX_dpy->dpy, GLX_VENDOR);
571 if (vendor && strstr(vendor, "NVIDIA")) {
572 vendor = GLX_drv->glXQueryServerString(GLX_dpy->dpy, screen, GLX_VENDOR);
573 if (vendor && strstr(vendor, "NVIDIA")) {
574 _eglLog(_EGL_DEBUG, "disable quirks");
575 GLX_dpy->single_buffered_quirk = EGL_FALSE;
576 GLX_dpy->glx_window_quirk = EGL_FALSE;
577 }
578 }
579 }
580
581
582 /**
583 * Called via eglInitialize(), GLX_drv->API.Initialize().
584 */
585 static EGLBoolean
586 GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp)
587 {
588 struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
589 struct GLX_egl_display *GLX_dpy;
590
591 if (disp->Platform != _EGL_PLATFORM_X11)
592 return EGL_FALSE;
593
594 /* this is a fallback driver */
595 if (!disp->Options.UseFallback)
596 return EGL_FALSE;
597
598 if (disp->Options.TestOnly)
599 return EGL_TRUE;
600
601 GLX_dpy = CALLOC_STRUCT(GLX_egl_display);
602 if (!GLX_dpy)
603 return _eglError(EGL_BAD_ALLOC, "eglInitialize");
604
605 GLX_dpy->dpy = (Display *) disp->PlatformDisplay;
606 if (!GLX_dpy->dpy) {
607 GLX_dpy->dpy = XOpenDisplay(NULL);
608 if (!GLX_dpy->dpy) {
609 _eglLog(_EGL_WARNING, "GLX: XOpenDisplay failed");
610 free(GLX_dpy);
611 return EGL_FALSE;
612 }
613 }
614
615 if (!GLX_drv->glXQueryVersion(GLX_dpy->dpy,
616 &GLX_dpy->glx_maj, &GLX_dpy->glx_min)) {
617 _eglLog(_EGL_WARNING, "GLX: glXQueryVersion failed");
618 if (!disp->PlatformDisplay)
619 XCloseDisplay(GLX_dpy->dpy);
620 free(GLX_dpy);
621 return EGL_FALSE;
622 }
623
624 disp->DriverData = (void *) GLX_dpy;
625 disp->ClientAPIs = EGL_OPENGL_BIT;
626
627 check_extensions(GLX_drv, GLX_dpy, DefaultScreen(GLX_dpy->dpy));
628 check_quirks(GLX_drv, GLX_dpy, DefaultScreen(GLX_dpy->dpy));
629
630 create_configs(drv, disp, DefaultScreen(GLX_dpy->dpy));
631 if (!_eglGetArraySize(disp->Configs)) {
632 _eglLog(_EGL_WARNING, "GLX: failed to create any config");
633 if (!disp->PlatformDisplay)
634 XCloseDisplay(GLX_dpy->dpy);
635 free(GLX_dpy);
636 return EGL_FALSE;
637 }
638
639 /* we're supporting EGL 1.4 */
640 disp->VersionMajor = 1;
641 disp->VersionMinor = 4;
642
643 return EGL_TRUE;
644 }
645
646
647 /**
648 * Called via eglTerminate(), drv->API.Terminate().
649 */
650 static EGLBoolean
651 GLX_eglTerminate(_EGLDriver *drv, _EGLDisplay *disp)
652 {
653 struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
654
655 _eglReleaseDisplayResources(drv, disp);
656 _eglCleanupDisplay(disp);
657
658 if (GLX_dpy->visuals)
659 XFree(GLX_dpy->visuals);
660 if (GLX_dpy->fbconfigs)
661 XFree(GLX_dpy->fbconfigs);
662
663 if (!disp->PlatformDisplay)
664 XCloseDisplay(GLX_dpy->dpy);
665 free(GLX_dpy);
666
667 disp->DriverData = NULL;
668
669 return EGL_TRUE;
670 }
671
672
673 /**
674 * Called via eglCreateContext(), drv->API.CreateContext().
675 */
676 static _EGLContext *
677 GLX_eglCreateContext(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
678 _EGLContext *share_list, const EGLint *attrib_list)
679 {
680 struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
681 struct GLX_egl_context *GLX_ctx = CALLOC_STRUCT(GLX_egl_context);
682 struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
683 struct GLX_egl_context *GLX_ctx_shared = GLX_egl_context(share_list);
684
685 if (!GLX_ctx) {
686 _eglError(EGL_BAD_ALLOC, "eglCreateContext");
687 return NULL;
688 }
689
690 if (!_eglInitContext(&GLX_ctx->Base, disp, conf, attrib_list)) {
691 free(GLX_ctx);
692 return NULL;
693 }
694
695 if (GLX_dpy->have_fbconfig) {
696 GLX_ctx->context = GLX_drv->glXCreateNewContext(GLX_dpy->dpy,
697 GLX_dpy->fbconfigs[GLX_egl_config_index(conf)],
698 GLX_RGBA_TYPE,
699 GLX_ctx_shared ? GLX_ctx_shared->context : NULL,
700 GL_TRUE);
701 }
702 else {
703 GLX_ctx->context = GLX_drv->glXCreateContext(GLX_dpy->dpy,
704 &GLX_dpy->visuals[GLX_egl_config_index(conf)],
705 GLX_ctx_shared ? GLX_ctx_shared->context : NULL,
706 GL_TRUE);
707 }
708 if (!GLX_ctx->context) {
709 free(GLX_ctx);
710 return NULL;
711 }
712
713 return &GLX_ctx->Base;
714 }
715
716
717 /**
718 * Destroy a surface. The display is allowed to be uninitialized.
719 */
720 static void
721 destroy_surface(_EGLDisplay *disp, _EGLSurface *surf)
722 {
723 struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
724 struct GLX_egl_surface *GLX_surf = GLX_egl_surface(surf);
725
726 if (GLX_surf->destroy)
727 GLX_surf->destroy(GLX_dpy->dpy, GLX_surf->glx_drawable);
728
729 free(GLX_surf);
730 }
731
732
733 /**
734 * Called via eglMakeCurrent(), drv->API.MakeCurrent().
735 */
736 static EGLBoolean
737 GLX_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf,
738 _EGLSurface *rsurf, _EGLContext *ctx)
739 {
740 struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
741 struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
742 struct GLX_egl_surface *GLX_dsurf = GLX_egl_surface(dsurf);
743 struct GLX_egl_surface *GLX_rsurf = GLX_egl_surface(rsurf);
744 struct GLX_egl_context *GLX_ctx = GLX_egl_context(ctx);
745 _EGLContext *old_ctx;
746 _EGLSurface *old_dsurf, *old_rsurf;
747 GLXDrawable ddraw, rdraw;
748 GLXContext cctx;
749 EGLBoolean ret = EGL_FALSE;
750
751 /* make new bindings */
752 if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf))
753 return EGL_FALSE;
754
755 ddraw = (GLX_dsurf) ? GLX_dsurf->glx_drawable : None;
756 rdraw = (GLX_rsurf) ? GLX_rsurf->glx_drawable : None;
757 cctx = (GLX_ctx) ? GLX_ctx->context : NULL;
758
759 if (GLX_dpy->have_make_current_read)
760 ret = GLX_drv->glXMakeContextCurrent(GLX_dpy->dpy, ddraw, rdraw, cctx);
761 else if (ddraw == rdraw)
762 ret = GLX_drv->glXMakeCurrent(GLX_dpy->dpy, ddraw, cctx);
763
764 if (ret) {
765 if (_eglPutSurface(old_dsurf))
766 destroy_surface(disp, old_dsurf);
767 if (_eglPutSurface(old_rsurf))
768 destroy_surface(disp, old_rsurf);
769 /* no destroy? */
770 _eglPutContext(old_ctx);
771 }
772 else {
773 /* undo the previous _eglBindContext */
774 _eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &dsurf, &rsurf);
775 assert(&GLX_ctx->Base == ctx &&
776 &GLX_dsurf->Base == dsurf &&
777 &GLX_rsurf->Base == rsurf);
778
779 _eglPutSurface(dsurf);
780 _eglPutSurface(rsurf);
781 _eglPutContext(ctx);
782
783 _eglPutSurface(old_dsurf);
784 _eglPutSurface(old_rsurf);
785 _eglPutContext(old_ctx);
786 }
787
788 return ret;
789 }
790
791 /** Get size of given window */
792 static Status
793 get_drawable_size(Display *dpy, Drawable d, uint *width, uint *height)
794 {
795 Window root;
796 Status stat;
797 int xpos, ypos;
798 unsigned int w, h, bw, depth;
799 stat = XGetGeometry(dpy, d, &root, &xpos, &ypos, &w, &h, &bw, &depth);
800 *width = w;
801 *height = h;
802 return stat;
803 }
804
805 /**
806 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
807 */
808 static _EGLSurface *
809 GLX_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *disp,
810 _EGLConfig *conf, EGLNativeWindowType window,
811 const EGLint *attrib_list)
812 {
813 struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
814 struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
815 struct GLX_egl_surface *GLX_surf;
816 uint width, height;
817
818 GLX_surf = CALLOC_STRUCT(GLX_egl_surface);
819 if (!GLX_surf) {
820 _eglError(EGL_BAD_ALLOC, "eglCreateWindowSurface");
821 return NULL;
822 }
823
824 if (!_eglInitSurface(&GLX_surf->Base, disp, EGL_WINDOW_BIT,
825 conf, attrib_list)) {
826 free(GLX_surf);
827 return NULL;
828 }
829
830 GLX_surf->drawable = window;
831
832 if (GLX_dpy->have_1_3 && !GLX_dpy->glx_window_quirk) {
833 GLX_surf->glx_drawable = GLX_drv->glXCreateWindow(GLX_dpy->dpy,
834 GLX_dpy->fbconfigs[GLX_egl_config_index(conf)],
835 GLX_surf->drawable, NULL);
836 }
837 else {
838 GLX_surf->glx_drawable = GLX_surf->drawable;
839 }
840
841 if (!GLX_surf->glx_drawable) {
842 free(GLX_surf);
843 return NULL;
844 }
845
846 if (GLX_dpy->have_1_3 && !GLX_dpy->glx_window_quirk)
847 GLX_surf->destroy = GLX_drv->glXDestroyWindow;
848
849 get_drawable_size(GLX_dpy->dpy, window, &width, &height);
850 GLX_surf->Base.Width = width;
851 GLX_surf->Base.Height = height;
852
853 return &GLX_surf->Base;
854 }
855
856 static _EGLSurface *
857 GLX_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *disp,
858 _EGLConfig *conf, EGLNativePixmapType pixmap,
859 const EGLint *attrib_list)
860 {
861 struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
862 struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
863 struct GLX_egl_surface *GLX_surf;
864 uint width, height;
865
866 GLX_surf = CALLOC_STRUCT(GLX_egl_surface);
867 if (!GLX_surf) {
868 _eglError(EGL_BAD_ALLOC, "eglCreatePixmapSurface");
869 return NULL;
870 }
871
872 if (!_eglInitSurface(&GLX_surf->Base, disp, EGL_PIXMAP_BIT,
873 conf, attrib_list)) {
874 free(GLX_surf);
875 return NULL;
876 }
877
878 GLX_surf->drawable = pixmap;
879
880 if (GLX_dpy->have_1_3) {
881 GLX_surf->glx_drawable = GLX_drv->glXCreatePixmap(GLX_dpy->dpy,
882 GLX_dpy->fbconfigs[GLX_egl_config_index(conf)],
883 GLX_surf->drawable, NULL);
884 }
885 else if (GLX_dpy->have_fbconfig) {
886 GLXFBConfig fbconfig = GLX_dpy->fbconfigs[GLX_egl_config_index(conf)];
887 XVisualInfo *vinfo;
888
889 vinfo = GLX_drv->glXGetVisualFromFBConfig(GLX_dpy->dpy, fbconfig);
890 if (vinfo) {
891 GLX_surf->glx_drawable = GLX_drv->glXCreateGLXPixmap(GLX_dpy->dpy,
892 vinfo, GLX_surf->drawable);
893 XFree(vinfo);
894 }
895 }
896 else {
897 GLX_surf->glx_drawable = GLX_drv->glXCreateGLXPixmap(GLX_dpy->dpy,
898 &GLX_dpy->visuals[GLX_egl_config_index(conf)],
899 GLX_surf->drawable);
900 }
901
902 if (!GLX_surf->glx_drawable) {
903 free(GLX_surf);
904 return NULL;
905 }
906
907 GLX_surf->destroy = (GLX_dpy->have_1_3) ?
908 GLX_drv->glXDestroyPixmap : GLX_drv->glXDestroyGLXPixmap;
909
910 get_drawable_size(GLX_dpy->dpy, pixmap, &width, &height);
911 GLX_surf->Base.Width = width;
912 GLX_surf->Base.Height = height;
913
914 return &GLX_surf->Base;
915 }
916
917 static _EGLSurface *
918 GLX_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *disp,
919 _EGLConfig *conf, const EGLint *attrib_list)
920 {
921 struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
922 struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
923 struct GLX_egl_surface *GLX_surf;
924 int attribs[5];
925 int i;
926
927 GLX_surf = CALLOC_STRUCT(GLX_egl_surface);
928 if (!GLX_surf) {
929 _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface");
930 return NULL;
931 }
932
933 if (!_eglInitSurface(&GLX_surf->Base, disp, EGL_PBUFFER_BIT,
934 conf, attrib_list)) {
935 free(GLX_surf);
936 return NULL;
937 }
938
939 i = 0;
940 attribs[i] = None;
941
942 GLX_surf->drawable = None;
943
944 if (GLX_dpy->have_1_3) {
945 /* put geometry in attribs */
946 if (GLX_surf->Base.Width) {
947 attribs[i++] = GLX_PBUFFER_WIDTH;
948 attribs[i++] = GLX_surf->Base.Width;
949 }
950 if (GLX_surf->Base.Height) {
951 attribs[i++] = GLX_PBUFFER_HEIGHT;
952 attribs[i++] = GLX_surf->Base.Height;
953 }
954 attribs[i] = None;
955
956 GLX_surf->glx_drawable = GLX_drv->glXCreatePbuffer(GLX_dpy->dpy,
957 GLX_dpy->fbconfigs[GLX_egl_config_index(conf)], attribs);
958 }
959 else if (GLX_dpy->have_pbuffer) {
960 GLX_surf->glx_drawable = GLX_drv->glXCreateGLXPbufferSGIX(GLX_dpy->dpy,
961 GLX_dpy->fbconfigs[GLX_egl_config_index(conf)],
962 GLX_surf->Base.Width,
963 GLX_surf->Base.Height,
964 attribs);
965 }
966
967 if (!GLX_surf->glx_drawable) {
968 free(GLX_surf);
969 return NULL;
970 }
971
972 GLX_surf->destroy = (GLX_dpy->have_1_3) ?
973 GLX_drv->glXDestroyPbuffer : GLX_drv->glXDestroyGLXPbufferSGIX;
974
975 return &GLX_surf->Base;
976 }
977
978
979 static EGLBoolean
980 GLX_eglDestroySurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
981 {
982 (void) drv;
983
984 if (_eglPutSurface(surf))
985 destroy_surface(disp, surf);
986
987 return EGL_TRUE;
988 }
989
990
991 static EGLBoolean
992 GLX_eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
993 {
994 struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
995 struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
996 struct GLX_egl_surface *GLX_surf = GLX_egl_surface(draw);
997
998 GLX_drv->glXSwapBuffers(GLX_dpy->dpy, GLX_surf->glx_drawable);
999
1000 return EGL_TRUE;
1001 }
1002
1003 /*
1004 * Called from eglGetProcAddress() via drv->API.GetProcAddress().
1005 */
1006 static _EGLProc
1007 GLX_eglGetProcAddress(_EGLDriver *drv, const char *procname)
1008 {
1009 struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
1010
1011 return (_EGLProc) GLX_drv->glXGetProcAddress((const GLubyte *) procname);
1012 }
1013
1014 static EGLBoolean
1015 GLX_eglWaitClient(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx)
1016 {
1017 struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
1018
1019 (void) dpy;
1020 (void) ctx;
1021
1022 GLX_drv->glXWaitGL();
1023 return EGL_TRUE;
1024 }
1025
1026 static EGLBoolean
1027 GLX_eglWaitNative(_EGLDriver *drv, _EGLDisplay *dpy, EGLint engine)
1028 {
1029 struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
1030
1031 (void) dpy;
1032
1033 if (engine != EGL_CORE_NATIVE_ENGINE)
1034 return _eglError(EGL_BAD_PARAMETER, "eglWaitNative");
1035 GLX_drv->glXWaitX();
1036 return EGL_TRUE;
1037 }
1038
1039 static void
1040 GLX_Unload(_EGLDriver *drv)
1041 {
1042 struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
1043
1044 if (GLX_drv->handle)
1045 dlclose(GLX_drv->handle);
1046 free(GLX_drv);
1047 }
1048
1049
1050 static EGLBoolean
1051 GLX_Load(_EGLDriver *drv)
1052 {
1053 struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
1054 void *handle;
1055
1056 handle = dlopen("libGL.so", RTLD_LAZY | RTLD_LOCAL);
1057 if (!handle)
1058 goto fail;
1059
1060 GLX_drv->glXGetProcAddress = dlsym(handle, "glXGetProcAddress");
1061 if (!GLX_drv->glXGetProcAddress)
1062 GLX_drv->glXGetProcAddress = dlsym(handle, "glXGetProcAddressARB");
1063 if (!GLX_drv->glXGetProcAddress)
1064 goto fail;
1065
1066 #define GET_PROC(proc_type, proc_name, check) \
1067 do { \
1068 GLX_drv->proc_name = (proc_type) \
1069 GLX_drv->glXGetProcAddress((const GLubyte *) #proc_name); \
1070 if (check && !GLX_drv->proc_name) goto fail; \
1071 } while (0)
1072
1073 /* GLX 1.0 */
1074 GET_PROC(GLXCREATECONTEXTPROC, glXCreateContext, EGL_TRUE);
1075 GET_PROC(GLXDESTROYCONTEXTPROC, glXDestroyContext, EGL_TRUE);
1076 GET_PROC(GLXMAKECURRENTPROC, glXMakeCurrent, EGL_TRUE);
1077 GET_PROC(GLXSWAPBUFFERSPROC, glXSwapBuffers, EGL_TRUE);
1078 GET_PROC(GLXCREATEGLXPIXMAPPROC, glXCreateGLXPixmap, EGL_TRUE);
1079 GET_PROC(GLXDESTROYGLXPIXMAPPROC, glXDestroyGLXPixmap, EGL_TRUE);
1080 GET_PROC(GLXQUERYVERSIONPROC, glXQueryVersion, EGL_TRUE);
1081 GET_PROC(GLXGETCONFIGPROC, glXGetConfig, EGL_TRUE);
1082 GET_PROC(GLXWAITGLPROC, glXWaitGL, EGL_TRUE);
1083 GET_PROC(GLXWAITXPROC, glXWaitX, EGL_TRUE);
1084
1085 /* GLX 1.1 */
1086 GET_PROC(GLXQUERYEXTENSIONSSTRINGPROC, glXQueryExtensionsString, EGL_TRUE);
1087 GET_PROC(GLXQUERYSERVERSTRINGPROC, glXQueryServerString, EGL_TRUE);
1088 GET_PROC(GLXGETCLIENTSTRINGPROC, glXGetClientString, EGL_TRUE);
1089
1090 /* GLX 1.3 */
1091 GET_PROC(PFNGLXGETFBCONFIGSPROC, glXGetFBConfigs, EGL_FALSE);
1092 GET_PROC(PFNGLXGETFBCONFIGATTRIBPROC, glXGetFBConfigAttrib, EGL_FALSE);
1093 GET_PROC(PFNGLXGETVISUALFROMFBCONFIGPROC, glXGetVisualFromFBConfig, EGL_FALSE);
1094 GET_PROC(PFNGLXCREATEWINDOWPROC, glXCreateWindow, EGL_FALSE);
1095 GET_PROC(PFNGLXDESTROYWINDOWPROC, glXDestroyWindow, EGL_FALSE);
1096 GET_PROC(PFNGLXCREATEPIXMAPPROC, glXCreatePixmap, EGL_FALSE);
1097 GET_PROC(PFNGLXDESTROYPIXMAPPROC, glXDestroyPixmap, EGL_FALSE);
1098 GET_PROC(PFNGLXCREATEPBUFFERPROC, glXCreatePbuffer, EGL_FALSE);
1099 GET_PROC(PFNGLXDESTROYPBUFFERPROC, glXDestroyPbuffer, EGL_FALSE);
1100 GET_PROC(PFNGLXCREATENEWCONTEXTPROC, glXCreateNewContext, EGL_FALSE);
1101 GET_PROC(PFNGLXMAKECONTEXTCURRENTPROC, glXMakeContextCurrent, EGL_FALSE);
1102
1103 /* GLX_SGIX_pbuffer */
1104 GET_PROC(PFNGLXCREATEGLXPBUFFERSGIXPROC,
1105 glXCreateGLXPbufferSGIX, EGL_FALSE);
1106 GET_PROC(PFNGLXDESTROYGLXPBUFFERSGIXPROC,
1107 glXDestroyGLXPbufferSGIX, EGL_FALSE);
1108 #undef GET_PROC
1109
1110 GLX_drv->handle = handle;
1111
1112 return EGL_TRUE;
1113
1114 fail:
1115 if (handle)
1116 dlclose(handle);
1117 return EGL_FALSE;
1118 }
1119
1120
1121 /**
1122 * This is the main entrypoint into the driver, called by libEGL.
1123 * Create a new _EGLDriver object and init its dispatch table.
1124 */
1125 _EGLDriver *
1126 _EGL_MAIN(const char *args)
1127 {
1128 struct GLX_egl_driver *GLX_drv = CALLOC_STRUCT(GLX_egl_driver);
1129
1130 (void) args;
1131
1132 if (!GLX_drv)
1133 return NULL;
1134
1135 if (!GLX_Load(&GLX_drv->Base)) {
1136 _eglLog(_EGL_WARNING, "GLX: failed to load GLX");
1137 free(GLX_drv);
1138 return NULL;
1139 }
1140
1141 _eglInitDriverFallbacks(&GLX_drv->Base);
1142 GLX_drv->Base.API.Initialize = GLX_eglInitialize;
1143 GLX_drv->Base.API.Terminate = GLX_eglTerminate;
1144 GLX_drv->Base.API.CreateContext = GLX_eglCreateContext;
1145 GLX_drv->Base.API.MakeCurrent = GLX_eglMakeCurrent;
1146 GLX_drv->Base.API.CreateWindowSurface = GLX_eglCreateWindowSurface;
1147 GLX_drv->Base.API.CreatePixmapSurface = GLX_eglCreatePixmapSurface;
1148 GLX_drv->Base.API.CreatePbufferSurface = GLX_eglCreatePbufferSurface;
1149 GLX_drv->Base.API.DestroySurface = GLX_eglDestroySurface;
1150 GLX_drv->Base.API.SwapBuffers = GLX_eglSwapBuffers;
1151 GLX_drv->Base.API.GetProcAddress = GLX_eglGetProcAddress;
1152 GLX_drv->Base.API.WaitClient = GLX_eglWaitClient;
1153 GLX_drv->Base.API.WaitNative = GLX_eglWaitNative;
1154
1155 GLX_drv->Base.Name = "GLX";
1156 GLX_drv->Base.Unload = GLX_Unload;
1157
1158 return &GLX_drv->Base;
1159 }