1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 * This is an EGL driver that wraps GLX. This gives the benefit of being
31 * completely agnostic of the direct rendering implementation.
33 * Authors: Alan Hourihane <alanh@tungstengraphics.com>
42 #include "eglconfig.h"
43 #include "eglcontext.h"
44 #include "egldefines.h"
45 #include "egldisplay.h"
46 #include "egldriver.h"
47 #include "eglcurrent.h"
49 #include "eglsurface.h"
51 #define CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))
53 #ifndef GLX_VERSION_1_4
54 #error "GL/glx.h must be equal to or greater than GLX 1.4"
57 /** subclass of _EGLDriver */
60 _EGLDriver Base
; /**< base class */
64 /** driver data of _EGLDisplay */
65 struct GLX_egl_display
69 GLXFBConfig
*fbconfigs
;
73 const char *extensions
;
75 EGLBoolean have_make_current_read
;
76 EGLBoolean have_fbconfig
;
77 EGLBoolean have_pbuffer
;
79 /* GLX_SGIX_pbuffer */
80 PFNGLXCREATEGLXPBUFFERSGIXPROC glXCreateGLXPbufferSGIX
;
81 PFNGLXDESTROYGLXPBUFFERSGIXPROC glXDestroyGLXPbufferSGIX
;
83 /* workaround quirks of different GLX implementations */
84 EGLBoolean single_buffered_quirk
;
85 EGLBoolean glx_window_quirk
;
90 /** subclass of _EGLContext */
91 struct GLX_egl_context
93 _EGLContext Base
; /**< base class */
99 /** subclass of _EGLSurface */
100 struct GLX_egl_surface
102 _EGLSurface Base
; /**< base class */
105 GLXDrawable glx_drawable
;
107 void (*destroy
)(Display
*, GLXDrawable
);
111 /** subclass of _EGLConfig */
112 struct GLX_egl_config
114 _EGLConfig Base
; /**< base class */
115 EGLBoolean double_buffered
;
119 /* standard typecasts */
120 _EGL_DRIVER_STANDARD_TYPECASTS(GLX_egl
)
123 GLX_egl_config_index(_EGLConfig
*conf
)
125 struct GLX_egl_config
*GLX_conf
= GLX_egl_config(conf
);
126 return GLX_conf
->index
;
130 static const struct {
133 } fbconfig_attributes
[] = {
134 /* table 3.1 of GLX 1.4 */
135 { GLX_BUFFER_SIZE
, EGL_BUFFER_SIZE
},
136 { GLX_LEVEL
, EGL_LEVEL
},
137 { GLX_RED_SIZE
, EGL_RED_SIZE
},
138 { GLX_GREEN_SIZE
, EGL_GREEN_SIZE
},
139 { GLX_BLUE_SIZE
, EGL_BLUE_SIZE
},
140 { GLX_ALPHA_SIZE
, EGL_ALPHA_SIZE
},
141 { GLX_DEPTH_SIZE
, EGL_DEPTH_SIZE
},
142 { GLX_STENCIL_SIZE
, EGL_STENCIL_SIZE
},
143 { GLX_SAMPLE_BUFFERS
, EGL_SAMPLE_BUFFERS
},
144 { GLX_SAMPLES
, EGL_SAMPLES
},
145 { GLX_RENDER_TYPE
, EGL_RENDERABLE_TYPE
},
146 { GLX_X_RENDERABLE
, EGL_NATIVE_RENDERABLE
},
147 { GLX_X_VISUAL_TYPE
, EGL_NATIVE_VISUAL_TYPE
},
148 { GLX_CONFIG_CAVEAT
, EGL_CONFIG_CAVEAT
},
149 { GLX_TRANSPARENT_TYPE
, EGL_TRANSPARENT_TYPE
},
150 { GLX_TRANSPARENT_RED_VALUE
, EGL_TRANSPARENT_RED_VALUE
},
151 { GLX_TRANSPARENT_GREEN_VALUE
, EGL_TRANSPARENT_GREEN_VALUE
},
152 { GLX_TRANSPARENT_BLUE_VALUE
, EGL_TRANSPARENT_BLUE_VALUE
},
153 { GLX_MAX_PBUFFER_WIDTH
, EGL_MAX_PBUFFER_WIDTH
},
154 { GLX_MAX_PBUFFER_HEIGHT
, EGL_MAX_PBUFFER_HEIGHT
},
155 { GLX_MAX_PBUFFER_PIXELS
, EGL_MAX_PBUFFER_PIXELS
},
156 { GLX_VISUAL_ID
, EGL_NATIVE_VISUAL_ID
},
157 { GLX_X_VISUAL_TYPE
, EGL_NATIVE_VISUAL_TYPE
},
162 convert_fbconfig(Display
*dpy
, GLXFBConfig fbconfig
,
163 struct GLX_egl_config
*GLX_conf
)
165 int err
= 0, attr
, egl_attr
, val
, i
;
166 EGLint conformant
, config_caveat
, surface_type
;
168 for (i
= 0; i
< ARRAY_SIZE(fbconfig_attributes
); i
++) {
169 attr
= fbconfig_attributes
[i
].attr
;
170 egl_attr
= fbconfig_attributes
[i
].egl_attr
;
171 err
= glXGetFBConfigAttrib(dpy
, fbconfig
, attr
, &val
);
173 if (err
== GLX_BAD_ATTRIBUTE
) {
180 _eglSetConfigKey(&GLX_conf
->Base
, egl_attr
, val
);
185 /* must have rgba bit */
186 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_RENDER_TYPE
, &val
);
187 if (!(val
& GLX_RGBA_BIT
))
190 conformant
= EGL_OPENGL_BIT
;
191 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_CONFIG_CAVEAT
, &val
);
192 if (val
== GLX_SLOW_CONFIG
)
193 config_caveat
= EGL_SLOW_CONFIG
;
194 if (val
== GLX_NON_CONFORMANT_CONFIG
)
195 conformant
&= ~EGL_OPENGL_BIT
;
196 if (!(conformant
& EGL_OPENGL_ES_BIT
))
197 config_caveat
= EGL_NON_CONFORMANT_CONFIG
;
199 _eglSetConfigKey(&GLX_conf
->Base
, EGL_CONFIG_CAVEAT
, config_caveat
);
202 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_DRAWABLE_TYPE
, &val
);
203 if (val
& GLX_WINDOW_BIT
)
204 surface_type
|= EGL_WINDOW_BIT
;
205 if (val
& GLX_PIXMAP_BIT
)
206 surface_type
|= EGL_PIXMAP_BIT
;
207 if (val
& GLX_PBUFFER_BIT
)
208 surface_type
|= EGL_PBUFFER_BIT
;
210 /* pixmap and pbuffer surfaces must be single-buffered in EGL */
211 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_DOUBLEBUFFER
, &val
);
212 GLX_conf
->double_buffered
= val
;
213 if (GLX_conf
->double_buffered
) {
214 surface_type
&= ~(EGL_PIXMAP_BIT
| EGL_PBUFFER_BIT
);
219 _eglSetConfigKey(&GLX_conf
->Base
, EGL_SURFACE_TYPE
, surface_type
);
224 static const struct {
227 } visual_attributes
[] = {
228 /* table 3.7 of GLX 1.4 */
230 { GLX_BUFFER_SIZE
, EGL_BUFFER_SIZE
},
231 { GLX_LEVEL
, EGL_LEVEL
},
232 { GLX_RED_SIZE
, EGL_RED_SIZE
},
233 { GLX_GREEN_SIZE
, EGL_GREEN_SIZE
},
234 { GLX_BLUE_SIZE
, EGL_BLUE_SIZE
},
235 { GLX_ALPHA_SIZE
, EGL_ALPHA_SIZE
},
236 { GLX_DEPTH_SIZE
, EGL_DEPTH_SIZE
},
237 { GLX_STENCIL_SIZE
, EGL_STENCIL_SIZE
},
238 { GLX_SAMPLE_BUFFERS
, EGL_SAMPLE_BUFFERS
},
239 { GLX_SAMPLES
, EGL_SAMPLES
},
243 convert_visual(Display
*dpy
, XVisualInfo
*vinfo
,
244 struct GLX_egl_config
*GLX_conf
)
246 int err
, attr
, egl_attr
, val
, i
;
247 EGLint conformant
, config_caveat
, surface_type
;
249 /* the visual must support OpenGL */
250 err
= glXGetConfig(dpy
, vinfo
, GLX_USE_GL
, &val
);
254 for (i
= 0; i
< ARRAY_SIZE(visual_attributes
); i
++) {
255 attr
= visual_attributes
[i
].attr
;
256 egl_attr
= fbconfig_attributes
[i
].egl_attr
;
257 err
= glXGetConfig(dpy
, vinfo
, attr
, &val
);
259 if (err
== GLX_BAD_ATTRIBUTE
) {
266 _eglSetConfigKey(&GLX_conf
->Base
, egl_attr
, val
);
271 glXGetConfig(dpy
, vinfo
, GLX_RGBA
, &val
);
275 conformant
= EGL_OPENGL_BIT
;
276 glXGetConfig(dpy
, vinfo
, GLX_VISUAL_CAVEAT_EXT
, &val
);
277 if (val
== GLX_SLOW_CONFIG
)
278 config_caveat
= EGL_SLOW_CONFIG
;
279 if (val
== GLX_NON_CONFORMANT_CONFIG
)
280 conformant
&= ~EGL_OPENGL_BIT
;
281 if (!(conformant
& EGL_OPENGL_ES_BIT
))
282 config_caveat
= EGL_NON_CONFORMANT_CONFIG
;
284 _eglSetConfigKey(&GLX_conf
->Base
, EGL_CONFIG_CAVEAT
, config_caveat
);
285 _eglSetConfigKey(&GLX_conf
->Base
, EGL_NATIVE_VISUAL_ID
, vinfo
->visualid
);
286 _eglSetConfigKey(&GLX_conf
->Base
, EGL_NATIVE_VISUAL_TYPE
, vinfo
->class);
288 /* pixmap and pbuffer surfaces must be single-buffered in EGL */
289 glXGetConfig(dpy
, vinfo
, GLX_DOUBLEBUFFER
, &val
);
290 GLX_conf
->double_buffered
= val
;
291 surface_type
= EGL_WINDOW_BIT
;
292 /* pixmap surfaces must be single-buffered in EGL */
293 if (!GLX_conf
->double_buffered
)
294 surface_type
|= EGL_PIXMAP_BIT
;
296 _eglSetConfigKey(&GLX_conf
->Base
, EGL_SURFACE_TYPE
, surface_type
);
298 _eglSetConfigKey(&GLX_conf
->Base
, EGL_NATIVE_RENDERABLE
, EGL_TRUE
);
305 fix_config(struct GLX_egl_display
*GLX_dpy
, struct GLX_egl_config
*GLX_conf
)
307 _EGLConfig
*conf
= &GLX_conf
->Base
;
308 EGLint surface_type
, r
, g
, b
, a
;
310 surface_type
= GET_CONFIG_ATTRIB(conf
, EGL_SURFACE_TYPE
);
311 if (!GLX_conf
->double_buffered
&& GLX_dpy
->single_buffered_quirk
) {
312 /* some GLX impls do not like single-buffered window surface */
313 surface_type
&= ~EGL_WINDOW_BIT
;
314 /* pbuffer bit is usually not set */
315 if (GLX_dpy
->have_pbuffer
)
316 surface_type
|= EGL_PBUFFER_BIT
;
317 SET_CONFIG_ATTRIB(conf
, EGL_SURFACE_TYPE
, surface_type
);
320 /* no visual attribs unless window bit is set */
321 if (!(surface_type
& EGL_WINDOW_BIT
)) {
322 SET_CONFIG_ATTRIB(conf
, EGL_NATIVE_VISUAL_ID
, 0);
323 SET_CONFIG_ATTRIB(conf
, EGL_NATIVE_VISUAL_TYPE
, EGL_NONE
);
326 /* make sure buffer size is set correctly */
327 r
= GET_CONFIG_ATTRIB(conf
, EGL_RED_SIZE
);
328 g
= GET_CONFIG_ATTRIB(conf
, EGL_GREEN_SIZE
);
329 b
= GET_CONFIG_ATTRIB(conf
, EGL_BLUE_SIZE
);
330 a
= GET_CONFIG_ATTRIB(conf
, EGL_ALPHA_SIZE
);
331 SET_CONFIG_ATTRIB(conf
, EGL_BUFFER_SIZE
, r
+ g
+ b
+ a
);
336 create_configs(_EGLDisplay
*dpy
, struct GLX_egl_display
*GLX_dpy
,
339 EGLint num_configs
= 0, i
;
342 if (GLX_dpy
->have_fbconfig
) {
343 GLX_dpy
->fbconfigs
= glXGetFBConfigs(GLX_dpy
->dpy
, screen
, &num_configs
);
346 XVisualInfo vinfo_template
;
349 vinfo_template
.screen
= screen
;
350 mask
= VisualScreenMask
;
351 GLX_dpy
->visuals
= XGetVisualInfo(GLX_dpy
->dpy
, mask
, &vinfo_template
,
358 for (i
= 0; i
< num_configs
; i
++) {
359 struct GLX_egl_config
*GLX_conf
, template;
362 memset(&template, 0, sizeof(template));
363 _eglInitConfig(&template.Base
, dpy
, id
);
364 if (GLX_dpy
->have_fbconfig
)
365 ok
= convert_fbconfig(GLX_dpy
->dpy
, GLX_dpy
->fbconfigs
[i
], &template);
367 ok
= convert_visual(GLX_dpy
->dpy
, &GLX_dpy
->visuals
[i
], &template);
371 fix_config(GLX_dpy
, &template);
372 if (!_eglValidateConfig(&template.Base
, EGL_FALSE
)) {
373 _eglLog(_EGL_DEBUG
, "GLX: failed to validate config %d", i
);
377 GLX_conf
= CALLOC_STRUCT(GLX_egl_config
);
379 memcpy(GLX_conf
, &template, sizeof(template));
382 _eglAddConfig(dpy
, &GLX_conf
->Base
);
392 check_extensions(struct GLX_egl_display
*GLX_dpy
, EGLint screen
)
394 GLX_dpy
->extensions
=
395 glXQueryExtensionsString(GLX_dpy
->dpy
, screen
);
396 if (GLX_dpy
->extensions
) {
397 /* glXGetProcAddress is assumed */
399 if (strstr(GLX_dpy
->extensions
, "GLX_SGI_make_current_read")) {
400 /* GLX 1.3 entry points are used */
401 GLX_dpy
->have_make_current_read
= EGL_TRUE
;
404 if (strstr(GLX_dpy
->extensions
, "GLX_SGIX_fbconfig")) {
405 /* GLX 1.3 entry points are used */
406 GLX_dpy
->have_fbconfig
= EGL_TRUE
;
409 if (strstr(GLX_dpy
->extensions
, "GLX_SGIX_pbuffer")) {
410 GLX_dpy
->glXCreateGLXPbufferSGIX
= (PFNGLXCREATEGLXPBUFFERSGIXPROC
)
411 glXGetProcAddress((const GLubyte
*) "glXCreateGLXPbufferSGIX");
412 GLX_dpy
->glXDestroyGLXPbufferSGIX
= (PFNGLXDESTROYGLXPBUFFERSGIXPROC
)
413 glXGetProcAddress((const GLubyte
*) "glXDestroyGLXPbufferSGIX");
415 if (GLX_dpy
->glXCreateGLXPbufferSGIX
&&
416 GLX_dpy
->glXDestroyGLXPbufferSGIX
&&
417 GLX_dpy
->have_fbconfig
)
418 GLX_dpy
->have_pbuffer
= EGL_TRUE
;
422 if (GLX_dpy
->glx_maj
== 1 && GLX_dpy
->glx_min
>= 3) {
423 GLX_dpy
->have_1_3
= EGL_TRUE
;
424 GLX_dpy
->have_make_current_read
= EGL_TRUE
;
425 GLX_dpy
->have_fbconfig
= EGL_TRUE
;
426 GLX_dpy
->have_pbuffer
= EGL_TRUE
;
432 check_quirks(struct GLX_egl_display
*GLX_dpy
, EGLint screen
)
436 GLX_dpy
->single_buffered_quirk
= EGL_TRUE
;
437 GLX_dpy
->glx_window_quirk
= EGL_TRUE
;
439 vendor
= glXGetClientString(GLX_dpy
->dpy
, GLX_VENDOR
);
440 if (vendor
&& strstr(vendor
, "NVIDIA")) {
441 vendor
= glXQueryServerString(GLX_dpy
->dpy
, screen
, GLX_VENDOR
);
442 if (vendor
&& strstr(vendor
, "NVIDIA")) {
443 _eglLog(_EGL_DEBUG
, "disable quirks");
444 GLX_dpy
->single_buffered_quirk
= EGL_FALSE
;
445 GLX_dpy
->glx_window_quirk
= EGL_FALSE
;
452 * Called via eglInitialize(), GLX_drv->API.Initialize().
455 GLX_eglInitialize(_EGLDriver
*drv
, _EGLDisplay
*disp
,
456 EGLint
*major
, EGLint
*minor
)
458 struct GLX_egl_display
*GLX_dpy
;
462 if (disp
->Platform
!= _EGL_PLATFORM_X11
)
465 GLX_dpy
= CALLOC_STRUCT(GLX_egl_display
);
467 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
469 GLX_dpy
->dpy
= (Display
*) disp
->PlatformDisplay
;
471 GLX_dpy
->dpy
= XOpenDisplay(NULL
);
473 _eglLog(_EGL_WARNING
, "GLX: XOpenDisplay failed");
479 if (!glXQueryVersion(GLX_dpy
->dpy
, &GLX_dpy
->glx_maj
, &GLX_dpy
->glx_min
)) {
480 _eglLog(_EGL_WARNING
, "GLX: glXQueryVersion failed");
481 if (!disp
->PlatformDisplay
)
482 XCloseDisplay(GLX_dpy
->dpy
);
487 check_extensions(GLX_dpy
, DefaultScreen(GLX_dpy
->dpy
));
488 check_quirks(GLX_dpy
, DefaultScreen(GLX_dpy
->dpy
));
490 create_configs(disp
, GLX_dpy
, DefaultScreen(GLX_dpy
->dpy
));
491 if (!_eglGetArraySize(disp
->Configs
)) {
492 _eglLog(_EGL_WARNING
, "GLX: failed to create any config");
493 if (!disp
->PlatformDisplay
)
494 XCloseDisplay(GLX_dpy
->dpy
);
499 disp
->DriverData
= (void *) GLX_dpy
;
500 disp
->ClientAPIsMask
= EGL_OPENGL_BIT
;
502 /* we're supporting EGL 1.4 */
510 * Called via eglTerminate(), drv->API.Terminate().
513 GLX_eglTerminate(_EGLDriver
*drv
, _EGLDisplay
*disp
)
515 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
517 _eglReleaseDisplayResources(drv
, disp
);
518 _eglCleanupDisplay(disp
);
520 if (GLX_dpy
->visuals
)
521 XFree(GLX_dpy
->visuals
);
522 if (GLX_dpy
->fbconfigs
)
523 XFree(GLX_dpy
->fbconfigs
);
525 if (!disp
->PlatformDisplay
)
526 XCloseDisplay(GLX_dpy
->dpy
);
529 disp
->DriverData
= NULL
;
536 * Called via eglCreateContext(), drv->API.CreateContext().
539 GLX_eglCreateContext(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLConfig
*conf
,
540 _EGLContext
*share_list
, const EGLint
*attrib_list
)
542 struct GLX_egl_context
*GLX_ctx
= CALLOC_STRUCT(GLX_egl_context
);
543 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
544 struct GLX_egl_context
*GLX_ctx_shared
= GLX_egl_context(share_list
);
549 _eglError(EGL_BAD_ALLOC
, "eglCreateContext");
553 if (!_eglInitContext(&GLX_ctx
->Base
, disp
, conf
, attrib_list
)) {
558 if (GLX_dpy
->have_fbconfig
)
560 glXCreateNewContext(GLX_dpy
->dpy
,
561 GLX_dpy
->fbconfigs
[GLX_egl_config_index(conf
)],
563 GLX_ctx_shared
? GLX_ctx_shared
->context
: NULL
,
567 glXCreateContext(GLX_dpy
->dpy
,
568 &GLX_dpy
->visuals
[GLX_egl_config_index(conf
)],
569 GLX_ctx_shared
? GLX_ctx_shared
->context
: NULL
,
571 if (!GLX_ctx
->context
) {
576 return &GLX_ctx
->Base
;
581 * Destroy a surface. The display is allowed to be uninitialized.
584 destroy_surface(_EGLDisplay
*disp
, _EGLSurface
*surf
)
586 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
587 struct GLX_egl_surface
*GLX_surf
= GLX_egl_surface(surf
);
589 if (GLX_surf
->destroy
)
590 GLX_surf
->destroy(GLX_dpy
->dpy
, GLX_surf
->glx_drawable
);
597 * Called via eglMakeCurrent(), drv->API.MakeCurrent().
600 GLX_eglMakeCurrent(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*dsurf
,
601 _EGLSurface
*rsurf
, _EGLContext
*ctx
)
603 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
604 struct GLX_egl_surface
*GLX_dsurf
= GLX_egl_surface(dsurf
);
605 struct GLX_egl_surface
*GLX_rsurf
= GLX_egl_surface(rsurf
);
606 struct GLX_egl_context
*GLX_ctx
= GLX_egl_context(ctx
);
607 GLXDrawable ddraw
, rdraw
;
609 EGLBoolean ret
= EGL_FALSE
;
613 /* bind the new context and return the "orphaned" one */
614 if (!_eglBindContext(&ctx
, &dsurf
, &rsurf
))
617 ddraw
= (GLX_dsurf
) ? GLX_dsurf
->glx_drawable
: None
;
618 rdraw
= (GLX_rsurf
) ? GLX_rsurf
->glx_drawable
: None
;
619 cctx
= (GLX_ctx
) ? GLX_ctx
->context
: NULL
;
621 if (GLX_dpy
->have_make_current_read
)
622 ret
= glXMakeContextCurrent(GLX_dpy
->dpy
, ddraw
, rdraw
, cctx
);
623 else if (ddraw
== rdraw
)
624 ret
= glXMakeCurrent(GLX_dpy
->dpy
, ddraw
, cctx
);
627 if (dsurf
&& !_eglIsSurfaceLinked(dsurf
))
628 destroy_surface(disp
, dsurf
);
629 if (rsurf
&& rsurf
!= dsurf
&& !_eglIsSurfaceLinked(rsurf
))
630 destroy_surface(disp
, rsurf
);
633 _eglBindContext(&ctx
, &dsurf
, &rsurf
);
639 /** Get size of given window */
641 get_drawable_size(Display
*dpy
, Drawable d
, uint
*width
, uint
*height
)
646 unsigned int w
, h
, bw
, depth
;
647 stat
= XGetGeometry(dpy
, d
, &root
, &xpos
, &ypos
, &w
, &h
, &bw
, &depth
);
654 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
657 GLX_eglCreateWindowSurface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
658 _EGLConfig
*conf
, EGLNativeWindowType window
,
659 const EGLint
*attrib_list
)
661 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
662 struct GLX_egl_surface
*GLX_surf
;
667 GLX_surf
= CALLOC_STRUCT(GLX_egl_surface
);
669 _eglError(EGL_BAD_ALLOC
, "eglCreateWindowSurface");
673 if (!_eglInitSurface(&GLX_surf
->Base
, disp
, EGL_WINDOW_BIT
,
674 conf
, attrib_list
)) {
679 GLX_surf
->drawable
= window
;
681 if (GLX_dpy
->have_1_3
&& !GLX_dpy
->glx_window_quirk
)
682 GLX_surf
->glx_drawable
=
683 glXCreateWindow(GLX_dpy
->dpy
,
684 GLX_dpy
->fbconfigs
[GLX_egl_config_index(conf
)],
685 GLX_surf
->drawable
, NULL
);
687 GLX_surf
->glx_drawable
= GLX_surf
->drawable
;
689 if (!GLX_surf
->glx_drawable
) {
694 if (GLX_dpy
->have_1_3
&& !GLX_dpy
->glx_window_quirk
)
695 GLX_surf
->destroy
= glXDestroyWindow
;
697 get_drawable_size(GLX_dpy
->dpy
, window
, &width
, &height
);
698 GLX_surf
->Base
.Width
= width
;
699 GLX_surf
->Base
.Height
= height
;
701 return &GLX_surf
->Base
;
705 GLX_eglCreatePixmapSurface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
706 _EGLConfig
*conf
, EGLNativePixmapType pixmap
,
707 const EGLint
*attrib_list
)
709 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
710 struct GLX_egl_surface
*GLX_surf
;
715 GLX_surf
= CALLOC_STRUCT(GLX_egl_surface
);
717 _eglError(EGL_BAD_ALLOC
, "eglCreatePixmapSurface");
721 if (!_eglInitSurface(&GLX_surf
->Base
, disp
, EGL_PIXMAP_BIT
,
722 conf
, attrib_list
)) {
727 GLX_surf
->drawable
= pixmap
;
729 if (GLX_dpy
->have_1_3
) {
730 GLX_surf
->glx_drawable
=
731 glXCreatePixmap(GLX_dpy
->dpy
,
732 GLX_dpy
->fbconfigs
[GLX_egl_config_index(conf
)],
733 GLX_surf
->drawable
, NULL
);
735 else if (GLX_dpy
->have_fbconfig
) {
736 GLXFBConfig fbconfig
= GLX_dpy
->fbconfigs
[GLX_egl_config_index(conf
)];
737 XVisualInfo
*vinfo
= glXGetVisualFromFBConfig(GLX_dpy
->dpy
, fbconfig
);
739 GLX_surf
->glx_drawable
=
740 glXCreateGLXPixmap(GLX_dpy
->dpy
, vinfo
, GLX_surf
->drawable
);
745 GLX_surf
->glx_drawable
=
746 glXCreateGLXPixmap(GLX_dpy
->dpy
,
747 &GLX_dpy
->visuals
[GLX_egl_config_index(conf
)],
751 if (!GLX_surf
->glx_drawable
) {
756 GLX_surf
->destroy
= (GLX_dpy
->have_1_3
) ?
757 glXDestroyPixmap
: glXDestroyGLXPixmap
;
759 get_drawable_size(GLX_dpy
->dpy
, pixmap
, &width
, &height
);
760 GLX_surf
->Base
.Width
= width
;
761 GLX_surf
->Base
.Height
= height
;
763 return &GLX_surf
->Base
;
767 GLX_eglCreatePbufferSurface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
768 _EGLConfig
*conf
, const EGLint
*attrib_list
)
770 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
771 struct GLX_egl_surface
*GLX_surf
;
777 GLX_surf
= CALLOC_STRUCT(GLX_egl_surface
);
779 _eglError(EGL_BAD_ALLOC
, "eglCreatePbufferSurface");
783 if (!_eglInitSurface(&GLX_surf
->Base
, disp
, EGL_PBUFFER_BIT
,
784 conf
, attrib_list
)) {
792 GLX_surf
->drawable
= None
;
794 if (GLX_dpy
->have_1_3
) {
795 /* put geometry in attribs */
796 if (GLX_surf
->Base
.Width
) {
797 attribs
[i
++] = GLX_PBUFFER_WIDTH
;
798 attribs
[i
++] = GLX_surf
->Base
.Width
;
800 if (GLX_surf
->Base
.Height
) {
801 attribs
[i
++] = GLX_PBUFFER_HEIGHT
;
802 attribs
[i
++] = GLX_surf
->Base
.Height
;
806 GLX_surf
->glx_drawable
=
807 glXCreatePbuffer(GLX_dpy
->dpy
,
808 GLX_dpy
->fbconfigs
[GLX_egl_config_index(conf
)],
811 else if (GLX_dpy
->have_pbuffer
) {
812 GLX_surf
->glx_drawable
= GLX_dpy
->glXCreateGLXPbufferSGIX(
814 GLX_dpy
->fbconfigs
[GLX_egl_config_index(conf
)],
815 GLX_surf
->Base
.Width
,
816 GLX_surf
->Base
.Height
,
820 if (!GLX_surf
->glx_drawable
) {
825 GLX_surf
->destroy
= (GLX_dpy
->have_1_3
) ?
826 glXDestroyPbuffer
: GLX_dpy
->glXDestroyGLXPbufferSGIX
;
828 return &GLX_surf
->Base
;
833 GLX_eglDestroySurface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
837 if (!_eglIsSurfaceBound(surf
))
838 destroy_surface(disp
, surf
);
845 GLX_eglSwapBuffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
847 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
848 struct GLX_egl_surface
*GLX_surf
= GLX_egl_surface(draw
);
852 glXSwapBuffers(GLX_dpy
->dpy
, GLX_surf
->glx_drawable
);
858 * Called from eglGetProcAddress() via drv->API.GetProcAddress().
861 GLX_eglGetProcAddress(_EGLDriver
*drv
, const char *procname
)
865 return (_EGLProc
) glXGetProcAddress((const GLubyte
*) procname
);
869 GLX_eglWaitClient(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*ctx
)
880 GLX_eglWaitNative(_EGLDriver
*drv
, _EGLDisplay
*dpy
, EGLint engine
)
885 if (engine
!= EGL_CORE_NATIVE_ENGINE
)
886 return _eglError(EGL_BAD_PARAMETER
, "eglWaitNative");
892 GLX_Unload(_EGLDriver
*drv
)
894 struct GLX_egl_driver
*GLX_drv
= GLX_egl_driver(drv
);
900 * This is the main entrypoint into the driver, called by libEGL.
901 * Create a new _EGLDriver object and init its dispatch table.
904 _eglMain(const char *args
)
906 struct GLX_egl_driver
*GLX_drv
= CALLOC_STRUCT(GLX_egl_driver
);
913 _eglInitDriverFallbacks(&GLX_drv
->Base
);
914 GLX_drv
->Base
.API
.Initialize
= GLX_eglInitialize
;
915 GLX_drv
->Base
.API
.Terminate
= GLX_eglTerminate
;
916 GLX_drv
->Base
.API
.CreateContext
= GLX_eglCreateContext
;
917 GLX_drv
->Base
.API
.MakeCurrent
= GLX_eglMakeCurrent
;
918 GLX_drv
->Base
.API
.CreateWindowSurface
= GLX_eglCreateWindowSurface
;
919 GLX_drv
->Base
.API
.CreatePixmapSurface
= GLX_eglCreatePixmapSurface
;
920 GLX_drv
->Base
.API
.CreatePbufferSurface
= GLX_eglCreatePbufferSurface
;
921 GLX_drv
->Base
.API
.DestroySurface
= GLX_eglDestroySurface
;
922 GLX_drv
->Base
.API
.SwapBuffers
= GLX_eglSwapBuffers
;
923 GLX_drv
->Base
.API
.GetProcAddress
= GLX_eglGetProcAddress
;
924 GLX_drv
->Base
.API
.WaitClient
= GLX_eglWaitClient
;
925 GLX_drv
->Base
.API
.WaitNative
= GLX_eglWaitNative
;
927 GLX_drv
->Base
.Name
= "GLX";
928 GLX_drv
->Base
.Unload
= GLX_Unload
;
930 return &GLX_drv
->Base
;