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 ret
= _eglGetConfigs(drv
, disp
, configs
, config_size
, num_config
);
730 RETURN_EGL_EVAL(disp
, ret
);
734 EGLBoolean EGLAPIENTRY
735 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
736 EGLint config_size
, EGLint
*num_config
)
738 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
742 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
744 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
747 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
749 ret
= _eglChooseConfig(drv
, disp
, attrib_list
, configs
,
750 config_size
, num_config
);
752 RETURN_EGL_EVAL(disp
, ret
);
756 EGLBoolean EGLAPIENTRY
757 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
758 EGLint attribute
, EGLint
*value
)
760 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
761 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
765 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
767 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
769 ret
= _eglGetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
771 RETURN_EGL_EVAL(disp
, ret
);
775 EGLContext EGLAPIENTRY
776 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
777 const EGLint
*attrib_list
)
779 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
780 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
781 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
783 _EGLContext
*context
;
786 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
788 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
790 if (config
!= EGL_NO_CONFIG_KHR
)
791 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
792 else if (!disp
->Extensions
.KHR_no_config_context
)
793 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
795 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
796 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
798 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
799 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
801 RETURN_EGL_EVAL(disp
, ret
);
805 EGLBoolean EGLAPIENTRY
806 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
808 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
809 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
813 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
815 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
816 _eglUnlinkContext(context
);
817 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
819 RETURN_EGL_EVAL(disp
, ret
);
823 EGLBoolean EGLAPIENTRY
824 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
827 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
828 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
829 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
830 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
834 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
837 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
840 /* display is allowed to be uninitialized under certain condition */
841 if (!disp
->Initialized
) {
842 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
843 ctx
!= EGL_NO_CONTEXT
)
844 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
847 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
849 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
850 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
851 if (!draw_surf
|| !read_surf
) {
852 /* From the EGL 1.4 (20130211) spec:
854 * To release the current context without assigning a new one, set ctx
855 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
857 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
858 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
860 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
861 (!read_surf
&& read
!= EGL_NO_SURFACE
))
862 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
863 if (draw_surf
|| read_surf
)
864 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
867 /* If a native window underlying either draw or read is no longer valid,
868 * an EGL_BAD_NATIVE_WINDOW error is generated.
870 if (draw_surf
&& draw_surf
->Lost
)
871 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
872 if (read_surf
&& read_surf
->Lost
)
873 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
875 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
877 RETURN_EGL_EVAL(disp
, ret
);
881 EGLBoolean EGLAPIENTRY
882 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
883 EGLint attribute
, EGLint
*value
)
885 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
886 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
890 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
892 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
894 ret
= _eglQueryContext(drv
, disp
, context
, attribute
, value
);
896 RETURN_EGL_EVAL(disp
, ret
);
900 /* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says
901 * that if native_surface was already used to create a window or pixmap, we
902 * can't create a new one. This is what this function checks for.
905 _eglNativeSurfaceAlreadyUsed(_EGLDisplay
*disp
, void *native_surface
)
909 list
= disp
->ResourceLists
[_EGL_RESOURCE_SURFACE
];
911 _EGLSurface
*surf
= (_EGLSurface
*) list
;
915 if (surf
->Type
== EGL_PBUFFER_BIT
)
918 if (surf
->NativeSurface
== native_surface
)
927 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
928 void *native_window
, const EGLint
*attrib_list
)
930 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
936 if (native_window
== NULL
)
937 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
939 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
940 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
941 /* From the EGL_MESA_platform_surfaceless spec (v1):
943 * eglCreatePlatformWindowSurface fails when called with a <display>
944 * that belongs to the surfaceless platform. It returns
945 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
946 * justification for this unconditional failure is that the
947 * surfaceless platform has no native windows, and therefore the
948 * <native_window> parameter is always invalid.
950 * This check must occur before checking the EGLConfig, which emits
953 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
956 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
958 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
959 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
961 if (_eglNativeSurfaceAlreadyUsed(disp
, native_window
))
962 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
964 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
966 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
968 RETURN_EGL_EVAL(disp
, ret
);
972 EGLSurface EGLAPIENTRY
973 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
974 EGLNativeWindowType window
, const EGLint
*attrib_list
)
976 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
978 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
979 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
980 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
985 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
987 #ifdef HAVE_X11_PLATFORM
988 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
989 /* The `native_window` parameter for the X11 platform differs between
990 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
991 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
992 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
993 * `Window*`. Convert `Window*` to `Window` because that's what
994 * dri2_x11_create_window_surface() expects.
996 return (void *)(* (Window
*) native_window
);
999 return native_window
;
1002 static EGLSurface EGLAPIENTRY
1003 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1004 void *native_window
,
1005 const EGLint
*attrib_list
)
1007 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1009 native_window
= _fixupNativeWindow(disp
, native_window
);
1011 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1012 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1017 EGLSurface EGLAPIENTRY
1018 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
1019 void *native_window
,
1020 const EGLAttrib
*attrib_list
)
1022 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1024 EGLint
*int_attribs
;
1026 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1028 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1029 if (attrib_list
&& !int_attribs
)
1030 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1032 native_window
= _fixupNativeWindow(disp
, native_window
);
1033 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1040 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
1042 #ifdef HAVE_X11_PLATFORM
1043 /* The `native_pixmap` parameter for the X11 platform differs between
1044 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1045 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1046 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1047 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1048 * dri2_x11_create_pixmap_surface() expects.
1050 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
1051 return (void *)(* (Pixmap
*) native_pixmap
);
1053 return native_pixmap
;
1057 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1058 void *native_pixmap
, const EGLint
*attrib_list
)
1060 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1065 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
1066 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
1067 /* From the EGL_MESA_platform_surfaceless spec (v1):
1069 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1070 * also fails when called with a <display> that belongs to the
1071 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1072 * EGL_BAD_NATIVE_PIXMAP.
1074 * This check must occur before checking the EGLConfig, which emits
1077 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1080 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1082 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1083 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1085 if (native_pixmap
== NULL
)
1086 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1088 if (_eglNativeSurfaceAlreadyUsed(disp
, native_pixmap
))
1089 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1091 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1093 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1095 RETURN_EGL_EVAL(disp
, ret
);
1099 EGLSurface EGLAPIENTRY
1100 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1101 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1103 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1105 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1106 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1107 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1111 static EGLSurface EGLAPIENTRY
1112 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1113 void *native_pixmap
,
1114 const EGLint
*attrib_list
)
1116 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1118 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1119 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1120 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1125 EGLSurface EGLAPIENTRY
1126 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1127 void *native_pixmap
,
1128 const EGLAttrib
*attrib_list
)
1130 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1132 EGLint
*int_attribs
;
1134 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1136 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1137 if (attrib_list
&& !int_attribs
)
1138 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1140 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1141 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1148 EGLSurface EGLAPIENTRY
1149 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1150 const EGLint
*attrib_list
)
1152 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1153 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1158 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1159 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1161 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1162 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1164 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1165 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1167 RETURN_EGL_EVAL(disp
, ret
);
1171 EGLBoolean EGLAPIENTRY
1172 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1174 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1175 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1179 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1180 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1181 _eglUnlinkSurface(surf
);
1182 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1184 RETURN_EGL_EVAL(disp
, ret
);
1187 EGLBoolean EGLAPIENTRY
1188 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1189 EGLint attribute
, EGLint
*value
)
1191 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1192 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1196 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1197 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1199 if (drv
->API
.QuerySurface
)
1200 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1202 ret
= _eglQuerySurface(drv
, disp
, surf
, attribute
, value
);
1204 RETURN_EGL_EVAL(disp
, ret
);
1207 EGLBoolean EGLAPIENTRY
1208 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1209 EGLint attribute
, EGLint value
)
1211 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1212 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1216 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1217 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1219 ret
= _eglSurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1221 RETURN_EGL_EVAL(disp
, ret
);
1225 EGLBoolean EGLAPIENTRY
1226 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1228 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1229 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1233 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1234 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1235 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1237 RETURN_EGL_EVAL(disp
, ret
);
1241 EGLBoolean EGLAPIENTRY
1242 eglReleaseTexImage(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
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1253 RETURN_EGL_EVAL(disp
, ret
);
1257 EGLBoolean EGLAPIENTRY
1258 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1260 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1261 _EGLContext
*ctx
= _eglGetCurrentContext();
1262 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1266 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1267 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1269 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1270 ctx
->Resource
.Display
!= disp
)
1271 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1273 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1274 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1276 if (surf
->Type
!= EGL_WINDOW_BIT
)
1277 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1279 interval
= CLAMP(interval
,
1280 surf
->Config
->MinSwapInterval
,
1281 surf
->Config
->MaxSwapInterval
);
1283 if (surf
->SwapInterval
!= interval
) {
1284 if (drv
->API
.SwapInterval
)
1285 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1287 ret
= _eglSwapInterval(drv
, disp
, surf
, interval
);
1294 surf
->SwapInterval
= interval
;
1296 RETURN_EGL_EVAL(disp
, ret
);
1300 EGLBoolean EGLAPIENTRY
1301 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1303 _EGLContext
*ctx
= _eglGetCurrentContext();
1304 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1305 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1309 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1310 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1312 /* surface must be bound to current context in EGL 1.4 */
1313 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1314 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1315 surf
!= ctx
->DrawSurface
)
1316 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1319 if (surf
->Type
!= EGL_WINDOW_BIT
)
1320 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1322 /* From the EGL 1.5 spec:
1324 * If eglSwapBuffers is called and the native window associated with
1325 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1329 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1331 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1333 /* EGL_KHR_partial_update
1334 * Frame boundary successfully reached,
1335 * reset damage region and reset BufferAgeRead
1338 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1339 surf
->BufferAgeRead
= EGL_FALSE
;
1342 RETURN_EGL_EVAL(disp
, ret
);
1347 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1348 EGLint
*rects
, EGLint n_rects
)
1350 _EGLContext
*ctx
= _eglGetCurrentContext();
1354 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1356 /* surface must be bound to current context in EGL 1.4 */
1357 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1358 surf
!= ctx
->DrawSurface
)
1359 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1361 if (surf
->Type
!= EGL_WINDOW_BIT
)
1362 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1364 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1365 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1367 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1369 /* EGL_KHR_partial_update
1370 * Frame boundary successfully reached,
1371 * reset damage region and reset BufferAgeRead
1374 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1375 surf
->BufferAgeRead
= EGL_FALSE
;
1378 RETURN_EGL_EVAL(disp
, ret
);
1381 static EGLBoolean EGLAPIENTRY
1382 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1383 EGLint
*rects
, EGLint n_rects
)
1385 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1386 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1387 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1388 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1391 static EGLBoolean EGLAPIENTRY
1392 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1393 EGLint
*rects
, EGLint n_rects
)
1395 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1396 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1397 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1398 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1402 * Clamp the rectangles so that they lie within the surface.
1406 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1407 EGLint
*rects
, EGLint n_rects
)
1410 EGLint surf_height
= surf
->Height
;
1411 EGLint surf_width
= surf
->Width
;
1413 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1414 EGLint x1
, y1
, x2
, y2
;
1417 x2
= rects
[i
+ 2] + x1
;
1418 y2
= rects
[i
+ 3] + y1
;
1420 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1421 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1422 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1423 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1427 static EGLBoolean EGLAPIENTRY
1428 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1429 EGLint
*rects
, EGLint n_rects
)
1431 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1432 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1433 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1434 _EGLContext
*ctx
= _eglGetCurrentContext();
1437 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1439 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1440 surf
->Type
!= EGL_WINDOW_BIT
||
1441 ctx
->DrawSurface
!= surf
||
1442 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1443 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1445 /* If the damage region is already set or
1446 * buffer age is not queried between
1447 * frame boundaries, throw bad access error
1450 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1451 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1453 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1454 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1457 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1459 RETURN_EGL_EVAL(disp
, ret
);
1462 EGLBoolean EGLAPIENTRY
1463 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1465 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1466 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1469 void *native_pixmap_ptr
;
1471 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1472 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1473 native_pixmap_ptr
= (void*) target
;
1475 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1476 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1478 RETURN_EGL_EVAL(disp
, ret
);
1483 _eglWaitClientCommon(void)
1485 _EGLContext
*ctx
= _eglGetCurrentContext();
1491 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1493 disp
= ctx
->Resource
.Display
;
1494 mtx_lock(&disp
->Mutex
);
1496 /* let bad current context imply bad current surface */
1497 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1498 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1499 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1501 /* a valid current context implies an initialized current display */
1502 assert(disp
->Initialized
);
1504 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1506 RETURN_EGL_EVAL(disp
, ret
);
1509 EGLBoolean EGLAPIENTRY
1512 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1513 return _eglWaitClientCommon();
1516 EGLBoolean EGLAPIENTRY
1519 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1520 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1521 return _eglWaitClientCommon();
1525 EGLBoolean EGLAPIENTRY
1526 eglWaitNative(EGLint engine
)
1528 _EGLContext
*ctx
= _eglGetCurrentContext();
1534 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1536 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1538 disp
= ctx
->Resource
.Display
;
1539 mtx_lock(&disp
->Mutex
);
1541 /* let bad current context imply bad current surface */
1542 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1543 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1544 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1546 /* a valid current context implies an initialized current display */
1547 assert(disp
->Initialized
);
1549 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1551 RETURN_EGL_EVAL(disp
, ret
);
1555 EGLDisplay EGLAPIENTRY
1556 eglGetCurrentDisplay(void)
1558 _EGLContext
*ctx
= _eglGetCurrentContext();
1561 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1563 RETURN_EGL_SUCCESS(NULL
, ret
);
1567 EGLContext EGLAPIENTRY
1568 eglGetCurrentContext(void)
1570 _EGLContext
*ctx
= _eglGetCurrentContext();
1573 ret
= _eglGetContextHandle(ctx
);
1575 RETURN_EGL_SUCCESS(NULL
, ret
);
1579 EGLSurface EGLAPIENTRY
1580 eglGetCurrentSurface(EGLint readdraw
)
1582 _EGLContext
*ctx
= _eglGetCurrentContext();
1583 EGLint err
= EGL_SUCCESS
;
1587 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1590 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1594 surf
= ctx
->DrawSurface
;
1597 surf
= ctx
->ReadSurface
;
1601 err
= EGL_BAD_PARAMETER
;
1605 ret
= _eglGetSurfaceHandle(surf
);
1607 RETURN_EGL_ERROR(NULL
, err
, ret
);
1614 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1615 EGLint e
= t
->LastError
;
1616 if (!_eglIsCurrentThreadDummy())
1617 t
->LastError
= EGL_SUCCESS
;
1627 * Specify the client API to use for subsequent calls including:
1628 * eglCreateContext()
1629 * eglGetCurrentContext()
1630 * eglGetCurrentDisplay()
1631 * eglGetCurrentSurface()
1632 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1635 * See section 3.7 "Rendering Context" in the EGL specification for details.
1637 EGLBoolean EGLAPIENTRY
1638 eglBindAPI(EGLenum api
)
1642 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1644 t
= _eglGetCurrentThread();
1645 if (_eglIsCurrentThreadDummy())
1646 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1648 if (!_eglIsApiValid(api
))
1649 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1651 t
->CurrentAPI
= api
;
1653 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1658 * Return the last value set with eglBindAPI().
1663 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1666 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1667 ret
= t
->CurrentAPI
;
1669 RETURN_EGL_SUCCESS(NULL
, ret
);
1673 EGLSurface EGLAPIENTRY
1674 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1675 EGLClientBuffer buffer
, EGLConfig config
,
1676 const EGLint
*attrib_list
)
1678 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1679 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1684 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1686 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1688 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1690 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1692 RETURN_EGL_EVAL(disp
, ret
);
1696 EGLBoolean EGLAPIENTRY
1697 eglReleaseThread(void)
1699 /* unbind current contexts */
1700 if (!_eglIsCurrentThreadDummy()) {
1701 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1702 _EGLContext
*ctx
= t
->CurrentContext
;
1704 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1707 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1710 mtx_lock(&disp
->Mutex
);
1712 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1713 mtx_unlock(&disp
->Mutex
);
1717 _eglDestroyCurrentThread();
1719 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1724 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1725 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1727 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1732 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1733 if (!disp
->Extensions
.KHR_image_base
)
1734 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1735 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1736 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1737 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1738 * <ctx> must be EGL_NO_CONTEXT..."
1740 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1741 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1743 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1745 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1747 RETURN_EGL_EVAL(disp
, ret
);
1750 static EGLImage EGLAPIENTRY
1751 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1752 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1754 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1755 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1756 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1760 EGLImage EGLAPIENTRY
1761 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1762 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1764 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1766 EGLint
*int_attribs
;
1768 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1770 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1771 if (attr_list
&& !int_attribs
)
1772 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1774 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1781 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1786 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1787 if (!disp
->Extensions
.KHR_image_base
)
1788 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1790 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1792 _eglUnlinkImage(img
);
1793 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1795 RETURN_EGL_EVAL(disp
, ret
);
1798 EGLBoolean EGLAPIENTRY
1799 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1801 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1802 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1803 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1804 return _eglDestroyImageCommon(disp
, img
);
1807 static EGLBoolean EGLAPIENTRY
1808 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1810 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1811 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1812 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1813 return _eglDestroyImageCommon(disp
, img
);
1818 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1819 EGLBoolean orig_is_EGLAttrib
,
1820 EGLenum invalid_type_error
)
1822 _EGLContext
*ctx
= _eglGetCurrentContext();
1827 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1829 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1830 /* There exist two EGLAttrib variants of eglCreateSync*:
1831 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1832 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1833 * support as a proxy for EGL 1.5 support, even though that's not
1834 * entirely correct (though _eglComputeVersion does the same).
1836 * The EGL spec provides no guidance on how to handle unsupported
1837 * functions. EGL_BAD_MATCH seems reasonable.
1839 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1842 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1843 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1844 * error is generated.
1847 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1848 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1850 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1851 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1852 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1853 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1856 case EGL_SYNC_FENCE_KHR
:
1857 if (!disp
->Extensions
.KHR_fence_sync
)
1858 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1860 case EGL_SYNC_REUSABLE_KHR
:
1861 if (!disp
->Extensions
.KHR_reusable_sync
)
1862 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1864 case EGL_SYNC_CL_EVENT_KHR
:
1865 if (!disp
->Extensions
.KHR_cl_event2
)
1866 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1868 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1869 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1870 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1873 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1876 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1877 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1879 RETURN_EGL_EVAL(disp
, ret
);
1883 static EGLSync EGLAPIENTRY
1884 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1886 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1887 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1890 EGLAttrib
*attrib_list
;
1893 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1894 attrib_list
= (EGLAttrib
*) int_list
;
1896 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1897 if (err
!= EGL_SUCCESS
)
1898 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1901 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1904 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1907 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1912 static EGLSync EGLAPIENTRY
1913 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1915 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1916 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1917 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1923 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1925 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1926 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1927 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1933 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1938 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1939 assert(disp
->Extensions
.KHR_reusable_sync
||
1940 disp
->Extensions
.KHR_fence_sync
||
1941 disp
->Extensions
.ANDROID_native_fence_sync
);
1944 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1946 RETURN_EGL_EVAL(disp
, ret
);
1949 EGLBoolean EGLAPIENTRY
1950 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1952 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1953 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1954 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1955 return _eglDestroySync(disp
, s
);
1958 static EGLBoolean EGLAPIENTRY
1959 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1961 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1962 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1963 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1964 return _eglDestroySync(disp
, s
);
1969 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1970 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1975 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1976 assert(disp
->Extensions
.KHR_reusable_sync
||
1977 disp
->Extensions
.KHR_fence_sync
||
1978 disp
->Extensions
.ANDROID_native_fence_sync
);
1980 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1981 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1983 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1984 * unlocked here to allow other threads also to be able to
1985 * go into waiting state.
1988 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1989 _eglUnlockDisplay(dpy
);
1991 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1994 * 'disp' is already unlocked for reusable sync type,
1995 * so passing 'NULL' to bypass unlocking display.
1997 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1998 RETURN_EGL_EVAL(NULL
, ret
);
2000 RETURN_EGL_EVAL(disp
, ret
);
2004 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
2005 EGLint flags
, EGLTime timeout
)
2007 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2008 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2009 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2010 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2013 static EGLint EGLAPIENTRY
2014 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
2015 EGLint flags
, EGLTime timeout
)
2017 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2018 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2019 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2020 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2025 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
2027 _EGLContext
*ctx
= _eglGetCurrentContext();
2031 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2032 assert(disp
->Extensions
.KHR_wait_sync
);
2034 /* return an error if the client API doesn't support GL_OES_EGL_sync */
2035 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
2036 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
2038 /* the API doesn't allow any flags yet */
2040 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2042 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
2044 RETURN_EGL_EVAL(disp
, ret
);
2047 static EGLint EGLAPIENTRY
2048 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2050 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2051 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2052 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2053 return _eglWaitSyncCommon(disp
, s
, flags
);
2057 EGLBoolean EGLAPIENTRY
2058 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2060 /* The KHR version returns EGLint, while the core version returns
2061 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2064 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2065 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2066 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2067 return _eglWaitSyncCommon(disp
, s
, flags
);
2071 static EGLBoolean EGLAPIENTRY
2072 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2074 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2075 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2079 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2081 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2082 assert(disp
->Extensions
.KHR_reusable_sync
);
2083 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2085 RETURN_EGL_EVAL(disp
, ret
);
2090 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2095 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2096 assert(disp
->Extensions
.KHR_reusable_sync
||
2097 disp
->Extensions
.KHR_fence_sync
||
2098 disp
->Extensions
.ANDROID_native_fence_sync
);
2100 ret
= _eglGetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2102 RETURN_EGL_EVAL(disp
, ret
);
2105 EGLBoolean EGLAPIENTRY
2106 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2108 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2109 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2110 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2111 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2115 static EGLBoolean EGLAPIENTRY
2116 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2118 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2119 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2123 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2126 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2129 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2131 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2133 * If any error occurs, <*value> is not modified.
2135 if (result
== EGL_FALSE
)
2142 static EGLint EGLAPIENTRY
2143 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2145 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2146 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2150 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2152 /* the spec doesn't seem to specify what happens if the fence
2153 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2156 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2157 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2159 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2160 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2161 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2163 RETURN_EGL_EVAL(disp
, ret
);
2166 static EGLBoolean EGLAPIENTRY
2167 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2168 EGLint numRects
, const EGLint
*rects
)
2170 _EGLContext
*ctx
= _eglGetCurrentContext();
2171 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2172 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2176 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2178 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2180 if (!disp
->Extensions
.NOK_swap_region
)
2181 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2183 /* surface must be bound to current context in EGL 1.4 */
2184 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2185 surf
!= ctx
->DrawSurface
)
2186 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2188 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2190 RETURN_EGL_EVAL(disp
, ret
);
2194 static EGLImage EGLAPIENTRY
2195 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2197 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2202 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2204 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2205 if (!disp
->Extensions
.MESA_drm_image
)
2206 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2208 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2209 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2211 RETURN_EGL_EVAL(disp
, ret
);
2214 static EGLBoolean EGLAPIENTRY
2215 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2216 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2218 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2219 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2223 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2225 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2226 assert(disp
->Extensions
.MESA_drm_image
);
2229 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2231 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2233 RETURN_EGL_EVAL(disp
, ret
);
2239 static EGLBoolean EGLAPIENTRY
2240 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2242 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2246 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2248 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2249 assert(disp
->Extensions
.WL_bind_wayland_display
);
2252 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2254 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2256 RETURN_EGL_EVAL(disp
, ret
);
2259 static EGLBoolean EGLAPIENTRY
2260 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2262 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2266 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2268 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2269 assert(disp
->Extensions
.WL_bind_wayland_display
);
2272 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2274 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2276 RETURN_EGL_EVAL(disp
, ret
);
2279 static EGLBoolean EGLAPIENTRY
2280 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2281 EGLint attribute
, EGLint
*value
)
2283 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2287 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2289 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2290 assert(disp
->Extensions
.WL_bind_wayland_display
);
2293 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2295 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2297 RETURN_EGL_EVAL(disp
, ret
);
2301 static struct wl_buffer
* EGLAPIENTRY
2302 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2304 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2307 struct wl_buffer
*ret
;
2309 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2311 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2312 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2313 RETURN_EGL_EVAL(disp
, NULL
);
2315 img
= _eglLookupImage(image
, disp
);
2318 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2320 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2322 RETURN_EGL_EVAL(disp
, ret
);
2325 static EGLBoolean EGLAPIENTRY
2326 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2327 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2329 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2330 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2334 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2336 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2338 if (!disp
->Extensions
.NV_post_sub_buffer
)
2339 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2341 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2343 RETURN_EGL_EVAL(disp
, ret
);
2346 static EGLBoolean EGLAPIENTRY
2347 eglGetSyncValuesCHROMIUM(EGLDisplay dpy
, EGLSurface surface
,
2348 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2351 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2352 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2356 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2358 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2359 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2360 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2362 if (!ust
|| !msc
|| !sbc
)
2363 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2365 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2367 RETURN_EGL_EVAL(disp
, ret
);
2370 static EGLBoolean EGLAPIENTRY
2371 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2372 EGLint
*fourcc
, EGLint
*nplanes
,
2373 EGLuint64KHR
*modifiers
)
2375 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2376 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2380 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2382 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2383 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2386 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2388 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2391 RETURN_EGL_EVAL(disp
, ret
);
2394 static EGLBoolean EGLAPIENTRY
2395 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2396 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2398 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2399 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2403 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2405 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2406 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2409 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2411 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2413 RETURN_EGL_EVAL(disp
, ret
);
2416 static EGLint EGLAPIENTRY
2417 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2420 _EGLDisplay
*disp
= NULL
;
2421 _EGLResourceType type
;
2423 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2425 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2426 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2428 if (!_eglIsCurrentThreadDummy()) {
2433 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2436 disp
= _eglLockDisplay(dpy
);
2438 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2440 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2441 if (dpy
!= (EGLDisplay
) object
)
2442 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2444 disp
->Label
= label
;
2445 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2448 switch (objectType
) {
2449 case EGL_OBJECT_CONTEXT_KHR
:
2450 type
= _EGL_RESOURCE_CONTEXT
;
2452 case EGL_OBJECT_SURFACE_KHR
:
2453 type
= _EGL_RESOURCE_SURFACE
;
2455 case EGL_OBJECT_IMAGE_KHR
:
2456 type
= _EGL_RESOURCE_IMAGE
;
2458 case EGL_OBJECT_SYNC_KHR
:
2459 type
= _EGL_RESOURCE_SYNC
;
2461 case EGL_OBJECT_STREAM_KHR
:
2463 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2466 if (_eglCheckResource(object
, type
, disp
)) {
2467 _EGLResource
*res
= (_EGLResource
*) object
;
2470 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2473 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2476 static EGLint EGLAPIENTRY
2477 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2478 const EGLAttrib
*attrib_list
)
2480 unsigned int newEnabled
;
2482 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2484 mtx_lock(_eglGlobal
.Mutex
);
2486 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2487 if (attrib_list
!= NULL
) {
2490 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2491 switch (attrib_list
[i
]) {
2492 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2493 case EGL_DEBUG_MSG_ERROR_KHR
:
2494 case EGL_DEBUG_MSG_WARN_KHR
:
2495 case EGL_DEBUG_MSG_INFO_KHR
:
2496 if (attrib_list
[i
+ 1])
2497 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2499 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2502 // On error, set the last error code, call the current
2503 // debug callback, and return the error code.
2504 mtx_unlock(_eglGlobal
.Mutex
);
2505 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2506 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2507 return EGL_BAD_ATTRIBUTE
;
2512 if (callback
!= NULL
) {
2513 _eglGlobal
.debugCallback
= callback
;
2514 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2516 _eglGlobal
.debugCallback
= NULL
;
2517 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2520 mtx_unlock(_eglGlobal
.Mutex
);
2524 static EGLBoolean EGLAPIENTRY
2525 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2527 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2529 mtx_lock(_eglGlobal
.Mutex
);
2531 switch (attribute
) {
2532 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2533 case EGL_DEBUG_MSG_ERROR_KHR
:
2534 case EGL_DEBUG_MSG_WARN_KHR
:
2535 case EGL_DEBUG_MSG_INFO_KHR
:
2536 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2541 case EGL_DEBUG_CALLBACK_KHR
:
2542 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2545 mtx_unlock(_eglGlobal
.Mutex
);
2546 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2547 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2551 mtx_unlock(_eglGlobal
.Mutex
);
2556 _eglFunctionCompare(const void *key
, const void *elem
)
2558 const char *procname
= key
;
2559 const struct _egl_entrypoint
*entrypoint
= elem
;
2560 return strcmp(procname
, entrypoint
->name
);
2563 static EGLBoolean EGLAPIENTRY
2564 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2565 EGLint
*formats
, EGLint
*num_formats
)
2567 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2571 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2573 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2575 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2578 RETURN_EGL_EVAL(disp
, ret
);
2581 static EGLBoolean EGLAPIENTRY
2582 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2583 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2584 EGLint
*num_modifiers
)
2586 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2590 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2592 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2594 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2595 modifiers
, external_only
,
2598 RETURN_EGL_EVAL(disp
, ret
);
2601 static void EGLAPIENTRY
2602 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2603 EGLGetBlobFuncANDROID get
)
2605 /* This function does not return anything so we cannot
2606 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2608 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2609 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2611 _eglUnlockDisplay(disp
);
2615 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2618 _eglUnlockDisplay(disp
);
2623 _eglError(EGL_BAD_PARAMETER
,
2624 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2625 _eglUnlockDisplay(disp
);
2629 if (disp
->BlobCacheSet
) {
2630 _eglError(EGL_BAD_PARAMETER
,
2631 "eglSetBlobCacheFuncsANDROID: functions already set");
2632 _eglUnlockDisplay(disp
);
2636 disp
->BlobCacheSet
= set
;
2637 disp
->BlobCacheGet
= get
;
2639 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2641 _eglUnlockDisplay(disp
);
2644 static EGLBoolean EGLAPIENTRY
2645 eglQueryDeviceAttribEXT(EGLDeviceEXT device
,
2649 _EGLDevice
*dev
= _eglLookupDevice(device
);
2652 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2654 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, EGL_FALSE
);
2656 ret
= _eglQueryDeviceAttribEXT(dev
, attribute
, value
);
2657 RETURN_EGL_EVAL(NULL
, ret
);
2660 static const char * EGLAPIENTRY
2661 eglQueryDeviceStringEXT(EGLDeviceEXT device
,
2664 _EGLDevice
*dev
= _eglLookupDevice(device
);
2666 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2668 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, NULL
);
2670 RETURN_EGL_EVAL(NULL
, _eglQueryDeviceStringEXT(dev
, name
));
2673 static EGLBoolean EGLAPIENTRY
2674 eglQueryDevicesEXT(EGLint max_devices
,
2675 EGLDeviceEXT
*devices
,
2676 EGLint
*num_devices
)
2680 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2681 ret
= _eglQueryDevicesEXT(max_devices
, (_EGLDevice
**) devices
,
2683 RETURN_EGL_EVAL(NULL
, ret
);
2686 static EGLBoolean EGLAPIENTRY
2687 eglQueryDisplayAttribEXT(EGLDisplay dpy
,
2691 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2694 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2695 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2697 switch (attribute
) {
2698 case EGL_DEVICE_EXT
:
2699 *value
= (EGLAttrib
) disp
->Device
;
2702 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
2704 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
2707 static char * EGLAPIENTRY
2708 eglGetDisplayDriverConfig(EGLDisplay dpy
)
2710 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2714 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2715 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2717 assert(disp
->Extensions
.MESA_query_driver
);
2719 ret
= drv
->API
.QueryDriverConfig(disp
);
2720 RETURN_EGL_EVAL(disp
, ret
);
2723 static const char * EGLAPIENTRY
2724 eglGetDisplayDriverName(EGLDisplay dpy
)
2726 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2730 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2731 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2733 assert(disp
->Extensions
.MESA_query_driver
);
2735 ret
= drv
->API
.QueryDriverName(disp
);
2736 RETURN_EGL_EVAL(disp
, ret
);
2739 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2740 eglGetProcAddress(const char *procname
)
2742 static const struct _egl_entrypoint egl_functions
[] = {
2743 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2744 #include "eglentrypoint.h"
2745 #undef EGL_ENTRYPOINT
2747 _EGLProc ret
= NULL
;
2750 RETURN_EGL_SUCCESS(NULL
, NULL
);
2752 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2754 if (strncmp(procname
, "egl", 3) == 0) {
2755 const struct _egl_entrypoint
*entrypoint
=
2757 egl_functions
, ARRAY_SIZE(egl_functions
),
2758 sizeof(egl_functions
[0]),
2759 _eglFunctionCompare
);
2761 ret
= entrypoint
->function
;
2765 ret
= _eglGetDriverProc(procname
);
2767 RETURN_EGL_SUCCESS(NULL
, ret
);
2771 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2772 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2776 *disp
= _eglLockDisplay(dpy
);
2777 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2779 _eglUnlockDisplay(*disp
);
2780 return MESA_GLINTEROP_INVALID_DISPLAY
;
2783 *drv
= (*disp
)->Driver
;
2785 *ctx
= _eglLookupContext(context
, *disp
);
2787 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2788 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2789 _eglUnlockDisplay(*disp
);
2790 return MESA_GLINTEROP_INVALID_CONTEXT
;
2793 return MESA_GLINTEROP_SUCCESS
;
2797 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2798 struct mesa_glinterop_device_info
*out
)
2805 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2806 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2809 if (drv
->API
.GLInteropQueryDeviceInfo
)
2810 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2812 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2814 _eglUnlockDisplay(disp
);
2819 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2820 struct mesa_glinterop_export_in
*in
,
2821 struct mesa_glinterop_export_out
*out
)
2828 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2829 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2832 if (drv
->API
.GLInteropExportObject
)
2833 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2835 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2837 _eglUnlockDisplay(disp
);