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
89 #include "c99_compat.h"
90 #include "c11/threads.h"
91 #include "GL/mesa_glinterop.h"
92 #include "eglcompiler.h"
94 #include "eglglobals.h"
95 #include "eglcontext.h"
96 #include "egldisplay.h"
97 #include "egltypedefs.h"
98 #include "eglcurrent.h"
99 #include "egldriver.h"
100 #include "eglsurface.h"
101 #include "eglconfig.h"
102 #include "eglimage.h"
107 * Macros to help return an API entrypoint.
109 * These macros will unlock the display and record the error code.
111 #define RETURN_EGL_ERROR(disp, err, ret) \
114 _eglUnlockDisplay(disp); \
115 /* EGL error codes are non-zero */ \
117 _eglError(err, __func__); \
121 #define RETURN_EGL_SUCCESS(disp, ret) \
122 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
124 /* record EGL_SUCCESS only when ret evaluates to true */
125 #define RETURN_EGL_EVAL(disp, ret) \
126 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
130 * A bunch of macros and checks to simplify error checking.
133 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
135 drv = _eglCheckDisplay(disp, __func__); \
137 RETURN_EGL_ERROR(disp, 0, ret); \
140 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
142 drv = _eglCheck ## type(disp, obj, __func__); \
144 RETURN_EGL_ERROR(disp, 0, ret); \
147 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
148 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
150 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
151 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
153 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
154 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
156 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
157 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
160 static inline _EGLDriver
*
161 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
164 _eglError(EGL_BAD_DISPLAY
, msg
);
167 if (!disp
->Initialized
) {
168 _eglError(EGL_NOT_INITIALIZED
, msg
);
175 static inline _EGLDriver
*
176 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
178 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
182 _eglError(EGL_BAD_SURFACE
, msg
);
189 static inline _EGLDriver
*
190 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
192 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
196 _eglError(EGL_BAD_CONTEXT
, msg
);
203 static inline _EGLDriver
*
204 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
206 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
210 _eglError(EGL_BAD_CONFIG
, msg
);
217 static inline _EGLDriver
*
218 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
220 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
224 _eglError(EGL_BAD_PARAMETER
, msg
);
232 * Lookup and lock a display.
234 static inline _EGLDisplay
*
235 _eglLockDisplay(EGLDisplay display
)
237 _EGLDisplay
*dpy
= _eglLookupDisplay(display
);
239 mtx_lock(&dpy
->Mutex
);
248 _eglUnlockDisplay(_EGLDisplay
*dpy
)
250 mtx_unlock(&dpy
->Mutex
);
254 _eglSetFuncName(const char *funcName
, _EGLDisplay
*disp
, EGLenum objectType
, _EGLResource
*object
)
256 _EGLThreadInfo
*thr
= _eglGetCurrentThread();
257 if (!_eglIsCurrentThreadDummy()) {
258 thr
->CurrentFuncName
= funcName
;
259 thr
->CurrentObjectLabel
= NULL
;
261 if (objectType
== EGL_OBJECT_THREAD_KHR
)
262 thr
->CurrentObjectLabel
= thr
->Label
;
263 else if (objectType
== EGL_OBJECT_DISPLAY_KHR
&& disp
)
264 thr
->CurrentObjectLabel
= disp
->Label
;
266 thr
->CurrentObjectLabel
= object
->Label
;
271 _eglDebugReportFull(EGL_BAD_ALLOC
, funcName
, funcName
,
272 EGL_DEBUG_MSG_CRITICAL_KHR
, NULL
, NULL
);
276 #define _EGL_FUNC_START(disp, objectType, object, ret) \
278 if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \
280 _eglUnlockDisplay(disp); \
286 * Convert an attribute list from EGLint[] to EGLAttrib[].
288 * Return an EGL error code. The output parameter out_attrib_list is modified
292 _eglConvertIntsToAttribs(const EGLint
*int_list
, EGLAttrib
**out_attrib_list
)
295 EGLAttrib
*attrib_list
;
298 while (int_list
[2*len
] != EGL_NONE
)
303 *out_attrib_list
= NULL
;
307 if (2*len
+ 1 > SIZE_MAX
/ sizeof(EGLAttrib
))
308 return EGL_BAD_ALLOC
;
310 attrib_list
= malloc((2*len
+ 1) * sizeof(EGLAttrib
));
312 return EGL_BAD_ALLOC
;
314 for (size_t i
= 0; i
< len
; ++i
) {
315 attrib_list
[2*i
+ 0] = int_list
[2*i
+ 0];
316 attrib_list
[2*i
+ 1] = int_list
[2*i
+ 1];
319 attrib_list
[2*len
] = EGL_NONE
;
321 *out_attrib_list
= attrib_list
;
327 _eglConvertAttribsToInt(const EGLAttrib
*attr_list
)
329 EGLint
*int_attribs
= NULL
;
331 /* Convert attributes from EGLAttrib[] to EGLint[] */
335 while (attr_list
[size
] != EGL_NONE
)
338 size
+= 1; /* add space for EGL_NONE */
340 int_attribs
= calloc(size
, sizeof(int_attribs
[0]));
344 for (i
= 0; i
< size
; i
++)
345 int_attribs
[i
] = attr_list
[i
];
352 * This is typically the first EGL function that an application calls.
353 * It associates a private _EGLDisplay object to the native display.
355 EGLDisplay EGLAPIENTRY
356 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
358 _EGLPlatformType plat
;
360 void *native_display_ptr
;
362 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
364 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
365 native_display_ptr
= (void*) nativeDisplay
;
367 plat
= _eglGetNativePlatform(native_display_ptr
);
368 dpy
= _eglFindDisplay(plat
, native_display_ptr
);
369 return _eglGetDisplayHandle(dpy
);
373 _eglGetPlatformDisplayCommon(EGLenum platform
, void *native_display
,
374 const EGLint
*attrib_list
)
379 #ifdef HAVE_X11_PLATFORM
380 case EGL_PLATFORM_X11_EXT
:
381 dpy
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
384 #ifdef HAVE_DRM_PLATFORM
385 case EGL_PLATFORM_GBM_MESA
:
386 dpy
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
390 #ifdef HAVE_WAYLAND_PLATFORM
391 case EGL_PLATFORM_WAYLAND_EXT
:
392 dpy
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
396 #ifdef HAVE_SURFACELESS_PLATFORM
397 case EGL_PLATFORM_SURFACELESS_MESA
:
398 dpy
= _eglGetSurfacelessDisplay(native_display
, attrib_list
);
402 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
405 return _eglGetDisplayHandle(dpy
);
408 static EGLDisplay EGLAPIENTRY
409 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
410 const EGLint
*attrib_list
)
412 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
413 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
416 EGLDisplay EGLAPIENTRY
417 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
418 const EGLAttrib
*attrib_list
)
423 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
425 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
426 if (attrib_list
&& !int_attribs
)
427 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
429 display
= _eglGetPlatformDisplayCommon(platform
, native_display
, int_attribs
);
435 * Copy the extension into the string and update the string pointer.
438 _eglAppendExtension(char **str
, const char *ext
)
441 size_t len
= strlen(ext
);
458 * Examine the individual extension enable/disable flags and recompute
459 * the driver's Extensions string.
462 _eglCreateExtensionsString(_EGLDisplay
*dpy
)
464 #define _EGL_CHECK_EXTENSION(ext) \
466 if (dpy->Extensions.ext) { \
467 _eglAppendExtension(&exts, "EGL_" #ext); \
468 assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
472 char *exts
= dpy
->ExtensionsString
;
474 /* Please keep these sorted alphabetically. */
475 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
476 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
477 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
479 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
481 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
482 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
483 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
484 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
486 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
487 _EGL_CHECK_EXTENSION(KHR_create_context
);
488 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
489 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
490 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
491 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
492 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
493 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
494 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
495 if (dpy
->Extensions
.KHR_image_base
&& dpy
->Extensions
.KHR_image_pixmap
)
496 _eglAppendExtension(&exts
, "EGL_KHR_image");
497 _EGL_CHECK_EXTENSION(KHR_image_base
);
498 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
499 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
500 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
501 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
502 if (dpy
->Extensions
.EXT_swap_buffers_with_damage
)
503 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
504 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
506 if (dpy
->Extensions
.KHR_no_config_context
)
507 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
508 _EGL_CHECK_EXTENSION(MESA_drm_image
);
509 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
511 _EGL_CHECK_EXTENSION(NOK_swap_region
);
512 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
514 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
516 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
517 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
519 #undef _EGL_CHECK_EXTENSION
523 _eglCreateAPIsString(_EGLDisplay
*dpy
)
525 if (dpy
->ClientAPIs
& EGL_OPENGL_BIT
)
526 strcat(dpy
->ClientAPIsString
, "OpenGL ");
528 if (dpy
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
529 dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
530 dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
531 strcat(dpy
->ClientAPIsString
, "OpenGL_ES ");
534 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
535 strcat(dpy
->ClientAPIsString
, "OpenVG ");
537 assert(strlen(dpy
->ClientAPIsString
) < sizeof(dpy
->ClientAPIsString
));
541 _eglComputeVersion(_EGLDisplay
*disp
)
545 if (disp
->Extensions
.KHR_fence_sync
&&
546 disp
->Extensions
.KHR_cl_event2
&&
547 disp
->Extensions
.KHR_wait_sync
&&
548 disp
->Extensions
.KHR_image_base
&&
549 disp
->Extensions
.KHR_gl_texture_2D_image
&&
550 disp
->Extensions
.KHR_gl_texture_3D_image
&&
551 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
552 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
553 disp
->Extensions
.KHR_create_context
&&
554 disp
->Extensions
.EXT_create_context_robustness
&&
555 disp
->Extensions
.KHR_get_all_proc_addresses
&&
556 disp
->Extensions
.KHR_gl_colorspace
&&
557 disp
->Extensions
.KHR_surfaceless_context
)
562 * This is typically the second EGL function that an application calls.
563 * Here we load/initialize the actual hardware driver.
565 EGLBoolean EGLAPIENTRY
566 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
568 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
570 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
573 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
575 if (!disp
->Initialized
) {
576 if (!_eglMatchDriver(disp
, EGL_FALSE
))
577 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
579 /* limit to APIs supported by core */
580 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
582 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
583 * classifies it as an EGL display extension, though conceptually it's an
584 * EGL client extension.
586 * From the EGL_KHR_get_all_proc_addresses spec:
588 * The EGL implementation must expose the name
589 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
590 * EGL_KHR_get_all_proc_addresses and supports
591 * EGL_EXT_client_extensions.
593 * Mesa unconditionally exposes both client extensions mentioned above,
594 * so the spec requires that each EGLDisplay unconditionally expose
595 * EGL_KHR_get_all_proc_addresses also.
597 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
599 _eglComputeVersion(disp
);
600 _eglCreateExtensionsString(disp
);
601 _eglCreateAPIsString(disp
);
602 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
603 "%d.%d (%s)", disp
->Version
/ 10, disp
->Version
% 10,
607 /* Update applications version of major and minor if not NULL */
608 if ((major
!= NULL
) && (minor
!= NULL
)) {
609 *major
= disp
->Version
/ 10;
610 *minor
= disp
->Version
% 10;
613 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
617 EGLBoolean EGLAPIENTRY
618 eglTerminate(EGLDisplay dpy
)
620 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
622 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
625 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
627 if (disp
->Initialized
) {
628 _EGLDriver
*drv
= disp
->Driver
;
630 drv
->API
.Terminate(drv
, disp
);
631 /* do not reset disp->Driver */
632 disp
->ClientAPIsString
[0] = 0;
633 disp
->Initialized
= EGL_FALSE
;
636 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
640 const char * EGLAPIENTRY
641 eglQueryString(EGLDisplay dpy
, EGLint name
)
646 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
647 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
650 disp
= _eglLockDisplay(dpy
);
651 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
652 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
656 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
658 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
660 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
661 case EGL_CLIENT_APIS
:
662 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
664 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
669 EGLBoolean EGLAPIENTRY
670 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
671 EGLint config_size
, EGLint
*num_config
)
673 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
677 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
679 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
680 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
682 RETURN_EGL_EVAL(disp
, ret
);
686 EGLBoolean EGLAPIENTRY
687 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
688 EGLint config_size
, EGLint
*num_config
)
690 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
694 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
696 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
697 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
698 config_size
, num_config
);
700 RETURN_EGL_EVAL(disp
, ret
);
704 EGLBoolean EGLAPIENTRY
705 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
706 EGLint attribute
, EGLint
*value
)
708 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
709 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
713 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
715 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
716 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
718 RETURN_EGL_EVAL(disp
, ret
);
722 EGLContext EGLAPIENTRY
723 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
724 const EGLint
*attrib_list
)
726 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
727 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
728 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
730 _EGLContext
*context
;
733 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
735 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
737 if (!config
&& !disp
->Extensions
.KHR_no_config_context
)
738 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
740 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
741 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
743 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
744 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
746 RETURN_EGL_EVAL(disp
, ret
);
750 EGLBoolean EGLAPIENTRY
751 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
753 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
754 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
758 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
760 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
761 _eglUnlinkContext(context
);
762 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
764 RETURN_EGL_EVAL(disp
, ret
);
768 EGLBoolean EGLAPIENTRY
769 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
772 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
773 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
774 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
775 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
779 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
782 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
785 /* display is allowed to be uninitialized under certain condition */
786 if (!disp
->Initialized
) {
787 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
788 ctx
!= EGL_NO_CONTEXT
)
789 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
792 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
794 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
795 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
796 if (!draw_surf
|| !read_surf
) {
797 /* From the EGL 1.4 (20130211) spec:
799 * To release the current context without assigning a new one, set ctx
800 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
802 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
803 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
805 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
806 (!read_surf
&& read
!= EGL_NO_SURFACE
))
807 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
808 if (draw_surf
|| read_surf
)
809 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
812 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
814 RETURN_EGL_EVAL(disp
, ret
);
818 EGLBoolean EGLAPIENTRY
819 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
820 EGLint attribute
, EGLint
*value
)
822 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
823 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
827 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
829 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
830 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
832 RETURN_EGL_EVAL(disp
, ret
);
837 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
838 void *native_window
, const EGLint
*attrib_list
)
840 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
846 if (native_window
== NULL
)
847 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
849 #ifdef HAVE_SURFACELESS_PLATFORM
850 if (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
851 /* From the EGL_MESA_platform_surfaceless spec (v1):
853 * eglCreatePlatformWindowSurface fails when called with a <display>
854 * that belongs to the surfaceless platform. It returns
855 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
856 * justification for this unconditional failure is that the
857 * surfaceless platform has no native windows, and therefore the
858 * <native_window> parameter is always invalid.
860 * This check must occur before checking the EGLConfig, which emits
863 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
867 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
869 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
871 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
873 RETURN_EGL_EVAL(disp
, ret
);
877 EGLSurface EGLAPIENTRY
878 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
879 EGLNativeWindowType window
, const EGLint
*attrib_list
)
881 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
883 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
884 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
885 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
890 fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
892 #ifdef HAVE_X11_PLATFORM
893 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
894 /* The `native_window` parameter for the X11 platform differs between
895 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
896 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
897 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
898 * `Window*`. Convert `Window*` to `Window` because that's what
899 * dri2_x11_create_window_surface() expects.
901 return (void *)(* (Window
*) native_window
);
904 return native_window
;
907 static EGLSurface EGLAPIENTRY
908 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
910 const EGLint
*attrib_list
)
912 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
914 native_window
= fixupNativeWindow(disp
, native_window
);
916 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
917 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
922 EGLSurface EGLAPIENTRY
923 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
925 const EGLAttrib
*attrib_list
)
927 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
931 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
933 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
934 if (attrib_list
&& !int_attribs
)
935 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
937 native_window
= fixupNativeWindow(disp
, native_window
);
938 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
945 fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
947 #ifdef HAVE_X11_PLATFORM
948 /* The `native_pixmap` parameter for the X11 platform differs between
949 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
950 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
951 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
952 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
953 * dri2_x11_create_pixmap_surface() expects.
955 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
956 return (void *)(* (Pixmap
*) native_pixmap
);
958 return native_pixmap
;
962 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
963 void *native_pixmap
, const EGLint
*attrib_list
)
965 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
970 #if HAVE_SURFACELESS_PLATFORM
971 if (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
972 /* From the EGL_MESA_platform_surfaceless spec (v1):
974 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
975 * also fails when called with a <display> that belongs to the
976 * surfaceless platform. It returns EGL_NO_SURFACE and generates
977 * EGL_BAD_NATIVE_PIXMAP.
979 * This check must occur before checking the EGLConfig, which emits
982 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
986 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
987 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
989 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
991 RETURN_EGL_EVAL(disp
, ret
);
995 EGLSurface EGLAPIENTRY
996 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
997 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
999 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1001 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1002 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1003 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1007 static EGLSurface EGLAPIENTRY
1008 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1009 void *native_pixmap
,
1010 const EGLint
*attrib_list
)
1012 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1014 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1015 native_pixmap
= fixupNativePixmap(disp
, native_pixmap
);
1016 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1021 EGLSurface EGLAPIENTRY
1022 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1023 void *native_pixmap
,
1024 const EGLAttrib
*attrib_list
)
1026 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1028 EGLint
*int_attribs
;
1030 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1032 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1033 if (attrib_list
&& !int_attribs
)
1034 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1036 native_pixmap
= fixupNativePixmap(disp
, native_pixmap
);
1037 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1044 EGLSurface EGLAPIENTRY
1045 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1046 const EGLint
*attrib_list
)
1048 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1049 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1054 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1055 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1057 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1058 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1060 RETURN_EGL_EVAL(disp
, ret
);
1064 EGLBoolean EGLAPIENTRY
1065 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1067 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1068 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1072 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1073 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1074 _eglUnlinkSurface(surf
);
1075 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1077 RETURN_EGL_EVAL(disp
, ret
);
1080 EGLBoolean EGLAPIENTRY
1081 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1082 EGLint attribute
, EGLint
*value
)
1084 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1085 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1089 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1090 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1091 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1093 RETURN_EGL_EVAL(disp
, ret
);
1096 EGLBoolean EGLAPIENTRY
1097 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1098 EGLint attribute
, EGLint value
)
1100 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1101 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1105 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1106 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1107 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1109 RETURN_EGL_EVAL(disp
, ret
);
1113 EGLBoolean EGLAPIENTRY
1114 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1116 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1117 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1121 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1122 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1123 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1125 RETURN_EGL_EVAL(disp
, ret
);
1129 EGLBoolean EGLAPIENTRY
1130 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1132 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1133 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1137 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1138 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1139 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1141 RETURN_EGL_EVAL(disp
, ret
);
1145 EGLBoolean EGLAPIENTRY
1146 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1148 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1149 _EGLContext
*ctx
= _eglGetCurrentContext();
1150 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1154 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1155 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1157 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1158 ctx
->Resource
.Display
!= disp
)
1159 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1161 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1162 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1164 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1166 RETURN_EGL_EVAL(disp
, ret
);
1170 EGLBoolean EGLAPIENTRY
1171 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1173 _EGLContext
*ctx
= _eglGetCurrentContext();
1174 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1175 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1179 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1180 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1182 /* surface must be bound to current context in EGL 1.4 */
1183 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1184 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1185 surf
!= ctx
->DrawSurface
)
1186 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1189 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1191 RETURN_EGL_EVAL(disp
, ret
);
1196 eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1197 EGLint
*rects
, EGLint n_rects
)
1199 _EGLContext
*ctx
= _eglGetCurrentContext();
1203 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1205 /* surface must be bound to current context in EGL 1.4 */
1206 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1207 surf
!= ctx
->DrawSurface
)
1208 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1210 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1211 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1213 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1215 RETURN_EGL_EVAL(disp
, ret
);
1218 static EGLBoolean EGLAPIENTRY
1219 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1220 EGLint
*rects
, EGLint n_rects
)
1222 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1223 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1224 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1225 return eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1228 static EGLBoolean EGLAPIENTRY
1229 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1230 EGLint
*rects
, EGLint n_rects
)
1232 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1233 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1234 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1235 return eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1238 EGLBoolean EGLAPIENTRY
1239 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1241 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1242 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1245 void *native_pixmap_ptr
;
1247 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1248 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1249 native_pixmap_ptr
= (void*) target
;
1251 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1252 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
1253 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
1254 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1256 RETURN_EGL_EVAL(disp
, ret
);
1261 _eglWaitClientCommon(void)
1263 _EGLContext
*ctx
= _eglGetCurrentContext();
1269 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1271 disp
= ctx
->Resource
.Display
;
1272 mtx_lock(&disp
->Mutex
);
1274 /* let bad current context imply bad current surface */
1275 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1276 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1277 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1279 /* a valid current context implies an initialized current display */
1280 assert(disp
->Initialized
);
1282 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1284 RETURN_EGL_EVAL(disp
, ret
);
1287 EGLBoolean EGLAPIENTRY
1290 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1291 return _eglWaitClientCommon();
1294 EGLBoolean EGLAPIENTRY
1297 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1298 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1299 return _eglWaitClientCommon();
1303 EGLBoolean EGLAPIENTRY
1304 eglWaitNative(EGLint engine
)
1306 _EGLContext
*ctx
= _eglGetCurrentContext();
1312 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1314 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1316 disp
= ctx
->Resource
.Display
;
1317 mtx_lock(&disp
->Mutex
);
1319 /* let bad current context imply bad current surface */
1320 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1321 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1322 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1324 /* a valid current context implies an initialized current display */
1325 assert(disp
->Initialized
);
1327 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1329 RETURN_EGL_EVAL(disp
, ret
);
1333 EGLDisplay EGLAPIENTRY
1334 eglGetCurrentDisplay(void)
1336 _EGLContext
*ctx
= _eglGetCurrentContext();
1339 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1341 RETURN_EGL_SUCCESS(NULL
, ret
);
1345 EGLContext EGLAPIENTRY
1346 eglGetCurrentContext(void)
1348 _EGLContext
*ctx
= _eglGetCurrentContext();
1351 ret
= _eglGetContextHandle(ctx
);
1353 RETURN_EGL_SUCCESS(NULL
, ret
);
1357 EGLSurface EGLAPIENTRY
1358 eglGetCurrentSurface(EGLint readdraw
)
1360 _EGLContext
*ctx
= _eglGetCurrentContext();
1361 EGLint err
= EGL_SUCCESS
;
1365 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1368 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1372 surf
= ctx
->DrawSurface
;
1375 surf
= ctx
->ReadSurface
;
1379 err
= EGL_BAD_PARAMETER
;
1383 ret
= _eglGetSurfaceHandle(surf
);
1385 RETURN_EGL_ERROR(NULL
, err
, ret
);
1392 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1393 EGLint e
= t
->LastError
;
1394 if (!_eglIsCurrentThreadDummy())
1395 t
->LastError
= EGL_SUCCESS
;
1405 * Specify the client API to use for subsequent calls including:
1406 * eglCreateContext()
1407 * eglGetCurrentContext()
1408 * eglGetCurrentDisplay()
1409 * eglGetCurrentSurface()
1410 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1413 * See section 3.7 "Rendering Context" in the EGL specification for details.
1415 EGLBoolean EGLAPIENTRY
1416 eglBindAPI(EGLenum api
)
1420 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1422 t
= _eglGetCurrentThread();
1423 if (_eglIsCurrentThreadDummy())
1424 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1426 if (!_eglIsApiValid(api
))
1427 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1429 t
->CurrentAPI
= api
;
1431 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1436 * Return the last value set with eglBindAPI().
1441 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1444 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1445 ret
= t
->CurrentAPI
;
1447 RETURN_EGL_SUCCESS(NULL
, ret
);
1451 EGLSurface EGLAPIENTRY
1452 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1453 EGLClientBuffer buffer
, EGLConfig config
,
1454 const EGLint
*attrib_list
)
1456 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1457 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1462 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1464 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1466 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1468 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1470 RETURN_EGL_EVAL(disp
, ret
);
1474 EGLBoolean EGLAPIENTRY
1475 eglReleaseThread(void)
1477 /* unbind current contexts */
1478 if (!_eglIsCurrentThreadDummy()) {
1479 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1480 _EGLContext
*ctx
= t
->CurrentContext
;
1482 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1485 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1488 mtx_lock(&disp
->Mutex
);
1490 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1491 mtx_unlock(&disp
->Mutex
);
1495 _eglDestroyCurrentThread();
1497 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1502 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1503 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1505 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1510 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1511 if (!disp
->Extensions
.KHR_image_base
)
1512 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1513 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1514 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1515 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1516 * <ctx> must be EGL_NO_CONTEXT..."
1518 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1519 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1521 img
= drv
->API
.CreateImageKHR(drv
,
1522 disp
, context
, target
, buffer
, attr_list
);
1523 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1525 RETURN_EGL_EVAL(disp
, ret
);
1528 static EGLImage EGLAPIENTRY
1529 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1530 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1532 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1533 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1534 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1538 EGLImage EGLAPIENTRY
1539 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1540 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1542 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1544 EGLint
*int_attribs
;
1546 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1548 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1549 if (attr_list
&& !int_attribs
)
1550 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1552 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1558 EGLBoolean EGLAPIENTRY
1559 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1561 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1562 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1566 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1568 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1569 if (!disp
->Extensions
.KHR_image_base
)
1570 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1572 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1574 _eglUnlinkImage(img
);
1575 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1577 RETURN_EGL_EVAL(disp
, ret
);
1582 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1583 EGLBoolean orig_is_EGLAttrib
,
1584 EGLenum invalid_type_error
)
1586 _EGLContext
*ctx
= _eglGetCurrentContext();
1591 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1593 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1594 /* There exist two EGLAttrib variants of eglCreateSync*:
1595 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1596 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1597 * support as a proxy for EGL 1.5 support, even though that's not
1598 * entirely correct (though _eglComputeVersion does the same).
1600 * The EGL spec provides no guidance on how to handle unsupported
1601 * functions. EGL_BAD_MATCH seems reasonable.
1603 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1606 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1607 if (!ctx
|| ctx
->Resource
.Display
!= disp
||
1608 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1609 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1612 case EGL_SYNC_FENCE_KHR
:
1613 if (!disp
->Extensions
.KHR_fence_sync
)
1614 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1616 case EGL_SYNC_REUSABLE_KHR
:
1617 if (!disp
->Extensions
.KHR_reusable_sync
)
1618 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1620 case EGL_SYNC_CL_EVENT_KHR
:
1621 if (!disp
->Extensions
.KHR_cl_event2
)
1622 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1625 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1628 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1629 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1631 RETURN_EGL_EVAL(disp
, ret
);
1635 static EGLSync EGLAPIENTRY
1636 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1638 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1639 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1642 EGLAttrib
*attrib_list
;
1645 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1646 attrib_list
= (EGLAttrib
*) int_list
;
1648 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1649 if (err
!= EGL_SUCCESS
)
1650 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1653 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1656 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1659 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1664 static EGLSync EGLAPIENTRY
1665 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1667 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1668 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1669 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1675 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1677 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1678 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1679 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1684 EGLBoolean EGLAPIENTRY
1685 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1687 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1688 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1692 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1694 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1695 assert(disp
->Extensions
.KHR_reusable_sync
||
1696 disp
->Extensions
.KHR_fence_sync
);
1699 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1701 RETURN_EGL_EVAL(disp
, ret
);
1706 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
, EGLTime timeout
)
1708 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1709 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1713 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1715 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1716 assert(disp
->Extensions
.KHR_reusable_sync
||
1717 disp
->Extensions
.KHR_fence_sync
);
1719 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1720 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1722 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1723 * unlocked here to allow other threads also to be able to
1724 * go into waiting state.
1727 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1728 _eglUnlockDisplay(dpy
);
1730 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1733 * 'disp' is already unlocked for reusable sync type,
1734 * so passing 'NULL' to bypass unlocking display.
1736 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1737 RETURN_EGL_EVAL(NULL
, ret
);
1739 RETURN_EGL_EVAL(disp
, ret
);
1744 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
1746 _EGLContext
*ctx
= _eglGetCurrentContext();
1750 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1751 assert(disp
->Extensions
.KHR_wait_sync
);
1753 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1754 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1755 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1757 /* the API doesn't allow any flags yet */
1759 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1761 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1763 RETURN_EGL_EVAL(disp
, ret
);
1766 static EGLint EGLAPIENTRY
1767 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1769 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1770 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1771 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1772 return _eglWaitSyncCommon(disp
, s
, flags
);
1776 EGLBoolean EGLAPIENTRY
1777 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1779 /* The KHR version returns EGLint, while the core version returns
1780 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1783 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1784 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1785 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1786 return _eglWaitSyncCommon(disp
, s
, flags
);
1790 static EGLBoolean EGLAPIENTRY
1791 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
1793 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1794 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1798 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1800 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1801 assert(disp
->Extensions
.KHR_reusable_sync
);
1802 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
1804 RETURN_EGL_EVAL(disp
, ret
);
1809 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
1814 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1815 assert(disp
->Extensions
.KHR_reusable_sync
||
1816 disp
->Extensions
.KHR_fence_sync
);
1817 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
1819 RETURN_EGL_EVAL(disp
, ret
);
1822 EGLBoolean EGLAPIENTRY
1823 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
1825 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1826 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1827 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1828 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
1832 static EGLBoolean EGLAPIENTRY
1833 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
1835 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1836 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1840 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1843 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1846 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
1848 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
1850 * If any error occurs, <*value> is not modified.
1852 if (result
== EGL_FALSE
)
1860 static EGLBoolean EGLAPIENTRY
1861 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
1862 EGLint numRects
, const EGLint
*rects
)
1864 _EGLContext
*ctx
= _eglGetCurrentContext();
1865 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1866 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1870 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1872 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1874 if (!disp
->Extensions
.NOK_swap_region
)
1875 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1877 /* surface must be bound to current context in EGL 1.4 */
1878 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1879 surf
!= ctx
->DrawSurface
)
1880 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1882 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
1884 RETURN_EGL_EVAL(disp
, ret
);
1888 static EGLImage EGLAPIENTRY
1889 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
1891 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1896 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1898 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1899 if (!disp
->Extensions
.MESA_drm_image
)
1900 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1902 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
1903 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1905 RETURN_EGL_EVAL(disp
, ret
);
1908 static EGLBoolean EGLAPIENTRY
1909 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
1910 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
1912 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1913 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1917 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1919 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1920 assert(disp
->Extensions
.MESA_drm_image
);
1923 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1925 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
1927 RETURN_EGL_EVAL(disp
, ret
);
1933 static EGLBoolean EGLAPIENTRY
1934 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1936 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1940 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1942 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1943 assert(disp
->Extensions
.WL_bind_wayland_display
);
1946 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1948 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
1950 RETURN_EGL_EVAL(disp
, ret
);
1953 static EGLBoolean EGLAPIENTRY
1954 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1956 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1960 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1962 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1963 assert(disp
->Extensions
.WL_bind_wayland_display
);
1966 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1968 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
1970 RETURN_EGL_EVAL(disp
, ret
);
1973 static EGLBoolean EGLAPIENTRY
1974 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
1975 EGLint attribute
, EGLint
*value
)
1977 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1981 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1983 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1984 assert(disp
->Extensions
.WL_bind_wayland_display
);
1987 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1989 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
1991 RETURN_EGL_EVAL(disp
, ret
);
1995 static struct wl_buffer
* EGLAPIENTRY
1996 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
1998 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2001 struct wl_buffer
*ret
;
2003 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2005 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2006 assert(disp
->Extensions
.WL_create_wayland_buffer_from_image
);
2008 img
= _eglLookupImage(image
, disp
);
2011 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2013 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2015 RETURN_EGL_EVAL(disp
, ret
);
2018 static EGLBoolean EGLAPIENTRY
2019 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2020 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2022 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2023 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2027 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2029 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2031 if (!disp
->Extensions
.NV_post_sub_buffer
)
2032 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2034 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2036 RETURN_EGL_EVAL(disp
, ret
);
2039 static EGLBoolean EGLAPIENTRY
2040 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
2041 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2044 _EGLDisplay
*disp
= _eglLockDisplay(display
);
2045 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2049 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2051 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2052 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2053 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2055 if (!ust
|| !msc
|| !sbc
)
2056 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2058 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2060 RETURN_EGL_EVAL(disp
, ret
);
2063 static EGLBoolean EGLAPIENTRY
2064 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2065 EGLint
*fourcc
, EGLint
*nplanes
,
2066 EGLuint64KHR
*modifiers
)
2068 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2069 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2073 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2075 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2076 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2079 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2081 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2084 RETURN_EGL_EVAL(disp
, ret
);
2087 static EGLBoolean EGLAPIENTRY
2088 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2089 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2091 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2092 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2096 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2098 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2099 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2102 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2104 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2106 RETURN_EGL_EVAL(disp
, ret
);
2109 static EGLint EGLAPIENTRY
2110 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2113 _EGLDisplay
*disp
= NULL
;
2114 _EGLResourceType type
;
2116 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2118 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2119 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2121 if (!_eglIsCurrentThreadDummy()) {
2126 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2129 disp
= _eglLockDisplay(dpy
);
2131 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2133 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2134 if (dpy
!= (EGLDisplay
) object
)
2135 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2137 disp
->Label
= label
;
2138 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2141 switch (objectType
) {
2142 case EGL_OBJECT_CONTEXT_KHR
:
2143 type
= _EGL_RESOURCE_CONTEXT
;
2145 case EGL_OBJECT_SURFACE_KHR
:
2146 type
= _EGL_RESOURCE_SURFACE
;
2148 case EGL_OBJECT_IMAGE_KHR
:
2149 type
= _EGL_RESOURCE_IMAGE
;
2151 case EGL_OBJECT_SYNC_KHR
:
2152 type
= _EGL_RESOURCE_SYNC
;
2154 case EGL_OBJECT_STREAM_KHR
:
2156 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2159 if (_eglCheckResource(object
, type
, disp
)) {
2160 _EGLResource
*res
= (_EGLResource
*) object
;
2163 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2166 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2170 validDebugMessageLevel(EGLAttrib level
)
2172 return (level
>= EGL_DEBUG_MSG_CRITICAL_KHR
&&
2173 level
<= EGL_DEBUG_MSG_INFO_KHR
);
2176 static EGLint EGLAPIENTRY
2177 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2178 const EGLAttrib
*attrib_list
)
2180 unsigned int newEnabled
;
2182 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2184 mtx_lock(_eglGlobal
.Mutex
);
2186 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2187 if (attrib_list
!= NULL
) {
2190 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2191 if (validDebugMessageLevel(attrib_list
[i
])) {
2192 if (attrib_list
[i
+ 1])
2193 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2195 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2199 // On error, set the last error code, call the current
2200 // debug callback, and return the error code.
2201 mtx_unlock(_eglGlobal
.Mutex
);
2202 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2203 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2204 return EGL_BAD_ATTRIBUTE
;
2208 if (callback
!= NULL
) {
2209 _eglGlobal
.debugCallback
= callback
;
2210 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2212 _eglGlobal
.debugCallback
= NULL
;
2213 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2216 mtx_unlock(_eglGlobal
.Mutex
);
2220 static EGLBoolean EGLAPIENTRY
2221 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2223 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2225 mtx_lock(_eglGlobal
.Mutex
);
2228 if (validDebugMessageLevel(attribute
)) {
2229 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2236 if (attribute
== EGL_DEBUG_CALLBACK_KHR
) {
2237 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2241 mtx_unlock(_eglGlobal
.Mutex
);
2242 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2243 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2247 mtx_unlock(_eglGlobal
.Mutex
);
2251 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2252 eglGetProcAddress(const char *procname
)
2254 static const struct {
2257 } egl_functions
[] = {
2258 /* core functions queryable in the presence of
2259 * EGL_KHR_get_all_proc_addresses or EGL 1.5
2261 /* alphabetical order */
2262 { "eglBindAPI", (_EGLProc
) eglBindAPI
},
2263 { "eglBindTexImage", (_EGLProc
) eglBindTexImage
},
2264 { "eglChooseConfig", (_EGLProc
) eglChooseConfig
},
2265 { "eglCopyBuffers", (_EGLProc
) eglCopyBuffers
},
2266 { "eglCreateContext", (_EGLProc
) eglCreateContext
},
2267 { "eglCreatePbufferFromClientBuffer", (_EGLProc
) eglCreatePbufferFromClientBuffer
},
2268 { "eglCreatePbufferSurface", (_EGLProc
) eglCreatePbufferSurface
},
2269 { "eglCreatePixmapSurface", (_EGLProc
) eglCreatePixmapSurface
},
2270 { "eglCreateWindowSurface", (_EGLProc
) eglCreateWindowSurface
},
2271 { "eglDestroyContext", (_EGLProc
) eglDestroyContext
},
2272 { "eglDestroySurface", (_EGLProc
) eglDestroySurface
},
2273 { "eglGetConfigAttrib", (_EGLProc
) eglGetConfigAttrib
},
2274 { "eglGetConfigs", (_EGLProc
) eglGetConfigs
},
2275 { "eglGetCurrentContext", (_EGLProc
) eglGetCurrentContext
},
2276 { "eglGetCurrentDisplay", (_EGLProc
) eglGetCurrentDisplay
},
2277 { "eglGetCurrentSurface", (_EGLProc
) eglGetCurrentSurface
},
2278 { "eglGetDisplay", (_EGLProc
) eglGetDisplay
},
2279 { "eglGetError", (_EGLProc
) eglGetError
},
2280 { "eglGetProcAddress", (_EGLProc
) eglGetProcAddress
},
2281 { "eglInitialize", (_EGLProc
) eglInitialize
},
2282 { "eglMakeCurrent", (_EGLProc
) eglMakeCurrent
},
2283 { "eglQueryAPI", (_EGLProc
) eglQueryAPI
},
2284 { "eglQueryContext", (_EGLProc
) eglQueryContext
},
2285 { "eglQueryString", (_EGLProc
) eglQueryString
},
2286 { "eglQuerySurface", (_EGLProc
) eglQuerySurface
},
2287 { "eglReleaseTexImage", (_EGLProc
) eglReleaseTexImage
},
2288 { "eglReleaseThread", (_EGLProc
) eglReleaseThread
},
2289 { "eglSurfaceAttrib", (_EGLProc
) eglSurfaceAttrib
},
2290 { "eglSwapBuffers", (_EGLProc
) eglSwapBuffers
},
2291 { "eglSwapInterval", (_EGLProc
) eglSwapInterval
},
2292 { "eglTerminate", (_EGLProc
) eglTerminate
},
2293 { "eglWaitClient", (_EGLProc
) eglWaitClient
},
2294 { "eglWaitGL", (_EGLProc
) eglWaitGL
},
2295 { "eglWaitNative", (_EGLProc
) eglWaitNative
},
2296 { "eglCreateSync", (_EGLProc
) eglCreateSync
},
2297 { "eglDestroySync", (_EGLProc
) eglDestroySync
},
2298 { "eglClientWaitSync", (_EGLProc
) eglClientWaitSync
},
2299 { "eglGetSyncAttrib", (_EGLProc
) eglGetSyncAttrib
},
2300 { "eglWaitSync", (_EGLProc
) eglWaitSync
},
2301 { "eglCreateImage", (_EGLProc
) eglCreateImage
},
2302 { "eglDestroyImage", (_EGLProc
) eglDestroyImage
},
2303 { "eglGetPlatformDisplay", (_EGLProc
) eglGetPlatformDisplay
},
2304 { "eglCreatePlatformWindowSurface", (_EGLProc
) eglCreatePlatformWindowSurface
},
2305 { "eglCreatePlatformPixmapSurface", (_EGLProc
) eglCreatePlatformPixmapSurface
},
2306 { "eglCreateImageKHR", (_EGLProc
) eglCreateImageKHR
},
2307 { "eglDestroyImageKHR", (_EGLProc
) eglDestroyImage
},
2308 { "eglCreateSyncKHR", (_EGLProc
) eglCreateSyncKHR
},
2309 { "eglCreateSync64KHR", (_EGLProc
) eglCreateSync64KHR
},
2310 { "eglDestroySyncKHR", (_EGLProc
) eglDestroySync
},
2311 { "eglClientWaitSyncKHR", (_EGLProc
) eglClientWaitSync
},
2312 { "eglWaitSyncKHR", (_EGLProc
) eglWaitSyncKHR
},
2313 { "eglSignalSyncKHR", (_EGLProc
) eglSignalSyncKHR
},
2314 { "eglGetSyncAttribKHR", (_EGLProc
) eglGetSyncAttribKHR
},
2315 { "eglSwapBuffersRegionNOK", (_EGLProc
) eglSwapBuffersRegionNOK
},
2316 { "eglCreateDRMImageMESA", (_EGLProc
) eglCreateDRMImageMESA
},
2317 { "eglExportDRMImageMESA", (_EGLProc
) eglExportDRMImageMESA
},
2318 { "eglBindWaylandDisplayWL", (_EGLProc
) eglBindWaylandDisplayWL
},
2319 { "eglUnbindWaylandDisplayWL", (_EGLProc
) eglUnbindWaylandDisplayWL
},
2320 { "eglQueryWaylandBufferWL", (_EGLProc
) eglQueryWaylandBufferWL
},
2321 { "eglCreateWaylandBufferFromImageWL", (_EGLProc
) eglCreateWaylandBufferFromImageWL
},
2322 { "eglPostSubBufferNV", (_EGLProc
) eglPostSubBufferNV
},
2323 { "eglSwapBuffersWithDamageEXT", (_EGLProc
) eglSwapBuffersWithDamageEXT
},
2324 { "eglSwapBuffersWithDamageKHR", (_EGLProc
) eglSwapBuffersWithDamageKHR
},
2325 { "eglGetPlatformDisplayEXT", (_EGLProc
) eglGetPlatformDisplayEXT
},
2326 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc
) eglCreatePlatformWindowSurfaceEXT
},
2327 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc
) eglCreatePlatformPixmapSurfaceEXT
},
2328 { "eglGetSyncValuesCHROMIUM", (_EGLProc
) eglGetSyncValuesCHROMIUM
},
2329 { "eglExportDMABUFImageQueryMESA", (_EGLProc
) eglExportDMABUFImageQueryMESA
},
2330 { "eglExportDMABUFImageMESA", (_EGLProc
) eglExportDMABUFImageMESA
},
2331 { "eglLabelObjectKHR", (_EGLProc
) eglLabelObjectKHR
},
2332 { "eglDebugMessageControlKHR", (_EGLProc
) eglDebugMessageControlKHR
},
2333 { "eglQueryDebugKHR", (_EGLProc
) eglQueryDebugKHR
},
2340 RETURN_EGL_SUCCESS(NULL
, NULL
);
2342 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2345 if (strncmp(procname
, "egl", 3) == 0) {
2346 for (i
= 0; egl_functions
[i
].name
; i
++) {
2347 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
2348 ret
= egl_functions
[i
].function
;
2354 ret
= _eglGetDriverProc(procname
);
2356 RETURN_EGL_SUCCESS(NULL
, ret
);
2360 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2361 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2365 *disp
= _eglLockDisplay(dpy
);
2366 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2368 _eglUnlockDisplay(*disp
);
2369 return MESA_GLINTEROP_INVALID_DISPLAY
;
2372 *drv
= (*disp
)->Driver
;
2374 *ctx
= _eglLookupContext(context
, *disp
);
2376 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2377 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2378 _eglUnlockDisplay(*disp
);
2379 return MESA_GLINTEROP_INVALID_CONTEXT
;
2382 return MESA_GLINTEROP_SUCCESS
;
2386 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2387 struct mesa_glinterop_device_info
*out
)
2394 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2395 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2398 if (drv
->API
.GLInteropQueryDeviceInfo
)
2399 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2401 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2403 _eglUnlockDisplay(disp
);
2408 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2409 struct mesa_glinterop_export_in
*in
,
2410 struct mesa_glinterop_export_out
*out
)
2417 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2418 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2421 if (drv
->API
.GLInteropExportObject
)
2422 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2424 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2426 _eglUnlockDisplay(disp
);