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 /* From the EGL 1.5 spec:
1265 * If eglSwapBuffers is called and the native window associated with
1266 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1270 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1272 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1274 /* EGL_KHR_partial_update
1275 * Frame boundary successfully reached,
1276 * reset damage region and reset BufferAgeRead
1279 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1280 surf
->BufferAgeRead
= EGL_FALSE
;
1283 RETURN_EGL_EVAL(disp
, ret
);
1288 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1289 EGLint
*rects
, EGLint n_rects
)
1291 _EGLContext
*ctx
= _eglGetCurrentContext();
1295 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1297 /* surface must be bound to current context in EGL 1.4 */
1298 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1299 surf
!= ctx
->DrawSurface
)
1300 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1302 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1303 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1305 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1307 /* EGL_KHR_partial_update
1308 * Frame boundary successfully reached,
1309 * reset damage region and reset BufferAgeRead
1312 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1313 surf
->BufferAgeRead
= EGL_FALSE
;
1316 RETURN_EGL_EVAL(disp
, ret
);
1319 static EGLBoolean EGLAPIENTRY
1320 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1321 EGLint
*rects
, EGLint n_rects
)
1323 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1324 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1325 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1326 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1329 static EGLBoolean EGLAPIENTRY
1330 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1331 EGLint
*rects
, EGLint n_rects
)
1333 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1334 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1335 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1336 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1340 * Clamp the rectangles so that they lie within the surface.
1344 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1345 EGLint
*rects
, EGLint n_rects
)
1348 EGLint surf_height
= surf
->Height
;
1349 EGLint surf_width
= surf
->Width
;
1351 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1352 EGLint x1
, y1
, x2
, y2
;
1355 x2
= rects
[i
+ 2] + x1
;
1356 y2
= rects
[i
+ 3] + y1
;
1358 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1359 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1360 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1361 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1365 static EGLBoolean EGLAPIENTRY
1366 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1367 EGLint
*rects
, EGLint n_rects
)
1369 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1370 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1371 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1372 _EGLContext
*ctx
= _eglGetCurrentContext();
1375 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1377 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1378 surf
->Type
!= EGL_WINDOW_BIT
||
1379 ctx
->DrawSurface
!= surf
||
1380 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1381 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1383 /* If the damage region is already set or
1384 * buffer age is not queried between
1385 * frame boundaries, throw bad access error
1388 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1389 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1391 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1392 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1395 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1397 RETURN_EGL_EVAL(disp
, ret
);
1400 EGLBoolean EGLAPIENTRY
1401 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1403 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1404 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1407 void *native_pixmap_ptr
;
1409 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1410 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1411 native_pixmap_ptr
= (void*) target
;
1413 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1414 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1416 RETURN_EGL_EVAL(disp
, ret
);
1421 _eglWaitClientCommon(void)
1423 _EGLContext
*ctx
= _eglGetCurrentContext();
1429 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1431 disp
= ctx
->Resource
.Display
;
1432 mtx_lock(&disp
->Mutex
);
1434 /* let bad current context imply bad current surface */
1435 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1436 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1437 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1439 /* a valid current context implies an initialized current display */
1440 assert(disp
->Initialized
);
1442 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1444 RETURN_EGL_EVAL(disp
, ret
);
1447 EGLBoolean EGLAPIENTRY
1450 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1451 return _eglWaitClientCommon();
1454 EGLBoolean EGLAPIENTRY
1457 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1458 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1459 return _eglWaitClientCommon();
1463 EGLBoolean EGLAPIENTRY
1464 eglWaitNative(EGLint engine
)
1466 _EGLContext
*ctx
= _eglGetCurrentContext();
1472 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1474 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1476 disp
= ctx
->Resource
.Display
;
1477 mtx_lock(&disp
->Mutex
);
1479 /* let bad current context imply bad current surface */
1480 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1481 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1482 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1484 /* a valid current context implies an initialized current display */
1485 assert(disp
->Initialized
);
1487 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1489 RETURN_EGL_EVAL(disp
, ret
);
1493 EGLDisplay EGLAPIENTRY
1494 eglGetCurrentDisplay(void)
1496 _EGLContext
*ctx
= _eglGetCurrentContext();
1499 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1501 RETURN_EGL_SUCCESS(NULL
, ret
);
1505 EGLContext EGLAPIENTRY
1506 eglGetCurrentContext(void)
1508 _EGLContext
*ctx
= _eglGetCurrentContext();
1511 ret
= _eglGetContextHandle(ctx
);
1513 RETURN_EGL_SUCCESS(NULL
, ret
);
1517 EGLSurface EGLAPIENTRY
1518 eglGetCurrentSurface(EGLint readdraw
)
1520 _EGLContext
*ctx
= _eglGetCurrentContext();
1521 EGLint err
= EGL_SUCCESS
;
1525 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1528 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1532 surf
= ctx
->DrawSurface
;
1535 surf
= ctx
->ReadSurface
;
1539 err
= EGL_BAD_PARAMETER
;
1543 ret
= _eglGetSurfaceHandle(surf
);
1545 RETURN_EGL_ERROR(NULL
, err
, ret
);
1552 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1553 EGLint e
= t
->LastError
;
1554 if (!_eglIsCurrentThreadDummy())
1555 t
->LastError
= EGL_SUCCESS
;
1565 * Specify the client API to use for subsequent calls including:
1566 * eglCreateContext()
1567 * eglGetCurrentContext()
1568 * eglGetCurrentDisplay()
1569 * eglGetCurrentSurface()
1570 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1573 * See section 3.7 "Rendering Context" in the EGL specification for details.
1575 EGLBoolean EGLAPIENTRY
1576 eglBindAPI(EGLenum api
)
1580 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1582 t
= _eglGetCurrentThread();
1583 if (_eglIsCurrentThreadDummy())
1584 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1586 if (!_eglIsApiValid(api
))
1587 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1589 t
->CurrentAPI
= api
;
1591 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1596 * Return the last value set with eglBindAPI().
1601 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1604 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1605 ret
= t
->CurrentAPI
;
1607 RETURN_EGL_SUCCESS(NULL
, ret
);
1611 EGLSurface EGLAPIENTRY
1612 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1613 EGLClientBuffer buffer
, EGLConfig config
,
1614 const EGLint
*attrib_list
)
1616 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1617 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1622 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1624 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1626 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1628 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1630 RETURN_EGL_EVAL(disp
, ret
);
1634 EGLBoolean EGLAPIENTRY
1635 eglReleaseThread(void)
1637 /* unbind current contexts */
1638 if (!_eglIsCurrentThreadDummy()) {
1639 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1640 _EGLContext
*ctx
= t
->CurrentContext
;
1642 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1645 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1648 mtx_lock(&disp
->Mutex
);
1650 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1651 mtx_unlock(&disp
->Mutex
);
1655 _eglDestroyCurrentThread();
1657 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1662 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1663 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1665 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1670 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1671 if (!disp
->Extensions
.KHR_image_base
)
1672 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1673 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1674 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1675 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1676 * <ctx> must be EGL_NO_CONTEXT..."
1678 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1679 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1681 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1683 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1685 RETURN_EGL_EVAL(disp
, ret
);
1688 static EGLImage EGLAPIENTRY
1689 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1690 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1692 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1693 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1694 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1698 EGLImage EGLAPIENTRY
1699 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1700 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1702 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1704 EGLint
*int_attribs
;
1706 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1708 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1709 if (attr_list
&& !int_attribs
)
1710 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1712 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1719 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1724 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1725 if (!disp
->Extensions
.KHR_image_base
)
1726 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1728 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1730 _eglUnlinkImage(img
);
1731 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1733 RETURN_EGL_EVAL(disp
, ret
);
1736 EGLBoolean EGLAPIENTRY
1737 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1739 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1740 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1741 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1742 return _eglDestroyImageCommon(disp
, img
);
1745 static EGLBoolean EGLAPIENTRY
1746 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1748 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1749 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1750 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1751 return _eglDestroyImageCommon(disp
, img
);
1756 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1757 EGLBoolean orig_is_EGLAttrib
,
1758 EGLenum invalid_type_error
)
1760 _EGLContext
*ctx
= _eglGetCurrentContext();
1765 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1767 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1768 /* There exist two EGLAttrib variants of eglCreateSync*:
1769 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1770 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1771 * support as a proxy for EGL 1.5 support, even though that's not
1772 * entirely correct (though _eglComputeVersion does the same).
1774 * The EGL spec provides no guidance on how to handle unsupported
1775 * functions. EGL_BAD_MATCH seems reasonable.
1777 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1780 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1781 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1782 * error is generated.
1785 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1786 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1788 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1789 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1790 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1791 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1794 case EGL_SYNC_FENCE_KHR
:
1795 if (!disp
->Extensions
.KHR_fence_sync
)
1796 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1798 case EGL_SYNC_REUSABLE_KHR
:
1799 if (!disp
->Extensions
.KHR_reusable_sync
)
1800 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1802 case EGL_SYNC_CL_EVENT_KHR
:
1803 if (!disp
->Extensions
.KHR_cl_event2
)
1804 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1806 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1807 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1808 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1811 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1814 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1815 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1817 RETURN_EGL_EVAL(disp
, ret
);
1821 static EGLSync EGLAPIENTRY
1822 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1824 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1825 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1828 EGLAttrib
*attrib_list
;
1831 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1832 attrib_list
= (EGLAttrib
*) int_list
;
1834 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1835 if (err
!= EGL_SUCCESS
)
1836 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1839 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1842 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1845 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1850 static EGLSync EGLAPIENTRY
1851 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1853 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1854 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1855 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1861 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1863 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1864 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1865 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1871 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1876 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1877 assert(disp
->Extensions
.KHR_reusable_sync
||
1878 disp
->Extensions
.KHR_fence_sync
||
1879 disp
->Extensions
.ANDROID_native_fence_sync
);
1882 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1884 RETURN_EGL_EVAL(disp
, ret
);
1887 EGLBoolean EGLAPIENTRY
1888 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1890 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1891 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1892 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1893 return _eglDestroySync(disp
, s
);
1896 static EGLBoolean EGLAPIENTRY
1897 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1899 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1900 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1901 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1902 return _eglDestroySync(disp
, s
);
1907 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1908 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1913 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1914 assert(disp
->Extensions
.KHR_reusable_sync
||
1915 disp
->Extensions
.KHR_fence_sync
||
1916 disp
->Extensions
.ANDROID_native_fence_sync
);
1918 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1919 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1921 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1922 * unlocked here to allow other threads also to be able to
1923 * go into waiting state.
1926 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1927 _eglUnlockDisplay(dpy
);
1929 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1932 * 'disp' is already unlocked for reusable sync type,
1933 * so passing 'NULL' to bypass unlocking display.
1935 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1936 RETURN_EGL_EVAL(NULL
, ret
);
1938 RETURN_EGL_EVAL(disp
, ret
);
1942 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
1943 EGLint flags
, EGLTime timeout
)
1945 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1946 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1947 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1948 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1951 static EGLint EGLAPIENTRY
1952 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
1953 EGLint flags
, EGLTime timeout
)
1955 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1956 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1957 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1958 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1963 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
1965 _EGLContext
*ctx
= _eglGetCurrentContext();
1969 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1970 assert(disp
->Extensions
.KHR_wait_sync
);
1972 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1973 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1974 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1976 /* the API doesn't allow any flags yet */
1978 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1980 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1982 RETURN_EGL_EVAL(disp
, ret
);
1985 static EGLint EGLAPIENTRY
1986 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
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 _eglWaitSyncCommon(disp
, s
, flags
);
1995 EGLBoolean EGLAPIENTRY
1996 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1998 /* The KHR version returns EGLint, while the core version returns
1999 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2002 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2003 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2004 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2005 return _eglWaitSyncCommon(disp
, s
, flags
);
2009 static EGLBoolean EGLAPIENTRY
2010 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2012 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2013 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2017 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2019 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2020 assert(disp
->Extensions
.KHR_reusable_sync
);
2021 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2023 RETURN_EGL_EVAL(disp
, ret
);
2028 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2033 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2034 assert(disp
->Extensions
.KHR_reusable_sync
||
2035 disp
->Extensions
.KHR_fence_sync
||
2036 disp
->Extensions
.ANDROID_native_fence_sync
);
2037 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2039 RETURN_EGL_EVAL(disp
, ret
);
2042 EGLBoolean EGLAPIENTRY
2043 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2045 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2046 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2047 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2048 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2052 static EGLBoolean EGLAPIENTRY
2053 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2055 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2056 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2060 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2063 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2066 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2068 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2070 * If any error occurs, <*value> is not modified.
2072 if (result
== EGL_FALSE
)
2079 static EGLint EGLAPIENTRY
2080 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2082 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2083 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2087 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2089 /* the spec doesn't seem to specify what happens if the fence
2090 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2093 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2094 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2096 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2097 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2098 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2100 RETURN_EGL_EVAL(disp
, ret
);
2103 static EGLBoolean EGLAPIENTRY
2104 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2105 EGLint numRects
, const EGLint
*rects
)
2107 _EGLContext
*ctx
= _eglGetCurrentContext();
2108 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2109 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2113 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2115 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2117 if (!disp
->Extensions
.NOK_swap_region
)
2118 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2120 /* surface must be bound to current context in EGL 1.4 */
2121 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2122 surf
!= ctx
->DrawSurface
)
2123 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2125 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2127 RETURN_EGL_EVAL(disp
, ret
);
2131 static EGLImage EGLAPIENTRY
2132 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2134 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2139 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2141 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2142 if (!disp
->Extensions
.MESA_drm_image
)
2143 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2145 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2146 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2148 RETURN_EGL_EVAL(disp
, ret
);
2151 static EGLBoolean EGLAPIENTRY
2152 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2153 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2155 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2156 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2160 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2162 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2163 assert(disp
->Extensions
.MESA_drm_image
);
2166 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2168 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2170 RETURN_EGL_EVAL(disp
, ret
);
2176 static EGLBoolean EGLAPIENTRY
2177 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2179 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2183 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2185 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2186 assert(disp
->Extensions
.WL_bind_wayland_display
);
2189 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2191 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2193 RETURN_EGL_EVAL(disp
, ret
);
2196 static EGLBoolean EGLAPIENTRY
2197 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2199 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2203 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2205 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2206 assert(disp
->Extensions
.WL_bind_wayland_display
);
2209 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2211 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2213 RETURN_EGL_EVAL(disp
, ret
);
2216 static EGLBoolean EGLAPIENTRY
2217 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2218 EGLint attribute
, EGLint
*value
)
2220 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2224 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2226 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2227 assert(disp
->Extensions
.WL_bind_wayland_display
);
2230 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2232 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2234 RETURN_EGL_EVAL(disp
, ret
);
2238 static struct wl_buffer
* EGLAPIENTRY
2239 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2241 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2244 struct wl_buffer
*ret
;
2246 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2248 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2249 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2250 RETURN_EGL_EVAL(disp
, NULL
);
2252 img
= _eglLookupImage(image
, disp
);
2255 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2257 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2259 RETURN_EGL_EVAL(disp
, ret
);
2262 static EGLBoolean EGLAPIENTRY
2263 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2264 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2266 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2267 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2271 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2273 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2275 if (!disp
->Extensions
.NV_post_sub_buffer
)
2276 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2278 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2280 RETURN_EGL_EVAL(disp
, ret
);
2283 static EGLBoolean EGLAPIENTRY
2284 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
2285 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2288 _EGLDisplay
*disp
= _eglLockDisplay(display
);
2289 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2293 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2295 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2296 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2297 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2299 if (!ust
|| !msc
|| !sbc
)
2300 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2302 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2304 RETURN_EGL_EVAL(disp
, ret
);
2307 static EGLBoolean EGLAPIENTRY
2308 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2309 EGLint
*fourcc
, EGLint
*nplanes
,
2310 EGLuint64KHR
*modifiers
)
2312 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2313 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2317 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2319 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2320 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2323 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2325 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2328 RETURN_EGL_EVAL(disp
, ret
);
2331 static EGLBoolean EGLAPIENTRY
2332 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2333 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2335 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2336 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2340 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2342 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2343 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2346 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2348 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2350 RETURN_EGL_EVAL(disp
, ret
);
2353 static EGLint EGLAPIENTRY
2354 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2357 _EGLDisplay
*disp
= NULL
;
2358 _EGLResourceType type
;
2360 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2362 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2363 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2365 if (!_eglIsCurrentThreadDummy()) {
2370 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2373 disp
= _eglLockDisplay(dpy
);
2375 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2377 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2378 if (dpy
!= (EGLDisplay
) object
)
2379 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2381 disp
->Label
= label
;
2382 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2385 switch (objectType
) {
2386 case EGL_OBJECT_CONTEXT_KHR
:
2387 type
= _EGL_RESOURCE_CONTEXT
;
2389 case EGL_OBJECT_SURFACE_KHR
:
2390 type
= _EGL_RESOURCE_SURFACE
;
2392 case EGL_OBJECT_IMAGE_KHR
:
2393 type
= _EGL_RESOURCE_IMAGE
;
2395 case EGL_OBJECT_SYNC_KHR
:
2396 type
= _EGL_RESOURCE_SYNC
;
2398 case EGL_OBJECT_STREAM_KHR
:
2400 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2403 if (_eglCheckResource(object
, type
, disp
)) {
2404 _EGLResource
*res
= (_EGLResource
*) object
;
2407 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2410 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2413 static EGLint EGLAPIENTRY
2414 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2415 const EGLAttrib
*attrib_list
)
2417 unsigned int newEnabled
;
2419 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2421 mtx_lock(_eglGlobal
.Mutex
);
2423 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2424 if (attrib_list
!= NULL
) {
2427 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2428 switch (attrib_list
[i
]) {
2429 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2430 case EGL_DEBUG_MSG_ERROR_KHR
:
2431 case EGL_DEBUG_MSG_WARN_KHR
:
2432 case EGL_DEBUG_MSG_INFO_KHR
:
2433 if (attrib_list
[i
+ 1])
2434 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2436 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2439 // On error, set the last error code, call the current
2440 // debug callback, and return the error code.
2441 mtx_unlock(_eglGlobal
.Mutex
);
2442 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2443 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2444 return EGL_BAD_ATTRIBUTE
;
2449 if (callback
!= NULL
) {
2450 _eglGlobal
.debugCallback
= callback
;
2451 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2453 _eglGlobal
.debugCallback
= NULL
;
2454 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2457 mtx_unlock(_eglGlobal
.Mutex
);
2461 static EGLBoolean EGLAPIENTRY
2462 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2464 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2466 mtx_lock(_eglGlobal
.Mutex
);
2468 switch (attribute
) {
2469 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2470 case EGL_DEBUG_MSG_ERROR_KHR
:
2471 case EGL_DEBUG_MSG_WARN_KHR
:
2472 case EGL_DEBUG_MSG_INFO_KHR
:
2473 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2478 case EGL_DEBUG_CALLBACK_KHR
:
2479 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2482 mtx_unlock(_eglGlobal
.Mutex
);
2483 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2484 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2488 mtx_unlock(_eglGlobal
.Mutex
);
2493 _eglFunctionCompare(const void *key
, const void *elem
)
2495 const char *procname
= key
;
2496 const struct _egl_entrypoint
*entrypoint
= elem
;
2497 return strcmp(procname
, entrypoint
->name
);
2500 static EGLBoolean EGLAPIENTRY
2501 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2502 EGLint
*formats
, EGLint
*num_formats
)
2504 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2508 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2510 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2512 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2515 RETURN_EGL_EVAL(disp
, ret
);
2518 static EGLBoolean EGLAPIENTRY
2519 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2520 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2521 EGLint
*num_modifiers
)
2523 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2527 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2529 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2531 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2532 modifiers
, external_only
,
2535 RETURN_EGL_EVAL(disp
, ret
);
2538 static void EGLAPIENTRY
2539 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2540 EGLGetBlobFuncANDROID get
)
2542 /* This function does not return anything so we cannot
2543 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2545 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2546 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2548 _eglUnlockDisplay(disp
);
2552 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2555 _eglUnlockDisplay(disp
);
2560 _eglError(EGL_BAD_PARAMETER
,
2561 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2562 _eglUnlockDisplay(disp
);
2566 if (disp
->BlobCacheSet
) {
2567 _eglError(EGL_BAD_PARAMETER
,
2568 "eglSetBlobCacheFuncsANDROID: functions already set");
2569 _eglUnlockDisplay(disp
);
2573 disp
->BlobCacheSet
= set
;
2574 disp
->BlobCacheGet
= get
;
2576 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2578 _eglUnlockDisplay(disp
);
2581 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2582 eglGetProcAddress(const char *procname
)
2584 static const struct _egl_entrypoint egl_functions
[] = {
2585 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2586 #include "eglentrypoint.h"
2587 #undef EGL_ENTRYPOINT
2589 _EGLProc ret
= NULL
;
2592 RETURN_EGL_SUCCESS(NULL
, NULL
);
2594 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2596 if (strncmp(procname
, "egl", 3) == 0) {
2597 const struct _egl_entrypoint
*entrypoint
=
2599 egl_functions
, ARRAY_SIZE(egl_functions
),
2600 sizeof(egl_functions
[0]),
2601 _eglFunctionCompare
);
2603 ret
= entrypoint
->function
;
2607 ret
= _eglGetDriverProc(procname
);
2609 RETURN_EGL_SUCCESS(NULL
, ret
);
2613 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2614 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2618 *disp
= _eglLockDisplay(dpy
);
2619 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2621 _eglUnlockDisplay(*disp
);
2622 return MESA_GLINTEROP_INVALID_DISPLAY
;
2625 *drv
= (*disp
)->Driver
;
2627 *ctx
= _eglLookupContext(context
, *disp
);
2629 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2630 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2631 _eglUnlockDisplay(*disp
);
2632 return MESA_GLINTEROP_INVALID_CONTEXT
;
2635 return MESA_GLINTEROP_SUCCESS
;
2639 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2640 struct mesa_glinterop_device_info
*out
)
2647 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2648 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2651 if (drv
->API
.GLInteropQueryDeviceInfo
)
2652 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2654 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2656 _eglUnlockDisplay(disp
);
2661 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2662 struct mesa_glinterop_export_in
*in
,
2663 struct mesa_glinterop_export_out
*out
)
2670 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2671 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2674 if (drv
->API
.GLInteropExportObject
)
2675 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2677 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2679 _eglUnlockDisplay(disp
);