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
95 #include "c99_compat.h"
96 #include "c11/threads.h"
97 #include "util/macros.h"
99 #include "egldefines.h"
100 #include "eglglobals.h"
101 #include "eglcontext.h"
102 #include "egldisplay.h"
103 #include "egltypedefs.h"
104 #include "eglcurrent.h"
105 #include "egldevice.h"
106 #include "egldriver.h"
107 #include "eglsurface.h"
108 #include "eglconfig.h"
109 #include "eglimage.h"
112 #include "GL/mesa_glinterop.h"
115 * Macros to help return an API entrypoint.
117 * These macros will unlock the display and record the error code.
119 #define RETURN_EGL_ERROR(disp, err, ret) \
122 _eglUnlockDisplay(disp); \
123 /* EGL error codes are non-zero */ \
125 _eglError(err, __func__); \
129 #define RETURN_EGL_SUCCESS(disp, ret) \
130 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
132 /* record EGL_SUCCESS only when ret evaluates to true */
133 #define RETURN_EGL_EVAL(disp, ret) \
134 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
138 * A bunch of macros and checks to simplify error checking.
141 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
143 drv = _eglCheckDisplay(disp, __func__); \
145 RETURN_EGL_ERROR(disp, 0, ret); \
148 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
150 drv = _eglCheck ## type(disp, obj, __func__); \
152 RETURN_EGL_ERROR(disp, 0, ret); \
155 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
156 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
158 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
159 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
161 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
162 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
164 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
165 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
168 struct _egl_entrypoint
{
174 static inline const _EGLDriver
*
175 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
178 _eglError(EGL_BAD_DISPLAY
, msg
);
181 if (!disp
->Initialized
) {
182 _eglError(EGL_NOT_INITIALIZED
, msg
);
189 static inline const _EGLDriver
*
190 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
192 const _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
196 _eglError(EGL_BAD_SURFACE
, msg
);
203 static inline const _EGLDriver
*
204 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
206 const _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
210 _eglError(EGL_BAD_CONTEXT
, msg
);
217 static inline const _EGLDriver
*
218 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
220 const _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
224 _eglError(EGL_BAD_CONFIG
, msg
);
231 static inline const _EGLDriver
*
232 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
234 const _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
238 _eglError(EGL_BAD_PARAMETER
, msg
);
246 * Lookup and lock a display.
248 static inline _EGLDisplay
*
249 _eglLockDisplay(EGLDisplay dpy
)
251 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
253 mtx_lock(&disp
->Mutex
);
262 _eglUnlockDisplay(_EGLDisplay
*disp
)
264 mtx_unlock(&disp
->Mutex
);
268 _eglSetFuncName(const char *funcName
, _EGLDisplay
*disp
, EGLenum objectType
, _EGLResource
*object
)
270 _EGLThreadInfo
*thr
= _eglGetCurrentThread();
271 if (!_eglIsCurrentThreadDummy()) {
272 thr
->CurrentFuncName
= funcName
;
273 thr
->CurrentObjectLabel
= NULL
;
275 if (objectType
== EGL_OBJECT_THREAD_KHR
)
276 thr
->CurrentObjectLabel
= thr
->Label
;
277 else if (objectType
== EGL_OBJECT_DISPLAY_KHR
&& disp
)
278 thr
->CurrentObjectLabel
= disp
->Label
;
280 thr
->CurrentObjectLabel
= object
->Label
;
285 _eglDebugReport(EGL_BAD_ALLOC
, funcName
, EGL_DEBUG_MSG_CRITICAL_KHR
, NULL
);
289 #define _EGL_FUNC_START(disp, objectType, object, ret) \
291 if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \
293 _eglUnlockDisplay(disp); \
299 * Convert an attribute list from EGLint[] to EGLAttrib[].
301 * Return an EGL error code. The output parameter out_attrib_list is modified
305 _eglConvertIntsToAttribs(const EGLint
*int_list
, EGLAttrib
**out_attrib_list
)
308 EGLAttrib
*attrib_list
;
311 while (int_list
[2*len
] != EGL_NONE
)
316 *out_attrib_list
= NULL
;
320 if (2*len
+ 1 > SIZE_MAX
/ sizeof(EGLAttrib
))
321 return EGL_BAD_ALLOC
;
323 attrib_list
= malloc((2*len
+ 1) * sizeof(EGLAttrib
));
325 return EGL_BAD_ALLOC
;
327 for (size_t i
= 0; i
< len
; ++i
) {
328 attrib_list
[2*i
+ 0] = int_list
[2*i
+ 0];
329 attrib_list
[2*i
+ 1] = int_list
[2*i
+ 1];
332 attrib_list
[2*len
] = EGL_NONE
;
334 *out_attrib_list
= attrib_list
;
340 _eglConvertAttribsToInt(const EGLAttrib
*attr_list
)
342 size_t size
= _eglNumAttribs(attr_list
);
343 EGLint
*int_attribs
= NULL
;
345 /* Convert attributes from EGLAttrib[] to EGLint[] */
347 int_attribs
= calloc(size
, sizeof(int_attribs
[0]));
351 for (size_t i
= 0; i
< size
; i
++)
352 int_attribs
[i
] = attr_list
[i
];
359 * This is typically the first EGL function that an application calls.
360 * It associates a private _EGLDisplay object to the native display.
362 EGLDisplay EGLAPIENTRY
363 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
365 _EGLPlatformType plat
;
367 void *native_display_ptr
;
369 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
371 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
372 native_display_ptr
= (void*) nativeDisplay
;
374 plat
= _eglGetNativePlatform(native_display_ptr
);
375 disp
= _eglFindDisplay(plat
, native_display_ptr
, NULL
);
376 return _eglGetDisplayHandle(disp
);
380 _eglGetPlatformDisplayCommon(EGLenum platform
, void *native_display
,
381 const EGLAttrib
*attrib_list
)
386 #ifdef HAVE_X11_PLATFORM
387 case EGL_PLATFORM_X11_EXT
:
388 disp
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
391 #ifdef HAVE_DRM_PLATFORM
392 case EGL_PLATFORM_GBM_MESA
:
393 disp
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
397 #ifdef HAVE_WAYLAND_PLATFORM
398 case EGL_PLATFORM_WAYLAND_EXT
:
399 disp
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
403 case EGL_PLATFORM_SURFACELESS_MESA
:
404 disp
= _eglGetSurfacelessDisplay(native_display
, attrib_list
);
406 #ifdef HAVE_ANDROID_PLATFORM
407 case EGL_PLATFORM_ANDROID_KHR
:
408 disp
= _eglGetAndroidDisplay(native_display
, attrib_list
);
411 case EGL_PLATFORM_DEVICE_EXT
:
412 disp
= _eglGetDeviceDisplay(native_display
, attrib_list
);
415 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
418 return _eglGetDisplayHandle(disp
);
421 static EGLDisplay EGLAPIENTRY
422 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
423 const EGLint
*int_attribs
)
425 EGLAttrib
*attrib_list
;
428 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
430 if (_eglConvertIntsToAttribs(int_attribs
, &attrib_list
) != EGL_SUCCESS
)
431 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
433 disp
= _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
438 EGLDisplay EGLAPIENTRY
439 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
440 const EGLAttrib
*attrib_list
)
442 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
443 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
447 * Copy the extension into the string and update the string pointer.
450 _eglAppendExtension(char **str
, const char *ext
)
453 size_t len
= strlen(ext
);
470 * Examine the individual extension enable/disable flags and recompute
471 * the driver's Extensions string.
474 _eglCreateExtensionsString(_EGLDisplay
*disp
)
476 #define _EGL_CHECK_EXTENSION(ext) \
478 if (disp->Extensions.ext) { \
479 _eglAppendExtension(&exts, "EGL_" #ext); \
480 assert(exts <= disp->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
484 char *exts
= disp
->ExtensionsString
;
486 /* Please keep these sorted alphabetically. */
487 _EGL_CHECK_EXTENSION(ANDROID_blob_cache
);
488 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
489 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
490 _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync
);
491 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
493 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
495 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
496 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
497 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
498 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers
);
499 _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata
);
500 _EGL_CHECK_EXTENSION(EXT_surface_SMPTE2086_metadata
);
501 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
503 _EGL_CHECK_EXTENSION(IMG_context_priority
);
505 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
506 _EGL_CHECK_EXTENSION(KHR_config_attribs
);
507 _EGL_CHECK_EXTENSION(KHR_context_flush_control
);
508 _EGL_CHECK_EXTENSION(KHR_create_context
);
509 _EGL_CHECK_EXTENSION(KHR_create_context_no_error
);
510 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
511 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
512 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
513 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
514 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
515 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
516 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
517 if (disp
->Extensions
.KHR_image_base
&& disp
->Extensions
.KHR_image_pixmap
)
518 disp
->Extensions
.KHR_image
= EGL_TRUE
;
519 _EGL_CHECK_EXTENSION(KHR_image
);
520 _EGL_CHECK_EXTENSION(KHR_image_base
);
521 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
522 _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer
);
523 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
524 _EGL_CHECK_EXTENSION(KHR_partial_update
);
525 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
526 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
527 if (disp
->Extensions
.EXT_swap_buffers_with_damage
)
528 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
529 _EGL_CHECK_EXTENSION(EXT_pixel_format_float
);
530 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
532 if (disp
->Extensions
.KHR_no_config_context
)
533 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
534 _EGL_CHECK_EXTENSION(MESA_drm_image
);
535 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
536 _EGL_CHECK_EXTENSION(MESA_query_driver
);
538 _EGL_CHECK_EXTENSION(NOK_swap_region
);
539 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
541 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
543 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
544 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
546 #undef _EGL_CHECK_EXTENSION
550 _eglCreateAPIsString(_EGLDisplay
*disp
)
552 #define addstr(str) \
554 const size_t old_len = strlen(disp->ClientAPIsString); \
555 const size_t add_len = sizeof(str); \
556 const size_t max_len = sizeof(disp->ClientAPIsString) - 1; \
557 if (old_len + add_len <= max_len) \
558 strcat(disp->ClientAPIsString, str " "); \
560 assert(!"disp->ClientAPIsString is not large enough"); \
563 if (disp
->ClientAPIs
& EGL_OPENGL_BIT
)
566 if (disp
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
567 disp
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
568 disp
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
572 if (disp
->ClientAPIs
& EGL_OPENVG_BIT
)
579 _eglComputeVersion(_EGLDisplay
*disp
)
583 if (disp
->Extensions
.KHR_fence_sync
&&
584 disp
->Extensions
.KHR_cl_event2
&&
585 disp
->Extensions
.KHR_wait_sync
&&
586 disp
->Extensions
.KHR_image_base
&&
587 disp
->Extensions
.KHR_gl_texture_2D_image
&&
588 disp
->Extensions
.KHR_gl_texture_3D_image
&&
589 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
590 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
591 disp
->Extensions
.KHR_create_context
&&
592 disp
->Extensions
.EXT_create_context_robustness
&&
593 disp
->Extensions
.KHR_get_all_proc_addresses
&&
594 disp
->Extensions
.KHR_gl_colorspace
&&
595 disp
->Extensions
.KHR_surfaceless_context
)
598 /* For Android P and below limit the EGL version to 1.4 */
599 #if defined(ANDROID) && ANDROID_API_LEVEL <= 28
605 * This is typically the second EGL function that an application calls.
606 * Here we load/initialize the actual hardware driver.
608 EGLBoolean EGLAPIENTRY
609 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
611 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
613 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
616 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
618 if (!disp
->Initialized
) {
619 if (!_eglInitializeDisplay(disp
))
620 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
622 /* limit to APIs supported by core */
623 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
625 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
626 * classifies it as an EGL display extension, though conceptually it's an
627 * EGL client extension.
629 * From the EGL_KHR_get_all_proc_addresses spec:
631 * The EGL implementation must expose the name
632 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
633 * EGL_KHR_get_all_proc_addresses and supports
634 * EGL_EXT_client_extensions.
636 * Mesa unconditionally exposes both client extensions mentioned above,
637 * so the spec requires that each EGLDisplay unconditionally expose
638 * EGL_KHR_get_all_proc_addresses also.
640 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
642 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
643 * programs. It is driver agnostic and handled in the main EGL code.
645 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
647 _eglComputeVersion(disp
);
648 _eglCreateExtensionsString(disp
);
649 _eglCreateAPIsString(disp
);
650 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
651 "%d.%d", disp
->Version
/ 10, disp
->Version
% 10);
654 /* Update applications version of major and minor if not NULL */
655 if ((major
!= NULL
) && (minor
!= NULL
)) {
656 *major
= disp
->Version
/ 10;
657 *minor
= disp
->Version
% 10;
660 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
664 EGLBoolean EGLAPIENTRY
665 eglTerminate(EGLDisplay dpy
)
667 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
669 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
672 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
674 if (disp
->Initialized
) {
675 disp
->Driver
->Terminate(disp
);
676 /* do not reset disp->Driver */
677 disp
->ClientAPIsString
[0] = 0;
678 disp
->Initialized
= EGL_FALSE
;
680 /* Reset blob cache funcs on terminate. */
681 disp
->BlobCacheSet
= NULL
;
682 disp
->BlobCacheGet
= NULL
;
685 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
689 const char * EGLAPIENTRY
690 eglQueryString(EGLDisplay dpy
, EGLint name
)
693 const _EGLDriver
*drv
;
696 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
697 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
701 disp
= _eglLockDisplay(dpy
);
702 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
703 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
707 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
709 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
711 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
712 case EGL_CLIENT_APIS
:
713 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
715 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
720 EGLBoolean EGLAPIENTRY
721 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
722 EGLint config_size
, EGLint
*num_config
)
724 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
725 const _EGLDriver
*drv
;
728 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
730 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
733 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
735 ret
= _eglGetConfigs(drv
, disp
, configs
, config_size
, num_config
);
737 RETURN_EGL_EVAL(disp
, ret
);
741 EGLBoolean EGLAPIENTRY
742 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
743 EGLint config_size
, EGLint
*num_config
)
745 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
746 const _EGLDriver
*drv
;
749 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
751 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
754 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
756 ret
= _eglChooseConfig(drv
, disp
, attrib_list
, configs
,
757 config_size
, num_config
);
759 RETURN_EGL_EVAL(disp
, ret
);
763 EGLBoolean EGLAPIENTRY
764 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
765 EGLint attribute
, EGLint
*value
)
767 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
768 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
769 const _EGLDriver
*drv
;
772 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
774 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
776 ret
= _eglGetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
778 RETURN_EGL_EVAL(disp
, ret
);
782 EGLContext EGLAPIENTRY
783 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
784 const EGLint
*attrib_list
)
786 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
787 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
788 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
789 const _EGLDriver
*drv
;
790 _EGLContext
*context
;
793 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
795 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
797 if (config
!= EGL_NO_CONFIG_KHR
)
798 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
799 else if (!disp
->Extensions
.KHR_no_config_context
)
800 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
802 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
803 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
805 context
= drv
->CreateContext(disp
, conf
, share
, attrib_list
);
806 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
808 RETURN_EGL_EVAL(disp
, ret
);
812 EGLBoolean EGLAPIENTRY
813 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
815 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
816 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
817 const _EGLDriver
*drv
;
820 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
822 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
823 _eglUnlinkContext(context
);
824 ret
= drv
->DestroyContext(disp
, context
);
826 RETURN_EGL_EVAL(disp
, ret
);
830 EGLBoolean EGLAPIENTRY
831 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
834 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
835 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
836 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
837 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
838 const _EGLDriver
*drv
;
841 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
844 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
847 /* display is allowed to be uninitialized under certain condition */
848 if (!disp
->Initialized
) {
849 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
850 ctx
!= EGL_NO_CONTEXT
)
851 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
854 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
856 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
857 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
858 if (!draw_surf
|| !read_surf
) {
859 /* From the EGL 1.4 (20130211) spec:
861 * To release the current context without assigning a new one, set ctx
862 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
864 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
865 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
867 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
868 (!read_surf
&& read
!= EGL_NO_SURFACE
))
869 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
870 if (draw_surf
|| read_surf
)
871 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
874 /* If a native window underlying either draw or read is no longer valid,
875 * an EGL_BAD_NATIVE_WINDOW error is generated.
877 if (draw_surf
&& draw_surf
->Lost
)
878 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
879 if (read_surf
&& read_surf
->Lost
)
880 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
882 ret
= drv
->MakeCurrent(disp
, draw_surf
, read_surf
, context
);
884 RETURN_EGL_EVAL(disp
, ret
);
888 EGLBoolean EGLAPIENTRY
889 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
890 EGLint attribute
, EGLint
*value
)
892 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
893 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
894 const _EGLDriver
*drv
;
897 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
899 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
901 ret
= _eglQueryContext(drv
, disp
, context
, attribute
, value
);
903 RETURN_EGL_EVAL(disp
, ret
);
907 /* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says
908 * that if native_surface was already used to create a window or pixmap, we
909 * can't create a new one. This is what this function checks for.
912 _eglNativeSurfaceAlreadyUsed(_EGLDisplay
*disp
, void *native_surface
)
916 list
= disp
->ResourceLists
[_EGL_RESOURCE_SURFACE
];
918 _EGLSurface
*surf
= (_EGLSurface
*) list
;
922 if (surf
->Type
== EGL_PBUFFER_BIT
)
925 if (surf
->NativeSurface
== native_surface
)
934 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
935 void *native_window
, const EGLint
*attrib_list
)
937 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
938 const _EGLDriver
*drv
;
943 if (native_window
== NULL
)
944 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
946 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
947 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
948 /* From the EGL_MESA_platform_surfaceless spec (v1):
950 * eglCreatePlatformWindowSurface fails when called with a <display>
951 * that belongs to the surfaceless platform. It returns
952 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
953 * justification for this unconditional failure is that the
954 * surfaceless platform has no native windows, and therefore the
955 * <native_window> parameter is always invalid.
957 * This check must occur before checking the EGLConfig, which emits
960 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
963 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
965 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
966 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
968 if (_eglNativeSurfaceAlreadyUsed(disp
, native_window
))
969 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
971 surf
= drv
->CreateWindowSurface(disp
, conf
, native_window
, attrib_list
);
972 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
974 RETURN_EGL_EVAL(disp
, ret
);
978 EGLSurface EGLAPIENTRY
979 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
980 EGLNativeWindowType window
, const EGLint
*attrib_list
)
982 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
984 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
985 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
986 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
991 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
993 #ifdef HAVE_X11_PLATFORM
994 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
995 /* The `native_window` parameter for the X11 platform differs between
996 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
997 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
998 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
999 * `Window*`. Convert `Window*` to `Window` because that's what
1000 * dri2_x11_create_window_surface() expects.
1002 return (void *)(* (Window
*) native_window
);
1005 return native_window
;
1008 static EGLSurface EGLAPIENTRY
1009 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1010 void *native_window
,
1011 const EGLint
*attrib_list
)
1013 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1015 native_window
= _fixupNativeWindow(disp
, native_window
);
1017 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1018 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1023 EGLSurface EGLAPIENTRY
1024 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
1025 void *native_window
,
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_window
= _fixupNativeWindow(disp
, native_window
);
1039 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1046 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
1048 #ifdef HAVE_X11_PLATFORM
1049 /* The `native_pixmap` parameter for the X11 platform differs between
1050 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1051 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1052 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1053 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1054 * dri2_x11_create_pixmap_surface() expects.
1056 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
1057 return (void *)(* (Pixmap
*) native_pixmap
);
1059 return native_pixmap
;
1063 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1064 void *native_pixmap
, const EGLint
*attrib_list
)
1066 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1067 const _EGLDriver
*drv
;
1071 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
1072 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
1073 /* From the EGL_MESA_platform_surfaceless spec (v1):
1075 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1076 * also fails when called with a <display> that belongs to the
1077 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1078 * EGL_BAD_NATIVE_PIXMAP.
1080 * This check must occur before checking the EGLConfig, which emits
1083 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1086 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1088 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1089 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1091 if (native_pixmap
== NULL
)
1092 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1094 if (_eglNativeSurfaceAlreadyUsed(disp
, native_pixmap
))
1095 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1097 surf
= drv
->CreatePixmapSurface(disp
, conf
, native_pixmap
, attrib_list
);
1098 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1100 RETURN_EGL_EVAL(disp
, ret
);
1104 EGLSurface EGLAPIENTRY
1105 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1106 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1108 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1110 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1111 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1112 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1116 static EGLSurface EGLAPIENTRY
1117 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1118 void *native_pixmap
,
1119 const EGLint
*attrib_list
)
1121 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1123 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1124 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1125 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1130 EGLSurface EGLAPIENTRY
1131 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1132 void *native_pixmap
,
1133 const EGLAttrib
*attrib_list
)
1135 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1137 EGLint
*int_attribs
;
1139 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1141 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1142 if (attrib_list
&& !int_attribs
)
1143 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1145 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1146 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1153 EGLSurface EGLAPIENTRY
1154 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1155 const EGLint
*attrib_list
)
1157 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1158 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1159 const _EGLDriver
*drv
;
1163 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1164 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1166 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1167 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1169 surf
= drv
->CreatePbufferSurface(disp
, conf
, attrib_list
);
1170 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1172 RETURN_EGL_EVAL(disp
, ret
);
1176 EGLBoolean EGLAPIENTRY
1177 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1179 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1180 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1181 const _EGLDriver
*drv
;
1184 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1185 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1186 _eglUnlinkSurface(surf
);
1187 ret
= drv
->DestroySurface(disp
, surf
);
1189 RETURN_EGL_EVAL(disp
, ret
);
1192 EGLBoolean EGLAPIENTRY
1193 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1194 EGLint attribute
, EGLint
*value
)
1196 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1197 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1198 const _EGLDriver
*drv
;
1201 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1202 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1204 if (drv
->QuerySurface
)
1205 ret
= drv
->QuerySurface(disp
, surf
, attribute
, value
);
1207 ret
= _eglQuerySurface(disp
, surf
, attribute
, value
);
1209 RETURN_EGL_EVAL(disp
, ret
);
1212 EGLBoolean EGLAPIENTRY
1213 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1214 EGLint attribute
, EGLint value
)
1216 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1217 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1218 const _EGLDriver
*drv
;
1221 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1222 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1224 ret
= _eglSurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1226 RETURN_EGL_EVAL(disp
, ret
);
1230 EGLBoolean EGLAPIENTRY
1231 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1233 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1234 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1235 const _EGLDriver
*drv
;
1238 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1239 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1240 ret
= drv
->BindTexImage(disp
, surf
, buffer
);
1242 RETURN_EGL_EVAL(disp
, ret
);
1246 EGLBoolean EGLAPIENTRY
1247 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1249 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1250 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1251 const _EGLDriver
*drv
;
1254 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1255 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1256 ret
= drv
->ReleaseTexImage(disp
, surf
, buffer
);
1258 RETURN_EGL_EVAL(disp
, ret
);
1262 EGLBoolean EGLAPIENTRY
1263 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1265 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1266 _EGLContext
*ctx
= _eglGetCurrentContext();
1267 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1268 const _EGLDriver
*drv
;
1271 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1272 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1274 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1275 ctx
->Resource
.Display
!= disp
)
1276 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1278 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1279 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1281 if (surf
->Type
!= EGL_WINDOW_BIT
)
1282 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1284 interval
= CLAMP(interval
,
1285 surf
->Config
->MinSwapInterval
,
1286 surf
->Config
->MaxSwapInterval
);
1288 if (surf
->SwapInterval
!= interval
) {
1289 if (drv
->SwapInterval
)
1290 ret
= drv
->SwapInterval(disp
, surf
, interval
);
1292 ret
= _eglSwapInterval(disp
, surf
, interval
);
1299 surf
->SwapInterval
= interval
;
1301 RETURN_EGL_EVAL(disp
, ret
);
1305 EGLBoolean EGLAPIENTRY
1306 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1308 _EGLContext
*ctx
= _eglGetCurrentContext();
1309 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1310 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1311 const _EGLDriver
*drv
;
1314 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1315 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1317 /* surface must be bound to current context in EGL 1.4 */
1318 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1319 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1320 surf
!= ctx
->DrawSurface
)
1321 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1324 if (surf
->Type
!= EGL_WINDOW_BIT
)
1325 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1327 /* From the EGL 1.5 spec:
1329 * If eglSwapBuffers is called and the native window associated with
1330 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1334 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1336 ret
= drv
->SwapBuffers(drv
, disp
, surf
);
1338 /* EGL_KHR_partial_update
1339 * Frame boundary successfully reached,
1340 * reset damage region and reset BufferAgeRead
1343 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1344 surf
->BufferAgeRead
= EGL_FALSE
;
1347 RETURN_EGL_EVAL(disp
, ret
);
1352 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1353 const EGLint
*rects
, EGLint n_rects
)
1355 _EGLContext
*ctx
= _eglGetCurrentContext();
1356 const _EGLDriver
*drv
;
1359 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1361 /* surface must be bound to current context in EGL 1.4 */
1362 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1363 surf
!= ctx
->DrawSurface
)
1364 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1366 if (surf
->Type
!= EGL_WINDOW_BIT
)
1367 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1369 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1370 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1372 ret
= drv
->SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1374 /* EGL_KHR_partial_update
1375 * Frame boundary successfully reached,
1376 * reset damage region and reset BufferAgeRead
1379 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1380 surf
->BufferAgeRead
= EGL_FALSE
;
1383 RETURN_EGL_EVAL(disp
, ret
);
1386 static EGLBoolean EGLAPIENTRY
1387 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1388 const EGLint
*rects
, EGLint n_rects
)
1390 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1391 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1392 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1393 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1396 static EGLBoolean EGLAPIENTRY
1397 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1398 const EGLint
*rects
, EGLint n_rects
)
1400 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1401 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1402 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1403 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1407 * Clamp the rectangles so that they lie within the surface.
1411 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1412 EGLint
*rects
, EGLint n_rects
)
1415 EGLint surf_height
= surf
->Height
;
1416 EGLint surf_width
= surf
->Width
;
1418 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1419 EGLint x1
, y1
, x2
, y2
;
1422 x2
= rects
[i
+ 2] + x1
;
1423 y2
= rects
[i
+ 3] + y1
;
1425 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1426 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1427 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1428 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1432 static EGLBoolean EGLAPIENTRY
1433 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1434 EGLint
*rects
, EGLint n_rects
)
1436 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1437 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1438 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1439 _EGLContext
*ctx
= _eglGetCurrentContext();
1440 const _EGLDriver
*drv
;
1442 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1444 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1445 surf
->Type
!= EGL_WINDOW_BIT
||
1446 ctx
->DrawSurface
!= surf
||
1447 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1448 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1450 /* If the damage region is already set or
1451 * buffer age is not queried between
1452 * frame boundaries, throw bad access error
1455 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1456 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1458 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1459 ret
= drv
->SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1462 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1464 RETURN_EGL_EVAL(disp
, ret
);
1467 EGLBoolean EGLAPIENTRY
1468 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1470 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1471 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1472 const _EGLDriver
*drv
;
1474 void *native_pixmap_ptr
;
1476 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1477 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1478 native_pixmap_ptr
= (void*) target
;
1480 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1481 ret
= drv
->CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1483 RETURN_EGL_EVAL(disp
, ret
);
1488 _eglWaitClientCommon(void)
1490 _EGLContext
*ctx
= _eglGetCurrentContext();
1492 const _EGLDriver
*drv
;
1496 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1498 disp
= ctx
->Resource
.Display
;
1499 mtx_lock(&disp
->Mutex
);
1501 /* let bad current context imply bad current surface */
1502 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1503 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1504 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1506 /* a valid current context implies an initialized current display */
1507 assert(disp
->Initialized
);
1509 ret
= drv
->WaitClient(drv
, disp
, ctx
);
1511 RETURN_EGL_EVAL(disp
, ret
);
1514 EGLBoolean EGLAPIENTRY
1517 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1518 return _eglWaitClientCommon();
1521 EGLBoolean EGLAPIENTRY
1524 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1525 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1526 return _eglWaitClientCommon();
1530 EGLBoolean EGLAPIENTRY
1531 eglWaitNative(EGLint engine
)
1533 _EGLContext
*ctx
= _eglGetCurrentContext();
1535 const _EGLDriver
*drv
;
1539 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1541 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1543 disp
= ctx
->Resource
.Display
;
1544 mtx_lock(&disp
->Mutex
);
1546 /* let bad current context imply bad current surface */
1547 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1548 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1549 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1551 /* a valid current context implies an initialized current display */
1552 assert(disp
->Initialized
);
1554 ret
= drv
->WaitNative(drv
, disp
, engine
);
1556 RETURN_EGL_EVAL(disp
, ret
);
1560 EGLDisplay EGLAPIENTRY
1561 eglGetCurrentDisplay(void)
1563 _EGLContext
*ctx
= _eglGetCurrentContext();
1566 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1568 RETURN_EGL_SUCCESS(NULL
, ret
);
1572 EGLContext EGLAPIENTRY
1573 eglGetCurrentContext(void)
1575 _EGLContext
*ctx
= _eglGetCurrentContext();
1578 ret
= _eglGetContextHandle(ctx
);
1580 RETURN_EGL_SUCCESS(NULL
, ret
);
1584 EGLSurface EGLAPIENTRY
1585 eglGetCurrentSurface(EGLint readdraw
)
1587 _EGLContext
*ctx
= _eglGetCurrentContext();
1588 EGLint err
= EGL_SUCCESS
;
1592 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1595 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1599 surf
= ctx
->DrawSurface
;
1602 surf
= ctx
->ReadSurface
;
1606 err
= EGL_BAD_PARAMETER
;
1610 ret
= _eglGetSurfaceHandle(surf
);
1612 RETURN_EGL_ERROR(NULL
, err
, ret
);
1619 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1620 EGLint e
= t
->LastError
;
1621 if (!_eglIsCurrentThreadDummy())
1622 t
->LastError
= EGL_SUCCESS
;
1632 * Specify the client API to use for subsequent calls including:
1633 * eglCreateContext()
1634 * eglGetCurrentContext()
1635 * eglGetCurrentDisplay()
1636 * eglGetCurrentSurface()
1637 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1640 * See section 3.7 "Rendering Context" in the EGL specification for details.
1642 EGLBoolean EGLAPIENTRY
1643 eglBindAPI(EGLenum api
)
1647 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1649 t
= _eglGetCurrentThread();
1650 if (_eglIsCurrentThreadDummy())
1651 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1653 if (!_eglIsApiValid(api
))
1654 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1656 t
->CurrentAPI
= api
;
1658 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1663 * Return the last value set with eglBindAPI().
1668 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1671 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1672 ret
= t
->CurrentAPI
;
1674 RETURN_EGL_SUCCESS(NULL
, ret
);
1678 EGLSurface EGLAPIENTRY
1679 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1680 EGLClientBuffer buffer
, EGLConfig config
,
1681 const EGLint
*attrib_list
)
1683 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1684 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1685 const _EGLDriver
*drv
;
1687 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1689 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1691 /* OpenVG is not supported */
1692 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1696 EGLBoolean EGLAPIENTRY
1697 eglReleaseThread(void)
1699 /* unbind current contexts */
1700 if (!_eglIsCurrentThreadDummy()) {
1701 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1702 _EGLContext
*ctx
= t
->CurrentContext
;
1704 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1707 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1709 mtx_lock(&disp
->Mutex
);
1710 (void) disp
->Driver
->MakeCurrent(disp
, NULL
, NULL
, NULL
);
1711 mtx_unlock(&disp
->Mutex
);
1715 _eglDestroyCurrentThread();
1717 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1722 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1723 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1725 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1726 const _EGLDriver
*drv
;
1730 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1731 if (!disp
->Extensions
.KHR_image_base
)
1732 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1733 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1734 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1735 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1736 * <ctx> must be EGL_NO_CONTEXT..."
1738 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1739 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1741 img
= drv
->CreateImageKHR(drv
, disp
, context
, target
,
1743 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1745 RETURN_EGL_EVAL(disp
, ret
);
1748 static EGLImage EGLAPIENTRY
1749 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1750 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1752 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1753 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1754 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1758 EGLImage EGLAPIENTRY
1759 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1760 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1762 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1764 EGLint
*int_attribs
;
1766 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1768 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1769 if (attr_list
&& !int_attribs
)
1770 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1772 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1779 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1781 const _EGLDriver
*drv
;
1784 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1785 if (!disp
->Extensions
.KHR_image_base
)
1786 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1788 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1790 _eglUnlinkImage(img
);
1791 ret
= drv
->DestroyImageKHR(drv
, disp
, img
);
1793 RETURN_EGL_EVAL(disp
, ret
);
1796 EGLBoolean EGLAPIENTRY
1797 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1799 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1800 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1801 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1802 return _eglDestroyImageCommon(disp
, img
);
1805 static EGLBoolean EGLAPIENTRY
1806 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1808 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1809 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1810 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1811 return _eglDestroyImageCommon(disp
, img
);
1816 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1817 EGLBoolean orig_is_EGLAttrib
,
1818 EGLenum invalid_type_error
)
1820 _EGLContext
*ctx
= _eglGetCurrentContext();
1821 const _EGLDriver
*drv
;
1825 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1827 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1828 /* There exist two EGLAttrib variants of eglCreateSync*:
1829 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1830 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1831 * support as a proxy for EGL 1.5 support, even though that's not
1832 * entirely correct (though _eglComputeVersion does the same).
1834 * The EGL spec provides no guidance on how to handle unsupported
1835 * functions. EGL_BAD_MATCH seems reasonable.
1837 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1840 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1841 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1842 * error is generated.
1845 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1846 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1848 /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */
1849 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1850 (ctx
->ClientAPI
!= EGL_OPENGL_ES_API
&&
1851 ctx
->ClientAPI
!= EGL_OPENGL_API
)))
1852 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1855 case EGL_SYNC_FENCE_KHR
:
1856 if (!disp
->Extensions
.KHR_fence_sync
)
1857 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1859 case EGL_SYNC_REUSABLE_KHR
:
1860 if (!disp
->Extensions
.KHR_reusable_sync
)
1861 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1863 case EGL_SYNC_CL_EVENT_KHR
:
1864 if (!disp
->Extensions
.KHR_cl_event2
)
1865 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1867 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1868 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1869 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1872 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1875 sync
= drv
->CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1876 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1878 RETURN_EGL_EVAL(disp
, ret
);
1882 static EGLSync EGLAPIENTRY
1883 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1885 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1886 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1889 EGLAttrib
*attrib_list
;
1892 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1893 attrib_list
= (EGLAttrib
*) int_list
;
1895 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1896 if (err
!= EGL_SUCCESS
)
1897 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1900 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1903 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1906 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1911 static EGLSync EGLAPIENTRY
1912 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1914 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1915 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1916 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1922 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1924 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1925 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1926 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1932 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1934 const _EGLDriver
*drv
;
1937 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1938 assert(disp
->Extensions
.KHR_reusable_sync
||
1939 disp
->Extensions
.KHR_fence_sync
||
1940 disp
->Extensions
.ANDROID_native_fence_sync
);
1943 ret
= drv
->DestroySyncKHR(drv
, disp
, s
);
1945 RETURN_EGL_EVAL(disp
, ret
);
1948 EGLBoolean EGLAPIENTRY
1949 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1951 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1952 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1953 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1954 return _eglDestroySync(disp
, s
);
1957 static EGLBoolean EGLAPIENTRY
1958 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1960 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1961 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1962 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1963 return _eglDestroySync(disp
, s
);
1968 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1969 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1971 const _EGLDriver
*drv
;
1974 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1975 assert(disp
->Extensions
.KHR_reusable_sync
||
1976 disp
->Extensions
.KHR_fence_sync
||
1977 disp
->Extensions
.ANDROID_native_fence_sync
);
1979 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1980 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1982 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1983 * unlocked here to allow other threads also to be able to
1984 * go into waiting state.
1987 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1988 _eglUnlockDisplay(dpy
);
1990 ret
= drv
->ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1993 * 'disp' is already unlocked for reusable sync type,
1994 * so passing 'NULL' to bypass unlocking display.
1996 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1997 RETURN_EGL_EVAL(NULL
, ret
);
1999 RETURN_EGL_EVAL(disp
, ret
);
2003 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
2004 EGLint flags
, EGLTime timeout
)
2006 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2007 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2008 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2009 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2012 static EGLint EGLAPIENTRY
2013 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
2014 EGLint flags
, EGLTime timeout
)
2016 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2017 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2018 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2019 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2024 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
2026 _EGLContext
*ctx
= _eglGetCurrentContext();
2027 const _EGLDriver
*drv
;
2030 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2031 assert(disp
->Extensions
.KHR_wait_sync
);
2033 /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */
2034 if (ctx
== EGL_NO_CONTEXT
||
2035 (ctx
->ClientAPI
!= EGL_OPENGL_ES_API
&&
2036 ctx
->ClientAPI
!= EGL_OPENGL_API
))
2037 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
2039 /* the API doesn't allow any flags yet */
2041 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2043 ret
= drv
->WaitSyncKHR(drv
, disp
, s
);
2045 RETURN_EGL_EVAL(disp
, ret
);
2048 static EGLint EGLAPIENTRY
2049 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2051 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2052 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2053 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2054 return _eglWaitSyncCommon(disp
, s
, flags
);
2058 EGLBoolean EGLAPIENTRY
2059 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2061 /* The KHR version returns EGLint, while the core version returns
2062 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2065 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2066 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2067 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2068 return _eglWaitSyncCommon(disp
, s
, flags
);
2072 static EGLBoolean EGLAPIENTRY
2073 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2075 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2076 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2077 const _EGLDriver
*drv
;
2080 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2082 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2083 assert(disp
->Extensions
.KHR_reusable_sync
);
2084 ret
= drv
->SignalSyncKHR(drv
, disp
, s
, mode
);
2086 RETURN_EGL_EVAL(disp
, ret
);
2091 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2093 const _EGLDriver
*drv
;
2096 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2097 assert(disp
->Extensions
.KHR_reusable_sync
||
2098 disp
->Extensions
.KHR_fence_sync
||
2099 disp
->Extensions
.ANDROID_native_fence_sync
);
2101 ret
= _eglGetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2103 RETURN_EGL_EVAL(disp
, ret
);
2106 EGLBoolean EGLAPIENTRY
2107 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2109 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2110 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2111 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2114 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2116 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2120 static EGLBoolean EGLAPIENTRY
2121 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2123 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2124 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2128 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2131 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2134 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2136 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2138 * If any error occurs, <*value> is not modified.
2140 if (result
== EGL_FALSE
)
2147 static EGLint EGLAPIENTRY
2148 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2150 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2151 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2152 const _EGLDriver
*drv
;
2155 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2157 /* the spec doesn't seem to specify what happens if the fence
2158 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2161 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2162 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2164 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2165 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2166 ret
= drv
->DupNativeFenceFDANDROID(drv
, disp
, s
);
2168 RETURN_EGL_EVAL(disp
, ret
);
2171 static EGLBoolean EGLAPIENTRY
2172 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2173 EGLint numRects
, const EGLint
*rects
)
2175 _EGLContext
*ctx
= _eglGetCurrentContext();
2176 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2177 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2178 const _EGLDriver
*drv
;
2181 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2183 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2185 if (!disp
->Extensions
.NOK_swap_region
)
2186 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2188 /* surface must be bound to current context in EGL 1.4 */
2189 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2190 surf
!= ctx
->DrawSurface
)
2191 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2193 ret
= drv
->SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2195 RETURN_EGL_EVAL(disp
, ret
);
2199 static EGLImage EGLAPIENTRY
2200 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2202 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2203 const _EGLDriver
*drv
;
2207 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2209 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2210 if (!disp
->Extensions
.MESA_drm_image
)
2211 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2213 img
= drv
->CreateDRMImageMESA(drv
, disp
, attr_list
);
2214 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2216 RETURN_EGL_EVAL(disp
, ret
);
2219 static EGLBoolean EGLAPIENTRY
2220 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2221 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2223 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2224 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2225 const _EGLDriver
*drv
;
2228 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2230 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2231 assert(disp
->Extensions
.MESA_drm_image
);
2234 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2236 ret
= drv
->ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2238 RETURN_EGL_EVAL(disp
, ret
);
2244 static EGLBoolean EGLAPIENTRY
2245 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2247 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2248 const _EGLDriver
*drv
;
2251 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2253 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2254 assert(disp
->Extensions
.WL_bind_wayland_display
);
2257 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2259 ret
= drv
->BindWaylandDisplayWL(drv
, disp
, display
);
2261 RETURN_EGL_EVAL(disp
, ret
);
2264 static EGLBoolean EGLAPIENTRY
2265 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2267 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2268 const _EGLDriver
*drv
;
2271 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2273 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2274 assert(disp
->Extensions
.WL_bind_wayland_display
);
2277 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2279 ret
= drv
->UnbindWaylandDisplayWL(drv
, disp
, display
);
2281 RETURN_EGL_EVAL(disp
, ret
);
2284 static EGLBoolean EGLAPIENTRY
2285 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2286 EGLint attribute
, EGLint
*value
)
2288 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2289 const _EGLDriver
*drv
;
2292 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2294 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2295 assert(disp
->Extensions
.WL_bind_wayland_display
);
2298 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2300 ret
= drv
->QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2302 RETURN_EGL_EVAL(disp
, ret
);
2306 static struct wl_buffer
* EGLAPIENTRY
2307 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2309 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2311 const _EGLDriver
*drv
;
2312 struct wl_buffer
*ret
;
2314 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2316 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2317 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2318 RETURN_EGL_EVAL(disp
, NULL
);
2320 img
= _eglLookupImage(image
, disp
);
2323 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2325 ret
= drv
->CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2327 RETURN_EGL_EVAL(disp
, ret
);
2330 static EGLBoolean EGLAPIENTRY
2331 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2332 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2334 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2335 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2336 const _EGLDriver
*drv
;
2339 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2341 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2343 if (!disp
->Extensions
.NV_post_sub_buffer
)
2344 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2346 ret
= drv
->PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2348 RETURN_EGL_EVAL(disp
, ret
);
2351 static EGLBoolean EGLAPIENTRY
2352 eglGetSyncValuesCHROMIUM(EGLDisplay dpy
, EGLSurface surface
,
2353 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2356 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2357 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2358 const _EGLDriver
*drv
;
2361 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2363 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2364 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2365 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2367 if (!ust
|| !msc
|| !sbc
)
2368 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2370 ret
= drv
->GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2372 RETURN_EGL_EVAL(disp
, ret
);
2375 static EGLBoolean EGLAPIENTRY
2376 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2377 EGLint
*fourcc
, EGLint
*nplanes
,
2378 EGLuint64KHR
*modifiers
)
2380 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2381 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2382 const _EGLDriver
*drv
;
2385 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2387 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2388 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2391 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2393 ret
= drv
->ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2396 RETURN_EGL_EVAL(disp
, ret
);
2399 static EGLBoolean EGLAPIENTRY
2400 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2401 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2403 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2404 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2405 const _EGLDriver
*drv
;
2408 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2410 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2411 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2414 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2416 ret
= drv
->ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2418 RETURN_EGL_EVAL(disp
, ret
);
2421 static EGLint EGLAPIENTRY
2422 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2425 _EGLDisplay
*disp
= NULL
;
2426 _EGLResourceType type
;
2428 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2430 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2431 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2433 if (!_eglIsCurrentThreadDummy()) {
2438 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2441 disp
= _eglLockDisplay(dpy
);
2443 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2445 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2446 if (dpy
!= (EGLDisplay
) object
)
2447 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2449 disp
->Label
= label
;
2450 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2453 switch (objectType
) {
2454 case EGL_OBJECT_CONTEXT_KHR
:
2455 type
= _EGL_RESOURCE_CONTEXT
;
2457 case EGL_OBJECT_SURFACE_KHR
:
2458 type
= _EGL_RESOURCE_SURFACE
;
2460 case EGL_OBJECT_IMAGE_KHR
:
2461 type
= _EGL_RESOURCE_IMAGE
;
2463 case EGL_OBJECT_SYNC_KHR
:
2464 type
= _EGL_RESOURCE_SYNC
;
2466 case EGL_OBJECT_STREAM_KHR
:
2468 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2471 if (_eglCheckResource(object
, type
, disp
)) {
2472 _EGLResource
*res
= (_EGLResource
*) object
;
2475 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2478 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2481 static EGLint EGLAPIENTRY
2482 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2483 const EGLAttrib
*attrib_list
)
2485 unsigned int newEnabled
;
2487 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2489 mtx_lock(_eglGlobal
.Mutex
);
2491 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2492 if (attrib_list
!= NULL
) {
2495 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2496 switch (attrib_list
[i
]) {
2497 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2498 case EGL_DEBUG_MSG_ERROR_KHR
:
2499 case EGL_DEBUG_MSG_WARN_KHR
:
2500 case EGL_DEBUG_MSG_INFO_KHR
:
2501 if (attrib_list
[i
+ 1])
2502 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2504 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2507 // On error, set the last error code, call the current
2508 // debug callback, and return the error code.
2509 mtx_unlock(_eglGlobal
.Mutex
);
2510 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2511 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2512 return EGL_BAD_ATTRIBUTE
;
2517 if (callback
!= NULL
) {
2518 _eglGlobal
.debugCallback
= callback
;
2519 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2521 _eglGlobal
.debugCallback
= NULL
;
2522 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2525 mtx_unlock(_eglGlobal
.Mutex
);
2529 static EGLBoolean EGLAPIENTRY
2530 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2532 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2534 mtx_lock(_eglGlobal
.Mutex
);
2536 switch (attribute
) {
2537 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2538 case EGL_DEBUG_MSG_ERROR_KHR
:
2539 case EGL_DEBUG_MSG_WARN_KHR
:
2540 case EGL_DEBUG_MSG_INFO_KHR
:
2541 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2546 case EGL_DEBUG_CALLBACK_KHR
:
2547 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2550 mtx_unlock(_eglGlobal
.Mutex
);
2551 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2552 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2556 mtx_unlock(_eglGlobal
.Mutex
);
2561 _eglFunctionCompare(const void *key
, const void *elem
)
2563 const char *procname
= key
;
2564 const struct _egl_entrypoint
*entrypoint
= elem
;
2565 return strcmp(procname
, entrypoint
->name
);
2568 static EGLBoolean EGLAPIENTRY
2569 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2570 EGLint
*formats
, EGLint
*num_formats
)
2572 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2573 const _EGLDriver
*drv
;
2576 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2578 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2580 ret
= drv
->QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2583 RETURN_EGL_EVAL(disp
, ret
);
2586 static EGLBoolean EGLAPIENTRY
2587 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2588 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2589 EGLint
*num_modifiers
)
2591 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2592 const _EGLDriver
*drv
;
2595 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2597 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2599 ret
= drv
->QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2600 modifiers
, external_only
,
2603 RETURN_EGL_EVAL(disp
, ret
);
2606 static void EGLAPIENTRY
2607 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2608 EGLGetBlobFuncANDROID get
)
2610 /* This function does not return anything so we cannot
2611 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2613 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2614 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2616 _eglUnlockDisplay(disp
);
2620 const _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2623 _eglUnlockDisplay(disp
);
2628 _eglError(EGL_BAD_PARAMETER
,
2629 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2630 _eglUnlockDisplay(disp
);
2634 if (disp
->BlobCacheSet
) {
2635 _eglError(EGL_BAD_PARAMETER
,
2636 "eglSetBlobCacheFuncsANDROID: functions already set");
2637 _eglUnlockDisplay(disp
);
2641 disp
->BlobCacheSet
= set
;
2642 disp
->BlobCacheGet
= get
;
2644 drv
->SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2646 _eglUnlockDisplay(disp
);
2649 static EGLBoolean EGLAPIENTRY
2650 eglQueryDeviceAttribEXT(EGLDeviceEXT device
,
2654 _EGLDevice
*dev
= _eglLookupDevice(device
);
2657 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2659 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, EGL_FALSE
);
2661 ret
= _eglQueryDeviceAttribEXT(dev
, attribute
, value
);
2662 RETURN_EGL_EVAL(NULL
, ret
);
2665 static const char * EGLAPIENTRY
2666 eglQueryDeviceStringEXT(EGLDeviceEXT device
,
2669 _EGLDevice
*dev
= _eglLookupDevice(device
);
2671 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2673 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, NULL
);
2675 RETURN_EGL_EVAL(NULL
, _eglQueryDeviceStringEXT(dev
, name
));
2678 static EGLBoolean EGLAPIENTRY
2679 eglQueryDevicesEXT(EGLint max_devices
,
2680 EGLDeviceEXT
*devices
,
2681 EGLint
*num_devices
)
2685 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2686 ret
= _eglQueryDevicesEXT(max_devices
, (_EGLDevice
**) devices
,
2688 RETURN_EGL_EVAL(NULL
, ret
);
2691 static EGLBoolean EGLAPIENTRY
2692 eglQueryDisplayAttribEXT(EGLDisplay dpy
,
2696 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2697 const _EGLDriver
*drv
;
2699 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2700 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2702 switch (attribute
) {
2703 case EGL_DEVICE_EXT
:
2704 *value
= (EGLAttrib
) disp
->Device
;
2707 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
2709 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
2712 static char * EGLAPIENTRY
2713 eglGetDisplayDriverConfig(EGLDisplay dpy
)
2715 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2716 const _EGLDriver
*drv
;
2719 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2720 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2722 assert(disp
->Extensions
.MESA_query_driver
);
2724 ret
= drv
->QueryDriverConfig(disp
);
2725 RETURN_EGL_EVAL(disp
, ret
);
2728 static const char * EGLAPIENTRY
2729 eglGetDisplayDriverName(EGLDisplay dpy
)
2731 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2732 const _EGLDriver
*drv
;
2735 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2736 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2738 assert(disp
->Extensions
.MESA_query_driver
);
2740 ret
= drv
->QueryDriverName(disp
);
2741 RETURN_EGL_EVAL(disp
, ret
);
2744 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2745 eglGetProcAddress(const char *procname
)
2747 static const struct _egl_entrypoint egl_functions
[] = {
2748 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2749 #include "eglentrypoint.h"
2750 #undef EGL_ENTRYPOINT
2752 _EGLProc ret
= NULL
;
2755 RETURN_EGL_SUCCESS(NULL
, NULL
);
2757 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2759 if (strncmp(procname
, "egl", 3) == 0) {
2760 const struct _egl_entrypoint
*entrypoint
=
2762 egl_functions
, ARRAY_SIZE(egl_functions
),
2763 sizeof(egl_functions
[0]),
2764 _eglFunctionCompare
);
2766 ret
= entrypoint
->function
;
2770 ret
= _eglGetDriverProc(procname
);
2772 RETURN_EGL_SUCCESS(NULL
, ret
);
2776 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2777 _EGLDisplay
**disp
, const _EGLDriver
**drv
,
2781 *disp
= _eglLockDisplay(dpy
);
2782 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2784 _eglUnlockDisplay(*disp
);
2785 return MESA_GLINTEROP_INVALID_DISPLAY
;
2788 *drv
= (*disp
)->Driver
;
2790 *ctx
= _eglLookupContext(context
, *disp
);
2792 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2793 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2794 _eglUnlockDisplay(*disp
);
2795 return MESA_GLINTEROP_INVALID_CONTEXT
;
2798 return MESA_GLINTEROP_SUCCESS
;
2802 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2803 struct mesa_glinterop_device_info
*out
)
2806 const _EGLDriver
*drv
;
2810 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2811 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2814 if (drv
->GLInteropQueryDeviceInfo
)
2815 ret
= drv
->GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2817 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2819 _eglUnlockDisplay(disp
);
2824 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2825 struct mesa_glinterop_export_in
*in
,
2826 struct mesa_glinterop_export_out
*out
)
2829 const _EGLDriver
*drv
;
2833 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2834 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2837 if (drv
->GLInteropExportObject
)
2838 ret
= drv
->GLInteropExportObject(disp
, ctx
, in
, out
);
2840 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2842 _eglUnlockDisplay(disp
);