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 interval
= CLAMP(interval
,
1226 surf
->Config
->MinSwapInterval
,
1227 surf
->Config
->MaxSwapInterval
);
1229 if (surf
->SwapInterval
!= interval
)
1230 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1235 surf
->SwapInterval
= interval
;
1237 RETURN_EGL_EVAL(disp
, ret
);
1241 EGLBoolean EGLAPIENTRY
1242 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1244 _EGLContext
*ctx
= _eglGetCurrentContext();
1245 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1246 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1250 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1251 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1253 /* surface must be bound to current context in EGL 1.4 */
1254 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1255 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1256 surf
!= ctx
->DrawSurface
)
1257 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1260 /* From the EGL 1.5 spec:
1262 * If eglSwapBuffers is called and the native window associated with
1263 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1267 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1269 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1271 /* EGL_KHR_partial_update
1272 * Frame boundary successfully reached,
1273 * reset damage region and reset BufferAgeRead
1276 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1277 surf
->BufferAgeRead
= EGL_FALSE
;
1280 RETURN_EGL_EVAL(disp
, ret
);
1285 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1286 EGLint
*rects
, EGLint n_rects
)
1288 _EGLContext
*ctx
= _eglGetCurrentContext();
1292 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1294 /* surface must be bound to current context in EGL 1.4 */
1295 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1296 surf
!= ctx
->DrawSurface
)
1297 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1299 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1300 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1302 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1304 /* EGL_KHR_partial_update
1305 * Frame boundary successfully reached,
1306 * reset damage region and reset BufferAgeRead
1309 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1310 surf
->BufferAgeRead
= EGL_FALSE
;
1313 RETURN_EGL_EVAL(disp
, ret
);
1316 static EGLBoolean EGLAPIENTRY
1317 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1318 EGLint
*rects
, EGLint n_rects
)
1320 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1321 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1322 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1323 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1326 static EGLBoolean EGLAPIENTRY
1327 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1328 EGLint
*rects
, EGLint n_rects
)
1330 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1331 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1332 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1333 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1337 * Clamp the rectangles so that they lie within the surface.
1341 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1342 EGLint
*rects
, EGLint n_rects
)
1345 EGLint surf_height
= surf
->Height
;
1346 EGLint surf_width
= surf
->Width
;
1348 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1349 EGLint x1
, y1
, x2
, y2
;
1352 x2
= rects
[i
+ 2] + x1
;
1353 y2
= rects
[i
+ 3] + y1
;
1355 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1356 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1357 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1358 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1362 static EGLBoolean EGLAPIENTRY
1363 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1364 EGLint
*rects
, EGLint n_rects
)
1366 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1367 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1368 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1369 _EGLContext
*ctx
= _eglGetCurrentContext();
1372 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1374 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1375 surf
->Type
!= EGL_WINDOW_BIT
||
1376 ctx
->DrawSurface
!= surf
||
1377 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1378 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1380 /* If the damage region is already set or
1381 * buffer age is not queried between
1382 * frame boundaries, throw bad access error
1385 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1386 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1388 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1389 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1392 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1394 RETURN_EGL_EVAL(disp
, ret
);
1397 EGLBoolean EGLAPIENTRY
1398 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1400 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1401 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1404 void *native_pixmap_ptr
;
1406 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1407 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1408 native_pixmap_ptr
= (void*) target
;
1410 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1411 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1413 RETURN_EGL_EVAL(disp
, ret
);
1418 _eglWaitClientCommon(void)
1420 _EGLContext
*ctx
= _eglGetCurrentContext();
1426 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1428 disp
= ctx
->Resource
.Display
;
1429 mtx_lock(&disp
->Mutex
);
1431 /* let bad current context imply bad current surface */
1432 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1433 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1434 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1436 /* a valid current context implies an initialized current display */
1437 assert(disp
->Initialized
);
1439 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1441 RETURN_EGL_EVAL(disp
, ret
);
1444 EGLBoolean EGLAPIENTRY
1447 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1448 return _eglWaitClientCommon();
1451 EGLBoolean EGLAPIENTRY
1454 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1455 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1456 return _eglWaitClientCommon();
1460 EGLBoolean EGLAPIENTRY
1461 eglWaitNative(EGLint engine
)
1463 _EGLContext
*ctx
= _eglGetCurrentContext();
1469 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1471 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1473 disp
= ctx
->Resource
.Display
;
1474 mtx_lock(&disp
->Mutex
);
1476 /* let bad current context imply bad current surface */
1477 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1478 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1479 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1481 /* a valid current context implies an initialized current display */
1482 assert(disp
->Initialized
);
1484 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1486 RETURN_EGL_EVAL(disp
, ret
);
1490 EGLDisplay EGLAPIENTRY
1491 eglGetCurrentDisplay(void)
1493 _EGLContext
*ctx
= _eglGetCurrentContext();
1496 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1498 RETURN_EGL_SUCCESS(NULL
, ret
);
1502 EGLContext EGLAPIENTRY
1503 eglGetCurrentContext(void)
1505 _EGLContext
*ctx
= _eglGetCurrentContext();
1508 ret
= _eglGetContextHandle(ctx
);
1510 RETURN_EGL_SUCCESS(NULL
, ret
);
1514 EGLSurface EGLAPIENTRY
1515 eglGetCurrentSurface(EGLint readdraw
)
1517 _EGLContext
*ctx
= _eglGetCurrentContext();
1518 EGLint err
= EGL_SUCCESS
;
1522 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1525 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1529 surf
= ctx
->DrawSurface
;
1532 surf
= ctx
->ReadSurface
;
1536 err
= EGL_BAD_PARAMETER
;
1540 ret
= _eglGetSurfaceHandle(surf
);
1542 RETURN_EGL_ERROR(NULL
, err
, ret
);
1549 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1550 EGLint e
= t
->LastError
;
1551 if (!_eglIsCurrentThreadDummy())
1552 t
->LastError
= EGL_SUCCESS
;
1562 * Specify the client API to use for subsequent calls including:
1563 * eglCreateContext()
1564 * eglGetCurrentContext()
1565 * eglGetCurrentDisplay()
1566 * eglGetCurrentSurface()
1567 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1570 * See section 3.7 "Rendering Context" in the EGL specification for details.
1572 EGLBoolean EGLAPIENTRY
1573 eglBindAPI(EGLenum api
)
1577 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1579 t
= _eglGetCurrentThread();
1580 if (_eglIsCurrentThreadDummy())
1581 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1583 if (!_eglIsApiValid(api
))
1584 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1586 t
->CurrentAPI
= api
;
1588 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1593 * Return the last value set with eglBindAPI().
1598 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1601 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1602 ret
= t
->CurrentAPI
;
1604 RETURN_EGL_SUCCESS(NULL
, ret
);
1608 EGLSurface EGLAPIENTRY
1609 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1610 EGLClientBuffer buffer
, EGLConfig config
,
1611 const EGLint
*attrib_list
)
1613 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1614 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1619 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1621 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1623 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1625 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1627 RETURN_EGL_EVAL(disp
, ret
);
1631 EGLBoolean EGLAPIENTRY
1632 eglReleaseThread(void)
1634 /* unbind current contexts */
1635 if (!_eglIsCurrentThreadDummy()) {
1636 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1637 _EGLContext
*ctx
= t
->CurrentContext
;
1639 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1642 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1645 mtx_lock(&disp
->Mutex
);
1647 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1648 mtx_unlock(&disp
->Mutex
);
1652 _eglDestroyCurrentThread();
1654 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1659 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1660 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1662 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1667 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1668 if (!disp
->Extensions
.KHR_image_base
)
1669 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1670 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1671 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1672 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1673 * <ctx> must be EGL_NO_CONTEXT..."
1675 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1676 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1678 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1680 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1682 RETURN_EGL_EVAL(disp
, ret
);
1685 static EGLImage EGLAPIENTRY
1686 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1687 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1689 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1690 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1691 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1695 EGLImage EGLAPIENTRY
1696 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1697 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1699 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1701 EGLint
*int_attribs
;
1703 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1705 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1706 if (attr_list
&& !int_attribs
)
1707 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1709 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1716 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1721 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1722 if (!disp
->Extensions
.KHR_image_base
)
1723 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1725 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1727 _eglUnlinkImage(img
);
1728 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1730 RETURN_EGL_EVAL(disp
, ret
);
1733 EGLBoolean EGLAPIENTRY
1734 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1736 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1737 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1738 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1739 return _eglDestroyImageCommon(disp
, img
);
1742 static EGLBoolean EGLAPIENTRY
1743 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1745 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1746 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1747 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1748 return _eglDestroyImageCommon(disp
, img
);
1753 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1754 EGLBoolean orig_is_EGLAttrib
,
1755 EGLenum invalid_type_error
)
1757 _EGLContext
*ctx
= _eglGetCurrentContext();
1762 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1764 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1765 /* There exist two EGLAttrib variants of eglCreateSync*:
1766 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1767 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1768 * support as a proxy for EGL 1.5 support, even though that's not
1769 * entirely correct (though _eglComputeVersion does the same).
1771 * The EGL spec provides no guidance on how to handle unsupported
1772 * functions. EGL_BAD_MATCH seems reasonable.
1774 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1777 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1778 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1779 * error is generated.
1782 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1783 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1785 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1786 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1787 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1788 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1791 case EGL_SYNC_FENCE_KHR
:
1792 if (!disp
->Extensions
.KHR_fence_sync
)
1793 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1795 case EGL_SYNC_REUSABLE_KHR
:
1796 if (!disp
->Extensions
.KHR_reusable_sync
)
1797 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1799 case EGL_SYNC_CL_EVENT_KHR
:
1800 if (!disp
->Extensions
.KHR_cl_event2
)
1801 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1803 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1804 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1805 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1808 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1811 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1812 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1814 RETURN_EGL_EVAL(disp
, ret
);
1818 static EGLSync EGLAPIENTRY
1819 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1821 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1822 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1825 EGLAttrib
*attrib_list
;
1828 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1829 attrib_list
= (EGLAttrib
*) int_list
;
1831 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1832 if (err
!= EGL_SUCCESS
)
1833 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1836 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1839 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1842 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1847 static EGLSync EGLAPIENTRY
1848 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1850 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1851 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1852 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1858 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1860 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1861 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1862 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1868 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1873 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1874 assert(disp
->Extensions
.KHR_reusable_sync
||
1875 disp
->Extensions
.KHR_fence_sync
||
1876 disp
->Extensions
.ANDROID_native_fence_sync
);
1879 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1881 RETURN_EGL_EVAL(disp
, ret
);
1884 EGLBoolean EGLAPIENTRY
1885 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1887 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1888 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1889 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1890 return _eglDestroySync(disp
, s
);
1893 static EGLBoolean EGLAPIENTRY
1894 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1896 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1897 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1898 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1899 return _eglDestroySync(disp
, s
);
1904 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1905 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1910 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1911 assert(disp
->Extensions
.KHR_reusable_sync
||
1912 disp
->Extensions
.KHR_fence_sync
||
1913 disp
->Extensions
.ANDROID_native_fence_sync
);
1915 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1916 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1918 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1919 * unlocked here to allow other threads also to be able to
1920 * go into waiting state.
1923 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1924 _eglUnlockDisplay(dpy
);
1926 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1929 * 'disp' is already unlocked for reusable sync type,
1930 * so passing 'NULL' to bypass unlocking display.
1932 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1933 RETURN_EGL_EVAL(NULL
, ret
);
1935 RETURN_EGL_EVAL(disp
, ret
);
1939 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
1940 EGLint flags
, EGLTime timeout
)
1942 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1943 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1944 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1945 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1948 static EGLint EGLAPIENTRY
1949 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
1950 EGLint flags
, EGLTime timeout
)
1952 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1953 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1954 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1955 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1960 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
1962 _EGLContext
*ctx
= _eglGetCurrentContext();
1966 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1967 assert(disp
->Extensions
.KHR_wait_sync
);
1969 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1970 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1971 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1973 /* the API doesn't allow any flags yet */
1975 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1977 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1979 RETURN_EGL_EVAL(disp
, ret
);
1982 static EGLint EGLAPIENTRY
1983 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1985 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1986 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1987 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1988 return _eglWaitSyncCommon(disp
, s
, flags
);
1992 EGLBoolean EGLAPIENTRY
1993 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1995 /* The KHR version returns EGLint, while the core version returns
1996 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1999 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2000 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2001 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2002 return _eglWaitSyncCommon(disp
, s
, flags
);
2006 static EGLBoolean EGLAPIENTRY
2007 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2009 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2010 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2014 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2016 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2017 assert(disp
->Extensions
.KHR_reusable_sync
);
2018 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2020 RETURN_EGL_EVAL(disp
, ret
);
2025 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2030 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2031 assert(disp
->Extensions
.KHR_reusable_sync
||
2032 disp
->Extensions
.KHR_fence_sync
||
2033 disp
->Extensions
.ANDROID_native_fence_sync
);
2034 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2036 RETURN_EGL_EVAL(disp
, ret
);
2039 EGLBoolean EGLAPIENTRY
2040 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2042 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2043 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2044 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2045 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2049 static EGLBoolean EGLAPIENTRY
2050 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2052 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2053 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2057 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2060 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2063 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2065 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2067 * If any error occurs, <*value> is not modified.
2069 if (result
== EGL_FALSE
)
2076 static EGLint EGLAPIENTRY
2077 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2079 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2080 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2084 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2086 /* the spec doesn't seem to specify what happens if the fence
2087 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2090 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2091 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2093 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2094 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2095 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2097 RETURN_EGL_EVAL(disp
, ret
);
2100 static EGLBoolean EGLAPIENTRY
2101 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2102 EGLint numRects
, const EGLint
*rects
)
2104 _EGLContext
*ctx
= _eglGetCurrentContext();
2105 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2106 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2110 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2112 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2114 if (!disp
->Extensions
.NOK_swap_region
)
2115 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2117 /* surface must be bound to current context in EGL 1.4 */
2118 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2119 surf
!= ctx
->DrawSurface
)
2120 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2122 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2124 RETURN_EGL_EVAL(disp
, ret
);
2128 static EGLImage EGLAPIENTRY
2129 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2131 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2136 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2138 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2139 if (!disp
->Extensions
.MESA_drm_image
)
2140 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2142 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2143 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2145 RETURN_EGL_EVAL(disp
, ret
);
2148 static EGLBoolean EGLAPIENTRY
2149 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2150 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2152 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2153 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2157 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2159 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2160 assert(disp
->Extensions
.MESA_drm_image
);
2163 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2165 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2167 RETURN_EGL_EVAL(disp
, ret
);
2173 static EGLBoolean EGLAPIENTRY
2174 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2176 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2180 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2182 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2183 assert(disp
->Extensions
.WL_bind_wayland_display
);
2186 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2188 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2190 RETURN_EGL_EVAL(disp
, ret
);
2193 static EGLBoolean EGLAPIENTRY
2194 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2196 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2200 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2202 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2203 assert(disp
->Extensions
.WL_bind_wayland_display
);
2206 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2208 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2210 RETURN_EGL_EVAL(disp
, ret
);
2213 static EGLBoolean EGLAPIENTRY
2214 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2215 EGLint attribute
, EGLint
*value
)
2217 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2221 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2223 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2224 assert(disp
->Extensions
.WL_bind_wayland_display
);
2227 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2229 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2231 RETURN_EGL_EVAL(disp
, ret
);
2235 static struct wl_buffer
* EGLAPIENTRY
2236 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2238 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2241 struct wl_buffer
*ret
;
2243 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2245 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2246 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2247 RETURN_EGL_EVAL(disp
, NULL
);
2249 img
= _eglLookupImage(image
, disp
);
2252 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2254 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2256 RETURN_EGL_EVAL(disp
, ret
);
2259 static EGLBoolean EGLAPIENTRY
2260 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2261 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2263 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2264 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2268 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2270 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2272 if (!disp
->Extensions
.NV_post_sub_buffer
)
2273 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2275 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2277 RETURN_EGL_EVAL(disp
, ret
);
2280 static EGLBoolean EGLAPIENTRY
2281 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
2282 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2285 _EGLDisplay
*disp
= _eglLockDisplay(display
);
2286 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2290 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2292 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2293 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2294 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2296 if (!ust
|| !msc
|| !sbc
)
2297 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2299 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2301 RETURN_EGL_EVAL(disp
, ret
);
2304 static EGLBoolean EGLAPIENTRY
2305 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2306 EGLint
*fourcc
, EGLint
*nplanes
,
2307 EGLuint64KHR
*modifiers
)
2309 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2310 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2314 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2316 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2317 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2320 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2322 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2325 RETURN_EGL_EVAL(disp
, ret
);
2328 static EGLBoolean EGLAPIENTRY
2329 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2330 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2332 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2333 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2337 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2339 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2340 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2343 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2345 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2347 RETURN_EGL_EVAL(disp
, ret
);
2350 static EGLint EGLAPIENTRY
2351 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2354 _EGLDisplay
*disp
= NULL
;
2355 _EGLResourceType type
;
2357 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2359 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2360 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2362 if (!_eglIsCurrentThreadDummy()) {
2367 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2370 disp
= _eglLockDisplay(dpy
);
2372 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2374 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2375 if (dpy
!= (EGLDisplay
) object
)
2376 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2378 disp
->Label
= label
;
2379 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2382 switch (objectType
) {
2383 case EGL_OBJECT_CONTEXT_KHR
:
2384 type
= _EGL_RESOURCE_CONTEXT
;
2386 case EGL_OBJECT_SURFACE_KHR
:
2387 type
= _EGL_RESOURCE_SURFACE
;
2389 case EGL_OBJECT_IMAGE_KHR
:
2390 type
= _EGL_RESOURCE_IMAGE
;
2392 case EGL_OBJECT_SYNC_KHR
:
2393 type
= _EGL_RESOURCE_SYNC
;
2395 case EGL_OBJECT_STREAM_KHR
:
2397 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2400 if (_eglCheckResource(object
, type
, disp
)) {
2401 _EGLResource
*res
= (_EGLResource
*) object
;
2404 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2407 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2410 static EGLint EGLAPIENTRY
2411 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2412 const EGLAttrib
*attrib_list
)
2414 unsigned int newEnabled
;
2416 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2418 mtx_lock(_eglGlobal
.Mutex
);
2420 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2421 if (attrib_list
!= NULL
) {
2424 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2425 switch (attrib_list
[i
]) {
2426 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2427 case EGL_DEBUG_MSG_ERROR_KHR
:
2428 case EGL_DEBUG_MSG_WARN_KHR
:
2429 case EGL_DEBUG_MSG_INFO_KHR
:
2430 if (attrib_list
[i
+ 1])
2431 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2433 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2436 // On error, set the last error code, call the current
2437 // debug callback, and return the error code.
2438 mtx_unlock(_eglGlobal
.Mutex
);
2439 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2440 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2441 return EGL_BAD_ATTRIBUTE
;
2446 if (callback
!= NULL
) {
2447 _eglGlobal
.debugCallback
= callback
;
2448 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2450 _eglGlobal
.debugCallback
= NULL
;
2451 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2454 mtx_unlock(_eglGlobal
.Mutex
);
2458 static EGLBoolean EGLAPIENTRY
2459 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2461 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2463 mtx_lock(_eglGlobal
.Mutex
);
2465 switch (attribute
) {
2466 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2467 case EGL_DEBUG_MSG_ERROR_KHR
:
2468 case EGL_DEBUG_MSG_WARN_KHR
:
2469 case EGL_DEBUG_MSG_INFO_KHR
:
2470 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2475 case EGL_DEBUG_CALLBACK_KHR
:
2476 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2479 mtx_unlock(_eglGlobal
.Mutex
);
2480 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2481 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2485 mtx_unlock(_eglGlobal
.Mutex
);
2490 _eglFunctionCompare(const void *key
, const void *elem
)
2492 const char *procname
= key
;
2493 const struct _egl_entrypoint
*entrypoint
= elem
;
2494 return strcmp(procname
, entrypoint
->name
);
2497 static EGLBoolean EGLAPIENTRY
2498 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2499 EGLint
*formats
, EGLint
*num_formats
)
2501 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2505 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2507 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2509 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2512 RETURN_EGL_EVAL(disp
, ret
);
2515 static EGLBoolean EGLAPIENTRY
2516 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2517 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2518 EGLint
*num_modifiers
)
2520 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2524 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2526 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2528 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2529 modifiers
, external_only
,
2532 RETURN_EGL_EVAL(disp
, ret
);
2535 static void EGLAPIENTRY
2536 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2537 EGLGetBlobFuncANDROID get
)
2539 /* This function does not return anything so we cannot
2540 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2542 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2543 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2545 _eglUnlockDisplay(disp
);
2549 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2552 _eglUnlockDisplay(disp
);
2557 _eglError(EGL_BAD_PARAMETER
,
2558 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2559 _eglUnlockDisplay(disp
);
2563 if (disp
->BlobCacheSet
) {
2564 _eglError(EGL_BAD_PARAMETER
,
2565 "eglSetBlobCacheFuncsANDROID: functions already set");
2566 _eglUnlockDisplay(disp
);
2570 disp
->BlobCacheSet
= set
;
2571 disp
->BlobCacheGet
= get
;
2573 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2575 _eglUnlockDisplay(disp
);
2578 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2579 eglGetProcAddress(const char *procname
)
2581 static const struct _egl_entrypoint egl_functions
[] = {
2582 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2583 #include "eglentrypoint.h"
2584 #undef EGL_ENTRYPOINT
2586 _EGLProc ret
= NULL
;
2589 RETURN_EGL_SUCCESS(NULL
, NULL
);
2591 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2593 if (strncmp(procname
, "egl", 3) == 0) {
2594 const struct _egl_entrypoint
*entrypoint
=
2596 egl_functions
, ARRAY_SIZE(egl_functions
),
2597 sizeof(egl_functions
[0]),
2598 _eglFunctionCompare
);
2600 ret
= entrypoint
->function
;
2604 ret
= _eglGetDriverProc(procname
);
2606 RETURN_EGL_SUCCESS(NULL
, ret
);
2610 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2611 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2615 *disp
= _eglLockDisplay(dpy
);
2616 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2618 _eglUnlockDisplay(*disp
);
2619 return MESA_GLINTEROP_INVALID_DISPLAY
;
2622 *drv
= (*disp
)->Driver
;
2624 *ctx
= _eglLookupContext(context
, *disp
);
2626 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2627 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2628 _eglUnlockDisplay(*disp
);
2629 return MESA_GLINTEROP_INVALID_CONTEXT
;
2632 return MESA_GLINTEROP_SUCCESS
;
2636 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2637 struct mesa_glinterop_device_info
*out
)
2644 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2645 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2648 if (drv
->API
.GLInteropQueryDeviceInfo
)
2649 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2651 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2653 _eglUnlockDisplay(disp
);
2658 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2659 struct mesa_glinterop_export_in
*in
,
2660 struct mesa_glinterop_export_out
*out
)
2667 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2668 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2671 if (drv
->API
.GLInteropExportObject
)
2672 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2674 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2676 _eglUnlockDisplay(disp
);