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 #ifdef HAVE_SURFACELESS_PLATFORM
405 case EGL_PLATFORM_SURFACELESS_MESA
:
406 disp
= _eglGetSurfacelessDisplay(native_display
, attrib_list
);
409 #ifdef HAVE_ANDROID_PLATFORM
410 case EGL_PLATFORM_ANDROID_KHR
:
411 disp
= _eglGetAndroidDisplay(native_display
, attrib_list
);
414 case EGL_PLATFORM_DEVICE_EXT
:
415 disp
= _eglGetDeviceDisplay(native_display
, attrib_list
);
418 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
421 return _eglGetDisplayHandle(disp
);
424 static EGLDisplay EGLAPIENTRY
425 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
426 const EGLint
*int_attribs
)
428 EGLAttrib
*attrib_list
;
431 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
433 if (_eglConvertIntsToAttribs(int_attribs
, &attrib_list
) != EGL_SUCCESS
)
434 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
436 disp
= _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
441 EGLDisplay EGLAPIENTRY
442 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
443 const EGLAttrib
*attrib_list
)
445 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
446 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
450 * Copy the extension into the string and update the string pointer.
453 _eglAppendExtension(char **str
, const char *ext
)
456 size_t len
= strlen(ext
);
473 * Examine the individual extension enable/disable flags and recompute
474 * the driver's Extensions string.
477 _eglCreateExtensionsString(_EGLDisplay
*disp
)
479 #define _EGL_CHECK_EXTENSION(ext) \
481 if (disp->Extensions.ext) { \
482 _eglAppendExtension(&exts, "EGL_" #ext); \
483 assert(exts <= disp->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
487 char *exts
= disp
->ExtensionsString
;
489 /* Please keep these sorted alphabetically. */
490 _EGL_CHECK_EXTENSION(ANDROID_blob_cache
);
491 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
492 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
493 _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync
);
494 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
496 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
498 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
499 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
500 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
501 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers
);
502 _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata
);
503 _EGL_CHECK_EXTENSION(EXT_surface_SMPTE2086_metadata
);
504 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
506 _EGL_CHECK_EXTENSION(IMG_context_priority
);
508 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
509 _EGL_CHECK_EXTENSION(KHR_config_attribs
);
510 _EGL_CHECK_EXTENSION(KHR_context_flush_control
);
511 _EGL_CHECK_EXTENSION(KHR_create_context
);
512 _EGL_CHECK_EXTENSION(KHR_create_context_no_error
);
513 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
514 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
515 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
516 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
517 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
518 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
519 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
520 if (disp
->Extensions
.KHR_image_base
&& disp
->Extensions
.KHR_image_pixmap
)
521 disp
->Extensions
.KHR_image
= EGL_TRUE
;
522 _EGL_CHECK_EXTENSION(KHR_image
);
523 _EGL_CHECK_EXTENSION(KHR_image_base
);
524 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
525 _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer
);
526 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
527 _EGL_CHECK_EXTENSION(KHR_partial_update
);
528 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
529 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
530 if (disp
->Extensions
.EXT_swap_buffers_with_damage
)
531 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
532 _EGL_CHECK_EXTENSION(EXT_pixel_format_float
);
533 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
535 if (disp
->Extensions
.KHR_no_config_context
)
536 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
537 _EGL_CHECK_EXTENSION(MESA_drm_image
);
538 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
539 _EGL_CHECK_EXTENSION(MESA_query_driver
);
541 _EGL_CHECK_EXTENSION(NOK_swap_region
);
542 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
544 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
546 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
547 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
549 #undef _EGL_CHECK_EXTENSION
553 _eglCreateAPIsString(_EGLDisplay
*disp
)
555 #define addstr(str) \
557 const size_t old_len = strlen(disp->ClientAPIsString); \
558 const size_t add_len = sizeof(str); \
559 const size_t max_len = sizeof(disp->ClientAPIsString) - 1; \
560 if (old_len + add_len <= max_len) \
561 strcat(disp->ClientAPIsString, str " "); \
563 assert(!"disp->ClientAPIsString is not large enough"); \
566 if (disp
->ClientAPIs
& EGL_OPENGL_BIT
)
569 if (disp
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
570 disp
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
571 disp
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
575 if (disp
->ClientAPIs
& EGL_OPENVG_BIT
)
582 _eglComputeVersion(_EGLDisplay
*disp
)
586 if (disp
->Extensions
.KHR_fence_sync
&&
587 disp
->Extensions
.KHR_cl_event2
&&
588 disp
->Extensions
.KHR_wait_sync
&&
589 disp
->Extensions
.KHR_image_base
&&
590 disp
->Extensions
.KHR_gl_texture_2D_image
&&
591 disp
->Extensions
.KHR_gl_texture_3D_image
&&
592 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
593 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
594 disp
->Extensions
.KHR_create_context
&&
595 disp
->Extensions
.EXT_create_context_robustness
&&
596 disp
->Extensions
.KHR_get_all_proc_addresses
&&
597 disp
->Extensions
.KHR_gl_colorspace
&&
598 disp
->Extensions
.KHR_surfaceless_context
)
601 /* For Android P and below limit the EGL version to 1.4 */
602 #if defined(ANDROID) && ANDROID_API_LEVEL <= 28
608 * This is typically the second EGL function that an application calls.
609 * Here we load/initialize the actual hardware driver.
611 EGLBoolean EGLAPIENTRY
612 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
614 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
616 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
619 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
621 if (!disp
->Initialized
) {
622 if (!_eglMatchDriver(disp
))
623 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
625 /* limit to APIs supported by core */
626 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
628 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
629 * classifies it as an EGL display extension, though conceptually it's an
630 * EGL client extension.
632 * From the EGL_KHR_get_all_proc_addresses spec:
634 * The EGL implementation must expose the name
635 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
636 * EGL_KHR_get_all_proc_addresses and supports
637 * EGL_EXT_client_extensions.
639 * Mesa unconditionally exposes both client extensions mentioned above,
640 * so the spec requires that each EGLDisplay unconditionally expose
641 * EGL_KHR_get_all_proc_addresses also.
643 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
645 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
646 * programs. It is driver agnostic and handled in the main EGL code.
648 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
650 _eglComputeVersion(disp
);
651 _eglCreateExtensionsString(disp
);
652 _eglCreateAPIsString(disp
);
653 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
654 "%d.%d", disp
->Version
/ 10, disp
->Version
% 10);
657 /* Update applications version of major and minor if not NULL */
658 if ((major
!= NULL
) && (minor
!= NULL
)) {
659 *major
= disp
->Version
/ 10;
660 *minor
= disp
->Version
% 10;
663 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
667 EGLBoolean EGLAPIENTRY
668 eglTerminate(EGLDisplay dpy
)
670 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
672 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
675 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
677 if (disp
->Initialized
) {
678 _EGLDriver
*drv
= disp
->Driver
;
680 drv
->API
.Terminate(drv
, disp
);
681 /* do not reset disp->Driver */
682 disp
->ClientAPIsString
[0] = 0;
683 disp
->Initialized
= EGL_FALSE
;
685 /* Reset blob cache funcs on terminate. */
686 disp
->BlobCacheSet
= NULL
;
687 disp
->BlobCacheGet
= NULL
;
690 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
694 const char * EGLAPIENTRY
695 eglQueryString(EGLDisplay dpy
, EGLint name
)
701 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
702 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
706 disp
= _eglLockDisplay(dpy
);
707 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
708 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
712 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
714 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
716 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
717 case EGL_CLIENT_APIS
:
718 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
720 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
725 EGLBoolean EGLAPIENTRY
726 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
727 EGLint config_size
, EGLint
*num_config
)
729 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
733 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
735 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
738 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
740 ret
= _eglGetConfigs(drv
, disp
, configs
, config_size
, num_config
);
742 RETURN_EGL_EVAL(disp
, ret
);
746 EGLBoolean EGLAPIENTRY
747 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
748 EGLint config_size
, EGLint
*num_config
)
750 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
754 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
756 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
759 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
761 ret
= _eglChooseConfig(drv
, disp
, attrib_list
, configs
,
762 config_size
, num_config
);
764 RETURN_EGL_EVAL(disp
, ret
);
768 EGLBoolean EGLAPIENTRY
769 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
770 EGLint attribute
, EGLint
*value
)
772 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
773 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
777 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
779 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
781 ret
= _eglGetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
783 RETURN_EGL_EVAL(disp
, ret
);
787 EGLContext EGLAPIENTRY
788 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
789 const EGLint
*attrib_list
)
791 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
792 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
793 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
795 _EGLContext
*context
;
798 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
800 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
802 if (config
!= EGL_NO_CONFIG_KHR
)
803 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
804 else if (!disp
->Extensions
.KHR_no_config_context
)
805 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
807 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
808 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
810 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
811 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
813 RETURN_EGL_EVAL(disp
, ret
);
817 EGLBoolean EGLAPIENTRY
818 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
820 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
821 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
825 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
827 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
828 _eglUnlinkContext(context
);
829 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
831 RETURN_EGL_EVAL(disp
, ret
);
835 EGLBoolean EGLAPIENTRY
836 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
839 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
840 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
841 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
842 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
846 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
849 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
852 /* display is allowed to be uninitialized under certain condition */
853 if (!disp
->Initialized
) {
854 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
855 ctx
!= EGL_NO_CONTEXT
)
856 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
859 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
861 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
862 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
863 if (!draw_surf
|| !read_surf
) {
864 /* From the EGL 1.4 (20130211) spec:
866 * To release the current context without assigning a new one, set ctx
867 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
869 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
870 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
872 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
873 (!read_surf
&& read
!= EGL_NO_SURFACE
))
874 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
875 if (draw_surf
|| read_surf
)
876 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
879 /* If a native window underlying either draw or read is no longer valid,
880 * an EGL_BAD_NATIVE_WINDOW error is generated.
882 if (draw_surf
&& draw_surf
->Lost
)
883 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
884 if (read_surf
&& read_surf
->Lost
)
885 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
887 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
889 RETURN_EGL_EVAL(disp
, ret
);
893 EGLBoolean EGLAPIENTRY
894 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
895 EGLint attribute
, EGLint
*value
)
897 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
898 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
902 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
904 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
906 ret
= _eglQueryContext(drv
, disp
, context
, attribute
, value
);
908 RETURN_EGL_EVAL(disp
, ret
);
912 /* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says
913 * that if native_surface was already used to create a window or pixmap, we
914 * can't create a new one. This is what this function checks for.
917 _eglNativeSurfaceAlreadyUsed(_EGLDisplay
*disp
, void *native_surface
)
921 list
= disp
->ResourceLists
[_EGL_RESOURCE_SURFACE
];
923 _EGLSurface
*surf
= (_EGLSurface
*) list
;
927 if (surf
->Type
== EGL_PBUFFER_BIT
)
930 if (surf
->NativeSurface
== native_surface
)
939 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
940 void *native_window
, const EGLint
*attrib_list
)
942 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
948 if (native_window
== NULL
)
949 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
951 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
952 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
953 /* From the EGL_MESA_platform_surfaceless spec (v1):
955 * eglCreatePlatformWindowSurface fails when called with a <display>
956 * that belongs to the surfaceless platform. It returns
957 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
958 * justification for this unconditional failure is that the
959 * surfaceless platform has no native windows, and therefore the
960 * <native_window> parameter is always invalid.
962 * This check must occur before checking the EGLConfig, which emits
965 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
968 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
970 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
971 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
973 if (_eglNativeSurfaceAlreadyUsed(disp
, native_window
))
974 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
976 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
978 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
980 RETURN_EGL_EVAL(disp
, ret
);
984 EGLSurface EGLAPIENTRY
985 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
986 EGLNativeWindowType window
, const EGLint
*attrib_list
)
988 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
990 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
991 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
992 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
997 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
999 #ifdef HAVE_X11_PLATFORM
1000 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
1001 /* The `native_window` parameter for the X11 platform differs between
1002 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1003 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
1004 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
1005 * `Window*`. Convert `Window*` to `Window` because that's what
1006 * dri2_x11_create_window_surface() expects.
1008 return (void *)(* (Window
*) native_window
);
1011 return native_window
;
1014 static EGLSurface EGLAPIENTRY
1015 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1016 void *native_window
,
1017 const EGLint
*attrib_list
)
1019 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1021 native_window
= _fixupNativeWindow(disp
, native_window
);
1023 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1024 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1029 EGLSurface EGLAPIENTRY
1030 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
1031 void *native_window
,
1032 const EGLAttrib
*attrib_list
)
1034 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1036 EGLint
*int_attribs
;
1038 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1040 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1041 if (attrib_list
&& !int_attribs
)
1042 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1044 native_window
= _fixupNativeWindow(disp
, native_window
);
1045 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1052 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
1054 #ifdef HAVE_X11_PLATFORM
1055 /* The `native_pixmap` parameter for the X11 platform differs between
1056 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1057 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1058 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1059 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1060 * dri2_x11_create_pixmap_surface() expects.
1062 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
1063 return (void *)(* (Pixmap
*) native_pixmap
);
1065 return native_pixmap
;
1069 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1070 void *native_pixmap
, const EGLint
*attrib_list
)
1072 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1077 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
1078 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
1079 /* From the EGL_MESA_platform_surfaceless spec (v1):
1081 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1082 * also fails when called with a <display> that belongs to the
1083 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1084 * EGL_BAD_NATIVE_PIXMAP.
1086 * This check must occur before checking the EGLConfig, which emits
1089 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1092 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1094 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1095 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1097 if (native_pixmap
== NULL
)
1098 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1100 if (_eglNativeSurfaceAlreadyUsed(disp
, native_pixmap
))
1101 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1103 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1105 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1107 RETURN_EGL_EVAL(disp
, ret
);
1111 EGLSurface EGLAPIENTRY
1112 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1113 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1115 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1117 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1118 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1119 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1123 static EGLSurface EGLAPIENTRY
1124 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1125 void *native_pixmap
,
1126 const EGLint
*attrib_list
)
1128 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1130 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1131 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1132 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1137 EGLSurface EGLAPIENTRY
1138 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1139 void *native_pixmap
,
1140 const EGLAttrib
*attrib_list
)
1142 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1144 EGLint
*int_attribs
;
1146 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1148 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1149 if (attrib_list
&& !int_attribs
)
1150 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1152 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1153 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1160 EGLSurface EGLAPIENTRY
1161 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1162 const EGLint
*attrib_list
)
1164 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1165 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1170 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1171 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1173 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1174 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1176 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1177 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1179 RETURN_EGL_EVAL(disp
, ret
);
1183 EGLBoolean EGLAPIENTRY
1184 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1186 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1187 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1191 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1192 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1193 _eglUnlinkSurface(surf
);
1194 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1196 RETURN_EGL_EVAL(disp
, ret
);
1199 EGLBoolean EGLAPIENTRY
1200 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1201 EGLint attribute
, EGLint
*value
)
1203 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1204 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1208 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1209 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1211 if (drv
->API
.QuerySurface
)
1212 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1214 ret
= _eglQuerySurface(drv
, disp
, surf
, attribute
, value
);
1216 RETURN_EGL_EVAL(disp
, ret
);
1219 EGLBoolean EGLAPIENTRY
1220 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1221 EGLint attribute
, EGLint value
)
1223 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1224 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1228 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1229 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1231 ret
= _eglSurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1233 RETURN_EGL_EVAL(disp
, ret
);
1237 EGLBoolean EGLAPIENTRY
1238 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1240 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1241 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1245 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1246 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1247 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1249 RETURN_EGL_EVAL(disp
, ret
);
1253 EGLBoolean EGLAPIENTRY
1254 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1256 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1257 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1261 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1262 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1263 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1265 RETURN_EGL_EVAL(disp
, ret
);
1269 EGLBoolean EGLAPIENTRY
1270 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1272 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1273 _EGLContext
*ctx
= _eglGetCurrentContext();
1274 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1278 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1279 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1281 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1282 ctx
->Resource
.Display
!= disp
)
1283 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1285 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1286 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1288 if (surf
->Type
!= EGL_WINDOW_BIT
)
1289 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1291 interval
= CLAMP(interval
,
1292 surf
->Config
->MinSwapInterval
,
1293 surf
->Config
->MaxSwapInterval
);
1295 if (surf
->SwapInterval
!= interval
) {
1296 if (drv
->API
.SwapInterval
)
1297 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1299 ret
= _eglSwapInterval(drv
, disp
, surf
, interval
);
1306 surf
->SwapInterval
= interval
;
1308 RETURN_EGL_EVAL(disp
, ret
);
1312 EGLBoolean EGLAPIENTRY
1313 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1315 _EGLContext
*ctx
= _eglGetCurrentContext();
1316 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1317 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1321 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1322 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1324 /* surface must be bound to current context in EGL 1.4 */
1325 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1326 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1327 surf
!= ctx
->DrawSurface
)
1328 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1331 if (surf
->Type
!= EGL_WINDOW_BIT
)
1332 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1334 /* From the EGL 1.5 spec:
1336 * If eglSwapBuffers is called and the native window associated with
1337 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1341 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1343 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1345 /* EGL_KHR_partial_update
1346 * Frame boundary successfully reached,
1347 * reset damage region and reset BufferAgeRead
1350 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1351 surf
->BufferAgeRead
= EGL_FALSE
;
1354 RETURN_EGL_EVAL(disp
, ret
);
1359 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1360 EGLint
*rects
, EGLint n_rects
)
1362 _EGLContext
*ctx
= _eglGetCurrentContext();
1366 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1368 /* surface must be bound to current context in EGL 1.4 */
1369 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1370 surf
!= ctx
->DrawSurface
)
1371 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1373 if (surf
->Type
!= EGL_WINDOW_BIT
)
1374 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1376 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1377 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1379 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1381 /* EGL_KHR_partial_update
1382 * Frame boundary successfully reached,
1383 * reset damage region and reset BufferAgeRead
1386 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1387 surf
->BufferAgeRead
= EGL_FALSE
;
1390 RETURN_EGL_EVAL(disp
, ret
);
1393 static EGLBoolean EGLAPIENTRY
1394 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1395 EGLint
*rects
, EGLint n_rects
)
1397 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1398 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1399 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1400 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1403 static EGLBoolean EGLAPIENTRY
1404 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1405 EGLint
*rects
, EGLint n_rects
)
1407 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1408 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1409 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1410 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1414 * Clamp the rectangles so that they lie within the surface.
1418 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1419 EGLint
*rects
, EGLint n_rects
)
1422 EGLint surf_height
= surf
->Height
;
1423 EGLint surf_width
= surf
->Width
;
1425 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1426 EGLint x1
, y1
, x2
, y2
;
1429 x2
= rects
[i
+ 2] + x1
;
1430 y2
= rects
[i
+ 3] + y1
;
1432 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1433 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1434 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1435 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1439 static EGLBoolean EGLAPIENTRY
1440 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1441 EGLint
*rects
, EGLint n_rects
)
1443 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1444 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1445 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1446 _EGLContext
*ctx
= _eglGetCurrentContext();
1449 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1451 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1452 surf
->Type
!= EGL_WINDOW_BIT
||
1453 ctx
->DrawSurface
!= surf
||
1454 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1455 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1457 /* If the damage region is already set or
1458 * buffer age is not queried between
1459 * frame boundaries, throw bad access error
1462 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1463 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1465 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1466 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1469 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1471 RETURN_EGL_EVAL(disp
, ret
);
1474 EGLBoolean EGLAPIENTRY
1475 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1477 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1478 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1481 void *native_pixmap_ptr
;
1483 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1484 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1485 native_pixmap_ptr
= (void*) target
;
1487 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1488 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1490 RETURN_EGL_EVAL(disp
, ret
);
1495 _eglWaitClientCommon(void)
1497 _EGLContext
*ctx
= _eglGetCurrentContext();
1503 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1505 disp
= ctx
->Resource
.Display
;
1506 mtx_lock(&disp
->Mutex
);
1508 /* let bad current context imply bad current surface */
1509 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1510 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1511 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1513 /* a valid current context implies an initialized current display */
1514 assert(disp
->Initialized
);
1516 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1518 RETURN_EGL_EVAL(disp
, ret
);
1521 EGLBoolean EGLAPIENTRY
1524 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1525 return _eglWaitClientCommon();
1528 EGLBoolean EGLAPIENTRY
1531 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1532 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1533 return _eglWaitClientCommon();
1537 EGLBoolean EGLAPIENTRY
1538 eglWaitNative(EGLint engine
)
1540 _EGLContext
*ctx
= _eglGetCurrentContext();
1546 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1548 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1550 disp
= ctx
->Resource
.Display
;
1551 mtx_lock(&disp
->Mutex
);
1553 /* let bad current context imply bad current surface */
1554 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1555 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1556 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1558 /* a valid current context implies an initialized current display */
1559 assert(disp
->Initialized
);
1561 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1563 RETURN_EGL_EVAL(disp
, ret
);
1567 EGLDisplay EGLAPIENTRY
1568 eglGetCurrentDisplay(void)
1570 _EGLContext
*ctx
= _eglGetCurrentContext();
1573 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1575 RETURN_EGL_SUCCESS(NULL
, ret
);
1579 EGLContext EGLAPIENTRY
1580 eglGetCurrentContext(void)
1582 _EGLContext
*ctx
= _eglGetCurrentContext();
1585 ret
= _eglGetContextHandle(ctx
);
1587 RETURN_EGL_SUCCESS(NULL
, ret
);
1591 EGLSurface EGLAPIENTRY
1592 eglGetCurrentSurface(EGLint readdraw
)
1594 _EGLContext
*ctx
= _eglGetCurrentContext();
1595 EGLint err
= EGL_SUCCESS
;
1599 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1602 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1606 surf
= ctx
->DrawSurface
;
1609 surf
= ctx
->ReadSurface
;
1613 err
= EGL_BAD_PARAMETER
;
1617 ret
= _eglGetSurfaceHandle(surf
);
1619 RETURN_EGL_ERROR(NULL
, err
, ret
);
1626 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1627 EGLint e
= t
->LastError
;
1628 if (!_eglIsCurrentThreadDummy())
1629 t
->LastError
= EGL_SUCCESS
;
1639 * Specify the client API to use for subsequent calls including:
1640 * eglCreateContext()
1641 * eglGetCurrentContext()
1642 * eglGetCurrentDisplay()
1643 * eglGetCurrentSurface()
1644 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1647 * See section 3.7 "Rendering Context" in the EGL specification for details.
1649 EGLBoolean EGLAPIENTRY
1650 eglBindAPI(EGLenum api
)
1654 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1656 t
= _eglGetCurrentThread();
1657 if (_eglIsCurrentThreadDummy())
1658 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1660 if (!_eglIsApiValid(api
))
1661 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1663 t
->CurrentAPI
= api
;
1665 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1670 * Return the last value set with eglBindAPI().
1675 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1678 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1679 ret
= t
->CurrentAPI
;
1681 RETURN_EGL_SUCCESS(NULL
, ret
);
1685 EGLSurface EGLAPIENTRY
1686 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1687 EGLClientBuffer buffer
, EGLConfig config
,
1688 const EGLint
*attrib_list
)
1690 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1691 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1694 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1696 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1698 /* OpenVG is not supported */
1699 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1703 EGLBoolean EGLAPIENTRY
1704 eglReleaseThread(void)
1706 /* unbind current contexts */
1707 if (!_eglIsCurrentThreadDummy()) {
1708 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1709 _EGLContext
*ctx
= t
->CurrentContext
;
1711 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1714 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1717 mtx_lock(&disp
->Mutex
);
1719 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1720 mtx_unlock(&disp
->Mutex
);
1724 _eglDestroyCurrentThread();
1726 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1731 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1732 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1734 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1739 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1740 if (!disp
->Extensions
.KHR_image_base
)
1741 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1742 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1743 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1744 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1745 * <ctx> must be EGL_NO_CONTEXT..."
1747 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1748 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1750 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1752 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1754 RETURN_EGL_EVAL(disp
, ret
);
1757 static EGLImage EGLAPIENTRY
1758 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1759 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1761 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1762 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1763 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1767 EGLImage EGLAPIENTRY
1768 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1769 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1771 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1773 EGLint
*int_attribs
;
1775 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1777 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1778 if (attr_list
&& !int_attribs
)
1779 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1781 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1788 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1793 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1794 if (!disp
->Extensions
.KHR_image_base
)
1795 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1797 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1799 _eglUnlinkImage(img
);
1800 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1802 RETURN_EGL_EVAL(disp
, ret
);
1805 EGLBoolean EGLAPIENTRY
1806 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1808 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1809 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1810 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1811 return _eglDestroyImageCommon(disp
, img
);
1814 static EGLBoolean EGLAPIENTRY
1815 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1817 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1818 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1819 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1820 return _eglDestroyImageCommon(disp
, img
);
1825 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1826 EGLBoolean orig_is_EGLAttrib
,
1827 EGLenum invalid_type_error
)
1829 _EGLContext
*ctx
= _eglGetCurrentContext();
1834 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1836 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1837 /* There exist two EGLAttrib variants of eglCreateSync*:
1838 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1839 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1840 * support as a proxy for EGL 1.5 support, even though that's not
1841 * entirely correct (though _eglComputeVersion does the same).
1843 * The EGL spec provides no guidance on how to handle unsupported
1844 * functions. EGL_BAD_MATCH seems reasonable.
1846 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1849 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1850 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1851 * error is generated.
1854 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1855 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1857 /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */
1858 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1859 (ctx
->ClientAPI
!= EGL_OPENGL_ES_API
&&
1860 ctx
->ClientAPI
!= EGL_OPENGL_API
)))
1861 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1864 case EGL_SYNC_FENCE_KHR
:
1865 if (!disp
->Extensions
.KHR_fence_sync
)
1866 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1868 case EGL_SYNC_REUSABLE_KHR
:
1869 if (!disp
->Extensions
.KHR_reusable_sync
)
1870 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1872 case EGL_SYNC_CL_EVENT_KHR
:
1873 if (!disp
->Extensions
.KHR_cl_event2
)
1874 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1876 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1877 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1878 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1881 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1884 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1885 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1887 RETURN_EGL_EVAL(disp
, ret
);
1891 static EGLSync EGLAPIENTRY
1892 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1894 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1895 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1898 EGLAttrib
*attrib_list
;
1901 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1902 attrib_list
= (EGLAttrib
*) int_list
;
1904 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1905 if (err
!= EGL_SUCCESS
)
1906 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1909 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1912 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1915 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1920 static EGLSync EGLAPIENTRY
1921 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1923 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1924 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1925 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1931 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1933 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1934 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1935 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1941 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1946 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1947 assert(disp
->Extensions
.KHR_reusable_sync
||
1948 disp
->Extensions
.KHR_fence_sync
||
1949 disp
->Extensions
.ANDROID_native_fence_sync
);
1952 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1954 RETURN_EGL_EVAL(disp
, ret
);
1957 EGLBoolean EGLAPIENTRY
1958 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1960 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1961 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1962 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1963 return _eglDestroySync(disp
, s
);
1966 static EGLBoolean EGLAPIENTRY
1967 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1969 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1970 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1971 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1972 return _eglDestroySync(disp
, s
);
1977 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1978 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1983 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1984 assert(disp
->Extensions
.KHR_reusable_sync
||
1985 disp
->Extensions
.KHR_fence_sync
||
1986 disp
->Extensions
.ANDROID_native_fence_sync
);
1988 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1989 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1991 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1992 * unlocked here to allow other threads also to be able to
1993 * go into waiting state.
1996 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1997 _eglUnlockDisplay(dpy
);
1999 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
2002 * 'disp' is already unlocked for reusable sync type,
2003 * so passing 'NULL' to bypass unlocking display.
2005 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
2006 RETURN_EGL_EVAL(NULL
, ret
);
2008 RETURN_EGL_EVAL(disp
, ret
);
2012 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
2013 EGLint flags
, EGLTime timeout
)
2015 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2016 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2017 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2018 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2021 static EGLint EGLAPIENTRY
2022 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
2023 EGLint flags
, EGLTime timeout
)
2025 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2026 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2027 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2028 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2033 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
2035 _EGLContext
*ctx
= _eglGetCurrentContext();
2039 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2040 assert(disp
->Extensions
.KHR_wait_sync
);
2042 /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */
2043 if (ctx
== EGL_NO_CONTEXT
||
2044 (ctx
->ClientAPI
!= EGL_OPENGL_ES_API
&&
2045 ctx
->ClientAPI
!= EGL_OPENGL_API
))
2046 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
2048 /* the API doesn't allow any flags yet */
2050 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2052 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
2054 RETURN_EGL_EVAL(disp
, ret
);
2057 static EGLint EGLAPIENTRY
2058 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2060 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2061 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2062 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2063 return _eglWaitSyncCommon(disp
, s
, flags
);
2067 EGLBoolean EGLAPIENTRY
2068 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2070 /* The KHR version returns EGLint, while the core version returns
2071 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2074 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2075 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2076 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2077 return _eglWaitSyncCommon(disp
, s
, flags
);
2081 static EGLBoolean EGLAPIENTRY
2082 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2084 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2085 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2089 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2091 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2092 assert(disp
->Extensions
.KHR_reusable_sync
);
2093 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2095 RETURN_EGL_EVAL(disp
, ret
);
2100 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2105 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2106 assert(disp
->Extensions
.KHR_reusable_sync
||
2107 disp
->Extensions
.KHR_fence_sync
||
2108 disp
->Extensions
.ANDROID_native_fence_sync
);
2110 ret
= _eglGetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2112 RETURN_EGL_EVAL(disp
, ret
);
2115 EGLBoolean EGLAPIENTRY
2116 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2118 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2119 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2120 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2123 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2125 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2129 static EGLBoolean EGLAPIENTRY
2130 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2132 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2133 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2137 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2140 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2143 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2145 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2147 * If any error occurs, <*value> is not modified.
2149 if (result
== EGL_FALSE
)
2156 static EGLint EGLAPIENTRY
2157 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2159 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2160 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2164 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2166 /* the spec doesn't seem to specify what happens if the fence
2167 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2170 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2171 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2173 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2174 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2175 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2177 RETURN_EGL_EVAL(disp
, ret
);
2180 static EGLBoolean EGLAPIENTRY
2181 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2182 EGLint numRects
, const EGLint
*rects
)
2184 _EGLContext
*ctx
= _eglGetCurrentContext();
2185 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2186 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2190 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2192 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2194 if (!disp
->Extensions
.NOK_swap_region
)
2195 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2197 /* surface must be bound to current context in EGL 1.4 */
2198 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2199 surf
!= ctx
->DrawSurface
)
2200 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2202 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2204 RETURN_EGL_EVAL(disp
, ret
);
2208 static EGLImage EGLAPIENTRY
2209 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2211 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2216 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2218 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2219 if (!disp
->Extensions
.MESA_drm_image
)
2220 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2222 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2223 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2225 RETURN_EGL_EVAL(disp
, ret
);
2228 static EGLBoolean EGLAPIENTRY
2229 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2230 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2232 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2233 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2237 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2239 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2240 assert(disp
->Extensions
.MESA_drm_image
);
2243 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2245 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2247 RETURN_EGL_EVAL(disp
, ret
);
2253 static EGLBoolean EGLAPIENTRY
2254 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2256 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2260 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2262 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2263 assert(disp
->Extensions
.WL_bind_wayland_display
);
2266 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2268 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2270 RETURN_EGL_EVAL(disp
, ret
);
2273 static EGLBoolean EGLAPIENTRY
2274 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2276 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2280 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2282 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2283 assert(disp
->Extensions
.WL_bind_wayland_display
);
2286 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2288 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2290 RETURN_EGL_EVAL(disp
, ret
);
2293 static EGLBoolean EGLAPIENTRY
2294 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2295 EGLint attribute
, EGLint
*value
)
2297 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2301 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2303 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2304 assert(disp
->Extensions
.WL_bind_wayland_display
);
2307 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2309 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2311 RETURN_EGL_EVAL(disp
, ret
);
2315 static struct wl_buffer
* EGLAPIENTRY
2316 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2318 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2321 struct wl_buffer
*ret
;
2323 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2325 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2326 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2327 RETURN_EGL_EVAL(disp
, NULL
);
2329 img
= _eglLookupImage(image
, disp
);
2332 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2334 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2336 RETURN_EGL_EVAL(disp
, ret
);
2339 static EGLBoolean EGLAPIENTRY
2340 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2341 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2343 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2344 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2348 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2350 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2352 if (!disp
->Extensions
.NV_post_sub_buffer
)
2353 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2355 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2357 RETURN_EGL_EVAL(disp
, ret
);
2360 static EGLBoolean EGLAPIENTRY
2361 eglGetSyncValuesCHROMIUM(EGLDisplay dpy
, EGLSurface surface
,
2362 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2365 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2366 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2370 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2372 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2373 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2374 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2376 if (!ust
|| !msc
|| !sbc
)
2377 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2379 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2381 RETURN_EGL_EVAL(disp
, ret
);
2384 static EGLBoolean EGLAPIENTRY
2385 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2386 EGLint
*fourcc
, EGLint
*nplanes
,
2387 EGLuint64KHR
*modifiers
)
2389 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2390 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2394 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2396 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2397 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2400 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2402 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2405 RETURN_EGL_EVAL(disp
, ret
);
2408 static EGLBoolean EGLAPIENTRY
2409 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2410 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2412 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2413 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2417 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2419 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2420 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2423 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2425 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2427 RETURN_EGL_EVAL(disp
, ret
);
2430 static EGLint EGLAPIENTRY
2431 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2434 _EGLDisplay
*disp
= NULL
;
2435 _EGLResourceType type
;
2437 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2439 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2440 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2442 if (!_eglIsCurrentThreadDummy()) {
2447 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2450 disp
= _eglLockDisplay(dpy
);
2452 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2454 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2455 if (dpy
!= (EGLDisplay
) object
)
2456 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2458 disp
->Label
= label
;
2459 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2462 switch (objectType
) {
2463 case EGL_OBJECT_CONTEXT_KHR
:
2464 type
= _EGL_RESOURCE_CONTEXT
;
2466 case EGL_OBJECT_SURFACE_KHR
:
2467 type
= _EGL_RESOURCE_SURFACE
;
2469 case EGL_OBJECT_IMAGE_KHR
:
2470 type
= _EGL_RESOURCE_IMAGE
;
2472 case EGL_OBJECT_SYNC_KHR
:
2473 type
= _EGL_RESOURCE_SYNC
;
2475 case EGL_OBJECT_STREAM_KHR
:
2477 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2480 if (_eglCheckResource(object
, type
, disp
)) {
2481 _EGLResource
*res
= (_EGLResource
*) object
;
2484 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2487 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2490 static EGLint EGLAPIENTRY
2491 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2492 const EGLAttrib
*attrib_list
)
2494 unsigned int newEnabled
;
2496 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2498 mtx_lock(_eglGlobal
.Mutex
);
2500 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2501 if (attrib_list
!= NULL
) {
2504 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2505 switch (attrib_list
[i
]) {
2506 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2507 case EGL_DEBUG_MSG_ERROR_KHR
:
2508 case EGL_DEBUG_MSG_WARN_KHR
:
2509 case EGL_DEBUG_MSG_INFO_KHR
:
2510 if (attrib_list
[i
+ 1])
2511 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2513 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2516 // On error, set the last error code, call the current
2517 // debug callback, and return the error code.
2518 mtx_unlock(_eglGlobal
.Mutex
);
2519 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2520 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2521 return EGL_BAD_ATTRIBUTE
;
2526 if (callback
!= NULL
) {
2527 _eglGlobal
.debugCallback
= callback
;
2528 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2530 _eglGlobal
.debugCallback
= NULL
;
2531 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2534 mtx_unlock(_eglGlobal
.Mutex
);
2538 static EGLBoolean EGLAPIENTRY
2539 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2541 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2543 mtx_lock(_eglGlobal
.Mutex
);
2545 switch (attribute
) {
2546 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2547 case EGL_DEBUG_MSG_ERROR_KHR
:
2548 case EGL_DEBUG_MSG_WARN_KHR
:
2549 case EGL_DEBUG_MSG_INFO_KHR
:
2550 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2555 case EGL_DEBUG_CALLBACK_KHR
:
2556 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2559 mtx_unlock(_eglGlobal
.Mutex
);
2560 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2561 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2565 mtx_unlock(_eglGlobal
.Mutex
);
2570 _eglFunctionCompare(const void *key
, const void *elem
)
2572 const char *procname
= key
;
2573 const struct _egl_entrypoint
*entrypoint
= elem
;
2574 return strcmp(procname
, entrypoint
->name
);
2577 static EGLBoolean EGLAPIENTRY
2578 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2579 EGLint
*formats
, EGLint
*num_formats
)
2581 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2585 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2587 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2589 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2592 RETURN_EGL_EVAL(disp
, ret
);
2595 static EGLBoolean EGLAPIENTRY
2596 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2597 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2598 EGLint
*num_modifiers
)
2600 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2604 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2606 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2608 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2609 modifiers
, external_only
,
2612 RETURN_EGL_EVAL(disp
, ret
);
2615 static void EGLAPIENTRY
2616 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2617 EGLGetBlobFuncANDROID get
)
2619 /* This function does not return anything so we cannot
2620 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2622 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2623 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2625 _eglUnlockDisplay(disp
);
2629 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2632 _eglUnlockDisplay(disp
);
2637 _eglError(EGL_BAD_PARAMETER
,
2638 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2639 _eglUnlockDisplay(disp
);
2643 if (disp
->BlobCacheSet
) {
2644 _eglError(EGL_BAD_PARAMETER
,
2645 "eglSetBlobCacheFuncsANDROID: functions already set");
2646 _eglUnlockDisplay(disp
);
2650 disp
->BlobCacheSet
= set
;
2651 disp
->BlobCacheGet
= get
;
2653 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2655 _eglUnlockDisplay(disp
);
2658 static EGLBoolean EGLAPIENTRY
2659 eglQueryDeviceAttribEXT(EGLDeviceEXT device
,
2663 _EGLDevice
*dev
= _eglLookupDevice(device
);
2666 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2668 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, EGL_FALSE
);
2670 ret
= _eglQueryDeviceAttribEXT(dev
, attribute
, value
);
2671 RETURN_EGL_EVAL(NULL
, ret
);
2674 static const char * EGLAPIENTRY
2675 eglQueryDeviceStringEXT(EGLDeviceEXT device
,
2678 _EGLDevice
*dev
= _eglLookupDevice(device
);
2680 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2682 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, NULL
);
2684 RETURN_EGL_EVAL(NULL
, _eglQueryDeviceStringEXT(dev
, name
));
2687 static EGLBoolean EGLAPIENTRY
2688 eglQueryDevicesEXT(EGLint max_devices
,
2689 EGLDeviceEXT
*devices
,
2690 EGLint
*num_devices
)
2694 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2695 ret
= _eglQueryDevicesEXT(max_devices
, (_EGLDevice
**) devices
,
2697 RETURN_EGL_EVAL(NULL
, ret
);
2700 static EGLBoolean EGLAPIENTRY
2701 eglQueryDisplayAttribEXT(EGLDisplay dpy
,
2705 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2708 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2709 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2711 switch (attribute
) {
2712 case EGL_DEVICE_EXT
:
2713 *value
= (EGLAttrib
) disp
->Device
;
2716 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
2718 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
2721 static char * EGLAPIENTRY
2722 eglGetDisplayDriverConfig(EGLDisplay dpy
)
2724 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2728 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2729 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2731 assert(disp
->Extensions
.MESA_query_driver
);
2733 ret
= drv
->API
.QueryDriverConfig(disp
);
2734 RETURN_EGL_EVAL(disp
, ret
);
2737 static const char * EGLAPIENTRY
2738 eglGetDisplayDriverName(EGLDisplay dpy
)
2740 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2744 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2745 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2747 assert(disp
->Extensions
.MESA_query_driver
);
2749 ret
= drv
->API
.QueryDriverName(disp
);
2750 RETURN_EGL_EVAL(disp
, ret
);
2753 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2754 eglGetProcAddress(const char *procname
)
2756 static const struct _egl_entrypoint egl_functions
[] = {
2757 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2758 #include "eglentrypoint.h"
2759 #undef EGL_ENTRYPOINT
2761 _EGLProc ret
= NULL
;
2764 RETURN_EGL_SUCCESS(NULL
, NULL
);
2766 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2768 if (strncmp(procname
, "egl", 3) == 0) {
2769 const struct _egl_entrypoint
*entrypoint
=
2771 egl_functions
, ARRAY_SIZE(egl_functions
),
2772 sizeof(egl_functions
[0]),
2773 _eglFunctionCompare
);
2775 ret
= entrypoint
->function
;
2779 ret
= _eglGetDriverProc(procname
);
2781 RETURN_EGL_SUCCESS(NULL
, ret
);
2785 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2786 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2790 *disp
= _eglLockDisplay(dpy
);
2791 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2793 _eglUnlockDisplay(*disp
);
2794 return MESA_GLINTEROP_INVALID_DISPLAY
;
2797 *drv
= (*disp
)->Driver
;
2799 *ctx
= _eglLookupContext(context
, *disp
);
2801 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2802 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2803 _eglUnlockDisplay(*disp
);
2804 return MESA_GLINTEROP_INVALID_CONTEXT
;
2807 return MESA_GLINTEROP_SUCCESS
;
2811 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2812 struct mesa_glinterop_device_info
*out
)
2819 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2820 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2823 if (drv
->API
.GLInteropQueryDeviceInfo
)
2824 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2826 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2828 _eglUnlockDisplay(disp
);
2833 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2834 struct mesa_glinterop_export_in
*in
,
2835 struct mesa_glinterop_export_out
*out
)
2842 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2843 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2846 if (drv
->API
.GLInteropExportObject
)
2847 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2849 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2851 _eglUnlockDisplay(disp
);