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
;
167 EGLint conformant
, config_caveat
, surface_type
;
169 for (i
= 0; i
< ARRAY_SIZE(fbconfig_attributes
); i
++) {
170 attr
= fbconfig_attributes
[i
].attr
;
171 egl_attr
= fbconfig_attributes
[i
].egl_attr
;
172 err
= glXGetFBConfigAttrib(dpy
, fbconfig
, attr
, &val
);
174 if (err
== GLX_BAD_ATTRIBUTE
) {
181 _eglSetConfigKey(&GLX_conf
->Base
, egl_attr
, val
);
186 /* must have rgba bit */
187 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_RENDER_TYPE
, &val
);
188 if (!(val
& GLX_RGBA_BIT
))
191 conformant
= EGL_OPENGL_BIT
;
192 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_CONFIG_CAVEAT
, &val
);
193 if (val
== GLX_SLOW_CONFIG
)
194 config_caveat
= EGL_SLOW_CONFIG
;
195 if (val
== GLX_NON_CONFORMANT_CONFIG
)
196 conformant
&= ~EGL_OPENGL_BIT
;
197 if (!(conformant
& EGL_OPENGL_ES_BIT
))
198 config_caveat
= EGL_NON_CONFORMANT_CONFIG
;
200 _eglSetConfigKey(&GLX_conf
->Base
, EGL_CONFIG_CAVEAT
, config_caveat
);
203 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_DRAWABLE_TYPE
, &val
);
204 if (val
& GLX_WINDOW_BIT
)
205 surface_type
|= EGL_WINDOW_BIT
;
206 if (val
& GLX_PIXMAP_BIT
)
207 surface_type
|= EGL_PIXMAP_BIT
;
208 if (val
& GLX_PBUFFER_BIT
)
209 surface_type
|= EGL_PBUFFER_BIT
;
211 /* pixmap and pbuffer surfaces must be single-buffered in EGL */
212 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_DOUBLEBUFFER
, &val
);
213 GLX_conf
->double_buffered
= val
;
214 if (GLX_conf
->double_buffered
) {
215 surface_type
&= ~(EGL_PIXMAP_BIT
| EGL_PBUFFER_BIT
);
220 _eglSetConfigKey(&GLX_conf
->Base
, EGL_SURFACE_TYPE
, surface_type
);
225 static const struct {
228 } visual_attributes
[] = {
229 /* table 3.7 of GLX 1.4 */
231 { GLX_BUFFER_SIZE
, EGL_BUFFER_SIZE
},
232 { GLX_LEVEL
, EGL_LEVEL
},
233 { GLX_RED_SIZE
, EGL_RED_SIZE
},
234 { GLX_GREEN_SIZE
, EGL_GREEN_SIZE
},
235 { GLX_BLUE_SIZE
, EGL_BLUE_SIZE
},
236 { GLX_ALPHA_SIZE
, EGL_ALPHA_SIZE
},
237 { GLX_DEPTH_SIZE
, EGL_DEPTH_SIZE
},
238 { GLX_STENCIL_SIZE
, EGL_STENCIL_SIZE
},
239 { GLX_SAMPLE_BUFFERS
, EGL_SAMPLE_BUFFERS
},
240 { GLX_SAMPLES
, EGL_SAMPLES
},
244 convert_visual(Display
*dpy
, XVisualInfo
*vinfo
,
245 struct GLX_egl_config
*GLX_conf
)
247 int err
, attr
, egl_attr
, val
;
249 EGLint conformant
, config_caveat
, surface_type
;
251 /* the visual must support OpenGL */
252 err
= glXGetConfig(dpy
, vinfo
, GLX_USE_GL
, &val
);
256 for (i
= 0; i
< ARRAY_SIZE(visual_attributes
); i
++) {
257 attr
= visual_attributes
[i
].attr
;
258 egl_attr
= fbconfig_attributes
[i
].egl_attr
;
259 err
= glXGetConfig(dpy
, vinfo
, attr
, &val
);
261 if (err
== GLX_BAD_ATTRIBUTE
) {
268 _eglSetConfigKey(&GLX_conf
->Base
, egl_attr
, val
);
273 glXGetConfig(dpy
, vinfo
, GLX_RGBA
, &val
);
277 conformant
= EGL_OPENGL_BIT
;
278 glXGetConfig(dpy
, vinfo
, GLX_VISUAL_CAVEAT_EXT
, &val
);
279 if (val
== GLX_SLOW_CONFIG
)
280 config_caveat
= EGL_SLOW_CONFIG
;
281 if (val
== GLX_NON_CONFORMANT_CONFIG
)
282 conformant
&= ~EGL_OPENGL_BIT
;
283 if (!(conformant
& EGL_OPENGL_ES_BIT
))
284 config_caveat
= EGL_NON_CONFORMANT_CONFIG
;
286 _eglSetConfigKey(&GLX_conf
->Base
, EGL_CONFIG_CAVEAT
, config_caveat
);
287 _eglSetConfigKey(&GLX_conf
->Base
, EGL_NATIVE_VISUAL_ID
, vinfo
->visualid
);
288 _eglSetConfigKey(&GLX_conf
->Base
, EGL_NATIVE_VISUAL_TYPE
, vinfo
->class);
290 /* pixmap and pbuffer surfaces must be single-buffered in EGL */
291 glXGetConfig(dpy
, vinfo
, GLX_DOUBLEBUFFER
, &val
);
292 GLX_conf
->double_buffered
= val
;
293 surface_type
= EGL_WINDOW_BIT
;
294 /* pixmap surfaces must be single-buffered in EGL */
295 if (!GLX_conf
->double_buffered
)
296 surface_type
|= EGL_PIXMAP_BIT
;
298 _eglSetConfigKey(&GLX_conf
->Base
, EGL_SURFACE_TYPE
, surface_type
);
300 _eglSetConfigKey(&GLX_conf
->Base
, EGL_NATIVE_RENDERABLE
, EGL_TRUE
);
307 fix_config(struct GLX_egl_display
*GLX_dpy
, struct GLX_egl_config
*GLX_conf
)
309 _EGLConfig
*conf
= &GLX_conf
->Base
;
310 EGLint surface_type
, r
, g
, b
, a
;
312 surface_type
= GET_CONFIG_ATTRIB(conf
, EGL_SURFACE_TYPE
);
313 if (!GLX_conf
->double_buffered
&& GLX_dpy
->single_buffered_quirk
) {
314 /* some GLX impls do not like single-buffered window surface */
315 surface_type
&= ~EGL_WINDOW_BIT
;
316 /* pbuffer bit is usually not set */
317 if (GLX_dpy
->have_pbuffer
)
318 surface_type
|= EGL_PBUFFER_BIT
;
319 SET_CONFIG_ATTRIB(conf
, EGL_SURFACE_TYPE
, surface_type
);
322 /* no visual attribs unless window bit is set */
323 if (!(surface_type
& EGL_WINDOW_BIT
)) {
324 SET_CONFIG_ATTRIB(conf
, EGL_NATIVE_VISUAL_ID
, 0);
325 SET_CONFIG_ATTRIB(conf
, EGL_NATIVE_VISUAL_TYPE
, EGL_NONE
);
328 /* make sure buffer size is set correctly */
329 r
= GET_CONFIG_ATTRIB(conf
, EGL_RED_SIZE
);
330 g
= GET_CONFIG_ATTRIB(conf
, EGL_GREEN_SIZE
);
331 b
= GET_CONFIG_ATTRIB(conf
, EGL_BLUE_SIZE
);
332 a
= GET_CONFIG_ATTRIB(conf
, EGL_ALPHA_SIZE
);
333 SET_CONFIG_ATTRIB(conf
, EGL_BUFFER_SIZE
, r
+ g
+ b
+ a
);
338 create_configs(_EGLDisplay
*dpy
, struct GLX_egl_display
*GLX_dpy
,
341 EGLint num_configs
= 0, i
;
344 if (GLX_dpy
->have_fbconfig
) {
345 GLX_dpy
->fbconfigs
= glXGetFBConfigs(GLX_dpy
->dpy
, screen
, &num_configs
);
348 XVisualInfo vinfo_template
;
351 vinfo_template
.screen
= screen
;
352 mask
= VisualScreenMask
;
353 GLX_dpy
->visuals
= XGetVisualInfo(GLX_dpy
->dpy
, mask
, &vinfo_template
,
360 for (i
= 0; i
< num_configs
; i
++) {
361 struct GLX_egl_config
*GLX_conf
, template;
364 memset(&template, 0, sizeof(template));
365 _eglInitConfig(&template.Base
, dpy
, id
);
366 if (GLX_dpy
->have_fbconfig
)
367 ok
= convert_fbconfig(GLX_dpy
->dpy
, GLX_dpy
->fbconfigs
[i
], &template);
369 ok
= convert_visual(GLX_dpy
->dpy
, &GLX_dpy
->visuals
[i
], &template);
373 fix_config(GLX_dpy
, &template);
374 if (!_eglValidateConfig(&template.Base
, EGL_FALSE
)) {
375 _eglLog(_EGL_DEBUG
, "GLX: failed to validate config %d", i
);
379 GLX_conf
= CALLOC_STRUCT(GLX_egl_config
);
381 memcpy(GLX_conf
, &template, sizeof(template));
384 _eglAddConfig(dpy
, &GLX_conf
->Base
);
394 check_extensions(struct GLX_egl_display
*GLX_dpy
, EGLint screen
)
396 GLX_dpy
->extensions
=
397 glXQueryExtensionsString(GLX_dpy
->dpy
, screen
);
398 if (GLX_dpy
->extensions
) {
399 /* glXGetProcAddress is assumed */
401 if (strstr(GLX_dpy
->extensions
, "GLX_SGI_make_current_read")) {
402 /* GLX 1.3 entry points are used */
403 GLX_dpy
->have_make_current_read
= EGL_TRUE
;
406 if (strstr(GLX_dpy
->extensions
, "GLX_SGIX_fbconfig")) {
407 /* GLX 1.3 entry points are used */
408 GLX_dpy
->have_fbconfig
= EGL_TRUE
;
411 if (strstr(GLX_dpy
->extensions
, "GLX_SGIX_pbuffer")) {
412 GLX_dpy
->glXCreateGLXPbufferSGIX
= (PFNGLXCREATEGLXPBUFFERSGIXPROC
)
413 glXGetProcAddress((const GLubyte
*) "glXCreateGLXPbufferSGIX");
414 GLX_dpy
->glXDestroyGLXPbufferSGIX
= (PFNGLXDESTROYGLXPBUFFERSGIXPROC
)
415 glXGetProcAddress((const GLubyte
*) "glXDestroyGLXPbufferSGIX");
417 if (GLX_dpy
->glXCreateGLXPbufferSGIX
&&
418 GLX_dpy
->glXDestroyGLXPbufferSGIX
&&
419 GLX_dpy
->have_fbconfig
)
420 GLX_dpy
->have_pbuffer
= EGL_TRUE
;
424 if (GLX_dpy
->glx_maj
== 1 && GLX_dpy
->glx_min
>= 3) {
425 GLX_dpy
->have_1_3
= EGL_TRUE
;
426 GLX_dpy
->have_make_current_read
= EGL_TRUE
;
427 GLX_dpy
->have_fbconfig
= EGL_TRUE
;
428 GLX_dpy
->have_pbuffer
= EGL_TRUE
;
434 check_quirks(struct GLX_egl_display
*GLX_dpy
, EGLint screen
)
438 GLX_dpy
->single_buffered_quirk
= EGL_TRUE
;
439 GLX_dpy
->glx_window_quirk
= EGL_TRUE
;
441 vendor
= glXGetClientString(GLX_dpy
->dpy
, GLX_VENDOR
);
442 if (vendor
&& strstr(vendor
, "NVIDIA")) {
443 vendor
= glXQueryServerString(GLX_dpy
->dpy
, screen
, GLX_VENDOR
);
444 if (vendor
&& strstr(vendor
, "NVIDIA")) {
445 _eglLog(_EGL_DEBUG
, "disable quirks");
446 GLX_dpy
->single_buffered_quirk
= EGL_FALSE
;
447 GLX_dpy
->glx_window_quirk
= EGL_FALSE
;
454 * Called via eglInitialize(), GLX_drv->API.Initialize().
457 GLX_eglInitialize(_EGLDriver
*drv
, _EGLDisplay
*disp
,
458 EGLint
*major
, EGLint
*minor
)
460 struct GLX_egl_display
*GLX_dpy
;
464 if (disp
->Platform
!= _EGL_PLATFORM_X11
)
467 GLX_dpy
= CALLOC_STRUCT(GLX_egl_display
);
469 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
471 GLX_dpy
->dpy
= (Display
*) disp
->PlatformDisplay
;
473 GLX_dpy
->dpy
= XOpenDisplay(NULL
);
475 _eglLog(_EGL_WARNING
, "GLX: XOpenDisplay failed");
481 if (!glXQueryVersion(GLX_dpy
->dpy
, &GLX_dpy
->glx_maj
, &GLX_dpy
->glx_min
)) {
482 _eglLog(_EGL_WARNING
, "GLX: glXQueryVersion failed");
483 if (!disp
->PlatformDisplay
)
484 XCloseDisplay(GLX_dpy
->dpy
);
489 check_extensions(GLX_dpy
, DefaultScreen(GLX_dpy
->dpy
));
490 check_quirks(GLX_dpy
, DefaultScreen(GLX_dpy
->dpy
));
492 create_configs(disp
, GLX_dpy
, DefaultScreen(GLX_dpy
->dpy
));
493 if (!_eglGetArraySize(disp
->Configs
)) {
494 _eglLog(_EGL_WARNING
, "GLX: failed to create any config");
495 if (!disp
->PlatformDisplay
)
496 XCloseDisplay(GLX_dpy
->dpy
);
501 disp
->DriverData
= (void *) GLX_dpy
;
502 disp
->ClientAPIsMask
= EGL_OPENGL_BIT
;
504 /* we're supporting EGL 1.4 */
512 * Called via eglTerminate(), drv->API.Terminate().
515 GLX_eglTerminate(_EGLDriver
*drv
, _EGLDisplay
*disp
)
517 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
519 _eglReleaseDisplayResources(drv
, disp
);
520 _eglCleanupDisplay(disp
);
522 if (GLX_dpy
->visuals
)
523 XFree(GLX_dpy
->visuals
);
524 if (GLX_dpy
->fbconfigs
)
525 XFree(GLX_dpy
->fbconfigs
);
527 if (!disp
->PlatformDisplay
)
528 XCloseDisplay(GLX_dpy
->dpy
);
531 disp
->DriverData
= NULL
;
538 * Called via eglCreateContext(), drv->API.CreateContext().
541 GLX_eglCreateContext(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLConfig
*conf
,
542 _EGLContext
*share_list
, const EGLint
*attrib_list
)
544 struct GLX_egl_context
*GLX_ctx
= CALLOC_STRUCT(GLX_egl_context
);
545 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
546 struct GLX_egl_context
*GLX_ctx_shared
= GLX_egl_context(share_list
);
551 _eglError(EGL_BAD_ALLOC
, "eglCreateContext");
555 if (!_eglInitContext(&GLX_ctx
->Base
, disp
, conf
, attrib_list
)) {
560 if (GLX_dpy
->have_fbconfig
)
562 glXCreateNewContext(GLX_dpy
->dpy
,
563 GLX_dpy
->fbconfigs
[GLX_egl_config_index(conf
)],
565 GLX_ctx_shared
? GLX_ctx_shared
->context
: NULL
,
569 glXCreateContext(GLX_dpy
->dpy
,
570 &GLX_dpy
->visuals
[GLX_egl_config_index(conf
)],
571 GLX_ctx_shared
? GLX_ctx_shared
->context
: NULL
,
573 if (!GLX_ctx
->context
) {
578 return &GLX_ctx
->Base
;
583 * Destroy a surface. The display is allowed to be uninitialized.
586 destroy_surface(_EGLDisplay
*disp
, _EGLSurface
*surf
)
588 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
589 struct GLX_egl_surface
*GLX_surf
= GLX_egl_surface(surf
);
591 if (GLX_surf
->destroy
)
592 GLX_surf
->destroy(GLX_dpy
->dpy
, GLX_surf
->glx_drawable
);
599 * Called via eglMakeCurrent(), drv->API.MakeCurrent().
602 GLX_eglMakeCurrent(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*dsurf
,
603 _EGLSurface
*rsurf
, _EGLContext
*ctx
)
605 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
606 struct GLX_egl_surface
*GLX_dsurf
= GLX_egl_surface(dsurf
);
607 struct GLX_egl_surface
*GLX_rsurf
= GLX_egl_surface(rsurf
);
608 struct GLX_egl_context
*GLX_ctx
= GLX_egl_context(ctx
);
609 GLXDrawable ddraw
, rdraw
;
611 EGLBoolean ret
= EGL_FALSE
;
615 /* bind the new context and return the "orphaned" one */
616 if (!_eglBindContext(&ctx
, &dsurf
, &rsurf
))
619 ddraw
= (GLX_dsurf
) ? GLX_dsurf
->glx_drawable
: None
;
620 rdraw
= (GLX_rsurf
) ? GLX_rsurf
->glx_drawable
: None
;
621 cctx
= (GLX_ctx
) ? GLX_ctx
->context
: NULL
;
623 if (GLX_dpy
->have_make_current_read
)
624 ret
= glXMakeContextCurrent(GLX_dpy
->dpy
, ddraw
, rdraw
, cctx
);
625 else if (ddraw
== rdraw
)
626 ret
= glXMakeCurrent(GLX_dpy
->dpy
, ddraw
, cctx
);
629 if (dsurf
&& !_eglIsSurfaceLinked(dsurf
))
630 destroy_surface(disp
, dsurf
);
631 if (rsurf
&& rsurf
!= dsurf
&& !_eglIsSurfaceLinked(rsurf
))
632 destroy_surface(disp
, rsurf
);
635 _eglBindContext(&ctx
, &dsurf
, &rsurf
);
641 /** Get size of given window */
643 get_drawable_size(Display
*dpy
, Drawable d
, uint
*width
, uint
*height
)
648 unsigned int w
, h
, bw
, depth
;
649 stat
= XGetGeometry(dpy
, d
, &root
, &xpos
, &ypos
, &w
, &h
, &bw
, &depth
);
656 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
659 GLX_eglCreateWindowSurface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
660 _EGLConfig
*conf
, EGLNativeWindowType window
,
661 const EGLint
*attrib_list
)
663 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
664 struct GLX_egl_surface
*GLX_surf
;
669 GLX_surf
= CALLOC_STRUCT(GLX_egl_surface
);
671 _eglError(EGL_BAD_ALLOC
, "eglCreateWindowSurface");
675 if (!_eglInitSurface(&GLX_surf
->Base
, disp
, EGL_WINDOW_BIT
,
676 conf
, attrib_list
)) {
681 GLX_surf
->drawable
= window
;
683 if (GLX_dpy
->have_1_3
&& !GLX_dpy
->glx_window_quirk
)
684 GLX_surf
->glx_drawable
=
685 glXCreateWindow(GLX_dpy
->dpy
,
686 GLX_dpy
->fbconfigs
[GLX_egl_config_index(conf
)],
687 GLX_surf
->drawable
, NULL
);
689 GLX_surf
->glx_drawable
= GLX_surf
->drawable
;
691 if (!GLX_surf
->glx_drawable
) {
696 if (GLX_dpy
->have_1_3
&& !GLX_dpy
->glx_window_quirk
)
697 GLX_surf
->destroy
= glXDestroyWindow
;
699 get_drawable_size(GLX_dpy
->dpy
, window
, &width
, &height
);
700 GLX_surf
->Base
.Width
= width
;
701 GLX_surf
->Base
.Height
= height
;
703 return &GLX_surf
->Base
;
707 GLX_eglCreatePixmapSurface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
708 _EGLConfig
*conf
, EGLNativePixmapType pixmap
,
709 const EGLint
*attrib_list
)
711 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
712 struct GLX_egl_surface
*GLX_surf
;
717 GLX_surf
= CALLOC_STRUCT(GLX_egl_surface
);
719 _eglError(EGL_BAD_ALLOC
, "eglCreatePixmapSurface");
723 if (!_eglInitSurface(&GLX_surf
->Base
, disp
, EGL_PIXMAP_BIT
,
724 conf
, attrib_list
)) {
729 GLX_surf
->drawable
= pixmap
;
731 if (GLX_dpy
->have_1_3
) {
732 GLX_surf
->glx_drawable
=
733 glXCreatePixmap(GLX_dpy
->dpy
,
734 GLX_dpy
->fbconfigs
[GLX_egl_config_index(conf
)],
735 GLX_surf
->drawable
, NULL
);
737 else if (GLX_dpy
->have_fbconfig
) {
738 GLXFBConfig fbconfig
= GLX_dpy
->fbconfigs
[GLX_egl_config_index(conf
)];
739 XVisualInfo
*vinfo
= glXGetVisualFromFBConfig(GLX_dpy
->dpy
, fbconfig
);
741 GLX_surf
->glx_drawable
=
742 glXCreateGLXPixmap(GLX_dpy
->dpy
, vinfo
, GLX_surf
->drawable
);
747 GLX_surf
->glx_drawable
=
748 glXCreateGLXPixmap(GLX_dpy
->dpy
,
749 &GLX_dpy
->visuals
[GLX_egl_config_index(conf
)],
753 if (!GLX_surf
->glx_drawable
) {
758 GLX_surf
->destroy
= (GLX_dpy
->have_1_3
) ?
759 glXDestroyPixmap
: glXDestroyGLXPixmap
;
761 get_drawable_size(GLX_dpy
->dpy
, pixmap
, &width
, &height
);
762 GLX_surf
->Base
.Width
= width
;
763 GLX_surf
->Base
.Height
= height
;
765 return &GLX_surf
->Base
;
769 GLX_eglCreatePbufferSurface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
770 _EGLConfig
*conf
, const EGLint
*attrib_list
)
772 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
773 struct GLX_egl_surface
*GLX_surf
;
779 GLX_surf
= CALLOC_STRUCT(GLX_egl_surface
);
781 _eglError(EGL_BAD_ALLOC
, "eglCreatePbufferSurface");
785 if (!_eglInitSurface(&GLX_surf
->Base
, disp
, EGL_PBUFFER_BIT
,
786 conf
, attrib_list
)) {
794 GLX_surf
->drawable
= None
;
796 if (GLX_dpy
->have_1_3
) {
797 /* put geometry in attribs */
798 if (GLX_surf
->Base
.Width
) {
799 attribs
[i
++] = GLX_PBUFFER_WIDTH
;
800 attribs
[i
++] = GLX_surf
->Base
.Width
;
802 if (GLX_surf
->Base
.Height
) {
803 attribs
[i
++] = GLX_PBUFFER_HEIGHT
;
804 attribs
[i
++] = GLX_surf
->Base
.Height
;
808 GLX_surf
->glx_drawable
=
809 glXCreatePbuffer(GLX_dpy
->dpy
,
810 GLX_dpy
->fbconfigs
[GLX_egl_config_index(conf
)],
813 else if (GLX_dpy
->have_pbuffer
) {
814 GLX_surf
->glx_drawable
= GLX_dpy
->glXCreateGLXPbufferSGIX(
816 GLX_dpy
->fbconfigs
[GLX_egl_config_index(conf
)],
817 GLX_surf
->Base
.Width
,
818 GLX_surf
->Base
.Height
,
822 if (!GLX_surf
->glx_drawable
) {
827 GLX_surf
->destroy
= (GLX_dpy
->have_1_3
) ?
828 glXDestroyPbuffer
: GLX_dpy
->glXDestroyGLXPbufferSGIX
;
830 return &GLX_surf
->Base
;
835 GLX_eglDestroySurface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
839 if (!_eglIsSurfaceBound(surf
))
840 destroy_surface(disp
, surf
);
847 GLX_eglSwapBuffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
849 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
850 struct GLX_egl_surface
*GLX_surf
= GLX_egl_surface(draw
);
854 glXSwapBuffers(GLX_dpy
->dpy
, GLX_surf
->glx_drawable
);
860 * Called from eglGetProcAddress() via drv->API.GetProcAddress().
863 GLX_eglGetProcAddress(_EGLDriver
*drv
, const char *procname
)
867 return (_EGLProc
) glXGetProcAddress((const GLubyte
*) procname
);
871 GLX_eglWaitClient(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*ctx
)
882 GLX_eglWaitNative(_EGLDriver
*drv
, _EGLDisplay
*dpy
, EGLint engine
)
887 if (engine
!= EGL_CORE_NATIVE_ENGINE
)
888 return _eglError(EGL_BAD_PARAMETER
, "eglWaitNative");
894 GLX_Unload(_EGLDriver
*drv
)
896 struct GLX_egl_driver
*GLX_drv
= GLX_egl_driver(drv
);
902 * This is the main entrypoint into the driver, called by libEGL.
903 * Create a new _EGLDriver object and init its dispatch table.
906 _eglMain(const char *args
)
908 struct GLX_egl_driver
*GLX_drv
= CALLOC_STRUCT(GLX_egl_driver
);
915 _eglInitDriverFallbacks(&GLX_drv
->Base
);
916 GLX_drv
->Base
.API
.Initialize
= GLX_eglInitialize
;
917 GLX_drv
->Base
.API
.Terminate
= GLX_eglTerminate
;
918 GLX_drv
->Base
.API
.CreateContext
= GLX_eglCreateContext
;
919 GLX_drv
->Base
.API
.MakeCurrent
= GLX_eglMakeCurrent
;
920 GLX_drv
->Base
.API
.CreateWindowSurface
= GLX_eglCreateWindowSurface
;
921 GLX_drv
->Base
.API
.CreatePixmapSurface
= GLX_eglCreatePixmapSurface
;
922 GLX_drv
->Base
.API
.CreatePbufferSurface
= GLX_eglCreatePbufferSurface
;
923 GLX_drv
->Base
.API
.DestroySurface
= GLX_eglDestroySurface
;
924 GLX_drv
->Base
.API
.SwapBuffers
= GLX_eglSwapBuffers
;
925 GLX_drv
->Base
.API
.GetProcAddress
= GLX_eglGetProcAddress
;
926 GLX_drv
->Base
.API
.WaitClient
= GLX_eglWaitClient
;
927 GLX_drv
->Base
.API
.WaitNative
= GLX_eglWaitNative
;
929 GLX_drv
->Base
.Name
= "GLX";
930 GLX_drv
->Base
.Unload
= GLX_Unload
;
932 return &GLX_drv
->Base
;