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"
103 #include "eglstring.h"
107 * Macros to help return an API entrypoint.
109 * These macros will unlock the display and record the error code.
111 #define RETURN_EGL_ERROR(disp, err, ret) \
114 _eglUnlockDisplay(disp); \
115 /* EGL error codes are non-zero */ \
117 _eglError(err, __func__); \
121 #define RETURN_EGL_SUCCESS(disp, ret) \
122 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
124 /* record EGL_SUCCESS only when ret evaluates to true */
125 #define RETURN_EGL_EVAL(disp, ret) \
126 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
130 * A bunch of macros and checks to simplify error checking.
133 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
135 drv = _eglCheckDisplay(disp, __func__); \
137 RETURN_EGL_ERROR(disp, 0, ret); \
140 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
142 drv = _eglCheck ## type(disp, obj, __func__); \
144 RETURN_EGL_ERROR(disp, 0, ret); \
147 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
148 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
150 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
151 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
153 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
154 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
156 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
157 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
160 static inline _EGLDriver
*
161 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
164 _eglError(EGL_BAD_DISPLAY
, msg
);
167 if (!disp
->Initialized
) {
168 _eglError(EGL_NOT_INITIALIZED
, msg
);
175 static inline _EGLDriver
*
176 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
178 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
182 _eglError(EGL_BAD_SURFACE
, msg
);
189 static inline _EGLDriver
*
190 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
192 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
196 _eglError(EGL_BAD_CONTEXT
, msg
);
203 static inline _EGLDriver
*
204 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
206 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
210 _eglError(EGL_BAD_CONFIG
, msg
);
217 static inline _EGLDriver
*
218 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
220 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
224 _eglError(EGL_BAD_PARAMETER
, msg
);
232 * Lookup and lock a display.
234 static inline _EGLDisplay
*
235 _eglLockDisplay(EGLDisplay display
)
237 _EGLDisplay
*dpy
= _eglLookupDisplay(display
);
239 mtx_lock(&dpy
->Mutex
);
248 _eglUnlockDisplay(_EGLDisplay
*dpy
)
250 mtx_unlock(&dpy
->Mutex
);
255 * This is typically the first EGL function that an application calls.
256 * It associates a private _EGLDisplay object to the native display.
258 EGLDisplay EGLAPIENTRY
259 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
261 _EGLPlatformType plat
;
263 void *native_display_ptr
;
265 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
266 native_display_ptr
= (void*) nativeDisplay
;
268 plat
= _eglGetNativePlatform(native_display_ptr
);
269 dpy
= _eglFindDisplay(plat
, native_display_ptr
);
270 return _eglGetDisplayHandle(dpy
);
273 static EGLDisplay EGLAPIENTRY
274 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
275 const EGLint
*attrib_list
)
280 #ifdef HAVE_X11_PLATFORM
281 case EGL_PLATFORM_X11_EXT
:
282 dpy
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
285 #ifdef HAVE_DRM_PLATFORM
286 case EGL_PLATFORM_GBM_MESA
:
287 dpy
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
291 #ifdef HAVE_WAYLAND_PLATFORM
292 case EGL_PLATFORM_WAYLAND_EXT
:
293 dpy
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
298 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
301 return _eglGetDisplayHandle(dpy
);
305 * Copy the extension into the string and update the string pointer.
308 _eglAppendExtension(char **str
, const char *ext
)
311 size_t len
= strlen(ext
);
328 * Examine the individual extension enable/disable flags and recompute
329 * the driver's Extensions string.
332 _eglCreateExtensionsString(_EGLDisplay
*dpy
)
334 #define _EGL_CHECK_EXTENSION(ext) \
336 if (dpy->Extensions.ext) { \
337 _eglAppendExtension(&exts, "EGL_" #ext); \
338 assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
342 char *exts
= dpy
->ExtensionsString
;
344 _EGL_CHECK_EXTENSION(MESA_drm_display
);
345 _EGL_CHECK_EXTENSION(MESA_drm_image
);
346 _EGL_CHECK_EXTENSION(MESA_configless_context
);
348 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
349 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
351 _EGL_CHECK_EXTENSION(KHR_image_base
);
352 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
353 if (dpy
->Extensions
.KHR_image_base
&& dpy
->Extensions
.KHR_image_pixmap
)
354 _eglAppendExtension(&exts
, "EGL_KHR_image");
356 _EGL_CHECK_EXTENSION(KHR_vg_parent_image
);
357 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
358 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
359 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
360 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
361 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
363 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
364 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
365 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
366 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
368 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
369 _EGL_CHECK_EXTENSION(KHR_create_context
);
371 _EGL_CHECK_EXTENSION(NOK_swap_region
);
372 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
374 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
376 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
378 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
379 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
380 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
381 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
383 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
385 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
386 #undef _EGL_CHECK_EXTENSION
390 _eglCreateAPIsString(_EGLDisplay
*dpy
)
392 if (dpy
->ClientAPIs
& EGL_OPENGL_BIT
)
393 strcat(dpy
->ClientAPIsString
, "OpenGL ");
395 if (dpy
->ClientAPIs
& EGL_OPENGL_ES_BIT
)
396 strcat(dpy
->ClientAPIsString
, "OpenGL_ES ");
398 if (dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
)
399 strcat(dpy
->ClientAPIsString
, "OpenGL_ES2 ");
401 if (dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
)
402 strcat(dpy
->ClientAPIsString
, "OpenGL_ES3 ");
404 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
405 strcat(dpy
->ClientAPIsString
, "OpenVG ");
407 assert(strlen(dpy
->ClientAPIsString
) < sizeof(dpy
->ClientAPIsString
));
411 _eglComputeVersion(_EGLDisplay
*disp
)
417 * This is typically the second EGL function that an application calls.
418 * Here we load/initialize the actual hardware driver.
420 EGLBoolean EGLAPIENTRY
421 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
423 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
426 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
428 if (!disp
->Initialized
) {
429 if (!_eglMatchDriver(disp
, EGL_FALSE
))
430 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
432 /* limit to APIs supported by core */
433 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
435 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
436 * classifies it as an EGL display extension, though conceptually it's an
437 * EGL client extension.
439 * From the EGL_KHR_get_all_proc_addresses spec:
441 * The EGL implementation must expose the name
442 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
443 * EGL_KHR_get_all_proc_addresses and supports
444 * EGL_EXT_client_extensions.
446 * Mesa unconditionally exposes both client extensions mentioned above,
447 * so the spec requires that each EGLDisplay unconditionally expose
448 * EGL_KHR_get_all_proc_addresses also.
450 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
452 _eglComputeVersion(disp
);
453 _eglCreateExtensionsString(disp
);
454 _eglCreateAPIsString(disp
);
455 _eglsnprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
456 "%d.%d (%s)", disp
->Version
/ 10, disp
->Version
% 10,
460 /* Update applications version of major and minor if not NULL */
461 if ((major
!= NULL
) && (minor
!= NULL
)) {
462 *major
= disp
->Version
/ 10;
463 *minor
= disp
->Version
% 10;
466 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
470 EGLBoolean EGLAPIENTRY
471 eglTerminate(EGLDisplay dpy
)
473 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
476 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
478 if (disp
->Initialized
) {
479 _EGLDriver
*drv
= disp
->Driver
;
481 drv
->API
.Terminate(drv
, disp
);
482 /* do not reset disp->Driver */
483 disp
->ClientAPIsString
[0] = 0;
484 disp
->Initialized
= EGL_FALSE
;
487 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
491 const char * EGLAPIENTRY
492 eglQueryString(EGLDisplay dpy
, EGLint name
)
497 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
498 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
501 disp
= _eglLockDisplay(dpy
);
502 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
506 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
508 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
510 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
511 case EGL_CLIENT_APIS
:
512 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
514 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
519 EGLBoolean EGLAPIENTRY
520 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
521 EGLint config_size
, EGLint
*num_config
)
523 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
527 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
528 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
530 RETURN_EGL_EVAL(disp
, ret
);
534 EGLBoolean EGLAPIENTRY
535 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
536 EGLint config_size
, EGLint
*num_config
)
538 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
542 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
543 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
544 config_size
, num_config
);
546 RETURN_EGL_EVAL(disp
, ret
);
550 EGLBoolean EGLAPIENTRY
551 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
552 EGLint attribute
, EGLint
*value
)
554 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
555 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
559 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
560 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
562 RETURN_EGL_EVAL(disp
, ret
);
566 EGLContext EGLAPIENTRY
567 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
568 const EGLint
*attrib_list
)
570 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
571 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
572 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
574 _EGLContext
*context
;
577 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
579 if (!config
&& !disp
->Extensions
.MESA_configless_context
)
580 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
582 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
583 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
585 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
586 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
588 RETURN_EGL_EVAL(disp
, ret
);
592 EGLBoolean EGLAPIENTRY
593 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
595 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
596 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
600 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
601 _eglUnlinkContext(context
);
602 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
604 RETURN_EGL_EVAL(disp
, ret
);
608 EGLBoolean EGLAPIENTRY
609 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
612 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
613 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
614 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
615 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
620 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
623 /* display is allowed to be uninitialized under certain condition */
624 if (!disp
->Initialized
) {
625 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
626 ctx
!= EGL_NO_CONTEXT
)
627 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
630 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
632 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
633 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
634 if (!draw_surf
|| !read_surf
) {
635 /* From the EGL 1.4 (20130211) spec:
637 * To release the current context without assigning a new one, set ctx
638 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
640 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
641 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
643 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
644 (!read_surf
&& read
!= EGL_NO_SURFACE
))
645 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
646 if (draw_surf
|| read_surf
)
647 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
650 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
652 RETURN_EGL_EVAL(disp
, ret
);
656 EGLBoolean EGLAPIENTRY
657 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
658 EGLint attribute
, EGLint
*value
)
660 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
661 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
665 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
666 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
668 RETURN_EGL_EVAL(disp
, ret
);
673 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
674 void *native_window
, const EGLint
*attrib_list
)
676 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
681 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
683 if (native_window
== NULL
)
684 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
686 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
688 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
690 RETURN_EGL_EVAL(disp
, ret
);
694 EGLSurface EGLAPIENTRY
695 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
696 EGLNativeWindowType window
, const EGLint
*attrib_list
)
698 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
699 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
700 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
705 static EGLSurface EGLAPIENTRY
706 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
708 const EGLint
*attrib_list
)
710 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
712 #ifdef HAVE_X11_PLATFORM
713 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
714 /* The `native_window` parameter for the X11 platform differs between
715 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
716 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
717 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
718 * `Window*`. Convert `Window*` to `Window` because that's what
719 * dri2_x11_create_window_surface() expects.
721 native_window
= (void*) (* (Window
*) native_window
);
725 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
731 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
732 void *native_pixmap
, const EGLint
*attrib_list
)
734 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
739 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
740 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
742 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
744 RETURN_EGL_EVAL(disp
, ret
);
748 EGLSurface EGLAPIENTRY
749 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
750 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
752 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
753 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
754 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
758 static EGLSurface EGLAPIENTRY
759 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
761 const EGLint
*attrib_list
)
763 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
765 #ifdef HAVE_X11_PLATFORM
766 /* The `native_pixmap` parameter for the X11 platform differs between
767 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
768 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
769 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
770 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
771 * dri2_x11_create_pixmap_surface() expects.
773 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
) {
774 native_pixmap
= (void*) (* (Pixmap
*) native_pixmap
);
778 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
783 EGLSurface EGLAPIENTRY
784 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
785 const EGLint
*attrib_list
)
787 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
788 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
793 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
795 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
796 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
798 RETURN_EGL_EVAL(disp
, ret
);
802 EGLBoolean EGLAPIENTRY
803 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
805 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
806 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
810 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
811 _eglUnlinkSurface(surf
);
812 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
814 RETURN_EGL_EVAL(disp
, ret
);
817 EGLBoolean EGLAPIENTRY
818 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
819 EGLint attribute
, EGLint
*value
)
821 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
822 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
826 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
827 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
829 RETURN_EGL_EVAL(disp
, ret
);
832 EGLBoolean EGLAPIENTRY
833 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
834 EGLint attribute
, EGLint value
)
836 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
837 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
841 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
842 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
844 RETURN_EGL_EVAL(disp
, ret
);
848 EGLBoolean EGLAPIENTRY
849 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
851 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
852 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
856 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
857 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
859 RETURN_EGL_EVAL(disp
, ret
);
863 EGLBoolean EGLAPIENTRY
864 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
866 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
867 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
871 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
872 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
874 RETURN_EGL_EVAL(disp
, ret
);
878 EGLBoolean EGLAPIENTRY
879 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
881 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
882 _EGLContext
*ctx
= _eglGetCurrentContext();
887 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
889 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
890 ctx
->Resource
.Display
!= disp
)
891 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
893 surf
= ctx
->DrawSurface
;
894 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
895 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
897 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
899 RETURN_EGL_EVAL(disp
, ret
);
903 EGLBoolean EGLAPIENTRY
904 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
906 _EGLContext
*ctx
= _eglGetCurrentContext();
907 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
908 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
912 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
914 /* surface must be bound to current context in EGL 1.4 */
915 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
916 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
917 surf
!= ctx
->DrawSurface
)
918 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
921 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
923 RETURN_EGL_EVAL(disp
, ret
);
927 #ifdef EGL_EXT_swap_buffers_with_damage
929 static EGLBoolean EGLAPIENTRY
930 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
931 EGLint
*rects
, EGLint n_rects
)
933 _EGLContext
*ctx
= _eglGetCurrentContext();
934 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
935 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
939 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
941 /* surface must be bound to current context in EGL 1.4 */
942 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
943 surf
!= ctx
->DrawSurface
)
944 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
946 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
947 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
949 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
951 RETURN_EGL_EVAL(disp
, ret
);
954 #endif /* EGL_EXT_swap_buffers_with_damage */
956 EGLBoolean EGLAPIENTRY
957 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
959 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
960 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
963 void *native_pixmap_ptr
;
965 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
966 native_pixmap_ptr
= (void*) target
;
968 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
969 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
970 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
971 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
973 RETURN_EGL_EVAL(disp
, ret
);
977 EGLBoolean EGLAPIENTRY
980 _EGLContext
*ctx
= _eglGetCurrentContext();
986 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
988 disp
= ctx
->Resource
.Display
;
989 mtx_lock(&disp
->Mutex
);
991 /* let bad current context imply bad current surface */
992 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
993 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
994 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
996 /* a valid current context implies an initialized current display */
997 assert(disp
->Initialized
);
999 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1001 RETURN_EGL_EVAL(disp
, ret
);
1005 EGLBoolean EGLAPIENTRY
1008 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1009 EGLint api_index
= t
->CurrentAPIIndex
;
1010 EGLint es_index
= _eglConvertApiToIndex(EGL_OPENGL_ES_API
);
1013 if (api_index
!= es_index
&& _eglIsCurrentThreadDummy())
1014 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1016 t
->CurrentAPIIndex
= es_index
;
1017 ret
= eglWaitClient();
1018 t
->CurrentAPIIndex
= api_index
;
1023 EGLBoolean EGLAPIENTRY
1024 eglWaitNative(EGLint engine
)
1026 _EGLContext
*ctx
= _eglGetCurrentContext();
1032 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1034 disp
= ctx
->Resource
.Display
;
1035 mtx_lock(&disp
->Mutex
);
1037 /* let bad current context imply bad current surface */
1038 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1039 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1040 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1042 /* a valid current context implies an initialized current display */
1043 assert(disp
->Initialized
);
1045 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1047 RETURN_EGL_EVAL(disp
, ret
);
1051 EGLDisplay EGLAPIENTRY
1052 eglGetCurrentDisplay(void)
1054 _EGLContext
*ctx
= _eglGetCurrentContext();
1057 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1059 RETURN_EGL_SUCCESS(NULL
, ret
);
1063 EGLContext EGLAPIENTRY
1064 eglGetCurrentContext(void)
1066 _EGLContext
*ctx
= _eglGetCurrentContext();
1069 ret
= _eglGetContextHandle(ctx
);
1071 RETURN_EGL_SUCCESS(NULL
, ret
);
1075 EGLSurface EGLAPIENTRY
1076 eglGetCurrentSurface(EGLint readdraw
)
1078 _EGLContext
*ctx
= _eglGetCurrentContext();
1079 EGLint err
= EGL_SUCCESS
;
1084 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1088 surf
= ctx
->DrawSurface
;
1091 surf
= ctx
->ReadSurface
;
1095 err
= EGL_BAD_PARAMETER
;
1099 ret
= _eglGetSurfaceHandle(surf
);
1101 RETURN_EGL_ERROR(NULL
, err
, ret
);
1108 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1109 EGLint e
= t
->LastError
;
1110 if (!_eglIsCurrentThreadDummy())
1111 t
->LastError
= EGL_SUCCESS
;
1116 #ifdef EGL_MESA_drm_display
1118 static EGLDisplay EGLAPIENTRY
1119 eglGetDRMDisplayMESA(int fd
)
1121 _EGLDisplay
*dpy
= _eglFindDisplay(_EGL_PLATFORM_DRM
, (void *) (intptr_t) fd
);
1122 return _eglGetDisplayHandle(dpy
);
1125 #endif /* EGL_MESA_drm_display */
1132 * Specify the client API to use for subsequent calls including:
1133 * eglCreateContext()
1134 * eglGetCurrentContext()
1135 * eglGetCurrentDisplay()
1136 * eglGetCurrentSurface()
1137 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1140 * See section 3.7 "Rendering Context" in the EGL specification for details.
1142 EGLBoolean EGLAPIENTRY
1143 eglBindAPI(EGLenum api
)
1145 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1147 if (_eglIsCurrentThreadDummy())
1148 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1150 if (!_eglIsApiValid(api
))
1151 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1153 t
->CurrentAPIIndex
= _eglConvertApiToIndex(api
);
1155 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1160 * Return the last value set with eglBindAPI().
1165 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1168 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1169 ret
= _eglConvertApiFromIndex(t
->CurrentAPIIndex
);
1171 RETURN_EGL_SUCCESS(NULL
, ret
);
1175 EGLSurface EGLAPIENTRY
1176 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1177 EGLClientBuffer buffer
, EGLConfig config
,
1178 const EGLint
*attrib_list
)
1180 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1181 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1186 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1188 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1190 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1192 RETURN_EGL_EVAL(disp
, ret
);
1196 EGLBoolean EGLAPIENTRY
1197 eglReleaseThread(void)
1199 /* unbind current contexts */
1200 if (!_eglIsCurrentThreadDummy()) {
1201 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1202 EGLint api_index
= t
->CurrentAPIIndex
;
1205 for (i
= 0; i
< _EGL_API_NUM_APIS
; i
++) {
1206 _EGLContext
*ctx
= t
->CurrentContexts
[i
];
1208 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1211 t
->CurrentAPIIndex
= i
;
1213 mtx_lock(&disp
->Mutex
);
1215 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1216 mtx_unlock(&disp
->Mutex
);
1220 t
->CurrentAPIIndex
= api_index
;
1223 _eglDestroyCurrentThread();
1225 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1229 static EGLImageKHR EGLAPIENTRY
1230 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1231 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1233 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1234 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1239 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1240 if (!disp
->Extensions
.KHR_image_base
)
1241 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1242 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1243 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1244 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1245 * <ctx> must be EGL_NO_CONTEXT..."
1247 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1248 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1250 img
= drv
->API
.CreateImageKHR(drv
,
1251 disp
, context
, target
, buffer
, attr_list
);
1252 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1254 RETURN_EGL_EVAL(disp
, ret
);
1258 static EGLBoolean EGLAPIENTRY
1259 eglDestroyImageKHR(EGLDisplay dpy
, EGLImageKHR image
)
1261 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1262 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1266 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1267 if (!disp
->Extensions
.KHR_image_base
)
1268 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1270 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1272 _eglUnlinkImage(img
);
1273 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1275 RETURN_EGL_EVAL(disp
, ret
);
1280 _eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLint
*attrib_list
,
1281 const EGLAttribKHR
*attrib_list64
, EGLBoolean is64
)
1283 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1284 _EGLContext
*ctx
= _eglGetCurrentContext();
1289 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1291 if (!disp
->Extensions
.KHR_cl_event2
&& is64
)
1292 RETURN_EGL_EVAL(disp
, EGL_NO_SYNC_KHR
);
1294 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1295 if (!ctx
|| ctx
->Resource
.Display
!= dpy
||
1296 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1297 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1300 case EGL_SYNC_FENCE_KHR
:
1301 if (!disp
->Extensions
.KHR_fence_sync
)
1302 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_NO_SYNC_KHR
);
1304 case EGL_SYNC_REUSABLE_KHR
:
1305 if (!disp
->Extensions
.KHR_reusable_sync
)
1306 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_NO_SYNC_KHR
);
1308 case EGL_SYNC_CL_EVENT_KHR
:
1309 if (!disp
->Extensions
.KHR_cl_event2
)
1310 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_NO_SYNC_KHR
);
1313 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_NO_SYNC_KHR
);
1316 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
, attrib_list64
);
1317 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1319 RETURN_EGL_EVAL(disp
, ret
);
1323 static EGLSyncKHR EGLAPIENTRY
1324 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*attrib_list
)
1326 return _eglCreateSync(dpy
, type
, attrib_list
, NULL
, EGL_FALSE
);
1330 static EGLSyncKHR EGLAPIENTRY
1331 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttribKHR
*attrib_list
)
1333 return _eglCreateSync(dpy
, type
, NULL
, attrib_list
, EGL_TRUE
);
1337 static EGLBoolean EGLAPIENTRY
1338 eglDestroySyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
)
1340 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1341 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1345 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1346 assert(disp
->Extensions
.KHR_reusable_sync
||
1347 disp
->Extensions
.KHR_fence_sync
);
1350 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1352 RETURN_EGL_EVAL(disp
, ret
);
1356 static EGLint EGLAPIENTRY
1357 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLint flags
, EGLTimeKHR timeout
)
1359 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1360 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1364 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1365 assert(disp
->Extensions
.KHR_reusable_sync
||
1366 disp
->Extensions
.KHR_fence_sync
);
1368 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1369 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1371 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1373 RETURN_EGL_EVAL(disp
, ret
);
1377 static EGLint EGLAPIENTRY
1378 eglWaitSyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLint flags
)
1380 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1381 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1382 _EGLContext
*ctx
= _eglGetCurrentContext();
1386 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1387 assert(disp
->Extensions
.KHR_wait_sync
);
1389 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1390 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1391 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1393 /* the API doesn't allow any flags yet */
1395 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1397 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1399 RETURN_EGL_EVAL(disp
, ret
);
1403 static EGLBoolean EGLAPIENTRY
1404 eglSignalSyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLenum mode
)
1406 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1407 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1411 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1412 assert(disp
->Extensions
.KHR_reusable_sync
);
1413 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
1415 RETURN_EGL_EVAL(disp
, ret
);
1419 static EGLBoolean EGLAPIENTRY
1420 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLint attribute
, EGLint
*value
)
1422 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1423 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1427 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1428 assert(disp
->Extensions
.KHR_reusable_sync
||
1429 disp
->Extensions
.KHR_fence_sync
);
1430 ret
= drv
->API
.GetSyncAttribKHR(drv
, disp
, s
, attribute
, value
);
1432 RETURN_EGL_EVAL(disp
, ret
);
1436 #ifdef EGL_NOK_swap_region
1438 static EGLBoolean EGLAPIENTRY
1439 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
1440 EGLint numRects
, const EGLint
*rects
)
1442 _EGLContext
*ctx
= _eglGetCurrentContext();
1443 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1444 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1448 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1450 if (!disp
->Extensions
.NOK_swap_region
)
1451 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1453 /* surface must be bound to current context in EGL 1.4 */
1454 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1455 surf
!= ctx
->DrawSurface
)
1456 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1458 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
1460 RETURN_EGL_EVAL(disp
, ret
);
1463 #endif /* EGL_NOK_swap_region */
1466 #ifdef EGL_MESA_drm_image
1468 static EGLImageKHR EGLAPIENTRY
1469 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
1471 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1476 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1477 if (!disp
->Extensions
.MESA_drm_image
)
1478 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1480 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
1481 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1483 RETURN_EGL_EVAL(disp
, ret
);
1486 static EGLBoolean EGLAPIENTRY
1487 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImageKHR image
,
1488 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
1490 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1491 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1495 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1496 assert(disp
->Extensions
.MESA_drm_image
);
1499 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1501 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
1503 RETURN_EGL_EVAL(disp
, ret
);
1508 #ifdef EGL_WL_bind_wayland_display
1511 static EGLBoolean EGLAPIENTRY
1512 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1514 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1518 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1519 assert(disp
->Extensions
.WL_bind_wayland_display
);
1522 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1524 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
1526 RETURN_EGL_EVAL(disp
, ret
);
1529 static EGLBoolean EGLAPIENTRY
1530 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1532 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1536 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1537 assert(disp
->Extensions
.WL_bind_wayland_display
);
1540 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1542 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
1544 RETURN_EGL_EVAL(disp
, ret
);
1547 static EGLBoolean EGLAPIENTRY
1548 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
1549 EGLint attribute
, EGLint
*value
)
1551 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1555 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1556 assert(disp
->Extensions
.WL_bind_wayland_display
);
1559 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1561 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
1563 RETURN_EGL_EVAL(disp
, ret
);
1567 #ifdef EGL_WL_create_wayland_buffer_from_image
1568 static struct wl_buffer
* EGLAPIENTRY
1569 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImageKHR image
)
1571 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1574 struct wl_buffer
*ret
;
1576 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
1577 assert(disp
->Extensions
.WL_create_wayland_buffer_from_image
);
1579 img
= _eglLookupImage(image
, disp
);
1582 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
1584 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
1586 RETURN_EGL_EVAL(disp
, ret
);
1590 static EGLBoolean EGLAPIENTRY
1591 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
1592 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
1594 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1595 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1599 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1601 if (!disp
->Extensions
.NV_post_sub_buffer
)
1602 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1604 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
1606 RETURN_EGL_EVAL(disp
, ret
);
1609 static EGLBoolean EGLAPIENTRY
1610 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
1611 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
1614 _EGLDisplay
*disp
= _eglLockDisplay(display
);
1615 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1619 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1620 if (!disp
->Extensions
.CHROMIUM_sync_control
)
1621 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1623 if (!ust
|| !msc
|| !sbc
)
1624 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1626 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
1628 RETURN_EGL_EVAL(disp
, ret
);
1631 #ifdef EGL_MESA_image_dma_buf_export
1632 static EGLBoolean EGLAPIENTRY
1633 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImageKHR image
,
1634 EGLint
*fourcc
, EGLint
*nplanes
,
1635 EGLuint64KHR
*modifiers
)
1637 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1638 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1642 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1643 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
1646 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1648 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
1651 RETURN_EGL_EVAL(disp
, ret
);
1654 static EGLBoolean EGLAPIENTRY
1655 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImageKHR image
,
1656 int *fds
, EGLint
*strides
, EGLint
*offsets
)
1658 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1659 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1663 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1664 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
1667 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1669 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
1671 RETURN_EGL_EVAL(disp
, ret
);
1675 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
1676 eglGetProcAddress(const char *procname
)
1678 static const struct {
1681 } egl_functions
[] = {
1682 /* core functions queryable in the presence of
1683 * EGL_KHR_get_all_proc_addresses or EGL 1.5
1685 /* alphabetical order */
1686 { "eglBindAPI", (_EGLProc
) eglBindAPI
},
1687 { "eglBindTexImage", (_EGLProc
) eglBindTexImage
},
1688 { "eglChooseConfig", (_EGLProc
) eglChooseConfig
},
1689 { "eglCopyBuffers", (_EGLProc
) eglCopyBuffers
},
1690 { "eglCreateContext", (_EGLProc
) eglCreateContext
},
1691 { "eglCreatePbufferFromClientBuffer", (_EGLProc
) eglCreatePbufferFromClientBuffer
},
1692 { "eglCreatePbufferSurface", (_EGLProc
) eglCreatePbufferSurface
},
1693 { "eglCreatePixmapSurface", (_EGLProc
) eglCreatePixmapSurface
},
1694 { "eglCreateWindowSurface", (_EGLProc
) eglCreateWindowSurface
},
1695 { "eglDestroyContext", (_EGLProc
) eglDestroyContext
},
1696 { "eglDestroySurface", (_EGLProc
) eglDestroySurface
},
1697 { "eglGetConfigAttrib", (_EGLProc
) eglGetConfigAttrib
},
1698 { "eglGetConfigs", (_EGLProc
) eglGetConfigs
},
1699 { "eglGetCurrentContext", (_EGLProc
) eglGetCurrentContext
},
1700 { "eglGetCurrentDisplay", (_EGLProc
) eglGetCurrentDisplay
},
1701 { "eglGetCurrentSurface", (_EGLProc
) eglGetCurrentSurface
},
1702 { "eglGetDisplay", (_EGLProc
) eglGetDisplay
},
1703 { "eglGetError", (_EGLProc
) eglGetError
},
1704 { "eglGetProcAddress", (_EGLProc
) eglGetProcAddress
},
1705 { "eglInitialize", (_EGLProc
) eglInitialize
},
1706 { "eglMakeCurrent", (_EGLProc
) eglMakeCurrent
},
1707 { "eglQueryAPI", (_EGLProc
) eglQueryAPI
},
1708 { "eglQueryContext", (_EGLProc
) eglQueryContext
},
1709 { "eglQueryString", (_EGLProc
) eglQueryString
},
1710 { "eglQuerySurface", (_EGLProc
) eglQuerySurface
},
1711 { "eglReleaseTexImage", (_EGLProc
) eglReleaseTexImage
},
1712 { "eglReleaseThread", (_EGLProc
) eglReleaseThread
},
1713 { "eglSurfaceAttrib", (_EGLProc
) eglSurfaceAttrib
},
1714 { "eglSwapBuffers", (_EGLProc
) eglSwapBuffers
},
1715 { "eglSwapInterval", (_EGLProc
) eglSwapInterval
},
1716 { "eglTerminate", (_EGLProc
) eglTerminate
},
1717 { "eglWaitClient", (_EGLProc
) eglWaitClient
},
1718 { "eglWaitGL", (_EGLProc
) eglWaitGL
},
1719 { "eglWaitNative", (_EGLProc
) eglWaitNative
},
1720 #ifdef EGL_MESA_drm_display
1721 { "eglGetDRMDisplayMESA", (_EGLProc
) eglGetDRMDisplayMESA
},
1723 { "eglCreateImageKHR", (_EGLProc
) eglCreateImageKHR
},
1724 { "eglDestroyImageKHR", (_EGLProc
) eglDestroyImageKHR
},
1725 { "eglCreateSyncKHR", (_EGLProc
) eglCreateSyncKHR
},
1726 { "eglCreateSync64KHR", (_EGLProc
) eglCreateSync64KHR
},
1727 { "eglDestroySyncKHR", (_EGLProc
) eglDestroySyncKHR
},
1728 { "eglClientWaitSyncKHR", (_EGLProc
) eglClientWaitSyncKHR
},
1729 { "eglWaitSyncKHR", (_EGLProc
) eglWaitSyncKHR
},
1730 { "eglSignalSyncKHR", (_EGLProc
) eglSignalSyncKHR
},
1731 { "eglGetSyncAttribKHR", (_EGLProc
) eglGetSyncAttribKHR
},
1732 #ifdef EGL_NOK_swap_region
1733 { "eglSwapBuffersRegionNOK", (_EGLProc
) eglSwapBuffersRegionNOK
},
1735 #ifdef EGL_MESA_drm_image
1736 { "eglCreateDRMImageMESA", (_EGLProc
) eglCreateDRMImageMESA
},
1737 { "eglExportDRMImageMESA", (_EGLProc
) eglExportDRMImageMESA
},
1739 #ifdef EGL_WL_bind_wayland_display
1740 { "eglBindWaylandDisplayWL", (_EGLProc
) eglBindWaylandDisplayWL
},
1741 { "eglUnbindWaylandDisplayWL", (_EGLProc
) eglUnbindWaylandDisplayWL
},
1742 { "eglQueryWaylandBufferWL", (_EGLProc
) eglQueryWaylandBufferWL
},
1744 #ifdef EGL_WL_create_wayland_buffer_from_image
1745 { "eglCreateWaylandBufferFromImageWL", (_EGLProc
) eglCreateWaylandBufferFromImageWL
},
1747 { "eglPostSubBufferNV", (_EGLProc
) eglPostSubBufferNV
},
1748 #ifdef EGL_EXT_swap_buffers_with_damage
1749 { "eglSwapBuffersWithDamageEXT", (_EGLProc
) eglSwapBuffersWithDamageEXT
},
1751 { "eglGetPlatformDisplayEXT", (_EGLProc
) eglGetPlatformDisplayEXT
},
1752 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc
) eglCreatePlatformWindowSurfaceEXT
},
1753 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc
) eglCreatePlatformPixmapSurfaceEXT
},
1754 { "eglGetSyncValuesCHROMIUM", (_EGLProc
) eglGetSyncValuesCHROMIUM
},
1755 #ifdef EGL_MESA_image_dma_buf_export
1756 { "eglExportDMABUFImageQueryMESA", (_EGLProc
) eglExportDMABUFImageQueryMESA
},
1757 { "eglExportDMABUFImageMESA", (_EGLProc
) eglExportDMABUFImageMESA
},
1765 RETURN_EGL_SUCCESS(NULL
, NULL
);
1768 if (strncmp(procname
, "egl", 3) == 0) {
1769 for (i
= 0; egl_functions
[i
].name
; i
++) {
1770 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
1771 ret
= egl_functions
[i
].function
;
1777 ret
= _eglGetDriverProc(procname
);
1779 RETURN_EGL_SUCCESS(NULL
, ret
);