1 /**************************************************************************
3 * Copyright 2008 VMware, Inc.
4 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5 * Copyright 2010-2011 LunarG, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
32 * Public EGL API entrypoints
34 * Generally, we use the EGLDisplay parameter as a key to lookup the
35 * appropriate device driver handle, then jump though the driver's
36 * dispatch table to handle the function.
38 * That allows us the option of supporting multiple, simultaneous,
39 * heterogeneous hardware devices in the future.
41 * The EGLDisplay, EGLConfig, EGLContext and EGLSurface types are
42 * opaque handles. Internal objects are linked to a display to
45 * For each public API entry point, the opaque handles are looked up
46 * before being dispatched to the drivers. When it fails to look up
56 * is generated and the driver function is not called. An
57 * uninitialized EGLDisplay has no driver associated with it. When
58 * such display is detected,
64 * Some of the entry points use current display, context, or surface
65 * implicitly. For such entry points, the implicit objects are also
66 * checked before calling the driver function. Other than the
67 * errors listed above,
69 * EGL_BAD_CURRENT_SURFACE
71 * may also be generated.
73 * Notes on naming conventions:
75 * eglFooBar - public EGL function
76 * EGL_FOO_BAR - public EGL token
77 * EGLDatatype - public EGL datatype
79 * _eglFooBar - private EGL function
80 * _EGLDatatype - private EGL datatype, typedef'd struct
81 * _egl_struct - private EGL struct, non-typedef'd
89 #include "c99_compat.h"
90 #include "c11/threads.h"
91 #include "util/macros.h"
93 #include "eglglobals.h"
94 #include "eglcontext.h"
95 #include "egldisplay.h"
96 #include "egltypedefs.h"
97 #include "eglcurrent.h"
98 #include "egldriver.h"
99 #include "eglsurface.h"
100 #include "eglconfig.h"
101 #include "eglimage.h"
104 #include "GL/mesa_glinterop.h"
107 * Macros to help return an API entrypoint.
109 * These macros will unlock the display and record the error code.
111 #define RETURN_EGL_ERROR(disp, err, ret) \
114 _eglUnlockDisplay(disp); \
115 /* EGL error codes are non-zero */ \
117 _eglError(err, __func__); \
121 #define RETURN_EGL_SUCCESS(disp, ret) \
122 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
124 /* record EGL_SUCCESS only when ret evaluates to true */
125 #define RETURN_EGL_EVAL(disp, ret) \
126 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
130 * A bunch of macros and checks to simplify error checking.
133 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
135 drv = _eglCheckDisplay(disp, __func__); \
137 RETURN_EGL_ERROR(disp, 0, ret); \
140 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
142 drv = _eglCheck ## type(disp, obj, __func__); \
144 RETURN_EGL_ERROR(disp, 0, ret); \
147 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
148 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
150 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
151 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
153 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
154 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
156 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
157 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
160 struct _egl_entrypoint
{
166 static inline _EGLDriver
*
167 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
170 _eglError(EGL_BAD_DISPLAY
, msg
);
173 if (!disp
->Initialized
) {
174 _eglError(EGL_NOT_INITIALIZED
, msg
);
181 static inline _EGLDriver
*
182 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
184 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
188 _eglError(EGL_BAD_SURFACE
, msg
);
195 static inline _EGLDriver
*
196 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
198 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
202 _eglError(EGL_BAD_CONTEXT
, msg
);
209 static inline _EGLDriver
*
210 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
212 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
216 _eglError(EGL_BAD_CONFIG
, msg
);
223 static inline _EGLDriver
*
224 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
226 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
230 _eglError(EGL_BAD_PARAMETER
, msg
);
238 * Lookup and lock a display.
240 static inline _EGLDisplay
*
241 _eglLockDisplay(EGLDisplay display
)
243 _EGLDisplay
*dpy
= _eglLookupDisplay(display
);
245 mtx_lock(&dpy
->Mutex
);
254 _eglUnlockDisplay(_EGLDisplay
*dpy
)
256 mtx_unlock(&dpy
->Mutex
);
260 _eglSetFuncName(const char *funcName
, _EGLDisplay
*disp
, EGLenum objectType
, _EGLResource
*object
)
262 _EGLThreadInfo
*thr
= _eglGetCurrentThread();
263 if (!_eglIsCurrentThreadDummy()) {
264 thr
->CurrentFuncName
= funcName
;
265 thr
->CurrentObjectLabel
= NULL
;
267 if (objectType
== EGL_OBJECT_THREAD_KHR
)
268 thr
->CurrentObjectLabel
= thr
->Label
;
269 else if (objectType
== EGL_OBJECT_DISPLAY_KHR
&& disp
)
270 thr
->CurrentObjectLabel
= disp
->Label
;
272 thr
->CurrentObjectLabel
= object
->Label
;
277 _eglDebugReport(EGL_BAD_ALLOC
, funcName
, EGL_DEBUG_MSG_CRITICAL_KHR
, NULL
);
281 #define _EGL_FUNC_START(disp, objectType, object, ret) \
283 if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \
285 _eglUnlockDisplay(disp); \
291 * Convert an attribute list from EGLint[] to EGLAttrib[].
293 * Return an EGL error code. The output parameter out_attrib_list is modified
297 _eglConvertIntsToAttribs(const EGLint
*int_list
, EGLAttrib
**out_attrib_list
)
300 EGLAttrib
*attrib_list
;
303 while (int_list
[2*len
] != EGL_NONE
)
308 *out_attrib_list
= NULL
;
312 if (2*len
+ 1 > SIZE_MAX
/ sizeof(EGLAttrib
))
313 return EGL_BAD_ALLOC
;
315 attrib_list
= malloc((2*len
+ 1) * sizeof(EGLAttrib
));
317 return EGL_BAD_ALLOC
;
319 for (size_t i
= 0; i
< len
; ++i
) {
320 attrib_list
[2*i
+ 0] = int_list
[2*i
+ 0];
321 attrib_list
[2*i
+ 1] = int_list
[2*i
+ 1];
324 attrib_list
[2*len
] = EGL_NONE
;
326 *out_attrib_list
= attrib_list
;
332 _eglConvertAttribsToInt(const EGLAttrib
*attr_list
)
334 EGLint
*int_attribs
= NULL
;
336 /* Convert attributes from EGLAttrib[] to EGLint[] */
340 while (attr_list
[size
] != EGL_NONE
)
343 size
+= 1; /* add space for EGL_NONE */
345 int_attribs
= calloc(size
, sizeof(int_attribs
[0]));
349 for (i
= 0; i
< size
; i
++)
350 int_attribs
[i
] = attr_list
[i
];
357 * This is typically the first EGL function that an application calls.
358 * It associates a private _EGLDisplay object to the native display.
360 EGLDisplay EGLAPIENTRY
361 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
363 _EGLPlatformType plat
;
365 void *native_display_ptr
;
367 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
369 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
370 native_display_ptr
= (void*) nativeDisplay
;
372 plat
= _eglGetNativePlatform(native_display_ptr
);
373 dpy
= _eglFindDisplay(plat
, native_display_ptr
);
374 return _eglGetDisplayHandle(dpy
);
378 _eglGetPlatformDisplayCommon(EGLenum platform
, void *native_display
,
379 const EGLAttrib
*attrib_list
)
384 #ifdef HAVE_X11_PLATFORM
385 case EGL_PLATFORM_X11_EXT
:
386 dpy
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
389 #ifdef HAVE_DRM_PLATFORM
390 case EGL_PLATFORM_GBM_MESA
:
391 dpy
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
395 #ifdef HAVE_WAYLAND_PLATFORM
396 case EGL_PLATFORM_WAYLAND_EXT
:
397 dpy
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
401 #ifdef HAVE_SURFACELESS_PLATFORM
402 case EGL_PLATFORM_SURFACELESS_MESA
:
403 dpy
= _eglGetSurfacelessDisplay(native_display
, attrib_list
);
407 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
410 return _eglGetDisplayHandle(dpy
);
413 static EGLDisplay EGLAPIENTRY
414 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
415 const EGLint
*int_attribs
)
417 EGLAttrib
*attrib_list
;
420 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
422 if (_eglConvertIntsToAttribs(int_attribs
, &attrib_list
) != EGL_SUCCESS
)
423 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
425 display
= _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
430 EGLDisplay EGLAPIENTRY
431 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
432 const EGLAttrib
*attrib_list
)
434 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
435 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
439 * Copy the extension into the string and update the string pointer.
442 _eglAppendExtension(char **str
, const char *ext
)
445 size_t len
= strlen(ext
);
462 * Examine the individual extension enable/disable flags and recompute
463 * the driver's Extensions string.
466 _eglCreateExtensionsString(_EGLDisplay
*dpy
)
468 #define _EGL_CHECK_EXTENSION(ext) \
470 if (dpy->Extensions.ext) { \
471 _eglAppendExtension(&exts, "EGL_" #ext); \
472 assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
476 char *exts
= dpy
->ExtensionsString
;
478 /* Please keep these sorted alphabetically. */
479 _EGL_CHECK_EXTENSION(ANDROID_blob_cache
);
480 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
481 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
482 _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync
);
483 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
485 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
487 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
488 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
489 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
490 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers
);
491 _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata
);
492 _EGL_CHECK_EXTENSION(EXT_surface_SMPTE2086_metadata
);
493 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
495 _EGL_CHECK_EXTENSION(IMG_context_priority
);
497 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
498 _EGL_CHECK_EXTENSION(KHR_config_attribs
);
499 _EGL_CHECK_EXTENSION(KHR_context_flush_control
);
500 _EGL_CHECK_EXTENSION(KHR_create_context
);
501 _EGL_CHECK_EXTENSION(KHR_create_context_no_error
);
502 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
503 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
504 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
505 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
506 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
507 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
508 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
509 if (dpy
->Extensions
.KHR_image_base
&& dpy
->Extensions
.KHR_image_pixmap
)
510 dpy
->Extensions
.KHR_image
= EGL_TRUE
;
511 _EGL_CHECK_EXTENSION(KHR_image
);
512 _EGL_CHECK_EXTENSION(KHR_image_base
);
513 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
514 _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer
);
515 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
516 _EGL_CHECK_EXTENSION(KHR_partial_update
);
517 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
518 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
519 if (dpy
->Extensions
.EXT_swap_buffers_with_damage
)
520 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
521 _EGL_CHECK_EXTENSION(EXT_pixel_format_float
);
522 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
524 if (dpy
->Extensions
.KHR_no_config_context
)
525 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
526 _EGL_CHECK_EXTENSION(MESA_drm_image
);
527 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
529 _EGL_CHECK_EXTENSION(NOK_swap_region
);
530 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
532 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
534 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
535 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
537 #undef _EGL_CHECK_EXTENSION
541 _eglCreateAPIsString(_EGLDisplay
*dpy
)
543 #define addstr(str) \
545 const size_t old_len = strlen(dpy->ClientAPIsString); \
546 const size_t add_len = sizeof(str); \
547 const size_t max_len = sizeof(dpy->ClientAPIsString) - 1; \
548 if (old_len + add_len <= max_len) \
549 strcat(dpy->ClientAPIsString, str " "); \
551 assert(!"dpy->ClientAPIsString is not large enough"); \
554 if (dpy
->ClientAPIs
& EGL_OPENGL_BIT
)
557 if (dpy
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
558 dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
559 dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
563 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
570 _eglComputeVersion(_EGLDisplay
*disp
)
574 if (disp
->Extensions
.KHR_fence_sync
&&
575 disp
->Extensions
.KHR_cl_event2
&&
576 disp
->Extensions
.KHR_wait_sync
&&
577 disp
->Extensions
.KHR_image_base
&&
578 disp
->Extensions
.KHR_gl_texture_2D_image
&&
579 disp
->Extensions
.KHR_gl_texture_3D_image
&&
580 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
581 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
582 disp
->Extensions
.KHR_create_context
&&
583 disp
->Extensions
.EXT_create_context_robustness
&&
584 disp
->Extensions
.KHR_get_all_proc_addresses
&&
585 disp
->Extensions
.KHR_gl_colorspace
&&
586 disp
->Extensions
.KHR_surfaceless_context
)
591 * This is typically the second EGL function that an application calls.
592 * Here we load/initialize the actual hardware driver.
594 EGLBoolean EGLAPIENTRY
595 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
597 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
599 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
602 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
604 if (!disp
->Initialized
) {
605 if (!_eglMatchDriver(disp
))
606 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
608 /* limit to APIs supported by core */
609 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
611 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
612 * classifies it as an EGL display extension, though conceptually it's an
613 * EGL client extension.
615 * From the EGL_KHR_get_all_proc_addresses spec:
617 * The EGL implementation must expose the name
618 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
619 * EGL_KHR_get_all_proc_addresses and supports
620 * EGL_EXT_client_extensions.
622 * Mesa unconditionally exposes both client extensions mentioned above,
623 * so the spec requires that each EGLDisplay unconditionally expose
624 * EGL_KHR_get_all_proc_addresses also.
626 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
628 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
629 * programs. It is driver agnostic and handled in the main EGL code.
631 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
633 _eglComputeVersion(disp
);
634 _eglCreateExtensionsString(disp
);
635 _eglCreateAPIsString(disp
);
636 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
637 "%d.%d (%s)", disp
->Version
/ 10, disp
->Version
% 10,
641 /* Update applications version of major and minor if not NULL */
642 if ((major
!= NULL
) && (minor
!= NULL
)) {
643 *major
= disp
->Version
/ 10;
644 *minor
= disp
->Version
% 10;
647 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
651 EGLBoolean EGLAPIENTRY
652 eglTerminate(EGLDisplay dpy
)
654 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
656 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
659 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
661 if (disp
->Initialized
) {
662 _EGLDriver
*drv
= disp
->Driver
;
664 drv
->API
.Terminate(drv
, disp
);
665 /* do not reset disp->Driver */
666 disp
->ClientAPIsString
[0] = 0;
667 disp
->Initialized
= EGL_FALSE
;
670 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
674 const char * EGLAPIENTRY
675 eglQueryString(EGLDisplay dpy
, EGLint name
)
680 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
681 const char *ret
= _eglGetClientExtensionString();
683 RETURN_EGL_SUCCESS(NULL
, ret
);
685 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
688 disp
= _eglLockDisplay(dpy
);
689 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
690 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
694 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
696 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
698 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
699 case EGL_CLIENT_APIS
:
700 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
702 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
707 EGLBoolean EGLAPIENTRY
708 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
709 EGLint config_size
, EGLint
*num_config
)
711 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
715 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
717 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
718 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
720 RETURN_EGL_EVAL(disp
, ret
);
724 EGLBoolean EGLAPIENTRY
725 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
726 EGLint config_size
, EGLint
*num_config
)
728 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
732 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
734 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
735 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
736 config_size
, num_config
);
738 RETURN_EGL_EVAL(disp
, ret
);
742 EGLBoolean EGLAPIENTRY
743 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
744 EGLint attribute
, EGLint
*value
)
746 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
747 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
751 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
753 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
754 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
756 RETURN_EGL_EVAL(disp
, ret
);
760 EGLContext EGLAPIENTRY
761 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
762 const EGLint
*attrib_list
)
764 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
765 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
766 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
768 _EGLContext
*context
;
771 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
773 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
775 if (config
!= EGL_NO_CONFIG_KHR
)
776 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
777 else if (!disp
->Extensions
.KHR_no_config_context
)
778 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
780 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
781 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
783 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
784 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
786 RETURN_EGL_EVAL(disp
, ret
);
790 EGLBoolean EGLAPIENTRY
791 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
793 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
794 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
798 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
800 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
801 _eglUnlinkContext(context
);
802 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
804 RETURN_EGL_EVAL(disp
, ret
);
808 EGLBoolean EGLAPIENTRY
809 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
812 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
813 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
814 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
815 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
819 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
822 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
825 /* display is allowed to be uninitialized under certain condition */
826 if (!disp
->Initialized
) {
827 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
828 ctx
!= EGL_NO_CONTEXT
)
829 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
832 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
834 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
835 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
836 if (!draw_surf
|| !read_surf
) {
837 /* From the EGL 1.4 (20130211) spec:
839 * To release the current context without assigning a new one, set ctx
840 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
842 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
843 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
845 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
846 (!read_surf
&& read
!= EGL_NO_SURFACE
))
847 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
848 if (draw_surf
|| read_surf
)
849 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
852 /* If a native window underlying either draw or read is no longer valid,
853 * an EGL_BAD_NATIVE_WINDOW error is generated.
855 if (draw_surf
&& draw_surf
->Lost
)
856 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
857 if (read_surf
&& read_surf
->Lost
)
858 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
860 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
862 RETURN_EGL_EVAL(disp
, ret
);
866 EGLBoolean EGLAPIENTRY
867 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
868 EGLint attribute
, EGLint
*value
)
870 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
871 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
875 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
877 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
878 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
880 RETURN_EGL_EVAL(disp
, ret
);
885 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
886 void *native_window
, const EGLint
*attrib_list
)
888 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
894 if (native_window
== NULL
)
895 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
897 #ifdef HAVE_SURFACELESS_PLATFORM
898 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
899 /* From the EGL_MESA_platform_surfaceless spec (v1):
901 * eglCreatePlatformWindowSurface fails when called with a <display>
902 * that belongs to the surfaceless platform. It returns
903 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
904 * justification for this unconditional failure is that the
905 * surfaceless platform has no native windows, and therefore the
906 * <native_window> parameter is always invalid.
908 * This check must occur before checking the EGLConfig, which emits
911 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
915 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
917 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
918 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
920 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
922 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
924 RETURN_EGL_EVAL(disp
, ret
);
928 EGLSurface EGLAPIENTRY
929 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
930 EGLNativeWindowType window
, const EGLint
*attrib_list
)
932 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
934 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
935 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
936 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
941 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
943 #ifdef HAVE_X11_PLATFORM
944 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
945 /* The `native_window` parameter for the X11 platform differs between
946 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
947 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
948 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
949 * `Window*`. Convert `Window*` to `Window` because that's what
950 * dri2_x11_create_window_surface() expects.
952 return (void *)(* (Window
*) native_window
);
955 return native_window
;
958 static EGLSurface EGLAPIENTRY
959 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
961 const EGLint
*attrib_list
)
963 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
965 native_window
= _fixupNativeWindow(disp
, native_window
);
967 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
968 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
973 EGLSurface EGLAPIENTRY
974 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
976 const EGLAttrib
*attrib_list
)
978 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
982 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
984 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
985 if (attrib_list
&& !int_attribs
)
986 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
988 native_window
= _fixupNativeWindow(disp
, native_window
);
989 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
996 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
998 #ifdef HAVE_X11_PLATFORM
999 /* The `native_pixmap` parameter for the X11 platform differs between
1000 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1001 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1002 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1003 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1004 * dri2_x11_create_pixmap_surface() expects.
1006 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
1007 return (void *)(* (Pixmap
*) native_pixmap
);
1009 return native_pixmap
;
1013 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1014 void *native_pixmap
, const EGLint
*attrib_list
)
1016 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1021 #if HAVE_SURFACELESS_PLATFORM
1022 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
1023 /* From the EGL_MESA_platform_surfaceless spec (v1):
1025 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1026 * also fails when called with a <display> that belongs to the
1027 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1028 * EGL_BAD_NATIVE_PIXMAP.
1030 * This check must occur before checking the EGLConfig, which emits
1033 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1037 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1039 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1040 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1042 if (native_pixmap
== NULL
)
1043 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1045 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1047 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1049 RETURN_EGL_EVAL(disp
, ret
);
1053 EGLSurface EGLAPIENTRY
1054 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1055 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1057 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1059 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1060 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1061 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1065 static EGLSurface EGLAPIENTRY
1066 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1067 void *native_pixmap
,
1068 const EGLint
*attrib_list
)
1070 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1072 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1073 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1074 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1079 EGLSurface EGLAPIENTRY
1080 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1081 void *native_pixmap
,
1082 const EGLAttrib
*attrib_list
)
1084 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1086 EGLint
*int_attribs
;
1088 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1090 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1091 if (attrib_list
&& !int_attribs
)
1092 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1094 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1095 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1102 EGLSurface EGLAPIENTRY
1103 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1104 const EGLint
*attrib_list
)
1106 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1107 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1112 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1113 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1115 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1116 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1118 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1119 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1121 RETURN_EGL_EVAL(disp
, ret
);
1125 EGLBoolean EGLAPIENTRY
1126 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1128 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1129 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1133 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1134 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1135 _eglUnlinkSurface(surf
);
1136 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1138 RETURN_EGL_EVAL(disp
, ret
);
1141 EGLBoolean EGLAPIENTRY
1142 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1143 EGLint attribute
, EGLint
*value
)
1145 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1146 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1150 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1151 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1152 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1154 RETURN_EGL_EVAL(disp
, ret
);
1157 EGLBoolean EGLAPIENTRY
1158 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1159 EGLint attribute
, EGLint value
)
1161 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1162 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1166 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1167 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1168 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1170 RETURN_EGL_EVAL(disp
, ret
);
1174 EGLBoolean EGLAPIENTRY
1175 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1177 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1178 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1182 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1183 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1184 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1186 RETURN_EGL_EVAL(disp
, ret
);
1190 EGLBoolean EGLAPIENTRY
1191 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1193 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1194 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1198 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1199 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1200 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1202 RETURN_EGL_EVAL(disp
, ret
);
1206 EGLBoolean EGLAPIENTRY
1207 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1209 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1210 _EGLContext
*ctx
= _eglGetCurrentContext();
1211 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1215 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1216 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1218 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1219 ctx
->Resource
.Display
!= disp
)
1220 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1222 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1223 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1225 if (surf
->Type
!= EGL_WINDOW_BIT
)
1226 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1228 interval
= CLAMP(interval
,
1229 surf
->Config
->MinSwapInterval
,
1230 surf
->Config
->MaxSwapInterval
);
1232 if (surf
->SwapInterval
!= interval
)
1233 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1238 surf
->SwapInterval
= interval
;
1240 RETURN_EGL_EVAL(disp
, ret
);
1244 EGLBoolean EGLAPIENTRY
1245 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1247 _EGLContext
*ctx
= _eglGetCurrentContext();
1248 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1249 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1253 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1254 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1256 /* surface must be bound to current context in EGL 1.4 */
1257 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1258 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1259 surf
!= ctx
->DrawSurface
)
1260 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1263 if (surf
->Type
!= EGL_WINDOW_BIT
)
1264 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1266 /* From the EGL 1.5 spec:
1268 * If eglSwapBuffers is called and the native window associated with
1269 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1273 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1275 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1277 /* EGL_KHR_partial_update
1278 * Frame boundary successfully reached,
1279 * reset damage region and reset BufferAgeRead
1282 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1283 surf
->BufferAgeRead
= EGL_FALSE
;
1286 RETURN_EGL_EVAL(disp
, ret
);
1291 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1292 EGLint
*rects
, EGLint n_rects
)
1294 _EGLContext
*ctx
= _eglGetCurrentContext();
1298 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1300 /* surface must be bound to current context in EGL 1.4 */
1301 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1302 surf
!= ctx
->DrawSurface
)
1303 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1305 if (surf
->Type
!= EGL_WINDOW_BIT
)
1306 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1308 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1309 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1311 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1313 /* EGL_KHR_partial_update
1314 * Frame boundary successfully reached,
1315 * reset damage region and reset BufferAgeRead
1318 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1319 surf
->BufferAgeRead
= EGL_FALSE
;
1322 RETURN_EGL_EVAL(disp
, ret
);
1325 static EGLBoolean EGLAPIENTRY
1326 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1327 EGLint
*rects
, EGLint n_rects
)
1329 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1330 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1331 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1332 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1335 static EGLBoolean EGLAPIENTRY
1336 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1337 EGLint
*rects
, EGLint n_rects
)
1339 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1340 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1341 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1342 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1346 * Clamp the rectangles so that they lie within the surface.
1350 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1351 EGLint
*rects
, EGLint n_rects
)
1354 EGLint surf_height
= surf
->Height
;
1355 EGLint surf_width
= surf
->Width
;
1357 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1358 EGLint x1
, y1
, x2
, y2
;
1361 x2
= rects
[i
+ 2] + x1
;
1362 y2
= rects
[i
+ 3] + y1
;
1364 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1365 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1366 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1367 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1371 static EGLBoolean EGLAPIENTRY
1372 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1373 EGLint
*rects
, EGLint n_rects
)
1375 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1376 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1377 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1378 _EGLContext
*ctx
= _eglGetCurrentContext();
1381 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1383 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1384 surf
->Type
!= EGL_WINDOW_BIT
||
1385 ctx
->DrawSurface
!= surf
||
1386 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1387 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1389 /* If the damage region is already set or
1390 * buffer age is not queried between
1391 * frame boundaries, throw bad access error
1394 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1395 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1397 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1398 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1401 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1403 RETURN_EGL_EVAL(disp
, ret
);
1406 EGLBoolean EGLAPIENTRY
1407 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1409 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1410 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1413 void *native_pixmap_ptr
;
1415 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1416 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1417 native_pixmap_ptr
= (void*) target
;
1419 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1420 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1422 RETURN_EGL_EVAL(disp
, ret
);
1427 _eglWaitClientCommon(void)
1429 _EGLContext
*ctx
= _eglGetCurrentContext();
1435 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1437 disp
= ctx
->Resource
.Display
;
1438 mtx_lock(&disp
->Mutex
);
1440 /* let bad current context imply bad current surface */
1441 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1442 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1443 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1445 /* a valid current context implies an initialized current display */
1446 assert(disp
->Initialized
);
1448 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1450 RETURN_EGL_EVAL(disp
, ret
);
1453 EGLBoolean EGLAPIENTRY
1456 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1457 return _eglWaitClientCommon();
1460 EGLBoolean EGLAPIENTRY
1463 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1464 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1465 return _eglWaitClientCommon();
1469 EGLBoolean EGLAPIENTRY
1470 eglWaitNative(EGLint engine
)
1472 _EGLContext
*ctx
= _eglGetCurrentContext();
1478 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1480 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1482 disp
= ctx
->Resource
.Display
;
1483 mtx_lock(&disp
->Mutex
);
1485 /* let bad current context imply bad current surface */
1486 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1487 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1488 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1490 /* a valid current context implies an initialized current display */
1491 assert(disp
->Initialized
);
1493 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1495 RETURN_EGL_EVAL(disp
, ret
);
1499 EGLDisplay EGLAPIENTRY
1500 eglGetCurrentDisplay(void)
1502 _EGLContext
*ctx
= _eglGetCurrentContext();
1505 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1507 RETURN_EGL_SUCCESS(NULL
, ret
);
1511 EGLContext EGLAPIENTRY
1512 eglGetCurrentContext(void)
1514 _EGLContext
*ctx
= _eglGetCurrentContext();
1517 ret
= _eglGetContextHandle(ctx
);
1519 RETURN_EGL_SUCCESS(NULL
, ret
);
1523 EGLSurface EGLAPIENTRY
1524 eglGetCurrentSurface(EGLint readdraw
)
1526 _EGLContext
*ctx
= _eglGetCurrentContext();
1527 EGLint err
= EGL_SUCCESS
;
1531 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1534 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1538 surf
= ctx
->DrawSurface
;
1541 surf
= ctx
->ReadSurface
;
1545 err
= EGL_BAD_PARAMETER
;
1549 ret
= _eglGetSurfaceHandle(surf
);
1551 RETURN_EGL_ERROR(NULL
, err
, ret
);
1558 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1559 EGLint e
= t
->LastError
;
1560 if (!_eglIsCurrentThreadDummy())
1561 t
->LastError
= EGL_SUCCESS
;
1571 * Specify the client API to use for subsequent calls including:
1572 * eglCreateContext()
1573 * eglGetCurrentContext()
1574 * eglGetCurrentDisplay()
1575 * eglGetCurrentSurface()
1576 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1579 * See section 3.7 "Rendering Context" in the EGL specification for details.
1581 EGLBoolean EGLAPIENTRY
1582 eglBindAPI(EGLenum api
)
1586 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1588 t
= _eglGetCurrentThread();
1589 if (_eglIsCurrentThreadDummy())
1590 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1592 if (!_eglIsApiValid(api
))
1593 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1595 t
->CurrentAPI
= api
;
1597 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1602 * Return the last value set with eglBindAPI().
1607 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1610 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1611 ret
= t
->CurrentAPI
;
1613 RETURN_EGL_SUCCESS(NULL
, ret
);
1617 EGLSurface EGLAPIENTRY
1618 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1619 EGLClientBuffer buffer
, EGLConfig config
,
1620 const EGLint
*attrib_list
)
1622 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1623 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1628 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1630 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1632 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1634 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1636 RETURN_EGL_EVAL(disp
, ret
);
1640 EGLBoolean EGLAPIENTRY
1641 eglReleaseThread(void)
1643 /* unbind current contexts */
1644 if (!_eglIsCurrentThreadDummy()) {
1645 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1646 _EGLContext
*ctx
= t
->CurrentContext
;
1648 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1651 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1654 mtx_lock(&disp
->Mutex
);
1656 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1657 mtx_unlock(&disp
->Mutex
);
1661 _eglDestroyCurrentThread();
1663 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1668 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1669 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1671 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1676 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1677 if (!disp
->Extensions
.KHR_image_base
)
1678 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1679 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1680 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1681 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1682 * <ctx> must be EGL_NO_CONTEXT..."
1684 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1685 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1687 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1689 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1691 RETURN_EGL_EVAL(disp
, ret
);
1694 static EGLImage EGLAPIENTRY
1695 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1696 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1698 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1699 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1700 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1704 EGLImage EGLAPIENTRY
1705 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1706 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1708 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1710 EGLint
*int_attribs
;
1712 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1714 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1715 if (attr_list
&& !int_attribs
)
1716 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1718 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1725 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1730 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1731 if (!disp
->Extensions
.KHR_image_base
)
1732 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1734 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1736 _eglUnlinkImage(img
);
1737 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1739 RETURN_EGL_EVAL(disp
, ret
);
1742 EGLBoolean EGLAPIENTRY
1743 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1745 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1746 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1747 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1748 return _eglDestroyImageCommon(disp
, img
);
1751 static EGLBoolean EGLAPIENTRY
1752 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1754 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1755 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1756 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1757 return _eglDestroyImageCommon(disp
, img
);
1762 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1763 EGLBoolean orig_is_EGLAttrib
,
1764 EGLenum invalid_type_error
)
1766 _EGLContext
*ctx
= _eglGetCurrentContext();
1771 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1773 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1774 /* There exist two EGLAttrib variants of eglCreateSync*:
1775 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1776 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1777 * support as a proxy for EGL 1.5 support, even though that's not
1778 * entirely correct (though _eglComputeVersion does the same).
1780 * The EGL spec provides no guidance on how to handle unsupported
1781 * functions. EGL_BAD_MATCH seems reasonable.
1783 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1786 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1787 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1788 * error is generated.
1791 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1792 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1794 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1795 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1796 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1797 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1800 case EGL_SYNC_FENCE_KHR
:
1801 if (!disp
->Extensions
.KHR_fence_sync
)
1802 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1804 case EGL_SYNC_REUSABLE_KHR
:
1805 if (!disp
->Extensions
.KHR_reusable_sync
)
1806 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1808 case EGL_SYNC_CL_EVENT_KHR
:
1809 if (!disp
->Extensions
.KHR_cl_event2
)
1810 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1812 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1813 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1814 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1817 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1820 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1821 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1823 RETURN_EGL_EVAL(disp
, ret
);
1827 static EGLSync EGLAPIENTRY
1828 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1830 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1831 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1834 EGLAttrib
*attrib_list
;
1837 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1838 attrib_list
= (EGLAttrib
*) int_list
;
1840 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1841 if (err
!= EGL_SUCCESS
)
1842 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1845 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1848 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1851 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1856 static EGLSync EGLAPIENTRY
1857 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1859 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1860 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1861 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1867 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1869 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1870 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1871 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1877 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1882 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1883 assert(disp
->Extensions
.KHR_reusable_sync
||
1884 disp
->Extensions
.KHR_fence_sync
||
1885 disp
->Extensions
.ANDROID_native_fence_sync
);
1888 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1890 RETURN_EGL_EVAL(disp
, ret
);
1893 EGLBoolean EGLAPIENTRY
1894 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1896 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1897 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1898 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1899 return _eglDestroySync(disp
, s
);
1902 static EGLBoolean EGLAPIENTRY
1903 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1905 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1906 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1907 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1908 return _eglDestroySync(disp
, s
);
1913 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1914 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1919 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1920 assert(disp
->Extensions
.KHR_reusable_sync
||
1921 disp
->Extensions
.KHR_fence_sync
||
1922 disp
->Extensions
.ANDROID_native_fence_sync
);
1924 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1925 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1927 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1928 * unlocked here to allow other threads also to be able to
1929 * go into waiting state.
1932 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1933 _eglUnlockDisplay(dpy
);
1935 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1938 * 'disp' is already unlocked for reusable sync type,
1939 * so passing 'NULL' to bypass unlocking display.
1941 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1942 RETURN_EGL_EVAL(NULL
, ret
);
1944 RETURN_EGL_EVAL(disp
, ret
);
1948 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
1949 EGLint flags
, EGLTime timeout
)
1951 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1952 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1953 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1954 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1957 static EGLint EGLAPIENTRY
1958 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
1959 EGLint flags
, EGLTime timeout
)
1961 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1962 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1963 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1964 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1969 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
1971 _EGLContext
*ctx
= _eglGetCurrentContext();
1975 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1976 assert(disp
->Extensions
.KHR_wait_sync
);
1978 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1979 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1980 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1982 /* the API doesn't allow any flags yet */
1984 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1986 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1988 RETURN_EGL_EVAL(disp
, ret
);
1991 static EGLint EGLAPIENTRY
1992 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1994 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1995 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1996 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1997 return _eglWaitSyncCommon(disp
, s
, flags
);
2001 EGLBoolean EGLAPIENTRY
2002 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2004 /* The KHR version returns EGLint, while the core version returns
2005 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2008 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2009 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2010 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2011 return _eglWaitSyncCommon(disp
, s
, flags
);
2015 static EGLBoolean EGLAPIENTRY
2016 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2018 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2019 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2023 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2025 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2026 assert(disp
->Extensions
.KHR_reusable_sync
);
2027 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2029 RETURN_EGL_EVAL(disp
, ret
);
2034 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2039 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2040 assert(disp
->Extensions
.KHR_reusable_sync
||
2041 disp
->Extensions
.KHR_fence_sync
||
2042 disp
->Extensions
.ANDROID_native_fence_sync
);
2043 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2045 RETURN_EGL_EVAL(disp
, ret
);
2048 EGLBoolean EGLAPIENTRY
2049 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
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 _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2058 static EGLBoolean EGLAPIENTRY
2059 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2061 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2062 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2066 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2069 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2072 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2074 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2076 * If any error occurs, <*value> is not modified.
2078 if (result
== EGL_FALSE
)
2085 static EGLint EGLAPIENTRY
2086 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2088 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2089 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2093 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2095 /* the spec doesn't seem to specify what happens if the fence
2096 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2099 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2100 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2102 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2103 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2104 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2106 RETURN_EGL_EVAL(disp
, ret
);
2109 static EGLBoolean EGLAPIENTRY
2110 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2111 EGLint numRects
, const EGLint
*rects
)
2113 _EGLContext
*ctx
= _eglGetCurrentContext();
2114 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2115 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2119 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2121 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2123 if (!disp
->Extensions
.NOK_swap_region
)
2124 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2126 /* surface must be bound to current context in EGL 1.4 */
2127 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2128 surf
!= ctx
->DrawSurface
)
2129 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2131 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2133 RETURN_EGL_EVAL(disp
, ret
);
2137 static EGLImage EGLAPIENTRY
2138 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2140 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2145 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2147 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2148 if (!disp
->Extensions
.MESA_drm_image
)
2149 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2151 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2152 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2154 RETURN_EGL_EVAL(disp
, ret
);
2157 static EGLBoolean EGLAPIENTRY
2158 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2159 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2161 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2162 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2166 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2168 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2169 assert(disp
->Extensions
.MESA_drm_image
);
2172 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2174 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2176 RETURN_EGL_EVAL(disp
, ret
);
2182 static EGLBoolean EGLAPIENTRY
2183 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2185 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2189 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2191 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2192 assert(disp
->Extensions
.WL_bind_wayland_display
);
2195 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2197 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2199 RETURN_EGL_EVAL(disp
, ret
);
2202 static EGLBoolean EGLAPIENTRY
2203 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2205 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2209 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2211 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2212 assert(disp
->Extensions
.WL_bind_wayland_display
);
2215 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2217 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2219 RETURN_EGL_EVAL(disp
, ret
);
2222 static EGLBoolean EGLAPIENTRY
2223 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2224 EGLint attribute
, EGLint
*value
)
2226 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2230 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2232 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2233 assert(disp
->Extensions
.WL_bind_wayland_display
);
2236 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2238 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2240 RETURN_EGL_EVAL(disp
, ret
);
2244 static struct wl_buffer
* EGLAPIENTRY
2245 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2247 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2250 struct wl_buffer
*ret
;
2252 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2254 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2255 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2256 RETURN_EGL_EVAL(disp
, NULL
);
2258 img
= _eglLookupImage(image
, disp
);
2261 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2263 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2265 RETURN_EGL_EVAL(disp
, ret
);
2268 static EGLBoolean EGLAPIENTRY
2269 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2270 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2272 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2273 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2277 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2279 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2281 if (!disp
->Extensions
.NV_post_sub_buffer
)
2282 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2284 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2286 RETURN_EGL_EVAL(disp
, ret
);
2289 static EGLBoolean EGLAPIENTRY
2290 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
2291 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2294 _EGLDisplay
*disp
= _eglLockDisplay(display
);
2295 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2299 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2301 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2302 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2303 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2305 if (!ust
|| !msc
|| !sbc
)
2306 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2308 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2310 RETURN_EGL_EVAL(disp
, ret
);
2313 static EGLBoolean EGLAPIENTRY
2314 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2315 EGLint
*fourcc
, EGLint
*nplanes
,
2316 EGLuint64KHR
*modifiers
)
2318 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2319 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2323 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2325 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2326 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2329 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2331 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2334 RETURN_EGL_EVAL(disp
, ret
);
2337 static EGLBoolean EGLAPIENTRY
2338 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2339 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2341 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2342 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2346 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2348 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2349 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2352 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2354 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2356 RETURN_EGL_EVAL(disp
, ret
);
2359 static EGLint EGLAPIENTRY
2360 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2363 _EGLDisplay
*disp
= NULL
;
2364 _EGLResourceType type
;
2366 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2368 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2369 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2371 if (!_eglIsCurrentThreadDummy()) {
2376 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2379 disp
= _eglLockDisplay(dpy
);
2381 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2383 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2384 if (dpy
!= (EGLDisplay
) object
)
2385 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2387 disp
->Label
= label
;
2388 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2391 switch (objectType
) {
2392 case EGL_OBJECT_CONTEXT_KHR
:
2393 type
= _EGL_RESOURCE_CONTEXT
;
2395 case EGL_OBJECT_SURFACE_KHR
:
2396 type
= _EGL_RESOURCE_SURFACE
;
2398 case EGL_OBJECT_IMAGE_KHR
:
2399 type
= _EGL_RESOURCE_IMAGE
;
2401 case EGL_OBJECT_SYNC_KHR
:
2402 type
= _EGL_RESOURCE_SYNC
;
2404 case EGL_OBJECT_STREAM_KHR
:
2406 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2409 if (_eglCheckResource(object
, type
, disp
)) {
2410 _EGLResource
*res
= (_EGLResource
*) object
;
2413 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2416 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2419 static EGLint EGLAPIENTRY
2420 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2421 const EGLAttrib
*attrib_list
)
2423 unsigned int newEnabled
;
2425 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2427 mtx_lock(_eglGlobal
.Mutex
);
2429 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2430 if (attrib_list
!= NULL
) {
2433 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2434 switch (attrib_list
[i
]) {
2435 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2436 case EGL_DEBUG_MSG_ERROR_KHR
:
2437 case EGL_DEBUG_MSG_WARN_KHR
:
2438 case EGL_DEBUG_MSG_INFO_KHR
:
2439 if (attrib_list
[i
+ 1])
2440 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2442 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2445 // On error, set the last error code, call the current
2446 // debug callback, and return the error code.
2447 mtx_unlock(_eglGlobal
.Mutex
);
2448 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2449 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2450 return EGL_BAD_ATTRIBUTE
;
2455 if (callback
!= NULL
) {
2456 _eglGlobal
.debugCallback
= callback
;
2457 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2459 _eglGlobal
.debugCallback
= NULL
;
2460 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2463 mtx_unlock(_eglGlobal
.Mutex
);
2467 static EGLBoolean EGLAPIENTRY
2468 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2470 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2472 mtx_lock(_eglGlobal
.Mutex
);
2474 switch (attribute
) {
2475 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2476 case EGL_DEBUG_MSG_ERROR_KHR
:
2477 case EGL_DEBUG_MSG_WARN_KHR
:
2478 case EGL_DEBUG_MSG_INFO_KHR
:
2479 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2484 case EGL_DEBUG_CALLBACK_KHR
:
2485 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2488 mtx_unlock(_eglGlobal
.Mutex
);
2489 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2490 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2494 mtx_unlock(_eglGlobal
.Mutex
);
2499 _eglFunctionCompare(const void *key
, const void *elem
)
2501 const char *procname
= key
;
2502 const struct _egl_entrypoint
*entrypoint
= elem
;
2503 return strcmp(procname
, entrypoint
->name
);
2506 static EGLBoolean EGLAPIENTRY
2507 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2508 EGLint
*formats
, EGLint
*num_formats
)
2510 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2514 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2516 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2518 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2521 RETURN_EGL_EVAL(disp
, ret
);
2524 static EGLBoolean EGLAPIENTRY
2525 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2526 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2527 EGLint
*num_modifiers
)
2529 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2533 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2535 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2537 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2538 modifiers
, external_only
,
2541 RETURN_EGL_EVAL(disp
, ret
);
2544 static void EGLAPIENTRY
2545 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2546 EGLGetBlobFuncANDROID get
)
2548 /* This function does not return anything so we cannot
2549 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2551 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2552 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2554 _eglUnlockDisplay(disp
);
2558 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2561 _eglUnlockDisplay(disp
);
2566 _eglError(EGL_BAD_PARAMETER
,
2567 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2568 _eglUnlockDisplay(disp
);
2572 if (disp
->BlobCacheSet
) {
2573 _eglError(EGL_BAD_PARAMETER
,
2574 "eglSetBlobCacheFuncsANDROID: functions already set");
2575 _eglUnlockDisplay(disp
);
2579 disp
->BlobCacheSet
= set
;
2580 disp
->BlobCacheGet
= get
;
2582 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2584 _eglUnlockDisplay(disp
);
2587 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2588 eglGetProcAddress(const char *procname
)
2590 static const struct _egl_entrypoint egl_functions
[] = {
2591 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2592 #include "eglentrypoint.h"
2593 #undef EGL_ENTRYPOINT
2595 _EGLProc ret
= NULL
;
2598 RETURN_EGL_SUCCESS(NULL
, NULL
);
2600 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2602 if (strncmp(procname
, "egl", 3) == 0) {
2603 const struct _egl_entrypoint
*entrypoint
=
2605 egl_functions
, ARRAY_SIZE(egl_functions
),
2606 sizeof(egl_functions
[0]),
2607 _eglFunctionCompare
);
2609 ret
= entrypoint
->function
;
2613 ret
= _eglGetDriverProc(procname
);
2615 RETURN_EGL_SUCCESS(NULL
, ret
);
2619 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2620 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2624 *disp
= _eglLockDisplay(dpy
);
2625 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2627 _eglUnlockDisplay(*disp
);
2628 return MESA_GLINTEROP_INVALID_DISPLAY
;
2631 *drv
= (*disp
)->Driver
;
2633 *ctx
= _eglLookupContext(context
, *disp
);
2635 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2636 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2637 _eglUnlockDisplay(*disp
);
2638 return MESA_GLINTEROP_INVALID_CONTEXT
;
2641 return MESA_GLINTEROP_SUCCESS
;
2645 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2646 struct mesa_glinterop_device_info
*out
)
2653 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2654 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2657 if (drv
->API
.GLInteropQueryDeviceInfo
)
2658 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2660 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2662 _eglUnlockDisplay(disp
);
2667 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2668 struct mesa_glinterop_export_in
*in
,
2669 struct mesa_glinterop_export_out
*out
)
2676 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2677 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2680 if (drv
->API
.GLInteropExportObject
)
2681 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2683 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2685 _eglUnlockDisplay(disp
);