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 "GL/mesa_glinterop.h"
92 #include "eglcompiler.h"
94 #include "eglglobals.h"
95 #include "eglcontext.h"
96 #include "egldisplay.h"
97 #include "egltypedefs.h"
98 #include "eglcurrent.h"
99 #include "egldriver.h"
100 #include "eglsurface.h"
101 #include "eglconfig.h"
102 #include "eglimage.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
);
254 _eglSetFuncName(const char *funcName
, _EGLDisplay
*disp
, EGLenum objectType
, _EGLResource
*object
)
256 _EGLThreadInfo
*thr
= _eglGetCurrentThread();
257 if (!_eglIsCurrentThreadDummy()) {
258 thr
->CurrentFuncName
= funcName
;
259 thr
->CurrentObjectLabel
= NULL
;
261 if (objectType
== EGL_OBJECT_THREAD_KHR
)
262 thr
->CurrentObjectLabel
= thr
->Label
;
263 else if (objectType
== EGL_OBJECT_DISPLAY_KHR
&& disp
)
264 thr
->CurrentObjectLabel
= disp
->Label
;
266 thr
->CurrentObjectLabel
= object
->Label
;
271 _eglDebugReportFull(EGL_BAD_ALLOC
, funcName
, funcName
,
272 EGL_DEBUG_MSG_CRITICAL_KHR
, NULL
, NULL
);
276 #define _EGL_FUNC_START(disp, objectType, object, ret) \
278 if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \
280 _eglUnlockDisplay(disp); \
286 * Convert an attribute list from EGLint[] to EGLAttrib[].
288 * Return an EGL error code. The output parameter out_attrib_list is modified
292 _eglConvertIntsToAttribs(const EGLint
*int_list
, EGLAttrib
**out_attrib_list
)
295 EGLAttrib
*attrib_list
;
298 while (int_list
[2*len
] != EGL_NONE
)
303 *out_attrib_list
= NULL
;
307 if (2*len
+ 1 > SIZE_MAX
/ sizeof(EGLAttrib
))
308 return EGL_BAD_ALLOC
;
310 attrib_list
= malloc((2*len
+ 1) * sizeof(EGLAttrib
));
312 return EGL_BAD_ALLOC
;
314 for (size_t i
= 0; i
< len
; ++i
) {
315 attrib_list
[2*i
+ 0] = int_list
[2*i
+ 0];
316 attrib_list
[2*i
+ 1] = int_list
[2*i
+ 1];
319 attrib_list
[2*len
] = EGL_NONE
;
321 *out_attrib_list
= attrib_list
;
327 _eglConvertAttribsToInt(const EGLAttrib
*attr_list
)
329 EGLint
*int_attribs
= NULL
;
331 /* Convert attributes from EGLAttrib[] to EGLint[] */
335 while (attr_list
[size
] != EGL_NONE
)
338 size
+= 1; /* add space for EGL_NONE */
340 int_attribs
= calloc(size
, sizeof(int_attribs
[0]));
344 for (i
= 0; i
< size
; i
++)
345 int_attribs
[i
] = attr_list
[i
];
352 * This is typically the first EGL function that an application calls.
353 * It associates a private _EGLDisplay object to the native display.
355 EGLDisplay EGLAPIENTRY
356 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
358 _EGLPlatformType plat
;
360 void *native_display_ptr
;
362 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
364 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
365 native_display_ptr
= (void*) nativeDisplay
;
367 plat
= _eglGetNativePlatform(native_display_ptr
);
368 dpy
= _eglFindDisplay(plat
, native_display_ptr
);
369 return _eglGetDisplayHandle(dpy
);
373 _eglGetPlatformDisplayCommon(EGLenum platform
, void *native_display
,
374 const EGLint
*attrib_list
)
379 #ifdef HAVE_X11_PLATFORM
380 case EGL_PLATFORM_X11_EXT
:
381 dpy
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
384 #ifdef HAVE_DRM_PLATFORM
385 case EGL_PLATFORM_GBM_MESA
:
386 dpy
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
390 #ifdef HAVE_WAYLAND_PLATFORM
391 case EGL_PLATFORM_WAYLAND_EXT
:
392 dpy
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
396 #ifdef HAVE_SURFACELESS_PLATFORM
397 case EGL_PLATFORM_SURFACELESS_MESA
:
398 dpy
= _eglGetSurfacelessDisplay(native_display
, attrib_list
);
402 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
405 return _eglGetDisplayHandle(dpy
);
408 static EGLDisplay EGLAPIENTRY
409 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
410 const EGLint
*attrib_list
)
412 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
413 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
416 EGLDisplay EGLAPIENTRY
417 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
418 const EGLAttrib
*attrib_list
)
423 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
425 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
426 if (attrib_list
&& !int_attribs
)
427 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
429 display
= _eglGetPlatformDisplayCommon(platform
, native_display
, int_attribs
);
435 * Copy the extension into the string and update the string pointer.
438 _eglAppendExtension(char **str
, const char *ext
)
441 size_t len
= strlen(ext
);
458 * Examine the individual extension enable/disable flags and recompute
459 * the driver's Extensions string.
462 _eglCreateExtensionsString(_EGLDisplay
*dpy
)
464 #define _EGL_CHECK_EXTENSION(ext) \
466 if (dpy->Extensions.ext) { \
467 _eglAppendExtension(&exts, "EGL_" #ext); \
468 assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
472 char *exts
= dpy
->ExtensionsString
;
474 /* Please keep these sorted alphabetically. */
475 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
476 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
477 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
479 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
481 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
482 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
483 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
484 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
486 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
487 _EGL_CHECK_EXTENSION(KHR_create_context
);
488 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
489 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
490 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
491 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
492 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
493 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
494 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
495 if (dpy
->Extensions
.KHR_image_base
&& dpy
->Extensions
.KHR_image_pixmap
)
496 _eglAppendExtension(&exts
, "EGL_KHR_image");
497 _EGL_CHECK_EXTENSION(KHR_image_base
);
498 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
499 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
500 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
501 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
502 if (dpy
->Extensions
.EXT_swap_buffers_with_damage
)
503 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
504 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
506 if (dpy
->Extensions
.KHR_no_config_context
)
507 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
508 _EGL_CHECK_EXTENSION(MESA_drm_image
);
509 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
511 _EGL_CHECK_EXTENSION(NOK_swap_region
);
512 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
514 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
516 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
517 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
519 #undef _EGL_CHECK_EXTENSION
523 _eglCreateAPIsString(_EGLDisplay
*dpy
)
525 if (dpy
->ClientAPIs
& EGL_OPENGL_BIT
)
526 strcat(dpy
->ClientAPIsString
, "OpenGL ");
528 if (dpy
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
529 dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
530 dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
531 strcat(dpy
->ClientAPIsString
, "OpenGL_ES ");
534 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
535 strcat(dpy
->ClientAPIsString
, "OpenVG ");
537 assert(strlen(dpy
->ClientAPIsString
) < sizeof(dpy
->ClientAPIsString
));
541 _eglComputeVersion(_EGLDisplay
*disp
)
545 if (disp
->Extensions
.KHR_fence_sync
&&
546 disp
->Extensions
.KHR_cl_event2
&&
547 disp
->Extensions
.KHR_wait_sync
&&
548 disp
->Extensions
.KHR_image_base
&&
549 disp
->Extensions
.KHR_gl_texture_2D_image
&&
550 disp
->Extensions
.KHR_gl_texture_3D_image
&&
551 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
552 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
553 disp
->Extensions
.KHR_create_context
&&
554 disp
->Extensions
.EXT_create_context_robustness
&&
555 disp
->Extensions
.KHR_get_all_proc_addresses
&&
556 disp
->Extensions
.KHR_gl_colorspace
&&
557 disp
->Extensions
.KHR_surfaceless_context
)
562 * This is typically the second EGL function that an application calls.
563 * Here we load/initialize the actual hardware driver.
565 EGLBoolean EGLAPIENTRY
566 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
568 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
570 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
573 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
575 if (!disp
->Initialized
) {
576 if (!_eglMatchDriver(disp
, EGL_FALSE
))
577 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
579 /* limit to APIs supported by core */
580 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
582 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
583 * classifies it as an EGL display extension, though conceptually it's an
584 * EGL client extension.
586 * From the EGL_KHR_get_all_proc_addresses spec:
588 * The EGL implementation must expose the name
589 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
590 * EGL_KHR_get_all_proc_addresses and supports
591 * EGL_EXT_client_extensions.
593 * Mesa unconditionally exposes both client extensions mentioned above,
594 * so the spec requires that each EGLDisplay unconditionally expose
595 * EGL_KHR_get_all_proc_addresses also.
597 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
599 _eglComputeVersion(disp
);
600 _eglCreateExtensionsString(disp
);
601 _eglCreateAPIsString(disp
);
602 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
603 "%d.%d (%s)", disp
->Version
/ 10, disp
->Version
% 10,
607 /* Update applications version of major and minor if not NULL */
608 if ((major
!= NULL
) && (minor
!= NULL
)) {
609 *major
= disp
->Version
/ 10;
610 *minor
= disp
->Version
% 10;
613 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
617 EGLBoolean EGLAPIENTRY
618 eglTerminate(EGLDisplay dpy
)
620 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
622 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
625 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
627 if (disp
->Initialized
) {
628 _EGLDriver
*drv
= disp
->Driver
;
630 drv
->API
.Terminate(drv
, disp
);
631 /* do not reset disp->Driver */
632 disp
->ClientAPIsString
[0] = 0;
633 disp
->Initialized
= EGL_FALSE
;
636 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
640 const char * EGLAPIENTRY
641 eglQueryString(EGLDisplay dpy
, EGLint name
)
646 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
647 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
650 disp
= _eglLockDisplay(dpy
);
651 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
652 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
656 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
658 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
660 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
661 case EGL_CLIENT_APIS
:
662 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
664 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
669 EGLBoolean EGLAPIENTRY
670 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
671 EGLint config_size
, EGLint
*num_config
)
673 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
677 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
679 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
680 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
682 RETURN_EGL_EVAL(disp
, ret
);
686 EGLBoolean EGLAPIENTRY
687 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
688 EGLint config_size
, EGLint
*num_config
)
690 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
694 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
696 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
697 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
698 config_size
, num_config
);
700 RETURN_EGL_EVAL(disp
, ret
);
704 EGLBoolean EGLAPIENTRY
705 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
706 EGLint attribute
, EGLint
*value
)
708 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
709 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
713 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
715 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
716 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
718 RETURN_EGL_EVAL(disp
, ret
);
722 EGLContext EGLAPIENTRY
723 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
724 const EGLint
*attrib_list
)
726 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
727 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
728 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
730 _EGLContext
*context
;
733 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
735 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
737 if (config
!= EGL_NO_CONFIG_KHR
)
738 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
739 else if (!disp
->Extensions
.KHR_no_config_context
)
740 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
742 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
743 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
745 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
746 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
748 RETURN_EGL_EVAL(disp
, ret
);
752 EGLBoolean EGLAPIENTRY
753 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
755 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
756 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
760 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
762 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
763 _eglUnlinkContext(context
);
764 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
766 RETURN_EGL_EVAL(disp
, ret
);
770 EGLBoolean EGLAPIENTRY
771 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
774 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
775 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
776 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
777 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
781 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
784 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
787 /* display is allowed to be uninitialized under certain condition */
788 if (!disp
->Initialized
) {
789 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
790 ctx
!= EGL_NO_CONTEXT
)
791 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
794 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
796 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
797 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
798 if (!draw_surf
|| !read_surf
) {
799 /* From the EGL 1.4 (20130211) spec:
801 * To release the current context without assigning a new one, set ctx
802 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
804 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
805 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
807 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
808 (!read_surf
&& read
!= EGL_NO_SURFACE
))
809 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
810 if (draw_surf
|| read_surf
)
811 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
814 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
816 RETURN_EGL_EVAL(disp
, ret
);
820 EGLBoolean EGLAPIENTRY
821 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
822 EGLint attribute
, EGLint
*value
)
824 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
825 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
829 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
831 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
832 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
834 RETURN_EGL_EVAL(disp
, ret
);
839 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
840 void *native_window
, const EGLint
*attrib_list
)
842 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
848 if (native_window
== NULL
)
849 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
851 #ifdef HAVE_SURFACELESS_PLATFORM
852 if (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
853 /* From the EGL_MESA_platform_surfaceless spec (v1):
855 * eglCreatePlatformWindowSurface fails when called with a <display>
856 * that belongs to the surfaceless platform. It returns
857 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
858 * justification for this unconditional failure is that the
859 * surfaceless platform has no native windows, and therefore the
860 * <native_window> parameter is always invalid.
862 * This check must occur before checking the EGLConfig, which emits
865 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
869 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
871 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
873 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
875 RETURN_EGL_EVAL(disp
, ret
);
879 EGLSurface EGLAPIENTRY
880 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
881 EGLNativeWindowType window
, const EGLint
*attrib_list
)
883 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
885 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
886 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
887 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
892 fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
894 #ifdef HAVE_X11_PLATFORM
895 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
896 /* The `native_window` parameter for the X11 platform differs between
897 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
898 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
899 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
900 * `Window*`. Convert `Window*` to `Window` because that's what
901 * dri2_x11_create_window_surface() expects.
903 return (void *)(* (Window
*) native_window
);
906 return native_window
;
909 static EGLSurface EGLAPIENTRY
910 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
912 const EGLint
*attrib_list
)
914 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
916 native_window
= fixupNativeWindow(disp
, native_window
);
918 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
919 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
924 EGLSurface EGLAPIENTRY
925 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
927 const EGLAttrib
*attrib_list
)
929 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
933 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
935 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
936 if (attrib_list
&& !int_attribs
)
937 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
939 native_window
= fixupNativeWindow(disp
, native_window
);
940 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
947 fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
949 #ifdef HAVE_X11_PLATFORM
950 /* The `native_pixmap` parameter for the X11 platform differs between
951 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
952 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
953 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
954 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
955 * dri2_x11_create_pixmap_surface() expects.
957 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
958 return (void *)(* (Pixmap
*) native_pixmap
);
960 return native_pixmap
;
964 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
965 void *native_pixmap
, const EGLint
*attrib_list
)
967 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
972 #if HAVE_SURFACELESS_PLATFORM
973 if (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
974 /* From the EGL_MESA_platform_surfaceless spec (v1):
976 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
977 * also fails when called with a <display> that belongs to the
978 * surfaceless platform. It returns EGL_NO_SURFACE and generates
979 * EGL_BAD_NATIVE_PIXMAP.
981 * This check must occur before checking the EGLConfig, which emits
984 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
988 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
989 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
991 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
993 RETURN_EGL_EVAL(disp
, ret
);
997 EGLSurface EGLAPIENTRY
998 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
999 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1001 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1003 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1004 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1005 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1009 static EGLSurface EGLAPIENTRY
1010 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1011 void *native_pixmap
,
1012 const EGLint
*attrib_list
)
1014 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1016 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1017 native_pixmap
= fixupNativePixmap(disp
, native_pixmap
);
1018 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1023 EGLSurface EGLAPIENTRY
1024 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1025 void *native_pixmap
,
1026 const EGLAttrib
*attrib_list
)
1028 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1030 EGLint
*int_attribs
;
1032 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1034 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1035 if (attrib_list
&& !int_attribs
)
1036 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1038 native_pixmap
= fixupNativePixmap(disp
, native_pixmap
);
1039 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1046 EGLSurface EGLAPIENTRY
1047 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1048 const EGLint
*attrib_list
)
1050 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1051 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1056 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1057 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1059 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1060 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1062 RETURN_EGL_EVAL(disp
, ret
);
1066 EGLBoolean EGLAPIENTRY
1067 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1069 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1070 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1074 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1075 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1076 _eglUnlinkSurface(surf
);
1077 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1079 RETURN_EGL_EVAL(disp
, ret
);
1082 EGLBoolean EGLAPIENTRY
1083 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1084 EGLint attribute
, EGLint
*value
)
1086 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1087 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1091 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1092 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1093 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1095 RETURN_EGL_EVAL(disp
, ret
);
1098 EGLBoolean EGLAPIENTRY
1099 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1100 EGLint attribute
, EGLint value
)
1102 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1103 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1107 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1108 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1109 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1111 RETURN_EGL_EVAL(disp
, ret
);
1115 EGLBoolean EGLAPIENTRY
1116 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1118 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1119 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1123 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1124 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1125 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1127 RETURN_EGL_EVAL(disp
, ret
);
1131 EGLBoolean EGLAPIENTRY
1132 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1134 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1135 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1139 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1140 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1141 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1143 RETURN_EGL_EVAL(disp
, ret
);
1147 EGLBoolean EGLAPIENTRY
1148 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1150 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1151 _EGLContext
*ctx
= _eglGetCurrentContext();
1152 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1156 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1157 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1159 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1160 ctx
->Resource
.Display
!= disp
)
1161 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1163 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1164 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1166 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1168 RETURN_EGL_EVAL(disp
, ret
);
1172 EGLBoolean EGLAPIENTRY
1173 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1175 _EGLContext
*ctx
= _eglGetCurrentContext();
1176 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1177 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1181 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1182 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1184 /* surface must be bound to current context in EGL 1.4 */
1185 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1186 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1187 surf
!= ctx
->DrawSurface
)
1188 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1191 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1193 RETURN_EGL_EVAL(disp
, ret
);
1198 eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1199 EGLint
*rects
, EGLint n_rects
)
1201 _EGLContext
*ctx
= _eglGetCurrentContext();
1205 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1207 /* surface must be bound to current context in EGL 1.4 */
1208 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1209 surf
!= ctx
->DrawSurface
)
1210 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1212 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1213 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1215 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1217 RETURN_EGL_EVAL(disp
, ret
);
1220 static EGLBoolean EGLAPIENTRY
1221 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1222 EGLint
*rects
, EGLint n_rects
)
1224 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1225 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1226 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1227 return eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1230 static EGLBoolean EGLAPIENTRY
1231 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1232 EGLint
*rects
, EGLint n_rects
)
1234 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1235 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1236 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1237 return eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1240 EGLBoolean EGLAPIENTRY
1241 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1243 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1244 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1247 void *native_pixmap_ptr
;
1249 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1250 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1251 native_pixmap_ptr
= (void*) target
;
1253 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1254 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
1255 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
1256 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1258 RETURN_EGL_EVAL(disp
, ret
);
1263 _eglWaitClientCommon(void)
1265 _EGLContext
*ctx
= _eglGetCurrentContext();
1271 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1273 disp
= ctx
->Resource
.Display
;
1274 mtx_lock(&disp
->Mutex
);
1276 /* let bad current context imply bad current surface */
1277 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1278 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1279 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1281 /* a valid current context implies an initialized current display */
1282 assert(disp
->Initialized
);
1284 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1286 RETURN_EGL_EVAL(disp
, ret
);
1289 EGLBoolean EGLAPIENTRY
1292 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1293 return _eglWaitClientCommon();
1296 EGLBoolean EGLAPIENTRY
1299 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1300 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1301 return _eglWaitClientCommon();
1305 EGLBoolean EGLAPIENTRY
1306 eglWaitNative(EGLint engine
)
1308 _EGLContext
*ctx
= _eglGetCurrentContext();
1314 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1316 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1318 disp
= ctx
->Resource
.Display
;
1319 mtx_lock(&disp
->Mutex
);
1321 /* let bad current context imply bad current surface */
1322 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1323 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1324 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1326 /* a valid current context implies an initialized current display */
1327 assert(disp
->Initialized
);
1329 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1331 RETURN_EGL_EVAL(disp
, ret
);
1335 EGLDisplay EGLAPIENTRY
1336 eglGetCurrentDisplay(void)
1338 _EGLContext
*ctx
= _eglGetCurrentContext();
1341 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1343 RETURN_EGL_SUCCESS(NULL
, ret
);
1347 EGLContext EGLAPIENTRY
1348 eglGetCurrentContext(void)
1350 _EGLContext
*ctx
= _eglGetCurrentContext();
1353 ret
= _eglGetContextHandle(ctx
);
1355 RETURN_EGL_SUCCESS(NULL
, ret
);
1359 EGLSurface EGLAPIENTRY
1360 eglGetCurrentSurface(EGLint readdraw
)
1362 _EGLContext
*ctx
= _eglGetCurrentContext();
1363 EGLint err
= EGL_SUCCESS
;
1367 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1370 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1374 surf
= ctx
->DrawSurface
;
1377 surf
= ctx
->ReadSurface
;
1381 err
= EGL_BAD_PARAMETER
;
1385 ret
= _eglGetSurfaceHandle(surf
);
1387 RETURN_EGL_ERROR(NULL
, err
, ret
);
1394 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1395 EGLint e
= t
->LastError
;
1396 if (!_eglIsCurrentThreadDummy())
1397 t
->LastError
= EGL_SUCCESS
;
1407 * Specify the client API to use for subsequent calls including:
1408 * eglCreateContext()
1409 * eglGetCurrentContext()
1410 * eglGetCurrentDisplay()
1411 * eglGetCurrentSurface()
1412 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1415 * See section 3.7 "Rendering Context" in the EGL specification for details.
1417 EGLBoolean EGLAPIENTRY
1418 eglBindAPI(EGLenum api
)
1422 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1424 t
= _eglGetCurrentThread();
1425 if (_eglIsCurrentThreadDummy())
1426 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1428 if (!_eglIsApiValid(api
))
1429 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1431 t
->CurrentAPI
= api
;
1433 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1438 * Return the last value set with eglBindAPI().
1443 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1446 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1447 ret
= t
->CurrentAPI
;
1449 RETURN_EGL_SUCCESS(NULL
, ret
);
1453 EGLSurface EGLAPIENTRY
1454 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1455 EGLClientBuffer buffer
, EGLConfig config
,
1456 const EGLint
*attrib_list
)
1458 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1459 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1464 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1466 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1468 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1470 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1472 RETURN_EGL_EVAL(disp
, ret
);
1476 EGLBoolean EGLAPIENTRY
1477 eglReleaseThread(void)
1479 /* unbind current contexts */
1480 if (!_eglIsCurrentThreadDummy()) {
1481 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1482 _EGLContext
*ctx
= t
->CurrentContext
;
1484 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1487 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1490 mtx_lock(&disp
->Mutex
);
1492 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1493 mtx_unlock(&disp
->Mutex
);
1497 _eglDestroyCurrentThread();
1499 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1504 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1505 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1507 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1512 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1513 if (!disp
->Extensions
.KHR_image_base
)
1514 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1515 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1516 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1517 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1518 * <ctx> must be EGL_NO_CONTEXT..."
1520 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1521 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1523 img
= drv
->API
.CreateImageKHR(drv
,
1524 disp
, context
, target
, buffer
, attr_list
);
1525 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1527 RETURN_EGL_EVAL(disp
, ret
);
1530 static EGLImage EGLAPIENTRY
1531 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1532 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1534 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1535 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1536 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1540 EGLImage EGLAPIENTRY
1541 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1542 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1544 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1546 EGLint
*int_attribs
;
1548 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1550 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1551 if (attr_list
&& !int_attribs
)
1552 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1554 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1560 EGLBoolean EGLAPIENTRY
1561 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1563 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1564 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1568 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1570 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1571 if (!disp
->Extensions
.KHR_image_base
)
1572 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1574 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1576 _eglUnlinkImage(img
);
1577 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1579 RETURN_EGL_EVAL(disp
, ret
);
1584 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1585 EGLBoolean orig_is_EGLAttrib
,
1586 EGLenum invalid_type_error
)
1588 _EGLContext
*ctx
= _eglGetCurrentContext();
1593 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1595 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1596 /* There exist two EGLAttrib variants of eglCreateSync*:
1597 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1598 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1599 * support as a proxy for EGL 1.5 support, even though that's not
1600 * entirely correct (though _eglComputeVersion does the same).
1602 * The EGL spec provides no guidance on how to handle unsupported
1603 * functions. EGL_BAD_MATCH seems reasonable.
1605 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1608 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1609 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1610 * error is generated.
1612 if (!ctx
&& type
== EGL_SYNC_FENCE_KHR
)
1613 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1615 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1616 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1617 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1618 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1621 case EGL_SYNC_FENCE_KHR
:
1622 if (!disp
->Extensions
.KHR_fence_sync
)
1623 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1625 case EGL_SYNC_REUSABLE_KHR
:
1626 if (!disp
->Extensions
.KHR_reusable_sync
)
1627 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1629 case EGL_SYNC_CL_EVENT_KHR
:
1630 if (!disp
->Extensions
.KHR_cl_event2
)
1631 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1634 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1637 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1638 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1640 RETURN_EGL_EVAL(disp
, ret
);
1644 static EGLSync EGLAPIENTRY
1645 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1647 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1648 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1651 EGLAttrib
*attrib_list
;
1654 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1655 attrib_list
= (EGLAttrib
*) int_list
;
1657 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1658 if (err
!= EGL_SUCCESS
)
1659 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1662 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1665 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1668 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1673 static EGLSync EGLAPIENTRY
1674 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1676 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1677 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1678 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1684 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1686 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1687 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1688 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1693 EGLBoolean EGLAPIENTRY
1694 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1696 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1697 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1701 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1703 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1704 assert(disp
->Extensions
.KHR_reusable_sync
||
1705 disp
->Extensions
.KHR_fence_sync
);
1708 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1710 RETURN_EGL_EVAL(disp
, ret
);
1715 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
, EGLTime timeout
)
1717 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1718 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1722 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1724 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1725 assert(disp
->Extensions
.KHR_reusable_sync
||
1726 disp
->Extensions
.KHR_fence_sync
);
1728 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1729 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1731 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1732 * unlocked here to allow other threads also to be able to
1733 * go into waiting state.
1736 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1737 _eglUnlockDisplay(dpy
);
1739 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1742 * 'disp' is already unlocked for reusable sync type,
1743 * so passing 'NULL' to bypass unlocking display.
1745 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1746 RETURN_EGL_EVAL(NULL
, ret
);
1748 RETURN_EGL_EVAL(disp
, ret
);
1753 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
1755 _EGLContext
*ctx
= _eglGetCurrentContext();
1759 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1760 assert(disp
->Extensions
.KHR_wait_sync
);
1762 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1763 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1764 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1766 /* the API doesn't allow any flags yet */
1768 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1770 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1772 RETURN_EGL_EVAL(disp
, ret
);
1775 static EGLint EGLAPIENTRY
1776 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1778 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1779 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1780 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1781 return _eglWaitSyncCommon(disp
, s
, flags
);
1785 EGLBoolean EGLAPIENTRY
1786 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1788 /* The KHR version returns EGLint, while the core version returns
1789 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1792 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1793 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1794 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1795 return _eglWaitSyncCommon(disp
, s
, flags
);
1799 static EGLBoolean EGLAPIENTRY
1800 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
1802 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1803 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1807 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1809 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1810 assert(disp
->Extensions
.KHR_reusable_sync
);
1811 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
1813 RETURN_EGL_EVAL(disp
, ret
);
1818 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
1823 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1824 assert(disp
->Extensions
.KHR_reusable_sync
||
1825 disp
->Extensions
.KHR_fence_sync
);
1826 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
1828 RETURN_EGL_EVAL(disp
, ret
);
1831 EGLBoolean EGLAPIENTRY
1832 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
1834 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1835 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1836 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1837 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
1841 static EGLBoolean EGLAPIENTRY
1842 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
1844 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1845 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1849 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1852 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1855 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
1857 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
1859 * If any error occurs, <*value> is not modified.
1861 if (result
== EGL_FALSE
)
1869 static EGLBoolean EGLAPIENTRY
1870 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
1871 EGLint numRects
, const EGLint
*rects
)
1873 _EGLContext
*ctx
= _eglGetCurrentContext();
1874 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1875 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1879 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1881 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1883 if (!disp
->Extensions
.NOK_swap_region
)
1884 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1886 /* surface must be bound to current context in EGL 1.4 */
1887 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1888 surf
!= ctx
->DrawSurface
)
1889 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1891 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
1893 RETURN_EGL_EVAL(disp
, ret
);
1897 static EGLImage EGLAPIENTRY
1898 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
1900 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1905 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1907 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1908 if (!disp
->Extensions
.MESA_drm_image
)
1909 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1911 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
1912 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1914 RETURN_EGL_EVAL(disp
, ret
);
1917 static EGLBoolean EGLAPIENTRY
1918 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
1919 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
1921 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1922 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1926 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1928 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1929 assert(disp
->Extensions
.MESA_drm_image
);
1932 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1934 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
1936 RETURN_EGL_EVAL(disp
, ret
);
1942 static EGLBoolean EGLAPIENTRY
1943 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1945 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1949 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1951 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1952 assert(disp
->Extensions
.WL_bind_wayland_display
);
1955 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1957 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
1959 RETURN_EGL_EVAL(disp
, ret
);
1962 static EGLBoolean EGLAPIENTRY
1963 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1965 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1969 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1971 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1972 assert(disp
->Extensions
.WL_bind_wayland_display
);
1975 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1977 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
1979 RETURN_EGL_EVAL(disp
, ret
);
1982 static EGLBoolean EGLAPIENTRY
1983 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
1984 EGLint attribute
, EGLint
*value
)
1986 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1990 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1992 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1993 assert(disp
->Extensions
.WL_bind_wayland_display
);
1996 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1998 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2000 RETURN_EGL_EVAL(disp
, ret
);
2004 static struct wl_buffer
* EGLAPIENTRY
2005 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2007 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2010 struct wl_buffer
*ret
;
2012 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2014 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2015 assert(disp
->Extensions
.WL_create_wayland_buffer_from_image
);
2017 img
= _eglLookupImage(image
, disp
);
2020 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2022 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2024 RETURN_EGL_EVAL(disp
, ret
);
2027 static EGLBoolean EGLAPIENTRY
2028 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2029 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2031 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2032 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2036 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2038 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2040 if (!disp
->Extensions
.NV_post_sub_buffer
)
2041 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2043 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2045 RETURN_EGL_EVAL(disp
, ret
);
2048 static EGLBoolean EGLAPIENTRY
2049 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
2050 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2053 _EGLDisplay
*disp
= _eglLockDisplay(display
);
2054 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2058 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2060 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2061 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2062 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2064 if (!ust
|| !msc
|| !sbc
)
2065 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2067 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2069 RETURN_EGL_EVAL(disp
, ret
);
2072 static EGLBoolean EGLAPIENTRY
2073 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2074 EGLint
*fourcc
, EGLint
*nplanes
,
2075 EGLuint64KHR
*modifiers
)
2077 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2078 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2082 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2084 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2085 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2088 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2090 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2093 RETURN_EGL_EVAL(disp
, ret
);
2096 static EGLBoolean EGLAPIENTRY
2097 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2098 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2100 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2101 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2105 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2107 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2108 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2111 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2113 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2115 RETURN_EGL_EVAL(disp
, ret
);
2118 static EGLint EGLAPIENTRY
2119 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2122 _EGLDisplay
*disp
= NULL
;
2123 _EGLResourceType type
;
2125 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2127 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2128 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2130 if (!_eglIsCurrentThreadDummy()) {
2135 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2138 disp
= _eglLockDisplay(dpy
);
2140 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2142 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2143 if (dpy
!= (EGLDisplay
) object
)
2144 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2146 disp
->Label
= label
;
2147 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2150 switch (objectType
) {
2151 case EGL_OBJECT_CONTEXT_KHR
:
2152 type
= _EGL_RESOURCE_CONTEXT
;
2154 case EGL_OBJECT_SURFACE_KHR
:
2155 type
= _EGL_RESOURCE_SURFACE
;
2157 case EGL_OBJECT_IMAGE_KHR
:
2158 type
= _EGL_RESOURCE_IMAGE
;
2160 case EGL_OBJECT_SYNC_KHR
:
2161 type
= _EGL_RESOURCE_SYNC
;
2163 case EGL_OBJECT_STREAM_KHR
:
2165 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2168 if (_eglCheckResource(object
, type
, disp
)) {
2169 _EGLResource
*res
= (_EGLResource
*) object
;
2172 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2175 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2179 validDebugMessageLevel(EGLAttrib level
)
2181 return (level
>= EGL_DEBUG_MSG_CRITICAL_KHR
&&
2182 level
<= EGL_DEBUG_MSG_INFO_KHR
);
2185 static EGLint EGLAPIENTRY
2186 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2187 const EGLAttrib
*attrib_list
)
2189 unsigned int newEnabled
;
2191 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2193 mtx_lock(_eglGlobal
.Mutex
);
2195 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2196 if (attrib_list
!= NULL
) {
2199 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2200 if (validDebugMessageLevel(attrib_list
[i
])) {
2201 if (attrib_list
[i
+ 1])
2202 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2204 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2208 // On error, set the last error code, call the current
2209 // debug callback, and return the error code.
2210 mtx_unlock(_eglGlobal
.Mutex
);
2211 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2212 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2213 return EGL_BAD_ATTRIBUTE
;
2217 if (callback
!= NULL
) {
2218 _eglGlobal
.debugCallback
= callback
;
2219 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2221 _eglGlobal
.debugCallback
= NULL
;
2222 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2225 mtx_unlock(_eglGlobal
.Mutex
);
2229 static EGLBoolean EGLAPIENTRY
2230 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2232 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2234 mtx_lock(_eglGlobal
.Mutex
);
2237 if (validDebugMessageLevel(attribute
)) {
2238 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2245 if (attribute
== EGL_DEBUG_CALLBACK_KHR
) {
2246 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2250 mtx_unlock(_eglGlobal
.Mutex
);
2251 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2252 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2256 mtx_unlock(_eglGlobal
.Mutex
);
2260 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2261 eglGetProcAddress(const char *procname
)
2263 static const struct {
2266 } egl_functions
[] = {
2267 /* core functions queryable in the presence of
2268 * EGL_KHR_get_all_proc_addresses or EGL 1.5
2270 /* alphabetical order */
2271 { "eglBindAPI", (_EGLProc
) eglBindAPI
},
2272 { "eglBindTexImage", (_EGLProc
) eglBindTexImage
},
2273 { "eglChooseConfig", (_EGLProc
) eglChooseConfig
},
2274 { "eglCopyBuffers", (_EGLProc
) eglCopyBuffers
},
2275 { "eglCreateContext", (_EGLProc
) eglCreateContext
},
2276 { "eglCreatePbufferFromClientBuffer", (_EGLProc
) eglCreatePbufferFromClientBuffer
},
2277 { "eglCreatePbufferSurface", (_EGLProc
) eglCreatePbufferSurface
},
2278 { "eglCreatePixmapSurface", (_EGLProc
) eglCreatePixmapSurface
},
2279 { "eglCreateWindowSurface", (_EGLProc
) eglCreateWindowSurface
},
2280 { "eglDestroyContext", (_EGLProc
) eglDestroyContext
},
2281 { "eglDestroySurface", (_EGLProc
) eglDestroySurface
},
2282 { "eglGetConfigAttrib", (_EGLProc
) eglGetConfigAttrib
},
2283 { "eglGetConfigs", (_EGLProc
) eglGetConfigs
},
2284 { "eglGetCurrentContext", (_EGLProc
) eglGetCurrentContext
},
2285 { "eglGetCurrentDisplay", (_EGLProc
) eglGetCurrentDisplay
},
2286 { "eglGetCurrentSurface", (_EGLProc
) eglGetCurrentSurface
},
2287 { "eglGetDisplay", (_EGLProc
) eglGetDisplay
},
2288 { "eglGetError", (_EGLProc
) eglGetError
},
2289 { "eglGetProcAddress", (_EGLProc
) eglGetProcAddress
},
2290 { "eglInitialize", (_EGLProc
) eglInitialize
},
2291 { "eglMakeCurrent", (_EGLProc
) eglMakeCurrent
},
2292 { "eglQueryAPI", (_EGLProc
) eglQueryAPI
},
2293 { "eglQueryContext", (_EGLProc
) eglQueryContext
},
2294 { "eglQueryString", (_EGLProc
) eglQueryString
},
2295 { "eglQuerySurface", (_EGLProc
) eglQuerySurface
},
2296 { "eglReleaseTexImage", (_EGLProc
) eglReleaseTexImage
},
2297 { "eglReleaseThread", (_EGLProc
) eglReleaseThread
},
2298 { "eglSurfaceAttrib", (_EGLProc
) eglSurfaceAttrib
},
2299 { "eglSwapBuffers", (_EGLProc
) eglSwapBuffers
},
2300 { "eglSwapInterval", (_EGLProc
) eglSwapInterval
},
2301 { "eglTerminate", (_EGLProc
) eglTerminate
},
2302 { "eglWaitClient", (_EGLProc
) eglWaitClient
},
2303 { "eglWaitGL", (_EGLProc
) eglWaitGL
},
2304 { "eglWaitNative", (_EGLProc
) eglWaitNative
},
2305 { "eglCreateSync", (_EGLProc
) eglCreateSync
},
2306 { "eglDestroySync", (_EGLProc
) eglDestroySync
},
2307 { "eglClientWaitSync", (_EGLProc
) eglClientWaitSync
},
2308 { "eglGetSyncAttrib", (_EGLProc
) eglGetSyncAttrib
},
2309 { "eglWaitSync", (_EGLProc
) eglWaitSync
},
2310 { "eglCreateImage", (_EGLProc
) eglCreateImage
},
2311 { "eglDestroyImage", (_EGLProc
) eglDestroyImage
},
2312 { "eglGetPlatformDisplay", (_EGLProc
) eglGetPlatformDisplay
},
2313 { "eglCreatePlatformWindowSurface", (_EGLProc
) eglCreatePlatformWindowSurface
},
2314 { "eglCreatePlatformPixmapSurface", (_EGLProc
) eglCreatePlatformPixmapSurface
},
2315 { "eglCreateImageKHR", (_EGLProc
) eglCreateImageKHR
},
2316 { "eglDestroyImageKHR", (_EGLProc
) eglDestroyImage
},
2317 { "eglCreateSyncKHR", (_EGLProc
) eglCreateSyncKHR
},
2318 { "eglCreateSync64KHR", (_EGLProc
) eglCreateSync64KHR
},
2319 { "eglDestroySyncKHR", (_EGLProc
) eglDestroySync
},
2320 { "eglClientWaitSyncKHR", (_EGLProc
) eglClientWaitSync
},
2321 { "eglWaitSyncKHR", (_EGLProc
) eglWaitSyncKHR
},
2322 { "eglSignalSyncKHR", (_EGLProc
) eglSignalSyncKHR
},
2323 { "eglGetSyncAttribKHR", (_EGLProc
) eglGetSyncAttribKHR
},
2324 { "eglSwapBuffersRegionNOK", (_EGLProc
) eglSwapBuffersRegionNOK
},
2325 { "eglCreateDRMImageMESA", (_EGLProc
) eglCreateDRMImageMESA
},
2326 { "eglExportDRMImageMESA", (_EGLProc
) eglExportDRMImageMESA
},
2327 { "eglBindWaylandDisplayWL", (_EGLProc
) eglBindWaylandDisplayWL
},
2328 { "eglUnbindWaylandDisplayWL", (_EGLProc
) eglUnbindWaylandDisplayWL
},
2329 { "eglQueryWaylandBufferWL", (_EGLProc
) eglQueryWaylandBufferWL
},
2330 { "eglCreateWaylandBufferFromImageWL", (_EGLProc
) eglCreateWaylandBufferFromImageWL
},
2331 { "eglPostSubBufferNV", (_EGLProc
) eglPostSubBufferNV
},
2332 { "eglSwapBuffersWithDamageEXT", (_EGLProc
) eglSwapBuffersWithDamageEXT
},
2333 { "eglSwapBuffersWithDamageKHR", (_EGLProc
) eglSwapBuffersWithDamageKHR
},
2334 { "eglGetPlatformDisplayEXT", (_EGLProc
) eglGetPlatformDisplayEXT
},
2335 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc
) eglCreatePlatformWindowSurfaceEXT
},
2336 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc
) eglCreatePlatformPixmapSurfaceEXT
},
2337 { "eglGetSyncValuesCHROMIUM", (_EGLProc
) eglGetSyncValuesCHROMIUM
},
2338 { "eglExportDMABUFImageQueryMESA", (_EGLProc
) eglExportDMABUFImageQueryMESA
},
2339 { "eglExportDMABUFImageMESA", (_EGLProc
) eglExportDMABUFImageMESA
},
2340 { "eglLabelObjectKHR", (_EGLProc
) eglLabelObjectKHR
},
2341 { "eglDebugMessageControlKHR", (_EGLProc
) eglDebugMessageControlKHR
},
2342 { "eglQueryDebugKHR", (_EGLProc
) eglQueryDebugKHR
},
2349 RETURN_EGL_SUCCESS(NULL
, NULL
);
2351 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2354 if (strncmp(procname
, "egl", 3) == 0) {
2355 for (i
= 0; egl_functions
[i
].name
; i
++) {
2356 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
2357 ret
= egl_functions
[i
].function
;
2363 ret
= _eglGetDriverProc(procname
);
2365 RETURN_EGL_SUCCESS(NULL
, ret
);
2369 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2370 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2374 *disp
= _eglLockDisplay(dpy
);
2375 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2377 _eglUnlockDisplay(*disp
);
2378 return MESA_GLINTEROP_INVALID_DISPLAY
;
2381 *drv
= (*disp
)->Driver
;
2383 *ctx
= _eglLookupContext(context
, *disp
);
2385 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2386 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2387 _eglUnlockDisplay(*disp
);
2388 return MESA_GLINTEROP_INVALID_CONTEXT
;
2391 return MESA_GLINTEROP_SUCCESS
;
2395 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2396 struct mesa_glinterop_device_info
*out
)
2403 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2404 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2407 if (drv
->API
.GLInteropQueryDeviceInfo
)
2408 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2410 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2412 _eglUnlockDisplay(disp
);
2417 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2418 struct mesa_glinterop_export_in
*in
,
2419 struct mesa_glinterop_export_out
*out
)
2426 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2427 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2430 if (drv
->API
.GLInteropExportObject
)
2431 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2433 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2435 _eglUnlockDisplay(disp
);