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_native_fence_sync
);
478 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
480 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
482 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
483 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
484 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
485 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
487 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
488 _EGL_CHECK_EXTENSION(KHR_create_context
);
489 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
490 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
491 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
492 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
493 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
494 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
495 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
496 if (dpy
->Extensions
.KHR_image_base
&& dpy
->Extensions
.KHR_image_pixmap
)
497 _eglAppendExtension(&exts
, "EGL_KHR_image");
498 _EGL_CHECK_EXTENSION(KHR_image_base
);
499 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
500 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
501 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
502 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
503 if (dpy
->Extensions
.EXT_swap_buffers_with_damage
)
504 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
505 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
507 if (dpy
->Extensions
.KHR_no_config_context
)
508 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
509 _EGL_CHECK_EXTENSION(MESA_drm_image
);
510 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
512 _EGL_CHECK_EXTENSION(NOK_swap_region
);
513 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
515 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
517 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
518 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
520 #undef _EGL_CHECK_EXTENSION
524 _eglCreateAPIsString(_EGLDisplay
*dpy
)
526 if (dpy
->ClientAPIs
& EGL_OPENGL_BIT
)
527 strcat(dpy
->ClientAPIsString
, "OpenGL ");
529 if (dpy
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
530 dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
531 dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
532 strcat(dpy
->ClientAPIsString
, "OpenGL_ES ");
535 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
536 strcat(dpy
->ClientAPIsString
, "OpenVG ");
538 assert(strlen(dpy
->ClientAPIsString
) < sizeof(dpy
->ClientAPIsString
));
542 _eglComputeVersion(_EGLDisplay
*disp
)
546 if (disp
->Extensions
.KHR_fence_sync
&&
547 disp
->Extensions
.KHR_cl_event2
&&
548 disp
->Extensions
.KHR_wait_sync
&&
549 disp
->Extensions
.KHR_image_base
&&
550 disp
->Extensions
.KHR_gl_texture_2D_image
&&
551 disp
->Extensions
.KHR_gl_texture_3D_image
&&
552 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
553 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
554 disp
->Extensions
.KHR_create_context
&&
555 disp
->Extensions
.EXT_create_context_robustness
&&
556 disp
->Extensions
.KHR_get_all_proc_addresses
&&
557 disp
->Extensions
.KHR_gl_colorspace
&&
558 disp
->Extensions
.KHR_surfaceless_context
)
563 * This is typically the second EGL function that an application calls.
564 * Here we load/initialize the actual hardware driver.
566 EGLBoolean EGLAPIENTRY
567 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
569 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
571 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
574 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
576 if (!disp
->Initialized
) {
577 if (!_eglMatchDriver(disp
, EGL_FALSE
))
578 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
580 /* limit to APIs supported by core */
581 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
583 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
584 * classifies it as an EGL display extension, though conceptually it's an
585 * EGL client extension.
587 * From the EGL_KHR_get_all_proc_addresses spec:
589 * The EGL implementation must expose the name
590 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
591 * EGL_KHR_get_all_proc_addresses and supports
592 * EGL_EXT_client_extensions.
594 * Mesa unconditionally exposes both client extensions mentioned above,
595 * so the spec requires that each EGLDisplay unconditionally expose
596 * EGL_KHR_get_all_proc_addresses also.
598 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
600 _eglComputeVersion(disp
);
601 _eglCreateExtensionsString(disp
);
602 _eglCreateAPIsString(disp
);
603 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
604 "%d.%d (%s)", disp
->Version
/ 10, disp
->Version
% 10,
608 /* Update applications version of major and minor if not NULL */
609 if ((major
!= NULL
) && (minor
!= NULL
)) {
610 *major
= disp
->Version
/ 10;
611 *minor
= disp
->Version
% 10;
614 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
618 EGLBoolean EGLAPIENTRY
619 eglTerminate(EGLDisplay dpy
)
621 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
623 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
626 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
628 if (disp
->Initialized
) {
629 _EGLDriver
*drv
= disp
->Driver
;
631 drv
->API
.Terminate(drv
, disp
);
632 /* do not reset disp->Driver */
633 disp
->ClientAPIsString
[0] = 0;
634 disp
->Initialized
= EGL_FALSE
;
637 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
641 const char * EGLAPIENTRY
642 eglQueryString(EGLDisplay dpy
, EGLint name
)
647 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
648 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
651 disp
= _eglLockDisplay(dpy
);
652 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
653 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
657 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
659 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
661 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
662 case EGL_CLIENT_APIS
:
663 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
665 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
670 EGLBoolean EGLAPIENTRY
671 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
672 EGLint config_size
, EGLint
*num_config
)
674 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
678 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
680 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
681 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
683 RETURN_EGL_EVAL(disp
, ret
);
687 EGLBoolean EGLAPIENTRY
688 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
689 EGLint config_size
, EGLint
*num_config
)
691 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
695 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
697 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
698 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
699 config_size
, num_config
);
701 RETURN_EGL_EVAL(disp
, ret
);
705 EGLBoolean EGLAPIENTRY
706 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
707 EGLint attribute
, EGLint
*value
)
709 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
710 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
714 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
716 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
717 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
719 RETURN_EGL_EVAL(disp
, ret
);
723 EGLContext EGLAPIENTRY
724 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
725 const EGLint
*attrib_list
)
727 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
728 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
729 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
731 _EGLContext
*context
;
734 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
736 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
738 if (config
!= EGL_NO_CONFIG_KHR
)
739 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
740 else if (!disp
->Extensions
.KHR_no_config_context
)
741 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
743 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
744 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
746 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
747 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
749 RETURN_EGL_EVAL(disp
, ret
);
753 EGLBoolean EGLAPIENTRY
754 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
756 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
757 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
761 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
763 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
764 _eglUnlinkContext(context
);
765 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
767 RETURN_EGL_EVAL(disp
, ret
);
771 EGLBoolean EGLAPIENTRY
772 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
775 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
776 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
777 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
778 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
782 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
785 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
788 /* display is allowed to be uninitialized under certain condition */
789 if (!disp
->Initialized
) {
790 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
791 ctx
!= EGL_NO_CONTEXT
)
792 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
795 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
797 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
798 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
799 if (!draw_surf
|| !read_surf
) {
800 /* From the EGL 1.4 (20130211) spec:
802 * To release the current context without assigning a new one, set ctx
803 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
805 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
806 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
808 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
809 (!read_surf
&& read
!= EGL_NO_SURFACE
))
810 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
811 if (draw_surf
|| read_surf
)
812 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
815 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
817 RETURN_EGL_EVAL(disp
, ret
);
821 EGLBoolean EGLAPIENTRY
822 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
823 EGLint attribute
, EGLint
*value
)
825 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
826 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
830 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
832 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
833 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
835 RETURN_EGL_EVAL(disp
, ret
);
840 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
841 void *native_window
, const EGLint
*attrib_list
)
843 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
849 if (native_window
== NULL
)
850 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
852 #ifdef HAVE_SURFACELESS_PLATFORM
853 if (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
854 /* From the EGL_MESA_platform_surfaceless spec (v1):
856 * eglCreatePlatformWindowSurface fails when called with a <display>
857 * that belongs to the surfaceless platform. It returns
858 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
859 * justification for this unconditional failure is that the
860 * surfaceless platform has no native windows, and therefore the
861 * <native_window> parameter is always invalid.
863 * This check must occur before checking the EGLConfig, which emits
866 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
870 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
872 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
874 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
876 RETURN_EGL_EVAL(disp
, ret
);
880 EGLSurface EGLAPIENTRY
881 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
882 EGLNativeWindowType window
, const EGLint
*attrib_list
)
884 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
886 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
887 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
888 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
893 fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
895 #ifdef HAVE_X11_PLATFORM
896 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
897 /* The `native_window` parameter for the X11 platform differs between
898 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
899 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
900 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
901 * `Window*`. Convert `Window*` to `Window` because that's what
902 * dri2_x11_create_window_surface() expects.
904 return (void *)(* (Window
*) native_window
);
907 return native_window
;
910 static EGLSurface EGLAPIENTRY
911 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
913 const EGLint
*attrib_list
)
915 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
917 native_window
= fixupNativeWindow(disp
, native_window
);
919 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
920 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
925 EGLSurface EGLAPIENTRY
926 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
928 const EGLAttrib
*attrib_list
)
930 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
934 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
936 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
937 if (attrib_list
&& !int_attribs
)
938 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
940 native_window
= fixupNativeWindow(disp
, native_window
);
941 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
948 fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
950 #ifdef HAVE_X11_PLATFORM
951 /* The `native_pixmap` parameter for the X11 platform differs between
952 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
953 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
954 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
955 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
956 * dri2_x11_create_pixmap_surface() expects.
958 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
959 return (void *)(* (Pixmap
*) native_pixmap
);
961 return native_pixmap
;
965 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
966 void *native_pixmap
, const EGLint
*attrib_list
)
968 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
973 #if HAVE_SURFACELESS_PLATFORM
974 if (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
975 /* From the EGL_MESA_platform_surfaceless spec (v1):
977 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
978 * also fails when called with a <display> that belongs to the
979 * surfaceless platform. It returns EGL_NO_SURFACE and generates
980 * EGL_BAD_NATIVE_PIXMAP.
982 * This check must occur before checking the EGLConfig, which emits
985 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
989 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
990 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
992 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
994 RETURN_EGL_EVAL(disp
, ret
);
998 EGLSurface EGLAPIENTRY
999 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1000 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1002 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1004 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1005 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1006 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1010 static EGLSurface EGLAPIENTRY
1011 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1012 void *native_pixmap
,
1013 const EGLint
*attrib_list
)
1015 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1017 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1018 native_pixmap
= fixupNativePixmap(disp
, native_pixmap
);
1019 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1024 EGLSurface EGLAPIENTRY
1025 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1026 void *native_pixmap
,
1027 const EGLAttrib
*attrib_list
)
1029 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1031 EGLint
*int_attribs
;
1033 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1035 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1036 if (attrib_list
&& !int_attribs
)
1037 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1039 native_pixmap
= fixupNativePixmap(disp
, native_pixmap
);
1040 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1047 EGLSurface EGLAPIENTRY
1048 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1049 const EGLint
*attrib_list
)
1051 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1052 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1057 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1058 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1060 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1061 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1063 RETURN_EGL_EVAL(disp
, ret
);
1067 EGLBoolean EGLAPIENTRY
1068 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1070 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1071 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1075 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1076 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1077 _eglUnlinkSurface(surf
);
1078 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1080 RETURN_EGL_EVAL(disp
, ret
);
1083 EGLBoolean EGLAPIENTRY
1084 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1085 EGLint attribute
, EGLint
*value
)
1087 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1088 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1092 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1093 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1094 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1096 RETURN_EGL_EVAL(disp
, ret
);
1099 EGLBoolean EGLAPIENTRY
1100 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1101 EGLint attribute
, EGLint value
)
1103 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1104 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1108 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1109 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1110 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1112 RETURN_EGL_EVAL(disp
, ret
);
1116 EGLBoolean EGLAPIENTRY
1117 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1119 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1120 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1124 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1125 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1126 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1128 RETURN_EGL_EVAL(disp
, ret
);
1132 EGLBoolean EGLAPIENTRY
1133 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1135 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1136 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1140 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1141 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1142 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1144 RETURN_EGL_EVAL(disp
, ret
);
1148 EGLBoolean EGLAPIENTRY
1149 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1151 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1152 _EGLContext
*ctx
= _eglGetCurrentContext();
1153 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1157 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1158 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1160 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1161 ctx
->Resource
.Display
!= disp
)
1162 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1164 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1165 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1167 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1169 RETURN_EGL_EVAL(disp
, ret
);
1173 EGLBoolean EGLAPIENTRY
1174 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1176 _EGLContext
*ctx
= _eglGetCurrentContext();
1177 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1178 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1182 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1183 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1185 /* surface must be bound to current context in EGL 1.4 */
1186 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1187 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1188 surf
!= ctx
->DrawSurface
)
1189 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1192 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1194 RETURN_EGL_EVAL(disp
, ret
);
1199 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1200 EGLint
*rects
, EGLint n_rects
)
1202 _EGLContext
*ctx
= _eglGetCurrentContext();
1206 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1208 /* surface must be bound to current context in EGL 1.4 */
1209 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1210 surf
!= ctx
->DrawSurface
)
1211 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1213 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1214 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1216 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1218 RETURN_EGL_EVAL(disp
, ret
);
1221 static EGLBoolean EGLAPIENTRY
1222 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1223 EGLint
*rects
, EGLint n_rects
)
1225 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1226 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1227 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1228 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1231 static EGLBoolean EGLAPIENTRY
1232 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1233 EGLint
*rects
, EGLint n_rects
)
1235 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1236 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1237 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1238 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1241 EGLBoolean EGLAPIENTRY
1242 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1244 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1245 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1248 void *native_pixmap_ptr
;
1250 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1251 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1252 native_pixmap_ptr
= (void*) target
;
1254 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1255 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
1256 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
1257 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1259 RETURN_EGL_EVAL(disp
, ret
);
1264 _eglWaitClientCommon(void)
1266 _EGLContext
*ctx
= _eglGetCurrentContext();
1272 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1274 disp
= ctx
->Resource
.Display
;
1275 mtx_lock(&disp
->Mutex
);
1277 /* let bad current context imply bad current surface */
1278 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1279 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1280 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1282 /* a valid current context implies an initialized current display */
1283 assert(disp
->Initialized
);
1285 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1287 RETURN_EGL_EVAL(disp
, ret
);
1290 EGLBoolean EGLAPIENTRY
1293 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1294 return _eglWaitClientCommon();
1297 EGLBoolean EGLAPIENTRY
1300 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1301 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1302 return _eglWaitClientCommon();
1306 EGLBoolean EGLAPIENTRY
1307 eglWaitNative(EGLint engine
)
1309 _EGLContext
*ctx
= _eglGetCurrentContext();
1315 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1317 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1319 disp
= ctx
->Resource
.Display
;
1320 mtx_lock(&disp
->Mutex
);
1322 /* let bad current context imply bad current surface */
1323 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1324 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1325 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1327 /* a valid current context implies an initialized current display */
1328 assert(disp
->Initialized
);
1330 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1332 RETURN_EGL_EVAL(disp
, ret
);
1336 EGLDisplay EGLAPIENTRY
1337 eglGetCurrentDisplay(void)
1339 _EGLContext
*ctx
= _eglGetCurrentContext();
1342 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1344 RETURN_EGL_SUCCESS(NULL
, ret
);
1348 EGLContext EGLAPIENTRY
1349 eglGetCurrentContext(void)
1351 _EGLContext
*ctx
= _eglGetCurrentContext();
1354 ret
= _eglGetContextHandle(ctx
);
1356 RETURN_EGL_SUCCESS(NULL
, ret
);
1360 EGLSurface EGLAPIENTRY
1361 eglGetCurrentSurface(EGLint readdraw
)
1363 _EGLContext
*ctx
= _eglGetCurrentContext();
1364 EGLint err
= EGL_SUCCESS
;
1368 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1371 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1375 surf
= ctx
->DrawSurface
;
1378 surf
= ctx
->ReadSurface
;
1382 err
= EGL_BAD_PARAMETER
;
1386 ret
= _eglGetSurfaceHandle(surf
);
1388 RETURN_EGL_ERROR(NULL
, err
, ret
);
1395 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1396 EGLint e
= t
->LastError
;
1397 if (!_eglIsCurrentThreadDummy())
1398 t
->LastError
= EGL_SUCCESS
;
1408 * Specify the client API to use for subsequent calls including:
1409 * eglCreateContext()
1410 * eglGetCurrentContext()
1411 * eglGetCurrentDisplay()
1412 * eglGetCurrentSurface()
1413 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1416 * See section 3.7 "Rendering Context" in the EGL specification for details.
1418 EGLBoolean EGLAPIENTRY
1419 eglBindAPI(EGLenum api
)
1423 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1425 t
= _eglGetCurrentThread();
1426 if (_eglIsCurrentThreadDummy())
1427 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1429 if (!_eglIsApiValid(api
))
1430 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1432 t
->CurrentAPI
= api
;
1434 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1439 * Return the last value set with eglBindAPI().
1444 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1447 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1448 ret
= t
->CurrentAPI
;
1450 RETURN_EGL_SUCCESS(NULL
, ret
);
1454 EGLSurface EGLAPIENTRY
1455 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1456 EGLClientBuffer buffer
, EGLConfig config
,
1457 const EGLint
*attrib_list
)
1459 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1460 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1465 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1467 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1469 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1471 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1473 RETURN_EGL_EVAL(disp
, ret
);
1477 EGLBoolean EGLAPIENTRY
1478 eglReleaseThread(void)
1480 /* unbind current contexts */
1481 if (!_eglIsCurrentThreadDummy()) {
1482 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1483 _EGLContext
*ctx
= t
->CurrentContext
;
1485 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1488 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1491 mtx_lock(&disp
->Mutex
);
1493 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1494 mtx_unlock(&disp
->Mutex
);
1498 _eglDestroyCurrentThread();
1500 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1505 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1506 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1508 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1513 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1514 if (!disp
->Extensions
.KHR_image_base
)
1515 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1516 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1517 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1518 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1519 * <ctx> must be EGL_NO_CONTEXT..."
1521 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1522 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1524 img
= drv
->API
.CreateImageKHR(drv
,
1525 disp
, context
, target
, buffer
, attr_list
);
1526 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1528 RETURN_EGL_EVAL(disp
, ret
);
1531 static EGLImage EGLAPIENTRY
1532 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1533 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1535 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1536 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1537 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1541 EGLImage EGLAPIENTRY
1542 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1543 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1545 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1547 EGLint
*int_attribs
;
1549 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1551 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1552 if (attr_list
&& !int_attribs
)
1553 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1555 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1561 EGLBoolean EGLAPIENTRY
1562 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1564 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1565 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1569 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1571 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1572 if (!disp
->Extensions
.KHR_image_base
)
1573 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1575 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1577 _eglUnlinkImage(img
);
1578 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1580 RETURN_EGL_EVAL(disp
, ret
);
1585 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1586 EGLBoolean orig_is_EGLAttrib
,
1587 EGLenum invalid_type_error
)
1589 _EGLContext
*ctx
= _eglGetCurrentContext();
1594 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1596 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1597 /* There exist two EGLAttrib variants of eglCreateSync*:
1598 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1599 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1600 * support as a proxy for EGL 1.5 support, even though that's not
1601 * entirely correct (though _eglComputeVersion does the same).
1603 * The EGL spec provides no guidance on how to handle unsupported
1604 * functions. EGL_BAD_MATCH seems reasonable.
1606 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1609 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1610 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1611 * error is generated.
1614 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1615 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1617 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1618 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1619 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1620 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1623 case EGL_SYNC_FENCE_KHR
:
1624 if (!disp
->Extensions
.KHR_fence_sync
)
1625 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1627 case EGL_SYNC_REUSABLE_KHR
:
1628 if (!disp
->Extensions
.KHR_reusable_sync
)
1629 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1631 case EGL_SYNC_CL_EVENT_KHR
:
1632 if (!disp
->Extensions
.KHR_cl_event2
)
1633 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1635 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1636 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1637 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1640 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1643 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1644 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1646 RETURN_EGL_EVAL(disp
, ret
);
1650 static EGLSync EGLAPIENTRY
1651 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1653 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1654 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1657 EGLAttrib
*attrib_list
;
1660 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1661 attrib_list
= (EGLAttrib
*) int_list
;
1663 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1664 if (err
!= EGL_SUCCESS
)
1665 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1668 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1671 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1674 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1679 static EGLSync EGLAPIENTRY
1680 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1682 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1683 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1684 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1690 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1692 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1693 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1694 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1699 EGLBoolean EGLAPIENTRY
1700 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1702 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1703 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1707 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1709 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1710 assert(disp
->Extensions
.KHR_reusable_sync
||
1711 disp
->Extensions
.KHR_fence_sync
||
1712 disp
->Extensions
.ANDROID_native_fence_sync
);
1715 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1717 RETURN_EGL_EVAL(disp
, ret
);
1722 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
, EGLTime timeout
)
1724 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1725 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1729 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1731 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1732 assert(disp
->Extensions
.KHR_reusable_sync
||
1733 disp
->Extensions
.KHR_fence_sync
||
1734 disp
->Extensions
.ANDROID_native_fence_sync
);
1736 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1737 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1739 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1740 * unlocked here to allow other threads also to be able to
1741 * go into waiting state.
1744 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1745 _eglUnlockDisplay(dpy
);
1747 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1750 * 'disp' is already unlocked for reusable sync type,
1751 * so passing 'NULL' to bypass unlocking display.
1753 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1754 RETURN_EGL_EVAL(NULL
, ret
);
1756 RETURN_EGL_EVAL(disp
, ret
);
1761 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
1763 _EGLContext
*ctx
= _eglGetCurrentContext();
1767 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1768 assert(disp
->Extensions
.KHR_wait_sync
);
1770 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1771 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1772 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1774 /* the API doesn't allow any flags yet */
1776 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1778 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1780 RETURN_EGL_EVAL(disp
, ret
);
1783 static EGLint EGLAPIENTRY
1784 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1786 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1787 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1788 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1789 return _eglWaitSyncCommon(disp
, s
, flags
);
1793 EGLBoolean EGLAPIENTRY
1794 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1796 /* The KHR version returns EGLint, while the core version returns
1797 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1800 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1801 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1802 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1803 return _eglWaitSyncCommon(disp
, s
, flags
);
1807 static EGLBoolean EGLAPIENTRY
1808 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
1810 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1811 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1815 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1817 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1818 assert(disp
->Extensions
.KHR_reusable_sync
);
1819 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
1821 RETURN_EGL_EVAL(disp
, ret
);
1826 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
1831 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1832 assert(disp
->Extensions
.KHR_reusable_sync
||
1833 disp
->Extensions
.KHR_fence_sync
||
1834 disp
->Extensions
.ANDROID_native_fence_sync
);
1835 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
1837 RETURN_EGL_EVAL(disp
, ret
);
1840 EGLBoolean EGLAPIENTRY
1841 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
1843 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1844 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1845 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1846 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
1850 static EGLBoolean EGLAPIENTRY
1851 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
1853 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1854 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1858 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1861 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1864 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
1866 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
1868 * If any error occurs, <*value> is not modified.
1870 if (result
== EGL_FALSE
)
1877 static EGLint EGLAPIENTRY
1878 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
1880 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1881 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1885 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1887 /* the spec doesn't seem to specify what happens if the fence
1888 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
1891 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
1892 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
1894 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
1895 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
1896 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
1898 RETURN_EGL_EVAL(disp
, ret
);
1901 static EGLBoolean EGLAPIENTRY
1902 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
1903 EGLint numRects
, const EGLint
*rects
)
1905 _EGLContext
*ctx
= _eglGetCurrentContext();
1906 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1907 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1911 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1913 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1915 if (!disp
->Extensions
.NOK_swap_region
)
1916 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1918 /* surface must be bound to current context in EGL 1.4 */
1919 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1920 surf
!= ctx
->DrawSurface
)
1921 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1923 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
1925 RETURN_EGL_EVAL(disp
, ret
);
1929 static EGLImage EGLAPIENTRY
1930 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
1932 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1937 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1939 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1940 if (!disp
->Extensions
.MESA_drm_image
)
1941 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1943 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
1944 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1946 RETURN_EGL_EVAL(disp
, ret
);
1949 static EGLBoolean EGLAPIENTRY
1950 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
1951 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
1953 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1954 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1958 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1960 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1961 assert(disp
->Extensions
.MESA_drm_image
);
1964 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1966 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
1968 RETURN_EGL_EVAL(disp
, ret
);
1974 static EGLBoolean EGLAPIENTRY
1975 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
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
.BindWaylandDisplayWL(drv
, disp
, display
);
1991 RETURN_EGL_EVAL(disp
, ret
);
1994 static EGLBoolean EGLAPIENTRY
1995 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1997 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2001 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2003 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2004 assert(disp
->Extensions
.WL_bind_wayland_display
);
2007 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2009 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2011 RETURN_EGL_EVAL(disp
, ret
);
2014 static EGLBoolean EGLAPIENTRY
2015 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2016 EGLint attribute
, EGLint
*value
)
2018 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2022 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2024 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2025 assert(disp
->Extensions
.WL_bind_wayland_display
);
2028 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2030 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2032 RETURN_EGL_EVAL(disp
, ret
);
2036 static struct wl_buffer
* EGLAPIENTRY
2037 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2039 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2042 struct wl_buffer
*ret
;
2044 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2046 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2047 assert(disp
->Extensions
.WL_create_wayland_buffer_from_image
);
2049 img
= _eglLookupImage(image
, disp
);
2052 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2054 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2056 RETURN_EGL_EVAL(disp
, ret
);
2059 static EGLBoolean EGLAPIENTRY
2060 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2061 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2063 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2064 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2068 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2070 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2072 if (!disp
->Extensions
.NV_post_sub_buffer
)
2073 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2075 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2077 RETURN_EGL_EVAL(disp
, ret
);
2080 static EGLBoolean EGLAPIENTRY
2081 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
2082 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2085 _EGLDisplay
*disp
= _eglLockDisplay(display
);
2086 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2090 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2092 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2093 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2094 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2096 if (!ust
|| !msc
|| !sbc
)
2097 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2099 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2101 RETURN_EGL_EVAL(disp
, ret
);
2104 static EGLBoolean EGLAPIENTRY
2105 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2106 EGLint
*fourcc
, EGLint
*nplanes
,
2107 EGLuint64KHR
*modifiers
)
2109 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2110 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2114 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2116 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2117 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2120 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2122 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2125 RETURN_EGL_EVAL(disp
, ret
);
2128 static EGLBoolean EGLAPIENTRY
2129 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2130 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2132 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2133 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2137 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2139 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2140 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2143 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2145 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2147 RETURN_EGL_EVAL(disp
, ret
);
2150 static EGLint EGLAPIENTRY
2151 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2154 _EGLDisplay
*disp
= NULL
;
2155 _EGLResourceType type
;
2157 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2159 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2160 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2162 if (!_eglIsCurrentThreadDummy()) {
2167 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2170 disp
= _eglLockDisplay(dpy
);
2172 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2174 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2175 if (dpy
!= (EGLDisplay
) object
)
2176 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2178 disp
->Label
= label
;
2179 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2182 switch (objectType
) {
2183 case EGL_OBJECT_CONTEXT_KHR
:
2184 type
= _EGL_RESOURCE_CONTEXT
;
2186 case EGL_OBJECT_SURFACE_KHR
:
2187 type
= _EGL_RESOURCE_SURFACE
;
2189 case EGL_OBJECT_IMAGE_KHR
:
2190 type
= _EGL_RESOURCE_IMAGE
;
2192 case EGL_OBJECT_SYNC_KHR
:
2193 type
= _EGL_RESOURCE_SYNC
;
2195 case EGL_OBJECT_STREAM_KHR
:
2197 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2200 if (_eglCheckResource(object
, type
, disp
)) {
2201 _EGLResource
*res
= (_EGLResource
*) object
;
2204 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2207 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2211 validDebugMessageLevel(EGLAttrib level
)
2213 return (level
>= EGL_DEBUG_MSG_CRITICAL_KHR
&&
2214 level
<= EGL_DEBUG_MSG_INFO_KHR
);
2217 static EGLint EGLAPIENTRY
2218 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2219 const EGLAttrib
*attrib_list
)
2221 unsigned int newEnabled
;
2223 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2225 mtx_lock(_eglGlobal
.Mutex
);
2227 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2228 if (attrib_list
!= NULL
) {
2231 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2232 if (validDebugMessageLevel(attrib_list
[i
])) {
2233 if (attrib_list
[i
+ 1])
2234 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2236 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2240 // On error, set the last error code, call the current
2241 // debug callback, and return the error code.
2242 mtx_unlock(_eglGlobal
.Mutex
);
2243 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2244 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2245 return EGL_BAD_ATTRIBUTE
;
2249 if (callback
!= NULL
) {
2250 _eglGlobal
.debugCallback
= callback
;
2251 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2253 _eglGlobal
.debugCallback
= NULL
;
2254 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2257 mtx_unlock(_eglGlobal
.Mutex
);
2261 static EGLBoolean EGLAPIENTRY
2262 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2264 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2266 mtx_lock(_eglGlobal
.Mutex
);
2269 if (validDebugMessageLevel(attribute
)) {
2270 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2277 if (attribute
== EGL_DEBUG_CALLBACK_KHR
) {
2278 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2282 mtx_unlock(_eglGlobal
.Mutex
);
2283 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2284 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2288 mtx_unlock(_eglGlobal
.Mutex
);
2292 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2293 eglGetProcAddress(const char *procname
)
2295 static const struct {
2298 } egl_functions
[] = {
2299 /* core functions queryable in the presence of
2300 * EGL_KHR_get_all_proc_addresses or EGL 1.5
2302 /* alphabetical order */
2303 { "eglBindAPI", (_EGLProc
) eglBindAPI
},
2304 { "eglBindTexImage", (_EGLProc
) eglBindTexImage
},
2305 { "eglChooseConfig", (_EGLProc
) eglChooseConfig
},
2306 { "eglCopyBuffers", (_EGLProc
) eglCopyBuffers
},
2307 { "eglCreateContext", (_EGLProc
) eglCreateContext
},
2308 { "eglCreatePbufferFromClientBuffer", (_EGLProc
) eglCreatePbufferFromClientBuffer
},
2309 { "eglCreatePbufferSurface", (_EGLProc
) eglCreatePbufferSurface
},
2310 { "eglCreatePixmapSurface", (_EGLProc
) eglCreatePixmapSurface
},
2311 { "eglCreateWindowSurface", (_EGLProc
) eglCreateWindowSurface
},
2312 { "eglDestroyContext", (_EGLProc
) eglDestroyContext
},
2313 { "eglDestroySurface", (_EGLProc
) eglDestroySurface
},
2314 { "eglGetConfigAttrib", (_EGLProc
) eglGetConfigAttrib
},
2315 { "eglGetConfigs", (_EGLProc
) eglGetConfigs
},
2316 { "eglGetCurrentContext", (_EGLProc
) eglGetCurrentContext
},
2317 { "eglGetCurrentDisplay", (_EGLProc
) eglGetCurrentDisplay
},
2318 { "eglGetCurrentSurface", (_EGLProc
) eglGetCurrentSurface
},
2319 { "eglGetDisplay", (_EGLProc
) eglGetDisplay
},
2320 { "eglGetError", (_EGLProc
) eglGetError
},
2321 { "eglGetProcAddress", (_EGLProc
) eglGetProcAddress
},
2322 { "eglInitialize", (_EGLProc
) eglInitialize
},
2323 { "eglMakeCurrent", (_EGLProc
) eglMakeCurrent
},
2324 { "eglQueryAPI", (_EGLProc
) eglQueryAPI
},
2325 { "eglQueryContext", (_EGLProc
) eglQueryContext
},
2326 { "eglQueryString", (_EGLProc
) eglQueryString
},
2327 { "eglQuerySurface", (_EGLProc
) eglQuerySurface
},
2328 { "eglReleaseTexImage", (_EGLProc
) eglReleaseTexImage
},
2329 { "eglReleaseThread", (_EGLProc
) eglReleaseThread
},
2330 { "eglSurfaceAttrib", (_EGLProc
) eglSurfaceAttrib
},
2331 { "eglSwapBuffers", (_EGLProc
) eglSwapBuffers
},
2332 { "eglSwapInterval", (_EGLProc
) eglSwapInterval
},
2333 { "eglTerminate", (_EGLProc
) eglTerminate
},
2334 { "eglWaitClient", (_EGLProc
) eglWaitClient
},
2335 { "eglWaitGL", (_EGLProc
) eglWaitGL
},
2336 { "eglWaitNative", (_EGLProc
) eglWaitNative
},
2337 { "eglCreateSync", (_EGLProc
) eglCreateSync
},
2338 { "eglDestroySync", (_EGLProc
) eglDestroySync
},
2339 { "eglClientWaitSync", (_EGLProc
) eglClientWaitSync
},
2340 { "eglGetSyncAttrib", (_EGLProc
) eglGetSyncAttrib
},
2341 { "eglWaitSync", (_EGLProc
) eglWaitSync
},
2342 { "eglCreateImage", (_EGLProc
) eglCreateImage
},
2343 { "eglDestroyImage", (_EGLProc
) eglDestroyImage
},
2344 { "eglGetPlatformDisplay", (_EGLProc
) eglGetPlatformDisplay
},
2345 { "eglCreatePlatformWindowSurface", (_EGLProc
) eglCreatePlatformWindowSurface
},
2346 { "eglCreatePlatformPixmapSurface", (_EGLProc
) eglCreatePlatformPixmapSurface
},
2347 { "eglCreateImageKHR", (_EGLProc
) eglCreateImageKHR
},
2348 { "eglDestroyImageKHR", (_EGLProc
) eglDestroyImage
},
2349 { "eglCreateSyncKHR", (_EGLProc
) eglCreateSyncKHR
},
2350 { "eglCreateSync64KHR", (_EGLProc
) eglCreateSync64KHR
},
2351 { "eglDestroySyncKHR", (_EGLProc
) eglDestroySync
},
2352 { "eglClientWaitSyncKHR", (_EGLProc
) eglClientWaitSync
},
2353 { "eglWaitSyncKHR", (_EGLProc
) eglWaitSyncKHR
},
2354 { "eglSignalSyncKHR", (_EGLProc
) eglSignalSyncKHR
},
2355 { "eglGetSyncAttribKHR", (_EGLProc
) eglGetSyncAttribKHR
},
2356 { "eglSwapBuffersRegionNOK", (_EGLProc
) eglSwapBuffersRegionNOK
},
2357 { "eglCreateDRMImageMESA", (_EGLProc
) eglCreateDRMImageMESA
},
2358 { "eglExportDRMImageMESA", (_EGLProc
) eglExportDRMImageMESA
},
2359 { "eglBindWaylandDisplayWL", (_EGLProc
) eglBindWaylandDisplayWL
},
2360 { "eglUnbindWaylandDisplayWL", (_EGLProc
) eglUnbindWaylandDisplayWL
},
2361 { "eglQueryWaylandBufferWL", (_EGLProc
) eglQueryWaylandBufferWL
},
2362 { "eglCreateWaylandBufferFromImageWL", (_EGLProc
) eglCreateWaylandBufferFromImageWL
},
2363 { "eglPostSubBufferNV", (_EGLProc
) eglPostSubBufferNV
},
2364 { "eglSwapBuffersWithDamageEXT", (_EGLProc
) eglSwapBuffersWithDamageEXT
},
2365 { "eglSwapBuffersWithDamageKHR", (_EGLProc
) eglSwapBuffersWithDamageKHR
},
2366 { "eglGetPlatformDisplayEXT", (_EGLProc
) eglGetPlatformDisplayEXT
},
2367 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc
) eglCreatePlatformWindowSurfaceEXT
},
2368 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc
) eglCreatePlatformPixmapSurfaceEXT
},
2369 { "eglGetSyncValuesCHROMIUM", (_EGLProc
) eglGetSyncValuesCHROMIUM
},
2370 { "eglExportDMABUFImageQueryMESA", (_EGLProc
) eglExportDMABUFImageQueryMESA
},
2371 { "eglExportDMABUFImageMESA", (_EGLProc
) eglExportDMABUFImageMESA
},
2372 { "eglLabelObjectKHR", (_EGLProc
) eglLabelObjectKHR
},
2373 { "eglDebugMessageControlKHR", (_EGLProc
) eglDebugMessageControlKHR
},
2374 { "eglQueryDebugKHR", (_EGLProc
) eglQueryDebugKHR
},
2375 { "eglDupNativeFenceFDANDROID", (_EGLProc
) eglDupNativeFenceFDANDROID
},
2382 RETURN_EGL_SUCCESS(NULL
, NULL
);
2384 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2387 if (strncmp(procname
, "egl", 3) == 0) {
2388 for (i
= 0; egl_functions
[i
].name
; i
++) {
2389 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
2390 ret
= egl_functions
[i
].function
;
2396 ret
= _eglGetDriverProc(procname
);
2398 RETURN_EGL_SUCCESS(NULL
, ret
);
2402 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2403 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2407 *disp
= _eglLockDisplay(dpy
);
2408 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2410 _eglUnlockDisplay(*disp
);
2411 return MESA_GLINTEROP_INVALID_DISPLAY
;
2414 *drv
= (*disp
)->Driver
;
2416 *ctx
= _eglLookupContext(context
, *disp
);
2418 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2419 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2420 _eglUnlockDisplay(*disp
);
2421 return MESA_GLINTEROP_INVALID_CONTEXT
;
2424 return MESA_GLINTEROP_SUCCESS
;
2428 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2429 struct mesa_glinterop_device_info
*out
)
2436 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2437 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2440 if (drv
->API
.GLInteropQueryDeviceInfo
)
2441 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2443 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2445 _eglUnlockDisplay(disp
);
2450 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2451 struct mesa_glinterop_export_in
*in
,
2452 struct mesa_glinterop_export_out
*out
)
2459 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2460 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2463 if (drv
->API
.GLInteropExportObject
)
2464 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2466 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2468 _eglUnlockDisplay(disp
);