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 EGLint
*int_attribs
= NULL
;
345 /* Convert attributes from EGLAttrib[] to EGLint[] */
349 while (attr_list
[size
] != EGL_NONE
)
352 size
+= 1; /* add space for EGL_NONE */
354 int_attribs
= calloc(size
, sizeof(int_attribs
[0]));
358 for (i
= 0; i
< size
; i
++)
359 int_attribs
[i
] = attr_list
[i
];
366 * This is typically the first EGL function that an application calls.
367 * It associates a private _EGLDisplay object to the native display.
369 EGLDisplay EGLAPIENTRY
370 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
372 _EGLPlatformType plat
;
374 void *native_display_ptr
;
376 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
378 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
379 native_display_ptr
= (void*) nativeDisplay
;
381 plat
= _eglGetNativePlatform(native_display_ptr
);
382 disp
= _eglFindDisplay(plat
, native_display_ptr
);
383 return _eglGetDisplayHandle(disp
);
387 _eglGetPlatformDisplayCommon(EGLenum platform
, void *native_display
,
388 const EGLAttrib
*attrib_list
)
393 #ifdef HAVE_X11_PLATFORM
394 case EGL_PLATFORM_X11_EXT
:
395 disp
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
398 #ifdef HAVE_DRM_PLATFORM
399 case EGL_PLATFORM_GBM_MESA
:
400 disp
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
404 #ifdef HAVE_WAYLAND_PLATFORM
405 case EGL_PLATFORM_WAYLAND_EXT
:
406 disp
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
410 #ifdef HAVE_SURFACELESS_PLATFORM
411 case EGL_PLATFORM_SURFACELESS_MESA
:
412 disp
= _eglGetSurfacelessDisplay(native_display
, attrib_list
);
416 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
419 return _eglGetDisplayHandle(disp
);
422 static EGLDisplay EGLAPIENTRY
423 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
424 const EGLint
*int_attribs
)
426 EGLAttrib
*attrib_list
;
429 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
431 if (_eglConvertIntsToAttribs(int_attribs
, &attrib_list
) != EGL_SUCCESS
)
432 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
434 disp
= _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
439 EGLDisplay EGLAPIENTRY
440 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
441 const EGLAttrib
*attrib_list
)
443 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
444 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
448 * Copy the extension into the string and update the string pointer.
451 _eglAppendExtension(char **str
, const char *ext
)
454 size_t len
= strlen(ext
);
471 * Examine the individual extension enable/disable flags and recompute
472 * the driver's Extensions string.
475 _eglCreateExtensionsString(_EGLDisplay
*disp
)
477 #define _EGL_CHECK_EXTENSION(ext) \
479 if (disp->Extensions.ext) { \
480 _eglAppendExtension(&exts, "EGL_" #ext); \
481 assert(exts <= disp->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
485 char *exts
= disp
->ExtensionsString
;
487 /* Please keep these sorted alphabetically. */
488 _EGL_CHECK_EXTENSION(ANDROID_blob_cache
);
489 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
490 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
491 _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync
);
492 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
494 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
496 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
497 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
498 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
499 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers
);
500 _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata
);
501 _EGL_CHECK_EXTENSION(EXT_surface_SMPTE2086_metadata
);
502 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
504 _EGL_CHECK_EXTENSION(IMG_context_priority
);
506 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
507 _EGL_CHECK_EXTENSION(KHR_config_attribs
);
508 _EGL_CHECK_EXTENSION(KHR_context_flush_control
);
509 _EGL_CHECK_EXTENSION(KHR_create_context
);
510 _EGL_CHECK_EXTENSION(KHR_create_context_no_error
);
511 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
512 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
513 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
514 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
515 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
516 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
517 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
518 if (disp
->Extensions
.KHR_image_base
&& disp
->Extensions
.KHR_image_pixmap
)
519 disp
->Extensions
.KHR_image
= EGL_TRUE
;
520 _EGL_CHECK_EXTENSION(KHR_image
);
521 _EGL_CHECK_EXTENSION(KHR_image_base
);
522 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
523 _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer
);
524 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
525 _EGL_CHECK_EXTENSION(KHR_partial_update
);
526 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
527 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
528 if (disp
->Extensions
.EXT_swap_buffers_with_damage
)
529 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
530 _EGL_CHECK_EXTENSION(EXT_pixel_format_float
);
531 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
533 if (disp
->Extensions
.KHR_no_config_context
)
534 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
535 _EGL_CHECK_EXTENSION(MESA_drm_image
);
536 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
537 _EGL_CHECK_EXTENSION(MESA_query_driver
);
539 _EGL_CHECK_EXTENSION(NOK_swap_region
);
540 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
542 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
544 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
545 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
547 #undef _EGL_CHECK_EXTENSION
551 _eglCreateAPIsString(_EGLDisplay
*disp
)
553 #define addstr(str) \
555 const size_t old_len = strlen(disp->ClientAPIsString); \
556 const size_t add_len = sizeof(str); \
557 const size_t max_len = sizeof(disp->ClientAPIsString) - 1; \
558 if (old_len + add_len <= max_len) \
559 strcat(disp->ClientAPIsString, str " "); \
561 assert(!"disp->ClientAPIsString is not large enough"); \
564 if (disp
->ClientAPIs
& EGL_OPENGL_BIT
)
567 if (disp
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
568 disp
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
569 disp
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
573 if (disp
->ClientAPIs
& EGL_OPENVG_BIT
)
580 _eglComputeVersion(_EGLDisplay
*disp
)
584 if (disp
->Extensions
.KHR_fence_sync
&&
585 disp
->Extensions
.KHR_cl_event2
&&
586 disp
->Extensions
.KHR_wait_sync
&&
587 disp
->Extensions
.KHR_image_base
&&
588 disp
->Extensions
.KHR_gl_texture_2D_image
&&
589 disp
->Extensions
.KHR_gl_texture_3D_image
&&
590 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
591 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
592 disp
->Extensions
.KHR_create_context
&&
593 disp
->Extensions
.EXT_create_context_robustness
&&
594 disp
->Extensions
.KHR_get_all_proc_addresses
&&
595 disp
->Extensions
.KHR_gl_colorspace
&&
596 disp
->Extensions
.KHR_surfaceless_context
)
601 * This is typically the second EGL function that an application calls.
602 * Here we load/initialize the actual hardware driver.
604 EGLBoolean EGLAPIENTRY
605 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
607 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
609 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
612 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
614 if (!disp
->Initialized
) {
615 if (!_eglMatchDriver(disp
))
616 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
618 /* limit to APIs supported by core */
619 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
621 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
622 * classifies it as an EGL display extension, though conceptually it's an
623 * EGL client extension.
625 * From the EGL_KHR_get_all_proc_addresses spec:
627 * The EGL implementation must expose the name
628 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
629 * EGL_KHR_get_all_proc_addresses and supports
630 * EGL_EXT_client_extensions.
632 * Mesa unconditionally exposes both client extensions mentioned above,
633 * so the spec requires that each EGLDisplay unconditionally expose
634 * EGL_KHR_get_all_proc_addresses also.
636 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
638 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
639 * programs. It is driver agnostic and handled in the main EGL code.
641 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
643 _eglComputeVersion(disp
);
644 _eglCreateExtensionsString(disp
);
645 _eglCreateAPIsString(disp
);
646 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
647 "%d.%d", disp
->Version
/ 10, disp
->Version
% 10);
650 /* Update applications version of major and minor if not NULL */
651 if ((major
!= NULL
) && (minor
!= NULL
)) {
652 *major
= disp
->Version
/ 10;
653 *minor
= disp
->Version
% 10;
656 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
660 EGLBoolean EGLAPIENTRY
661 eglTerminate(EGLDisplay dpy
)
663 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
665 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
668 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
670 if (disp
->Initialized
) {
671 _EGLDriver
*drv
= disp
->Driver
;
673 drv
->API
.Terminate(drv
, disp
);
674 /* do not reset disp->Driver */
675 disp
->ClientAPIsString
[0] = 0;
676 disp
->Initialized
= EGL_FALSE
;
679 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
683 const char * EGLAPIENTRY
684 eglQueryString(EGLDisplay dpy
, EGLint name
)
689 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
690 const char *ret
= _eglGetClientExtensionString();
692 RETURN_EGL_SUCCESS(NULL
, ret
);
694 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
697 disp
= _eglLockDisplay(dpy
);
698 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
699 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
703 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
705 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
707 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
708 case EGL_CLIENT_APIS
:
709 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
711 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
716 EGLBoolean EGLAPIENTRY
717 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
718 EGLint config_size
, EGLint
*num_config
)
720 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
724 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
726 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
727 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
729 RETURN_EGL_EVAL(disp
, ret
);
733 EGLBoolean EGLAPIENTRY
734 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
735 EGLint config_size
, EGLint
*num_config
)
737 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
741 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
743 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
744 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
745 config_size
, num_config
);
747 RETURN_EGL_EVAL(disp
, ret
);
751 EGLBoolean EGLAPIENTRY
752 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
753 EGLint attribute
, EGLint
*value
)
755 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
756 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
760 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
762 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
763 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
765 RETURN_EGL_EVAL(disp
, ret
);
769 EGLContext EGLAPIENTRY
770 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
771 const EGLint
*attrib_list
)
773 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
774 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
775 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
777 _EGLContext
*context
;
780 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
782 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
784 if (config
!= EGL_NO_CONFIG_KHR
)
785 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
786 else if (!disp
->Extensions
.KHR_no_config_context
)
787 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
789 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
790 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
792 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
793 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
795 RETURN_EGL_EVAL(disp
, ret
);
799 EGLBoolean EGLAPIENTRY
800 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
802 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
803 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
807 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
809 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
810 _eglUnlinkContext(context
);
811 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
813 RETURN_EGL_EVAL(disp
, ret
);
817 EGLBoolean EGLAPIENTRY
818 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
821 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
822 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
823 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
824 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
828 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
831 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
834 /* display is allowed to be uninitialized under certain condition */
835 if (!disp
->Initialized
) {
836 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
837 ctx
!= EGL_NO_CONTEXT
)
838 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
841 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
843 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
844 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
845 if (!draw_surf
|| !read_surf
) {
846 /* From the EGL 1.4 (20130211) spec:
848 * To release the current context without assigning a new one, set ctx
849 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
851 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
852 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
854 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
855 (!read_surf
&& read
!= EGL_NO_SURFACE
))
856 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
857 if (draw_surf
|| read_surf
)
858 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
861 /* If a native window underlying either draw or read is no longer valid,
862 * an EGL_BAD_NATIVE_WINDOW error is generated.
864 if (draw_surf
&& draw_surf
->Lost
)
865 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
866 if (read_surf
&& read_surf
->Lost
)
867 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
869 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
871 RETURN_EGL_EVAL(disp
, ret
);
875 EGLBoolean EGLAPIENTRY
876 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
877 EGLint attribute
, EGLint
*value
)
879 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
880 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
884 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
886 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
887 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
889 RETURN_EGL_EVAL(disp
, ret
);
893 /* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says
894 * that if native_surface was already used to create a window or pixmap, we
895 * can't create a new one. This is what this function checks for.
898 _eglNativeSurfaceAlreadyUsed(_EGLDisplay
*disp
, void *native_surface
)
902 list
= disp
->ResourceLists
[_EGL_RESOURCE_SURFACE
];
904 _EGLSurface
*surf
= (_EGLSurface
*) list
;
908 if (surf
->Type
== EGL_PBUFFER_BIT
)
911 if (surf
->NativeSurface
== native_surface
)
920 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
921 void *native_window
, const EGLint
*attrib_list
)
923 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
929 if (native_window
== NULL
)
930 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
932 #ifdef HAVE_SURFACELESS_PLATFORM
933 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
934 /* From the EGL_MESA_platform_surfaceless spec (v1):
936 * eglCreatePlatformWindowSurface fails when called with a <display>
937 * that belongs to the surfaceless platform. It returns
938 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
939 * justification for this unconditional failure is that the
940 * surfaceless platform has no native windows, and therefore the
941 * <native_window> parameter is always invalid.
943 * This check must occur before checking the EGLConfig, which emits
946 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
950 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
952 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
953 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
955 if (_eglNativeSurfaceAlreadyUsed(disp
, native_window
))
956 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
958 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
960 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
962 RETURN_EGL_EVAL(disp
, ret
);
966 EGLSurface EGLAPIENTRY
967 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
968 EGLNativeWindowType window
, const EGLint
*attrib_list
)
970 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
972 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
973 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
974 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
979 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
981 #ifdef HAVE_X11_PLATFORM
982 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
983 /* The `native_window` parameter for the X11 platform differs between
984 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
985 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
986 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
987 * `Window*`. Convert `Window*` to `Window` because that's what
988 * dri2_x11_create_window_surface() expects.
990 return (void *)(* (Window
*) native_window
);
993 return native_window
;
996 static EGLSurface EGLAPIENTRY
997 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
999 const EGLint
*attrib_list
)
1001 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1003 native_window
= _fixupNativeWindow(disp
, native_window
);
1005 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1006 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1011 EGLSurface EGLAPIENTRY
1012 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
1013 void *native_window
,
1014 const EGLAttrib
*attrib_list
)
1016 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1018 EGLint
*int_attribs
;
1020 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1022 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1023 if (attrib_list
&& !int_attribs
)
1024 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1026 native_window
= _fixupNativeWindow(disp
, native_window
);
1027 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1034 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
1036 #ifdef HAVE_X11_PLATFORM
1037 /* The `native_pixmap` parameter for the X11 platform differs between
1038 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1039 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1040 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1041 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1042 * dri2_x11_create_pixmap_surface() expects.
1044 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
1045 return (void *)(* (Pixmap
*) native_pixmap
);
1047 return native_pixmap
;
1051 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1052 void *native_pixmap
, const EGLint
*attrib_list
)
1054 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1059 #if HAVE_SURFACELESS_PLATFORM
1060 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
1061 /* From the EGL_MESA_platform_surfaceless spec (v1):
1063 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1064 * also fails when called with a <display> that belongs to the
1065 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1066 * EGL_BAD_NATIVE_PIXMAP.
1068 * This check must occur before checking the EGLConfig, which emits
1071 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1075 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1077 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1078 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1080 if (native_pixmap
== NULL
)
1081 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1083 if (_eglNativeSurfaceAlreadyUsed(disp
, native_pixmap
))
1084 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1086 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1088 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1090 RETURN_EGL_EVAL(disp
, ret
);
1094 EGLSurface EGLAPIENTRY
1095 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1096 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1098 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1100 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1101 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1102 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1106 static EGLSurface EGLAPIENTRY
1107 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1108 void *native_pixmap
,
1109 const EGLint
*attrib_list
)
1111 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1113 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1114 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1115 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1120 EGLSurface EGLAPIENTRY
1121 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1122 void *native_pixmap
,
1123 const EGLAttrib
*attrib_list
)
1125 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1127 EGLint
*int_attribs
;
1129 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1131 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1132 if (attrib_list
&& !int_attribs
)
1133 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1135 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1136 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1143 EGLSurface EGLAPIENTRY
1144 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1145 const EGLint
*attrib_list
)
1147 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1148 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1153 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1154 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1156 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1157 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1159 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1160 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1162 RETURN_EGL_EVAL(disp
, ret
);
1166 EGLBoolean EGLAPIENTRY
1167 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1169 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1170 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1174 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1175 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1176 _eglUnlinkSurface(surf
);
1177 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1179 RETURN_EGL_EVAL(disp
, ret
);
1182 EGLBoolean EGLAPIENTRY
1183 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1184 EGLint attribute
, EGLint
*value
)
1186 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1187 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1191 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1192 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1193 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1195 RETURN_EGL_EVAL(disp
, ret
);
1198 EGLBoolean EGLAPIENTRY
1199 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1200 EGLint attribute
, EGLint value
)
1202 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1203 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1207 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1208 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1209 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1211 RETURN_EGL_EVAL(disp
, ret
);
1215 EGLBoolean EGLAPIENTRY
1216 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1218 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1219 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1223 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1224 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1225 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1227 RETURN_EGL_EVAL(disp
, ret
);
1231 EGLBoolean EGLAPIENTRY
1232 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1234 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1235 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1239 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1240 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1241 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1243 RETURN_EGL_EVAL(disp
, ret
);
1247 EGLBoolean EGLAPIENTRY
1248 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1250 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1251 _EGLContext
*ctx
= _eglGetCurrentContext();
1252 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1256 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1257 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1259 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1260 ctx
->Resource
.Display
!= disp
)
1261 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1263 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1264 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1266 if (surf
->Type
!= EGL_WINDOW_BIT
)
1267 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1269 interval
= CLAMP(interval
,
1270 surf
->Config
->MinSwapInterval
,
1271 surf
->Config
->MaxSwapInterval
);
1273 if (surf
->SwapInterval
!= interval
)
1274 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1279 surf
->SwapInterval
= interval
;
1281 RETURN_EGL_EVAL(disp
, ret
);
1285 EGLBoolean EGLAPIENTRY
1286 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1288 _EGLContext
*ctx
= _eglGetCurrentContext();
1289 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1290 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1294 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1295 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1297 /* surface must be bound to current context in EGL 1.4 */
1298 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1299 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1300 surf
!= ctx
->DrawSurface
)
1301 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1304 if (surf
->Type
!= EGL_WINDOW_BIT
)
1305 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1307 /* From the EGL 1.5 spec:
1309 * If eglSwapBuffers is called and the native window associated with
1310 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1314 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1316 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1318 /* EGL_KHR_partial_update
1319 * Frame boundary successfully reached,
1320 * reset damage region and reset BufferAgeRead
1323 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1324 surf
->BufferAgeRead
= EGL_FALSE
;
1327 RETURN_EGL_EVAL(disp
, ret
);
1332 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1333 EGLint
*rects
, EGLint n_rects
)
1335 _EGLContext
*ctx
= _eglGetCurrentContext();
1339 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1341 /* surface must be bound to current context in EGL 1.4 */
1342 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1343 surf
!= ctx
->DrawSurface
)
1344 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1346 if (surf
->Type
!= EGL_WINDOW_BIT
)
1347 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1349 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1350 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1352 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1354 /* EGL_KHR_partial_update
1355 * Frame boundary successfully reached,
1356 * reset damage region and reset BufferAgeRead
1359 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1360 surf
->BufferAgeRead
= EGL_FALSE
;
1363 RETURN_EGL_EVAL(disp
, ret
);
1366 static EGLBoolean EGLAPIENTRY
1367 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1368 EGLint
*rects
, EGLint n_rects
)
1370 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1371 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1372 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1373 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1376 static EGLBoolean EGLAPIENTRY
1377 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1378 EGLint
*rects
, EGLint n_rects
)
1380 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1381 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1382 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1383 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1387 * Clamp the rectangles so that they lie within the surface.
1391 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1392 EGLint
*rects
, EGLint n_rects
)
1395 EGLint surf_height
= surf
->Height
;
1396 EGLint surf_width
= surf
->Width
;
1398 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1399 EGLint x1
, y1
, x2
, y2
;
1402 x2
= rects
[i
+ 2] + x1
;
1403 y2
= rects
[i
+ 3] + y1
;
1405 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1406 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1407 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1408 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1412 static EGLBoolean EGLAPIENTRY
1413 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1414 EGLint
*rects
, EGLint n_rects
)
1416 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1417 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1418 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1419 _EGLContext
*ctx
= _eglGetCurrentContext();
1422 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1424 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1425 surf
->Type
!= EGL_WINDOW_BIT
||
1426 ctx
->DrawSurface
!= surf
||
1427 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1428 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1430 /* If the damage region is already set or
1431 * buffer age is not queried between
1432 * frame boundaries, throw bad access error
1435 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1436 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1438 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1439 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1442 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1444 RETURN_EGL_EVAL(disp
, ret
);
1447 EGLBoolean EGLAPIENTRY
1448 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1450 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1451 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1454 void *native_pixmap_ptr
;
1456 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1457 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1458 native_pixmap_ptr
= (void*) target
;
1460 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1461 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1463 RETURN_EGL_EVAL(disp
, ret
);
1468 _eglWaitClientCommon(void)
1470 _EGLContext
*ctx
= _eglGetCurrentContext();
1476 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1478 disp
= ctx
->Resource
.Display
;
1479 mtx_lock(&disp
->Mutex
);
1481 /* let bad current context imply bad current surface */
1482 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1483 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1484 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1486 /* a valid current context implies an initialized current display */
1487 assert(disp
->Initialized
);
1489 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1491 RETURN_EGL_EVAL(disp
, ret
);
1494 EGLBoolean EGLAPIENTRY
1497 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1498 return _eglWaitClientCommon();
1501 EGLBoolean EGLAPIENTRY
1504 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1505 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1506 return _eglWaitClientCommon();
1510 EGLBoolean EGLAPIENTRY
1511 eglWaitNative(EGLint engine
)
1513 _EGLContext
*ctx
= _eglGetCurrentContext();
1519 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1521 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1523 disp
= ctx
->Resource
.Display
;
1524 mtx_lock(&disp
->Mutex
);
1526 /* let bad current context imply bad current surface */
1527 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1528 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1529 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1531 /* a valid current context implies an initialized current display */
1532 assert(disp
->Initialized
);
1534 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1536 RETURN_EGL_EVAL(disp
, ret
);
1540 EGLDisplay EGLAPIENTRY
1541 eglGetCurrentDisplay(void)
1543 _EGLContext
*ctx
= _eglGetCurrentContext();
1546 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1548 RETURN_EGL_SUCCESS(NULL
, ret
);
1552 EGLContext EGLAPIENTRY
1553 eglGetCurrentContext(void)
1555 _EGLContext
*ctx
= _eglGetCurrentContext();
1558 ret
= _eglGetContextHandle(ctx
);
1560 RETURN_EGL_SUCCESS(NULL
, ret
);
1564 EGLSurface EGLAPIENTRY
1565 eglGetCurrentSurface(EGLint readdraw
)
1567 _EGLContext
*ctx
= _eglGetCurrentContext();
1568 EGLint err
= EGL_SUCCESS
;
1572 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1575 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1579 surf
= ctx
->DrawSurface
;
1582 surf
= ctx
->ReadSurface
;
1586 err
= EGL_BAD_PARAMETER
;
1590 ret
= _eglGetSurfaceHandle(surf
);
1592 RETURN_EGL_ERROR(NULL
, err
, ret
);
1599 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1600 EGLint e
= t
->LastError
;
1601 if (!_eglIsCurrentThreadDummy())
1602 t
->LastError
= EGL_SUCCESS
;
1612 * Specify the client API to use for subsequent calls including:
1613 * eglCreateContext()
1614 * eglGetCurrentContext()
1615 * eglGetCurrentDisplay()
1616 * eglGetCurrentSurface()
1617 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1620 * See section 3.7 "Rendering Context" in the EGL specification for details.
1622 EGLBoolean EGLAPIENTRY
1623 eglBindAPI(EGLenum api
)
1627 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1629 t
= _eglGetCurrentThread();
1630 if (_eglIsCurrentThreadDummy())
1631 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1633 if (!_eglIsApiValid(api
))
1634 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1636 t
->CurrentAPI
= api
;
1638 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1643 * Return the last value set with eglBindAPI().
1648 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1651 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1652 ret
= t
->CurrentAPI
;
1654 RETURN_EGL_SUCCESS(NULL
, ret
);
1658 EGLSurface EGLAPIENTRY
1659 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1660 EGLClientBuffer buffer
, EGLConfig config
,
1661 const EGLint
*attrib_list
)
1663 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1664 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1669 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1671 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1673 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1675 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1677 RETURN_EGL_EVAL(disp
, ret
);
1681 EGLBoolean EGLAPIENTRY
1682 eglReleaseThread(void)
1684 /* unbind current contexts */
1685 if (!_eglIsCurrentThreadDummy()) {
1686 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1687 _EGLContext
*ctx
= t
->CurrentContext
;
1689 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1692 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1695 mtx_lock(&disp
->Mutex
);
1697 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1698 mtx_unlock(&disp
->Mutex
);
1702 _eglDestroyCurrentThread();
1704 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1709 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1710 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1712 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1717 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1718 if (!disp
->Extensions
.KHR_image_base
)
1719 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1720 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1721 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1722 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1723 * <ctx> must be EGL_NO_CONTEXT..."
1725 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1726 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1728 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1730 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1732 RETURN_EGL_EVAL(disp
, ret
);
1735 static EGLImage EGLAPIENTRY
1736 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1737 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1739 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1740 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1741 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1745 EGLImage EGLAPIENTRY
1746 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1747 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1749 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1751 EGLint
*int_attribs
;
1753 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1755 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1756 if (attr_list
&& !int_attribs
)
1757 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1759 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1766 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1771 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1772 if (!disp
->Extensions
.KHR_image_base
)
1773 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1775 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1777 _eglUnlinkImage(img
);
1778 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1780 RETURN_EGL_EVAL(disp
, ret
);
1783 EGLBoolean EGLAPIENTRY
1784 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1786 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1787 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1788 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1789 return _eglDestroyImageCommon(disp
, img
);
1792 static EGLBoolean EGLAPIENTRY
1793 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1795 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1796 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1797 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1798 return _eglDestroyImageCommon(disp
, img
);
1803 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1804 EGLBoolean orig_is_EGLAttrib
,
1805 EGLenum invalid_type_error
)
1807 _EGLContext
*ctx
= _eglGetCurrentContext();
1812 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1814 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1815 /* There exist two EGLAttrib variants of eglCreateSync*:
1816 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1817 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1818 * support as a proxy for EGL 1.5 support, even though that's not
1819 * entirely correct (though _eglComputeVersion does the same).
1821 * The EGL spec provides no guidance on how to handle unsupported
1822 * functions. EGL_BAD_MATCH seems reasonable.
1824 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1827 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1828 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1829 * error is generated.
1832 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1833 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1835 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1836 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1837 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1838 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1841 case EGL_SYNC_FENCE_KHR
:
1842 if (!disp
->Extensions
.KHR_fence_sync
)
1843 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1845 case EGL_SYNC_REUSABLE_KHR
:
1846 if (!disp
->Extensions
.KHR_reusable_sync
)
1847 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1849 case EGL_SYNC_CL_EVENT_KHR
:
1850 if (!disp
->Extensions
.KHR_cl_event2
)
1851 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1853 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1854 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1855 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1858 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1861 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1862 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1864 RETURN_EGL_EVAL(disp
, ret
);
1868 static EGLSync EGLAPIENTRY
1869 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1871 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1872 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1875 EGLAttrib
*attrib_list
;
1878 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1879 attrib_list
= (EGLAttrib
*) int_list
;
1881 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1882 if (err
!= EGL_SUCCESS
)
1883 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1886 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1889 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1892 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1897 static EGLSync EGLAPIENTRY
1898 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1900 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1901 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1902 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1908 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1910 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1911 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1912 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1918 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1923 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1924 assert(disp
->Extensions
.KHR_reusable_sync
||
1925 disp
->Extensions
.KHR_fence_sync
||
1926 disp
->Extensions
.ANDROID_native_fence_sync
);
1929 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1931 RETURN_EGL_EVAL(disp
, ret
);
1934 EGLBoolean EGLAPIENTRY
1935 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1937 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1938 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1939 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1940 return _eglDestroySync(disp
, s
);
1943 static EGLBoolean EGLAPIENTRY
1944 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1946 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1947 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1948 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1949 return _eglDestroySync(disp
, s
);
1954 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1955 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1960 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1961 assert(disp
->Extensions
.KHR_reusable_sync
||
1962 disp
->Extensions
.KHR_fence_sync
||
1963 disp
->Extensions
.ANDROID_native_fence_sync
);
1965 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1966 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1968 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1969 * unlocked here to allow other threads also to be able to
1970 * go into waiting state.
1973 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1974 _eglUnlockDisplay(dpy
);
1976 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1979 * 'disp' is already unlocked for reusable sync type,
1980 * so passing 'NULL' to bypass unlocking display.
1982 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1983 RETURN_EGL_EVAL(NULL
, ret
);
1985 RETURN_EGL_EVAL(disp
, ret
);
1989 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
1990 EGLint flags
, EGLTime timeout
)
1992 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1993 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1994 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1995 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1998 static EGLint EGLAPIENTRY
1999 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
2000 EGLint flags
, EGLTime timeout
)
2002 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2003 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2004 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2005 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2010 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
2012 _EGLContext
*ctx
= _eglGetCurrentContext();
2016 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2017 assert(disp
->Extensions
.KHR_wait_sync
);
2019 /* return an error if the client API doesn't support GL_OES_EGL_sync */
2020 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
2021 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
2023 /* the API doesn't allow any flags yet */
2025 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2027 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
2029 RETURN_EGL_EVAL(disp
, ret
);
2032 static EGLint EGLAPIENTRY
2033 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2035 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2036 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2037 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2038 return _eglWaitSyncCommon(disp
, s
, flags
);
2042 EGLBoolean EGLAPIENTRY
2043 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2045 /* The KHR version returns EGLint, while the core version returns
2046 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
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 static EGLBoolean EGLAPIENTRY
2057 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2059 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2060 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2064 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2066 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2067 assert(disp
->Extensions
.KHR_reusable_sync
);
2068 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2070 RETURN_EGL_EVAL(disp
, ret
);
2075 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2080 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2081 assert(disp
->Extensions
.KHR_reusable_sync
||
2082 disp
->Extensions
.KHR_fence_sync
||
2083 disp
->Extensions
.ANDROID_native_fence_sync
);
2084 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2086 RETURN_EGL_EVAL(disp
, ret
);
2089 EGLBoolean EGLAPIENTRY
2090 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2092 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2093 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2094 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2095 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2099 static EGLBoolean EGLAPIENTRY
2100 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2102 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2103 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2107 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2110 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2113 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2115 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2117 * If any error occurs, <*value> is not modified.
2119 if (result
== EGL_FALSE
)
2126 static EGLint EGLAPIENTRY
2127 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2129 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2130 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2134 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2136 /* the spec doesn't seem to specify what happens if the fence
2137 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2140 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2141 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2143 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2144 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2145 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2147 RETURN_EGL_EVAL(disp
, ret
);
2150 static EGLBoolean EGLAPIENTRY
2151 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2152 EGLint numRects
, const EGLint
*rects
)
2154 _EGLContext
*ctx
= _eglGetCurrentContext();
2155 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2156 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2160 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2162 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2164 if (!disp
->Extensions
.NOK_swap_region
)
2165 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2167 /* surface must be bound to current context in EGL 1.4 */
2168 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2169 surf
!= ctx
->DrawSurface
)
2170 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2172 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2174 RETURN_EGL_EVAL(disp
, ret
);
2178 static EGLImage EGLAPIENTRY
2179 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2181 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2186 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2188 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2189 if (!disp
->Extensions
.MESA_drm_image
)
2190 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2192 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2193 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2195 RETURN_EGL_EVAL(disp
, ret
);
2198 static EGLBoolean EGLAPIENTRY
2199 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2200 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2202 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2203 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2207 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2209 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2210 assert(disp
->Extensions
.MESA_drm_image
);
2213 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2215 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2217 RETURN_EGL_EVAL(disp
, ret
);
2223 static EGLBoolean EGLAPIENTRY
2224 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2226 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2230 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2232 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2233 assert(disp
->Extensions
.WL_bind_wayland_display
);
2236 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2238 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2240 RETURN_EGL_EVAL(disp
, ret
);
2243 static EGLBoolean EGLAPIENTRY
2244 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2246 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2250 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2252 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2253 assert(disp
->Extensions
.WL_bind_wayland_display
);
2256 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2258 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2260 RETURN_EGL_EVAL(disp
, ret
);
2263 static EGLBoolean EGLAPIENTRY
2264 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2265 EGLint attribute
, EGLint
*value
)
2267 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2271 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2273 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2274 assert(disp
->Extensions
.WL_bind_wayland_display
);
2277 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2279 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2281 RETURN_EGL_EVAL(disp
, ret
);
2285 static struct wl_buffer
* EGLAPIENTRY
2286 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2288 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2291 struct wl_buffer
*ret
;
2293 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2295 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2296 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2297 RETURN_EGL_EVAL(disp
, NULL
);
2299 img
= _eglLookupImage(image
, disp
);
2302 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2304 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2306 RETURN_EGL_EVAL(disp
, ret
);
2309 static EGLBoolean EGLAPIENTRY
2310 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2311 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2313 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2314 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2318 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2320 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2322 if (!disp
->Extensions
.NV_post_sub_buffer
)
2323 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2325 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2327 RETURN_EGL_EVAL(disp
, ret
);
2330 static EGLBoolean EGLAPIENTRY
2331 eglGetSyncValuesCHROMIUM(EGLDisplay dpy
, EGLSurface surface
,
2332 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2335 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2336 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2340 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2342 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2343 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2344 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2346 if (!ust
|| !msc
|| !sbc
)
2347 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2349 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2351 RETURN_EGL_EVAL(disp
, ret
);
2354 static EGLBoolean EGLAPIENTRY
2355 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2356 EGLint
*fourcc
, EGLint
*nplanes
,
2357 EGLuint64KHR
*modifiers
)
2359 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2360 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2364 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2366 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2367 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2370 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2372 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2375 RETURN_EGL_EVAL(disp
, ret
);
2378 static EGLBoolean EGLAPIENTRY
2379 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2380 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2382 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2383 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2387 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2389 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2390 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2393 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2395 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2397 RETURN_EGL_EVAL(disp
, ret
);
2400 static EGLint EGLAPIENTRY
2401 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2404 _EGLDisplay
*disp
= NULL
;
2405 _EGLResourceType type
;
2407 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2409 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2410 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2412 if (!_eglIsCurrentThreadDummy()) {
2417 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2420 disp
= _eglLockDisplay(dpy
);
2422 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2424 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2425 if (dpy
!= (EGLDisplay
) object
)
2426 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2428 disp
->Label
= label
;
2429 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2432 switch (objectType
) {
2433 case EGL_OBJECT_CONTEXT_KHR
:
2434 type
= _EGL_RESOURCE_CONTEXT
;
2436 case EGL_OBJECT_SURFACE_KHR
:
2437 type
= _EGL_RESOURCE_SURFACE
;
2439 case EGL_OBJECT_IMAGE_KHR
:
2440 type
= _EGL_RESOURCE_IMAGE
;
2442 case EGL_OBJECT_SYNC_KHR
:
2443 type
= _EGL_RESOURCE_SYNC
;
2445 case EGL_OBJECT_STREAM_KHR
:
2447 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2450 if (_eglCheckResource(object
, type
, disp
)) {
2451 _EGLResource
*res
= (_EGLResource
*) object
;
2454 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2457 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2460 static EGLint EGLAPIENTRY
2461 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2462 const EGLAttrib
*attrib_list
)
2464 unsigned int newEnabled
;
2466 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2468 mtx_lock(_eglGlobal
.Mutex
);
2470 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2471 if (attrib_list
!= NULL
) {
2474 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2475 switch (attrib_list
[i
]) {
2476 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2477 case EGL_DEBUG_MSG_ERROR_KHR
:
2478 case EGL_DEBUG_MSG_WARN_KHR
:
2479 case EGL_DEBUG_MSG_INFO_KHR
:
2480 if (attrib_list
[i
+ 1])
2481 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2483 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2486 // On error, set the last error code, call the current
2487 // debug callback, and return the error code.
2488 mtx_unlock(_eglGlobal
.Mutex
);
2489 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2490 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2491 return EGL_BAD_ATTRIBUTE
;
2496 if (callback
!= NULL
) {
2497 _eglGlobal
.debugCallback
= callback
;
2498 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2500 _eglGlobal
.debugCallback
= NULL
;
2501 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2504 mtx_unlock(_eglGlobal
.Mutex
);
2508 static EGLBoolean EGLAPIENTRY
2509 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2511 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2513 mtx_lock(_eglGlobal
.Mutex
);
2515 switch (attribute
) {
2516 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2517 case EGL_DEBUG_MSG_ERROR_KHR
:
2518 case EGL_DEBUG_MSG_WARN_KHR
:
2519 case EGL_DEBUG_MSG_INFO_KHR
:
2520 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2525 case EGL_DEBUG_CALLBACK_KHR
:
2526 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2529 mtx_unlock(_eglGlobal
.Mutex
);
2530 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2531 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2535 mtx_unlock(_eglGlobal
.Mutex
);
2540 _eglFunctionCompare(const void *key
, const void *elem
)
2542 const char *procname
= key
;
2543 const struct _egl_entrypoint
*entrypoint
= elem
;
2544 return strcmp(procname
, entrypoint
->name
);
2547 static EGLBoolean EGLAPIENTRY
2548 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2549 EGLint
*formats
, EGLint
*num_formats
)
2551 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2555 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2557 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2559 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2562 RETURN_EGL_EVAL(disp
, ret
);
2565 static EGLBoolean EGLAPIENTRY
2566 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2567 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2568 EGLint
*num_modifiers
)
2570 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2574 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2576 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2578 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2579 modifiers
, external_only
,
2582 RETURN_EGL_EVAL(disp
, ret
);
2585 static void EGLAPIENTRY
2586 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2587 EGLGetBlobFuncANDROID get
)
2589 /* This function does not return anything so we cannot
2590 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2592 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2593 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2595 _eglUnlockDisplay(disp
);
2599 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2602 _eglUnlockDisplay(disp
);
2607 _eglError(EGL_BAD_PARAMETER
,
2608 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2609 _eglUnlockDisplay(disp
);
2613 if (disp
->BlobCacheSet
) {
2614 _eglError(EGL_BAD_PARAMETER
,
2615 "eglSetBlobCacheFuncsANDROID: functions already set");
2616 _eglUnlockDisplay(disp
);
2620 disp
->BlobCacheSet
= set
;
2621 disp
->BlobCacheGet
= get
;
2623 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2625 _eglUnlockDisplay(disp
);
2628 static EGLBoolean EGLAPIENTRY
2629 eglQueryDeviceAttribEXT(EGLDeviceEXT device
,
2633 _EGLDevice
*dev
= _eglLookupDevice(device
);
2636 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2638 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, EGL_FALSE
);
2640 ret
= _eglQueryDeviceAttribEXT(dev
, attribute
, value
);
2641 RETURN_EGL_EVAL(NULL
, ret
);
2644 static const char * EGLAPIENTRY
2645 eglQueryDeviceStringEXT(EGLDeviceEXT device
,
2648 _EGLDevice
*dev
= _eglLookupDevice(device
);
2650 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2652 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, NULL
);
2654 RETURN_EGL_EVAL(NULL
, _eglQueryDeviceStringEXT(dev
, name
));
2657 static EGLBoolean EGLAPIENTRY
2658 eglQueryDevicesEXT(EGLint max_devices
,
2659 EGLDeviceEXT
*devices
,
2660 EGLint
*num_devices
)
2664 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2665 ret
= _eglQueryDevicesEXT(max_devices
, (_EGLDevice
**) devices
,
2667 RETURN_EGL_EVAL(NULL
, ret
);
2670 static EGLBoolean EGLAPIENTRY
2671 eglQueryDisplayAttribEXT(EGLDisplay dpy
,
2675 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2678 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2679 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2681 switch (attribute
) {
2682 case EGL_DEVICE_EXT
:
2683 *value
= (EGLAttrib
) disp
->Device
;
2686 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
2688 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
2691 static char * EGLAPIENTRY
2692 eglGetDisplayDriverConfig(EGLDisplay dpy
)
2694 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2698 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2699 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2701 assert(disp
->Extensions
.MESA_query_driver
);
2703 ret
= drv
->API
.QueryDriverConfig(disp
);
2704 RETURN_EGL_EVAL(disp
, ret
);
2707 static const char * EGLAPIENTRY
2708 eglGetDisplayDriverName(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
.QueryDriverName(disp
);
2720 RETURN_EGL_EVAL(disp
, ret
);
2723 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2724 eglGetProcAddress(const char *procname
)
2726 static const struct _egl_entrypoint egl_functions
[] = {
2727 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2728 #include "eglentrypoint.h"
2729 #undef EGL_ENTRYPOINT
2731 _EGLProc ret
= NULL
;
2734 RETURN_EGL_SUCCESS(NULL
, NULL
);
2736 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2738 if (strncmp(procname
, "egl", 3) == 0) {
2739 const struct _egl_entrypoint
*entrypoint
=
2741 egl_functions
, ARRAY_SIZE(egl_functions
),
2742 sizeof(egl_functions
[0]),
2743 _eglFunctionCompare
);
2745 ret
= entrypoint
->function
;
2749 ret
= _eglGetDriverProc(procname
);
2751 RETURN_EGL_SUCCESS(NULL
, ret
);
2755 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2756 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2760 *disp
= _eglLockDisplay(dpy
);
2761 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2763 _eglUnlockDisplay(*disp
);
2764 return MESA_GLINTEROP_INVALID_DISPLAY
;
2767 *drv
= (*disp
)->Driver
;
2769 *ctx
= _eglLookupContext(context
, *disp
);
2771 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2772 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2773 _eglUnlockDisplay(*disp
);
2774 return MESA_GLINTEROP_INVALID_CONTEXT
;
2777 return MESA_GLINTEROP_SUCCESS
;
2781 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2782 struct mesa_glinterop_device_info
*out
)
2789 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2790 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2793 if (drv
->API
.GLInteropQueryDeviceInfo
)
2794 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2796 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2798 _eglUnlockDisplay(disp
);
2803 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2804 struct mesa_glinterop_export_in
*in
,
2805 struct mesa_glinterop_export_out
*out
)
2812 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2813 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2816 if (drv
->API
.GLInteropExportObject
)
2817 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2819 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2821 _eglUnlockDisplay(disp
);