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 **************************************************************************/
29 * EGL / softpipe / xlib winsys module
37 #include <X11/Xutil.h>
39 #include "pipe/p_compiler.h"
40 #include "pipe/p_format.h"
41 #include "pipe/p_state.h"
42 #include "pipe/internal/p_winsys_screen.h"
43 #include "util/u_memory.h"
44 #include "util/u_math.h"
45 #include "softpipe/sp_winsys.h"
46 #include "softpipe/sp_texture.h"
48 #include "eglconfig.h"
49 #include "eglconfigutil.h"
50 #include "eglcontext.h"
51 #include "egldisplay.h"
52 #include "egldriver.h"
53 #include "eglglobals.h"
55 #include "eglsurface.h"
57 #include "state_tracker/st_public.h"
59 #include "sw_winsys.h"
62 /** subclass of _EGLDriver */
63 struct xlib_egl_driver
65 _EGLDriver Base
; /**< base class */
70 /** driver data of _EGLDisplay */
71 struct xlib_egl_display
75 struct pipe_winsys
*winsys
;
76 struct pipe_screen
*screen
;
80 /** subclass of _EGLContext */
81 struct xlib_egl_context
83 _EGLContext Base
; /**< base class */
85 struct pipe_context
*pipe
; /**< Gallium driver context */
86 struct st_context
*Context
; /**< Mesa/gallium state tracker context */
90 /** subclass of _EGLSurface */
91 struct xlib_egl_surface
93 _EGLSurface Base
; /**< base class */
95 /* These are set for window surface */
96 Display
*Dpy
; /**< The X Display of the window */
97 Window Win
; /**< The user-created window ID */
101 struct pipe_winsys
*winsys
;
103 struct st_framebuffer
*Framebuffer
;
108 flush_frontbuffer(struct pipe_winsys
*pws
,
109 struct pipe_surface
*psurf
,
110 void *context_private
);
114 static INLINE
struct xlib_egl_driver
*
115 xlib_egl_driver(_EGLDriver
*drv
)
117 return (struct xlib_egl_driver
*) drv
;
121 static INLINE
struct xlib_egl_display
*
122 xlib_egl_display(_EGLDisplay
*dpy
)
124 return (struct xlib_egl_display
*) dpy
->DriverData
;
128 static INLINE
struct xlib_egl_surface
*
129 lookup_surface(_EGLSurface
*surf
)
131 return (struct xlib_egl_surface
*) surf
;
135 static INLINE
struct xlib_egl_context
*
136 lookup_context(_EGLContext
*ctx
)
138 return (struct xlib_egl_context
*) ctx
;
143 * Create the EGLConfigs. (one per X visual)
146 create_configs(struct xlib_egl_display
*xdpy
, _EGLDisplay
*disp
)
148 static const EGLint all_apis
= (EGL_OPENGL_ES_BIT
|
152 XVisualInfo
*visInfo
, visTemplate
;
155 /* get list of all X visuals, create an EGL config for each */
156 visTemplate
.screen
= DefaultScreen(xdpy
->Dpy
);
157 visInfo
= XGetVisualInfo(xdpy
->Dpy
, VisualScreenMask
,
158 &visTemplate
, &num_visuals
);
160 printf("egl_xlib.c: couldn't get any X visuals\n");
164 for (i
= 0; i
< num_visuals
; i
++) {
165 _EGLConfig
*config
= calloc(1, sizeof(_EGLConfig
));
167 int rbits
= util_bitcount(visInfo
[i
].red_mask
);
168 int gbits
= util_bitcount(visInfo
[i
].green_mask
);
169 int bbits
= util_bitcount(visInfo
[i
].blue_mask
);
170 int abits
= bbits
== 8 ? 8 : 0;
173 int visid
= visInfo
[i
].visualid
;
174 #if defined(__cplusplus) || defined(c_plusplus)
175 int vistype
= visInfo
[i
].c_class
;
177 int vistype
= visInfo
[i
].class;
180 _eglInitConfig(config
, id
);
181 SET_CONFIG_ATTRIB(config
, EGL_BUFFER_SIZE
, rbits
+ gbits
+ bbits
+ abits
);
182 SET_CONFIG_ATTRIB(config
, EGL_RED_SIZE
, rbits
);
183 SET_CONFIG_ATTRIB(config
, EGL_GREEN_SIZE
, gbits
);
184 SET_CONFIG_ATTRIB(config
, EGL_BLUE_SIZE
, bbits
);
185 SET_CONFIG_ATTRIB(config
, EGL_ALPHA_SIZE
, abits
);
186 SET_CONFIG_ATTRIB(config
, EGL_DEPTH_SIZE
, zbits
);
187 SET_CONFIG_ATTRIB(config
, EGL_STENCIL_SIZE
, sbits
);
188 SET_CONFIG_ATTRIB(config
, EGL_NATIVE_VISUAL_ID
, visid
);
189 SET_CONFIG_ATTRIB(config
, EGL_NATIVE_VISUAL_TYPE
, vistype
);
190 SET_CONFIG_ATTRIB(config
, EGL_NATIVE_RENDERABLE
, EGL_FALSE
);
191 SET_CONFIG_ATTRIB(config
, EGL_CONFORMANT
, all_apis
);
192 SET_CONFIG_ATTRIB(config
, EGL_RENDERABLE_TYPE
, all_apis
);
193 SET_CONFIG_ATTRIB(config
, EGL_SURFACE_TYPE
, EGL_WINDOW_BIT
| EGL_PBUFFER_BIT
);
194 SET_CONFIG_ATTRIB(config
, EGL_BIND_TO_TEXTURE_RGBA
, EGL_TRUE
);
195 SET_CONFIG_ATTRIB(config
, EGL_BIND_TO_TEXTURE_RGB
, EGL_TRUE
);
197 _eglAddConfig(disp
, config
);
205 * Called via eglInitialize(), drv->API.Initialize().
208 xlib_eglInitialize(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
209 EGLint
*major
, EGLint
*minor
)
211 struct xlib_egl_driver
*xdrv
= xlib_egl_driver(drv
);
212 struct xlib_egl_display
*xdpy
;
214 xdpy
= CALLOC_STRUCT(xlib_egl_display
);
216 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
218 xdpy
->Dpy
= (Display
*) dpy
->NativeDisplay
;
220 xdpy
->Dpy
= XOpenDisplay(NULL
);
227 /* create winsys and pipe screen */
228 xdpy
->winsys
= create_sw_winsys();
231 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
233 xdpy
->winsys
->flush_frontbuffer
= flush_frontbuffer
;
234 xdpy
->screen
= softpipe_create_screen(xdpy
->winsys
);
238 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
241 dpy
->DriverData
= (void *) xdpy
;
242 dpy
->ClientAPIsMask
= xdrv
->apis
;
244 create_configs(xdpy
, dpy
);
246 /* we're supporting EGL 1.4 */
255 * Called via eglTerminate(), drv->API.Terminate().
258 xlib_eglTerminate(_EGLDriver
*drv
, _EGLDisplay
*dpy
)
260 struct xlib_egl_display
*xdpy
= xlib_egl_display(dpy
);
262 _eglReleaseDisplayResources(drv
, dpy
);
263 _eglCleanupDisplay(dpy
);
265 xdpy
->screen
->destroy(xdpy
->screen
);
268 if (!dpy
->NativeDisplay
)
269 XCloseDisplay(xdpy
->Dpy
);
277 xlib_eglGetProcAddress(const char *procname
)
279 return (_EGLProc
) st_get_proc_address(procname
);
284 get_drawable_visual_info(Display
*dpy
, Drawable d
, XVisualInfo
*visInfo
)
286 XWindowAttributes attr
;
287 XVisualInfo visTemp
, *vis
;
290 XGetWindowAttributes(dpy
, d
, &attr
);
292 visTemp
.screen
= DefaultScreen(dpy
);
293 visTemp
.visualid
= attr
.visual
->visualid
;
294 vis
= XGetVisualInfo(dpy
,
295 (VisualScreenMask
| VisualIDMask
),
296 &visTemp
, &num_visuals
);
305 /** Get size of given window */
307 get_drawable_size(Display
*dpy
, Drawable d
, uint
*width
, uint
*height
)
312 unsigned int w
, h
, bw
, depth
;
313 stat
= XGetGeometry(dpy
, d
, &root
, &xpos
, &ypos
, &w
, &h
, &bw
, &depth
);
321 check_and_update_buffer_size(struct xlib_egl_surface
*surface
)
324 if (surface
->Base
.Type
== EGL_PBUFFER_BIT
) {
325 width
= surface
->Base
.Width
;
326 height
= surface
->Base
.Height
;
329 get_drawable_size(surface
->Dpy
, surface
->Win
, &width
, &height
);
331 st_resize_framebuffer(surface
->Framebuffer
, width
, height
);
332 surface
->Base
.Width
= width
;
333 surface
->Base
.Height
= height
;
339 display_surface(struct pipe_winsys
*pws
,
340 struct pipe_surface
*psurf
,
341 struct xlib_egl_surface
*xsurf
)
343 struct softpipe_texture
*spt
= softpipe_texture(psurf
->texture
);
347 if (xsurf
->Base
.Type
== EGL_PBUFFER_BIT
)
350 ximage
= XCreateImage(xsurf
->Dpy
,
351 xsurf
->VisInfo
.visual
,
352 xsurf
->VisInfo
.depth
,
353 ZPixmap
, 0, /* format, offset */
357 0); /* bytes_per_line */
360 assert(ximage
->format
);
361 assert(ximage
->bitmap_unit
);
363 data
= pws
->buffer_map(pws
, spt
->buffer
, 0);
365 /* update XImage's fields */
367 ximage
->width
= psurf
->width
;
368 ximage
->height
= psurf
->height
;
369 ximage
->bytes_per_line
= spt
->stride
[psurf
->level
];
371 XPutImage(xsurf
->Dpy
, xsurf
->Win
, xsurf
->Gc
,
372 ximage
, 0, 0, 0, 0, psurf
->width
, psurf
->height
);
374 XSync(xsurf
->Dpy
, 0);
377 XDestroyImage(ximage
);
379 pws
->buffer_unmap(pws
, spt
->buffer
);
384 /** Display gallium surface in X window */
386 flush_frontbuffer(struct pipe_winsys
*pws
,
387 struct pipe_surface
*psurf
,
388 void *context_private
)
390 struct xlib_egl_surface
*xsurf
= (struct xlib_egl_surface
*) context_private
;
391 display_surface(pws
, psurf
, xsurf
);
397 * Called via eglCreateContext(), drv->API.CreateContext().
400 xlib_eglCreateContext(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
401 _EGLContext
*share_list
, const EGLint
*attrib_list
)
403 struct xlib_egl_display
*xdpy
= xlib_egl_display(dpy
);
404 struct xlib_egl_context
*ctx
;
405 struct st_context
*share_ctx
= NULL
; /* XXX fix */
406 __GLcontextModes visual
;
408 ctx
= CALLOC_STRUCT(xlib_egl_context
);
412 /* let EGL lib init the common stuff */
413 if (!_eglInitContext(drv
, &ctx
->Base
, conf
, attrib_list
)) {
418 /* API-dependent context creation */
419 switch (ctx
->Base
.ClientAPI
) {
421 case EGL_OPENGL_ES_API
:
422 _eglLog(_EGL_DEBUG
, "Create Context for ES version %d\n",
423 ctx
->Base
.ClientVersion
);
426 /* create a softpipe context */
427 ctx
->pipe
= softpipe_create(xdpy
->screen
);
428 /* Now do xlib / state tracker inits here */
429 _eglConfigToContextModesRec(conf
, &visual
);
430 ctx
->Context
= st_create_context(ctx
->pipe
, &visual
, share_ctx
);
433 _eglError(EGL_BAD_MATCH
, "eglCreateContext(unsupported API)");
443 xlib_eglDestroyContext(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*ctx
)
445 struct xlib_egl_context
*context
= lookup_context(ctx
);
447 if (!_eglIsContextBound(&context
->Base
)) {
448 /* API-dependent clean-up */
449 switch (context
->Base
.ClientAPI
) {
450 case EGL_OPENGL_ES_API
:
454 st_destroy_context(context
->Context
);
466 * Called via eglMakeCurrent(), drv->API.MakeCurrent().
469 xlib_eglMakeCurrent(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
470 _EGLSurface
*draw
, _EGLSurface
*read
, _EGLContext
*ctx
)
472 struct xlib_egl_context
*context
= lookup_context(ctx
);
473 struct xlib_egl_surface
*draw_surf
= lookup_surface(draw
);
474 struct xlib_egl_surface
*read_surf
= lookup_surface(read
);
475 struct st_context
*oldcontext
= NULL
;
478 oldctx
= _eglGetCurrentContext();
479 if (oldctx
&& _eglIsContextLinked(oldctx
))
480 oldcontext
= st_get_current();
482 if (!_eglMakeCurrent(drv
, dpy
, draw
, read
, ctx
))
485 /* Flush before switching context. Check client API? */
487 st_flush(oldcontext
, PIPE_FLUSH_RENDER_CACHE
| PIPE_FLUSH_FRAME
, NULL
);
488 st_make_current((context
? context
->Context
: NULL
),
489 (draw_surf
? draw_surf
->Framebuffer
: NULL
),
490 (read_surf
? read_surf
->Framebuffer
: NULL
));
493 check_and_update_buffer_size(draw_surf
);
494 if (read_surf
&& read_surf
!= draw_surf
)
495 check_and_update_buffer_size(draw_surf
);
501 static enum pipe_format
502 choose_color_format(const __GLcontextModes
*visual
)
504 if (visual
->redBits
== 8 &&
505 visual
->greenBits
== 8 &&
506 visual
->blueBits
== 8 &&
507 visual
->alphaBits
== 8) {
508 /* XXX this really also depends on the ordering of R,G,B,A */
509 return PIPE_FORMAT_A8R8G8B8_UNORM
;
513 return PIPE_FORMAT_NONE
;
518 static enum pipe_format
519 choose_depth_format(const __GLcontextModes
*visual
)
521 if (visual
->depthBits
> 0)
522 return PIPE_FORMAT_S8Z24_UNORM
;
524 return PIPE_FORMAT_NONE
;
528 static enum pipe_format
529 choose_stencil_format(const __GLcontextModes
*visual
)
531 if (visual
->stencilBits
> 0)
532 return PIPE_FORMAT_S8Z24_UNORM
;
534 return PIPE_FORMAT_NONE
;
539 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
542 xlib_eglCreateWindowSurface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLConfig
*conf
,
543 NativeWindowType window
, const EGLint
*attrib_list
)
545 struct xlib_egl_display
*xdpy
= xlib_egl_display(disp
);
546 struct xlib_egl_surface
*surf
;
547 __GLcontextModes visual
;
550 surf
= CALLOC_STRUCT(xlib_egl_surface
);
554 /* Let EGL lib init the common stuff */
555 if (!_eglInitSurface(drv
, &surf
->Base
, EGL_WINDOW_BIT
,
556 conf
, attrib_list
)) {
562 * Now init the Xlib and gallium stuff
564 surf
->Win
= (Window
) window
; /* The X window ID */
565 surf
->Dpy
= xdpy
->Dpy
; /* The X display */
566 surf
->Gc
= XCreateGC(surf
->Dpy
, surf
->Win
, 0, NULL
);
568 surf
->winsys
= xdpy
->winsys
;
570 _eglConfigToContextModesRec(conf
, &visual
);
571 get_drawable_size(surf
->Dpy
, surf
->Win
, &width
, &height
);
572 get_drawable_visual_info(surf
->Dpy
, surf
->Win
, &surf
->VisInfo
);
574 surf
->Base
.Width
= width
;
575 surf
->Base
.Height
= height
;
577 /* Create GL statetracker framebuffer */
578 surf
->Framebuffer
= st_create_framebuffer(&visual
,
579 choose_color_format(&visual
),
580 choose_depth_format(&visual
),
581 choose_stencil_format(&visual
),
585 st_resize_framebuffer(surf
->Framebuffer
, width
, height
);
592 xlib_eglCreatePbufferSurface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLConfig
*conf
,
593 const EGLint
*attrib_list
)
595 struct xlib_egl_display
*xdpy
= xlib_egl_display(disp
);
596 struct xlib_egl_surface
*surf
;
597 __GLcontextModes visual
;
599 EGLBoolean bind_texture
;
601 surf
= CALLOC_STRUCT(xlib_egl_surface
);
603 _eglError(EGL_BAD_ALLOC
, "eglCreatePbufferSurface");
607 if (!_eglInitSurface(drv
, &surf
->Base
, EGL_PBUFFER_BIT
,
608 conf
, attrib_list
)) {
612 if (surf
->Base
.Width
< 0 || surf
->Base
.Height
< 0) {
613 _eglError(EGL_BAD_PARAMETER
, "eglCreatePbufferSurface");
618 bind_texture
= (surf
->Base
.TextureFormat
!= EGL_NO_TEXTURE
);
619 width
= (uint
) surf
->Base
.Width
;
620 height
= (uint
) surf
->Base
.Height
;
621 if ((surf
->Base
.TextureTarget
== EGL_NO_TEXTURE
&& bind_texture
) ||
622 (surf
->Base
.TextureTarget
!= EGL_NO_TEXTURE
&& !bind_texture
)) {
623 _eglError(EGL_BAD_MATCH
, "eglCreatePbufferSurface");
627 /* a framebuffer of zero width or height confuses st */
628 if (width
== 0 || height
== 0) {
629 _eglError(EGL_BAD_MATCH
, "eglCreatePbufferSurface");
633 /* no mipmap generation */
634 if (surf
->Base
.MipmapTexture
) {
635 _eglError(EGL_BAD_MATCH
, "eglCreatePbufferSurface");
640 surf
->winsys
= xdpy
->winsys
;
642 _eglConfigToContextModesRec(conf
, &visual
);
644 /* Create GL statetracker framebuffer */
645 surf
->Framebuffer
= st_create_framebuffer(&visual
,
646 choose_color_format(&visual
),
647 choose_depth_format(&visual
),
648 choose_stencil_format(&visual
),
651 st_resize_framebuffer(surf
->Framebuffer
, width
, height
);
658 xlib_eglDestroySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
)
660 struct xlib_egl_surface
*surf
= lookup_surface(surface
);
661 if (!_eglIsSurfaceBound(&surf
->Base
)) {
662 if (surf
->Base
.Type
!= EGL_PBUFFER_BIT
)
663 XFreeGC(surf
->Dpy
, surf
->Gc
);
664 st_unreference_framebuffer(surf
->Framebuffer
);
672 xlib_eglBindTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
673 _EGLSurface
*surface
, EGLint buffer
)
675 struct xlib_egl_surface
*xsurf
= lookup_surface(surface
);
676 struct xlib_egl_context
*xctx
;
677 struct pipe_surface
*psurf
;
678 enum pipe_format format
;
681 if (!xsurf
|| xsurf
->Base
.Type
!= EGL_PBUFFER_BIT
)
682 return _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
683 if (buffer
!= EGL_BACK_BUFFER
)
684 return _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
685 if (xsurf
->Base
.BoundToTexture
)
686 return _eglError(EGL_BAD_ACCESS
, "eglBindTexImage");
688 /* this should be updated when choose_color_format is */
689 switch (xsurf
->Base
.TextureFormat
) {
690 case EGL_TEXTURE_RGB
:
691 format
= PIPE_FORMAT_R8G8B8_UNORM
;
693 case EGL_TEXTURE_RGBA
:
694 format
= PIPE_FORMAT_A8R8G8B8_UNORM
;
697 return _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
700 switch (xsurf
->Base
.TextureTarget
) {
702 target
= ST_TEXTURE_2D
;
705 return _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
709 if (eglGetCurrentSurface(EGL_DRAW
) == surface
) {
710 xctx
= lookup_context(_eglGetCurrentContext());
711 st_flush(xctx
->Context
, PIPE_FLUSH_RENDER_CACHE
| PIPE_FLUSH_FRAME
,
714 else if (_eglIsSurfaceBound(&xsurf
->Base
)) {
715 xctx
= lookup_context(xsurf
->Base
.Binding
);
717 st_finish(xctx
->Context
);
720 st_get_framebuffer_surface(xsurf
->Framebuffer
, ST_SURFACE_BACK_LEFT
,
722 st_bind_texture_surface(psurf
, target
, xsurf
->Base
.MipmapLevel
, format
);
723 xsurf
->Base
.BoundToTexture
= EGL_TRUE
;
730 xlib_eglReleaseTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
733 struct xlib_egl_surface
*xsurf
= lookup_surface(surface
);
734 struct pipe_surface
*psurf
;
736 if (!xsurf
|| xsurf
->Base
.Type
!= EGL_PBUFFER_BIT
||
737 !xsurf
->Base
.BoundToTexture
)
738 return _eglError(EGL_BAD_SURFACE
, "eglReleaseTexImage");
739 if (buffer
!= EGL_BACK_BUFFER
)
740 return _eglError(EGL_BAD_PARAMETER
, "eglReleaseTexImage");
742 st_get_framebuffer_surface(xsurf
->Framebuffer
, ST_SURFACE_BACK_LEFT
,
744 st_unbind_texture_surface(psurf
, ST_TEXTURE_2D
, xsurf
->Base
.MipmapLevel
);
745 xsurf
->Base
.BoundToTexture
= EGL_FALSE
;
752 xlib_eglSwapBuffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*draw
)
754 /* error checking step: */
755 if (!_eglSwapBuffers(drv
, dpy
, draw
))
759 struct xlib_egl_surface
*xsurf
= lookup_surface(draw
);
760 struct pipe_winsys
*pws
= xsurf
->winsys
;
761 struct pipe_surface
*psurf
;
763 st_get_framebuffer_surface(xsurf
->Framebuffer
, ST_SURFACE_BACK_LEFT
,
766 st_notify_swapbuffers(xsurf
->Framebuffer
);
768 display_surface(pws
, psurf
, xsurf
);
770 check_and_update_buffer_size(xsurf
);
778 * Determine which API(s) is(are) present by looking for some specific
782 find_supported_apis(void)
787 handle
= dlopen(NULL
, RTLD_LAZY
| RTLD_LOCAL
);
791 if (dlsym(handle
, "st_api_OpenGL_ES1"))
792 mask
|= EGL_OPENGL_ES_BIT
;
794 if (dlsym(handle
, "st_api_OpenGL_ES2"))
795 mask
|= EGL_OPENGL_ES2_BIT
;
797 if (dlsym(handle
, "st_api_OpenGL"))
798 mask
|= EGL_OPENGL_BIT
;
800 if (dlsym(handle
, "st_api_OpenVG"))
801 mask
|= EGL_OPENVG_BIT
;
810 xlib_Unload(_EGLDriver
*drv
)
812 struct xlib_egl_driver
*xdrv
= xlib_egl_driver(drv
);
818 * This is the main entrypoint into the driver.
819 * Called by libEGL to instantiate an _EGLDriver object.
822 _eglMain(const char *args
)
824 struct xlib_egl_driver
*xdrv
;
826 _eglLog(_EGL_INFO
, "Entering EGL/Xlib _eglMain(%s)", args
);
828 xdrv
= CALLOC_STRUCT(xlib_egl_driver
);
832 _eglInitDriverFallbacks(&xdrv
->Base
);
833 xdrv
->Base
.API
.Initialize
= xlib_eglInitialize
;
834 xdrv
->Base
.API
.Terminate
= xlib_eglTerminate
;
835 xdrv
->Base
.API
.GetProcAddress
= xlib_eglGetProcAddress
;
836 xdrv
->Base
.API
.CreateContext
= xlib_eglCreateContext
;
837 xdrv
->Base
.API
.DestroyContext
= xlib_eglDestroyContext
;
838 xdrv
->Base
.API
.CreateWindowSurface
= xlib_eglCreateWindowSurface
;
839 xdrv
->Base
.API
.CreatePbufferSurface
= xlib_eglCreatePbufferSurface
;
840 xdrv
->Base
.API
.DestroySurface
= xlib_eglDestroySurface
;
841 xdrv
->Base
.API
.BindTexImage
= xlib_eglBindTexImage
;
842 xdrv
->Base
.API
.ReleaseTexImage
= xlib_eglReleaseTexImage
;
843 xdrv
->Base
.API
.MakeCurrent
= xlib_eglMakeCurrent
;
844 xdrv
->Base
.API
.SwapBuffers
= xlib_eglSwapBuffers
;
846 xdrv
->apis
= find_supported_apis();
847 if (xdrv
->apis
== 0x0) {
848 /* the app isn't directly linked with any EGL-supprted APIs
849 * (such as libGLESv2.so) so use an EGL utility to see what
850 * APIs might be loaded dynamically on this system.
852 xdrv
->apis
= _eglFindAPIs();
855 xdrv
->Base
.Name
= "Xlib/softpipe";
856 xdrv
->Base
.Unload
= xlib_Unload
;