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
&& disp
->Driver
->SwapInterval
)
1291 ret
= disp
->Driver
->SwapInterval(disp
, surf
, interval
);
1296 surf
->SwapInterval
= interval
;
1298 RETURN_EGL_EVAL(disp
, ret
);
1302 EGLBoolean EGLAPIENTRY
1303 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1305 _EGLContext
*ctx
= _eglGetCurrentContext();
1306 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1307 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1310 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1311 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
1313 /* surface must be bound to current context in EGL 1.4 */
1314 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1315 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1316 surf
!= ctx
->DrawSurface
)
1317 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1320 if (surf
->Type
!= EGL_WINDOW_BIT
)
1321 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1323 /* From the EGL 1.5 spec:
1325 * If eglSwapBuffers is called and the native window associated with
1326 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1330 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1332 ret
= disp
->Driver
->SwapBuffers(disp
, surf
);
1334 /* EGL_KHR_partial_update
1335 * Frame boundary successfully reached,
1336 * reset damage region and reset BufferAgeRead
1339 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1340 surf
->BufferAgeRead
= EGL_FALSE
;
1343 RETURN_EGL_EVAL(disp
, ret
);
1348 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1349 const EGLint
*rects
, EGLint n_rects
)
1351 _EGLContext
*ctx
= _eglGetCurrentContext();
1354 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
1356 /* surface must be bound to current context in EGL 1.4 */
1357 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1358 surf
!= ctx
->DrawSurface
)
1359 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1361 if (surf
->Type
!= EGL_WINDOW_BIT
)
1362 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1364 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1365 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1367 ret
= disp
->Driver
->SwapBuffersWithDamageEXT(disp
, surf
, rects
, n_rects
);
1369 /* EGL_KHR_partial_update
1370 * Frame boundary successfully reached,
1371 * reset damage region and reset BufferAgeRead
1374 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1375 surf
->BufferAgeRead
= EGL_FALSE
;
1378 RETURN_EGL_EVAL(disp
, ret
);
1381 static EGLBoolean EGLAPIENTRY
1382 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1383 const EGLint
*rects
, EGLint n_rects
)
1385 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1386 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1387 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1388 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1391 static EGLBoolean EGLAPIENTRY
1392 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1393 const EGLint
*rects
, EGLint n_rects
)
1395 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1396 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1397 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1398 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1402 * Clamp the rectangles so that they lie within the surface.
1406 _eglSetDamageRegionKHRClampRects(_EGLSurface
* surf
,
1407 EGLint
*rects
, EGLint n_rects
)
1410 EGLint surf_height
= surf
->Height
;
1411 EGLint surf_width
= surf
->Width
;
1413 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1414 EGLint x1
, y1
, x2
, y2
;
1417 x2
= rects
[i
+ 2] + x1
;
1418 y2
= rects
[i
+ 3] + y1
;
1420 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1421 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1422 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1423 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1427 static EGLBoolean EGLAPIENTRY
1428 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1429 EGLint
*rects
, EGLint n_rects
)
1431 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1432 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1433 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1434 _EGLContext
*ctx
= _eglGetCurrentContext();
1436 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
1438 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1439 surf
->Type
!= EGL_WINDOW_BIT
||
1440 ctx
->DrawSurface
!= surf
||
1441 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1442 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1444 /* If the damage region is already set or
1445 * buffer age is not queried between
1446 * frame boundaries, throw bad access error
1449 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1450 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1452 _eglSetDamageRegionKHRClampRects(surf
, rects
, n_rects
);
1453 ret
= disp
->Driver
->SetDamageRegion(disp
, surf
, rects
, n_rects
);
1456 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1458 RETURN_EGL_EVAL(disp
, ret
);
1461 EGLBoolean EGLAPIENTRY
1462 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1464 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1465 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1467 void *native_pixmap_ptr
;
1469 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1470 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1471 native_pixmap_ptr
= (void*) target
;
1473 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
1474 ret
= disp
->Driver
->CopyBuffers(disp
, surf
, native_pixmap_ptr
);
1476 RETURN_EGL_EVAL(disp
, ret
);
1481 _eglWaitClientCommon(void)
1483 _EGLContext
*ctx
= _eglGetCurrentContext();
1488 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1490 disp
= ctx
->Resource
.Display
;
1491 mtx_lock(&disp
->Mutex
);
1493 /* let bad current context imply bad current surface */
1494 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1495 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1496 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1498 /* a valid current context implies an initialized current display */
1499 assert(disp
->Initialized
);
1500 ret
= disp
->Driver
->WaitClient(disp
, ctx
);
1502 RETURN_EGL_EVAL(disp
, ret
);
1505 EGLBoolean EGLAPIENTRY
1508 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1509 return _eglWaitClientCommon();
1512 EGLBoolean EGLAPIENTRY
1515 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1516 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1517 return _eglWaitClientCommon();
1521 EGLBoolean EGLAPIENTRY
1522 eglWaitNative(EGLint engine
)
1524 _EGLContext
*ctx
= _eglGetCurrentContext();
1529 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1531 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1533 disp
= ctx
->Resource
.Display
;
1534 mtx_lock(&disp
->Mutex
);
1536 /* let bad current context imply bad current surface */
1537 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1538 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1539 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1541 /* a valid current context implies an initialized current display */
1542 assert(disp
->Initialized
);
1543 ret
= disp
->Driver
->WaitNative(engine
);
1545 RETURN_EGL_EVAL(disp
, ret
);
1549 EGLDisplay EGLAPIENTRY
1550 eglGetCurrentDisplay(void)
1552 _EGLContext
*ctx
= _eglGetCurrentContext();
1555 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1557 RETURN_EGL_SUCCESS(NULL
, ret
);
1561 EGLContext EGLAPIENTRY
1562 eglGetCurrentContext(void)
1564 _EGLContext
*ctx
= _eglGetCurrentContext();
1567 ret
= _eglGetContextHandle(ctx
);
1569 RETURN_EGL_SUCCESS(NULL
, ret
);
1573 EGLSurface EGLAPIENTRY
1574 eglGetCurrentSurface(EGLint readdraw
)
1576 _EGLContext
*ctx
= _eglGetCurrentContext();
1577 EGLint err
= EGL_SUCCESS
;
1581 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1584 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1588 surf
= ctx
->DrawSurface
;
1591 surf
= ctx
->ReadSurface
;
1595 err
= EGL_BAD_PARAMETER
;
1599 ret
= _eglGetSurfaceHandle(surf
);
1601 RETURN_EGL_ERROR(NULL
, err
, ret
);
1608 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1609 EGLint e
= t
->LastError
;
1610 if (!_eglIsCurrentThreadDummy())
1611 t
->LastError
= EGL_SUCCESS
;
1621 * Specify the client API to use for subsequent calls including:
1622 * eglCreateContext()
1623 * eglGetCurrentContext()
1624 * eglGetCurrentDisplay()
1625 * eglGetCurrentSurface()
1626 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1629 * See section 3.7 "Rendering Context" in the EGL specification for details.
1631 EGLBoolean EGLAPIENTRY
1632 eglBindAPI(EGLenum api
)
1636 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1638 t
= _eglGetCurrentThread();
1639 if (_eglIsCurrentThreadDummy())
1640 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1642 if (!_eglIsApiValid(api
))
1643 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1645 t
->CurrentAPI
= api
;
1647 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1652 * Return the last value set with eglBindAPI().
1657 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1660 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1661 ret
= t
->CurrentAPI
;
1663 RETURN_EGL_SUCCESS(NULL
, ret
);
1667 EGLSurface EGLAPIENTRY
1668 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1669 EGLClientBuffer buffer
, EGLConfig config
,
1670 const EGLint
*attrib_list
)
1672 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1673 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1675 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1677 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
);
1679 /* OpenVG is not supported */
1680 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1684 EGLBoolean EGLAPIENTRY
1685 eglReleaseThread(void)
1687 /* unbind current contexts */
1688 if (!_eglIsCurrentThreadDummy()) {
1689 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1690 _EGLContext
*ctx
= t
->CurrentContext
;
1692 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1695 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1697 mtx_lock(&disp
->Mutex
);
1698 (void) disp
->Driver
->MakeCurrent(disp
, NULL
, NULL
, NULL
);
1699 mtx_unlock(&disp
->Mutex
);
1703 _eglDestroyCurrentThread();
1705 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1710 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1711 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1713 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1717 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
);
1718 if (!disp
->Extensions
.KHR_image_base
)
1719 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1720 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1721 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1722 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1723 * <ctx> must be EGL_NO_CONTEXT..."
1725 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1726 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1728 img
= disp
->Driver
->CreateImageKHR(disp
, context
, target
, buffer
, attr_list
);
1729 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1731 RETURN_EGL_EVAL(disp
, ret
);
1734 static EGLImage EGLAPIENTRY
1735 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1736 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1738 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1739 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1740 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1744 EGLImage EGLAPIENTRY
1745 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1746 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1748 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1750 EGLint
*int_attribs
;
1752 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1754 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1755 if (attr_list
&& !int_attribs
)
1756 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1758 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1765 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1769 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
1770 if (!disp
->Extensions
.KHR_image_base
)
1771 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1773 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1775 _eglUnlinkImage(img
);
1776 ret
= disp
->Driver
->DestroyImageKHR(disp
, img
);
1778 RETURN_EGL_EVAL(disp
, ret
);
1781 EGLBoolean EGLAPIENTRY
1782 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1784 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1785 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1786 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1787 return _eglDestroyImageCommon(disp
, img
);
1790 static EGLBoolean EGLAPIENTRY
1791 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1793 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1794 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1795 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1796 return _eglDestroyImageCommon(disp
, img
);
1801 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1802 EGLBoolean orig_is_EGLAttrib
,
1803 EGLenum invalid_type_error
)
1805 _EGLContext
*ctx
= _eglGetCurrentContext();
1809 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
);
1811 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1812 /* There exist two EGLAttrib variants of eglCreateSync*:
1813 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1814 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1815 * support as a proxy for EGL 1.5 support, even though that's not
1816 * entirely correct (though _eglComputeVersion does the same).
1818 * The EGL spec provides no guidance on how to handle unsupported
1819 * functions. EGL_BAD_MATCH seems reasonable.
1821 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1824 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1825 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1826 * error is generated.
1829 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1830 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1832 /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */
1833 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1834 (ctx
->ClientAPI
!= EGL_OPENGL_ES_API
&&
1835 ctx
->ClientAPI
!= EGL_OPENGL_API
)))
1836 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1839 case EGL_SYNC_FENCE_KHR
:
1840 if (!disp
->Extensions
.KHR_fence_sync
)
1841 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1843 case EGL_SYNC_REUSABLE_KHR
:
1844 if (!disp
->Extensions
.KHR_reusable_sync
)
1845 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1847 case EGL_SYNC_CL_EVENT_KHR
:
1848 if (!disp
->Extensions
.KHR_cl_event2
)
1849 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1851 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1852 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1853 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1856 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1859 sync
= disp
->Driver
->CreateSyncKHR(disp
, type
, attrib_list
);
1860 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1862 RETURN_EGL_EVAL(disp
, ret
);
1866 static EGLSync EGLAPIENTRY
1867 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1869 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1870 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1873 EGLAttrib
*attrib_list
;
1876 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1877 attrib_list
= (EGLAttrib
*) int_list
;
1879 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1880 if (err
!= EGL_SUCCESS
)
1881 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1884 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1887 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1890 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1895 static EGLSync EGLAPIENTRY
1896 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1898 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1899 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1900 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1906 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1908 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1909 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1910 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1916 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1920 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
);
1921 assert(disp
->Extensions
.KHR_reusable_sync
||
1922 disp
->Extensions
.KHR_fence_sync
||
1923 disp
->Extensions
.ANDROID_native_fence_sync
);
1926 ret
= disp
->Driver
->DestroySyncKHR(disp
, s
);
1928 RETURN_EGL_EVAL(disp
, ret
);
1931 EGLBoolean EGLAPIENTRY
1932 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1934 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1935 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1936 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1937 return _eglDestroySync(disp
, s
);
1940 static EGLBoolean EGLAPIENTRY
1941 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1943 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1944 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1945 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1946 return _eglDestroySync(disp
, s
);
1951 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1952 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1956 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
);
1957 assert(disp
->Extensions
.KHR_reusable_sync
||
1958 disp
->Extensions
.KHR_fence_sync
||
1959 disp
->Extensions
.ANDROID_native_fence_sync
);
1961 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1962 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1964 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1965 * unlocked here to allow other threads also to be able to
1966 * go into waiting state.
1969 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1970 _eglUnlockDisplay(dpy
);
1972 ret
= disp
->Driver
->ClientWaitSyncKHR(disp
, s
, flags
, timeout
);
1975 * 'disp' is already unlocked for reusable sync type,
1976 * so passing 'NULL' to bypass unlocking display.
1978 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1979 RETURN_EGL_EVAL(NULL
, ret
);
1981 RETURN_EGL_EVAL(disp
, ret
);
1985 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
1986 EGLint flags
, EGLTime timeout
)
1988 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1989 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1990 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1991 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1994 static EGLint EGLAPIENTRY
1995 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
1996 EGLint flags
, EGLTime timeout
)
1998 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1999 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2000 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2001 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2006 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
2008 _EGLContext
*ctx
= _eglGetCurrentContext();
2011 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
);
2012 assert(disp
->Extensions
.KHR_wait_sync
);
2014 /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */
2015 if (ctx
== EGL_NO_CONTEXT
||
2016 (ctx
->ClientAPI
!= EGL_OPENGL_ES_API
&&
2017 ctx
->ClientAPI
!= EGL_OPENGL_API
))
2018 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
2020 /* the API doesn't allow any flags yet */
2022 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2024 ret
= disp
->Driver
->WaitSyncKHR(disp
, s
);
2026 RETURN_EGL_EVAL(disp
, ret
);
2029 static EGLint EGLAPIENTRY
2030 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2032 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2033 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2034 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2035 return _eglWaitSyncCommon(disp
, s
, flags
);
2039 EGLBoolean EGLAPIENTRY
2040 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2042 /* The KHR version returns EGLint, while the core version returns
2043 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2046 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2047 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2048 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2049 return _eglWaitSyncCommon(disp
, s
, flags
);
2053 static EGLBoolean EGLAPIENTRY
2054 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2056 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2057 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2060 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2062 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
);
2063 assert(disp
->Extensions
.KHR_reusable_sync
);
2064 ret
= disp
->Driver
->SignalSyncKHR(disp
, s
, mode
);
2066 RETURN_EGL_EVAL(disp
, ret
);
2071 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2075 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
);
2076 assert(disp
->Extensions
.KHR_reusable_sync
||
2077 disp
->Extensions
.KHR_fence_sync
||
2078 disp
->Extensions
.ANDROID_native_fence_sync
);
2080 ret
= _eglGetSyncAttrib(disp
, s
, attribute
, value
);
2082 RETURN_EGL_EVAL(disp
, ret
);
2085 EGLBoolean EGLAPIENTRY
2086 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2088 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2089 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2090 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2093 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2095 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2099 static EGLBoolean EGLAPIENTRY
2100 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2102 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2103 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2107 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2110 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2113 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2115 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2117 * If any error occurs, <*value> is not modified.
2119 if (result
== EGL_FALSE
)
2126 static EGLint EGLAPIENTRY
2127 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2129 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2130 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2133 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2135 /* the spec doesn't seem to specify what happens if the fence
2136 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2139 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2140 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2142 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2143 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2144 ret
= disp
->Driver
->DupNativeFenceFDANDROID(disp
, s
);
2146 RETURN_EGL_EVAL(disp
, ret
);
2149 static EGLBoolean EGLAPIENTRY
2150 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2151 EGLint numRects
, const EGLint
*rects
)
2153 _EGLContext
*ctx
= _eglGetCurrentContext();
2154 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2155 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2158 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2160 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
2162 if (!disp
->Extensions
.NOK_swap_region
)
2163 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2165 /* surface must be bound to current context in EGL 1.4 */
2166 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2167 surf
!= ctx
->DrawSurface
)
2168 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2170 ret
= disp
->Driver
->SwapBuffersRegionNOK(disp
, surf
, numRects
, rects
);
2172 RETURN_EGL_EVAL(disp
, ret
);
2176 static EGLImage EGLAPIENTRY
2177 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2179 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2183 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2185 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
);
2186 if (!disp
->Extensions
.MESA_drm_image
)
2187 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2189 img
= disp
->Driver
->CreateDRMImageMESA(disp
, attr_list
);
2190 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2192 RETURN_EGL_EVAL(disp
, ret
);
2195 static EGLBoolean EGLAPIENTRY
2196 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2197 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2199 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2200 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2203 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2205 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
2206 assert(disp
->Extensions
.MESA_drm_image
);
2209 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2211 ret
= disp
->Driver
->ExportDRMImageMESA(disp
, img
, name
, handle
, stride
);
2213 RETURN_EGL_EVAL(disp
, ret
);
2219 static EGLBoolean EGLAPIENTRY
2220 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2222 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2225 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2227 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
2228 assert(disp
->Extensions
.WL_bind_wayland_display
);
2231 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2233 ret
= disp
->Driver
->BindWaylandDisplayWL(disp
, display
);
2235 RETURN_EGL_EVAL(disp
, ret
);
2238 static EGLBoolean EGLAPIENTRY
2239 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2241 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2244 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2246 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
2247 assert(disp
->Extensions
.WL_bind_wayland_display
);
2250 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2252 ret
= disp
->Driver
->UnbindWaylandDisplayWL(disp
, display
);
2254 RETURN_EGL_EVAL(disp
, ret
);
2257 static EGLBoolean EGLAPIENTRY
2258 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2259 EGLint attribute
, EGLint
*value
)
2261 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2264 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2266 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
2267 assert(disp
->Extensions
.WL_bind_wayland_display
);
2270 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2272 ret
= disp
->Driver
->QueryWaylandBufferWL(disp
, buffer
, attribute
, value
);
2274 RETURN_EGL_EVAL(disp
, ret
);
2278 static struct wl_buffer
* EGLAPIENTRY
2279 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2281 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2283 struct wl_buffer
*ret
;
2285 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2287 _EGL_CHECK_DISPLAY(disp
, NULL
);
2288 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2289 RETURN_EGL_EVAL(disp
, NULL
);
2291 img
= _eglLookupImage(image
, disp
);
2294 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2296 ret
= disp
->Driver
->CreateWaylandBufferFromImageWL(disp
, img
);
2298 RETURN_EGL_EVAL(disp
, ret
);
2301 static EGLBoolean EGLAPIENTRY
2302 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2303 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2305 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2306 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2309 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2311 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
2313 if (!disp
->Extensions
.NV_post_sub_buffer
)
2314 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2316 ret
= disp
->Driver
->PostSubBufferNV(disp
, surf
, x
, y
, width
, height
);
2318 RETURN_EGL_EVAL(disp
, ret
);
2321 static EGLBoolean EGLAPIENTRY
2322 eglGetSyncValuesCHROMIUM(EGLDisplay dpy
, EGLSurface surface
,
2323 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2326 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2327 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2330 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2332 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
2333 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2334 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2336 if (!ust
|| !msc
|| !sbc
)
2337 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2339 ret
= disp
->Driver
->GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2341 RETURN_EGL_EVAL(disp
, ret
);
2344 static EGLBoolean EGLAPIENTRY
2345 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2346 EGLint
*fourcc
, EGLint
*nplanes
,
2347 EGLuint64KHR
*modifiers
)
2349 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2350 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2353 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2355 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
2356 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2359 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2361 ret
= disp
->Driver
->ExportDMABUFImageQueryMESA(disp
, img
, fourcc
, nplanes
, modifiers
);
2363 RETURN_EGL_EVAL(disp
, ret
);
2366 static EGLBoolean EGLAPIENTRY
2367 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2368 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2370 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2371 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2374 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2376 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
2377 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2380 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2382 ret
= disp
->Driver
->ExportDMABUFImageMESA(disp
, img
, fds
, strides
, offsets
);
2384 RETURN_EGL_EVAL(disp
, ret
);
2387 static EGLint EGLAPIENTRY
2388 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2391 _EGLDisplay
*disp
= NULL
;
2392 _EGLResourceType type
;
2394 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2396 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2397 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2399 if (!_eglIsCurrentThreadDummy()) {
2404 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2407 disp
= _eglLockDisplay(dpy
);
2409 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2411 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2412 if (dpy
!= (EGLDisplay
) object
)
2413 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2415 disp
->Label
= label
;
2416 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2419 switch (objectType
) {
2420 case EGL_OBJECT_CONTEXT_KHR
:
2421 type
= _EGL_RESOURCE_CONTEXT
;
2423 case EGL_OBJECT_SURFACE_KHR
:
2424 type
= _EGL_RESOURCE_SURFACE
;
2426 case EGL_OBJECT_IMAGE_KHR
:
2427 type
= _EGL_RESOURCE_IMAGE
;
2429 case EGL_OBJECT_SYNC_KHR
:
2430 type
= _EGL_RESOURCE_SYNC
;
2432 case EGL_OBJECT_STREAM_KHR
:
2434 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2437 if (_eglCheckResource(object
, type
, disp
)) {
2438 _EGLResource
*res
= (_EGLResource
*) object
;
2441 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2444 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2447 static EGLint EGLAPIENTRY
2448 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2449 const EGLAttrib
*attrib_list
)
2451 unsigned int newEnabled
;
2453 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2455 mtx_lock(_eglGlobal
.Mutex
);
2457 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2458 if (attrib_list
!= NULL
) {
2461 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2462 switch (attrib_list
[i
]) {
2463 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2464 case EGL_DEBUG_MSG_ERROR_KHR
:
2465 case EGL_DEBUG_MSG_WARN_KHR
:
2466 case EGL_DEBUG_MSG_INFO_KHR
:
2467 if (attrib_list
[i
+ 1])
2468 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2470 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2473 // On error, set the last error code, call the current
2474 // debug callback, and return the error code.
2475 mtx_unlock(_eglGlobal
.Mutex
);
2476 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2477 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2478 return EGL_BAD_ATTRIBUTE
;
2483 if (callback
!= NULL
) {
2484 _eglGlobal
.debugCallback
= callback
;
2485 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2487 _eglGlobal
.debugCallback
= NULL
;
2488 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2491 mtx_unlock(_eglGlobal
.Mutex
);
2495 static EGLBoolean EGLAPIENTRY
2496 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2498 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2500 mtx_lock(_eglGlobal
.Mutex
);
2502 switch (attribute
) {
2503 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2504 case EGL_DEBUG_MSG_ERROR_KHR
:
2505 case EGL_DEBUG_MSG_WARN_KHR
:
2506 case EGL_DEBUG_MSG_INFO_KHR
:
2507 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2512 case EGL_DEBUG_CALLBACK_KHR
:
2513 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2516 mtx_unlock(_eglGlobal
.Mutex
);
2517 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2518 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2522 mtx_unlock(_eglGlobal
.Mutex
);
2527 _eglFunctionCompare(const void *key
, const void *elem
)
2529 const char *procname
= key
;
2530 const struct _egl_entrypoint
*entrypoint
= elem
;
2531 return strcmp(procname
, entrypoint
->name
);
2534 static EGLBoolean EGLAPIENTRY
2535 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2536 EGLint
*formats
, EGLint
*num_formats
)
2538 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2541 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2543 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
2545 ret
= disp
->Driver
->QueryDmaBufFormatsEXT(disp
, max_formats
, formats
, num_formats
);
2547 RETURN_EGL_EVAL(disp
, ret
);
2550 static EGLBoolean EGLAPIENTRY
2551 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2552 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2553 EGLint
*num_modifiers
)
2555 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2558 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2560 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
2562 ret
= disp
->Driver
->QueryDmaBufModifiersEXT(disp
, format
, max_modifiers
, modifiers
,
2563 external_only
, num_modifiers
);
2565 RETURN_EGL_EVAL(disp
, ret
);
2568 static void EGLAPIENTRY
2569 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2570 EGLGetBlobFuncANDROID get
)
2572 /* This function does not return anything so we cannot
2573 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2575 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2576 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2578 _eglUnlockDisplay(disp
);
2582 if (!_eglCheckDisplay(disp
, __func__
)) {
2584 _eglUnlockDisplay(disp
);
2589 _eglError(EGL_BAD_PARAMETER
,
2590 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2591 _eglUnlockDisplay(disp
);
2595 if (disp
->BlobCacheSet
) {
2596 _eglError(EGL_BAD_PARAMETER
,
2597 "eglSetBlobCacheFuncsANDROID: functions already set");
2598 _eglUnlockDisplay(disp
);
2602 disp
->BlobCacheSet
= set
;
2603 disp
->BlobCacheGet
= get
;
2605 disp
->Driver
->SetBlobCacheFuncsANDROID(disp
, set
, get
);
2607 _eglUnlockDisplay(disp
);
2610 static EGLBoolean EGLAPIENTRY
2611 eglQueryDeviceAttribEXT(EGLDeviceEXT device
,
2615 _EGLDevice
*dev
= _eglLookupDevice(device
);
2618 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2620 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, EGL_FALSE
);
2622 ret
= _eglQueryDeviceAttribEXT(dev
, attribute
, value
);
2623 RETURN_EGL_EVAL(NULL
, ret
);
2626 static const char * EGLAPIENTRY
2627 eglQueryDeviceStringEXT(EGLDeviceEXT device
,
2630 _EGLDevice
*dev
= _eglLookupDevice(device
);
2632 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2634 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, NULL
);
2636 RETURN_EGL_EVAL(NULL
, _eglQueryDeviceStringEXT(dev
, name
));
2639 static EGLBoolean EGLAPIENTRY
2640 eglQueryDevicesEXT(EGLint max_devices
,
2641 EGLDeviceEXT
*devices
,
2642 EGLint
*num_devices
)
2646 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2647 ret
= _eglQueryDevicesEXT(max_devices
, (_EGLDevice
**) devices
,
2649 RETURN_EGL_EVAL(NULL
, ret
);
2652 static EGLBoolean EGLAPIENTRY
2653 eglQueryDisplayAttribEXT(EGLDisplay dpy
,
2657 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2659 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2660 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
2662 switch (attribute
) {
2663 case EGL_DEVICE_EXT
:
2664 *value
= (EGLAttrib
) disp
->Device
;
2667 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
2669 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
2672 static char * EGLAPIENTRY
2673 eglGetDisplayDriverConfig(EGLDisplay dpy
)
2675 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2678 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2679 _EGL_CHECK_DISPLAY(disp
, NULL
);
2681 assert(disp
->Extensions
.MESA_query_driver
);
2683 ret
= disp
->Driver
->QueryDriverConfig(disp
);
2684 RETURN_EGL_EVAL(disp
, ret
);
2687 static const char * EGLAPIENTRY
2688 eglGetDisplayDriverName(EGLDisplay dpy
)
2690 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2693 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2694 _EGL_CHECK_DISPLAY(disp
, NULL
);
2696 assert(disp
->Extensions
.MESA_query_driver
);
2698 ret
= disp
->Driver
->QueryDriverName(disp
);
2699 RETURN_EGL_EVAL(disp
, ret
);
2702 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2703 eglGetProcAddress(const char *procname
)
2705 static const struct _egl_entrypoint egl_functions
[] = {
2706 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2707 #include "eglentrypoint.h"
2708 #undef EGL_ENTRYPOINT
2710 _EGLProc ret
= NULL
;
2713 RETURN_EGL_SUCCESS(NULL
, NULL
);
2715 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2717 if (strncmp(procname
, "egl", 3) == 0) {
2718 const struct _egl_entrypoint
*entrypoint
=
2720 egl_functions
, ARRAY_SIZE(egl_functions
),
2721 sizeof(egl_functions
[0]),
2722 _eglFunctionCompare
);
2724 ret
= entrypoint
->function
;
2727 if (!ret
&& _eglDriver
.GetProcAddress
)
2728 ret
= _eglDriver
.GetProcAddress(procname
);
2730 RETURN_EGL_SUCCESS(NULL
, ret
);
2734 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2735 _EGLDisplay
**disp
, _EGLContext
**ctx
)
2738 *disp
= _eglLockDisplay(dpy
);
2739 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2741 _eglUnlockDisplay(*disp
);
2742 return MESA_GLINTEROP_INVALID_DISPLAY
;
2745 *ctx
= _eglLookupContext(context
, *disp
);
2747 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2748 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2749 _eglUnlockDisplay(*disp
);
2750 return MESA_GLINTEROP_INVALID_CONTEXT
;
2753 return MESA_GLINTEROP_SUCCESS
;
2757 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2758 struct mesa_glinterop_device_info
*out
)
2764 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &ctx
);
2765 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2768 if (disp
->Driver
->GLInteropQueryDeviceInfo
)
2769 ret
= disp
->Driver
->GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2771 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2773 _eglUnlockDisplay(disp
);
2778 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2779 struct mesa_glinterop_export_in
*in
,
2780 struct mesa_glinterop_export_out
*out
)
2786 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &ctx
);
2787 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2790 if (disp
->Driver
->GLInteropExportObject
)
2791 ret
= disp
->Driver
->GLInteropExportObject(disp
, ctx
, in
, out
);
2793 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2795 _eglUnlockDisplay(disp
);