1 /**************************************************************************
3 * Copyright 2008 VMware, Inc.
4 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5 * Copyright 2010-2011 LunarG, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
32 * Public EGL API entrypoints
34 * Generally, we use the EGLDisplay parameter as a key to lookup the
35 * appropriate device driver handle, then jump though the driver's
36 * dispatch table to handle the function.
38 * That allows us the option of supporting multiple, simultaneous,
39 * heterogeneous hardware devices in the future.
41 * The EGLDisplay, EGLConfig, EGLContext and EGLSurface types are
42 * opaque handles. Internal objects are linked to a display to
45 * For each public API entry point, the opaque handles are looked up
46 * before being dispatched to the drivers. When it fails to look up
56 * is generated and the driver function is not called. An
57 * uninitialized EGLDisplay has no driver associated with it. When
58 * such display is detected,
64 * Some of the entry points use current display, context, or surface
65 * implicitly. For such entry points, the implicit objects are also
66 * checked before calling the driver function. Other than the
67 * errors listed above,
69 * EGL_BAD_CURRENT_SURFACE
71 * may also be generated.
73 * Notes on naming conventions:
75 * eglFooBar - public EGL function
76 * EGL_FOO_BAR - public EGL token
77 * EGLDatatype - public EGL datatype
79 * _eglFooBar - private EGL function
80 * _EGLDatatype - private EGL datatype, typedef'd struct
81 * _egl_struct - private EGL struct, non-typedef'd
89 #include "c99_compat.h"
90 #include "c11/threads.h"
91 #include "eglcompiler.h"
93 #include "eglglobals.h"
94 #include "eglcontext.h"
95 #include "egldisplay.h"
96 #include "egltypedefs.h"
97 #include "eglcurrent.h"
98 #include "egldriver.h"
99 #include "eglsurface.h"
100 #include "eglconfig.h"
101 #include "eglimage.h"
106 * Macros to help return an API entrypoint.
108 * These macros will unlock the display and record the error code.
110 #define RETURN_EGL_ERROR(disp, err, ret) \
113 _eglUnlockDisplay(disp); \
114 /* EGL error codes are non-zero */ \
116 _eglError(err, __func__); \
120 #define RETURN_EGL_SUCCESS(disp, ret) \
121 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
123 /* record EGL_SUCCESS only when ret evaluates to true */
124 #define RETURN_EGL_EVAL(disp, ret) \
125 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
129 * A bunch of macros and checks to simplify error checking.
132 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
134 drv = _eglCheckDisplay(disp, __func__); \
136 RETURN_EGL_ERROR(disp, 0, ret); \
139 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
141 drv = _eglCheck ## type(disp, obj, __func__); \
143 RETURN_EGL_ERROR(disp, 0, ret); \
146 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
147 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
149 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
150 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
152 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
153 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
155 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
156 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
159 static inline _EGLDriver *
160 _eglCheckDisplay(_EGLDisplay *disp, const char *msg)
163 _eglError(EGL_BAD_DISPLAY, msg);
166 if (!disp->Initialized) {
167 _eglError(EGL_NOT_INITIALIZED, msg);
174 static inline _EGLDriver *
175 _eglCheckSurface(_EGLDisplay *disp, _EGLSurface *surf, const char *msg)
177 _EGLDriver *drv = _eglCheckDisplay(disp, msg);
181 _eglError(EGL_BAD_SURFACE, msg);
188 static inline _EGLDriver *
189 _eglCheckContext(_EGLDisplay *disp, _EGLContext *context, const char *msg)
191 _EGLDriver *drv = _eglCheckDisplay(disp, msg);
195 _eglError(EGL_BAD_CONTEXT, msg);
202 static inline _EGLDriver *
203 _eglCheckConfig(_EGLDisplay *disp, _EGLConfig *conf, const char *msg)
205 _EGLDriver *drv = _eglCheckDisplay(disp, msg);
209 _eglError(EGL_BAD_CONFIG, msg);
216 static inline _EGLDriver *
217 _eglCheckSync(_EGLDisplay *disp, _EGLSync *s, const char *msg)
219 _EGLDriver *drv = _eglCheckDisplay(disp, msg);
223 _eglError(EGL_BAD_PARAMETER, msg);
231 * Lookup and lock a display.
233 static inline _EGLDisplay *
234 _eglLockDisplay(EGLDisplay display)
236 _EGLDisplay *dpy = _eglLookupDisplay(display);
238 mtx_lock(&dpy->Mutex);
247 _eglUnlockDisplay(_EGLDisplay *dpy)
249 mtx_unlock(&dpy->Mutex);
254 _eglConvertAttribsToInt(const EGLAttrib *attr_list)
256 EGLint *int_attribs = NULL;
258 /* Convert attributes from EGLAttrib[] to EGLint[] */
262 while (attr_list[size] != EGL_NONE)
265 size += 1; /* add space for EGL_NONE */
267 int_attribs = calloc(size, sizeof(int_attribs[0]));
271 for (i = 0; i < size; i++)
272 int_attribs[i] = attr_list[i];
279 * This is typically the first EGL function that an application calls.
280 * It associates a private _EGLDisplay object to the native display.
282 EGLDisplay EGLAPIENTRY
283 eglGetDisplay(EGLNativeDisplayType nativeDisplay)
285 _EGLPlatformType plat;
287 void *native_display_ptr;
289 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay));
290 native_display_ptr = (void*) nativeDisplay;
292 plat = _eglGetNativePlatform(native_display_ptr);
293 dpy = _eglFindDisplay(plat, native_display_ptr);
294 return _eglGetDisplayHandle(dpy);
297 static EGLDisplay EGLAPIENTRY
298 eglGetPlatformDisplayEXT(EGLenum platform, void *native_display,
299 const EGLint *attrib_list)
304 #ifdef HAVE_X11_PLATFORM
305 case EGL_PLATFORM_X11_EXT:
306 dpy = _eglGetX11Display((Display*) native_display, attrib_list);
309 #ifdef HAVE_DRM_PLATFORM
310 case EGL_PLATFORM_GBM_MESA:
311 dpy = _eglGetGbmDisplay((struct gbm_device*) native_display,
315 #ifdef HAVE_WAYLAND_PLATFORM
316 case EGL_PLATFORM_WAYLAND_EXT:
317 dpy = _eglGetWaylandDisplay((struct wl_display*) native_display,
322 RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, NULL);
325 return _eglGetDisplayHandle(dpy);
328 EGLDisplay EGLAPIENTRY
329 eglGetPlatformDisplay(EGLenum platform, void *native_display,
330 const EGLAttrib *attrib_list)
333 EGLint *int_attribs = _eglConvertAttribsToInt(attrib_list);
335 if (attrib_list && !int_attribs)
336 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, NULL);
338 display = eglGetPlatformDisplayEXT(platform, native_display, int_attribs);
344 * Copy the extension into the string and update the string pointer.
347 _eglAppendExtension(char **str, const char *ext)
350 size_t len = strlen(ext);
367 * Examine the individual extension enable/disable flags and recompute
368 * the driver's Extensions string.
371 _eglCreateExtensionsString(_EGLDisplay *dpy)
373 #define _EGL_CHECK_EXTENSION(ext) \
375 if (dpy->Extensions.ext) { \
376 _eglAppendExtension(&exts, "EGL_" #ext); \
377 assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
381 char *exts = dpy->ExtensionsString;
383 /* Please keep these sorted alphabetically. */
384 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer);
386 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control);
388 _EGL_CHECK_EXTENSION(EXT_buffer_age);
389 _EGL_CHECK_EXTENSION(EXT_create_context_robustness);
390 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import);
391 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage);
393 _EGL_CHECK_EXTENSION(KHR_cl_event2);
394 _EGL_CHECK_EXTENSION(KHR_create_context);
395 _EGL_CHECK_EXTENSION(KHR_fence_sync);
396 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses);
397 _EGL_CHECK_EXTENSION(KHR_gl_colorspace);
398 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image);
399 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image);
400 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image);
401 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image);
402 if (dpy->Extensions.KHR_image_base && dpy->Extensions.KHR_image_pixmap)
403 _eglAppendExtension(&exts, "EGL_KHR_image");
404 _EGL_CHECK_EXTENSION(KHR_image_base);
405 _EGL_CHECK_EXTENSION(KHR_image_pixmap);
406 _EGL_CHECK_EXTENSION(KHR_reusable_sync);
407 _EGL_CHECK_EXTENSION(KHR_surfaceless_context);
408 _EGL_CHECK_EXTENSION(KHR_wait_sync);
410 _EGL_CHECK_EXTENSION(MESA_configless_context);
411 _EGL_CHECK_EXTENSION(MESA_drm_image);
412 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export);
414 _EGL_CHECK_EXTENSION(NOK_swap_region);
415 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap);
417 _EGL_CHECK_EXTENSION(NV_post_sub_buffer);
419 _EGL_CHECK_EXTENSION(WL_bind_wayland_display);
420 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image);
422 #undef _EGL_CHECK_EXTENSION
426 _eglCreateAPIsString(_EGLDisplay *dpy)
428 if (dpy->ClientAPIs & EGL_OPENGL_BIT)
429 strcat(dpy->ClientAPIsString, "OpenGL ");
431 if (dpy->ClientAPIs & EGL_OPENGL_ES_BIT)
432 strcat(dpy->ClientAPIsString, "OpenGL_ES ");
434 if (dpy->ClientAPIs & EGL_OPENGL_ES2_BIT)
435 strcat(dpy->ClientAPIsString, "OpenGL_ES2 ");
437 if (dpy->ClientAPIs & EGL_OPENGL_ES3_BIT_KHR)
438 strcat(dpy->ClientAPIsString, "OpenGL_ES3 ");
440 if (dpy->ClientAPIs & EGL_OPENVG_BIT)
441 strcat(dpy->ClientAPIsString, "OpenVG ");
443 assert(strlen(dpy->ClientAPIsString) < sizeof(dpy->ClientAPIsString));
447 _eglComputeVersion(_EGLDisplay *disp)
451 if (disp->Extensions.KHR_fence_sync &&
452 disp->Extensions.KHR_cl_event2 &&
453 disp->Extensions.KHR_wait_sync &&
454 disp->Extensions.KHR_image_base &&
455 disp->Extensions.KHR_gl_texture_2D_image &&
456 disp->Extensions.KHR_gl_texture_3D_image &&
457 disp->Extensions.KHR_gl_texture_cubemap_image &&
458 disp->Extensions.KHR_gl_renderbuffer_image &&
459 disp->Extensions.KHR_create_context &&
460 disp->Extensions.EXT_create_context_robustness &&
461 disp->Extensions.KHR_get_all_proc_addresses &&
462 disp->Extensions.KHR_gl_colorspace &&
463 disp->Extensions.KHR_surfaceless_context)
468 * This is typically the second EGL function that an application calls.
469 * Here we load/initialize the actual hardware driver.
471 EGLBoolean EGLAPIENTRY
472 eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
474 _EGLDisplay *disp = _eglLockDisplay(dpy);
477 RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE);
479 if (!disp->Initialized) {
480 if (!_eglMatchDriver(disp, EGL_FALSE))
481 RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE);
483 /* limit to APIs supported by core */
484 disp->ClientAPIs &= _EGL_API_ALL_BITS;
486 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
487 * classifies it as an EGL display extension, though conceptually it's an
488 * EGL client extension.
490 * From the EGL_KHR_get_all_proc_addresses spec:
492 * The EGL implementation must expose the name
493 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
494 * EGL_KHR_get_all_proc_addresses and supports
495 * EGL_EXT_client_extensions.
497 * Mesa unconditionally exposes both client extensions mentioned above,
498 * so the spec requires that each EGLDisplay unconditionally expose
499 * EGL_KHR_get_all_proc_addresses also.
501 disp->Extensions.KHR_get_all_proc_addresses = EGL_TRUE;
503 _eglComputeVersion(disp);
504 _eglCreateExtensionsString(disp);
505 _eglCreateAPIsString(disp);
506 snprintf(disp->VersionString, sizeof(disp->VersionString),
507 "%d.%d (%s)", disp->Version / 10, disp->Version % 10,
511 /* Update applications version of major and minor if not NULL */
512 if ((major != NULL) && (minor != NULL)) {
513 *major = disp->Version / 10;
514 *minor = disp->Version % 10;
517 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
521 EGLBoolean EGLAPIENTRY
522 eglTerminate(EGLDisplay dpy)
524 _EGLDisplay *disp = _eglLockDisplay(dpy);
527 RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE);
529 if (disp->Initialized) {
530 _EGLDriver *drv = disp->Driver;
532 drv->API.Terminate(drv, disp);
533 /* do not reset disp->Driver */
534 disp->ClientAPIsString[0] = 0;
535 disp->Initialized = EGL_FALSE;
538 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
542 const char * EGLAPIENTRY
543 eglQueryString(EGLDisplay dpy, EGLint name)
548 if (dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS) {
549 RETURN_EGL_SUCCESS(NULL, _eglGlobal.ClientExtensionString);
552 disp = _eglLockDisplay(dpy);
553 _EGL_CHECK_DISPLAY(disp, NULL, drv);
557 RETURN_EGL_SUCCESS(disp, _EGL_VENDOR_STRING);
559 RETURN_EGL_SUCCESS(disp, disp->VersionString);
561 RETURN_EGL_SUCCESS(disp, disp->ExtensionsString);
562 case EGL_CLIENT_APIS:
563 RETURN_EGL_SUCCESS(disp, disp->ClientAPIsString);
565 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL);
570 EGLBoolean EGLAPIENTRY
571 eglGetConfigs(EGLDisplay dpy, EGLConfig *configs,
572 EGLint config_size, EGLint *num_config)
574 _EGLDisplay *disp = _eglLockDisplay(dpy);
578 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
579 ret = drv->API.GetConfigs(drv, disp, configs, config_size, num_config);
581 RETURN_EGL_EVAL(disp, ret);
585 EGLBoolean EGLAPIENTRY
586 eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs,
587 EGLint config_size, EGLint *num_config)
589 _EGLDisplay *disp = _eglLockDisplay(dpy);
593 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
594 ret = drv->API.ChooseConfig(drv, disp, attrib_list, configs,
595 config_size, num_config);
597 RETURN_EGL_EVAL(disp, ret);
601 EGLBoolean EGLAPIENTRY
602 eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
603 EGLint attribute, EGLint *value)
605 _EGLDisplay *disp = _eglLockDisplay(dpy);
606 _EGLConfig *conf = _eglLookupConfig(config, disp);
610 _EGL_CHECK_CONFIG(disp, conf, EGL_FALSE, drv);
611 ret = drv->API.GetConfigAttrib(drv, disp, conf, attribute, value);
613 RETURN_EGL_EVAL(disp, ret);
617 EGLContext EGLAPIENTRY
618 eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list,
619 const EGLint *attrib_list)
621 _EGLDisplay *disp = _eglLockDisplay(dpy);
622 _EGLConfig *conf = _eglLookupConfig(config, disp);
623 _EGLContext *share = _eglLookupContext(share_list, disp);
625 _EGLContext *context;
628 _EGL_CHECK_DISPLAY(disp, EGL_NO_CONTEXT, drv);
630 if (!config && !disp->Extensions.MESA_configless_context)
631 RETURN_EGL_ERROR(disp, EGL_BAD_CONFIG, EGL_NO_CONTEXT);
633 if (!share && share_list != EGL_NO_CONTEXT)
634 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_CONTEXT);
636 context = drv->API.CreateContext(drv, disp, conf, share, attrib_list);
637 ret = (context) ? _eglLinkContext(context) : EGL_NO_CONTEXT;
639 RETURN_EGL_EVAL(disp, ret);
643 EGLBoolean EGLAPIENTRY
644 eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
646 _EGLDisplay *disp = _eglLockDisplay(dpy);
647 _EGLContext *context = _eglLookupContext(ctx, disp);
651 _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv);
652 _eglUnlinkContext(context);
653 ret = drv->API.DestroyContext(drv, disp, context);
655 RETURN_EGL_EVAL(disp, ret);
659 EGLBoolean EGLAPIENTRY
660 eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read,
663 _EGLDisplay *disp = _eglLockDisplay(dpy);
664 _EGLContext *context = _eglLookupContext(ctx, disp);
665 _EGLSurface *draw_surf = _eglLookupSurface(draw, disp);
666 _EGLSurface *read_surf = _eglLookupSurface(read, disp);
671 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE);
674 /* display is allowed to be uninitialized under certain condition */
675 if (!disp->Initialized) {
676 if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE ||
677 ctx != EGL_NO_CONTEXT)
678 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE);
681 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
683 if (!context && ctx != EGL_NO_CONTEXT)
684 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE);
685 if (!draw_surf || !read_surf) {
686 /* From the EGL 1.4 (20130211) spec:
688 * To release the current context without assigning a new one, set ctx
689 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
691 if (!disp->Extensions.KHR_surfaceless_context && ctx != EGL_NO_CONTEXT)
692 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
694 if ((!draw_surf && draw != EGL_NO_SURFACE) ||
695 (!read_surf && read != EGL_NO_SURFACE))
696 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
697 if (draw_surf || read_surf)
698 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
701 ret = drv->API.MakeCurrent(drv, disp, draw_surf, read_surf, context);
703 RETURN_EGL_EVAL(disp, ret);
707 EGLBoolean EGLAPIENTRY
708 eglQueryContext(EGLDisplay dpy, EGLContext ctx,
709 EGLint attribute, EGLint *value)
711 _EGLDisplay *disp = _eglLockDisplay(dpy);
712 _EGLContext *context = _eglLookupContext(ctx, disp);
716 _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv);
717 ret = drv->API.QueryContext(drv, disp, context, attribute, value);
719 RETURN_EGL_EVAL(disp, ret);
724 _eglCreateWindowSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
725 void *native_window, const EGLint *attrib_list)
727 _EGLConfig *conf = _eglLookupConfig(config, disp);
732 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
734 if (native_window == NULL)
735 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
737 surf = drv->API.CreateWindowSurface(drv, disp, conf, native_window,
739 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
741 RETURN_EGL_EVAL(disp, ret);
745 EGLSurface EGLAPIENTRY
746 eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
747 EGLNativeWindowType window, const EGLint *attrib_list)
749 _EGLDisplay *disp = _eglLockDisplay(dpy);
750 STATIC_ASSERT(sizeof(void*) == sizeof(window));
751 return _eglCreateWindowSurfaceCommon(disp, config, (void*) window,
756 static EGLSurface EGLAPIENTRY
757 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config,
759 const EGLint *attrib_list)
761 _EGLDisplay *disp = _eglLockDisplay(dpy);
763 #ifdef HAVE_X11_PLATFORM
764 if (disp->Platform == _EGL_PLATFORM_X11 && native_window != NULL) {
765 /* The `native_window` parameter for the X11 platform differs between
766 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
767 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
768 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
769 * `Window*`. Convert `Window*` to `Window` because that's what
770 * dri2_x11_create_window_surface() expects.
772 native_window = (void*) (* (Window*) native_window);
776 return _eglCreateWindowSurfaceCommon(disp, config, native_window,
781 EGLSurface EGLAPIENTRY
782 eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config,
784 const EGLAttrib *attrib_list)
787 EGLint *int_attribs = _eglConvertAttribsToInt(attrib_list);
789 if (attrib_list && !int_attribs)
790 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_NO_SURFACE);
792 surface = eglCreatePlatformWindowSurfaceEXT(dpy, config, native_window,
800 _eglCreatePixmapSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
801 void *native_pixmap, const EGLint *attrib_list)
803 _EGLConfig *conf = _eglLookupConfig(config, disp);
808 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
809 surf = drv->API.CreatePixmapSurface(drv, disp, conf, native_pixmap,
811 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
813 RETURN_EGL_EVAL(disp, ret);
817 EGLSurface EGLAPIENTRY
818 eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config,
819 EGLNativePixmapType pixmap, const EGLint *attrib_list)
821 _EGLDisplay *disp = _eglLockDisplay(dpy);
822 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap));
823 return _eglCreatePixmapSurfaceCommon(disp, config, (void*) pixmap,
827 static EGLSurface EGLAPIENTRY
828 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config,
830 const EGLint *attrib_list)
832 _EGLDisplay *disp = _eglLockDisplay(dpy);
834 #ifdef HAVE_X11_PLATFORM
835 /* The `native_pixmap` parameter for the X11 platform differs between
836 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
837 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
838 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
839 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
840 * dri2_x11_create_pixmap_surface() expects.
842 if (disp->Platform == _EGL_PLATFORM_X11 && native_pixmap != NULL) {
843 native_pixmap = (void*) (* (Pixmap*) native_pixmap);
847 return _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap,
852 EGLSurface EGLAPIENTRY
853 eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config,
855 const EGLAttrib *attrib_list)
858 EGLint *int_attribs = _eglConvertAttribsToInt(attrib_list);
860 if (attrib_list && !int_attribs)
861 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_NO_SURFACE);
863 surface = eglCreatePlatformPixmapSurfaceEXT(dpy, config, native_pixmap,
870 EGLSurface EGLAPIENTRY
871 eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,
872 const EGLint *attrib_list)
874 _EGLDisplay *disp = _eglLockDisplay(dpy);
875 _EGLConfig *conf = _eglLookupConfig(config, disp);
880 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
882 surf = drv->API.CreatePbufferSurface(drv, disp, conf, attrib_list);
883 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
885 RETURN_EGL_EVAL(disp, ret);
889 EGLBoolean EGLAPIENTRY
890 eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
892 _EGLDisplay *disp = _eglLockDisplay(dpy);
893 _EGLSurface *surf = _eglLookupSurface(surface, disp);
897 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
898 _eglUnlinkSurface(surf);
899 ret = drv->API.DestroySurface(drv, disp, surf);
901 RETURN_EGL_EVAL(disp, ret);
904 EGLBoolean EGLAPIENTRY
905 eglQuerySurface(EGLDisplay dpy, EGLSurface surface,
906 EGLint attribute, EGLint *value)
908 _EGLDisplay *disp = _eglLockDisplay(dpy);
909 _EGLSurface *surf = _eglLookupSurface(surface, disp);
913 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
914 ret = drv->API.QuerySurface(drv, disp, surf, attribute, value);
916 RETURN_EGL_EVAL(disp, ret);
919 EGLBoolean EGLAPIENTRY
920 eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface,
921 EGLint attribute, EGLint value)
923 _EGLDisplay *disp = _eglLockDisplay(dpy);
924 _EGLSurface *surf = _eglLookupSurface(surface, disp);
928 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
929 ret = drv->API.SurfaceAttrib(drv, disp, surf, attribute, value);
931 RETURN_EGL_EVAL(disp, ret);
935 EGLBoolean EGLAPIENTRY
936 eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
938 _EGLDisplay *disp = _eglLockDisplay(dpy);
939 _EGLSurface *surf = _eglLookupSurface(surface, disp);
943 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
944 ret = drv->API.BindTexImage(drv, disp, surf, buffer);
946 RETURN_EGL_EVAL(disp, ret);
950 EGLBoolean EGLAPIENTRY
951 eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
953 _EGLDisplay *disp = _eglLockDisplay(dpy);
954 _EGLSurface *surf = _eglLookupSurface(surface, disp);
958 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
959 ret = drv->API.ReleaseTexImage(drv, disp, surf, buffer);
961 RETURN_EGL_EVAL(disp, ret);
965 EGLBoolean EGLAPIENTRY
966 eglSwapInterval(EGLDisplay dpy, EGLint interval)
968 _EGLDisplay *disp = _eglLockDisplay(dpy);
969 _EGLContext *ctx = _eglGetCurrentContext();
974 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
976 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
977 ctx->Resource.Display != disp)
978 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE);
980 surf = ctx->DrawSurface;
981 if (_eglGetSurfaceHandle(surf) == EGL_NO_SURFACE)
982 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
984 ret = drv->API.SwapInterval(drv, disp, surf, interval);
986 RETURN_EGL_EVAL(disp, ret);
990 EGLBoolean EGLAPIENTRY
991 eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
993 _EGLContext *ctx = _eglGetCurrentContext();
994 _EGLDisplay *disp = _eglLockDisplay(dpy);
995 _EGLSurface *surf = _eglLookupSurface(surface, disp);
999 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1001 /* surface must be bound to current context in EGL 1.4 */
1002 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1003 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1004 surf != ctx->DrawSurface)
1005 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1008 ret = drv->API.SwapBuffers(drv, disp, surf);
1010 RETURN_EGL_EVAL(disp, ret);
1014 static EGLBoolean EGLAPIENTRY
1015 eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface,
1016 EGLint *rects, EGLint n_rects)
1018 _EGLContext *ctx = _eglGetCurrentContext();
1019 _EGLDisplay *disp = _eglLockDisplay(dpy);
1020 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1024 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1026 /* surface must be bound to current context in EGL 1.4 */
1027 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1028 surf != ctx->DrawSurface)
1029 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1031 if ((n_rects > 0 && rects == NULL) || n_rects < 0)
1032 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1034 ret = drv->API.SwapBuffersWithDamageEXT(drv, disp, surf, rects, n_rects);
1036 RETURN_EGL_EVAL(disp, ret);
1039 EGLBoolean EGLAPIENTRY
1040 eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
1042 _EGLDisplay *disp = _eglLockDisplay(dpy);
1043 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1046 void *native_pixmap_ptr;
1048 STATIC_ASSERT(sizeof(void*) == sizeof(target));
1049 native_pixmap_ptr = (void*) target;
1051 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1052 if (disp->Platform != _eglGetNativePlatform(disp->PlatformDisplay))
1053 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_FALSE);
1054 ret = drv->API.CopyBuffers(drv, disp, surf, native_pixmap_ptr);
1056 RETURN_EGL_EVAL(disp, ret);
1060 EGLBoolean EGLAPIENTRY
1063 _EGLContext *ctx = _eglGetCurrentContext();
1069 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1071 disp = ctx->Resource.Display;
1072 mtx_lock(&disp->Mutex);
1074 /* let bad current context imply bad current surface */
1075 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1076 _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE)
1077 RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
1079 /* a valid current context implies an initialized current display */
1080 assert(disp->Initialized);
1082 ret = drv->API.WaitClient(drv, disp, ctx);
1084 RETURN_EGL_EVAL(disp, ret);
1088 EGLBoolean EGLAPIENTRY
1091 _EGLThreadInfo *t = _eglGetCurrentThread();
1092 EGLint api_index = t->CurrentAPIIndex;
1093 EGLint es_index = _eglConvertApiToIndex(EGL_OPENGL_ES_API);
1096 if (api_index != es_index && _eglIsCurrentThreadDummy())
1097 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_FALSE);
1099 t->CurrentAPIIndex = es_index;
1100 ret = eglWaitClient();
1101 t->CurrentAPIIndex = api_index;
1106 EGLBoolean EGLAPIENTRY
1107 eglWaitNative(EGLint engine)
1109 _EGLContext *ctx = _eglGetCurrentContext();
1115 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1117 disp = ctx->Resource.Display;
1118 mtx_lock(&disp->Mutex);
1120 /* let bad current context imply bad current surface */
1121 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1122 _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE)
1123 RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
1125 /* a valid current context implies an initialized current display */
1126 assert(disp->Initialized);
1128 ret = drv->API.WaitNative(drv, disp, engine);
1130 RETURN_EGL_EVAL(disp, ret);
1134 EGLDisplay EGLAPIENTRY
1135 eglGetCurrentDisplay(void)
1137 _EGLContext *ctx = _eglGetCurrentContext();
1140 ret = (ctx) ? _eglGetDisplayHandle(ctx->Resource.Display) : EGL_NO_DISPLAY;
1142 RETURN_EGL_SUCCESS(NULL, ret);
1146 EGLContext EGLAPIENTRY
1147 eglGetCurrentContext(void)
1149 _EGLContext *ctx = _eglGetCurrentContext();
1152 ret = _eglGetContextHandle(ctx);
1154 RETURN_EGL_SUCCESS(NULL, ret);
1158 EGLSurface EGLAPIENTRY
1159 eglGetCurrentSurface(EGLint readdraw)
1161 _EGLContext *ctx = _eglGetCurrentContext();
1162 EGLint err = EGL_SUCCESS;
1167 RETURN_EGL_SUCCESS(NULL, EGL_NO_SURFACE);
1171 surf = ctx->DrawSurface;
1174 surf = ctx->ReadSurface;
1178 err = EGL_BAD_PARAMETER;
1182 ret = _eglGetSurfaceHandle(surf);
1184 RETURN_EGL_ERROR(NULL, err, ret);
1191 _EGLThreadInfo *t = _eglGetCurrentThread();
1192 EGLint e = t->LastError;
1193 if (!_eglIsCurrentThreadDummy())
1194 t->LastError = EGL_SUCCESS;
1204 * Specify the client API to use for subsequent calls including:
1205 * eglCreateContext()
1206 * eglGetCurrentContext()
1207 * eglGetCurrentDisplay()
1208 * eglGetCurrentSurface()
1209 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1212 * See section 3.7 "Rendering Context" in the EGL specification for details.
1214 EGLBoolean EGLAPIENTRY
1215 eglBindAPI(EGLenum api)
1217 _EGLThreadInfo *t = _eglGetCurrentThread();
1219 if (_eglIsCurrentThreadDummy())
1220 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_FALSE);
1222 if (!_eglIsApiValid(api))
1223 RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, EGL_FALSE);
1225 t->CurrentAPIIndex = _eglConvertApiToIndex(api);
1227 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1232 * Return the last value set with eglBindAPI().
1237 _EGLThreadInfo *t = _eglGetCurrentThread();
1240 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1241 ret = _eglConvertApiFromIndex(t->CurrentAPIIndex);
1243 RETURN_EGL_SUCCESS(NULL, ret);
1247 EGLSurface EGLAPIENTRY
1248 eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype,
1249 EGLClientBuffer buffer, EGLConfig config,
1250 const EGLint *attrib_list)
1252 _EGLDisplay *disp = _eglLockDisplay(dpy);
1253 _EGLConfig *conf = _eglLookupConfig(config, disp);
1258 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
1260 surf = drv->API.CreatePbufferFromClientBuffer(drv, disp, buftype, buffer,
1262 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
1264 RETURN_EGL_EVAL(disp, ret);
1268 EGLBoolean EGLAPIENTRY
1269 eglReleaseThread(void)
1271 /* unbind current contexts */
1272 if (!_eglIsCurrentThreadDummy()) {
1273 _EGLThreadInfo *t = _eglGetCurrentThread();
1274 EGLint api_index = t->CurrentAPIIndex;
1277 for (i = 0; i < _EGL_API_NUM_APIS; i++) {
1278 _EGLContext *ctx = t->CurrentContexts[i];
1280 _EGLDisplay *disp = ctx->Resource.Display;
1283 t->CurrentAPIIndex = i;
1285 mtx_lock(&disp->Mutex);
1287 (void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL);
1288 mtx_unlock(&disp->Mutex);
1292 t->CurrentAPIIndex = api_index;
1295 _eglDestroyCurrentThread();
1297 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1301 static EGLImage EGLAPIENTRY
1302 eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1303 EGLClientBuffer buffer, const EGLint *attr_list)
1305 _EGLDisplay *disp = _eglLockDisplay(dpy);
1306 _EGLContext *context = _eglLookupContext(ctx, disp);
1311 _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv);
1312 if (!disp->Extensions.KHR_image_base)
1313 RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR);
1314 if (!context && ctx != EGL_NO_CONTEXT)
1315 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR);
1316 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1317 * <ctx> must be EGL_NO_CONTEXT..."
1319 if (ctx != EGL_NO_CONTEXT && target == EGL_LINUX_DMA_BUF_EXT)
1320 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
1322 img = drv->API.CreateImageKHR(drv,
1323 disp, context, target, buffer, attr_list);
1324 ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR;
1326 RETURN_EGL_EVAL(disp, ret);
1330 EGLImage EGLAPIENTRY
1331 eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1332 EGLClientBuffer buffer, const EGLAttrib *attr_list)
1335 EGLint *int_attribs = _eglConvertAttribsToInt(attr_list);
1337 if (attr_list && !int_attribs)
1338 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_NO_IMAGE);
1340 image = eglCreateImageKHR(dpy, ctx, target, buffer, int_attribs);
1346 EGLBoolean EGLAPIENTRY
1347 eglDestroyImage(EGLDisplay dpy, EGLImage image)
1349 _EGLDisplay *disp = _eglLockDisplay(dpy);
1350 _EGLImage *img = _eglLookupImage(image, disp);
1354 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1355 if (!disp->Extensions.KHR_image_base)
1356 RETURN_EGL_EVAL(disp, EGL_FALSE);
1358 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1360 _eglUnlinkImage(img);
1361 ret = drv->API.DestroyImageKHR(drv, disp, img);
1363 RETURN_EGL_EVAL(disp, ret);
1368 _eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list,
1369 const EGLAttrib *attrib_list64, EGLBoolean is64,
1370 EGLenum invalid_type_error)
1372 _EGLDisplay *disp = _eglLockDisplay(dpy);
1373 _EGLContext *ctx = _eglGetCurrentContext();
1378 _EGL_CHECK_DISPLAY(disp, EGL_NO_SYNC_KHR, drv);
1380 if (!disp->Extensions.KHR_cl_event2 && is64)
1381 RETURN_EGL_EVAL(disp, EGL_NO_SYNC_KHR);
1383 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1384 if (!ctx || ctx->Resource.Display != dpy ||
1385 ctx->ClientAPI != EGL_OPENGL_ES_API)
1386 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
1389 case EGL_SYNC_FENCE_KHR:
1390 if (!disp->Extensions.KHR_fence_sync)
1391 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1393 case EGL_SYNC_REUSABLE_KHR:
1394 if (!disp->Extensions.KHR_reusable_sync)
1395 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1397 case EGL_SYNC_CL_EVENT_KHR:
1398 if (!disp->Extensions.KHR_cl_event2)
1399 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1402 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1405 sync = drv->API.CreateSyncKHR(drv, disp, type, attrib_list, attrib_list64);
1406 ret = (sync) ? _eglLinkSync(sync) : EGL_NO_SYNC_KHR;
1408 RETURN_EGL_EVAL(disp, ret);
1412 static EGLSync EGLAPIENTRY
1413 eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list)
1415 return _eglCreateSync(dpy, type, attrib_list, NULL, EGL_FALSE,
1420 static EGLSync EGLAPIENTRY
1421 eglCreateSync64KHR(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
1423 return _eglCreateSync(dpy, type, NULL, attrib_list, EGL_TRUE,
1429 eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
1431 return _eglCreateSync(dpy, type, NULL, attrib_list, EGL_TRUE,
1436 EGLBoolean EGLAPIENTRY
1437 eglDestroySync(EGLDisplay dpy, EGLSync sync)
1439 _EGLDisplay *disp = _eglLockDisplay(dpy);
1440 _EGLSync *s = _eglLookupSync(sync, disp);
1444 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1445 assert(disp->Extensions.KHR_reusable_sync ||
1446 disp->Extensions.KHR_fence_sync);
1449 ret = drv->API.DestroySyncKHR(drv, disp, s);
1451 RETURN_EGL_EVAL(disp, ret);
1456 eglClientWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout)
1458 _EGLDisplay *disp = _eglLockDisplay(dpy);
1459 _EGLSync *s = _eglLookupSync(sync, disp);
1463 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1464 assert(disp->Extensions.KHR_reusable_sync ||
1465 disp->Extensions.KHR_fence_sync);
1467 if (s->SyncStatus == EGL_SIGNALED_KHR)
1468 RETURN_EGL_EVAL(disp, EGL_CONDITION_SATISFIED_KHR);
1470 ret = drv->API.ClientWaitSyncKHR(drv, disp, s, flags, timeout);
1472 RETURN_EGL_EVAL(disp, ret);
1476 static EGLint EGLAPIENTRY
1477 eglWaitSyncKHR(EGLDisplay dpy, EGLSync sync, EGLint flags)
1479 _EGLDisplay *disp = _eglLockDisplay(dpy);
1480 _EGLSync *s = _eglLookupSync(sync, disp);
1481 _EGLContext *ctx = _eglGetCurrentContext();
1485 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1486 assert(disp->Extensions.KHR_wait_sync);
1488 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1489 if (ctx == EGL_NO_CONTEXT || ctx->ClientAPI != EGL_OPENGL_ES_API)
1490 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
1492 /* the API doesn't allow any flags yet */
1494 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1496 ret = drv->API.WaitSyncKHR(drv, disp, s);
1498 RETURN_EGL_EVAL(disp, ret);
1502 EGLBoolean EGLAPIENTRY
1503 eglWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags)
1505 /* The KHR version returns EGLint, while the core version returns
1506 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1509 return eglWaitSyncKHR(dpy, sync, flags);
1513 static EGLBoolean EGLAPIENTRY
1514 eglSignalSyncKHR(EGLDisplay dpy, EGLSync sync, EGLenum mode)
1516 _EGLDisplay *disp = _eglLockDisplay(dpy);
1517 _EGLSync *s = _eglLookupSync(sync, disp);
1521 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1522 assert(disp->Extensions.KHR_reusable_sync);
1523 ret = drv->API.SignalSyncKHR(drv, disp, s, mode);
1525 RETURN_EGL_EVAL(disp, ret);
1529 EGLBoolean EGLAPIENTRY
1530 eglGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value)
1532 _EGLDisplay *disp = _eglLockDisplay(dpy);
1533 _EGLSync *s = _eglLookupSync(sync, disp);
1537 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1538 assert(disp->Extensions.KHR_reusable_sync ||
1539 disp->Extensions.KHR_fence_sync);
1540 ret = drv->API.GetSyncAttrib(drv, disp, s, attribute, value);
1542 RETURN_EGL_EVAL(disp, ret);
1546 static EGLBoolean EGLAPIENTRY
1547 eglGetSyncAttribKHR(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLint *value)
1553 RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, EGL_FALSE);
1556 result = eglGetSyncAttrib(dpy, sync, attribute, &attrib);
1558 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
1560 * If any error occurs, <*value> is not modified.
1562 if (result == EGL_FALSE)
1570 static EGLBoolean EGLAPIENTRY
1571 eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface,
1572 EGLint numRects, const EGLint *rects)
1574 _EGLContext *ctx = _eglGetCurrentContext();
1575 _EGLDisplay *disp = _eglLockDisplay(dpy);
1576 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1580 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1582 if (!disp->Extensions.NOK_swap_region)
1583 RETURN_EGL_EVAL(disp, EGL_FALSE);
1585 /* surface must be bound to current context in EGL 1.4 */
1586 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1587 surf != ctx->DrawSurface)
1588 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1590 ret = drv->API.SwapBuffersRegionNOK(drv, disp, surf, numRects, rects);
1592 RETURN_EGL_EVAL(disp, ret);
1596 static EGLImage EGLAPIENTRY
1597 eglCreateDRMImageMESA(EGLDisplay dpy, const EGLint *attr_list)
1599 _EGLDisplay *disp = _eglLockDisplay(dpy);
1604 _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv);
1605 if (!disp->Extensions.MESA_drm_image)
1606 RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR);
1608 img = drv->API.CreateDRMImageMESA(drv, disp, attr_list);
1609 ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR;
1611 RETURN_EGL_EVAL(disp, ret);
1614 static EGLBoolean EGLAPIENTRY
1615 eglExportDRMImageMESA(EGLDisplay dpy, EGLImage image,
1616 EGLint *name, EGLint *handle, EGLint *stride)
1618 _EGLDisplay *disp = _eglLockDisplay(dpy);
1619 _EGLImage *img = _eglLookupImage(image, disp);
1623 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1624 assert(disp->Extensions.MESA_drm_image);
1627 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1629 ret = drv->API.ExportDRMImageMESA(drv, disp, img, name, handle, stride);
1631 RETURN_EGL_EVAL(disp, ret);
1637 static EGLBoolean EGLAPIENTRY
1638 eglBindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
1640 _EGLDisplay *disp = _eglLockDisplay(dpy);
1644 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1645 assert(disp->Extensions.WL_bind_wayland_display);
1648 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1650 ret = drv->API.BindWaylandDisplayWL(drv, disp, display);
1652 RETURN_EGL_EVAL(disp, ret);
1655 static EGLBoolean EGLAPIENTRY
1656 eglUnbindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
1658 _EGLDisplay *disp = _eglLockDisplay(dpy);
1662 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1663 assert(disp->Extensions.WL_bind_wayland_display);
1666 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1668 ret = drv->API.UnbindWaylandDisplayWL(drv, disp, display);
1670 RETURN_EGL_EVAL(disp, ret);
1673 static EGLBoolean EGLAPIENTRY
1674 eglQueryWaylandBufferWL(EGLDisplay dpy, struct wl_resource *buffer,
1675 EGLint attribute, EGLint *value)
1677 _EGLDisplay *disp = _eglLockDisplay(dpy);
1681 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1682 assert(disp->Extensions.WL_bind_wayland_display);
1685 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1687 ret = drv->API.QueryWaylandBufferWL(drv, disp, buffer, attribute, value);
1689 RETURN_EGL_EVAL(disp, ret);
1693 static struct wl_buffer * EGLAPIENTRY
1694 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy, EGLImage image)
1696 _EGLDisplay *disp = _eglLockDisplay(dpy);
1699 struct wl_buffer *ret;
1701 _EGL_CHECK_DISPLAY(disp, NULL, drv);
1702 assert(disp->Extensions.WL_create_wayland_buffer_from_image);
1704 img = _eglLookupImage(image, disp);
1707 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL);
1709 ret = drv->API.CreateWaylandBufferFromImageWL(drv, disp, img);
1711 RETURN_EGL_EVAL(disp, ret);
1714 static EGLBoolean EGLAPIENTRY
1715 eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface,
1716 EGLint x, EGLint y, EGLint width, EGLint height)
1718 _EGLDisplay *disp = _eglLockDisplay(dpy);
1719 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1723 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1725 if (!disp->Extensions.NV_post_sub_buffer)
1726 RETURN_EGL_EVAL(disp, EGL_FALSE);
1728 ret = drv->API.PostSubBufferNV(drv, disp, surf, x, y, width, height);
1730 RETURN_EGL_EVAL(disp, ret);
1733 static EGLBoolean EGLAPIENTRY
1734 eglGetSyncValuesCHROMIUM(EGLDisplay display, EGLSurface surface,
1735 EGLuint64KHR *ust, EGLuint64KHR *msc,
1738 _EGLDisplay *disp = _eglLockDisplay(display);
1739 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1743 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1744 if (!disp->Extensions.CHROMIUM_sync_control)
1745 RETURN_EGL_EVAL(disp, EGL_FALSE);
1747 if (!ust || !msc || !sbc)
1748 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1750 ret = drv->API.GetSyncValuesCHROMIUM(disp, surf, ust, msc, sbc);
1752 RETURN_EGL_EVAL(disp, ret);
1755 static EGLBoolean EGLAPIENTRY
1756 eglExportDMABUFImageQueryMESA(EGLDisplay dpy, EGLImage image,
1757 EGLint *fourcc, EGLint *nplanes,
1758 EGLuint64KHR *modifiers)
1760 _EGLDisplay *disp = _eglLockDisplay(dpy);
1761 _EGLImage *img = _eglLookupImage(image, disp);
1765 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1766 assert(disp->Extensions.MESA_image_dma_buf_export);
1769 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1771 ret = drv->API.ExportDMABUFImageQueryMESA(drv, disp, img, fourcc, nplanes,
1774 RETURN_EGL_EVAL(disp, ret);
1777 static EGLBoolean EGLAPIENTRY
1778 eglExportDMABUFImageMESA(EGLDisplay dpy, EGLImage image,
1779 int *fds, EGLint *strides, EGLint *offsets)
1781 _EGLDisplay *disp = _eglLockDisplay(dpy);
1782 _EGLImage *img = _eglLookupImage(image, disp);
1786 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1787 assert(disp->Extensions.MESA_image_dma_buf_export);
1790 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1792 ret = drv->API.ExportDMABUFImageMESA(drv, disp, img, fds, strides, offsets);
1794 RETURN_EGL_EVAL(disp, ret);
1797 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
1798 eglGetProcAddress(const char *procname)
1800 static const struct {
1803 } egl_functions[] = {
1804 /* core functions queryable in the presence of
1805 * EGL_KHR_get_all_proc_addresses or EGL 1.5
1807 /* alphabetical order */
1808 { "eglBindAPI", (_EGLProc) eglBindAPI },
1809 { "eglBindTexImage", (_EGLProc) eglBindTexImage },
1810 { "eglChooseConfig", (_EGLProc) eglChooseConfig },
1811 { "eglCopyBuffers", (_EGLProc) eglCopyBuffers },
1812 { "eglCreateContext", (_EGLProc) eglCreateContext },
1813 { "eglCreatePbufferFromClientBuffer", (_EGLProc) eglCreatePbufferFromClientBuffer },
1814 { "eglCreatePbufferSurface", (_EGLProc) eglCreatePbufferSurface },
1815 { "eglCreatePixmapSurface", (_EGLProc) eglCreatePixmapSurface },
1816 { "eglCreateWindowSurface", (_EGLProc) eglCreateWindowSurface },
1817 { "eglDestroyContext", (_EGLProc) eglDestroyContext },
1818 { "eglDestroySurface", (_EGLProc) eglDestroySurface },
1819 { "eglGetConfigAttrib", (_EGLProc) eglGetConfigAttrib },
1820 { "eglGetConfigs", (_EGLProc) eglGetConfigs },
1821 { "eglGetCurrentContext", (_EGLProc) eglGetCurrentContext },
1822 { "eglGetCurrentDisplay", (_EGLProc) eglGetCurrentDisplay },
1823 { "eglGetCurrentSurface", (_EGLProc) eglGetCurrentSurface },
1824 { "eglGetDisplay", (_EGLProc) eglGetDisplay },
1825 { "eglGetError", (_EGLProc) eglGetError },
1826 { "eglGetProcAddress", (_EGLProc) eglGetProcAddress },
1827 { "eglInitialize", (_EGLProc) eglInitialize },
1828 { "eglMakeCurrent", (_EGLProc) eglMakeCurrent },
1829 { "eglQueryAPI", (_EGLProc) eglQueryAPI },
1830 { "eglQueryContext", (_EGLProc) eglQueryContext },
1831 { "eglQueryString", (_EGLProc) eglQueryString },
1832 { "eglQuerySurface", (_EGLProc) eglQuerySurface },
1833 { "eglReleaseTexImage", (_EGLProc) eglReleaseTexImage },
1834 { "eglReleaseThread", (_EGLProc) eglReleaseThread },
1835 { "eglSurfaceAttrib", (_EGLProc) eglSurfaceAttrib },
1836 { "eglSwapBuffers", (_EGLProc) eglSwapBuffers },
1837 { "eglSwapInterval", (_EGLProc) eglSwapInterval },
1838 { "eglTerminate", (_EGLProc) eglTerminate },
1839 { "eglWaitClient", (_EGLProc) eglWaitClient },
1840 { "eglWaitGL", (_EGLProc) eglWaitGL },
1841 { "eglWaitNative", (_EGLProc) eglWaitNative },
1842 { "eglCreateSync", (_EGLProc) eglCreateSync },
1843 { "eglDestroySync", (_EGLProc) eglDestroySync },
1844 { "eglClientWaitSync", (_EGLProc) eglClientWaitSync },
1845 { "eglGetSyncAttrib", (_EGLProc) eglGetSyncAttrib },
1846 { "eglWaitSync", (_EGLProc) eglWaitSync },
1847 { "eglCreateImage", (_EGLProc) eglCreateImage },
1848 { "eglDestroyImage", (_EGLProc) eglDestroyImage },
1849 { "eglGetPlatformDisplay", (_EGLProc) eglGetPlatformDisplay },
1850 { "eglCreatePlatformWindowSurface", (_EGLProc) eglCreatePlatformWindowSurface },
1851 { "eglCreatePlatformPixmapSurface", (_EGLProc) eglCreatePlatformPixmapSurface },
1852 { "eglCreateImageKHR", (_EGLProc) eglCreateImageKHR },
1853 { "eglDestroyImageKHR", (_EGLProc) eglDestroyImage },
1854 { "eglCreateSyncKHR", (_EGLProc) eglCreateSyncKHR },
1855 { "eglCreateSync64KHR", (_EGLProc) eglCreateSync64KHR },
1856 { "eglDestroySyncKHR", (_EGLProc) eglDestroySync },
1857 { "eglClientWaitSyncKHR", (_EGLProc) eglClientWaitSync },
1858 { "eglWaitSyncKHR", (_EGLProc) eglWaitSyncKHR },
1859 { "eglSignalSyncKHR", (_EGLProc) eglSignalSyncKHR },
1860 { "eglGetSyncAttribKHR", (_EGLProc) eglGetSyncAttribKHR },
1861 { "eglSwapBuffersRegionNOK", (_EGLProc) eglSwapBuffersRegionNOK },
1862 { "eglCreateDRMImageMESA", (_EGLProc) eglCreateDRMImageMESA },
1863 { "eglExportDRMImageMESA", (_EGLProc) eglExportDRMImageMESA },
1864 { "eglBindWaylandDisplayWL", (_EGLProc) eglBindWaylandDisplayWL },
1865 { "eglUnbindWaylandDisplayWL", (_EGLProc) eglUnbindWaylandDisplayWL },
1866 { "eglQueryWaylandBufferWL", (_EGLProc) eglQueryWaylandBufferWL },
1867 { "eglCreateWaylandBufferFromImageWL", (_EGLProc) eglCreateWaylandBufferFromImageWL },
1868 { "eglPostSubBufferNV", (_EGLProc) eglPostSubBufferNV },
1869 { "eglSwapBuffersWithDamageEXT", (_EGLProc) eglSwapBuffersWithDamageEXT },
1870 { "eglGetPlatformDisplayEXT", (_EGLProc) eglGetPlatformDisplayEXT },
1871 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc) eglCreatePlatformWindowSurfaceEXT },
1872 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc) eglCreatePlatformPixmapSurfaceEXT },
1873 { "eglGetSyncValuesCHROMIUM", (_EGLProc) eglGetSyncValuesCHROMIUM },
1874 { "eglExportDMABUFImageQueryMESA", (_EGLProc) eglExportDMABUFImageQueryMESA },
1875 { "eglExportDMABUFImageMESA", (_EGLProc) eglExportDMABUFImageMESA },
1882 RETURN_EGL_SUCCESS(NULL, NULL);
1885 if (strncmp(procname, "egl", 3) == 0) {
1886 for (i = 0; egl_functions[i].name; i++) {
1887 if (strcmp(egl_functions[i].name, procname) == 0) {
1888 ret = egl_functions[i].function;
1894 ret = _eglGetDriverProc(procname);
1896 RETURN_EGL_SUCCESS(NULL, ret);