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
);
903 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
905 RETURN_EGL_EVAL(disp
, ret
);
909 /* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says
910 * that if native_surface was already used to create a window or pixmap, we
911 * can't create a new one. This is what this function checks for.
914 _eglNativeSurfaceAlreadyUsed(_EGLDisplay
*disp
, void *native_surface
)
918 list
= disp
->ResourceLists
[_EGL_RESOURCE_SURFACE
];
920 _EGLSurface
*surf
= (_EGLSurface
*) list
;
924 if (surf
->Type
== EGL_PBUFFER_BIT
)
927 if (surf
->NativeSurface
== native_surface
)
936 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
937 void *native_window
, const EGLint
*attrib_list
)
939 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
945 if (native_window
== NULL
)
946 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
948 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
949 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
950 /* From the EGL_MESA_platform_surfaceless spec (v1):
952 * eglCreatePlatformWindowSurface fails when called with a <display>
953 * that belongs to the surfaceless platform. It returns
954 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
955 * justification for this unconditional failure is that the
956 * surfaceless platform has no native windows, and therefore the
957 * <native_window> parameter is always invalid.
959 * This check must occur before checking the EGLConfig, which emits
962 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
965 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
967 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
968 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
970 if (_eglNativeSurfaceAlreadyUsed(disp
, native_window
))
971 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
973 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
975 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
977 RETURN_EGL_EVAL(disp
, ret
);
981 EGLSurface EGLAPIENTRY
982 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
983 EGLNativeWindowType window
, const EGLint
*attrib_list
)
985 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
987 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
988 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
989 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
994 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
996 #ifdef HAVE_X11_PLATFORM
997 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
998 /* The `native_window` parameter for the X11 platform differs between
999 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1000 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
1001 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
1002 * `Window*`. Convert `Window*` to `Window` because that's what
1003 * dri2_x11_create_window_surface() expects.
1005 return (void *)(* (Window
*) native_window
);
1008 return native_window
;
1011 static EGLSurface EGLAPIENTRY
1012 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1013 void *native_window
,
1014 const EGLint
*attrib_list
)
1016 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1018 native_window
= _fixupNativeWindow(disp
, native_window
);
1020 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1021 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1026 EGLSurface EGLAPIENTRY
1027 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
1028 void *native_window
,
1029 const EGLAttrib
*attrib_list
)
1031 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1033 EGLint
*int_attribs
;
1035 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1037 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1038 if (attrib_list
&& !int_attribs
)
1039 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1041 native_window
= _fixupNativeWindow(disp
, native_window
);
1042 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1049 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
1051 #ifdef HAVE_X11_PLATFORM
1052 /* The `native_pixmap` parameter for the X11 platform differs between
1053 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1054 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1055 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1056 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1057 * dri2_x11_create_pixmap_surface() expects.
1059 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
1060 return (void *)(* (Pixmap
*) native_pixmap
);
1062 return native_pixmap
;
1066 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1067 void *native_pixmap
, const EGLint
*attrib_list
)
1069 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1074 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
1075 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
1076 /* From the EGL_MESA_platform_surfaceless spec (v1):
1078 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1079 * also fails when called with a <display> that belongs to the
1080 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1081 * EGL_BAD_NATIVE_PIXMAP.
1083 * This check must occur before checking the EGLConfig, which emits
1086 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1089 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1091 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1092 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1094 if (native_pixmap
== NULL
)
1095 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1097 if (_eglNativeSurfaceAlreadyUsed(disp
, native_pixmap
))
1098 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1100 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1102 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1104 RETURN_EGL_EVAL(disp
, ret
);
1108 EGLSurface EGLAPIENTRY
1109 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1110 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1112 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1114 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1115 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1116 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1120 static EGLSurface EGLAPIENTRY
1121 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1122 void *native_pixmap
,
1123 const EGLint
*attrib_list
)
1125 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1127 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1128 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1129 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1134 EGLSurface EGLAPIENTRY
1135 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1136 void *native_pixmap
,
1137 const EGLAttrib
*attrib_list
)
1139 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1141 EGLint
*int_attribs
;
1143 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1145 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1146 if (attrib_list
&& !int_attribs
)
1147 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1149 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1150 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1157 EGLSurface EGLAPIENTRY
1158 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1159 const EGLint
*attrib_list
)
1161 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1162 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1167 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1168 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1170 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1171 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1173 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1174 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1176 RETURN_EGL_EVAL(disp
, ret
);
1180 EGLBoolean EGLAPIENTRY
1181 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1183 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1184 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1188 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1189 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1190 _eglUnlinkSurface(surf
);
1191 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1193 RETURN_EGL_EVAL(disp
, ret
);
1196 EGLBoolean EGLAPIENTRY
1197 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1198 EGLint attribute
, EGLint
*value
)
1200 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1201 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1205 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1206 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1207 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1209 RETURN_EGL_EVAL(disp
, ret
);
1212 EGLBoolean EGLAPIENTRY
1213 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1214 EGLint attribute
, EGLint value
)
1216 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1217 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1221 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1222 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1223 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1225 RETURN_EGL_EVAL(disp
, ret
);
1229 EGLBoolean EGLAPIENTRY
1230 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1232 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1233 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1237 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1238 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1239 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1241 RETURN_EGL_EVAL(disp
, ret
);
1245 EGLBoolean EGLAPIENTRY
1246 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1248 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1249 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1253 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1254 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1255 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1257 RETURN_EGL_EVAL(disp
, ret
);
1261 EGLBoolean EGLAPIENTRY
1262 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1264 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1265 _EGLContext
*ctx
= _eglGetCurrentContext();
1266 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1270 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1271 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1273 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1274 ctx
->Resource
.Display
!= disp
)
1275 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1277 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1278 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1280 if (surf
->Type
!= EGL_WINDOW_BIT
)
1281 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1283 interval
= CLAMP(interval
,
1284 surf
->Config
->MinSwapInterval
,
1285 surf
->Config
->MaxSwapInterval
);
1287 if (surf
->SwapInterval
!= interval
)
1288 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1293 surf
->SwapInterval
= interval
;
1295 RETURN_EGL_EVAL(disp
, ret
);
1299 EGLBoolean EGLAPIENTRY
1300 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1302 _EGLContext
*ctx
= _eglGetCurrentContext();
1303 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1304 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1308 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1309 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1311 /* surface must be bound to current context in EGL 1.4 */
1312 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1313 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1314 surf
!= ctx
->DrawSurface
)
1315 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1318 if (surf
->Type
!= EGL_WINDOW_BIT
)
1319 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1321 /* From the EGL 1.5 spec:
1323 * If eglSwapBuffers is called and the native window associated with
1324 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1328 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1330 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1332 /* EGL_KHR_partial_update
1333 * Frame boundary successfully reached,
1334 * reset damage region and reset BufferAgeRead
1337 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1338 surf
->BufferAgeRead
= EGL_FALSE
;
1341 RETURN_EGL_EVAL(disp
, ret
);
1346 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1347 EGLint
*rects
, EGLint n_rects
)
1349 _EGLContext
*ctx
= _eglGetCurrentContext();
1353 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1355 /* surface must be bound to current context in EGL 1.4 */
1356 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1357 surf
!= ctx
->DrawSurface
)
1358 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1360 if (surf
->Type
!= EGL_WINDOW_BIT
)
1361 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1363 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1364 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1366 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1368 /* EGL_KHR_partial_update
1369 * Frame boundary successfully reached,
1370 * reset damage region and reset BufferAgeRead
1373 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1374 surf
->BufferAgeRead
= EGL_FALSE
;
1377 RETURN_EGL_EVAL(disp
, ret
);
1380 static EGLBoolean EGLAPIENTRY
1381 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1382 EGLint
*rects
, EGLint n_rects
)
1384 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1385 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1386 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1387 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1390 static EGLBoolean EGLAPIENTRY
1391 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1392 EGLint
*rects
, EGLint n_rects
)
1394 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1395 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1396 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1397 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1401 * Clamp the rectangles so that they lie within the surface.
1405 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1406 EGLint
*rects
, EGLint n_rects
)
1409 EGLint surf_height
= surf
->Height
;
1410 EGLint surf_width
= surf
->Width
;
1412 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1413 EGLint x1
, y1
, x2
, y2
;
1416 x2
= rects
[i
+ 2] + x1
;
1417 y2
= rects
[i
+ 3] + y1
;
1419 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1420 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1421 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1422 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1426 static EGLBoolean EGLAPIENTRY
1427 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1428 EGLint
*rects
, EGLint n_rects
)
1430 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1431 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1432 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1433 _EGLContext
*ctx
= _eglGetCurrentContext();
1436 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1438 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1439 surf
->Type
!= EGL_WINDOW_BIT
||
1440 ctx
->DrawSurface
!= surf
||
1441 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1442 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1444 /* If the damage region is already set or
1445 * buffer age is not queried between
1446 * frame boundaries, throw bad access error
1449 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1450 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1452 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1453 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1456 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1458 RETURN_EGL_EVAL(disp
, ret
);
1461 EGLBoolean EGLAPIENTRY
1462 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1464 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1465 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1468 void *native_pixmap_ptr
;
1470 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1471 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1472 native_pixmap_ptr
= (void*) target
;
1474 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1475 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1477 RETURN_EGL_EVAL(disp
, ret
);
1482 _eglWaitClientCommon(void)
1484 _EGLContext
*ctx
= _eglGetCurrentContext();
1490 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1492 disp
= ctx
->Resource
.Display
;
1493 mtx_lock(&disp
->Mutex
);
1495 /* let bad current context imply bad current surface */
1496 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1497 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1498 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1500 /* a valid current context implies an initialized current display */
1501 assert(disp
->Initialized
);
1503 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1505 RETURN_EGL_EVAL(disp
, ret
);
1508 EGLBoolean EGLAPIENTRY
1511 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1512 return _eglWaitClientCommon();
1515 EGLBoolean EGLAPIENTRY
1518 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1519 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1520 return _eglWaitClientCommon();
1524 EGLBoolean EGLAPIENTRY
1525 eglWaitNative(EGLint engine
)
1527 _EGLContext
*ctx
= _eglGetCurrentContext();
1533 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1535 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1537 disp
= ctx
->Resource
.Display
;
1538 mtx_lock(&disp
->Mutex
);
1540 /* let bad current context imply bad current surface */
1541 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1542 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1543 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1545 /* a valid current context implies an initialized current display */
1546 assert(disp
->Initialized
);
1548 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1550 RETURN_EGL_EVAL(disp
, ret
);
1554 EGLDisplay EGLAPIENTRY
1555 eglGetCurrentDisplay(void)
1557 _EGLContext
*ctx
= _eglGetCurrentContext();
1560 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1562 RETURN_EGL_SUCCESS(NULL
, ret
);
1566 EGLContext EGLAPIENTRY
1567 eglGetCurrentContext(void)
1569 _EGLContext
*ctx
= _eglGetCurrentContext();
1572 ret
= _eglGetContextHandle(ctx
);
1574 RETURN_EGL_SUCCESS(NULL
, ret
);
1578 EGLSurface EGLAPIENTRY
1579 eglGetCurrentSurface(EGLint readdraw
)
1581 _EGLContext
*ctx
= _eglGetCurrentContext();
1582 EGLint err
= EGL_SUCCESS
;
1586 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1589 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1593 surf
= ctx
->DrawSurface
;
1596 surf
= ctx
->ReadSurface
;
1600 err
= EGL_BAD_PARAMETER
;
1604 ret
= _eglGetSurfaceHandle(surf
);
1606 RETURN_EGL_ERROR(NULL
, err
, ret
);
1613 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1614 EGLint e
= t
->LastError
;
1615 if (!_eglIsCurrentThreadDummy())
1616 t
->LastError
= EGL_SUCCESS
;
1626 * Specify the client API to use for subsequent calls including:
1627 * eglCreateContext()
1628 * eglGetCurrentContext()
1629 * eglGetCurrentDisplay()
1630 * eglGetCurrentSurface()
1631 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1634 * See section 3.7 "Rendering Context" in the EGL specification for details.
1636 EGLBoolean EGLAPIENTRY
1637 eglBindAPI(EGLenum api
)
1641 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1643 t
= _eglGetCurrentThread();
1644 if (_eglIsCurrentThreadDummy())
1645 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1647 if (!_eglIsApiValid(api
))
1648 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1650 t
->CurrentAPI
= api
;
1652 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1657 * Return the last value set with eglBindAPI().
1662 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1665 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1666 ret
= t
->CurrentAPI
;
1668 RETURN_EGL_SUCCESS(NULL
, ret
);
1672 EGLSurface EGLAPIENTRY
1673 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1674 EGLClientBuffer buffer
, EGLConfig config
,
1675 const EGLint
*attrib_list
)
1677 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1678 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1683 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1685 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1687 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1689 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1691 RETURN_EGL_EVAL(disp
, ret
);
1695 EGLBoolean EGLAPIENTRY
1696 eglReleaseThread(void)
1698 /* unbind current contexts */
1699 if (!_eglIsCurrentThreadDummy()) {
1700 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1701 _EGLContext
*ctx
= t
->CurrentContext
;
1703 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1706 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1709 mtx_lock(&disp
->Mutex
);
1711 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1712 mtx_unlock(&disp
->Mutex
);
1716 _eglDestroyCurrentThread();
1718 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1723 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1724 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1726 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1731 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1732 if (!disp
->Extensions
.KHR_image_base
)
1733 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1734 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1735 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1736 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1737 * <ctx> must be EGL_NO_CONTEXT..."
1739 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1740 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1742 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1744 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1746 RETURN_EGL_EVAL(disp
, ret
);
1749 static EGLImage EGLAPIENTRY
1750 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1751 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1753 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1754 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1755 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1759 EGLImage EGLAPIENTRY
1760 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1761 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1763 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1765 EGLint
*int_attribs
;
1767 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1769 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1770 if (attr_list
&& !int_attribs
)
1771 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1773 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1780 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1785 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1786 if (!disp
->Extensions
.KHR_image_base
)
1787 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1789 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1791 _eglUnlinkImage(img
);
1792 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1794 RETURN_EGL_EVAL(disp
, ret
);
1797 EGLBoolean EGLAPIENTRY
1798 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1800 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1801 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1802 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1803 return _eglDestroyImageCommon(disp
, img
);
1806 static EGLBoolean EGLAPIENTRY
1807 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1809 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1810 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1811 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1812 return _eglDestroyImageCommon(disp
, img
);
1817 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1818 EGLBoolean orig_is_EGLAttrib
,
1819 EGLenum invalid_type_error
)
1821 _EGLContext
*ctx
= _eglGetCurrentContext();
1826 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1828 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1829 /* There exist two EGLAttrib variants of eglCreateSync*:
1830 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1831 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1832 * support as a proxy for EGL 1.5 support, even though that's not
1833 * entirely correct (though _eglComputeVersion does the same).
1835 * The EGL spec provides no guidance on how to handle unsupported
1836 * functions. EGL_BAD_MATCH seems reasonable.
1838 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1841 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1842 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1843 * error is generated.
1846 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1847 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1849 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1850 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1851 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1852 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1855 case EGL_SYNC_FENCE_KHR
:
1856 if (!disp
->Extensions
.KHR_fence_sync
)
1857 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1859 case EGL_SYNC_REUSABLE_KHR
:
1860 if (!disp
->Extensions
.KHR_reusable_sync
)
1861 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1863 case EGL_SYNC_CL_EVENT_KHR
:
1864 if (!disp
->Extensions
.KHR_cl_event2
)
1865 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1867 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1868 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1869 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1872 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1875 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1876 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1878 RETURN_EGL_EVAL(disp
, ret
);
1882 static EGLSync EGLAPIENTRY
1883 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1885 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1886 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1889 EGLAttrib
*attrib_list
;
1892 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1893 attrib_list
= (EGLAttrib
*) int_list
;
1895 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1896 if (err
!= EGL_SUCCESS
)
1897 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1900 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1903 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1906 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1911 static EGLSync EGLAPIENTRY
1912 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1914 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1915 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1916 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1922 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1924 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1925 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1926 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1932 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1937 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1938 assert(disp
->Extensions
.KHR_reusable_sync
||
1939 disp
->Extensions
.KHR_fence_sync
||
1940 disp
->Extensions
.ANDROID_native_fence_sync
);
1943 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1945 RETURN_EGL_EVAL(disp
, ret
);
1948 EGLBoolean EGLAPIENTRY
1949 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1951 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1952 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1953 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1954 return _eglDestroySync(disp
, s
);
1957 static EGLBoolean EGLAPIENTRY
1958 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1960 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1961 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1962 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1963 return _eglDestroySync(disp
, s
);
1968 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1969 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1974 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1975 assert(disp
->Extensions
.KHR_reusable_sync
||
1976 disp
->Extensions
.KHR_fence_sync
||
1977 disp
->Extensions
.ANDROID_native_fence_sync
);
1979 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1980 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1982 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1983 * unlocked here to allow other threads also to be able to
1984 * go into waiting state.
1987 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1988 _eglUnlockDisplay(dpy
);
1990 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1993 * 'disp' is already unlocked for reusable sync type,
1994 * so passing 'NULL' to bypass unlocking display.
1996 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1997 RETURN_EGL_EVAL(NULL
, ret
);
1999 RETURN_EGL_EVAL(disp
, ret
);
2003 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
2004 EGLint flags
, EGLTime timeout
)
2006 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2007 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2008 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2009 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2012 static EGLint EGLAPIENTRY
2013 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
2014 EGLint flags
, EGLTime timeout
)
2016 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2017 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2018 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2019 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2024 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
2026 _EGLContext
*ctx
= _eglGetCurrentContext();
2030 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2031 assert(disp
->Extensions
.KHR_wait_sync
);
2033 /* return an error if the client API doesn't support GL_OES_EGL_sync */
2034 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
2035 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
2037 /* the API doesn't allow any flags yet */
2039 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2041 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
2043 RETURN_EGL_EVAL(disp
, ret
);
2046 static EGLint EGLAPIENTRY
2047 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2049 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2050 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2051 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2052 return _eglWaitSyncCommon(disp
, s
, flags
);
2056 EGLBoolean EGLAPIENTRY
2057 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2059 /* The KHR version returns EGLint, while the core version returns
2060 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2063 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2064 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2065 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2066 return _eglWaitSyncCommon(disp
, s
, flags
);
2070 static EGLBoolean EGLAPIENTRY
2071 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2073 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2074 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2078 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2080 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2081 assert(disp
->Extensions
.KHR_reusable_sync
);
2082 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2084 RETURN_EGL_EVAL(disp
, ret
);
2089 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2094 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2095 assert(disp
->Extensions
.KHR_reusable_sync
||
2096 disp
->Extensions
.KHR_fence_sync
||
2097 disp
->Extensions
.ANDROID_native_fence_sync
);
2098 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2100 RETURN_EGL_EVAL(disp
, ret
);
2103 EGLBoolean EGLAPIENTRY
2104 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2106 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2107 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2108 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2109 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2113 static EGLBoolean EGLAPIENTRY
2114 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2116 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2117 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2121 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2124 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2127 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2129 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2131 * If any error occurs, <*value> is not modified.
2133 if (result
== EGL_FALSE
)
2140 static EGLint EGLAPIENTRY
2141 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2143 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2144 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2148 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2150 /* the spec doesn't seem to specify what happens if the fence
2151 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2154 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2155 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2157 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2158 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2159 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2161 RETURN_EGL_EVAL(disp
, ret
);
2164 static EGLBoolean EGLAPIENTRY
2165 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2166 EGLint numRects
, const EGLint
*rects
)
2168 _EGLContext
*ctx
= _eglGetCurrentContext();
2169 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2170 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2174 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2176 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2178 if (!disp
->Extensions
.NOK_swap_region
)
2179 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2181 /* surface must be bound to current context in EGL 1.4 */
2182 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2183 surf
!= ctx
->DrawSurface
)
2184 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2186 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2188 RETURN_EGL_EVAL(disp
, ret
);
2192 static EGLImage EGLAPIENTRY
2193 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2195 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2200 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2202 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2203 if (!disp
->Extensions
.MESA_drm_image
)
2204 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2206 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2207 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2209 RETURN_EGL_EVAL(disp
, ret
);
2212 static EGLBoolean EGLAPIENTRY
2213 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2214 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2216 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2217 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2221 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2223 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2224 assert(disp
->Extensions
.MESA_drm_image
);
2227 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2229 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2231 RETURN_EGL_EVAL(disp
, ret
);
2237 static EGLBoolean EGLAPIENTRY
2238 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2240 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2244 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2246 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2247 assert(disp
->Extensions
.WL_bind_wayland_display
);
2250 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2252 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2254 RETURN_EGL_EVAL(disp
, ret
);
2257 static EGLBoolean EGLAPIENTRY
2258 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2260 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2264 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2266 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2267 assert(disp
->Extensions
.WL_bind_wayland_display
);
2270 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2272 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2274 RETURN_EGL_EVAL(disp
, ret
);
2277 static EGLBoolean EGLAPIENTRY
2278 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2279 EGLint attribute
, EGLint
*value
)
2281 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2285 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2287 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2288 assert(disp
->Extensions
.WL_bind_wayland_display
);
2291 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2293 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2295 RETURN_EGL_EVAL(disp
, ret
);
2299 static struct wl_buffer
* EGLAPIENTRY
2300 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2302 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2305 struct wl_buffer
*ret
;
2307 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2309 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2310 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2311 RETURN_EGL_EVAL(disp
, NULL
);
2313 img
= _eglLookupImage(image
, disp
);
2316 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2318 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2320 RETURN_EGL_EVAL(disp
, ret
);
2323 static EGLBoolean EGLAPIENTRY
2324 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2325 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2327 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2328 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2332 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2334 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2336 if (!disp
->Extensions
.NV_post_sub_buffer
)
2337 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2339 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2341 RETURN_EGL_EVAL(disp
, ret
);
2344 static EGLBoolean EGLAPIENTRY
2345 eglGetSyncValuesCHROMIUM(EGLDisplay dpy
, EGLSurface surface
,
2346 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2349 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2350 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2354 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2356 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2357 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2358 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2360 if (!ust
|| !msc
|| !sbc
)
2361 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2363 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2365 RETURN_EGL_EVAL(disp
, ret
);
2368 static EGLBoolean EGLAPIENTRY
2369 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2370 EGLint
*fourcc
, EGLint
*nplanes
,
2371 EGLuint64KHR
*modifiers
)
2373 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2374 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2378 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2380 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2381 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2384 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2386 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2389 RETURN_EGL_EVAL(disp
, ret
);
2392 static EGLBoolean EGLAPIENTRY
2393 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2394 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2396 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2397 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2401 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2403 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2404 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2407 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2409 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2411 RETURN_EGL_EVAL(disp
, ret
);
2414 static EGLint EGLAPIENTRY
2415 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2418 _EGLDisplay
*disp
= NULL
;
2419 _EGLResourceType type
;
2421 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2423 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2424 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2426 if (!_eglIsCurrentThreadDummy()) {
2431 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2434 disp
= _eglLockDisplay(dpy
);
2436 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2438 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2439 if (dpy
!= (EGLDisplay
) object
)
2440 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2442 disp
->Label
= label
;
2443 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2446 switch (objectType
) {
2447 case EGL_OBJECT_CONTEXT_KHR
:
2448 type
= _EGL_RESOURCE_CONTEXT
;
2450 case EGL_OBJECT_SURFACE_KHR
:
2451 type
= _EGL_RESOURCE_SURFACE
;
2453 case EGL_OBJECT_IMAGE_KHR
:
2454 type
= _EGL_RESOURCE_IMAGE
;
2456 case EGL_OBJECT_SYNC_KHR
:
2457 type
= _EGL_RESOURCE_SYNC
;
2459 case EGL_OBJECT_STREAM_KHR
:
2461 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2464 if (_eglCheckResource(object
, type
, disp
)) {
2465 _EGLResource
*res
= (_EGLResource
*) object
;
2468 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2471 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2474 static EGLint EGLAPIENTRY
2475 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2476 const EGLAttrib
*attrib_list
)
2478 unsigned int newEnabled
;
2480 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2482 mtx_lock(_eglGlobal
.Mutex
);
2484 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2485 if (attrib_list
!= NULL
) {
2488 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2489 switch (attrib_list
[i
]) {
2490 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2491 case EGL_DEBUG_MSG_ERROR_KHR
:
2492 case EGL_DEBUG_MSG_WARN_KHR
:
2493 case EGL_DEBUG_MSG_INFO_KHR
:
2494 if (attrib_list
[i
+ 1])
2495 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2497 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2500 // On error, set the last error code, call the current
2501 // debug callback, and return the error code.
2502 mtx_unlock(_eglGlobal
.Mutex
);
2503 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2504 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2505 return EGL_BAD_ATTRIBUTE
;
2510 if (callback
!= NULL
) {
2511 _eglGlobal
.debugCallback
= callback
;
2512 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2514 _eglGlobal
.debugCallback
= NULL
;
2515 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2518 mtx_unlock(_eglGlobal
.Mutex
);
2522 static EGLBoolean EGLAPIENTRY
2523 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2525 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2527 mtx_lock(_eglGlobal
.Mutex
);
2529 switch (attribute
) {
2530 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2531 case EGL_DEBUG_MSG_ERROR_KHR
:
2532 case EGL_DEBUG_MSG_WARN_KHR
:
2533 case EGL_DEBUG_MSG_INFO_KHR
:
2534 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2539 case EGL_DEBUG_CALLBACK_KHR
:
2540 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2543 mtx_unlock(_eglGlobal
.Mutex
);
2544 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2545 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2549 mtx_unlock(_eglGlobal
.Mutex
);
2554 _eglFunctionCompare(const void *key
, const void *elem
)
2556 const char *procname
= key
;
2557 const struct _egl_entrypoint
*entrypoint
= elem
;
2558 return strcmp(procname
, entrypoint
->name
);
2561 static EGLBoolean EGLAPIENTRY
2562 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2563 EGLint
*formats
, EGLint
*num_formats
)
2565 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2569 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2571 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2573 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2576 RETURN_EGL_EVAL(disp
, ret
);
2579 static EGLBoolean EGLAPIENTRY
2580 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2581 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2582 EGLint
*num_modifiers
)
2584 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2588 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2590 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2592 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2593 modifiers
, external_only
,
2596 RETURN_EGL_EVAL(disp
, ret
);
2599 static void EGLAPIENTRY
2600 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2601 EGLGetBlobFuncANDROID get
)
2603 /* This function does not return anything so we cannot
2604 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2606 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2607 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2609 _eglUnlockDisplay(disp
);
2613 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2616 _eglUnlockDisplay(disp
);
2621 _eglError(EGL_BAD_PARAMETER
,
2622 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2623 _eglUnlockDisplay(disp
);
2627 if (disp
->BlobCacheSet
) {
2628 _eglError(EGL_BAD_PARAMETER
,
2629 "eglSetBlobCacheFuncsANDROID: functions already set");
2630 _eglUnlockDisplay(disp
);
2634 disp
->BlobCacheSet
= set
;
2635 disp
->BlobCacheGet
= get
;
2637 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2639 _eglUnlockDisplay(disp
);
2642 static EGLBoolean EGLAPIENTRY
2643 eglQueryDeviceAttribEXT(EGLDeviceEXT device
,
2647 _EGLDevice
*dev
= _eglLookupDevice(device
);
2650 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2652 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, EGL_FALSE
);
2654 ret
= _eglQueryDeviceAttribEXT(dev
, attribute
, value
);
2655 RETURN_EGL_EVAL(NULL
, ret
);
2658 static const char * EGLAPIENTRY
2659 eglQueryDeviceStringEXT(EGLDeviceEXT device
,
2662 _EGLDevice
*dev
= _eglLookupDevice(device
);
2664 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2666 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, NULL
);
2668 RETURN_EGL_EVAL(NULL
, _eglQueryDeviceStringEXT(dev
, name
));
2671 static EGLBoolean EGLAPIENTRY
2672 eglQueryDevicesEXT(EGLint max_devices
,
2673 EGLDeviceEXT
*devices
,
2674 EGLint
*num_devices
)
2678 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2679 ret
= _eglQueryDevicesEXT(max_devices
, (_EGLDevice
**) devices
,
2681 RETURN_EGL_EVAL(NULL
, ret
);
2684 static EGLBoolean EGLAPIENTRY
2685 eglQueryDisplayAttribEXT(EGLDisplay dpy
,
2689 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2692 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2693 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2695 switch (attribute
) {
2696 case EGL_DEVICE_EXT
:
2697 *value
= (EGLAttrib
) disp
->Device
;
2700 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
2702 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
2705 static char * EGLAPIENTRY
2706 eglGetDisplayDriverConfig(EGLDisplay dpy
)
2708 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2712 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2713 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2715 assert(disp
->Extensions
.MESA_query_driver
);
2717 ret
= drv
->API
.QueryDriverConfig(disp
);
2718 RETURN_EGL_EVAL(disp
, ret
);
2721 static const char * EGLAPIENTRY
2722 eglGetDisplayDriverName(EGLDisplay dpy
)
2724 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2728 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2729 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2731 assert(disp
->Extensions
.MESA_query_driver
);
2733 ret
= drv
->API
.QueryDriverName(disp
);
2734 RETURN_EGL_EVAL(disp
, ret
);
2737 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2738 eglGetProcAddress(const char *procname
)
2740 static const struct _egl_entrypoint egl_functions
[] = {
2741 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2742 #include "eglentrypoint.h"
2743 #undef EGL_ENTRYPOINT
2745 _EGLProc ret
= NULL
;
2748 RETURN_EGL_SUCCESS(NULL
, NULL
);
2750 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2752 if (strncmp(procname
, "egl", 3) == 0) {
2753 const struct _egl_entrypoint
*entrypoint
=
2755 egl_functions
, ARRAY_SIZE(egl_functions
),
2756 sizeof(egl_functions
[0]),
2757 _eglFunctionCompare
);
2759 ret
= entrypoint
->function
;
2763 ret
= _eglGetDriverProc(procname
);
2765 RETURN_EGL_SUCCESS(NULL
, ret
);
2769 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2770 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2774 *disp
= _eglLockDisplay(dpy
);
2775 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2777 _eglUnlockDisplay(*disp
);
2778 return MESA_GLINTEROP_INVALID_DISPLAY
;
2781 *drv
= (*disp
)->Driver
;
2783 *ctx
= _eglLookupContext(context
, *disp
);
2785 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2786 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2787 _eglUnlockDisplay(*disp
);
2788 return MESA_GLINTEROP_INVALID_CONTEXT
;
2791 return MESA_GLINTEROP_SUCCESS
;
2795 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2796 struct mesa_glinterop_device_info
*out
)
2803 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2804 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2807 if (drv
->API
.GLInteropQueryDeviceInfo
)
2808 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2810 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2812 _eglUnlockDisplay(disp
);
2817 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2818 struct mesa_glinterop_export_in
*in
,
2819 struct mesa_glinterop_export_out
*out
)
2826 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2827 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2830 if (drv
->API
.GLInteropExportObject
)
2831 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2833 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2835 _eglUnlockDisplay(disp
);