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
96 #include "c99_compat.h"
97 #include "c11/threads.h"
98 #include "util/debug.h"
99 #include "util/macros.h"
101 #include "egldefines.h"
102 #include "eglglobals.h"
103 #include "eglcontext.h"
104 #include "egldisplay.h"
105 #include "egltypedefs.h"
106 #include "eglcurrent.h"
107 #include "egldevice.h"
108 #include "egldriver.h"
109 #include "eglsurface.h"
110 #include "eglconfig.h"
111 #include "eglimage.h"
115 #include "GL/mesa_glinterop.h"
118 * Macros to help return an API entrypoint.
120 * These macros will unlock the display and record the error code.
122 #define RETURN_EGL_ERROR(disp, err, ret) \
125 _eglUnlockDisplay(disp); \
126 /* EGL error codes are non-zero */ \
128 _eglError(err, __func__); \
132 #define RETURN_EGL_SUCCESS(disp, ret) \
133 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
135 /* record EGL_SUCCESS only when ret evaluates to true */
136 #define RETURN_EGL_EVAL(disp, ret) \
137 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
141 * A bunch of macros and checks to simplify error checking.
144 #define _EGL_CHECK_DISPLAY(disp, ret) \
146 if (!_eglCheckDisplay(disp, __func__)) \
147 RETURN_EGL_ERROR(disp, 0, ret); \
150 #define _EGL_CHECK_OBJECT(disp, type, obj, ret) \
152 if (!_eglCheck ## type(disp, obj, __func__)) \
153 RETURN_EGL_ERROR(disp, 0, ret); \
156 #define _EGL_CHECK_SURFACE(disp, surf, ret) \
157 _EGL_CHECK_OBJECT(disp, Surface, surf, ret)
159 #define _EGL_CHECK_CONTEXT(disp, context, ret) \
160 _EGL_CHECK_OBJECT(disp, Context, context, ret)
162 #define _EGL_CHECK_CONFIG(disp, conf, ret) \
163 _EGL_CHECK_OBJECT(disp, Config, conf, ret)
165 #define _EGL_CHECK_SYNC(disp, s, ret) \
166 _EGL_CHECK_OBJECT(disp, Sync, s, ret)
169 extern const _EGLDriver _eglDriver
;
172 struct _egl_entrypoint
{
179 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
182 _eglError(EGL_BAD_DISPLAY
, msg
);
185 if (!disp
->Initialized
) {
186 _eglError(EGL_NOT_INITIALIZED
, msg
);
194 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
196 if (!_eglCheckDisplay(disp
, msg
))
199 _eglError(EGL_BAD_SURFACE
, msg
);
207 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
209 if (!_eglCheckDisplay(disp
, msg
))
212 _eglError(EGL_BAD_CONTEXT
, msg
);
220 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
222 if (!_eglCheckDisplay(disp
, msg
))
225 _eglError(EGL_BAD_CONFIG
, msg
);
233 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
235 if (!_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
) {
620 disp
->Options
.ForceSoftware
=
621 env_var_as_boolean("LIBGL_ALWAYS_SOFTWARE", false);
622 if (disp
->Options
.ForceSoftware
)
623 _eglLog(_EGL_DEBUG
, "Found 'LIBGL_ALWAYS_SOFTWARE' set, will use a CPU renderer");
626 * Initialize the display using the driver's function.
627 * If the initialisation fails, try again using only software rendering.
629 if (!_eglDriver
.Initialize(disp
)) {
630 if (disp
->Options
.ForceSoftware
)
631 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
633 disp
->Options
.ForceSoftware
= EGL_TRUE
;
634 if (!_eglDriver
.Initialize(disp
))
635 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
639 disp
->Initialized
= EGL_TRUE
;
640 disp
->Driver
= &_eglDriver
;
642 /* limit to APIs supported by core */
643 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
645 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
646 * classifies it as an EGL display extension, though conceptually it's an
647 * EGL client extension.
649 * From the EGL_KHR_get_all_proc_addresses spec:
651 * The EGL implementation must expose the name
652 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
653 * EGL_KHR_get_all_proc_addresses and supports
654 * EGL_EXT_client_extensions.
656 * Mesa unconditionally exposes both client extensions mentioned above,
657 * so the spec requires that each EGLDisplay unconditionally expose
658 * EGL_KHR_get_all_proc_addresses also.
660 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
662 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
663 * programs. It is driver agnostic and handled in the main EGL code.
665 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
667 _eglComputeVersion(disp
);
668 _eglCreateExtensionsString(disp
);
669 _eglCreateAPIsString(disp
);
670 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
671 "%d.%d", disp
->Version
/ 10, disp
->Version
% 10);
674 /* Update applications version of major and minor if not NULL */
675 if ((major
!= NULL
) && (minor
!= NULL
)) {
676 *major
= disp
->Version
/ 10;
677 *minor
= disp
->Version
% 10;
680 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
684 EGLBoolean EGLAPIENTRY
685 eglTerminate(EGLDisplay dpy
)
687 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
689 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
692 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
694 if (disp
->Initialized
) {
695 disp
->Driver
->Terminate(disp
);
696 /* do not reset disp->Driver */
697 disp
->ClientAPIsString
[0] = 0;
698 disp
->Initialized
= EGL_FALSE
;
700 /* Reset blob cache funcs on terminate. */
701 disp
->BlobCacheSet
= NULL
;
702 disp
->BlobCacheGet
= NULL
;
705 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
709 const char * EGLAPIENTRY
710 eglQueryString(EGLDisplay dpy
, EGLint name
)
715 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
716 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
720 disp
= _eglLockDisplay(dpy
);
721 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
722 _EGL_CHECK_DISPLAY(disp
, NULL
);
726 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
728 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
730 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
731 case EGL_CLIENT_APIS
:
732 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
734 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
739 EGLBoolean EGLAPIENTRY
740 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
741 EGLint config_size
, EGLint
*num_config
)
743 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
746 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
748 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
751 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
753 ret
= _eglGetConfigs(disp
, configs
, config_size
, num_config
);
755 RETURN_EGL_EVAL(disp
, ret
);
759 EGLBoolean EGLAPIENTRY
760 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
761 EGLint config_size
, EGLint
*num_config
)
763 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
766 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
768 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
771 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
773 ret
= _eglChooseConfig(disp
, attrib_list
, configs
,
774 config_size
, num_config
);
776 RETURN_EGL_EVAL(disp
, ret
);
780 EGLBoolean EGLAPIENTRY
781 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
782 EGLint attribute
, EGLint
*value
)
784 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
785 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
788 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
790 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
);
792 ret
= _eglGetConfigAttrib(disp
, conf
, attribute
, value
);
794 RETURN_EGL_EVAL(disp
, ret
);
798 EGLContext EGLAPIENTRY
799 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
800 const EGLint
*attrib_list
)
802 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
803 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
804 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
805 _EGLContext
*context
;
808 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
810 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
);
812 if (config
!= EGL_NO_CONFIG_KHR
)
813 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
);
814 else if (!disp
->Extensions
.KHR_no_config_context
)
815 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
817 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
818 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
820 context
= disp
->Driver
->CreateContext(disp
, conf
, share
, attrib_list
);
821 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
823 RETURN_EGL_EVAL(disp
, ret
);
827 EGLBoolean EGLAPIENTRY
828 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
830 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
831 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
834 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
836 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
);
837 _eglUnlinkContext(context
);
838 ret
= disp
->Driver
->DestroyContext(disp
, context
);
840 RETURN_EGL_EVAL(disp
, ret
);
844 EGLBoolean EGLAPIENTRY
845 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
848 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
849 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
850 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
851 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
854 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
857 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
859 /* display is allowed to be uninitialized under certain condition */
860 if (!disp
->Initialized
) {
861 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
862 ctx
!= EGL_NO_CONTEXT
)
863 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
866 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
868 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
869 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
870 if (!draw_surf
|| !read_surf
) {
871 /* From the EGL 1.4 (20130211) spec:
873 * To release the current context without assigning a new one, set ctx
874 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
876 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
877 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
879 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
880 (!read_surf
&& read
!= EGL_NO_SURFACE
))
881 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
882 if (draw_surf
|| read_surf
)
883 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
886 /* If a native window underlying either draw or read is no longer valid,
887 * an EGL_BAD_NATIVE_WINDOW error is generated.
889 if (draw_surf
&& draw_surf
->Lost
)
890 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
891 if (read_surf
&& read_surf
->Lost
)
892 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
894 ret
= disp
->Driver
->MakeCurrent(disp
, draw_surf
, read_surf
, context
);
896 RETURN_EGL_EVAL(disp
, ret
);
900 EGLBoolean EGLAPIENTRY
901 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
902 EGLint attribute
, EGLint
*value
)
904 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
905 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
908 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
910 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
);
912 ret
= _eglQueryContext(context
, attribute
, value
);
914 RETURN_EGL_EVAL(disp
, ret
);
918 /* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says
919 * that if native_surface was already used to create a window or pixmap, we
920 * can't create a new one. This is what this function checks for.
923 _eglNativeSurfaceAlreadyUsed(_EGLDisplay
*disp
, void *native_surface
)
927 list
= disp
->ResourceLists
[_EGL_RESOURCE_SURFACE
];
929 _EGLSurface
*surf
= (_EGLSurface
*) list
;
933 if (surf
->Type
== EGL_PBUFFER_BIT
)
936 if (surf
->NativeSurface
== native_surface
)
945 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
946 void *native_window
, const EGLint
*attrib_list
)
948 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
953 if (native_window
== NULL
)
954 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
956 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
957 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
958 /* From the EGL_MESA_platform_surfaceless spec (v1):
960 * eglCreatePlatformWindowSurface fails when called with a <display>
961 * that belongs to the surfaceless platform. It returns
962 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
963 * justification for this unconditional failure is that the
964 * surfaceless platform has no native windows, and therefore the
965 * <native_window> parameter is always invalid.
967 * This check must occur before checking the EGLConfig, which emits
970 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
973 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
);
975 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
976 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
978 if (_eglNativeSurfaceAlreadyUsed(disp
, native_window
))
979 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
981 surf
= disp
->Driver
->CreateWindowSurface(disp
, conf
, native_window
, attrib_list
);
982 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
984 RETURN_EGL_EVAL(disp
, ret
);
988 EGLSurface EGLAPIENTRY
989 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
990 EGLNativeWindowType window
, const EGLint
*attrib_list
)
992 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
994 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
995 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
996 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
1001 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
1003 #ifdef HAVE_X11_PLATFORM
1004 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
1005 /* The `native_window` parameter for the X11 platform differs between
1006 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1007 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
1008 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
1009 * `Window*`. Convert `Window*` to `Window` because that's what
1010 * dri2_x11_create_window_surface() expects.
1012 return (void *)(* (Window
*) native_window
);
1015 return native_window
;
1018 static EGLSurface EGLAPIENTRY
1019 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1020 void *native_window
,
1021 const EGLint
*attrib_list
)
1023 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1025 native_window
= _fixupNativeWindow(disp
, native_window
);
1027 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1028 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1033 EGLSurface EGLAPIENTRY
1034 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
1035 void *native_window
,
1036 const EGLAttrib
*attrib_list
)
1038 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1040 EGLint
*int_attribs
;
1042 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1044 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1045 if (attrib_list
&& !int_attribs
)
1046 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1048 native_window
= _fixupNativeWindow(disp
, native_window
);
1049 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1056 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
1058 #ifdef HAVE_X11_PLATFORM
1059 /* The `native_pixmap` parameter for the X11 platform differs between
1060 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1061 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1062 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1063 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1064 * dri2_x11_create_pixmap_surface() expects.
1066 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
1067 return (void *)(* (Pixmap
*) native_pixmap
);
1069 return native_pixmap
;
1073 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1074 void *native_pixmap
, const EGLint
*attrib_list
)
1076 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1080 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
1081 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
1082 /* From the EGL_MESA_platform_surfaceless spec (v1):
1084 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1085 * also fails when called with a <display> that belongs to the
1086 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1087 * EGL_BAD_NATIVE_PIXMAP.
1089 * This check must occur before checking the EGLConfig, which emits
1092 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1095 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
);
1097 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1098 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1100 if (native_pixmap
== NULL
)
1101 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1103 if (_eglNativeSurfaceAlreadyUsed(disp
, native_pixmap
))
1104 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1106 surf
= disp
->Driver
->CreatePixmapSurface(disp
, conf
, native_pixmap
, attrib_list
);
1107 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1109 RETURN_EGL_EVAL(disp
, ret
);
1113 EGLSurface EGLAPIENTRY
1114 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1115 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1117 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1119 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1120 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1121 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1125 static EGLSurface EGLAPIENTRY
1126 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1127 void *native_pixmap
,
1128 const EGLint
*attrib_list
)
1130 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1132 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1133 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1134 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1139 EGLSurface EGLAPIENTRY
1140 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1141 void *native_pixmap
,
1142 const EGLAttrib
*attrib_list
)
1144 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1146 EGLint
*int_attribs
;
1148 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1150 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1151 if (attrib_list
&& !int_attribs
)
1152 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1154 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1155 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1162 EGLSurface EGLAPIENTRY
1163 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1164 const EGLint
*attrib_list
)
1166 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1167 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1171 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1172 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
);
1174 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1175 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1177 surf
= disp
->Driver
->CreatePbufferSurface(disp
, conf
, attrib_list
);
1178 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1180 RETURN_EGL_EVAL(disp
, ret
);
1184 EGLBoolean EGLAPIENTRY
1185 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1187 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1188 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1191 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1192 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
1193 _eglUnlinkSurface(surf
);
1194 ret
= disp
->Driver
->DestroySurface(disp
, surf
);
1196 RETURN_EGL_EVAL(disp
, ret
);
1199 EGLBoolean EGLAPIENTRY
1200 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1201 EGLint attribute
, EGLint
*value
)
1203 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1204 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1207 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1208 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
1210 if (disp
->Driver
->QuerySurface
)
1211 ret
= disp
->Driver
->QuerySurface(disp
, surf
, attribute
, value
);
1213 ret
= _eglQuerySurface(disp
, surf
, attribute
, value
);
1215 RETURN_EGL_EVAL(disp
, ret
);
1218 EGLBoolean EGLAPIENTRY
1219 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1220 EGLint attribute
, EGLint value
)
1222 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1223 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1226 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1227 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
1229 ret
= _eglSurfaceAttrib(disp
, surf
, attribute
, value
);
1231 RETURN_EGL_EVAL(disp
, ret
);
1235 EGLBoolean EGLAPIENTRY
1236 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1238 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1239 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1242 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1243 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
1244 ret
= disp
->Driver
->BindTexImage(disp
, surf
, buffer
);
1246 RETURN_EGL_EVAL(disp
, ret
);
1250 EGLBoolean EGLAPIENTRY
1251 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1253 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1254 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1257 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1258 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
1259 ret
= disp
->Driver
->ReleaseTexImage(disp
, surf
, buffer
);
1261 RETURN_EGL_EVAL(disp
, ret
);
1265 EGLBoolean EGLAPIENTRY
1266 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1268 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1269 _EGLContext
*ctx
= _eglGetCurrentContext();
1270 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1273 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1274 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
1276 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1277 ctx
->Resource
.Display
!= disp
)
1278 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1280 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1281 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1283 if (surf
->Type
!= EGL_WINDOW_BIT
)
1284 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1286 interval
= CLAMP(interval
,
1287 surf
->Config
->MinSwapInterval
,
1288 surf
->Config
->MaxSwapInterval
);
1290 if (surf
->SwapInterval
!= interval
) {
1291 if (disp
->Driver
->SwapInterval
)
1292 ret
= disp
->Driver
->SwapInterval(disp
, surf
, interval
);
1294 ret
= _eglSwapInterval(disp
, surf
, interval
);
1301 surf
->SwapInterval
= interval
;
1303 RETURN_EGL_EVAL(disp
, ret
);
1307 EGLBoolean EGLAPIENTRY
1308 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1310 _EGLContext
*ctx
= _eglGetCurrentContext();
1311 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1312 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1315 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1316 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
1318 /* surface must be bound to current context in EGL 1.4 */
1319 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1320 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1321 surf
!= ctx
->DrawSurface
)
1322 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1325 if (surf
->Type
!= EGL_WINDOW_BIT
)
1326 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1328 /* From the EGL 1.5 spec:
1330 * If eglSwapBuffers is called and the native window associated with
1331 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1335 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1337 ret
= disp
->Driver
->SwapBuffers(disp
, surf
);
1339 /* EGL_KHR_partial_update
1340 * Frame boundary successfully reached,
1341 * reset damage region and reset BufferAgeRead
1344 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1345 surf
->BufferAgeRead
= EGL_FALSE
;
1348 RETURN_EGL_EVAL(disp
, ret
);
1353 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1354 const EGLint
*rects
, EGLint n_rects
)
1356 _EGLContext
*ctx
= _eglGetCurrentContext();
1359 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
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
= disp
->Driver
->SwapBuffersWithDamageEXT(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(_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();
1441 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
1443 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1444 surf
->Type
!= EGL_WINDOW_BIT
||
1445 ctx
->DrawSurface
!= surf
||
1446 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1447 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1449 /* If the damage region is already set or
1450 * buffer age is not queried between
1451 * frame boundaries, throw bad access error
1454 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1455 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1457 _eglSetDamageRegionKHRClampRects(surf
, rects
, n_rects
);
1458 ret
= disp
->Driver
->SetDamageRegion(disp
, surf
, rects
, n_rects
);
1461 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1463 RETURN_EGL_EVAL(disp
, ret
);
1466 EGLBoolean EGLAPIENTRY
1467 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1469 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1470 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1472 void *native_pixmap_ptr
;
1474 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1475 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1476 native_pixmap_ptr
= (void*) target
;
1478 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
1479 ret
= disp
->Driver
->CopyBuffers(disp
, surf
, native_pixmap_ptr
);
1481 RETURN_EGL_EVAL(disp
, ret
);
1486 _eglWaitClientCommon(void)
1488 _EGLContext
*ctx
= _eglGetCurrentContext();
1493 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1495 disp
= ctx
->Resource
.Display
;
1496 mtx_lock(&disp
->Mutex
);
1498 /* let bad current context imply bad current surface */
1499 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1500 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1501 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1503 /* a valid current context implies an initialized current display */
1504 assert(disp
->Initialized
);
1505 ret
= disp
->Driver
->WaitClient(disp
, ctx
);
1507 RETURN_EGL_EVAL(disp
, ret
);
1510 EGLBoolean EGLAPIENTRY
1513 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1514 return _eglWaitClientCommon();
1517 EGLBoolean EGLAPIENTRY
1520 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1521 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1522 return _eglWaitClientCommon();
1526 EGLBoolean EGLAPIENTRY
1527 eglWaitNative(EGLint engine
)
1529 _EGLContext
*ctx
= _eglGetCurrentContext();
1534 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1536 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1538 disp
= ctx
->Resource
.Display
;
1539 mtx_lock(&disp
->Mutex
);
1541 /* let bad current context imply bad current surface */
1542 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1543 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1544 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1546 /* a valid current context implies an initialized current display */
1547 assert(disp
->Initialized
);
1548 ret
= disp
->Driver
->WaitNative(engine
);
1550 RETURN_EGL_EVAL(disp
, ret
);
1554 EGLDisplay EGLAPIENTRY
1555 eglGetCurrentDisplay(void)
1557 _EGLContext
*ctx
= _eglGetCurrentContext();
1560 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1562 RETURN_EGL_SUCCESS(NULL
, ret
);
1566 EGLContext EGLAPIENTRY
1567 eglGetCurrentContext(void)
1569 _EGLContext
*ctx
= _eglGetCurrentContext();
1572 ret
= _eglGetContextHandle(ctx
);
1574 RETURN_EGL_SUCCESS(NULL
, ret
);
1578 EGLSurface EGLAPIENTRY
1579 eglGetCurrentSurface(EGLint readdraw
)
1581 _EGLContext
*ctx
= _eglGetCurrentContext();
1582 EGLint err
= EGL_SUCCESS
;
1586 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1589 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1593 surf
= ctx
->DrawSurface
;
1596 surf
= ctx
->ReadSurface
;
1600 err
= EGL_BAD_PARAMETER
;
1604 ret
= _eglGetSurfaceHandle(surf
);
1606 RETURN_EGL_ERROR(NULL
, err
, ret
);
1613 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1614 EGLint e
= t
->LastError
;
1615 if (!_eglIsCurrentThreadDummy())
1616 t
->LastError
= EGL_SUCCESS
;
1626 * Specify the client API to use for subsequent calls including:
1627 * eglCreateContext()
1628 * eglGetCurrentContext()
1629 * eglGetCurrentDisplay()
1630 * eglGetCurrentSurface()
1631 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1634 * See section 3.7 "Rendering Context" in the EGL specification for details.
1636 EGLBoolean EGLAPIENTRY
1637 eglBindAPI(EGLenum api
)
1641 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1643 t
= _eglGetCurrentThread();
1644 if (_eglIsCurrentThreadDummy())
1645 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1647 if (!_eglIsApiValid(api
))
1648 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1650 t
->CurrentAPI
= api
;
1652 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1657 * Return the last value set with eglBindAPI().
1662 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1665 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1666 ret
= t
->CurrentAPI
;
1668 RETURN_EGL_SUCCESS(NULL
, ret
);
1672 EGLSurface EGLAPIENTRY
1673 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1674 EGLClientBuffer buffer
, EGLConfig config
,
1675 const EGLint
*attrib_list
)
1677 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1678 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1680 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1682 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
);
1684 /* OpenVG is not supported */
1685 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1689 EGLBoolean EGLAPIENTRY
1690 eglReleaseThread(void)
1692 /* unbind current contexts */
1693 if (!_eglIsCurrentThreadDummy()) {
1694 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1695 _EGLContext
*ctx
= t
->CurrentContext
;
1697 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1700 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1702 mtx_lock(&disp
->Mutex
);
1703 (void) disp
->Driver
->MakeCurrent(disp
, NULL
, NULL
, NULL
);
1704 mtx_unlock(&disp
->Mutex
);
1708 _eglDestroyCurrentThread();
1710 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1715 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1716 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1718 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1722 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
);
1723 if (!disp
->Extensions
.KHR_image_base
)
1724 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1725 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1726 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1727 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1728 * <ctx> must be EGL_NO_CONTEXT..."
1730 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1731 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1733 img
= disp
->Driver
->CreateImageKHR(disp
, context
, target
, buffer
, attr_list
);
1734 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1736 RETURN_EGL_EVAL(disp
, ret
);
1739 static EGLImage EGLAPIENTRY
1740 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1741 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1743 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1744 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1745 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1749 EGLImage EGLAPIENTRY
1750 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1751 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1753 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1755 EGLint
*int_attribs
;
1757 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1759 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1760 if (attr_list
&& !int_attribs
)
1761 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1763 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1770 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1774 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
1775 if (!disp
->Extensions
.KHR_image_base
)
1776 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1778 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1780 _eglUnlinkImage(img
);
1781 ret
= disp
->Driver
->DestroyImageKHR(disp
, img
);
1783 RETURN_EGL_EVAL(disp
, ret
);
1786 EGLBoolean EGLAPIENTRY
1787 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1789 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1790 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1791 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1792 return _eglDestroyImageCommon(disp
, img
);
1795 static EGLBoolean EGLAPIENTRY
1796 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1798 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1799 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1800 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1801 return _eglDestroyImageCommon(disp
, img
);
1806 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1807 EGLBoolean orig_is_EGLAttrib
,
1808 EGLenum invalid_type_error
)
1810 _EGLContext
*ctx
= _eglGetCurrentContext();
1814 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
);
1816 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1817 /* There exist two EGLAttrib variants of eglCreateSync*:
1818 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1819 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1820 * support as a proxy for EGL 1.5 support, even though that's not
1821 * entirely correct (though _eglComputeVersion does the same).
1823 * The EGL spec provides no guidance on how to handle unsupported
1824 * functions. EGL_BAD_MATCH seems reasonable.
1826 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1829 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1830 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1831 * error is generated.
1834 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1835 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1837 /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */
1838 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1839 (ctx
->ClientAPI
!= EGL_OPENGL_ES_API
&&
1840 ctx
->ClientAPI
!= EGL_OPENGL_API
)))
1841 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1844 case EGL_SYNC_FENCE_KHR
:
1845 if (!disp
->Extensions
.KHR_fence_sync
)
1846 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1848 case EGL_SYNC_REUSABLE_KHR
:
1849 if (!disp
->Extensions
.KHR_reusable_sync
)
1850 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1852 case EGL_SYNC_CL_EVENT_KHR
:
1853 if (!disp
->Extensions
.KHR_cl_event2
)
1854 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1856 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1857 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1858 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1861 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1864 sync
= disp
->Driver
->CreateSyncKHR(disp
, type
, attrib_list
);
1865 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1867 RETURN_EGL_EVAL(disp
, ret
);
1871 static EGLSync EGLAPIENTRY
1872 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1874 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1875 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1878 EGLAttrib
*attrib_list
;
1881 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1882 attrib_list
= (EGLAttrib
*) int_list
;
1884 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1885 if (err
!= EGL_SUCCESS
)
1886 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1889 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1892 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1895 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1900 static EGLSync EGLAPIENTRY
1901 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1903 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1904 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1905 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1911 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1913 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1914 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1915 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1921 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1925 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
);
1926 assert(disp
->Extensions
.KHR_reusable_sync
||
1927 disp
->Extensions
.KHR_fence_sync
||
1928 disp
->Extensions
.ANDROID_native_fence_sync
);
1931 ret
= disp
->Driver
->DestroySyncKHR(disp
, s
);
1933 RETURN_EGL_EVAL(disp
, ret
);
1936 EGLBoolean EGLAPIENTRY
1937 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1939 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1940 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1941 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1942 return _eglDestroySync(disp
, s
);
1945 static EGLBoolean EGLAPIENTRY
1946 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1948 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1949 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1950 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1951 return _eglDestroySync(disp
, s
);
1956 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1957 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1961 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
);
1962 assert(disp
->Extensions
.KHR_reusable_sync
||
1963 disp
->Extensions
.KHR_fence_sync
||
1964 disp
->Extensions
.ANDROID_native_fence_sync
);
1966 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1967 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1969 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1970 * unlocked here to allow other threads also to be able to
1971 * go into waiting state.
1974 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1975 _eglUnlockDisplay(dpy
);
1977 ret
= disp
->Driver
->ClientWaitSyncKHR(disp
, s
, flags
, timeout
);
1980 * 'disp' is already unlocked for reusable sync type,
1981 * so passing 'NULL' to bypass unlocking display.
1983 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1984 RETURN_EGL_EVAL(NULL
, ret
);
1986 RETURN_EGL_EVAL(disp
, ret
);
1990 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
1991 EGLint flags
, EGLTime timeout
)
1993 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1994 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1995 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1996 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1999 static EGLint EGLAPIENTRY
2000 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
2001 EGLint flags
, EGLTime timeout
)
2003 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2004 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2005 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2006 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2011 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
2013 _EGLContext
*ctx
= _eglGetCurrentContext();
2016 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
);
2017 assert(disp
->Extensions
.KHR_wait_sync
);
2019 /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */
2020 if (ctx
== EGL_NO_CONTEXT
||
2021 (ctx
->ClientAPI
!= EGL_OPENGL_ES_API
&&
2022 ctx
->ClientAPI
!= EGL_OPENGL_API
))
2023 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
2025 /* the API doesn't allow any flags yet */
2027 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2029 ret
= disp
->Driver
->WaitSyncKHR(disp
, s
);
2031 RETURN_EGL_EVAL(disp
, ret
);
2034 static EGLint EGLAPIENTRY
2035 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2037 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2038 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2039 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2040 return _eglWaitSyncCommon(disp
, s
, flags
);
2044 EGLBoolean EGLAPIENTRY
2045 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2047 /* The KHR version returns EGLint, while the core version returns
2048 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
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 static EGLBoolean EGLAPIENTRY
2059 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2061 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2062 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2065 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2067 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
);
2068 assert(disp
->Extensions
.KHR_reusable_sync
);
2069 ret
= disp
->Driver
->SignalSyncKHR(disp
, s
, mode
);
2071 RETURN_EGL_EVAL(disp
, ret
);
2076 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2080 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
);
2081 assert(disp
->Extensions
.KHR_reusable_sync
||
2082 disp
->Extensions
.KHR_fence_sync
||
2083 disp
->Extensions
.ANDROID_native_fence_sync
);
2085 ret
= _eglGetSyncAttrib(disp
, s
, attribute
, value
);
2087 RETURN_EGL_EVAL(disp
, ret
);
2090 EGLBoolean EGLAPIENTRY
2091 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2093 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2094 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2095 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2098 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2100 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2104 static EGLBoolean EGLAPIENTRY
2105 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2107 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2108 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2112 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2115 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2118 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2120 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2122 * If any error occurs, <*value> is not modified.
2124 if (result
== EGL_FALSE
)
2131 static EGLint EGLAPIENTRY
2132 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2134 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2135 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2138 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2140 /* the spec doesn't seem to specify what happens if the fence
2141 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2144 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2145 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2147 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2148 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2149 ret
= disp
->Driver
->DupNativeFenceFDANDROID(disp
, s
);
2151 RETURN_EGL_EVAL(disp
, ret
);
2154 static EGLBoolean EGLAPIENTRY
2155 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2156 EGLint numRects
, const EGLint
*rects
)
2158 _EGLContext
*ctx
= _eglGetCurrentContext();
2159 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2160 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2163 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2165 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
2167 if (!disp
->Extensions
.NOK_swap_region
)
2168 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2170 /* surface must be bound to current context in EGL 1.4 */
2171 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2172 surf
!= ctx
->DrawSurface
)
2173 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2175 ret
= disp
->Driver
->SwapBuffersRegionNOK(disp
, surf
, numRects
, rects
);
2177 RETURN_EGL_EVAL(disp
, ret
);
2181 static EGLImage EGLAPIENTRY
2182 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2184 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2188 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2190 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
);
2191 if (!disp
->Extensions
.MESA_drm_image
)
2192 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2194 img
= disp
->Driver
->CreateDRMImageMESA(disp
, attr_list
);
2195 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2197 RETURN_EGL_EVAL(disp
, ret
);
2200 static EGLBoolean EGLAPIENTRY
2201 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2202 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2204 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2205 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2208 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2210 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
2211 assert(disp
->Extensions
.MESA_drm_image
);
2214 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2216 ret
= disp
->Driver
->ExportDRMImageMESA(disp
, img
, name
, handle
, stride
);
2218 RETURN_EGL_EVAL(disp
, ret
);
2224 static EGLBoolean EGLAPIENTRY
2225 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2227 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2230 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2232 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
2233 assert(disp
->Extensions
.WL_bind_wayland_display
);
2236 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2238 ret
= disp
->Driver
->BindWaylandDisplayWL(disp
, display
);
2240 RETURN_EGL_EVAL(disp
, ret
);
2243 static EGLBoolean EGLAPIENTRY
2244 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2246 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2249 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2251 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
2252 assert(disp
->Extensions
.WL_bind_wayland_display
);
2255 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2257 ret
= disp
->Driver
->UnbindWaylandDisplayWL(disp
, display
);
2259 RETURN_EGL_EVAL(disp
, ret
);
2262 static EGLBoolean EGLAPIENTRY
2263 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2264 EGLint attribute
, EGLint
*value
)
2266 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2269 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2271 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
2272 assert(disp
->Extensions
.WL_bind_wayland_display
);
2275 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2277 ret
= disp
->Driver
->QueryWaylandBufferWL(disp
, buffer
, attribute
, value
);
2279 RETURN_EGL_EVAL(disp
, ret
);
2283 static struct wl_buffer
* EGLAPIENTRY
2284 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2286 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2288 struct wl_buffer
*ret
;
2290 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2292 _EGL_CHECK_DISPLAY(disp
, NULL
);
2293 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2294 RETURN_EGL_EVAL(disp
, NULL
);
2296 img
= _eglLookupImage(image
, disp
);
2299 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2301 ret
= disp
->Driver
->CreateWaylandBufferFromImageWL(disp
, img
);
2303 RETURN_EGL_EVAL(disp
, ret
);
2306 static EGLBoolean EGLAPIENTRY
2307 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2308 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2310 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2311 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2314 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2316 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
2318 if (!disp
->Extensions
.NV_post_sub_buffer
)
2319 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2321 ret
= disp
->Driver
->PostSubBufferNV(disp
, surf
, x
, y
, width
, height
);
2323 RETURN_EGL_EVAL(disp
, ret
);
2326 static EGLBoolean EGLAPIENTRY
2327 eglGetSyncValuesCHROMIUM(EGLDisplay dpy
, EGLSurface surface
,
2328 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2331 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2332 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2335 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2337 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
2338 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2339 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2341 if (!ust
|| !msc
|| !sbc
)
2342 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2344 ret
= disp
->Driver
->GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2346 RETURN_EGL_EVAL(disp
, ret
);
2349 static EGLBoolean EGLAPIENTRY
2350 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2351 EGLint
*fourcc
, EGLint
*nplanes
,
2352 EGLuint64KHR
*modifiers
)
2354 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2355 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2358 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2360 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
2361 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2364 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2366 ret
= disp
->Driver
->ExportDMABUFImageQueryMESA(disp
, img
, fourcc
, nplanes
, modifiers
);
2368 RETURN_EGL_EVAL(disp
, ret
);
2371 static EGLBoolean EGLAPIENTRY
2372 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2373 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2375 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2376 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2379 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2381 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
2382 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2385 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2387 ret
= disp
->Driver
->ExportDMABUFImageMESA(disp
, img
, fds
, strides
, offsets
);
2389 RETURN_EGL_EVAL(disp
, ret
);
2392 static EGLint EGLAPIENTRY
2393 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2396 _EGLDisplay
*disp
= NULL
;
2397 _EGLResourceType type
;
2399 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2401 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2402 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2404 if (!_eglIsCurrentThreadDummy()) {
2409 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2412 disp
= _eglLockDisplay(dpy
);
2414 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2416 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2417 if (dpy
!= (EGLDisplay
) object
)
2418 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2420 disp
->Label
= label
;
2421 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2424 switch (objectType
) {
2425 case EGL_OBJECT_CONTEXT_KHR
:
2426 type
= _EGL_RESOURCE_CONTEXT
;
2428 case EGL_OBJECT_SURFACE_KHR
:
2429 type
= _EGL_RESOURCE_SURFACE
;
2431 case EGL_OBJECT_IMAGE_KHR
:
2432 type
= _EGL_RESOURCE_IMAGE
;
2434 case EGL_OBJECT_SYNC_KHR
:
2435 type
= _EGL_RESOURCE_SYNC
;
2437 case EGL_OBJECT_STREAM_KHR
:
2439 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2442 if (_eglCheckResource(object
, type
, disp
)) {
2443 _EGLResource
*res
= (_EGLResource
*) object
;
2446 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2449 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2452 static EGLint EGLAPIENTRY
2453 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2454 const EGLAttrib
*attrib_list
)
2456 unsigned int newEnabled
;
2458 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2460 mtx_lock(_eglGlobal
.Mutex
);
2462 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2463 if (attrib_list
!= NULL
) {
2466 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2467 switch (attrib_list
[i
]) {
2468 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2469 case EGL_DEBUG_MSG_ERROR_KHR
:
2470 case EGL_DEBUG_MSG_WARN_KHR
:
2471 case EGL_DEBUG_MSG_INFO_KHR
:
2472 if (attrib_list
[i
+ 1])
2473 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2475 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2478 // On error, set the last error code, call the current
2479 // debug callback, and return the error code.
2480 mtx_unlock(_eglGlobal
.Mutex
);
2481 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2482 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2483 return EGL_BAD_ATTRIBUTE
;
2488 if (callback
!= NULL
) {
2489 _eglGlobal
.debugCallback
= callback
;
2490 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2492 _eglGlobal
.debugCallback
= NULL
;
2493 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2496 mtx_unlock(_eglGlobal
.Mutex
);
2500 static EGLBoolean EGLAPIENTRY
2501 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2503 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2505 mtx_lock(_eglGlobal
.Mutex
);
2507 switch (attribute
) {
2508 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2509 case EGL_DEBUG_MSG_ERROR_KHR
:
2510 case EGL_DEBUG_MSG_WARN_KHR
:
2511 case EGL_DEBUG_MSG_INFO_KHR
:
2512 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2517 case EGL_DEBUG_CALLBACK_KHR
:
2518 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2521 mtx_unlock(_eglGlobal
.Mutex
);
2522 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2523 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2527 mtx_unlock(_eglGlobal
.Mutex
);
2532 _eglFunctionCompare(const void *key
, const void *elem
)
2534 const char *procname
= key
;
2535 const struct _egl_entrypoint
*entrypoint
= elem
;
2536 return strcmp(procname
, entrypoint
->name
);
2539 static EGLBoolean EGLAPIENTRY
2540 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2541 EGLint
*formats
, EGLint
*num_formats
)
2543 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2546 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2548 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
2550 ret
= disp
->Driver
->QueryDmaBufFormatsEXT(disp
, max_formats
, formats
, num_formats
);
2552 RETURN_EGL_EVAL(disp
, ret
);
2555 static EGLBoolean EGLAPIENTRY
2556 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2557 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2558 EGLint
*num_modifiers
)
2560 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2563 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2565 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
2567 ret
= disp
->Driver
->QueryDmaBufModifiersEXT(disp
, format
, max_modifiers
, modifiers
,
2568 external_only
, num_modifiers
);
2570 RETURN_EGL_EVAL(disp
, ret
);
2573 static void EGLAPIENTRY
2574 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2575 EGLGetBlobFuncANDROID get
)
2577 /* This function does not return anything so we cannot
2578 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2580 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2581 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2583 _eglUnlockDisplay(disp
);
2587 if (!_eglCheckDisplay(disp
, __func__
)) {
2589 _eglUnlockDisplay(disp
);
2594 _eglError(EGL_BAD_PARAMETER
,
2595 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2596 _eglUnlockDisplay(disp
);
2600 if (disp
->BlobCacheSet
) {
2601 _eglError(EGL_BAD_PARAMETER
,
2602 "eglSetBlobCacheFuncsANDROID: functions already set");
2603 _eglUnlockDisplay(disp
);
2607 disp
->BlobCacheSet
= set
;
2608 disp
->BlobCacheGet
= get
;
2610 disp
->Driver
->SetBlobCacheFuncsANDROID(disp
, set
, get
);
2612 _eglUnlockDisplay(disp
);
2615 static EGLBoolean EGLAPIENTRY
2616 eglQueryDeviceAttribEXT(EGLDeviceEXT device
,
2620 _EGLDevice
*dev
= _eglLookupDevice(device
);
2623 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2625 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, EGL_FALSE
);
2627 ret
= _eglQueryDeviceAttribEXT(dev
, attribute
, value
);
2628 RETURN_EGL_EVAL(NULL
, ret
);
2631 static const char * EGLAPIENTRY
2632 eglQueryDeviceStringEXT(EGLDeviceEXT device
,
2635 _EGLDevice
*dev
= _eglLookupDevice(device
);
2637 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2639 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, NULL
);
2641 RETURN_EGL_EVAL(NULL
, _eglQueryDeviceStringEXT(dev
, name
));
2644 static EGLBoolean EGLAPIENTRY
2645 eglQueryDevicesEXT(EGLint max_devices
,
2646 EGLDeviceEXT
*devices
,
2647 EGLint
*num_devices
)
2651 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2652 ret
= _eglQueryDevicesEXT(max_devices
, (_EGLDevice
**) devices
,
2654 RETURN_EGL_EVAL(NULL
, ret
);
2657 static EGLBoolean EGLAPIENTRY
2658 eglQueryDisplayAttribEXT(EGLDisplay dpy
,
2662 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2664 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2665 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
2667 switch (attribute
) {
2668 case EGL_DEVICE_EXT
:
2669 *value
= (EGLAttrib
) disp
->Device
;
2672 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
2674 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
2677 static char * EGLAPIENTRY
2678 eglGetDisplayDriverConfig(EGLDisplay dpy
)
2680 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2683 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2684 _EGL_CHECK_DISPLAY(disp
, NULL
);
2686 assert(disp
->Extensions
.MESA_query_driver
);
2688 ret
= disp
->Driver
->QueryDriverConfig(disp
);
2689 RETURN_EGL_EVAL(disp
, ret
);
2692 static const char * EGLAPIENTRY
2693 eglGetDisplayDriverName(EGLDisplay dpy
)
2695 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2698 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2699 _EGL_CHECK_DISPLAY(disp
, NULL
);
2701 assert(disp
->Extensions
.MESA_query_driver
);
2703 ret
= disp
->Driver
->QueryDriverName(disp
);
2704 RETURN_EGL_EVAL(disp
, ret
);
2707 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2708 eglGetProcAddress(const char *procname
)
2710 static const struct _egl_entrypoint egl_functions
[] = {
2711 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2712 #include "eglentrypoint.h"
2713 #undef EGL_ENTRYPOINT
2715 _EGLProc ret
= NULL
;
2718 RETURN_EGL_SUCCESS(NULL
, NULL
);
2720 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2722 if (strncmp(procname
, "egl", 3) == 0) {
2723 const struct _egl_entrypoint
*entrypoint
=
2725 egl_functions
, ARRAY_SIZE(egl_functions
),
2726 sizeof(egl_functions
[0]),
2727 _eglFunctionCompare
);
2729 ret
= entrypoint
->function
;
2732 if (!ret
&& _eglDriver
.GetProcAddress
)
2733 ret
= _eglDriver
.GetProcAddress(procname
);
2735 RETURN_EGL_SUCCESS(NULL
, ret
);
2739 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2740 _EGLDisplay
**disp
, _EGLContext
**ctx
)
2743 *disp
= _eglLockDisplay(dpy
);
2744 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2746 _eglUnlockDisplay(*disp
);
2747 return MESA_GLINTEROP_INVALID_DISPLAY
;
2750 *ctx
= _eglLookupContext(context
, *disp
);
2752 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2753 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2754 _eglUnlockDisplay(*disp
);
2755 return MESA_GLINTEROP_INVALID_CONTEXT
;
2758 return MESA_GLINTEROP_SUCCESS
;
2762 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2763 struct mesa_glinterop_device_info
*out
)
2769 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &ctx
);
2770 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2773 if (disp
->Driver
->GLInteropQueryDeviceInfo
)
2774 ret
= disp
->Driver
->GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2776 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2778 _eglUnlockDisplay(disp
);
2783 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2784 struct mesa_glinterop_export_in
*in
,
2785 struct mesa_glinterop_export_out
*out
)
2791 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &ctx
);
2792 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2795 if (disp
->Driver
->GLInteropExportObject
)
2796 ret
= disp
->Driver
->GLInteropExportObject(disp
, ctx
, in
, out
);
2798 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2800 _eglUnlockDisplay(disp
);