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
,
397 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
400 return _eglGetDisplayHandle(dpy
);
403 static EGLDisplay EGLAPIENTRY
404 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
405 const EGLint
*attrib_list
)
407 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
408 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
411 EGLDisplay EGLAPIENTRY
412 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
413 const EGLAttrib
*attrib_list
)
418 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
420 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
421 if (attrib_list
&& !int_attribs
)
422 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
424 display
= _eglGetPlatformDisplayCommon(platform
, native_display
, int_attribs
);
430 * Copy the extension into the string and update the string pointer.
433 _eglAppendExtension(char **str
, const char *ext
)
436 size_t len
= strlen(ext
);
453 * Examine the individual extension enable/disable flags and recompute
454 * the driver's Extensions string.
457 _eglCreateExtensionsString(_EGLDisplay
*dpy
)
459 #define _EGL_CHECK_EXTENSION(ext) \
461 if (dpy->Extensions.ext) { \
462 _eglAppendExtension(&exts, "EGL_" #ext); \
463 assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
467 char *exts
= dpy
->ExtensionsString
;
469 /* Please keep these sorted alphabetically. */
470 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
471 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
472 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
474 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
476 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
477 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
478 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
479 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
481 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
482 _EGL_CHECK_EXTENSION(KHR_create_context
);
483 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
484 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
485 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
486 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
487 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
488 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
489 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
490 if (dpy
->Extensions
.KHR_image_base
&& dpy
->Extensions
.KHR_image_pixmap
)
491 _eglAppendExtension(&exts
, "EGL_KHR_image");
492 _EGL_CHECK_EXTENSION(KHR_image_base
);
493 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
494 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
495 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
496 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
497 if (dpy
->Extensions
.EXT_swap_buffers_with_damage
)
498 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
499 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
501 if (dpy
->Extensions
.KHR_no_config_context
)
502 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
503 _EGL_CHECK_EXTENSION(MESA_drm_image
);
504 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
506 _EGL_CHECK_EXTENSION(NOK_swap_region
);
507 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
509 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
511 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
512 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
514 #undef _EGL_CHECK_EXTENSION
518 _eglCreateAPIsString(_EGLDisplay
*dpy
)
520 if (dpy
->ClientAPIs
& EGL_OPENGL_BIT
)
521 strcat(dpy
->ClientAPIsString
, "OpenGL ");
523 if (dpy
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
524 dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
525 dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
526 strcat(dpy
->ClientAPIsString
, "OpenGL_ES ");
529 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
530 strcat(dpy
->ClientAPIsString
, "OpenVG ");
532 assert(strlen(dpy
->ClientAPIsString
) < sizeof(dpy
->ClientAPIsString
));
536 _eglComputeVersion(_EGLDisplay
*disp
)
540 if (disp
->Extensions
.KHR_fence_sync
&&
541 disp
->Extensions
.KHR_cl_event2
&&
542 disp
->Extensions
.KHR_wait_sync
&&
543 disp
->Extensions
.KHR_image_base
&&
544 disp
->Extensions
.KHR_gl_texture_2D_image
&&
545 disp
->Extensions
.KHR_gl_texture_3D_image
&&
546 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
547 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
548 disp
->Extensions
.KHR_create_context
&&
549 disp
->Extensions
.EXT_create_context_robustness
&&
550 disp
->Extensions
.KHR_get_all_proc_addresses
&&
551 disp
->Extensions
.KHR_gl_colorspace
&&
552 disp
->Extensions
.KHR_surfaceless_context
)
557 * This is typically the second EGL function that an application calls.
558 * Here we load/initialize the actual hardware driver.
560 EGLBoolean EGLAPIENTRY
561 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
563 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
565 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
568 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
570 if (!disp
->Initialized
) {
571 if (!_eglMatchDriver(disp
, EGL_FALSE
))
572 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
574 /* limit to APIs supported by core */
575 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
577 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
578 * classifies it as an EGL display extension, though conceptually it's an
579 * EGL client extension.
581 * From the EGL_KHR_get_all_proc_addresses spec:
583 * The EGL implementation must expose the name
584 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
585 * EGL_KHR_get_all_proc_addresses and supports
586 * EGL_EXT_client_extensions.
588 * Mesa unconditionally exposes both client extensions mentioned above,
589 * so the spec requires that each EGLDisplay unconditionally expose
590 * EGL_KHR_get_all_proc_addresses also.
592 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
594 _eglComputeVersion(disp
);
595 _eglCreateExtensionsString(disp
);
596 _eglCreateAPIsString(disp
);
597 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
598 "%d.%d (%s)", disp
->Version
/ 10, disp
->Version
% 10,
602 /* Update applications version of major and minor if not NULL */
603 if ((major
!= NULL
) && (minor
!= NULL
)) {
604 *major
= disp
->Version
/ 10;
605 *minor
= disp
->Version
% 10;
608 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
612 EGLBoolean EGLAPIENTRY
613 eglTerminate(EGLDisplay dpy
)
615 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
617 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
620 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
622 if (disp
->Initialized
) {
623 _EGLDriver
*drv
= disp
->Driver
;
625 drv
->API
.Terminate(drv
, disp
);
626 /* do not reset disp->Driver */
627 disp
->ClientAPIsString
[0] = 0;
628 disp
->Initialized
= EGL_FALSE
;
631 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
635 const char * EGLAPIENTRY
636 eglQueryString(EGLDisplay dpy
, EGLint name
)
641 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
642 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
645 disp
= _eglLockDisplay(dpy
);
646 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
647 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
651 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
653 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
655 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
656 case EGL_CLIENT_APIS
:
657 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
659 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
664 EGLBoolean EGLAPIENTRY
665 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
666 EGLint config_size
, EGLint
*num_config
)
668 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
672 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
674 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
675 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
677 RETURN_EGL_EVAL(disp
, ret
);
681 EGLBoolean EGLAPIENTRY
682 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
683 EGLint config_size
, EGLint
*num_config
)
685 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
689 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
691 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
692 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
693 config_size
, num_config
);
695 RETURN_EGL_EVAL(disp
, ret
);
699 EGLBoolean EGLAPIENTRY
700 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
701 EGLint attribute
, EGLint
*value
)
703 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
704 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
708 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
710 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
711 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
713 RETURN_EGL_EVAL(disp
, ret
);
717 EGLContext EGLAPIENTRY
718 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
719 const EGLint
*attrib_list
)
721 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
722 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
723 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
725 _EGLContext
*context
;
728 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
730 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
732 if (!config
&& !disp
->Extensions
.KHR_no_config_context
)
733 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
735 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
736 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
738 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
739 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
741 RETURN_EGL_EVAL(disp
, ret
);
745 EGLBoolean EGLAPIENTRY
746 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
748 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
749 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
753 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
755 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
756 _eglUnlinkContext(context
);
757 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
759 RETURN_EGL_EVAL(disp
, ret
);
763 EGLBoolean EGLAPIENTRY
764 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
767 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
768 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
769 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
770 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
774 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
777 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
780 /* display is allowed to be uninitialized under certain condition */
781 if (!disp
->Initialized
) {
782 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
783 ctx
!= EGL_NO_CONTEXT
)
784 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
787 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
789 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
790 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
791 if (!draw_surf
|| !read_surf
) {
792 /* From the EGL 1.4 (20130211) spec:
794 * To release the current context without assigning a new one, set ctx
795 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
797 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
798 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
800 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
801 (!read_surf
&& read
!= EGL_NO_SURFACE
))
802 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
803 if (draw_surf
|| read_surf
)
804 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
807 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
809 RETURN_EGL_EVAL(disp
, ret
);
813 EGLBoolean EGLAPIENTRY
814 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
815 EGLint attribute
, EGLint
*value
)
817 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
818 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
822 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
824 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
825 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
827 RETURN_EGL_EVAL(disp
, ret
);
832 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
833 void *native_window
, const EGLint
*attrib_list
)
835 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
840 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
842 if (native_window
== NULL
)
843 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
845 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
847 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
849 RETURN_EGL_EVAL(disp
, ret
);
853 EGLSurface EGLAPIENTRY
854 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
855 EGLNativeWindowType window
, const EGLint
*attrib_list
)
857 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
859 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
860 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
861 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
866 fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
868 #ifdef HAVE_X11_PLATFORM
869 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
870 /* The `native_window` parameter for the X11 platform differs between
871 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
872 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
873 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
874 * `Window*`. Convert `Window*` to `Window` because that's what
875 * dri2_x11_create_window_surface() expects.
877 return (void *)(* (Window
*) native_window
);
880 return native_window
;
883 static EGLSurface EGLAPIENTRY
884 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
886 const EGLint
*attrib_list
)
888 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
890 native_window
= fixupNativeWindow(disp
, native_window
);
892 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
893 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
898 EGLSurface EGLAPIENTRY
899 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
901 const EGLAttrib
*attrib_list
)
903 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
907 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
909 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
910 if (attrib_list
&& !int_attribs
)
911 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
913 native_window
= fixupNativeWindow(disp
, native_window
);
914 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
921 fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
923 #ifdef HAVE_X11_PLATFORM
924 /* The `native_pixmap` parameter for the X11 platform differs between
925 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
926 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
927 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
928 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
929 * dri2_x11_create_pixmap_surface() expects.
931 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
932 return (void *)(* (Pixmap
*) native_pixmap
);
934 return native_pixmap
;
938 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
939 void *native_pixmap
, const EGLint
*attrib_list
)
941 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
946 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
947 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
949 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
951 RETURN_EGL_EVAL(disp
, ret
);
955 EGLSurface EGLAPIENTRY
956 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
957 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
959 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
961 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
962 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
963 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
967 static EGLSurface EGLAPIENTRY
968 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
970 const EGLint
*attrib_list
)
972 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
974 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
975 native_pixmap
= fixupNativePixmap(disp
, native_pixmap
);
976 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
981 EGLSurface EGLAPIENTRY
982 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
984 const EGLAttrib
*attrib_list
)
986 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
990 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
992 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
993 if (attrib_list
&& !int_attribs
)
994 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
996 native_pixmap
= fixupNativePixmap(disp
, native_pixmap
);
997 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1004 EGLSurface EGLAPIENTRY
1005 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1006 const EGLint
*attrib_list
)
1008 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1009 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1014 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1015 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1017 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1018 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1020 RETURN_EGL_EVAL(disp
, ret
);
1024 EGLBoolean EGLAPIENTRY
1025 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1027 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1028 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1032 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1033 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1034 _eglUnlinkSurface(surf
);
1035 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1037 RETURN_EGL_EVAL(disp
, ret
);
1040 EGLBoolean EGLAPIENTRY
1041 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1042 EGLint attribute
, EGLint
*value
)
1044 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1045 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1049 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1050 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1051 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1053 RETURN_EGL_EVAL(disp
, ret
);
1056 EGLBoolean EGLAPIENTRY
1057 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1058 EGLint attribute
, EGLint value
)
1060 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1061 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1065 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1066 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1067 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1069 RETURN_EGL_EVAL(disp
, ret
);
1073 EGLBoolean EGLAPIENTRY
1074 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1076 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1077 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1081 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1082 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1083 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1085 RETURN_EGL_EVAL(disp
, ret
);
1089 EGLBoolean EGLAPIENTRY
1090 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1092 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1093 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1097 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1098 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1099 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1101 RETURN_EGL_EVAL(disp
, ret
);
1105 EGLBoolean EGLAPIENTRY
1106 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1108 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1109 _EGLContext
*ctx
= _eglGetCurrentContext();
1110 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1114 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1115 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1117 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1118 ctx
->Resource
.Display
!= disp
)
1119 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1121 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1122 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1124 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1126 RETURN_EGL_EVAL(disp
, ret
);
1130 EGLBoolean EGLAPIENTRY
1131 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1133 _EGLContext
*ctx
= _eglGetCurrentContext();
1134 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1135 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1139 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1140 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1142 /* surface must be bound to current context in EGL 1.4 */
1143 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1144 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1145 surf
!= ctx
->DrawSurface
)
1146 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1149 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1151 RETURN_EGL_EVAL(disp
, ret
);
1156 eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1157 EGLint
*rects
, EGLint n_rects
)
1159 _EGLContext
*ctx
= _eglGetCurrentContext();
1163 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1165 /* surface must be bound to current context in EGL 1.4 */
1166 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1167 surf
!= ctx
->DrawSurface
)
1168 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1170 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1171 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1173 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1175 RETURN_EGL_EVAL(disp
, ret
);
1178 static EGLBoolean EGLAPIENTRY
1179 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1180 EGLint
*rects
, EGLint n_rects
)
1182 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1183 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1184 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1185 return eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1188 static EGLBoolean EGLAPIENTRY
1189 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1190 EGLint
*rects
, EGLint n_rects
)
1192 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1193 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1194 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1195 return eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1198 EGLBoolean EGLAPIENTRY
1199 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1201 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1202 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1205 void *native_pixmap_ptr
;
1207 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1208 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1209 native_pixmap_ptr
= (void*) target
;
1211 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1212 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
1213 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
1214 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1216 RETURN_EGL_EVAL(disp
, ret
);
1221 _eglWaitClientCommon(void)
1223 _EGLContext
*ctx
= _eglGetCurrentContext();
1229 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1231 disp
= ctx
->Resource
.Display
;
1232 mtx_lock(&disp
->Mutex
);
1234 /* let bad current context imply bad current surface */
1235 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1236 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1237 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1239 /* a valid current context implies an initialized current display */
1240 assert(disp
->Initialized
);
1242 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1244 RETURN_EGL_EVAL(disp
, ret
);
1247 EGLBoolean EGLAPIENTRY
1250 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1251 return _eglWaitClientCommon();
1254 EGLBoolean EGLAPIENTRY
1257 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1258 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1259 return _eglWaitClientCommon();
1263 EGLBoolean EGLAPIENTRY
1264 eglWaitNative(EGLint engine
)
1266 _EGLContext
*ctx
= _eglGetCurrentContext();
1272 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1274 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1276 disp
= ctx
->Resource
.Display
;
1277 mtx_lock(&disp
->Mutex
);
1279 /* let bad current context imply bad current surface */
1280 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1281 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1282 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1284 /* a valid current context implies an initialized current display */
1285 assert(disp
->Initialized
);
1287 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1289 RETURN_EGL_EVAL(disp
, ret
);
1293 EGLDisplay EGLAPIENTRY
1294 eglGetCurrentDisplay(void)
1296 _EGLContext
*ctx
= _eglGetCurrentContext();
1299 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1301 RETURN_EGL_SUCCESS(NULL
, ret
);
1305 EGLContext EGLAPIENTRY
1306 eglGetCurrentContext(void)
1308 _EGLContext
*ctx
= _eglGetCurrentContext();
1311 ret
= _eglGetContextHandle(ctx
);
1313 RETURN_EGL_SUCCESS(NULL
, ret
);
1317 EGLSurface EGLAPIENTRY
1318 eglGetCurrentSurface(EGLint readdraw
)
1320 _EGLContext
*ctx
= _eglGetCurrentContext();
1321 EGLint err
= EGL_SUCCESS
;
1325 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1328 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1332 surf
= ctx
->DrawSurface
;
1335 surf
= ctx
->ReadSurface
;
1339 err
= EGL_BAD_PARAMETER
;
1343 ret
= _eglGetSurfaceHandle(surf
);
1345 RETURN_EGL_ERROR(NULL
, err
, ret
);
1352 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1353 EGLint e
= t
->LastError
;
1354 if (!_eglIsCurrentThreadDummy())
1355 t
->LastError
= EGL_SUCCESS
;
1365 * Specify the client API to use for subsequent calls including:
1366 * eglCreateContext()
1367 * eglGetCurrentContext()
1368 * eglGetCurrentDisplay()
1369 * eglGetCurrentSurface()
1370 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1373 * See section 3.7 "Rendering Context" in the EGL specification for details.
1375 EGLBoolean EGLAPIENTRY
1376 eglBindAPI(EGLenum api
)
1380 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1382 t
= _eglGetCurrentThread();
1383 if (_eglIsCurrentThreadDummy())
1384 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1386 if (!_eglIsApiValid(api
))
1387 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1389 t
->CurrentAPI
= api
;
1391 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1396 * Return the last value set with eglBindAPI().
1401 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1404 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1405 ret
= t
->CurrentAPI
;
1407 RETURN_EGL_SUCCESS(NULL
, ret
);
1411 EGLSurface EGLAPIENTRY
1412 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1413 EGLClientBuffer buffer
, EGLConfig config
,
1414 const EGLint
*attrib_list
)
1416 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1417 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1422 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1424 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1426 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1428 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1430 RETURN_EGL_EVAL(disp
, ret
);
1434 EGLBoolean EGLAPIENTRY
1435 eglReleaseThread(void)
1437 /* unbind current contexts */
1438 if (!_eglIsCurrentThreadDummy()) {
1439 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1440 _EGLContext
*ctx
= t
->CurrentContext
;
1442 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1445 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1448 mtx_lock(&disp
->Mutex
);
1450 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1451 mtx_unlock(&disp
->Mutex
);
1455 _eglDestroyCurrentThread();
1457 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1462 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1463 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1465 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1470 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1471 if (!disp
->Extensions
.KHR_image_base
)
1472 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1473 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1474 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1475 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1476 * <ctx> must be EGL_NO_CONTEXT..."
1478 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1479 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1481 img
= drv
->API
.CreateImageKHR(drv
,
1482 disp
, context
, target
, buffer
, attr_list
);
1483 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1485 RETURN_EGL_EVAL(disp
, ret
);
1488 static EGLImage EGLAPIENTRY
1489 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1490 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1492 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1493 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1494 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1498 EGLImage EGLAPIENTRY
1499 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1500 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1502 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1504 EGLint
*int_attribs
;
1506 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1508 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1509 if (attr_list
&& !int_attribs
)
1510 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1512 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1518 EGLBoolean EGLAPIENTRY
1519 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1521 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1522 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1526 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1528 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1529 if (!disp
->Extensions
.KHR_image_base
)
1530 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1532 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1534 _eglUnlinkImage(img
);
1535 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1537 RETURN_EGL_EVAL(disp
, ret
);
1542 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1543 EGLBoolean orig_is_EGLAttrib
,
1544 EGLenum invalid_type_error
)
1546 _EGLContext
*ctx
= _eglGetCurrentContext();
1551 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1553 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1554 /* There exist two EGLAttrib variants of eglCreateSync*:
1555 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1556 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1557 * support as a proxy for EGL 1.5 support, even though that's not
1558 * entirely correct (though _eglComputeVersion does the same).
1560 * The EGL spec provides no guidance on how to handle unsupported
1561 * functions. EGL_BAD_MATCH seems reasonable.
1563 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1566 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1567 if (!ctx
|| ctx
->Resource
.Display
!= disp
||
1568 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1569 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1572 case EGL_SYNC_FENCE_KHR
:
1573 if (!disp
->Extensions
.KHR_fence_sync
)
1574 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1576 case EGL_SYNC_REUSABLE_KHR
:
1577 if (!disp
->Extensions
.KHR_reusable_sync
)
1578 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1580 case EGL_SYNC_CL_EVENT_KHR
:
1581 if (!disp
->Extensions
.KHR_cl_event2
)
1582 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1585 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1588 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1589 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1591 RETURN_EGL_EVAL(disp
, ret
);
1595 static EGLSync EGLAPIENTRY
1596 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1598 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1599 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1602 EGLAttrib
*attrib_list
;
1605 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1606 attrib_list
= (EGLAttrib
*) int_list
;
1608 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1609 if (err
!= EGL_SUCCESS
)
1610 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1613 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1616 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1619 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1624 static EGLSync EGLAPIENTRY
1625 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1627 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1628 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1629 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1635 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1637 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1638 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1639 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1644 EGLBoolean EGLAPIENTRY
1645 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1647 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1648 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1652 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1654 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1655 assert(disp
->Extensions
.KHR_reusable_sync
||
1656 disp
->Extensions
.KHR_fence_sync
);
1659 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1661 RETURN_EGL_EVAL(disp
, ret
);
1666 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
, EGLTime timeout
)
1668 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1669 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1673 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1675 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1676 assert(disp
->Extensions
.KHR_reusable_sync
||
1677 disp
->Extensions
.KHR_fence_sync
);
1679 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1680 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1682 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1683 * unlocked here to allow other threads also to be able to
1684 * go into waiting state.
1687 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1688 _eglUnlockDisplay(dpy
);
1690 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1693 * 'disp' is already unlocked for reusable sync type,
1694 * so passing 'NULL' to bypass unlocking display.
1696 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1697 RETURN_EGL_EVAL(NULL
, ret
);
1699 RETURN_EGL_EVAL(disp
, ret
);
1704 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
1706 _EGLContext
*ctx
= _eglGetCurrentContext();
1710 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1711 assert(disp
->Extensions
.KHR_wait_sync
);
1713 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1714 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1715 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1717 /* the API doesn't allow any flags yet */
1719 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1721 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1723 RETURN_EGL_EVAL(disp
, ret
);
1726 static EGLint EGLAPIENTRY
1727 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1729 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1730 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1731 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1732 return _eglWaitSyncCommon(disp
, s
, flags
);
1736 EGLBoolean EGLAPIENTRY
1737 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1739 /* The KHR version returns EGLint, while the core version returns
1740 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1743 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1744 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1745 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1746 return _eglWaitSyncCommon(disp
, s
, flags
);
1750 static EGLBoolean EGLAPIENTRY
1751 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
1753 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1754 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1758 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1760 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1761 assert(disp
->Extensions
.KHR_reusable_sync
);
1762 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
1764 RETURN_EGL_EVAL(disp
, ret
);
1769 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
1774 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1775 assert(disp
->Extensions
.KHR_reusable_sync
||
1776 disp
->Extensions
.KHR_fence_sync
);
1777 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
1779 RETURN_EGL_EVAL(disp
, ret
);
1782 EGLBoolean EGLAPIENTRY
1783 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
1785 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1786 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1787 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1788 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
1792 static EGLBoolean EGLAPIENTRY
1793 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
1795 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1796 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1800 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1803 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1806 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
1808 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
1810 * If any error occurs, <*value> is not modified.
1812 if (result
== EGL_FALSE
)
1820 static EGLBoolean EGLAPIENTRY
1821 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
1822 EGLint numRects
, const EGLint
*rects
)
1824 _EGLContext
*ctx
= _eglGetCurrentContext();
1825 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1826 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1830 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1832 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1834 if (!disp
->Extensions
.NOK_swap_region
)
1835 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1837 /* surface must be bound to current context in EGL 1.4 */
1838 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1839 surf
!= ctx
->DrawSurface
)
1840 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1842 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
1844 RETURN_EGL_EVAL(disp
, ret
);
1848 static EGLImage EGLAPIENTRY
1849 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
1851 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1856 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1858 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1859 if (!disp
->Extensions
.MESA_drm_image
)
1860 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1862 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
1863 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1865 RETURN_EGL_EVAL(disp
, ret
);
1868 static EGLBoolean EGLAPIENTRY
1869 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
1870 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
1872 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1873 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1877 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1879 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1880 assert(disp
->Extensions
.MESA_drm_image
);
1883 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1885 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
1887 RETURN_EGL_EVAL(disp
, ret
);
1893 static EGLBoolean EGLAPIENTRY
1894 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1896 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1900 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1902 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1903 assert(disp
->Extensions
.WL_bind_wayland_display
);
1906 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1908 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
1910 RETURN_EGL_EVAL(disp
, ret
);
1913 static EGLBoolean EGLAPIENTRY
1914 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1916 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1920 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1922 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1923 assert(disp
->Extensions
.WL_bind_wayland_display
);
1926 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1928 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
1930 RETURN_EGL_EVAL(disp
, ret
);
1933 static EGLBoolean EGLAPIENTRY
1934 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
1935 EGLint attribute
, EGLint
*value
)
1937 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1941 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1943 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1944 assert(disp
->Extensions
.WL_bind_wayland_display
);
1947 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1949 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
1951 RETURN_EGL_EVAL(disp
, ret
);
1955 static struct wl_buffer
* EGLAPIENTRY
1956 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
1958 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1961 struct wl_buffer
*ret
;
1963 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1965 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
1966 assert(disp
->Extensions
.WL_create_wayland_buffer_from_image
);
1968 img
= _eglLookupImage(image
, disp
);
1971 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
1973 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
1975 RETURN_EGL_EVAL(disp
, ret
);
1978 static EGLBoolean EGLAPIENTRY
1979 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
1980 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
1982 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1983 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1987 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1989 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1991 if (!disp
->Extensions
.NV_post_sub_buffer
)
1992 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1994 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
1996 RETURN_EGL_EVAL(disp
, ret
);
1999 static EGLBoolean EGLAPIENTRY
2000 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
2001 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2004 _EGLDisplay
*disp
= _eglLockDisplay(display
);
2005 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2009 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2011 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2012 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2013 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2015 if (!ust
|| !msc
|| !sbc
)
2016 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2018 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2020 RETURN_EGL_EVAL(disp
, ret
);
2023 static EGLBoolean EGLAPIENTRY
2024 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2025 EGLint
*fourcc
, EGLint
*nplanes
,
2026 EGLuint64KHR
*modifiers
)
2028 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2029 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2033 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2035 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2036 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2039 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2041 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2044 RETURN_EGL_EVAL(disp
, ret
);
2047 static EGLBoolean EGLAPIENTRY
2048 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2049 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2051 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2052 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2056 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2058 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2059 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2062 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2064 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2066 RETURN_EGL_EVAL(disp
, ret
);
2069 static EGLint EGLAPIENTRY
2070 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2073 _EGLDisplay
*disp
= NULL
;
2074 _EGLResourceType type
;
2076 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2078 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2079 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2081 if (!_eglIsCurrentThreadDummy()) {
2086 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2089 disp
= _eglLockDisplay(dpy
);
2091 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2093 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2094 if (dpy
!= (EGLDisplay
) object
)
2095 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2097 disp
->Label
= label
;
2098 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2101 switch (objectType
) {
2102 case EGL_OBJECT_CONTEXT_KHR
:
2103 type
= _EGL_RESOURCE_CONTEXT
;
2105 case EGL_OBJECT_SURFACE_KHR
:
2106 type
= _EGL_RESOURCE_SURFACE
;
2108 case EGL_OBJECT_IMAGE_KHR
:
2109 type
= _EGL_RESOURCE_IMAGE
;
2111 case EGL_OBJECT_SYNC_KHR
:
2112 type
= _EGL_RESOURCE_SYNC
;
2114 case EGL_OBJECT_STREAM_KHR
:
2116 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2119 if (_eglCheckResource(object
, type
, disp
)) {
2120 _EGLResource
*res
= (_EGLResource
*) object
;
2123 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2126 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2130 validDebugMessageLevel(EGLAttrib level
)
2132 return (level
>= EGL_DEBUG_MSG_CRITICAL_KHR
&&
2133 level
<= EGL_DEBUG_MSG_INFO_KHR
);
2136 static EGLint EGLAPIENTRY
2137 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2138 const EGLAttrib
*attrib_list
)
2140 unsigned int newEnabled
;
2142 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2144 mtx_lock(_eglGlobal
.Mutex
);
2146 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2147 if (attrib_list
!= NULL
) {
2150 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2151 if (validDebugMessageLevel(attrib_list
[i
])) {
2152 if (attrib_list
[i
+ 1])
2153 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2155 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2159 // On error, set the last error code, call the current
2160 // debug callback, and return the error code.
2161 mtx_unlock(_eglGlobal
.Mutex
);
2162 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2163 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2164 return EGL_BAD_ATTRIBUTE
;
2168 if (callback
!= NULL
) {
2169 _eglGlobal
.debugCallback
= callback
;
2170 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2172 _eglGlobal
.debugCallback
= NULL
;
2173 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2176 mtx_unlock(_eglGlobal
.Mutex
);
2180 static EGLBoolean EGLAPIENTRY
2181 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2183 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2185 mtx_lock(_eglGlobal
.Mutex
);
2188 if (validDebugMessageLevel(attribute
)) {
2189 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2196 if (attribute
== EGL_DEBUG_CALLBACK_KHR
) {
2197 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2201 mtx_unlock(_eglGlobal
.Mutex
);
2202 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2203 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2207 mtx_unlock(_eglGlobal
.Mutex
);
2211 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2212 eglGetProcAddress(const char *procname
)
2214 static const struct {
2217 } egl_functions
[] = {
2218 /* core functions queryable in the presence of
2219 * EGL_KHR_get_all_proc_addresses or EGL 1.5
2221 /* alphabetical order */
2222 { "eglBindAPI", (_EGLProc
) eglBindAPI
},
2223 { "eglBindTexImage", (_EGLProc
) eglBindTexImage
},
2224 { "eglChooseConfig", (_EGLProc
) eglChooseConfig
},
2225 { "eglCopyBuffers", (_EGLProc
) eglCopyBuffers
},
2226 { "eglCreateContext", (_EGLProc
) eglCreateContext
},
2227 { "eglCreatePbufferFromClientBuffer", (_EGLProc
) eglCreatePbufferFromClientBuffer
},
2228 { "eglCreatePbufferSurface", (_EGLProc
) eglCreatePbufferSurface
},
2229 { "eglCreatePixmapSurface", (_EGLProc
) eglCreatePixmapSurface
},
2230 { "eglCreateWindowSurface", (_EGLProc
) eglCreateWindowSurface
},
2231 { "eglDestroyContext", (_EGLProc
) eglDestroyContext
},
2232 { "eglDestroySurface", (_EGLProc
) eglDestroySurface
},
2233 { "eglGetConfigAttrib", (_EGLProc
) eglGetConfigAttrib
},
2234 { "eglGetConfigs", (_EGLProc
) eglGetConfigs
},
2235 { "eglGetCurrentContext", (_EGLProc
) eglGetCurrentContext
},
2236 { "eglGetCurrentDisplay", (_EGLProc
) eglGetCurrentDisplay
},
2237 { "eglGetCurrentSurface", (_EGLProc
) eglGetCurrentSurface
},
2238 { "eglGetDisplay", (_EGLProc
) eglGetDisplay
},
2239 { "eglGetError", (_EGLProc
) eglGetError
},
2240 { "eglGetProcAddress", (_EGLProc
) eglGetProcAddress
},
2241 { "eglInitialize", (_EGLProc
) eglInitialize
},
2242 { "eglMakeCurrent", (_EGLProc
) eglMakeCurrent
},
2243 { "eglQueryAPI", (_EGLProc
) eglQueryAPI
},
2244 { "eglQueryContext", (_EGLProc
) eglQueryContext
},
2245 { "eglQueryString", (_EGLProc
) eglQueryString
},
2246 { "eglQuerySurface", (_EGLProc
) eglQuerySurface
},
2247 { "eglReleaseTexImage", (_EGLProc
) eglReleaseTexImage
},
2248 { "eglReleaseThread", (_EGLProc
) eglReleaseThread
},
2249 { "eglSurfaceAttrib", (_EGLProc
) eglSurfaceAttrib
},
2250 { "eglSwapBuffers", (_EGLProc
) eglSwapBuffers
},
2251 { "eglSwapInterval", (_EGLProc
) eglSwapInterval
},
2252 { "eglTerminate", (_EGLProc
) eglTerminate
},
2253 { "eglWaitClient", (_EGLProc
) eglWaitClient
},
2254 { "eglWaitGL", (_EGLProc
) eglWaitGL
},
2255 { "eglWaitNative", (_EGLProc
) eglWaitNative
},
2256 { "eglCreateSync", (_EGLProc
) eglCreateSync
},
2257 { "eglDestroySync", (_EGLProc
) eglDestroySync
},
2258 { "eglClientWaitSync", (_EGLProc
) eglClientWaitSync
},
2259 { "eglGetSyncAttrib", (_EGLProc
) eglGetSyncAttrib
},
2260 { "eglWaitSync", (_EGLProc
) eglWaitSync
},
2261 { "eglCreateImage", (_EGLProc
) eglCreateImage
},
2262 { "eglDestroyImage", (_EGLProc
) eglDestroyImage
},
2263 { "eglGetPlatformDisplay", (_EGLProc
) eglGetPlatformDisplay
},
2264 { "eglCreatePlatformWindowSurface", (_EGLProc
) eglCreatePlatformWindowSurface
},
2265 { "eglCreatePlatformPixmapSurface", (_EGLProc
) eglCreatePlatformPixmapSurface
},
2266 { "eglCreateImageKHR", (_EGLProc
) eglCreateImageKHR
},
2267 { "eglDestroyImageKHR", (_EGLProc
) eglDestroyImage
},
2268 { "eglCreateSyncKHR", (_EGLProc
) eglCreateSyncKHR
},
2269 { "eglCreateSync64KHR", (_EGLProc
) eglCreateSync64KHR
},
2270 { "eglDestroySyncKHR", (_EGLProc
) eglDestroySync
},
2271 { "eglClientWaitSyncKHR", (_EGLProc
) eglClientWaitSync
},
2272 { "eglWaitSyncKHR", (_EGLProc
) eglWaitSyncKHR
},
2273 { "eglSignalSyncKHR", (_EGLProc
) eglSignalSyncKHR
},
2274 { "eglGetSyncAttribKHR", (_EGLProc
) eglGetSyncAttribKHR
},
2275 { "eglSwapBuffersRegionNOK", (_EGLProc
) eglSwapBuffersRegionNOK
},
2276 { "eglCreateDRMImageMESA", (_EGLProc
) eglCreateDRMImageMESA
},
2277 { "eglExportDRMImageMESA", (_EGLProc
) eglExportDRMImageMESA
},
2278 { "eglBindWaylandDisplayWL", (_EGLProc
) eglBindWaylandDisplayWL
},
2279 { "eglUnbindWaylandDisplayWL", (_EGLProc
) eglUnbindWaylandDisplayWL
},
2280 { "eglQueryWaylandBufferWL", (_EGLProc
) eglQueryWaylandBufferWL
},
2281 { "eglCreateWaylandBufferFromImageWL", (_EGLProc
) eglCreateWaylandBufferFromImageWL
},
2282 { "eglPostSubBufferNV", (_EGLProc
) eglPostSubBufferNV
},
2283 { "eglSwapBuffersWithDamageEXT", (_EGLProc
) eglSwapBuffersWithDamageEXT
},
2284 { "eglSwapBuffersWithDamageKHR", (_EGLProc
) eglSwapBuffersWithDamageKHR
},
2285 { "eglGetPlatformDisplayEXT", (_EGLProc
) eglGetPlatformDisplayEXT
},
2286 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc
) eglCreatePlatformWindowSurfaceEXT
},
2287 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc
) eglCreatePlatformPixmapSurfaceEXT
},
2288 { "eglGetSyncValuesCHROMIUM", (_EGLProc
) eglGetSyncValuesCHROMIUM
},
2289 { "eglExportDMABUFImageQueryMESA", (_EGLProc
) eglExportDMABUFImageQueryMESA
},
2290 { "eglExportDMABUFImageMESA", (_EGLProc
) eglExportDMABUFImageMESA
},
2291 { "eglLabelObjectKHR", (_EGLProc
) eglLabelObjectKHR
},
2292 { "eglDebugMessageControlKHR", (_EGLProc
) eglDebugMessageControlKHR
},
2293 { "eglQueryDebugKHR", (_EGLProc
) eglQueryDebugKHR
},
2300 RETURN_EGL_SUCCESS(NULL
, NULL
);
2302 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2305 if (strncmp(procname
, "egl", 3) == 0) {
2306 for (i
= 0; egl_functions
[i
].name
; i
++) {
2307 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
2308 ret
= egl_functions
[i
].function
;
2314 ret
= _eglGetDriverProc(procname
);
2316 RETURN_EGL_SUCCESS(NULL
, ret
);
2320 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2321 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2325 *disp
= _eglLockDisplay(dpy
);
2326 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2328 _eglUnlockDisplay(*disp
);
2329 return MESA_GLINTEROP_INVALID_DISPLAY
;
2332 *drv
= (*disp
)->Driver
;
2334 *ctx
= _eglLookupContext(context
, *disp
);
2336 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2337 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2338 _eglUnlockDisplay(*disp
);
2339 return MESA_GLINTEROP_INVALID_CONTEXT
;
2342 return MESA_GLINTEROP_SUCCESS
;
2346 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2347 struct mesa_glinterop_device_info
*out
)
2354 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2355 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2358 if (drv
->API
.GLInteropQueryDeviceInfo
)
2359 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2361 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2363 _eglUnlockDisplay(disp
);
2368 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2369 struct mesa_glinterop_export_in
*in
,
2370 struct mesa_glinterop_export_out
*out
)
2377 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2378 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2381 if (drv
->API
.GLInteropExportObject
)
2382 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2384 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2386 _eglUnlockDisplay(disp
);