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_swap_buffers_with_damage
);
493 _EGL_CHECK_EXTENSION(IMG_context_priority
);
495 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
496 _EGL_CHECK_EXTENSION(KHR_config_attribs
);
497 _EGL_CHECK_EXTENSION(KHR_context_flush_control
);
498 _EGL_CHECK_EXTENSION(KHR_create_context
);
499 _EGL_CHECK_EXTENSION(KHR_create_context_no_error
);
500 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
501 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
502 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
503 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
504 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
505 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
506 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
507 if (dpy
->Extensions
.KHR_image_base
&& dpy
->Extensions
.KHR_image_pixmap
)
508 dpy
->Extensions
.KHR_image
= EGL_TRUE
;
509 _EGL_CHECK_EXTENSION(KHR_image
);
510 _EGL_CHECK_EXTENSION(KHR_image_base
);
511 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
512 _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer
);
513 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
514 _EGL_CHECK_EXTENSION(KHR_partial_update
);
515 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
516 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
517 if (dpy
->Extensions
.EXT_swap_buffers_with_damage
)
518 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
519 _EGL_CHECK_EXTENSION(EXT_pixel_format_float
);
520 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
522 if (dpy
->Extensions
.KHR_no_config_context
)
523 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
524 _EGL_CHECK_EXTENSION(MESA_drm_image
);
525 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
527 _EGL_CHECK_EXTENSION(NOK_swap_region
);
528 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
530 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
532 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
533 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
535 #undef _EGL_CHECK_EXTENSION
539 _eglCreateAPIsString(_EGLDisplay
*dpy
)
541 #define addstr(str) \
543 const size_t old_len = strlen(dpy->ClientAPIsString); \
544 const size_t add_len = sizeof(str); \
545 const size_t max_len = sizeof(dpy->ClientAPIsString) - 1; \
546 if (old_len + add_len <= max_len) \
547 strcat(dpy->ClientAPIsString, str " "); \
549 assert(!"dpy->ClientAPIsString is not large enough"); \
552 if (dpy
->ClientAPIs
& EGL_OPENGL_BIT
)
555 if (dpy
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
556 dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
557 dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
561 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
568 _eglComputeVersion(_EGLDisplay
*disp
)
572 if (disp
->Extensions
.KHR_fence_sync
&&
573 disp
->Extensions
.KHR_cl_event2
&&
574 disp
->Extensions
.KHR_wait_sync
&&
575 disp
->Extensions
.KHR_image_base
&&
576 disp
->Extensions
.KHR_gl_texture_2D_image
&&
577 disp
->Extensions
.KHR_gl_texture_3D_image
&&
578 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
579 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
580 disp
->Extensions
.KHR_create_context
&&
581 disp
->Extensions
.EXT_create_context_robustness
&&
582 disp
->Extensions
.KHR_get_all_proc_addresses
&&
583 disp
->Extensions
.KHR_gl_colorspace
&&
584 disp
->Extensions
.KHR_surfaceless_context
)
589 * This is typically the second EGL function that an application calls.
590 * Here we load/initialize the actual hardware driver.
592 EGLBoolean EGLAPIENTRY
593 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
595 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
597 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
600 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
602 if (!disp
->Initialized
) {
603 if (!_eglMatchDriver(disp
))
604 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
606 /* limit to APIs supported by core */
607 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
609 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
610 * classifies it as an EGL display extension, though conceptually it's an
611 * EGL client extension.
613 * From the EGL_KHR_get_all_proc_addresses spec:
615 * The EGL implementation must expose the name
616 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
617 * EGL_KHR_get_all_proc_addresses and supports
618 * EGL_EXT_client_extensions.
620 * Mesa unconditionally exposes both client extensions mentioned above,
621 * so the spec requires that each EGLDisplay unconditionally expose
622 * EGL_KHR_get_all_proc_addresses also.
624 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
626 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
627 * programs. It is driver agnostic and handled in the main EGL code.
629 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
631 _eglComputeVersion(disp
);
632 _eglCreateExtensionsString(disp
);
633 _eglCreateAPIsString(disp
);
634 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
635 "%d.%d (%s)", disp
->Version
/ 10, disp
->Version
% 10,
639 /* Update applications version of major and minor if not NULL */
640 if ((major
!= NULL
) && (minor
!= NULL
)) {
641 *major
= disp
->Version
/ 10;
642 *minor
= disp
->Version
% 10;
645 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
649 EGLBoolean EGLAPIENTRY
650 eglTerminate(EGLDisplay dpy
)
652 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
654 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
657 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
659 if (disp
->Initialized
) {
660 _EGLDriver
*drv
= disp
->Driver
;
662 drv
->API
.Terminate(drv
, disp
);
663 /* do not reset disp->Driver */
664 disp
->ClientAPIsString
[0] = 0;
665 disp
->Initialized
= EGL_FALSE
;
668 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
672 const char * EGLAPIENTRY
673 eglQueryString(EGLDisplay dpy
, EGLint name
)
678 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
679 const char *ret
= _eglGetClientExtensionString();
681 RETURN_EGL_SUCCESS(NULL
, ret
);
683 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
686 disp
= _eglLockDisplay(dpy
);
687 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
688 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
692 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
694 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
696 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
697 case EGL_CLIENT_APIS
:
698 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
700 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
705 EGLBoolean EGLAPIENTRY
706 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
707 EGLint config_size
, EGLint
*num_config
)
709 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
713 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
715 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
716 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
718 RETURN_EGL_EVAL(disp
, ret
);
722 EGLBoolean EGLAPIENTRY
723 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
724 EGLint config_size
, EGLint
*num_config
)
726 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
730 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
732 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
733 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
734 config_size
, num_config
);
736 RETURN_EGL_EVAL(disp
, ret
);
740 EGLBoolean EGLAPIENTRY
741 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
742 EGLint attribute
, EGLint
*value
)
744 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
745 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
749 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
751 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
752 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
754 RETURN_EGL_EVAL(disp
, ret
);
758 EGLContext EGLAPIENTRY
759 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
760 const EGLint
*attrib_list
)
762 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
763 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
764 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
766 _EGLContext
*context
;
769 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
771 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
773 if (config
!= EGL_NO_CONFIG_KHR
)
774 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
775 else if (!disp
->Extensions
.KHR_no_config_context
)
776 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
778 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
779 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
781 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
782 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
784 RETURN_EGL_EVAL(disp
, ret
);
788 EGLBoolean EGLAPIENTRY
789 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
791 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
792 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
796 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
798 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
799 _eglUnlinkContext(context
);
800 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
802 RETURN_EGL_EVAL(disp
, ret
);
806 EGLBoolean EGLAPIENTRY
807 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
810 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
811 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
812 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
813 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
817 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
820 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
823 /* display is allowed to be uninitialized under certain condition */
824 if (!disp
->Initialized
) {
825 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
826 ctx
!= EGL_NO_CONTEXT
)
827 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
830 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
832 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
833 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
834 if (!draw_surf
|| !read_surf
) {
835 /* From the EGL 1.4 (20130211) spec:
837 * To release the current context without assigning a new one, set ctx
838 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
840 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
841 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
843 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
844 (!read_surf
&& read
!= EGL_NO_SURFACE
))
845 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
846 if (draw_surf
|| read_surf
)
847 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
850 /* If a native window underlying either draw or read is no longer valid,
851 * an EGL_BAD_NATIVE_WINDOW error is generated.
853 if (draw_surf
&& draw_surf
->Lost
)
854 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
855 if (read_surf
&& read_surf
->Lost
)
856 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
858 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
860 RETURN_EGL_EVAL(disp
, ret
);
864 EGLBoolean EGLAPIENTRY
865 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
866 EGLint attribute
, EGLint
*value
)
868 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
869 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
873 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
875 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
876 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
878 RETURN_EGL_EVAL(disp
, ret
);
883 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
884 void *native_window
, const EGLint
*attrib_list
)
886 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
892 if (native_window
== NULL
)
893 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
895 #ifdef HAVE_SURFACELESS_PLATFORM
896 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
897 /* From the EGL_MESA_platform_surfaceless spec (v1):
899 * eglCreatePlatformWindowSurface fails when called with a <display>
900 * that belongs to the surfaceless platform. It returns
901 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
902 * justification for this unconditional failure is that the
903 * surfaceless platform has no native windows, and therefore the
904 * <native_window> parameter is always invalid.
906 * This check must occur before checking the EGLConfig, which emits
909 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
913 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
915 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
916 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
918 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
920 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
922 RETURN_EGL_EVAL(disp
, ret
);
926 EGLSurface EGLAPIENTRY
927 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
928 EGLNativeWindowType window
, const EGLint
*attrib_list
)
930 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
932 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
933 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
934 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
939 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
941 #ifdef HAVE_X11_PLATFORM
942 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
943 /* The `native_window` parameter for the X11 platform differs between
944 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
945 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
946 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
947 * `Window*`. Convert `Window*` to `Window` because that's what
948 * dri2_x11_create_window_surface() expects.
950 return (void *)(* (Window
*) native_window
);
953 return native_window
;
956 static EGLSurface EGLAPIENTRY
957 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
959 const EGLint
*attrib_list
)
961 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
963 native_window
= _fixupNativeWindow(disp
, native_window
);
965 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
966 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
971 EGLSurface EGLAPIENTRY
972 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
974 const EGLAttrib
*attrib_list
)
976 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
980 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
982 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
983 if (attrib_list
&& !int_attribs
)
984 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
986 native_window
= _fixupNativeWindow(disp
, native_window
);
987 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
994 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
996 #ifdef HAVE_X11_PLATFORM
997 /* The `native_pixmap` parameter for the X11 platform differs between
998 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
999 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1000 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1001 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1002 * dri2_x11_create_pixmap_surface() expects.
1004 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
1005 return (void *)(* (Pixmap
*) native_pixmap
);
1007 return native_pixmap
;
1011 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1012 void *native_pixmap
, const EGLint
*attrib_list
)
1014 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1019 #if HAVE_SURFACELESS_PLATFORM
1020 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
1021 /* From the EGL_MESA_platform_surfaceless spec (v1):
1023 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1024 * also fails when called with a <display> that belongs to the
1025 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1026 * EGL_BAD_NATIVE_PIXMAP.
1028 * This check must occur before checking the EGLConfig, which emits
1031 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1035 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1037 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1038 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1040 if (native_pixmap
== NULL
)
1041 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1043 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1045 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1047 RETURN_EGL_EVAL(disp
, ret
);
1051 EGLSurface EGLAPIENTRY
1052 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1053 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1055 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1057 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1058 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1059 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1063 static EGLSurface EGLAPIENTRY
1064 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1065 void *native_pixmap
,
1066 const EGLint
*attrib_list
)
1068 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1070 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1071 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1072 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1077 EGLSurface EGLAPIENTRY
1078 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1079 void *native_pixmap
,
1080 const EGLAttrib
*attrib_list
)
1082 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1084 EGLint
*int_attribs
;
1086 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1088 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1089 if (attrib_list
&& !int_attribs
)
1090 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1092 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1093 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1100 EGLSurface EGLAPIENTRY
1101 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1102 const EGLint
*attrib_list
)
1104 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1105 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1110 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1111 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1113 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1114 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1116 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1117 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1119 RETURN_EGL_EVAL(disp
, ret
);
1123 EGLBoolean EGLAPIENTRY
1124 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1126 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1127 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1131 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1132 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1133 _eglUnlinkSurface(surf
);
1134 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1136 RETURN_EGL_EVAL(disp
, ret
);
1139 EGLBoolean EGLAPIENTRY
1140 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1141 EGLint attribute
, EGLint
*value
)
1143 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1144 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1148 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1149 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1150 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1152 RETURN_EGL_EVAL(disp
, ret
);
1155 EGLBoolean EGLAPIENTRY
1156 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1157 EGLint attribute
, EGLint value
)
1159 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1160 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1164 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1165 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1166 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1168 RETURN_EGL_EVAL(disp
, ret
);
1172 EGLBoolean EGLAPIENTRY
1173 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1175 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1176 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1180 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1181 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1182 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1184 RETURN_EGL_EVAL(disp
, ret
);
1188 EGLBoolean EGLAPIENTRY
1189 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1191 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1192 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1196 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1197 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1198 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1200 RETURN_EGL_EVAL(disp
, ret
);
1204 EGLBoolean EGLAPIENTRY
1205 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1207 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1208 _EGLContext
*ctx
= _eglGetCurrentContext();
1209 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1213 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1214 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1216 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1217 ctx
->Resource
.Display
!= disp
)
1218 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1220 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1221 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1223 interval
= CLAMP(interval
,
1224 surf
->Config
->MinSwapInterval
,
1225 surf
->Config
->MaxSwapInterval
);
1227 if (surf
->SwapInterval
!= interval
)
1228 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1233 surf
->SwapInterval
= interval
;
1235 RETURN_EGL_EVAL(disp
, ret
);
1239 EGLBoolean EGLAPIENTRY
1240 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1242 _EGLContext
*ctx
= _eglGetCurrentContext();
1243 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1244 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1248 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1249 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1251 /* surface must be bound to current context in EGL 1.4 */
1252 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1253 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1254 surf
!= ctx
->DrawSurface
)
1255 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1258 /* From the EGL 1.5 spec:
1260 * If eglSwapBuffers is called and the native window associated with
1261 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1265 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1267 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1269 /* EGL_KHR_partial_update
1270 * Frame boundary successfully reached,
1271 * reset damage region and reset BufferAgeRead
1274 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1275 surf
->BufferAgeRead
= EGL_FALSE
;
1278 RETURN_EGL_EVAL(disp
, ret
);
1283 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1284 EGLint
*rects
, EGLint n_rects
)
1286 _EGLContext
*ctx
= _eglGetCurrentContext();
1290 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1292 /* surface must be bound to current context in EGL 1.4 */
1293 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1294 surf
!= ctx
->DrawSurface
)
1295 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1297 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1298 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1300 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1302 /* EGL_KHR_partial_update
1303 * Frame boundary successfully reached,
1304 * reset damage region and reset BufferAgeRead
1307 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1308 surf
->BufferAgeRead
= EGL_FALSE
;
1311 RETURN_EGL_EVAL(disp
, ret
);
1314 static EGLBoolean EGLAPIENTRY
1315 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1316 EGLint
*rects
, EGLint n_rects
)
1318 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1319 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1320 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1321 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1324 static EGLBoolean EGLAPIENTRY
1325 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1326 EGLint
*rects
, EGLint n_rects
)
1328 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1329 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1330 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1331 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1335 * Clamp the rectangles so that they lie within the surface.
1339 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1340 EGLint
*rects
, EGLint n_rects
)
1343 EGLint surf_height
= surf
->Height
;
1344 EGLint surf_width
= surf
->Width
;
1346 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1347 EGLint x1
, y1
, x2
, y2
;
1350 x2
= rects
[i
+ 2] + x1
;
1351 y2
= rects
[i
+ 3] + y1
;
1353 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1354 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1355 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1356 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1360 static EGLBoolean EGLAPIENTRY
1361 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1362 EGLint
*rects
, EGLint n_rects
)
1364 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1365 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1366 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1367 _EGLContext
*ctx
= _eglGetCurrentContext();
1370 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1372 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1373 surf
->Type
!= EGL_WINDOW_BIT
||
1374 ctx
->DrawSurface
!= surf
||
1375 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1376 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1378 /* If the damage region is already set or
1379 * buffer age is not queried between
1380 * frame boundaries, throw bad access error
1383 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1384 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1386 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1387 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1390 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1392 RETURN_EGL_EVAL(disp
, ret
);
1395 EGLBoolean EGLAPIENTRY
1396 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1398 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1399 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1402 void *native_pixmap_ptr
;
1404 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1405 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1406 native_pixmap_ptr
= (void*) target
;
1408 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1409 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1411 RETURN_EGL_EVAL(disp
, ret
);
1416 _eglWaitClientCommon(void)
1418 _EGLContext
*ctx
= _eglGetCurrentContext();
1424 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1426 disp
= ctx
->Resource
.Display
;
1427 mtx_lock(&disp
->Mutex
);
1429 /* let bad current context imply bad current surface */
1430 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1431 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1432 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1434 /* a valid current context implies an initialized current display */
1435 assert(disp
->Initialized
);
1437 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1439 RETURN_EGL_EVAL(disp
, ret
);
1442 EGLBoolean EGLAPIENTRY
1445 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1446 return _eglWaitClientCommon();
1449 EGLBoolean EGLAPIENTRY
1452 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1453 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1454 return _eglWaitClientCommon();
1458 EGLBoolean EGLAPIENTRY
1459 eglWaitNative(EGLint engine
)
1461 _EGLContext
*ctx
= _eglGetCurrentContext();
1467 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1469 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1471 disp
= ctx
->Resource
.Display
;
1472 mtx_lock(&disp
->Mutex
);
1474 /* let bad current context imply bad current surface */
1475 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1476 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1477 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1479 /* a valid current context implies an initialized current display */
1480 assert(disp
->Initialized
);
1482 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1484 RETURN_EGL_EVAL(disp
, ret
);
1488 EGLDisplay EGLAPIENTRY
1489 eglGetCurrentDisplay(void)
1491 _EGLContext
*ctx
= _eglGetCurrentContext();
1494 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1496 RETURN_EGL_SUCCESS(NULL
, ret
);
1500 EGLContext EGLAPIENTRY
1501 eglGetCurrentContext(void)
1503 _EGLContext
*ctx
= _eglGetCurrentContext();
1506 ret
= _eglGetContextHandle(ctx
);
1508 RETURN_EGL_SUCCESS(NULL
, ret
);
1512 EGLSurface EGLAPIENTRY
1513 eglGetCurrentSurface(EGLint readdraw
)
1515 _EGLContext
*ctx
= _eglGetCurrentContext();
1516 EGLint err
= EGL_SUCCESS
;
1520 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1523 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1527 surf
= ctx
->DrawSurface
;
1530 surf
= ctx
->ReadSurface
;
1534 err
= EGL_BAD_PARAMETER
;
1538 ret
= _eglGetSurfaceHandle(surf
);
1540 RETURN_EGL_ERROR(NULL
, err
, ret
);
1547 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1548 EGLint e
= t
->LastError
;
1549 if (!_eglIsCurrentThreadDummy())
1550 t
->LastError
= EGL_SUCCESS
;
1560 * Specify the client API to use for subsequent calls including:
1561 * eglCreateContext()
1562 * eglGetCurrentContext()
1563 * eglGetCurrentDisplay()
1564 * eglGetCurrentSurface()
1565 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1568 * See section 3.7 "Rendering Context" in the EGL specification for details.
1570 EGLBoolean EGLAPIENTRY
1571 eglBindAPI(EGLenum api
)
1575 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1577 t
= _eglGetCurrentThread();
1578 if (_eglIsCurrentThreadDummy())
1579 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1581 if (!_eglIsApiValid(api
))
1582 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1584 t
->CurrentAPI
= api
;
1586 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1591 * Return the last value set with eglBindAPI().
1596 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1599 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1600 ret
= t
->CurrentAPI
;
1602 RETURN_EGL_SUCCESS(NULL
, ret
);
1606 EGLSurface EGLAPIENTRY
1607 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1608 EGLClientBuffer buffer
, EGLConfig config
,
1609 const EGLint
*attrib_list
)
1611 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1612 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1617 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1619 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1621 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1623 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1625 RETURN_EGL_EVAL(disp
, ret
);
1629 EGLBoolean EGLAPIENTRY
1630 eglReleaseThread(void)
1632 /* unbind current contexts */
1633 if (!_eglIsCurrentThreadDummy()) {
1634 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1635 _EGLContext
*ctx
= t
->CurrentContext
;
1637 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1640 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1643 mtx_lock(&disp
->Mutex
);
1645 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1646 mtx_unlock(&disp
->Mutex
);
1650 _eglDestroyCurrentThread();
1652 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1657 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1658 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1660 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1665 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1666 if (!disp
->Extensions
.KHR_image_base
)
1667 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1668 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1669 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1670 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1671 * <ctx> must be EGL_NO_CONTEXT..."
1673 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1674 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1676 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1678 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1680 RETURN_EGL_EVAL(disp
, ret
);
1683 static EGLImage EGLAPIENTRY
1684 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1685 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1687 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1688 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1689 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1693 EGLImage EGLAPIENTRY
1694 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1695 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1697 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1699 EGLint
*int_attribs
;
1701 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1703 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1704 if (attr_list
&& !int_attribs
)
1705 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1707 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1714 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1719 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1720 if (!disp
->Extensions
.KHR_image_base
)
1721 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1723 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1725 _eglUnlinkImage(img
);
1726 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1728 RETURN_EGL_EVAL(disp
, ret
);
1731 EGLBoolean EGLAPIENTRY
1732 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1734 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1735 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1736 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1737 return _eglDestroyImageCommon(disp
, img
);
1740 static EGLBoolean EGLAPIENTRY
1741 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1743 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1744 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1745 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1746 return _eglDestroyImageCommon(disp
, img
);
1751 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1752 EGLBoolean orig_is_EGLAttrib
,
1753 EGLenum invalid_type_error
)
1755 _EGLContext
*ctx
= _eglGetCurrentContext();
1760 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1762 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1763 /* There exist two EGLAttrib variants of eglCreateSync*:
1764 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1765 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1766 * support as a proxy for EGL 1.5 support, even though that's not
1767 * entirely correct (though _eglComputeVersion does the same).
1769 * The EGL spec provides no guidance on how to handle unsupported
1770 * functions. EGL_BAD_MATCH seems reasonable.
1772 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1775 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1776 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1777 * error is generated.
1780 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1781 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1783 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1784 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1785 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1786 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1789 case EGL_SYNC_FENCE_KHR
:
1790 if (!disp
->Extensions
.KHR_fence_sync
)
1791 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1793 case EGL_SYNC_REUSABLE_KHR
:
1794 if (!disp
->Extensions
.KHR_reusable_sync
)
1795 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1797 case EGL_SYNC_CL_EVENT_KHR
:
1798 if (!disp
->Extensions
.KHR_cl_event2
)
1799 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1801 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1802 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1803 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1806 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1809 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1810 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1812 RETURN_EGL_EVAL(disp
, ret
);
1816 static EGLSync EGLAPIENTRY
1817 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1819 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1820 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1823 EGLAttrib
*attrib_list
;
1826 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1827 attrib_list
= (EGLAttrib
*) int_list
;
1829 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1830 if (err
!= EGL_SUCCESS
)
1831 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1834 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1837 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1840 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1845 static EGLSync EGLAPIENTRY
1846 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1848 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1849 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1850 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1856 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1858 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1859 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1860 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1866 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1871 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1872 assert(disp
->Extensions
.KHR_reusable_sync
||
1873 disp
->Extensions
.KHR_fence_sync
||
1874 disp
->Extensions
.ANDROID_native_fence_sync
);
1877 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1879 RETURN_EGL_EVAL(disp
, ret
);
1882 EGLBoolean EGLAPIENTRY
1883 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1885 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1886 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1887 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1888 return _eglDestroySync(disp
, s
);
1891 static EGLBoolean EGLAPIENTRY
1892 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1894 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1895 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1896 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1897 return _eglDestroySync(disp
, s
);
1902 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1903 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1908 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1909 assert(disp
->Extensions
.KHR_reusable_sync
||
1910 disp
->Extensions
.KHR_fence_sync
||
1911 disp
->Extensions
.ANDROID_native_fence_sync
);
1913 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1914 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1916 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1917 * unlocked here to allow other threads also to be able to
1918 * go into waiting state.
1921 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1922 _eglUnlockDisplay(dpy
);
1924 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1927 * 'disp' is already unlocked for reusable sync type,
1928 * so passing 'NULL' to bypass unlocking display.
1930 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1931 RETURN_EGL_EVAL(NULL
, ret
);
1933 RETURN_EGL_EVAL(disp
, ret
);
1937 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
1938 EGLint flags
, EGLTime timeout
)
1940 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1941 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1942 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1943 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1946 static EGLint EGLAPIENTRY
1947 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
1948 EGLint flags
, EGLTime timeout
)
1950 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1951 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1952 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1953 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1958 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
1960 _EGLContext
*ctx
= _eglGetCurrentContext();
1964 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1965 assert(disp
->Extensions
.KHR_wait_sync
);
1967 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1968 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1969 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1971 /* the API doesn't allow any flags yet */
1973 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1975 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1977 RETURN_EGL_EVAL(disp
, ret
);
1980 static EGLint EGLAPIENTRY
1981 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1983 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1984 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1985 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1986 return _eglWaitSyncCommon(disp
, s
, flags
);
1990 EGLBoolean EGLAPIENTRY
1991 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1993 /* The KHR version returns EGLint, while the core version returns
1994 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1997 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1998 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1999 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2000 return _eglWaitSyncCommon(disp
, s
, flags
);
2004 static EGLBoolean EGLAPIENTRY
2005 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2007 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2008 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2012 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2014 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2015 assert(disp
->Extensions
.KHR_reusable_sync
);
2016 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2018 RETURN_EGL_EVAL(disp
, ret
);
2023 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2028 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2029 assert(disp
->Extensions
.KHR_reusable_sync
||
2030 disp
->Extensions
.KHR_fence_sync
||
2031 disp
->Extensions
.ANDROID_native_fence_sync
);
2032 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2034 RETURN_EGL_EVAL(disp
, ret
);
2037 EGLBoolean EGLAPIENTRY
2038 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2040 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2041 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2042 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2043 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2047 static EGLBoolean EGLAPIENTRY
2048 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2050 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2051 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2055 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2058 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2061 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2063 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2065 * If any error occurs, <*value> is not modified.
2067 if (result
== EGL_FALSE
)
2074 static EGLint EGLAPIENTRY
2075 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2077 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2078 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2082 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2084 /* the spec doesn't seem to specify what happens if the fence
2085 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2088 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2089 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2091 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2092 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2093 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2095 RETURN_EGL_EVAL(disp
, ret
);
2098 static EGLBoolean EGLAPIENTRY
2099 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2100 EGLint numRects
, const EGLint
*rects
)
2102 _EGLContext
*ctx
= _eglGetCurrentContext();
2103 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2104 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2108 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2110 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2112 if (!disp
->Extensions
.NOK_swap_region
)
2113 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2115 /* surface must be bound to current context in EGL 1.4 */
2116 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2117 surf
!= ctx
->DrawSurface
)
2118 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2120 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2122 RETURN_EGL_EVAL(disp
, ret
);
2126 static EGLImage EGLAPIENTRY
2127 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2129 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2134 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2136 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2137 if (!disp
->Extensions
.MESA_drm_image
)
2138 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2140 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2141 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2143 RETURN_EGL_EVAL(disp
, ret
);
2146 static EGLBoolean EGLAPIENTRY
2147 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2148 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2150 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2151 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2155 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2157 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2158 assert(disp
->Extensions
.MESA_drm_image
);
2161 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2163 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2165 RETURN_EGL_EVAL(disp
, ret
);
2171 static EGLBoolean EGLAPIENTRY
2172 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2174 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2178 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2180 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2181 assert(disp
->Extensions
.WL_bind_wayland_display
);
2184 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2186 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2188 RETURN_EGL_EVAL(disp
, ret
);
2191 static EGLBoolean EGLAPIENTRY
2192 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2194 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2198 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2200 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2201 assert(disp
->Extensions
.WL_bind_wayland_display
);
2204 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2206 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2208 RETURN_EGL_EVAL(disp
, ret
);
2211 static EGLBoolean EGLAPIENTRY
2212 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2213 EGLint attribute
, EGLint
*value
)
2215 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2219 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2221 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2222 assert(disp
->Extensions
.WL_bind_wayland_display
);
2225 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2227 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2229 RETURN_EGL_EVAL(disp
, ret
);
2233 static struct wl_buffer
* EGLAPIENTRY
2234 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2236 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2239 struct wl_buffer
*ret
;
2241 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2243 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2244 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2245 RETURN_EGL_EVAL(disp
, NULL
);
2247 img
= _eglLookupImage(image
, disp
);
2250 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2252 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2254 RETURN_EGL_EVAL(disp
, ret
);
2257 static EGLBoolean EGLAPIENTRY
2258 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2259 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2261 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2262 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2266 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2268 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2270 if (!disp
->Extensions
.NV_post_sub_buffer
)
2271 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2273 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2275 RETURN_EGL_EVAL(disp
, ret
);
2278 static EGLBoolean EGLAPIENTRY
2279 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
2280 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2283 _EGLDisplay
*disp
= _eglLockDisplay(display
);
2284 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2288 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2290 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2291 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2292 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2294 if (!ust
|| !msc
|| !sbc
)
2295 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2297 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2299 RETURN_EGL_EVAL(disp
, ret
);
2302 static EGLBoolean EGLAPIENTRY
2303 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2304 EGLint
*fourcc
, EGLint
*nplanes
,
2305 EGLuint64KHR
*modifiers
)
2307 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2308 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2312 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2314 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2315 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2318 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2320 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2323 RETURN_EGL_EVAL(disp
, ret
);
2326 static EGLBoolean EGLAPIENTRY
2327 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2328 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2330 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2331 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2335 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2337 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2338 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2341 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2343 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2345 RETURN_EGL_EVAL(disp
, ret
);
2348 static EGLint EGLAPIENTRY
2349 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2352 _EGLDisplay
*disp
= NULL
;
2353 _EGLResourceType type
;
2355 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2357 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2358 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2360 if (!_eglIsCurrentThreadDummy()) {
2365 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2368 disp
= _eglLockDisplay(dpy
);
2370 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2372 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2373 if (dpy
!= (EGLDisplay
) object
)
2374 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2376 disp
->Label
= label
;
2377 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2380 switch (objectType
) {
2381 case EGL_OBJECT_CONTEXT_KHR
:
2382 type
= _EGL_RESOURCE_CONTEXT
;
2384 case EGL_OBJECT_SURFACE_KHR
:
2385 type
= _EGL_RESOURCE_SURFACE
;
2387 case EGL_OBJECT_IMAGE_KHR
:
2388 type
= _EGL_RESOURCE_IMAGE
;
2390 case EGL_OBJECT_SYNC_KHR
:
2391 type
= _EGL_RESOURCE_SYNC
;
2393 case EGL_OBJECT_STREAM_KHR
:
2395 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2398 if (_eglCheckResource(object
, type
, disp
)) {
2399 _EGLResource
*res
= (_EGLResource
*) object
;
2402 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2405 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2408 static EGLint EGLAPIENTRY
2409 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2410 const EGLAttrib
*attrib_list
)
2412 unsigned int newEnabled
;
2414 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2416 mtx_lock(_eglGlobal
.Mutex
);
2418 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2419 if (attrib_list
!= NULL
) {
2422 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2423 switch (attrib_list
[i
]) {
2424 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2425 case EGL_DEBUG_MSG_ERROR_KHR
:
2426 case EGL_DEBUG_MSG_WARN_KHR
:
2427 case EGL_DEBUG_MSG_INFO_KHR
:
2428 if (attrib_list
[i
+ 1])
2429 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2431 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2434 // On error, set the last error code, call the current
2435 // debug callback, and return the error code.
2436 mtx_unlock(_eglGlobal
.Mutex
);
2437 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2438 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2439 return EGL_BAD_ATTRIBUTE
;
2444 if (callback
!= NULL
) {
2445 _eglGlobal
.debugCallback
= callback
;
2446 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2448 _eglGlobal
.debugCallback
= NULL
;
2449 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2452 mtx_unlock(_eglGlobal
.Mutex
);
2456 static EGLBoolean EGLAPIENTRY
2457 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2459 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2461 mtx_lock(_eglGlobal
.Mutex
);
2463 switch (attribute
) {
2464 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2465 case EGL_DEBUG_MSG_ERROR_KHR
:
2466 case EGL_DEBUG_MSG_WARN_KHR
:
2467 case EGL_DEBUG_MSG_INFO_KHR
:
2468 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2473 case EGL_DEBUG_CALLBACK_KHR
:
2474 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2477 mtx_unlock(_eglGlobal
.Mutex
);
2478 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2479 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2483 mtx_unlock(_eglGlobal
.Mutex
);
2488 _eglFunctionCompare(const void *key
, const void *elem
)
2490 const char *procname
= key
;
2491 const struct _egl_entrypoint
*entrypoint
= elem
;
2492 return strcmp(procname
, entrypoint
->name
);
2495 static EGLBoolean EGLAPIENTRY
2496 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2497 EGLint
*formats
, EGLint
*num_formats
)
2499 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2503 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2505 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2507 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2510 RETURN_EGL_EVAL(disp
, ret
);
2513 static EGLBoolean EGLAPIENTRY
2514 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2515 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2516 EGLint
*num_modifiers
)
2518 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2522 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2524 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2526 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2527 modifiers
, external_only
,
2530 RETURN_EGL_EVAL(disp
, ret
);
2533 static void EGLAPIENTRY
2534 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2535 EGLGetBlobFuncANDROID get
)
2537 /* This function does not return anything so we cannot
2538 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2540 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2541 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2543 _eglUnlockDisplay(disp
);
2547 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2550 _eglUnlockDisplay(disp
);
2555 _eglError(EGL_BAD_PARAMETER
,
2556 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2557 _eglUnlockDisplay(disp
);
2561 if (disp
->BlobCacheSet
) {
2562 _eglError(EGL_BAD_PARAMETER
,
2563 "eglSetBlobCacheFuncsANDROID: functions already set");
2564 _eglUnlockDisplay(disp
);
2568 disp
->BlobCacheSet
= set
;
2569 disp
->BlobCacheGet
= get
;
2571 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2573 _eglUnlockDisplay(disp
);
2576 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2577 eglGetProcAddress(const char *procname
)
2579 static const struct _egl_entrypoint egl_functions
[] = {
2580 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2581 #include "eglentrypoint.h"
2582 #undef EGL_ENTRYPOINT
2584 _EGLProc ret
= NULL
;
2587 RETURN_EGL_SUCCESS(NULL
, NULL
);
2589 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2591 if (strncmp(procname
, "egl", 3) == 0) {
2592 const struct _egl_entrypoint
*entrypoint
=
2594 egl_functions
, ARRAY_SIZE(egl_functions
),
2595 sizeof(egl_functions
[0]),
2596 _eglFunctionCompare
);
2598 ret
= entrypoint
->function
;
2602 ret
= _eglGetDriverProc(procname
);
2604 RETURN_EGL_SUCCESS(NULL
, ret
);
2608 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2609 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2613 *disp
= _eglLockDisplay(dpy
);
2614 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2616 _eglUnlockDisplay(*disp
);
2617 return MESA_GLINTEROP_INVALID_DISPLAY
;
2620 *drv
= (*disp
)->Driver
;
2622 *ctx
= _eglLookupContext(context
, *disp
);
2624 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2625 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2626 _eglUnlockDisplay(*disp
);
2627 return MESA_GLINTEROP_INVALID_CONTEXT
;
2630 return MESA_GLINTEROP_SUCCESS
;
2634 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2635 struct mesa_glinterop_device_info
*out
)
2642 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2643 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2646 if (drv
->API
.GLInteropQueryDeviceInfo
)
2647 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2649 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2651 _eglUnlockDisplay(disp
);
2656 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2657 struct mesa_glinterop_export_in
*in
,
2658 struct mesa_glinterop_export_out
*out
)
2665 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2666 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2669 if (drv
->API
.GLInteropExportObject
)
2670 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2672 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2674 _eglUnlockDisplay(disp
);