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
95 #include "c99_compat.h"
96 #include "c11/threads.h"
97 #include "util/macros.h"
100 #include "egldefines.h"
101 #include "eglglobals.h"
102 #include "eglcontext.h"
103 #include "egldisplay.h"
104 #include "egltypedefs.h"
105 #include "eglcurrent.h"
106 #include "egldevice.h"
107 #include "egldriver.h"
108 #include "eglsurface.h"
109 #include "eglconfig.h"
110 #include "eglimage.h"
113 #include "GL/mesa_glinterop.h"
116 * Macros to help return an API entrypoint.
118 * These macros will unlock the display and record the error code.
120 #define RETURN_EGL_ERROR(disp, err, ret) \
123 _eglUnlockDisplay(disp); \
124 /* EGL error codes are non-zero */ \
126 _eglError(err, __func__); \
130 #define RETURN_EGL_SUCCESS(disp, ret) \
131 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
133 /* record EGL_SUCCESS only when ret evaluates to true */
134 #define RETURN_EGL_EVAL(disp, ret) \
135 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
139 * A bunch of macros and checks to simplify error checking.
142 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
144 drv = _eglCheckDisplay(disp, __func__); \
146 RETURN_EGL_ERROR(disp, 0, ret); \
149 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
151 drv = _eglCheck ## type(disp, obj, __func__); \
153 RETURN_EGL_ERROR(disp, 0, ret); \
156 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
157 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
159 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
160 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
162 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
163 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
165 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
166 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
169 struct _egl_entrypoint
{
175 static inline _EGLDriver
*
176 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
179 _eglError(EGL_BAD_DISPLAY
, msg
);
182 if (!disp
->Initialized
) {
183 _eglError(EGL_NOT_INITIALIZED
, msg
);
190 static inline _EGLDriver
*
191 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
193 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
197 _eglError(EGL_BAD_SURFACE
, msg
);
204 static inline _EGLDriver
*
205 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
207 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
211 _eglError(EGL_BAD_CONTEXT
, msg
);
218 static inline _EGLDriver
*
219 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
221 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
225 _eglError(EGL_BAD_CONFIG
, msg
);
232 static inline _EGLDriver
*
233 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
235 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
239 _eglError(EGL_BAD_PARAMETER
, msg
);
247 * Lookup and lock a display.
249 static inline _EGLDisplay
*
250 _eglLockDisplay(EGLDisplay dpy
)
252 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
254 mtx_lock(&disp
->Mutex
);
263 _eglUnlockDisplay(_EGLDisplay
*disp
)
265 mtx_unlock(&disp
->Mutex
);
269 _eglSetFuncName(const char *funcName
, _EGLDisplay
*disp
, EGLenum objectType
, _EGLResource
*object
)
271 _EGLThreadInfo
*thr
= _eglGetCurrentThread();
272 if (!_eglIsCurrentThreadDummy()) {
273 thr
->CurrentFuncName
= funcName
;
274 thr
->CurrentObjectLabel
= NULL
;
276 if (objectType
== EGL_OBJECT_THREAD_KHR
)
277 thr
->CurrentObjectLabel
= thr
->Label
;
278 else if (objectType
== EGL_OBJECT_DISPLAY_KHR
&& disp
)
279 thr
->CurrentObjectLabel
= disp
->Label
;
281 thr
->CurrentObjectLabel
= object
->Label
;
286 _eglDebugReport(EGL_BAD_ALLOC
, funcName
, EGL_DEBUG_MSG_CRITICAL_KHR
, NULL
);
290 #define _EGL_FUNC_START(disp, objectType, object, ret) \
292 if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \
294 _eglUnlockDisplay(disp); \
300 * Convert an attribute list from EGLint[] to EGLAttrib[].
302 * Return an EGL error code. The output parameter out_attrib_list is modified
306 _eglConvertIntsToAttribs(const EGLint
*int_list
, EGLAttrib
**out_attrib_list
)
309 EGLAttrib
*attrib_list
;
312 while (int_list
[2*len
] != EGL_NONE
)
317 *out_attrib_list
= NULL
;
321 if (2*len
+ 1 > SIZE_MAX
/ sizeof(EGLAttrib
))
322 return EGL_BAD_ALLOC
;
324 attrib_list
= malloc((2*len
+ 1) * sizeof(EGLAttrib
));
326 return EGL_BAD_ALLOC
;
328 for (size_t i
= 0; i
< len
; ++i
) {
329 attrib_list
[2*i
+ 0] = int_list
[2*i
+ 0];
330 attrib_list
[2*i
+ 1] = int_list
[2*i
+ 1];
333 attrib_list
[2*len
] = EGL_NONE
;
335 *out_attrib_list
= attrib_list
;
341 _eglConvertAttribsToInt(const EGLAttrib
*attr_list
)
343 size_t size
= _eglNumAttribs(attr_list
);
344 EGLint
*int_attribs
= NULL
;
346 /* Convert attributes from EGLAttrib[] to EGLint[] */
348 int_attribs
= calloc(size
, sizeof(int_attribs
[0]));
352 for (size_t i
= 0; i
< size
; i
++)
353 int_attribs
[i
] = attr_list
[i
];
360 * This is typically the first EGL function that an application calls.
361 * It associates a private _EGLDisplay object to the native display.
363 EGLDisplay EGLAPIENTRY
364 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
366 _EGLPlatformType plat
;
368 void *native_display_ptr
;
370 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
372 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
373 native_display_ptr
= (void*) nativeDisplay
;
375 plat
= _eglGetNativePlatform(native_display_ptr
);
376 disp
= _eglFindDisplay(plat
, native_display_ptr
, NULL
);
377 return _eglGetDisplayHandle(disp
);
381 _eglGetPlatformDisplayCommon(EGLenum platform
, void *native_display
,
382 const EGLAttrib
*attrib_list
)
387 #ifdef HAVE_X11_PLATFORM
388 case EGL_PLATFORM_X11_EXT
:
389 disp
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
392 #ifdef HAVE_DRM_PLATFORM
393 case EGL_PLATFORM_GBM_MESA
:
394 disp
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
398 #ifdef HAVE_WAYLAND_PLATFORM
399 case EGL_PLATFORM_WAYLAND_EXT
:
400 disp
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
404 case EGL_PLATFORM_SURFACELESS_MESA
:
405 disp
= _eglGetSurfacelessDisplay(native_display
, attrib_list
);
407 #ifdef HAVE_ANDROID_PLATFORM
408 case EGL_PLATFORM_ANDROID_KHR
:
409 disp
= _eglGetAndroidDisplay(native_display
, attrib_list
);
412 case EGL_PLATFORM_DEVICE_EXT
:
413 disp
= _eglGetDeviceDisplay(native_display
, attrib_list
);
416 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
419 return _eglGetDisplayHandle(disp
);
422 static EGLDisplay EGLAPIENTRY
423 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
424 const EGLint
*int_attribs
)
426 EGLAttrib
*attrib_list
;
429 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
431 if (_eglConvertIntsToAttribs(int_attribs
, &attrib_list
) != EGL_SUCCESS
)
432 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
434 disp
= _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
439 EGLDisplay EGLAPIENTRY
440 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
441 const EGLAttrib
*attrib_list
)
443 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
444 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
448 * Copy the extension into the string and update the string pointer.
451 _eglAppendExtension(char **str
, const char *ext
)
454 size_t len
= strlen(ext
);
471 * Examine the individual extension enable/disable flags and recompute
472 * the driver's Extensions string.
475 _eglCreateExtensionsString(_EGLDisplay
*disp
)
477 #define _EGL_CHECK_EXTENSION(ext) \
479 if (disp->Extensions.ext) { \
480 _eglAppendExtension(&exts, "EGL_" #ext); \
481 assert(exts <= disp->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
485 char *exts
= disp
->ExtensionsString
;
487 /* Please keep these sorted alphabetically. */
488 _EGL_CHECK_EXTENSION(ANDROID_blob_cache
);
489 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
490 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
491 _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync
);
492 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
494 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
496 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
497 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
498 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
499 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers
);
500 _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata
);
501 _EGL_CHECK_EXTENSION(EXT_surface_SMPTE2086_metadata
);
502 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
504 _EGL_CHECK_EXTENSION(IMG_context_priority
);
506 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
507 _EGL_CHECK_EXTENSION(KHR_config_attribs
);
508 _EGL_CHECK_EXTENSION(KHR_context_flush_control
);
509 _EGL_CHECK_EXTENSION(KHR_create_context
);
510 _EGL_CHECK_EXTENSION(KHR_create_context_no_error
);
511 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
512 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
513 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
514 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
515 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
516 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
517 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
518 if (disp
->Extensions
.KHR_image_base
&& disp
->Extensions
.KHR_image_pixmap
)
519 disp
->Extensions
.KHR_image
= EGL_TRUE
;
520 _EGL_CHECK_EXTENSION(KHR_image
);
521 _EGL_CHECK_EXTENSION(KHR_image_base
);
522 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
523 _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer
);
524 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
525 _EGL_CHECK_EXTENSION(KHR_partial_update
);
526 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
527 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
528 if (disp
->Extensions
.EXT_swap_buffers_with_damage
)
529 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
530 _EGL_CHECK_EXTENSION(EXT_pixel_format_float
);
531 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
533 if (disp
->Extensions
.KHR_no_config_context
)
534 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
535 _EGL_CHECK_EXTENSION(MESA_drm_image
);
536 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
537 _EGL_CHECK_EXTENSION(MESA_query_driver
);
539 _EGL_CHECK_EXTENSION(NOK_swap_region
);
540 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
542 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
544 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
545 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
547 #undef _EGL_CHECK_EXTENSION
551 _eglCreateAPIsString(_EGLDisplay
*disp
)
553 #define addstr(str) \
555 const size_t old_len = strlen(disp->ClientAPIsString); \
556 const size_t add_len = sizeof(str); \
557 const size_t max_len = sizeof(disp->ClientAPIsString) - 1; \
558 if (old_len + add_len <= max_len) \
559 strcat(disp->ClientAPIsString, str " "); \
561 assert(!"disp->ClientAPIsString is not large enough"); \
564 if (disp
->ClientAPIs
& EGL_OPENGL_BIT
)
567 if (disp
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
568 disp
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
569 disp
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
573 if (disp
->ClientAPIs
& EGL_OPENVG_BIT
)
580 _eglComputeVersion(_EGLDisplay
*disp
)
584 if (disp
->Extensions
.KHR_fence_sync
&&
585 disp
->Extensions
.KHR_cl_event2
&&
586 disp
->Extensions
.KHR_wait_sync
&&
587 disp
->Extensions
.KHR_image_base
&&
588 disp
->Extensions
.KHR_gl_texture_2D_image
&&
589 disp
->Extensions
.KHR_gl_texture_3D_image
&&
590 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
591 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
592 disp
->Extensions
.KHR_create_context
&&
593 disp
->Extensions
.EXT_create_context_robustness
&&
594 disp
->Extensions
.KHR_get_all_proc_addresses
&&
595 disp
->Extensions
.KHR_gl_colorspace
&&
596 disp
->Extensions
.KHR_surfaceless_context
)
599 /* For Android P and below limit the EGL version to 1.4 */
600 #if defined(ANDROID) && ANDROID_API_LEVEL <= 28
606 * This is typically the second EGL function that an application calls.
607 * Here we load/initialize the actual hardware driver.
609 EGLBoolean EGLAPIENTRY
610 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
612 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
614 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
617 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
619 if (!disp
->Initialized
) {
620 if (!_eglMatchDriver(disp
))
621 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
623 /* limit to APIs supported by core */
624 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
626 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
627 * classifies it as an EGL display extension, though conceptually it's an
628 * EGL client extension.
630 * From the EGL_KHR_get_all_proc_addresses spec:
632 * The EGL implementation must expose the name
633 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
634 * EGL_KHR_get_all_proc_addresses and supports
635 * EGL_EXT_client_extensions.
637 * Mesa unconditionally exposes both client extensions mentioned above,
638 * so the spec requires that each EGLDisplay unconditionally expose
639 * EGL_KHR_get_all_proc_addresses also.
641 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
643 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
644 * programs. It is driver agnostic and handled in the main EGL code.
646 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
648 _eglComputeVersion(disp
);
649 _eglCreateExtensionsString(disp
);
650 _eglCreateAPIsString(disp
);
651 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
652 "%d.%d", disp
->Version
/ 10, disp
->Version
% 10);
655 /* Update applications version of major and minor if not NULL */
656 if ((major
!= NULL
) && (minor
!= NULL
)) {
657 *major
= disp
->Version
/ 10;
658 *minor
= disp
->Version
% 10;
661 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
665 EGLBoolean EGLAPIENTRY
666 eglTerminate(EGLDisplay dpy
)
668 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
670 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
673 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
675 if (disp
->Initialized
) {
676 _EGLDriver
*drv
= disp
->Driver
;
678 drv
->API
.Terminate(drv
, disp
);
679 /* do not reset disp->Driver */
680 disp
->ClientAPIsString
[0] = 0;
681 disp
->Initialized
= EGL_FALSE
;
683 /* Reset blob cache funcs on terminate. */
684 disp
->BlobCacheSet
= NULL
;
685 disp
->BlobCacheGet
= NULL
;
688 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
692 const char * EGLAPIENTRY
693 eglQueryString(EGLDisplay dpy
, EGLint name
)
699 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
700 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
704 disp
= _eglLockDisplay(dpy
);
705 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
706 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
710 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
712 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
714 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
715 case EGL_CLIENT_APIS
:
716 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
718 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
723 EGLBoolean EGLAPIENTRY
724 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
725 EGLint config_size
, EGLint
*num_config
)
727 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
731 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
733 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
736 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
738 ret
= _eglGetConfigs(drv
, disp
, configs
, config_size
, num_config
);
740 RETURN_EGL_EVAL(disp
, ret
);
744 EGLBoolean EGLAPIENTRY
745 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
746 EGLint config_size
, EGLint
*num_config
)
748 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
752 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
754 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
757 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
759 ret
= _eglChooseConfig(drv
, disp
, attrib_list
, configs
,
760 config_size
, num_config
);
762 RETURN_EGL_EVAL(disp
, ret
);
766 EGLBoolean EGLAPIENTRY
767 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
768 EGLint attribute
, EGLint
*value
)
770 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
771 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
775 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
777 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
779 ret
= _eglGetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
781 RETURN_EGL_EVAL(disp
, ret
);
785 EGLContext EGLAPIENTRY
786 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
787 const EGLint
*attrib_list
)
789 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
790 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
791 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
793 _EGLContext
*context
;
796 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
798 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
800 if (config
!= EGL_NO_CONFIG_KHR
)
801 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
802 else if (!disp
->Extensions
.KHR_no_config_context
)
803 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
805 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
806 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
808 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
809 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
811 RETURN_EGL_EVAL(disp
, ret
);
815 EGLBoolean EGLAPIENTRY
816 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
818 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
819 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
823 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
825 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
826 _eglUnlinkContext(context
);
827 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
829 RETURN_EGL_EVAL(disp
, ret
);
833 EGLBoolean EGLAPIENTRY
834 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
837 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
838 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
839 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
840 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
844 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
847 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
850 /* display is allowed to be uninitialized under certain condition */
851 if (!disp
->Initialized
) {
852 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
853 ctx
!= EGL_NO_CONTEXT
)
854 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
857 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
859 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
860 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
861 if (!draw_surf
|| !read_surf
) {
862 /* From the EGL 1.4 (20130211) spec:
864 * To release the current context without assigning a new one, set ctx
865 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
867 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
868 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
870 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
871 (!read_surf
&& read
!= EGL_NO_SURFACE
))
872 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
873 if (draw_surf
|| read_surf
)
874 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
877 /* If a native window underlying either draw or read is no longer valid,
878 * an EGL_BAD_NATIVE_WINDOW error is generated.
880 if (draw_surf
&& draw_surf
->Lost
)
881 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
882 if (read_surf
&& read_surf
->Lost
)
883 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
885 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
887 RETURN_EGL_EVAL(disp
, ret
);
891 EGLBoolean EGLAPIENTRY
892 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
893 EGLint attribute
, EGLint
*value
)
895 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
896 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
900 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
902 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
904 ret
= _eglQueryContext(drv
, disp
, context
, attribute
, value
);
906 RETURN_EGL_EVAL(disp
, ret
);
910 /* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says
911 * that if native_surface was already used to create a window or pixmap, we
912 * can't create a new one. This is what this function checks for.
915 _eglNativeSurfaceAlreadyUsed(_EGLDisplay
*disp
, void *native_surface
)
919 list
= disp
->ResourceLists
[_EGL_RESOURCE_SURFACE
];
921 _EGLSurface
*surf
= (_EGLSurface
*) list
;
925 if (surf
->Type
== EGL_PBUFFER_BIT
)
928 if (surf
->NativeSurface
== native_surface
)
937 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
938 void *native_window
, const EGLint
*attrib_list
)
940 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
946 if (native_window
== NULL
)
947 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
949 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
950 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
951 /* From the EGL_MESA_platform_surfaceless spec (v1):
953 * eglCreatePlatformWindowSurface fails when called with a <display>
954 * that belongs to the surfaceless platform. It returns
955 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
956 * justification for this unconditional failure is that the
957 * surfaceless platform has no native windows, and therefore the
958 * <native_window> parameter is always invalid.
960 * This check must occur before checking the EGLConfig, which emits
963 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
966 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
968 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
969 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
971 if (_eglNativeSurfaceAlreadyUsed(disp
, native_window
))
972 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
974 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
976 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
978 RETURN_EGL_EVAL(disp
, ret
);
982 EGLSurface EGLAPIENTRY
983 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
984 EGLNativeWindowType window
, const EGLint
*attrib_list
)
986 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
988 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
989 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
990 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
995 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
997 #ifdef HAVE_X11_PLATFORM
998 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
999 /* The `native_window` parameter for the X11 platform differs between
1000 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1001 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
1002 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
1003 * `Window*`. Convert `Window*` to `Window` because that's what
1004 * dri2_x11_create_window_surface() expects.
1006 return (void *)(* (Window
*) native_window
);
1009 return native_window
;
1012 static EGLSurface EGLAPIENTRY
1013 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1014 void *native_window
,
1015 const EGLint
*attrib_list
)
1017 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1019 native_window
= _fixupNativeWindow(disp
, native_window
);
1021 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1022 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1027 EGLSurface EGLAPIENTRY
1028 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
1029 void *native_window
,
1030 const EGLAttrib
*attrib_list
)
1032 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1034 EGLint
*int_attribs
;
1036 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1038 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1039 if (attrib_list
&& !int_attribs
)
1040 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1042 native_window
= _fixupNativeWindow(disp
, native_window
);
1043 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1050 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
1052 #ifdef HAVE_X11_PLATFORM
1053 /* The `native_pixmap` parameter for the X11 platform differs between
1054 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1055 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1056 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1057 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1058 * dri2_x11_create_pixmap_surface() expects.
1060 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
1061 return (void *)(* (Pixmap
*) native_pixmap
);
1063 return native_pixmap
;
1067 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1068 void *native_pixmap
, const EGLint
*attrib_list
)
1070 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1075 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
1076 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
1077 /* From the EGL_MESA_platform_surfaceless spec (v1):
1079 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1080 * also fails when called with a <display> that belongs to the
1081 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1082 * EGL_BAD_NATIVE_PIXMAP.
1084 * This check must occur before checking the EGLConfig, which emits
1087 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1090 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1092 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1093 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1095 if (native_pixmap
== NULL
)
1096 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1098 if (_eglNativeSurfaceAlreadyUsed(disp
, native_pixmap
))
1099 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1101 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1103 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1105 RETURN_EGL_EVAL(disp
, ret
);
1109 EGLSurface EGLAPIENTRY
1110 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1111 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1113 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1115 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1116 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1117 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1121 static EGLSurface EGLAPIENTRY
1122 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1123 void *native_pixmap
,
1124 const EGLint
*attrib_list
)
1126 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1128 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1129 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1130 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1135 EGLSurface EGLAPIENTRY
1136 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1137 void *native_pixmap
,
1138 const EGLAttrib
*attrib_list
)
1140 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1142 EGLint
*int_attribs
;
1144 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1146 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1147 if (attrib_list
&& !int_attribs
)
1148 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1150 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1151 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1158 EGLSurface EGLAPIENTRY
1159 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1160 const EGLint
*attrib_list
)
1162 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1163 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1168 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1169 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1171 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1172 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1174 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1175 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1177 RETURN_EGL_EVAL(disp
, ret
);
1181 EGLBoolean EGLAPIENTRY
1182 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1184 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1185 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1189 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1190 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1191 _eglUnlinkSurface(surf
);
1192 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1194 RETURN_EGL_EVAL(disp
, ret
);
1197 EGLBoolean EGLAPIENTRY
1198 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1199 EGLint attribute
, EGLint
*value
)
1201 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1202 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1206 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1207 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1209 if (drv
->API
.QuerySurface
)
1210 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1212 ret
= _eglQuerySurface(drv
, disp
, surf
, attribute
, value
);
1214 RETURN_EGL_EVAL(disp
, ret
);
1217 EGLBoolean EGLAPIENTRY
1218 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1219 EGLint attribute
, EGLint value
)
1221 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1222 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1226 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1227 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1229 ret
= _eglSurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1231 RETURN_EGL_EVAL(disp
, ret
);
1235 EGLBoolean EGLAPIENTRY
1236 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1238 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1239 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1243 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1244 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1245 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1247 RETURN_EGL_EVAL(disp
, ret
);
1251 EGLBoolean EGLAPIENTRY
1252 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1254 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1255 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1259 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1260 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1261 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1263 RETURN_EGL_EVAL(disp
, ret
);
1267 EGLBoolean EGLAPIENTRY
1268 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1270 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1271 _EGLContext
*ctx
= _eglGetCurrentContext();
1272 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1276 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1277 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1279 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1280 ctx
->Resource
.Display
!= disp
)
1281 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1283 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1284 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1286 if (surf
->Type
!= EGL_WINDOW_BIT
)
1287 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1289 interval
= CLAMP(interval
,
1290 surf
->Config
->MinSwapInterval
,
1291 surf
->Config
->MaxSwapInterval
);
1293 if (surf
->SwapInterval
!= interval
) {
1294 if (drv
->API
.SwapInterval
)
1295 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1297 ret
= _eglSwapInterval(drv
, disp
, surf
, interval
);
1304 surf
->SwapInterval
= interval
;
1306 RETURN_EGL_EVAL(disp
, ret
);
1310 EGLBoolean EGLAPIENTRY
1311 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1313 _EGLContext
*ctx
= _eglGetCurrentContext();
1314 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1315 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1319 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1320 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1322 /* surface must be bound to current context in EGL 1.4 */
1323 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1324 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1325 surf
!= ctx
->DrawSurface
)
1326 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1329 if (surf
->Type
!= EGL_WINDOW_BIT
)
1330 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1332 /* From the EGL 1.5 spec:
1334 * If eglSwapBuffers is called and the native window associated with
1335 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1339 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1341 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1343 /* EGL_KHR_partial_update
1344 * Frame boundary successfully reached,
1345 * reset damage region and reset BufferAgeRead
1348 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1349 surf
->BufferAgeRead
= EGL_FALSE
;
1352 RETURN_EGL_EVAL(disp
, ret
);
1357 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1358 const EGLint
*rects
, EGLint n_rects
)
1360 _EGLContext
*ctx
= _eglGetCurrentContext();
1364 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1366 /* surface must be bound to current context in EGL 1.4 */
1367 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1368 surf
!= ctx
->DrawSurface
)
1369 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1371 if (surf
->Type
!= EGL_WINDOW_BIT
)
1372 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1374 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1375 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1377 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1379 /* EGL_KHR_partial_update
1380 * Frame boundary successfully reached,
1381 * reset damage region and reset BufferAgeRead
1384 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1385 surf
->BufferAgeRead
= EGL_FALSE
;
1388 RETURN_EGL_EVAL(disp
, ret
);
1391 static EGLBoolean EGLAPIENTRY
1392 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1393 const EGLint
*rects
, EGLint n_rects
)
1395 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1396 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1397 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1398 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1401 static EGLBoolean EGLAPIENTRY
1402 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1403 const EGLint
*rects
, EGLint n_rects
)
1405 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1406 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1407 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1408 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1412 * Clamp the rectangles so that they lie within the surface.
1416 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1417 EGLint
*rects
, EGLint n_rects
)
1420 EGLint surf_height
= surf
->Height
;
1421 EGLint surf_width
= surf
->Width
;
1423 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1424 EGLint x1
, y1
, x2
, y2
;
1427 x2
= rects
[i
+ 2] + x1
;
1428 y2
= rects
[i
+ 3] + y1
;
1430 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1431 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1432 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1433 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1437 static EGLBoolean EGLAPIENTRY
1438 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1439 EGLint
*rects
, EGLint n_rects
)
1441 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1442 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1443 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1444 _EGLContext
*ctx
= _eglGetCurrentContext();
1447 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1449 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1450 surf
->Type
!= EGL_WINDOW_BIT
||
1451 ctx
->DrawSurface
!= surf
||
1452 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1453 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1455 /* If the damage region is already set or
1456 * buffer age is not queried between
1457 * frame boundaries, throw bad access error
1460 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1461 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1463 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1464 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1467 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1469 RETURN_EGL_EVAL(disp
, ret
);
1472 EGLBoolean EGLAPIENTRY
1473 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1475 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1476 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1479 void *native_pixmap_ptr
;
1481 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1482 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1483 native_pixmap_ptr
= (void*) target
;
1485 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1486 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1488 RETURN_EGL_EVAL(disp
, ret
);
1493 _eglWaitClientCommon(void)
1495 _EGLContext
*ctx
= _eglGetCurrentContext();
1501 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1503 disp
= ctx
->Resource
.Display
;
1504 mtx_lock(&disp
->Mutex
);
1506 /* let bad current context imply bad current surface */
1507 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1508 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1509 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1511 /* a valid current context implies an initialized current display */
1512 assert(disp
->Initialized
);
1514 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1516 RETURN_EGL_EVAL(disp
, ret
);
1519 EGLBoolean EGLAPIENTRY
1522 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1523 return _eglWaitClientCommon();
1526 EGLBoolean EGLAPIENTRY
1529 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1530 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1531 return _eglWaitClientCommon();
1535 EGLBoolean EGLAPIENTRY
1536 eglWaitNative(EGLint engine
)
1538 _EGLContext
*ctx
= _eglGetCurrentContext();
1544 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1546 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1548 disp
= ctx
->Resource
.Display
;
1549 mtx_lock(&disp
->Mutex
);
1551 /* let bad current context imply bad current surface */
1552 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1553 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1554 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1556 /* a valid current context implies an initialized current display */
1557 assert(disp
->Initialized
);
1559 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1561 RETURN_EGL_EVAL(disp
, ret
);
1565 EGLDisplay EGLAPIENTRY
1566 eglGetCurrentDisplay(void)
1568 _EGLContext
*ctx
= _eglGetCurrentContext();
1571 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1573 RETURN_EGL_SUCCESS(NULL
, ret
);
1577 EGLContext EGLAPIENTRY
1578 eglGetCurrentContext(void)
1580 _EGLContext
*ctx
= _eglGetCurrentContext();
1583 ret
= _eglGetContextHandle(ctx
);
1585 RETURN_EGL_SUCCESS(NULL
, ret
);
1589 EGLSurface EGLAPIENTRY
1590 eglGetCurrentSurface(EGLint readdraw
)
1592 _EGLContext
*ctx
= _eglGetCurrentContext();
1593 EGLint err
= EGL_SUCCESS
;
1597 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1600 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1604 surf
= ctx
->DrawSurface
;
1607 surf
= ctx
->ReadSurface
;
1611 err
= EGL_BAD_PARAMETER
;
1615 ret
= _eglGetSurfaceHandle(surf
);
1617 RETURN_EGL_ERROR(NULL
, err
, ret
);
1624 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1625 EGLint e
= t
->LastError
;
1626 if (!_eglIsCurrentThreadDummy())
1627 t
->LastError
= EGL_SUCCESS
;
1637 * Specify the client API to use for subsequent calls including:
1638 * eglCreateContext()
1639 * eglGetCurrentContext()
1640 * eglGetCurrentDisplay()
1641 * eglGetCurrentSurface()
1642 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1645 * See section 3.7 "Rendering Context" in the EGL specification for details.
1647 EGLBoolean EGLAPIENTRY
1648 eglBindAPI(EGLenum api
)
1652 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1654 t
= _eglGetCurrentThread();
1655 if (_eglIsCurrentThreadDummy())
1656 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1658 if (!_eglIsApiValid(api
))
1659 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1661 t
->CurrentAPI
= api
;
1663 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1668 * Return the last value set with eglBindAPI().
1673 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1676 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1677 ret
= t
->CurrentAPI
;
1679 RETURN_EGL_SUCCESS(NULL
, ret
);
1683 EGLSurface EGLAPIENTRY
1684 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1685 EGLClientBuffer buffer
, EGLConfig config
,
1686 const EGLint
*attrib_list
)
1688 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1689 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1692 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1694 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1696 /* OpenVG is not supported */
1697 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1701 EGLBoolean EGLAPIENTRY
1702 eglReleaseThread(void)
1704 /* unbind current contexts */
1705 if (!_eglIsCurrentThreadDummy()) {
1706 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1707 _EGLContext
*ctx
= t
->CurrentContext
;
1709 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1712 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1715 mtx_lock(&disp
->Mutex
);
1717 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1718 mtx_unlock(&disp
->Mutex
);
1722 _eglDestroyCurrentThread();
1724 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1729 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1730 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1732 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1737 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1738 if (!disp
->Extensions
.KHR_image_base
)
1739 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1740 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1741 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1742 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1743 * <ctx> must be EGL_NO_CONTEXT..."
1745 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1746 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1748 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1750 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1752 RETURN_EGL_EVAL(disp
, ret
);
1755 static EGLImage EGLAPIENTRY
1756 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1757 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1759 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1760 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1761 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1765 EGLImage EGLAPIENTRY
1766 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1767 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1769 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1771 EGLint
*int_attribs
;
1773 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1775 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1776 if (attr_list
&& !int_attribs
)
1777 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1779 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1786 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1791 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1792 if (!disp
->Extensions
.KHR_image_base
)
1793 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1795 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1797 _eglUnlinkImage(img
);
1798 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1800 RETURN_EGL_EVAL(disp
, ret
);
1803 EGLBoolean EGLAPIENTRY
1804 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1806 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1807 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1808 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1809 return _eglDestroyImageCommon(disp
, img
);
1812 static EGLBoolean EGLAPIENTRY
1813 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1815 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1816 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1817 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1818 return _eglDestroyImageCommon(disp
, img
);
1823 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1824 EGLBoolean orig_is_EGLAttrib
,
1825 EGLenum invalid_type_error
)
1827 _EGLContext
*ctx
= _eglGetCurrentContext();
1832 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1834 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1835 /* There exist two EGLAttrib variants of eglCreateSync*:
1836 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1837 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1838 * support as a proxy for EGL 1.5 support, even though that's not
1839 * entirely correct (though _eglComputeVersion does the same).
1841 * The EGL spec provides no guidance on how to handle unsupported
1842 * functions. EGL_BAD_MATCH seems reasonable.
1844 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1847 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1848 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1849 * error is generated.
1852 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1853 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1855 /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */
1856 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1857 (ctx
->ClientAPI
!= EGL_OPENGL_ES_API
&&
1858 ctx
->ClientAPI
!= EGL_OPENGL_API
)))
1859 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1862 case EGL_SYNC_FENCE_KHR
:
1863 if (!disp
->Extensions
.KHR_fence_sync
)
1864 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1866 case EGL_SYNC_REUSABLE_KHR
:
1867 if (!disp
->Extensions
.KHR_reusable_sync
)
1868 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1870 case EGL_SYNC_CL_EVENT_KHR
:
1871 if (!disp
->Extensions
.KHR_cl_event2
)
1872 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1874 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1875 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1876 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1879 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1882 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1883 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1885 RETURN_EGL_EVAL(disp
, ret
);
1889 static EGLSync EGLAPIENTRY
1890 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1892 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1893 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1896 EGLAttrib
*attrib_list
;
1899 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1900 attrib_list
= (EGLAttrib
*) int_list
;
1902 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1903 if (err
!= EGL_SUCCESS
)
1904 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1907 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1910 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1913 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1918 static EGLSync EGLAPIENTRY
1919 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1921 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1922 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1923 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1929 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1931 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1932 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1933 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1939 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1944 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1945 assert(disp
->Extensions
.KHR_reusable_sync
||
1946 disp
->Extensions
.KHR_fence_sync
||
1947 disp
->Extensions
.ANDROID_native_fence_sync
);
1950 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1952 RETURN_EGL_EVAL(disp
, ret
);
1955 EGLBoolean EGLAPIENTRY
1956 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1958 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1959 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1960 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1961 return _eglDestroySync(disp
, s
);
1964 static EGLBoolean EGLAPIENTRY
1965 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1967 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1968 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1969 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1970 return _eglDestroySync(disp
, s
);
1975 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1976 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1981 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1982 assert(disp
->Extensions
.KHR_reusable_sync
||
1983 disp
->Extensions
.KHR_fence_sync
||
1984 disp
->Extensions
.ANDROID_native_fence_sync
);
1986 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1987 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1989 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1990 * unlocked here to allow other threads also to be able to
1991 * go into waiting state.
1994 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1995 _eglUnlockDisplay(dpy
);
1997 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
2000 * 'disp' is already unlocked for reusable sync type,
2001 * so passing 'NULL' to bypass unlocking display.
2003 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
2004 RETURN_EGL_EVAL(NULL
, ret
);
2006 RETURN_EGL_EVAL(disp
, ret
);
2010 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
2011 EGLint flags
, EGLTime timeout
)
2013 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2014 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2015 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2016 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2019 static EGLint EGLAPIENTRY
2020 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
2021 EGLint flags
, EGLTime timeout
)
2023 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2024 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2025 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2026 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2031 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
2033 _EGLContext
*ctx
= _eglGetCurrentContext();
2037 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2038 assert(disp
->Extensions
.KHR_wait_sync
);
2040 /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */
2041 if (ctx
== EGL_NO_CONTEXT
||
2042 (ctx
->ClientAPI
!= EGL_OPENGL_ES_API
&&
2043 ctx
->ClientAPI
!= EGL_OPENGL_API
))
2044 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
2046 /* the API doesn't allow any flags yet */
2048 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2050 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
2052 RETURN_EGL_EVAL(disp
, ret
);
2055 static EGLint EGLAPIENTRY
2056 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2058 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2059 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2060 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2061 return _eglWaitSyncCommon(disp
, s
, flags
);
2065 EGLBoolean EGLAPIENTRY
2066 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2068 /* The KHR version returns EGLint, while the core version returns
2069 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2072 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2073 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2074 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2075 return _eglWaitSyncCommon(disp
, s
, flags
);
2079 static EGLBoolean EGLAPIENTRY
2080 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2082 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2083 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2087 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2089 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2090 assert(disp
->Extensions
.KHR_reusable_sync
);
2091 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2093 RETURN_EGL_EVAL(disp
, ret
);
2098 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2103 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2104 assert(disp
->Extensions
.KHR_reusable_sync
||
2105 disp
->Extensions
.KHR_fence_sync
||
2106 disp
->Extensions
.ANDROID_native_fence_sync
);
2108 ret
= _eglGetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2110 RETURN_EGL_EVAL(disp
, ret
);
2113 EGLBoolean EGLAPIENTRY
2114 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2116 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2117 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2118 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2121 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2123 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2127 static EGLBoolean EGLAPIENTRY
2128 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2130 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2131 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2135 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2138 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2141 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2143 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2145 * If any error occurs, <*value> is not modified.
2147 if (result
== EGL_FALSE
)
2154 static EGLint EGLAPIENTRY
2155 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2157 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2158 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2162 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2164 /* the spec doesn't seem to specify what happens if the fence
2165 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2168 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2169 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2171 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2172 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2173 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2175 RETURN_EGL_EVAL(disp
, ret
);
2178 static EGLBoolean EGLAPIENTRY
2179 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2180 EGLint numRects
, const EGLint
*rects
)
2182 _EGLContext
*ctx
= _eglGetCurrentContext();
2183 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2184 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2188 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2190 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2192 if (!disp
->Extensions
.NOK_swap_region
)
2193 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2195 /* surface must be bound to current context in EGL 1.4 */
2196 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2197 surf
!= ctx
->DrawSurface
)
2198 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2200 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2202 RETURN_EGL_EVAL(disp
, ret
);
2206 static EGLImage EGLAPIENTRY
2207 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2209 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2214 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2216 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2217 if (!disp
->Extensions
.MESA_drm_image
)
2218 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2220 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2221 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2223 RETURN_EGL_EVAL(disp
, ret
);
2226 static EGLBoolean EGLAPIENTRY
2227 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2228 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2230 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2231 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2235 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2237 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2238 assert(disp
->Extensions
.MESA_drm_image
);
2241 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2243 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2245 RETURN_EGL_EVAL(disp
, ret
);
2251 static EGLBoolean EGLAPIENTRY
2252 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2254 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2258 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2260 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2261 assert(disp
->Extensions
.WL_bind_wayland_display
);
2264 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2266 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2268 RETURN_EGL_EVAL(disp
, ret
);
2271 static EGLBoolean EGLAPIENTRY
2272 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2274 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2278 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2280 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2281 assert(disp
->Extensions
.WL_bind_wayland_display
);
2284 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2286 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2288 RETURN_EGL_EVAL(disp
, ret
);
2291 static EGLBoolean EGLAPIENTRY
2292 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2293 EGLint attribute
, EGLint
*value
)
2295 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2299 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2301 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2302 assert(disp
->Extensions
.WL_bind_wayland_display
);
2305 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2307 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2309 RETURN_EGL_EVAL(disp
, ret
);
2313 static struct wl_buffer
* EGLAPIENTRY
2314 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2316 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2319 struct wl_buffer
*ret
;
2321 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2323 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2324 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2325 RETURN_EGL_EVAL(disp
, NULL
);
2327 img
= _eglLookupImage(image
, disp
);
2330 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2332 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2334 RETURN_EGL_EVAL(disp
, ret
);
2337 static EGLBoolean EGLAPIENTRY
2338 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2339 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2341 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2342 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2346 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2348 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2350 if (!disp
->Extensions
.NV_post_sub_buffer
)
2351 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2353 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2355 RETURN_EGL_EVAL(disp
, ret
);
2358 static EGLBoolean EGLAPIENTRY
2359 eglGetSyncValuesCHROMIUM(EGLDisplay dpy
, EGLSurface surface
,
2360 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2363 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2364 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2368 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2370 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2371 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2372 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2374 if (!ust
|| !msc
|| !sbc
)
2375 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2377 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2379 RETURN_EGL_EVAL(disp
, ret
);
2382 static EGLBoolean EGLAPIENTRY
2383 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2384 EGLint
*fourcc
, EGLint
*nplanes
,
2385 EGLuint64KHR
*modifiers
)
2387 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2388 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2392 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2394 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2395 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2398 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2400 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2403 RETURN_EGL_EVAL(disp
, ret
);
2406 static EGLBoolean EGLAPIENTRY
2407 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2408 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2410 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2411 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2415 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2417 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2418 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2421 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2423 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2425 RETURN_EGL_EVAL(disp
, ret
);
2428 static EGLint EGLAPIENTRY
2429 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2432 _EGLDisplay
*disp
= NULL
;
2433 _EGLResourceType type
;
2435 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2437 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2438 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2440 if (!_eglIsCurrentThreadDummy()) {
2445 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2448 disp
= _eglLockDisplay(dpy
);
2450 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2452 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2453 if (dpy
!= (EGLDisplay
) object
)
2454 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2456 disp
->Label
= label
;
2457 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2460 switch (objectType
) {
2461 case EGL_OBJECT_CONTEXT_KHR
:
2462 type
= _EGL_RESOURCE_CONTEXT
;
2464 case EGL_OBJECT_SURFACE_KHR
:
2465 type
= _EGL_RESOURCE_SURFACE
;
2467 case EGL_OBJECT_IMAGE_KHR
:
2468 type
= _EGL_RESOURCE_IMAGE
;
2470 case EGL_OBJECT_SYNC_KHR
:
2471 type
= _EGL_RESOURCE_SYNC
;
2473 case EGL_OBJECT_STREAM_KHR
:
2475 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2478 if (_eglCheckResource(object
, type
, disp
)) {
2479 _EGLResource
*res
= (_EGLResource
*) object
;
2482 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2485 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2488 static EGLint EGLAPIENTRY
2489 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2490 const EGLAttrib
*attrib_list
)
2492 unsigned int newEnabled
;
2494 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2496 mtx_lock(_eglGlobal
.Mutex
);
2498 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2499 if (attrib_list
!= NULL
) {
2502 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2503 switch (attrib_list
[i
]) {
2504 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2505 case EGL_DEBUG_MSG_ERROR_KHR
:
2506 case EGL_DEBUG_MSG_WARN_KHR
:
2507 case EGL_DEBUG_MSG_INFO_KHR
:
2508 if (attrib_list
[i
+ 1])
2509 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2511 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2514 // On error, set the last error code, call the current
2515 // debug callback, and return the error code.
2516 mtx_unlock(_eglGlobal
.Mutex
);
2517 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2518 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2519 return EGL_BAD_ATTRIBUTE
;
2524 if (callback
!= NULL
) {
2525 _eglGlobal
.debugCallback
= callback
;
2526 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2528 _eglGlobal
.debugCallback
= NULL
;
2529 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2532 mtx_unlock(_eglGlobal
.Mutex
);
2536 static EGLBoolean EGLAPIENTRY
2537 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2539 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2541 mtx_lock(_eglGlobal
.Mutex
);
2543 switch (attribute
) {
2544 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2545 case EGL_DEBUG_MSG_ERROR_KHR
:
2546 case EGL_DEBUG_MSG_WARN_KHR
:
2547 case EGL_DEBUG_MSG_INFO_KHR
:
2548 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2553 case EGL_DEBUG_CALLBACK_KHR
:
2554 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2557 mtx_unlock(_eglGlobal
.Mutex
);
2558 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2559 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2563 mtx_unlock(_eglGlobal
.Mutex
);
2568 _eglFunctionCompare(const void *key
, const void *elem
)
2570 const char *procname
= key
;
2571 const struct _egl_entrypoint
*entrypoint
= elem
;
2572 return strcmp(procname
, entrypoint
->name
);
2575 static EGLBoolean EGLAPIENTRY
2576 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2577 EGLint
*formats
, EGLint
*num_formats
)
2579 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2583 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2585 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2587 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2590 RETURN_EGL_EVAL(disp
, ret
);
2593 static EGLBoolean EGLAPIENTRY
2594 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2595 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2596 EGLint
*num_modifiers
)
2598 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2602 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2604 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2606 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2607 modifiers
, external_only
,
2610 RETURN_EGL_EVAL(disp
, ret
);
2613 static void EGLAPIENTRY
2614 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2615 EGLGetBlobFuncANDROID get
)
2617 /* This function does not return anything so we cannot
2618 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2620 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2621 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2623 _eglUnlockDisplay(disp
);
2627 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2630 _eglUnlockDisplay(disp
);
2635 _eglError(EGL_BAD_PARAMETER
,
2636 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2637 _eglUnlockDisplay(disp
);
2641 if (disp
->BlobCacheSet
) {
2642 _eglError(EGL_BAD_PARAMETER
,
2643 "eglSetBlobCacheFuncsANDROID: functions already set");
2644 _eglUnlockDisplay(disp
);
2648 disp
->BlobCacheSet
= set
;
2649 disp
->BlobCacheGet
= get
;
2651 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2653 _eglUnlockDisplay(disp
);
2656 static EGLBoolean EGLAPIENTRY
2657 eglQueryDeviceAttribEXT(EGLDeviceEXT device
,
2661 _EGLDevice
*dev
= _eglLookupDevice(device
);
2664 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2666 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, EGL_FALSE
);
2668 ret
= _eglQueryDeviceAttribEXT(dev
, attribute
, value
);
2669 RETURN_EGL_EVAL(NULL
, ret
);
2672 static const char * EGLAPIENTRY
2673 eglQueryDeviceStringEXT(EGLDeviceEXT device
,
2676 _EGLDevice
*dev
= _eglLookupDevice(device
);
2678 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2680 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, NULL
);
2682 RETURN_EGL_EVAL(NULL
, _eglQueryDeviceStringEXT(dev
, name
));
2685 static EGLBoolean EGLAPIENTRY
2686 eglQueryDevicesEXT(EGLint max_devices
,
2687 EGLDeviceEXT
*devices
,
2688 EGLint
*num_devices
)
2692 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2693 ret
= _eglQueryDevicesEXT(max_devices
, (_EGLDevice
**) devices
,
2695 RETURN_EGL_EVAL(NULL
, ret
);
2698 static EGLBoolean EGLAPIENTRY
2699 eglQueryDisplayAttribEXT(EGLDisplay dpy
,
2703 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2706 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2707 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2709 switch (attribute
) {
2710 case EGL_DEVICE_EXT
:
2711 *value
= (EGLAttrib
) disp
->Device
;
2714 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
2716 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
2719 static char * EGLAPIENTRY
2720 eglGetDisplayDriverConfig(EGLDisplay dpy
)
2722 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2726 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2727 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2729 assert(disp
->Extensions
.MESA_query_driver
);
2731 ret
= drv
->API
.QueryDriverConfig(disp
);
2732 RETURN_EGL_EVAL(disp
, ret
);
2735 static const char * EGLAPIENTRY
2736 eglGetDisplayDriverName(EGLDisplay dpy
)
2738 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2742 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2743 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2745 assert(disp
->Extensions
.MESA_query_driver
);
2747 ret
= drv
->API
.QueryDriverName(disp
);
2748 RETURN_EGL_EVAL(disp
, ret
);
2751 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2752 eglGetProcAddress(const char *procname
)
2754 static const struct _egl_entrypoint egl_functions
[] = {
2755 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2756 #include "eglentrypoint.h"
2757 #undef EGL_ENTRYPOINT
2759 _EGLProc ret
= NULL
;
2762 RETURN_EGL_SUCCESS(NULL
, NULL
);
2764 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2766 if (strncmp(procname
, "egl", 3) == 0) {
2767 const struct _egl_entrypoint
*entrypoint
=
2769 egl_functions
, ARRAY_SIZE(egl_functions
),
2770 sizeof(egl_functions
[0]),
2771 _eglFunctionCompare
);
2773 ret
= entrypoint
->function
;
2777 ret
= _eglGetDriverProc(procname
);
2779 RETURN_EGL_SUCCESS(NULL
, ret
);
2783 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2784 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2788 *disp
= _eglLockDisplay(dpy
);
2789 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2791 _eglUnlockDisplay(*disp
);
2792 return MESA_GLINTEROP_INVALID_DISPLAY
;
2795 *drv
= (*disp
)->Driver
;
2797 *ctx
= _eglLookupContext(context
, *disp
);
2799 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2800 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2801 _eglUnlockDisplay(*disp
);
2802 return MESA_GLINTEROP_INVALID_CONTEXT
;
2805 return MESA_GLINTEROP_SUCCESS
;
2809 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2810 struct mesa_glinterop_device_info
*out
)
2817 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2818 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2821 if (drv
->API
.GLInteropQueryDeviceInfo
)
2822 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2824 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2826 _eglUnlockDisplay(disp
);
2831 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2832 struct mesa_glinterop_export_in
*in
,
2833 struct mesa_glinterop_export_out
*out
)
2840 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2841 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2844 if (drv
->API
.GLInteropExportObject
)
2845 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2847 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2849 _eglUnlockDisplay(disp
);