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