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 case EGL_PLATFORM_DEVICE_EXT
:
410 disp
= _eglGetDeviceDisplay(native_display
, attrib_list
);
413 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
416 return _eglGetDisplayHandle(disp
);
419 static EGLDisplay EGLAPIENTRY
420 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
421 const EGLint
*int_attribs
)
423 EGLAttrib
*attrib_list
;
426 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
428 if (_eglConvertIntsToAttribs(int_attribs
, &attrib_list
) != EGL_SUCCESS
)
429 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
431 disp
= _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
436 EGLDisplay EGLAPIENTRY
437 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
438 const EGLAttrib
*attrib_list
)
440 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
441 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
445 * Copy the extension into the string and update the string pointer.
448 _eglAppendExtension(char **str
, const char *ext
)
451 size_t len
= strlen(ext
);
468 * Examine the individual extension enable/disable flags and recompute
469 * the driver's Extensions string.
472 _eglCreateExtensionsString(_EGLDisplay
*disp
)
474 #define _EGL_CHECK_EXTENSION(ext) \
476 if (disp->Extensions.ext) { \
477 _eglAppendExtension(&exts, "EGL_" #ext); \
478 assert(exts <= disp->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
482 char *exts
= disp
->ExtensionsString
;
484 /* Please keep these sorted alphabetically. */
485 _EGL_CHECK_EXTENSION(ANDROID_blob_cache
);
486 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
487 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
488 _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync
);
489 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
491 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
493 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
494 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
495 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
496 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers
);
497 _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata
);
498 _EGL_CHECK_EXTENSION(EXT_surface_SMPTE2086_metadata
);
499 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
501 _EGL_CHECK_EXTENSION(IMG_context_priority
);
503 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
504 _EGL_CHECK_EXTENSION(KHR_config_attribs
);
505 _EGL_CHECK_EXTENSION(KHR_context_flush_control
);
506 _EGL_CHECK_EXTENSION(KHR_create_context
);
507 _EGL_CHECK_EXTENSION(KHR_create_context_no_error
);
508 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
509 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
510 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
511 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
512 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
513 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
514 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
515 if (disp
->Extensions
.KHR_image_base
&& disp
->Extensions
.KHR_image_pixmap
)
516 disp
->Extensions
.KHR_image
= EGL_TRUE
;
517 _EGL_CHECK_EXTENSION(KHR_image
);
518 _EGL_CHECK_EXTENSION(KHR_image_base
);
519 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
520 _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer
);
521 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
522 _EGL_CHECK_EXTENSION(KHR_partial_update
);
523 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
524 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
525 if (disp
->Extensions
.EXT_swap_buffers_with_damage
)
526 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
527 _EGL_CHECK_EXTENSION(EXT_pixel_format_float
);
528 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
530 if (disp
->Extensions
.KHR_no_config_context
)
531 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
532 _EGL_CHECK_EXTENSION(MESA_drm_image
);
533 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
534 _EGL_CHECK_EXTENSION(MESA_query_driver
);
536 _EGL_CHECK_EXTENSION(NOK_swap_region
);
537 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
539 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
541 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
542 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
544 #undef _EGL_CHECK_EXTENSION
548 _eglCreateAPIsString(_EGLDisplay
*disp
)
550 #define addstr(str) \
552 const size_t old_len = strlen(disp->ClientAPIsString); \
553 const size_t add_len = sizeof(str); \
554 const size_t max_len = sizeof(disp->ClientAPIsString) - 1; \
555 if (old_len + add_len <= max_len) \
556 strcat(disp->ClientAPIsString, str " "); \
558 assert(!"disp->ClientAPIsString is not large enough"); \
561 if (disp
->ClientAPIs
& EGL_OPENGL_BIT
)
564 if (disp
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
565 disp
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
566 disp
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
570 if (disp
->ClientAPIs
& EGL_OPENVG_BIT
)
577 _eglComputeVersion(_EGLDisplay
*disp
)
581 if (disp
->Extensions
.KHR_fence_sync
&&
582 disp
->Extensions
.KHR_cl_event2
&&
583 disp
->Extensions
.KHR_wait_sync
&&
584 disp
->Extensions
.KHR_image_base
&&
585 disp
->Extensions
.KHR_gl_texture_2D_image
&&
586 disp
->Extensions
.KHR_gl_texture_3D_image
&&
587 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
588 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
589 disp
->Extensions
.KHR_create_context
&&
590 disp
->Extensions
.EXT_create_context_robustness
&&
591 disp
->Extensions
.KHR_get_all_proc_addresses
&&
592 disp
->Extensions
.KHR_gl_colorspace
&&
593 disp
->Extensions
.KHR_surfaceless_context
)
598 * This is typically the second EGL function that an application calls.
599 * Here we load/initialize the actual hardware driver.
601 EGLBoolean EGLAPIENTRY
602 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
604 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
606 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
609 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
611 if (!disp
->Initialized
) {
612 if (!_eglMatchDriver(disp
))
613 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
615 /* limit to APIs supported by core */
616 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
618 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
619 * classifies it as an EGL display extension, though conceptually it's an
620 * EGL client extension.
622 * From the EGL_KHR_get_all_proc_addresses spec:
624 * The EGL implementation must expose the name
625 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
626 * EGL_KHR_get_all_proc_addresses and supports
627 * EGL_EXT_client_extensions.
629 * Mesa unconditionally exposes both client extensions mentioned above,
630 * so the spec requires that each EGLDisplay unconditionally expose
631 * EGL_KHR_get_all_proc_addresses also.
633 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
635 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
636 * programs. It is driver agnostic and handled in the main EGL code.
638 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
640 _eglComputeVersion(disp
);
641 _eglCreateExtensionsString(disp
);
642 _eglCreateAPIsString(disp
);
643 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
644 "%d.%d", disp
->Version
/ 10, disp
->Version
% 10);
647 /* Update applications version of major and minor if not NULL */
648 if ((major
!= NULL
) && (minor
!= NULL
)) {
649 *major
= disp
->Version
/ 10;
650 *minor
= disp
->Version
% 10;
653 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
657 EGLBoolean EGLAPIENTRY
658 eglTerminate(EGLDisplay dpy
)
660 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
662 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
665 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
667 if (disp
->Initialized
) {
668 _EGLDriver
*drv
= disp
->Driver
;
670 drv
->API
.Terminate(drv
, disp
);
671 /* do not reset disp->Driver */
672 disp
->ClientAPIsString
[0] = 0;
673 disp
->Initialized
= EGL_FALSE
;
676 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
680 const char * EGLAPIENTRY
681 eglQueryString(EGLDisplay dpy
, EGLint name
)
686 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
687 const char *ret
= _eglGetClientExtensionString();
689 RETURN_EGL_SUCCESS(NULL
, ret
);
691 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
694 disp
= _eglLockDisplay(dpy
);
695 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
696 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
700 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
702 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
704 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
705 case EGL_CLIENT_APIS
:
706 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
708 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
713 EGLBoolean EGLAPIENTRY
714 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
715 EGLint config_size
, EGLint
*num_config
)
717 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
721 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
723 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
726 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
728 if (drv
->API
.GetConfigs
)
729 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
731 ret
= _eglGetConfigs(drv
, disp
, configs
, config_size
, num_config
);
733 RETURN_EGL_EVAL(disp
, ret
);
737 EGLBoolean EGLAPIENTRY
738 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
739 EGLint config_size
, EGLint
*num_config
)
741 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
745 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
747 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
750 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
752 if (drv
->API
.ChooseConfig
)
753 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
754 config_size
, num_config
);
756 ret
= _eglChooseConfig(drv
, disp
, attrib_list
, configs
,
757 config_size
, num_config
);
759 RETURN_EGL_EVAL(disp
, ret
);
763 EGLBoolean EGLAPIENTRY
764 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
765 EGLint attribute
, EGLint
*value
)
767 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
768 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
772 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
774 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
776 if (drv
->API
.GetConfigAttrib
)
777 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
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 if (drv
->API
.QueryContext
)
905 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
907 ret
= _eglQueryContext(drv
, disp
, context
, attribute
, value
);
909 RETURN_EGL_EVAL(disp
, ret
);
913 /* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says
914 * that if native_surface was already used to create a window or pixmap, we
915 * can't create a new one. This is what this function checks for.
918 _eglNativeSurfaceAlreadyUsed(_EGLDisplay
*disp
, void *native_surface
)
922 list
= disp
->ResourceLists
[_EGL_RESOURCE_SURFACE
];
924 _EGLSurface
*surf
= (_EGLSurface
*) list
;
928 if (surf
->Type
== EGL_PBUFFER_BIT
)
931 if (surf
->NativeSurface
== native_surface
)
940 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
941 void *native_window
, const EGLint
*attrib_list
)
943 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
949 if (native_window
== NULL
)
950 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
952 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
953 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
954 /* From the EGL_MESA_platform_surfaceless spec (v1):
956 * eglCreatePlatformWindowSurface fails when called with a <display>
957 * that belongs to the surfaceless platform. It returns
958 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
959 * justification for this unconditional failure is that the
960 * surfaceless platform has no native windows, and therefore the
961 * <native_window> parameter is always invalid.
963 * This check must occur before checking the EGLConfig, which emits
966 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
969 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
971 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
972 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
974 if (_eglNativeSurfaceAlreadyUsed(disp
, native_window
))
975 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
977 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
979 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
981 RETURN_EGL_EVAL(disp
, ret
);
985 EGLSurface EGLAPIENTRY
986 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
987 EGLNativeWindowType window
, const EGLint
*attrib_list
)
989 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
991 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
992 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
993 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
998 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
1000 #ifdef HAVE_X11_PLATFORM
1001 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
1002 /* The `native_window` parameter for the X11 platform differs between
1003 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1004 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
1005 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
1006 * `Window*`. Convert `Window*` to `Window` because that's what
1007 * dri2_x11_create_window_surface() expects.
1009 return (void *)(* (Window
*) native_window
);
1012 return native_window
;
1015 static EGLSurface EGLAPIENTRY
1016 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1017 void *native_window
,
1018 const EGLint
*attrib_list
)
1020 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1022 native_window
= _fixupNativeWindow(disp
, native_window
);
1024 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1025 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1030 EGLSurface EGLAPIENTRY
1031 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
1032 void *native_window
,
1033 const EGLAttrib
*attrib_list
)
1035 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1037 EGLint
*int_attribs
;
1039 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1041 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1042 if (attrib_list
&& !int_attribs
)
1043 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1045 native_window
= _fixupNativeWindow(disp
, native_window
);
1046 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1053 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
1055 #ifdef HAVE_X11_PLATFORM
1056 /* The `native_pixmap` parameter for the X11 platform differs between
1057 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1058 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1059 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1060 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1061 * dri2_x11_create_pixmap_surface() expects.
1063 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
1064 return (void *)(* (Pixmap
*) native_pixmap
);
1066 return native_pixmap
;
1070 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1071 void *native_pixmap
, const EGLint
*attrib_list
)
1073 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1078 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
1079 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
1080 /* From the EGL_MESA_platform_surfaceless spec (v1):
1082 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1083 * also fails when called with a <display> that belongs to the
1084 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1085 * EGL_BAD_NATIVE_PIXMAP.
1087 * This check must occur before checking the EGLConfig, which emits
1090 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1093 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1095 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1096 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1098 if (native_pixmap
== NULL
)
1099 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1101 if (_eglNativeSurfaceAlreadyUsed(disp
, native_pixmap
))
1102 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1104 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1106 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1108 RETURN_EGL_EVAL(disp
, ret
);
1112 EGLSurface EGLAPIENTRY
1113 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1114 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1116 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1118 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1119 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1120 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1124 static EGLSurface EGLAPIENTRY
1125 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1126 void *native_pixmap
,
1127 const EGLint
*attrib_list
)
1129 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1131 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1132 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1133 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1138 EGLSurface EGLAPIENTRY
1139 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1140 void *native_pixmap
,
1141 const EGLAttrib
*attrib_list
)
1143 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1145 EGLint
*int_attribs
;
1147 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1149 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1150 if (attrib_list
&& !int_attribs
)
1151 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1153 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1154 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1161 EGLSurface EGLAPIENTRY
1162 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1163 const EGLint
*attrib_list
)
1165 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1166 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1171 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1172 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1174 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1175 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1177 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1178 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1180 RETURN_EGL_EVAL(disp
, ret
);
1184 EGLBoolean EGLAPIENTRY
1185 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1187 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1188 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1192 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1193 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1194 _eglUnlinkSurface(surf
);
1195 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1197 RETURN_EGL_EVAL(disp
, ret
);
1200 EGLBoolean EGLAPIENTRY
1201 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1202 EGLint attribute
, EGLint
*value
)
1204 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1205 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1209 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1210 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1212 if (drv
->API
.QuerySurface
)
1213 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1215 ret
= _eglQuerySurface(drv
, disp
, surf
, attribute
, value
);
1217 RETURN_EGL_EVAL(disp
, ret
);
1220 EGLBoolean EGLAPIENTRY
1221 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1222 EGLint attribute
, EGLint value
)
1224 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1225 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1229 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1230 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1232 if (drv
->API
.SurfaceAttrib
)
1233 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1235 ret
= _eglSurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1237 RETURN_EGL_EVAL(disp
, ret
);
1241 EGLBoolean EGLAPIENTRY
1242 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1244 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1245 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1249 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1250 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1251 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1253 RETURN_EGL_EVAL(disp
, ret
);
1257 EGLBoolean EGLAPIENTRY
1258 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1260 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1261 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1265 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1266 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1267 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1269 RETURN_EGL_EVAL(disp
, ret
);
1273 EGLBoolean EGLAPIENTRY
1274 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1276 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1277 _EGLContext
*ctx
= _eglGetCurrentContext();
1278 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1282 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1283 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1285 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1286 ctx
->Resource
.Display
!= disp
)
1287 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1289 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1290 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1292 if (surf
->Type
!= EGL_WINDOW_BIT
)
1293 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1295 interval
= CLAMP(interval
,
1296 surf
->Config
->MinSwapInterval
,
1297 surf
->Config
->MaxSwapInterval
);
1299 if (surf
->SwapInterval
!= interval
)
1300 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1305 surf
->SwapInterval
= interval
;
1307 RETURN_EGL_EVAL(disp
, ret
);
1311 EGLBoolean EGLAPIENTRY
1312 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1314 _EGLContext
*ctx
= _eglGetCurrentContext();
1315 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1316 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1320 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1321 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1323 /* surface must be bound to current context in EGL 1.4 */
1324 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1325 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1326 surf
!= ctx
->DrawSurface
)
1327 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1330 if (surf
->Type
!= EGL_WINDOW_BIT
)
1331 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1333 /* From the EGL 1.5 spec:
1335 * If eglSwapBuffers is called and the native window associated with
1336 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1340 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1342 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1344 /* EGL_KHR_partial_update
1345 * Frame boundary successfully reached,
1346 * reset damage region and reset BufferAgeRead
1349 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1350 surf
->BufferAgeRead
= EGL_FALSE
;
1353 RETURN_EGL_EVAL(disp
, ret
);
1358 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1359 EGLint
*rects
, EGLint n_rects
)
1361 _EGLContext
*ctx
= _eglGetCurrentContext();
1365 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1367 /* surface must be bound to current context in EGL 1.4 */
1368 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1369 surf
!= ctx
->DrawSurface
)
1370 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1372 if (surf
->Type
!= EGL_WINDOW_BIT
)
1373 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1375 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1376 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1378 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1380 /* EGL_KHR_partial_update
1381 * Frame boundary successfully reached,
1382 * reset damage region and reset BufferAgeRead
1385 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1386 surf
->BufferAgeRead
= EGL_FALSE
;
1389 RETURN_EGL_EVAL(disp
, ret
);
1392 static EGLBoolean EGLAPIENTRY
1393 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1394 EGLint
*rects
, EGLint n_rects
)
1396 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1397 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1398 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1399 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1402 static EGLBoolean EGLAPIENTRY
1403 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1404 EGLint
*rects
, EGLint n_rects
)
1406 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1407 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1408 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1409 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1413 * Clamp the rectangles so that they lie within the surface.
1417 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1418 EGLint
*rects
, EGLint n_rects
)
1421 EGLint surf_height
= surf
->Height
;
1422 EGLint surf_width
= surf
->Width
;
1424 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1425 EGLint x1
, y1
, x2
, y2
;
1428 x2
= rects
[i
+ 2] + x1
;
1429 y2
= rects
[i
+ 3] + y1
;
1431 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1432 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1433 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1434 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1438 static EGLBoolean EGLAPIENTRY
1439 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1440 EGLint
*rects
, EGLint n_rects
)
1442 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1443 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1444 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1445 _EGLContext
*ctx
= _eglGetCurrentContext();
1448 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1450 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1451 surf
->Type
!= EGL_WINDOW_BIT
||
1452 ctx
->DrawSurface
!= surf
||
1453 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1454 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1456 /* If the damage region is already set or
1457 * buffer age is not queried between
1458 * frame boundaries, throw bad access error
1461 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1462 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1464 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1465 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1468 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1470 RETURN_EGL_EVAL(disp
, ret
);
1473 EGLBoolean EGLAPIENTRY
1474 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1476 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1477 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1480 void *native_pixmap_ptr
;
1482 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1483 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1484 native_pixmap_ptr
= (void*) target
;
1486 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1487 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1489 RETURN_EGL_EVAL(disp
, ret
);
1494 _eglWaitClientCommon(void)
1496 _EGLContext
*ctx
= _eglGetCurrentContext();
1502 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1504 disp
= ctx
->Resource
.Display
;
1505 mtx_lock(&disp
->Mutex
);
1507 /* let bad current context imply bad current surface */
1508 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1509 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1510 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1512 /* a valid current context implies an initialized current display */
1513 assert(disp
->Initialized
);
1515 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1517 RETURN_EGL_EVAL(disp
, ret
);
1520 EGLBoolean EGLAPIENTRY
1523 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1524 return _eglWaitClientCommon();
1527 EGLBoolean EGLAPIENTRY
1530 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1531 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1532 return _eglWaitClientCommon();
1536 EGLBoolean EGLAPIENTRY
1537 eglWaitNative(EGLint engine
)
1539 _EGLContext
*ctx
= _eglGetCurrentContext();
1545 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1547 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1549 disp
= ctx
->Resource
.Display
;
1550 mtx_lock(&disp
->Mutex
);
1552 /* let bad current context imply bad current surface */
1553 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1554 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1555 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1557 /* a valid current context implies an initialized current display */
1558 assert(disp
->Initialized
);
1560 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1562 RETURN_EGL_EVAL(disp
, ret
);
1566 EGLDisplay EGLAPIENTRY
1567 eglGetCurrentDisplay(void)
1569 _EGLContext
*ctx
= _eglGetCurrentContext();
1572 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1574 RETURN_EGL_SUCCESS(NULL
, ret
);
1578 EGLContext EGLAPIENTRY
1579 eglGetCurrentContext(void)
1581 _EGLContext
*ctx
= _eglGetCurrentContext();
1584 ret
= _eglGetContextHandle(ctx
);
1586 RETURN_EGL_SUCCESS(NULL
, ret
);
1590 EGLSurface EGLAPIENTRY
1591 eglGetCurrentSurface(EGLint readdraw
)
1593 _EGLContext
*ctx
= _eglGetCurrentContext();
1594 EGLint err
= EGL_SUCCESS
;
1598 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1601 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1605 surf
= ctx
->DrawSurface
;
1608 surf
= ctx
->ReadSurface
;
1612 err
= EGL_BAD_PARAMETER
;
1616 ret
= _eglGetSurfaceHandle(surf
);
1618 RETURN_EGL_ERROR(NULL
, err
, ret
);
1625 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1626 EGLint e
= t
->LastError
;
1627 if (!_eglIsCurrentThreadDummy())
1628 t
->LastError
= EGL_SUCCESS
;
1638 * Specify the client API to use for subsequent calls including:
1639 * eglCreateContext()
1640 * eglGetCurrentContext()
1641 * eglGetCurrentDisplay()
1642 * eglGetCurrentSurface()
1643 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1646 * See section 3.7 "Rendering Context" in the EGL specification for details.
1648 EGLBoolean EGLAPIENTRY
1649 eglBindAPI(EGLenum api
)
1653 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1655 t
= _eglGetCurrentThread();
1656 if (_eglIsCurrentThreadDummy())
1657 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1659 if (!_eglIsApiValid(api
))
1660 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1662 t
->CurrentAPI
= api
;
1664 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1669 * Return the last value set with eglBindAPI().
1674 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1677 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1678 ret
= t
->CurrentAPI
;
1680 RETURN_EGL_SUCCESS(NULL
, ret
);
1684 EGLSurface EGLAPIENTRY
1685 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1686 EGLClientBuffer buffer
, EGLConfig config
,
1687 const EGLint
*attrib_list
)
1689 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1690 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1695 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1697 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1699 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1701 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1703 RETURN_EGL_EVAL(disp
, ret
);
1707 EGLBoolean EGLAPIENTRY
1708 eglReleaseThread(void)
1710 /* unbind current contexts */
1711 if (!_eglIsCurrentThreadDummy()) {
1712 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1713 _EGLContext
*ctx
= t
->CurrentContext
;
1715 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1718 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1721 mtx_lock(&disp
->Mutex
);
1723 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1724 mtx_unlock(&disp
->Mutex
);
1728 _eglDestroyCurrentThread();
1730 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1735 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1736 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1738 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1743 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1744 if (!disp
->Extensions
.KHR_image_base
)
1745 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1746 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1747 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1748 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1749 * <ctx> must be EGL_NO_CONTEXT..."
1751 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1752 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1754 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1756 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1758 RETURN_EGL_EVAL(disp
, ret
);
1761 static EGLImage EGLAPIENTRY
1762 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1763 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1765 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1766 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1767 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1771 EGLImage EGLAPIENTRY
1772 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1773 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1775 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1777 EGLint
*int_attribs
;
1779 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1781 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1782 if (attr_list
&& !int_attribs
)
1783 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1785 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1792 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1797 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1798 if (!disp
->Extensions
.KHR_image_base
)
1799 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1801 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1803 _eglUnlinkImage(img
);
1804 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1806 RETURN_EGL_EVAL(disp
, ret
);
1809 EGLBoolean EGLAPIENTRY
1810 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1812 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1813 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1814 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1815 return _eglDestroyImageCommon(disp
, img
);
1818 static EGLBoolean EGLAPIENTRY
1819 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1821 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1822 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1823 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1824 return _eglDestroyImageCommon(disp
, img
);
1829 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1830 EGLBoolean orig_is_EGLAttrib
,
1831 EGLenum invalid_type_error
)
1833 _EGLContext
*ctx
= _eglGetCurrentContext();
1838 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1840 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1841 /* There exist two EGLAttrib variants of eglCreateSync*:
1842 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1843 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1844 * support as a proxy for EGL 1.5 support, even though that's not
1845 * entirely correct (though _eglComputeVersion does the same).
1847 * The EGL spec provides no guidance on how to handle unsupported
1848 * functions. EGL_BAD_MATCH seems reasonable.
1850 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1853 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1854 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1855 * error is generated.
1858 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1859 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1861 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1862 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1863 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1864 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1867 case EGL_SYNC_FENCE_KHR
:
1868 if (!disp
->Extensions
.KHR_fence_sync
)
1869 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1871 case EGL_SYNC_REUSABLE_KHR
:
1872 if (!disp
->Extensions
.KHR_reusable_sync
)
1873 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1875 case EGL_SYNC_CL_EVENT_KHR
:
1876 if (!disp
->Extensions
.KHR_cl_event2
)
1877 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1879 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1880 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1881 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1884 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1887 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1888 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1890 RETURN_EGL_EVAL(disp
, ret
);
1894 static EGLSync EGLAPIENTRY
1895 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1897 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1898 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1901 EGLAttrib
*attrib_list
;
1904 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1905 attrib_list
= (EGLAttrib
*) int_list
;
1907 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1908 if (err
!= EGL_SUCCESS
)
1909 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1912 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1915 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1918 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1923 static EGLSync EGLAPIENTRY
1924 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1926 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1927 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1928 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1934 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1936 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1937 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1938 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1944 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1949 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1950 assert(disp
->Extensions
.KHR_reusable_sync
||
1951 disp
->Extensions
.KHR_fence_sync
||
1952 disp
->Extensions
.ANDROID_native_fence_sync
);
1955 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1957 RETURN_EGL_EVAL(disp
, ret
);
1960 EGLBoolean EGLAPIENTRY
1961 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1963 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1964 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1965 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1966 return _eglDestroySync(disp
, s
);
1969 static EGLBoolean EGLAPIENTRY
1970 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1972 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1973 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1974 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1975 return _eglDestroySync(disp
, s
);
1980 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1981 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1986 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1987 assert(disp
->Extensions
.KHR_reusable_sync
||
1988 disp
->Extensions
.KHR_fence_sync
||
1989 disp
->Extensions
.ANDROID_native_fence_sync
);
1991 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1992 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1994 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1995 * unlocked here to allow other threads also to be able to
1996 * go into waiting state.
1999 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
2000 _eglUnlockDisplay(dpy
);
2002 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
2005 * 'disp' is already unlocked for reusable sync type,
2006 * so passing 'NULL' to bypass unlocking display.
2008 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
2009 RETURN_EGL_EVAL(NULL
, ret
);
2011 RETURN_EGL_EVAL(disp
, ret
);
2015 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
2016 EGLint flags
, EGLTime timeout
)
2018 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2019 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2020 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2021 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2024 static EGLint EGLAPIENTRY
2025 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
2026 EGLint flags
, EGLTime timeout
)
2028 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2029 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2030 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2031 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2036 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
2038 _EGLContext
*ctx
= _eglGetCurrentContext();
2042 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2043 assert(disp
->Extensions
.KHR_wait_sync
);
2045 /* return an error if the client API doesn't support GL_OES_EGL_sync */
2046 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
2047 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
2049 /* the API doesn't allow any flags yet */
2051 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2053 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
2055 RETURN_EGL_EVAL(disp
, ret
);
2058 static EGLint EGLAPIENTRY
2059 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2061 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2062 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2063 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2064 return _eglWaitSyncCommon(disp
, s
, flags
);
2068 EGLBoolean EGLAPIENTRY
2069 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2071 /* The KHR version returns EGLint, while the core version returns
2072 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2075 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2076 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2077 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2078 return _eglWaitSyncCommon(disp
, s
, flags
);
2082 static EGLBoolean EGLAPIENTRY
2083 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2085 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2086 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2090 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2092 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2093 assert(disp
->Extensions
.KHR_reusable_sync
);
2094 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2096 RETURN_EGL_EVAL(disp
, ret
);
2101 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2106 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2107 assert(disp
->Extensions
.KHR_reusable_sync
||
2108 disp
->Extensions
.KHR_fence_sync
||
2109 disp
->Extensions
.ANDROID_native_fence_sync
);
2110 ret
= drv
->API
.GetSyncAttrib(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
);
2121 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2125 static EGLBoolean EGLAPIENTRY
2126 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2128 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2129 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2133 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2136 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2139 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2141 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2143 * If any error occurs, <*value> is not modified.
2145 if (result
== EGL_FALSE
)
2152 static EGLint EGLAPIENTRY
2153 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2155 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2156 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2160 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2162 /* the spec doesn't seem to specify what happens if the fence
2163 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2166 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2167 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2169 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2170 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2171 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2173 RETURN_EGL_EVAL(disp
, ret
);
2176 static EGLBoolean EGLAPIENTRY
2177 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2178 EGLint numRects
, const EGLint
*rects
)
2180 _EGLContext
*ctx
= _eglGetCurrentContext();
2181 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2182 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2186 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2188 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2190 if (!disp
->Extensions
.NOK_swap_region
)
2191 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2193 /* surface must be bound to current context in EGL 1.4 */
2194 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2195 surf
!= ctx
->DrawSurface
)
2196 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2198 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2200 RETURN_EGL_EVAL(disp
, ret
);
2204 static EGLImage EGLAPIENTRY
2205 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2207 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2212 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2214 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2215 if (!disp
->Extensions
.MESA_drm_image
)
2216 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2218 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2219 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2221 RETURN_EGL_EVAL(disp
, ret
);
2224 static EGLBoolean EGLAPIENTRY
2225 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2226 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2228 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2229 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2233 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2235 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2236 assert(disp
->Extensions
.MESA_drm_image
);
2239 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2241 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2243 RETURN_EGL_EVAL(disp
, ret
);
2249 static EGLBoolean EGLAPIENTRY
2250 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2252 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2256 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2258 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2259 assert(disp
->Extensions
.WL_bind_wayland_display
);
2262 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2264 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2266 RETURN_EGL_EVAL(disp
, ret
);
2269 static EGLBoolean EGLAPIENTRY
2270 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2272 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2276 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2278 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2279 assert(disp
->Extensions
.WL_bind_wayland_display
);
2282 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2284 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2286 RETURN_EGL_EVAL(disp
, ret
);
2289 static EGLBoolean EGLAPIENTRY
2290 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2291 EGLint attribute
, EGLint
*value
)
2293 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2297 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2299 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2300 assert(disp
->Extensions
.WL_bind_wayland_display
);
2303 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2305 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2307 RETURN_EGL_EVAL(disp
, ret
);
2311 static struct wl_buffer
* EGLAPIENTRY
2312 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2314 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2317 struct wl_buffer
*ret
;
2319 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2321 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2322 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2323 RETURN_EGL_EVAL(disp
, NULL
);
2325 img
= _eglLookupImage(image
, disp
);
2328 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2330 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2332 RETURN_EGL_EVAL(disp
, ret
);
2335 static EGLBoolean EGLAPIENTRY
2336 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2337 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2339 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2340 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2344 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2346 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2348 if (!disp
->Extensions
.NV_post_sub_buffer
)
2349 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2351 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2353 RETURN_EGL_EVAL(disp
, ret
);
2356 static EGLBoolean EGLAPIENTRY
2357 eglGetSyncValuesCHROMIUM(EGLDisplay dpy
, EGLSurface surface
,
2358 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2361 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2362 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2366 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2368 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2369 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2370 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2372 if (!ust
|| !msc
|| !sbc
)
2373 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2375 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2377 RETURN_EGL_EVAL(disp
, ret
);
2380 static EGLBoolean EGLAPIENTRY
2381 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2382 EGLint
*fourcc
, EGLint
*nplanes
,
2383 EGLuint64KHR
*modifiers
)
2385 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2386 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2390 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2392 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2393 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2396 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2398 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2401 RETURN_EGL_EVAL(disp
, ret
);
2404 static EGLBoolean EGLAPIENTRY
2405 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2406 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2408 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2409 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2413 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2415 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2416 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2419 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2421 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2423 RETURN_EGL_EVAL(disp
, ret
);
2426 static EGLint EGLAPIENTRY
2427 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2430 _EGLDisplay
*disp
= NULL
;
2431 _EGLResourceType type
;
2433 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2435 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2436 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2438 if (!_eglIsCurrentThreadDummy()) {
2443 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2446 disp
= _eglLockDisplay(dpy
);
2448 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2450 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2451 if (dpy
!= (EGLDisplay
) object
)
2452 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2454 disp
->Label
= label
;
2455 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2458 switch (objectType
) {
2459 case EGL_OBJECT_CONTEXT_KHR
:
2460 type
= _EGL_RESOURCE_CONTEXT
;
2462 case EGL_OBJECT_SURFACE_KHR
:
2463 type
= _EGL_RESOURCE_SURFACE
;
2465 case EGL_OBJECT_IMAGE_KHR
:
2466 type
= _EGL_RESOURCE_IMAGE
;
2468 case EGL_OBJECT_SYNC_KHR
:
2469 type
= _EGL_RESOURCE_SYNC
;
2471 case EGL_OBJECT_STREAM_KHR
:
2473 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2476 if (_eglCheckResource(object
, type
, disp
)) {
2477 _EGLResource
*res
= (_EGLResource
*) object
;
2480 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2483 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2486 static EGLint EGLAPIENTRY
2487 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2488 const EGLAttrib
*attrib_list
)
2490 unsigned int newEnabled
;
2492 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2494 mtx_lock(_eglGlobal
.Mutex
);
2496 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2497 if (attrib_list
!= NULL
) {
2500 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2501 switch (attrib_list
[i
]) {
2502 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2503 case EGL_DEBUG_MSG_ERROR_KHR
:
2504 case EGL_DEBUG_MSG_WARN_KHR
:
2505 case EGL_DEBUG_MSG_INFO_KHR
:
2506 if (attrib_list
[i
+ 1])
2507 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2509 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2512 // On error, set the last error code, call the current
2513 // debug callback, and return the error code.
2514 mtx_unlock(_eglGlobal
.Mutex
);
2515 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2516 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2517 return EGL_BAD_ATTRIBUTE
;
2522 if (callback
!= NULL
) {
2523 _eglGlobal
.debugCallback
= callback
;
2524 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2526 _eglGlobal
.debugCallback
= NULL
;
2527 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2530 mtx_unlock(_eglGlobal
.Mutex
);
2534 static EGLBoolean EGLAPIENTRY
2535 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2537 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2539 mtx_lock(_eglGlobal
.Mutex
);
2541 switch (attribute
) {
2542 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2543 case EGL_DEBUG_MSG_ERROR_KHR
:
2544 case EGL_DEBUG_MSG_WARN_KHR
:
2545 case EGL_DEBUG_MSG_INFO_KHR
:
2546 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2551 case EGL_DEBUG_CALLBACK_KHR
:
2552 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2555 mtx_unlock(_eglGlobal
.Mutex
);
2556 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2557 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2561 mtx_unlock(_eglGlobal
.Mutex
);
2566 _eglFunctionCompare(const void *key
, const void *elem
)
2568 const char *procname
= key
;
2569 const struct _egl_entrypoint
*entrypoint
= elem
;
2570 return strcmp(procname
, entrypoint
->name
);
2573 static EGLBoolean EGLAPIENTRY
2574 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2575 EGLint
*formats
, EGLint
*num_formats
)
2577 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2581 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2583 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2585 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2588 RETURN_EGL_EVAL(disp
, ret
);
2591 static EGLBoolean EGLAPIENTRY
2592 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2593 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2594 EGLint
*num_modifiers
)
2596 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2600 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2602 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2604 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2605 modifiers
, external_only
,
2608 RETURN_EGL_EVAL(disp
, ret
);
2611 static void EGLAPIENTRY
2612 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2613 EGLGetBlobFuncANDROID get
)
2615 /* This function does not return anything so we cannot
2616 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2618 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2619 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2621 _eglUnlockDisplay(disp
);
2625 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2628 _eglUnlockDisplay(disp
);
2633 _eglError(EGL_BAD_PARAMETER
,
2634 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2635 _eglUnlockDisplay(disp
);
2639 if (disp
->BlobCacheSet
) {
2640 _eglError(EGL_BAD_PARAMETER
,
2641 "eglSetBlobCacheFuncsANDROID: functions already set");
2642 _eglUnlockDisplay(disp
);
2646 disp
->BlobCacheSet
= set
;
2647 disp
->BlobCacheGet
= get
;
2649 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2651 _eglUnlockDisplay(disp
);
2654 static EGLBoolean EGLAPIENTRY
2655 eglQueryDeviceAttribEXT(EGLDeviceEXT device
,
2659 _EGLDevice
*dev
= _eglLookupDevice(device
);
2662 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2664 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, EGL_FALSE
);
2666 ret
= _eglQueryDeviceAttribEXT(dev
, attribute
, value
);
2667 RETURN_EGL_EVAL(NULL
, ret
);
2670 static const char * EGLAPIENTRY
2671 eglQueryDeviceStringEXT(EGLDeviceEXT device
,
2674 _EGLDevice
*dev
= _eglLookupDevice(device
);
2676 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2678 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, NULL
);
2680 RETURN_EGL_EVAL(NULL
, _eglQueryDeviceStringEXT(dev
, name
));
2683 static EGLBoolean EGLAPIENTRY
2684 eglQueryDevicesEXT(EGLint max_devices
,
2685 EGLDeviceEXT
*devices
,
2686 EGLint
*num_devices
)
2690 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2691 ret
= _eglQueryDevicesEXT(max_devices
, (_EGLDevice
**) devices
,
2693 RETURN_EGL_EVAL(NULL
, ret
);
2696 static EGLBoolean EGLAPIENTRY
2697 eglQueryDisplayAttribEXT(EGLDisplay dpy
,
2701 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2704 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2705 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2707 switch (attribute
) {
2708 case EGL_DEVICE_EXT
:
2709 *value
= (EGLAttrib
) disp
->Device
;
2712 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
2714 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
2717 static char * EGLAPIENTRY
2718 eglGetDisplayDriverConfig(EGLDisplay dpy
)
2720 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2724 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2725 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2727 assert(disp
->Extensions
.MESA_query_driver
);
2729 ret
= drv
->API
.QueryDriverConfig(disp
);
2730 RETURN_EGL_EVAL(disp
, ret
);
2733 static const char * EGLAPIENTRY
2734 eglGetDisplayDriverName(EGLDisplay dpy
)
2736 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2740 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2741 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2743 assert(disp
->Extensions
.MESA_query_driver
);
2745 ret
= drv
->API
.QueryDriverName(disp
);
2746 RETURN_EGL_EVAL(disp
, ret
);
2749 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2750 eglGetProcAddress(const char *procname
)
2752 static const struct _egl_entrypoint egl_functions
[] = {
2753 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2754 #include "eglentrypoint.h"
2755 #undef EGL_ENTRYPOINT
2757 _EGLProc ret
= NULL
;
2760 RETURN_EGL_SUCCESS(NULL
, NULL
);
2762 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2764 if (strncmp(procname
, "egl", 3) == 0) {
2765 const struct _egl_entrypoint
*entrypoint
=
2767 egl_functions
, ARRAY_SIZE(egl_functions
),
2768 sizeof(egl_functions
[0]),
2769 _eglFunctionCompare
);
2771 ret
= entrypoint
->function
;
2775 ret
= _eglGetDriverProc(procname
);
2777 RETURN_EGL_SUCCESS(NULL
, ret
);
2781 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2782 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2786 *disp
= _eglLockDisplay(dpy
);
2787 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2789 _eglUnlockDisplay(*disp
);
2790 return MESA_GLINTEROP_INVALID_DISPLAY
;
2793 *drv
= (*disp
)->Driver
;
2795 *ctx
= _eglLookupContext(context
, *disp
);
2797 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2798 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2799 _eglUnlockDisplay(*disp
);
2800 return MESA_GLINTEROP_INVALID_CONTEXT
;
2803 return MESA_GLINTEROP_SUCCESS
;
2807 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2808 struct mesa_glinterop_device_info
*out
)
2815 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2816 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2819 if (drv
->API
.GLInteropQueryDeviceInfo
)
2820 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2822 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2824 _eglUnlockDisplay(disp
);
2829 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2830 struct mesa_glinterop_export_in
*in
,
2831 struct mesa_glinterop_export_out
*out
)
2838 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2839 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2842 if (drv
->API
.GLInteropExportObject
)
2843 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2845 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2847 _eglUnlockDisplay(disp
);