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_config_attribs
);
489 _EGL_CHECK_EXTENSION(KHR_create_context
);
490 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
491 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
492 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
493 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
494 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
495 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
496 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
497 if (dpy
->Extensions
.KHR_image_base
&& dpy
->Extensions
.KHR_image_pixmap
)
498 _eglAppendExtension(&exts
, "EGL_KHR_image");
499 _EGL_CHECK_EXTENSION(KHR_image_base
);
500 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
501 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
502 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
503 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
504 if (dpy
->Extensions
.EXT_swap_buffers_with_damage
)
505 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
506 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
508 if (dpy
->Extensions
.KHR_no_config_context
)
509 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
510 _EGL_CHECK_EXTENSION(MESA_drm_image
);
511 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
513 _EGL_CHECK_EXTENSION(NOK_swap_region
);
514 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
516 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
518 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
519 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
521 #undef _EGL_CHECK_EXTENSION
525 _eglCreateAPIsString(_EGLDisplay
*dpy
)
527 if (dpy
->ClientAPIs
& EGL_OPENGL_BIT
)
528 strcat(dpy
->ClientAPIsString
, "OpenGL ");
530 if (dpy
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
531 dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
532 dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
533 strcat(dpy
->ClientAPIsString
, "OpenGL_ES ");
536 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
537 strcat(dpy
->ClientAPIsString
, "OpenVG ");
539 assert(strlen(dpy
->ClientAPIsString
) < sizeof(dpy
->ClientAPIsString
));
543 _eglComputeVersion(_EGLDisplay
*disp
)
547 if (disp
->Extensions
.KHR_fence_sync
&&
548 disp
->Extensions
.KHR_cl_event2
&&
549 disp
->Extensions
.KHR_wait_sync
&&
550 disp
->Extensions
.KHR_image_base
&&
551 disp
->Extensions
.KHR_gl_texture_2D_image
&&
552 disp
->Extensions
.KHR_gl_texture_3D_image
&&
553 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
554 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
555 disp
->Extensions
.KHR_create_context
&&
556 disp
->Extensions
.EXT_create_context_robustness
&&
557 disp
->Extensions
.KHR_get_all_proc_addresses
&&
558 disp
->Extensions
.KHR_gl_colorspace
&&
559 disp
->Extensions
.KHR_surfaceless_context
)
564 * This is typically the second EGL function that an application calls.
565 * Here we load/initialize the actual hardware driver.
567 EGLBoolean EGLAPIENTRY
568 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
570 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
572 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
575 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
577 if (!disp
->Initialized
) {
578 if (!_eglMatchDriver(disp
, EGL_FALSE
))
579 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
581 /* limit to APIs supported by core */
582 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
584 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
585 * classifies it as an EGL display extension, though conceptually it's an
586 * EGL client extension.
588 * From the EGL_KHR_get_all_proc_addresses spec:
590 * The EGL implementation must expose the name
591 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
592 * EGL_KHR_get_all_proc_addresses and supports
593 * EGL_EXT_client_extensions.
595 * Mesa unconditionally exposes both client extensions mentioned above,
596 * so the spec requires that each EGLDisplay unconditionally expose
597 * EGL_KHR_get_all_proc_addresses also.
599 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
601 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
602 * programs. It is driver agnostic and handled in the main EGL code.
604 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
606 _eglComputeVersion(disp
);
607 _eglCreateExtensionsString(disp
);
608 _eglCreateAPIsString(disp
);
609 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
610 "%d.%d (%s)", disp
->Version
/ 10, disp
->Version
% 10,
614 /* Update applications version of major and minor if not NULL */
615 if ((major
!= NULL
) && (minor
!= NULL
)) {
616 *major
= disp
->Version
/ 10;
617 *minor
= disp
->Version
% 10;
620 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
624 EGLBoolean EGLAPIENTRY
625 eglTerminate(EGLDisplay dpy
)
627 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
629 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
632 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
634 if (disp
->Initialized
) {
635 _EGLDriver
*drv
= disp
->Driver
;
637 drv
->API
.Terminate(drv
, disp
);
638 /* do not reset disp->Driver */
639 disp
->ClientAPIsString
[0] = 0;
640 disp
->Initialized
= EGL_FALSE
;
643 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
647 const char * EGLAPIENTRY
648 eglQueryString(EGLDisplay dpy
, EGLint name
)
653 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
654 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
657 disp
= _eglLockDisplay(dpy
);
658 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
659 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
663 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
665 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
667 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
668 case EGL_CLIENT_APIS
:
669 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
671 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
676 EGLBoolean EGLAPIENTRY
677 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
678 EGLint config_size
, EGLint
*num_config
)
680 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
684 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
686 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
687 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
689 RETURN_EGL_EVAL(disp
, ret
);
693 EGLBoolean EGLAPIENTRY
694 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
695 EGLint config_size
, EGLint
*num_config
)
697 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
701 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
703 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
704 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
705 config_size
, num_config
);
707 RETURN_EGL_EVAL(disp
, ret
);
711 EGLBoolean EGLAPIENTRY
712 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
713 EGLint attribute
, EGLint
*value
)
715 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
716 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
720 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
722 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
723 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
725 RETURN_EGL_EVAL(disp
, ret
);
729 EGLContext EGLAPIENTRY
730 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
731 const EGLint
*attrib_list
)
733 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
734 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
735 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
737 _EGLContext
*context
;
740 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
742 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
744 if (config
!= EGL_NO_CONFIG_KHR
)
745 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
746 else if (!disp
->Extensions
.KHR_no_config_context
)
747 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
749 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
750 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
752 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
753 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
755 RETURN_EGL_EVAL(disp
, ret
);
759 EGLBoolean EGLAPIENTRY
760 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
762 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
763 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
767 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
769 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
770 _eglUnlinkContext(context
);
771 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
773 RETURN_EGL_EVAL(disp
, ret
);
777 EGLBoolean EGLAPIENTRY
778 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
781 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
782 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
783 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
784 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
788 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
791 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
794 /* display is allowed to be uninitialized under certain condition */
795 if (!disp
->Initialized
) {
796 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
797 ctx
!= EGL_NO_CONTEXT
)
798 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
801 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
803 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
804 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
805 if (!draw_surf
|| !read_surf
) {
806 /* From the EGL 1.4 (20130211) spec:
808 * To release the current context without assigning a new one, set ctx
809 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
811 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
812 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
814 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
815 (!read_surf
&& read
!= EGL_NO_SURFACE
))
816 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
817 if (draw_surf
|| read_surf
)
818 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
821 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
823 RETURN_EGL_EVAL(disp
, ret
);
827 EGLBoolean EGLAPIENTRY
828 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
829 EGLint attribute
, EGLint
*value
)
831 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
832 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
836 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
838 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
839 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
841 RETURN_EGL_EVAL(disp
, ret
);
846 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
847 void *native_window
, const EGLint
*attrib_list
)
849 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
855 if (native_window
== NULL
)
856 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
858 #ifdef HAVE_SURFACELESS_PLATFORM
859 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
860 /* From the EGL_MESA_platform_surfaceless spec (v1):
862 * eglCreatePlatformWindowSurface fails when called with a <display>
863 * that belongs to the surfaceless platform. It returns
864 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
865 * justification for this unconditional failure is that the
866 * surfaceless platform has no native windows, and therefore the
867 * <native_window> parameter is always invalid.
869 * This check must occur before checking the EGLConfig, which emits
872 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
876 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
878 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
879 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
881 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
883 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
885 RETURN_EGL_EVAL(disp
, ret
);
889 EGLSurface EGLAPIENTRY
890 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
891 EGLNativeWindowType window
, const EGLint
*attrib_list
)
893 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
895 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
896 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
897 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
902 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
904 #ifdef HAVE_X11_PLATFORM
905 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
906 /* The `native_window` parameter for the X11 platform differs between
907 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
908 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
909 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
910 * `Window*`. Convert `Window*` to `Window` because that's what
911 * dri2_x11_create_window_surface() expects.
913 return (void *)(* (Window
*) native_window
);
916 return native_window
;
919 static EGLSurface EGLAPIENTRY
920 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
922 const EGLint
*attrib_list
)
924 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
926 native_window
= _fixupNativeWindow(disp
, native_window
);
928 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
929 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
934 EGLSurface EGLAPIENTRY
935 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
937 const EGLAttrib
*attrib_list
)
939 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
943 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
945 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
946 if (attrib_list
&& !int_attribs
)
947 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
949 native_window
= _fixupNativeWindow(disp
, native_window
);
950 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
957 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
959 #ifdef HAVE_X11_PLATFORM
960 /* The `native_pixmap` parameter for the X11 platform differs between
961 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
962 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
963 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
964 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
965 * dri2_x11_create_pixmap_surface() expects.
967 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
968 return (void *)(* (Pixmap
*) native_pixmap
);
970 return native_pixmap
;
974 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
975 void *native_pixmap
, const EGLint
*attrib_list
)
977 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
982 #if HAVE_SURFACELESS_PLATFORM
983 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
984 /* From the EGL_MESA_platform_surfaceless spec (v1):
986 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
987 * also fails when called with a <display> that belongs to the
988 * surfaceless platform. It returns EGL_NO_SURFACE and generates
989 * EGL_BAD_NATIVE_PIXMAP.
991 * This check must occur before checking the EGLConfig, which emits
994 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
998 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1000 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1001 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1003 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1005 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1007 RETURN_EGL_EVAL(disp
, ret
);
1011 EGLSurface EGLAPIENTRY
1012 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1013 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1015 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1017 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1018 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1019 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1023 static EGLSurface EGLAPIENTRY
1024 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1025 void *native_pixmap
,
1026 const EGLint
*attrib_list
)
1028 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1030 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1031 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1032 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1037 EGLSurface EGLAPIENTRY
1038 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1039 void *native_pixmap
,
1040 const EGLAttrib
*attrib_list
)
1042 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1044 EGLint
*int_attribs
;
1046 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1048 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1049 if (attrib_list
&& !int_attribs
)
1050 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1052 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1053 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1060 EGLSurface EGLAPIENTRY
1061 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1062 const EGLint
*attrib_list
)
1064 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1065 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1070 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1071 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1073 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1074 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1076 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1077 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1079 RETURN_EGL_EVAL(disp
, ret
);
1083 EGLBoolean EGLAPIENTRY
1084 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1086 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1087 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1091 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1092 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1093 _eglUnlinkSurface(surf
);
1094 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1096 RETURN_EGL_EVAL(disp
, ret
);
1099 EGLBoolean EGLAPIENTRY
1100 eglQuerySurface(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
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1112 RETURN_EGL_EVAL(disp
, ret
);
1115 EGLBoolean EGLAPIENTRY
1116 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1117 EGLint attribute
, EGLint value
)
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
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1128 RETURN_EGL_EVAL(disp
, ret
);
1132 EGLBoolean EGLAPIENTRY
1133 eglBindTexImage(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
.BindTexImage(drv
, disp
, surf
, buffer
);
1144 RETURN_EGL_EVAL(disp
, ret
);
1148 EGLBoolean EGLAPIENTRY
1149 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1151 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1152 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1156 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1157 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1158 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1160 RETURN_EGL_EVAL(disp
, ret
);
1164 EGLBoolean EGLAPIENTRY
1165 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1167 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1168 _EGLContext
*ctx
= _eglGetCurrentContext();
1169 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1173 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1174 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1176 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1177 ctx
->Resource
.Display
!= disp
)
1178 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1180 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1181 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1183 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1185 RETURN_EGL_EVAL(disp
, ret
);
1189 EGLBoolean EGLAPIENTRY
1190 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1192 _EGLContext
*ctx
= _eglGetCurrentContext();
1193 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1194 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1198 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1199 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1201 /* surface must be bound to current context in EGL 1.4 */
1202 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1203 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1204 surf
!= ctx
->DrawSurface
)
1205 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1208 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1210 RETURN_EGL_EVAL(disp
, ret
);
1215 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1216 EGLint
*rects
, EGLint n_rects
)
1218 _EGLContext
*ctx
= _eglGetCurrentContext();
1222 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1224 /* surface must be bound to current context in EGL 1.4 */
1225 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1226 surf
!= ctx
->DrawSurface
)
1227 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1229 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1230 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1232 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1234 RETURN_EGL_EVAL(disp
, ret
);
1237 static EGLBoolean EGLAPIENTRY
1238 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1239 EGLint
*rects
, EGLint n_rects
)
1241 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1242 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1243 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1244 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1247 static EGLBoolean EGLAPIENTRY
1248 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1249 EGLint
*rects
, EGLint n_rects
)
1251 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1252 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1253 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1254 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1257 EGLBoolean EGLAPIENTRY
1258 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1260 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1261 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1264 void *native_pixmap_ptr
;
1266 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1267 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1268 native_pixmap_ptr
= (void*) target
;
1270 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1271 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
1272 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
1273 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1275 RETURN_EGL_EVAL(disp
, ret
);
1280 _eglWaitClientCommon(void)
1282 _EGLContext
*ctx
= _eglGetCurrentContext();
1288 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1290 disp
= ctx
->Resource
.Display
;
1291 mtx_lock(&disp
->Mutex
);
1293 /* let bad current context imply bad current surface */
1294 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1295 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1296 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1298 /* a valid current context implies an initialized current display */
1299 assert(disp
->Initialized
);
1301 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1303 RETURN_EGL_EVAL(disp
, ret
);
1306 EGLBoolean EGLAPIENTRY
1309 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1310 return _eglWaitClientCommon();
1313 EGLBoolean EGLAPIENTRY
1316 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1317 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1318 return _eglWaitClientCommon();
1322 EGLBoolean EGLAPIENTRY
1323 eglWaitNative(EGLint engine
)
1325 _EGLContext
*ctx
= _eglGetCurrentContext();
1331 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1333 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1335 disp
= ctx
->Resource
.Display
;
1336 mtx_lock(&disp
->Mutex
);
1338 /* let bad current context imply bad current surface */
1339 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1340 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1341 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1343 /* a valid current context implies an initialized current display */
1344 assert(disp
->Initialized
);
1346 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1348 RETURN_EGL_EVAL(disp
, ret
);
1352 EGLDisplay EGLAPIENTRY
1353 eglGetCurrentDisplay(void)
1355 _EGLContext
*ctx
= _eglGetCurrentContext();
1358 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1360 RETURN_EGL_SUCCESS(NULL
, ret
);
1364 EGLContext EGLAPIENTRY
1365 eglGetCurrentContext(void)
1367 _EGLContext
*ctx
= _eglGetCurrentContext();
1370 ret
= _eglGetContextHandle(ctx
);
1372 RETURN_EGL_SUCCESS(NULL
, ret
);
1376 EGLSurface EGLAPIENTRY
1377 eglGetCurrentSurface(EGLint readdraw
)
1379 _EGLContext
*ctx
= _eglGetCurrentContext();
1380 EGLint err
= EGL_SUCCESS
;
1384 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1387 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1391 surf
= ctx
->DrawSurface
;
1394 surf
= ctx
->ReadSurface
;
1398 err
= EGL_BAD_PARAMETER
;
1402 ret
= _eglGetSurfaceHandle(surf
);
1404 RETURN_EGL_ERROR(NULL
, err
, ret
);
1411 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1412 EGLint e
= t
->LastError
;
1413 if (!_eglIsCurrentThreadDummy())
1414 t
->LastError
= EGL_SUCCESS
;
1424 * Specify the client API to use for subsequent calls including:
1425 * eglCreateContext()
1426 * eglGetCurrentContext()
1427 * eglGetCurrentDisplay()
1428 * eglGetCurrentSurface()
1429 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1432 * See section 3.7 "Rendering Context" in the EGL specification for details.
1434 EGLBoolean EGLAPIENTRY
1435 eglBindAPI(EGLenum api
)
1439 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1441 t
= _eglGetCurrentThread();
1442 if (_eglIsCurrentThreadDummy())
1443 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1445 if (!_eglIsApiValid(api
))
1446 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1448 t
->CurrentAPI
= api
;
1450 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1455 * Return the last value set with eglBindAPI().
1460 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1463 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1464 ret
= t
->CurrentAPI
;
1466 RETURN_EGL_SUCCESS(NULL
, ret
);
1470 EGLSurface EGLAPIENTRY
1471 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1472 EGLClientBuffer buffer
, EGLConfig config
,
1473 const EGLint
*attrib_list
)
1475 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1476 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1481 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1483 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1485 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1487 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1489 RETURN_EGL_EVAL(disp
, ret
);
1493 EGLBoolean EGLAPIENTRY
1494 eglReleaseThread(void)
1496 /* unbind current contexts */
1497 if (!_eglIsCurrentThreadDummy()) {
1498 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1499 _EGLContext
*ctx
= t
->CurrentContext
;
1501 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1504 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1507 mtx_lock(&disp
->Mutex
);
1509 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1510 mtx_unlock(&disp
->Mutex
);
1514 _eglDestroyCurrentThread();
1516 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1521 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1522 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1524 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1529 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1530 if (!disp
->Extensions
.KHR_image_base
)
1531 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1532 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1533 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1534 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1535 * <ctx> must be EGL_NO_CONTEXT..."
1537 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1538 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1540 img
= drv
->API
.CreateImageKHR(drv
,
1541 disp
, context
, target
, buffer
, attr_list
);
1542 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1544 RETURN_EGL_EVAL(disp
, ret
);
1547 static EGLImage EGLAPIENTRY
1548 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1549 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1551 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1552 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1553 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1557 EGLImage EGLAPIENTRY
1558 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1559 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1561 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1563 EGLint
*int_attribs
;
1565 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1567 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1568 if (attr_list
&& !int_attribs
)
1569 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1571 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1578 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1583 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1584 if (!disp
->Extensions
.KHR_image_base
)
1585 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1587 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1589 _eglUnlinkImage(img
);
1590 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1592 RETURN_EGL_EVAL(disp
, ret
);
1595 EGLBoolean EGLAPIENTRY
1596 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1598 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1599 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1600 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1601 return _eglDestroyImageCommon(disp
, img
);
1604 static EGLBoolean EGLAPIENTRY
1605 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1607 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1608 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1609 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1610 return _eglDestroyImageCommon(disp
, img
);
1615 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1616 EGLBoolean orig_is_EGLAttrib
,
1617 EGLenum invalid_type_error
)
1619 _EGLContext
*ctx
= _eglGetCurrentContext();
1624 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1626 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1627 /* There exist two EGLAttrib variants of eglCreateSync*:
1628 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1629 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1630 * support as a proxy for EGL 1.5 support, even though that's not
1631 * entirely correct (though _eglComputeVersion does the same).
1633 * The EGL spec provides no guidance on how to handle unsupported
1634 * functions. EGL_BAD_MATCH seems reasonable.
1636 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1639 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1640 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1641 * error is generated.
1644 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1645 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1647 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1648 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1649 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1650 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1653 case EGL_SYNC_FENCE_KHR
:
1654 if (!disp
->Extensions
.KHR_fence_sync
)
1655 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1657 case EGL_SYNC_REUSABLE_KHR
:
1658 if (!disp
->Extensions
.KHR_reusable_sync
)
1659 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1661 case EGL_SYNC_CL_EVENT_KHR
:
1662 if (!disp
->Extensions
.KHR_cl_event2
)
1663 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1665 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1666 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1667 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1670 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1673 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1674 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1676 RETURN_EGL_EVAL(disp
, ret
);
1680 static EGLSync EGLAPIENTRY
1681 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1683 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1684 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1687 EGLAttrib
*attrib_list
;
1690 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1691 attrib_list
= (EGLAttrib
*) int_list
;
1693 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1694 if (err
!= EGL_SUCCESS
)
1695 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1698 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1701 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1704 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1709 static EGLSync EGLAPIENTRY
1710 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1712 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1713 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1714 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1720 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1722 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1723 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1724 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1730 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1735 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1736 assert(disp
->Extensions
.KHR_reusable_sync
||
1737 disp
->Extensions
.KHR_fence_sync
||
1738 disp
->Extensions
.ANDROID_native_fence_sync
);
1741 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1743 RETURN_EGL_EVAL(disp
, ret
);
1746 EGLBoolean EGLAPIENTRY
1747 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1749 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1750 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1751 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1752 return _eglDestroySync(disp
, s
);
1755 static EGLBoolean EGLAPIENTRY
1756 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1758 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1759 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1760 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1761 return _eglDestroySync(disp
, s
);
1766 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1767 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1772 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1773 assert(disp
->Extensions
.KHR_reusable_sync
||
1774 disp
->Extensions
.KHR_fence_sync
||
1775 disp
->Extensions
.ANDROID_native_fence_sync
);
1777 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1778 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1780 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1781 * unlocked here to allow other threads also to be able to
1782 * go into waiting state.
1785 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1786 _eglUnlockDisplay(dpy
);
1788 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1791 * 'disp' is already unlocked for reusable sync type,
1792 * so passing 'NULL' to bypass unlocking display.
1794 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1795 RETURN_EGL_EVAL(NULL
, ret
);
1797 RETURN_EGL_EVAL(disp
, ret
);
1801 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
1802 EGLint flags
, EGLTime timeout
)
1804 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1805 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1806 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1807 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1810 static EGLint EGLAPIENTRY
1811 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
1812 EGLint flags
, EGLTime timeout
)
1814 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1815 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1816 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1817 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1822 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
1824 _EGLContext
*ctx
= _eglGetCurrentContext();
1828 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1829 assert(disp
->Extensions
.KHR_wait_sync
);
1831 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1832 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1833 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1835 /* the API doesn't allow any flags yet */
1837 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1839 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1841 RETURN_EGL_EVAL(disp
, ret
);
1844 static EGLint EGLAPIENTRY
1845 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1847 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1848 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1849 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1850 return _eglWaitSyncCommon(disp
, s
, flags
);
1854 EGLBoolean EGLAPIENTRY
1855 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1857 /* The KHR version returns EGLint, while the core version returns
1858 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1861 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1862 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1863 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1864 return _eglWaitSyncCommon(disp
, s
, flags
);
1868 static EGLBoolean EGLAPIENTRY
1869 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
1871 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1872 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1876 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1878 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1879 assert(disp
->Extensions
.KHR_reusable_sync
);
1880 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
1882 RETURN_EGL_EVAL(disp
, ret
);
1887 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
1892 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1893 assert(disp
->Extensions
.KHR_reusable_sync
||
1894 disp
->Extensions
.KHR_fence_sync
||
1895 disp
->Extensions
.ANDROID_native_fence_sync
);
1896 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
1898 RETURN_EGL_EVAL(disp
, ret
);
1901 EGLBoolean EGLAPIENTRY
1902 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
1904 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1905 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1906 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1907 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
1911 static EGLBoolean EGLAPIENTRY
1912 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
1914 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1915 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1919 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1922 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1925 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
1927 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
1929 * If any error occurs, <*value> is not modified.
1931 if (result
== EGL_FALSE
)
1938 static EGLint EGLAPIENTRY
1939 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
1941 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1942 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1946 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1948 /* the spec doesn't seem to specify what happens if the fence
1949 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
1952 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
1953 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
1955 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
1956 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
1957 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
1959 RETURN_EGL_EVAL(disp
, ret
);
1962 static EGLBoolean EGLAPIENTRY
1963 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
1964 EGLint numRects
, const EGLint
*rects
)
1966 _EGLContext
*ctx
= _eglGetCurrentContext();
1967 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1968 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1972 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1974 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1976 if (!disp
->Extensions
.NOK_swap_region
)
1977 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1979 /* surface must be bound to current context in EGL 1.4 */
1980 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1981 surf
!= ctx
->DrawSurface
)
1982 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1984 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
1986 RETURN_EGL_EVAL(disp
, ret
);
1990 static EGLImage EGLAPIENTRY
1991 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
1993 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1998 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2000 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2001 if (!disp
->Extensions
.MESA_drm_image
)
2002 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2004 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2005 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2007 RETURN_EGL_EVAL(disp
, ret
);
2010 static EGLBoolean EGLAPIENTRY
2011 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2012 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2014 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2015 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2019 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2021 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2022 assert(disp
->Extensions
.MESA_drm_image
);
2025 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2027 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2029 RETURN_EGL_EVAL(disp
, ret
);
2035 static EGLBoolean EGLAPIENTRY
2036 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2038 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2042 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2044 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2045 assert(disp
->Extensions
.WL_bind_wayland_display
);
2048 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2050 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2052 RETURN_EGL_EVAL(disp
, ret
);
2055 static EGLBoolean EGLAPIENTRY
2056 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2058 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2062 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2064 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2065 assert(disp
->Extensions
.WL_bind_wayland_display
);
2068 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2070 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2072 RETURN_EGL_EVAL(disp
, ret
);
2075 static EGLBoolean EGLAPIENTRY
2076 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2077 EGLint attribute
, EGLint
*value
)
2079 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2083 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2085 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2086 assert(disp
->Extensions
.WL_bind_wayland_display
);
2089 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2091 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2093 RETURN_EGL_EVAL(disp
, ret
);
2097 static struct wl_buffer
* EGLAPIENTRY
2098 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2100 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2103 struct wl_buffer
*ret
;
2105 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2107 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2108 assert(disp
->Extensions
.WL_create_wayland_buffer_from_image
);
2110 img
= _eglLookupImage(image
, disp
);
2113 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2115 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2117 RETURN_EGL_EVAL(disp
, ret
);
2120 static EGLBoolean EGLAPIENTRY
2121 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2122 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2124 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2125 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2129 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2131 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2133 if (!disp
->Extensions
.NV_post_sub_buffer
)
2134 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2136 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2138 RETURN_EGL_EVAL(disp
, ret
);
2141 static EGLBoolean EGLAPIENTRY
2142 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
2143 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2146 _EGLDisplay
*disp
= _eglLockDisplay(display
);
2147 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2151 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2153 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2154 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2155 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2157 if (!ust
|| !msc
|| !sbc
)
2158 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2160 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2162 RETURN_EGL_EVAL(disp
, ret
);
2165 static EGLBoolean EGLAPIENTRY
2166 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2167 EGLint
*fourcc
, EGLint
*nplanes
,
2168 EGLuint64KHR
*modifiers
)
2170 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2171 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2175 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2177 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2178 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2181 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2183 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2186 RETURN_EGL_EVAL(disp
, ret
);
2189 static EGLBoolean EGLAPIENTRY
2190 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2191 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2193 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2194 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2198 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2200 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2201 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2204 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2206 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2208 RETURN_EGL_EVAL(disp
, ret
);
2211 static EGLint EGLAPIENTRY
2212 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2215 _EGLDisplay
*disp
= NULL
;
2216 _EGLResourceType type
;
2218 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2220 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2221 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2223 if (!_eglIsCurrentThreadDummy()) {
2228 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2231 disp
= _eglLockDisplay(dpy
);
2233 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2235 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2236 if (dpy
!= (EGLDisplay
) object
)
2237 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2239 disp
->Label
= label
;
2240 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2243 switch (objectType
) {
2244 case EGL_OBJECT_CONTEXT_KHR
:
2245 type
= _EGL_RESOURCE_CONTEXT
;
2247 case EGL_OBJECT_SURFACE_KHR
:
2248 type
= _EGL_RESOURCE_SURFACE
;
2250 case EGL_OBJECT_IMAGE_KHR
:
2251 type
= _EGL_RESOURCE_IMAGE
;
2253 case EGL_OBJECT_SYNC_KHR
:
2254 type
= _EGL_RESOURCE_SYNC
;
2256 case EGL_OBJECT_STREAM_KHR
:
2258 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2261 if (_eglCheckResource(object
, type
, disp
)) {
2262 _EGLResource
*res
= (_EGLResource
*) object
;
2265 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2268 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2272 _validDebugMessageLevel(EGLAttrib level
)
2274 return (level
>= EGL_DEBUG_MSG_CRITICAL_KHR
&&
2275 level
<= EGL_DEBUG_MSG_INFO_KHR
);
2278 static EGLint EGLAPIENTRY
2279 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2280 const EGLAttrib
*attrib_list
)
2282 unsigned int newEnabled
;
2284 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2286 mtx_lock(_eglGlobal
.Mutex
);
2288 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2289 if (attrib_list
!= NULL
) {
2292 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2293 if (_validDebugMessageLevel(attrib_list
[i
])) {
2294 if (attrib_list
[i
+ 1])
2295 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2297 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2301 // On error, set the last error code, call the current
2302 // debug callback, and return the error code.
2303 mtx_unlock(_eglGlobal
.Mutex
);
2304 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2305 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2306 return EGL_BAD_ATTRIBUTE
;
2310 if (callback
!= NULL
) {
2311 _eglGlobal
.debugCallback
= callback
;
2312 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2314 _eglGlobal
.debugCallback
= NULL
;
2315 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2318 mtx_unlock(_eglGlobal
.Mutex
);
2322 static EGLBoolean EGLAPIENTRY
2323 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2325 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2327 mtx_lock(_eglGlobal
.Mutex
);
2330 if (_validDebugMessageLevel(attribute
)) {
2331 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2338 if (attribute
== EGL_DEBUG_CALLBACK_KHR
) {
2339 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2343 mtx_unlock(_eglGlobal
.Mutex
);
2344 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2345 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2349 mtx_unlock(_eglGlobal
.Mutex
);
2353 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2354 eglGetProcAddress(const char *procname
)
2356 static const struct {
2359 } egl_functions
[] = {
2360 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2361 /* core functions queryable in the presence of
2362 * EGL_KHR_get_all_proc_addresses or EGL 1.5
2364 /* alphabetical order */
2365 EGL_ENTRYPOINT(eglBindAPI
)
2366 EGL_ENTRYPOINT(eglBindTexImage
)
2367 EGL_ENTRYPOINT(eglChooseConfig
)
2368 EGL_ENTRYPOINT(eglCopyBuffers
)
2369 EGL_ENTRYPOINT(eglCreateContext
)
2370 EGL_ENTRYPOINT(eglCreatePbufferFromClientBuffer
)
2371 EGL_ENTRYPOINT(eglCreatePbufferSurface
)
2372 EGL_ENTRYPOINT(eglCreatePixmapSurface
)
2373 EGL_ENTRYPOINT(eglCreateWindowSurface
)
2374 EGL_ENTRYPOINT(eglDestroyContext
)
2375 EGL_ENTRYPOINT(eglDestroySurface
)
2376 EGL_ENTRYPOINT(eglGetConfigAttrib
)
2377 EGL_ENTRYPOINT(eglGetConfigs
)
2378 EGL_ENTRYPOINT(eglGetCurrentContext
)
2379 EGL_ENTRYPOINT(eglGetCurrentDisplay
)
2380 EGL_ENTRYPOINT(eglGetCurrentSurface
)
2381 EGL_ENTRYPOINT(eglGetDisplay
)
2382 EGL_ENTRYPOINT(eglGetError
)
2383 EGL_ENTRYPOINT(eglGetProcAddress
)
2384 EGL_ENTRYPOINT(eglInitialize
)
2385 EGL_ENTRYPOINT(eglMakeCurrent
)
2386 EGL_ENTRYPOINT(eglQueryAPI
)
2387 EGL_ENTRYPOINT(eglQueryContext
)
2388 EGL_ENTRYPOINT(eglQueryString
)
2389 EGL_ENTRYPOINT(eglQuerySurface
)
2390 EGL_ENTRYPOINT(eglReleaseTexImage
)
2391 EGL_ENTRYPOINT(eglReleaseThread
)
2392 EGL_ENTRYPOINT(eglSurfaceAttrib
)
2393 EGL_ENTRYPOINT(eglSwapBuffers
)
2394 EGL_ENTRYPOINT(eglSwapInterval
)
2395 EGL_ENTRYPOINT(eglTerminate
)
2396 EGL_ENTRYPOINT(eglWaitClient
)
2397 EGL_ENTRYPOINT(eglWaitGL
)
2398 EGL_ENTRYPOINT(eglWaitNative
)
2399 EGL_ENTRYPOINT(eglCreateSync
)
2400 EGL_ENTRYPOINT(eglDestroySync
)
2401 EGL_ENTRYPOINT(eglClientWaitSync
)
2402 EGL_ENTRYPOINT(eglGetSyncAttrib
)
2403 EGL_ENTRYPOINT(eglWaitSync
)
2404 EGL_ENTRYPOINT(eglCreateImage
)
2405 EGL_ENTRYPOINT(eglDestroyImage
)
2406 EGL_ENTRYPOINT(eglGetPlatformDisplay
)
2407 EGL_ENTRYPOINT(eglCreatePlatformWindowSurface
)
2408 EGL_ENTRYPOINT(eglCreatePlatformPixmapSurface
)
2409 EGL_ENTRYPOINT(eglCreateImageKHR
)
2410 EGL_ENTRYPOINT(eglDestroyImageKHR
)
2411 EGL_ENTRYPOINT(eglCreateSyncKHR
)
2412 EGL_ENTRYPOINT(eglCreateSync64KHR
)
2413 EGL_ENTRYPOINT(eglDestroySyncKHR
)
2414 EGL_ENTRYPOINT(eglClientWaitSyncKHR
)
2415 EGL_ENTRYPOINT(eglWaitSyncKHR
)
2416 EGL_ENTRYPOINT(eglSignalSyncKHR
)
2417 EGL_ENTRYPOINT(eglGetSyncAttribKHR
)
2418 EGL_ENTRYPOINT(eglSwapBuffersRegionNOK
)
2419 EGL_ENTRYPOINT(eglCreateDRMImageMESA
)
2420 EGL_ENTRYPOINT(eglExportDRMImageMESA
)
2421 EGL_ENTRYPOINT(eglBindWaylandDisplayWL
)
2422 EGL_ENTRYPOINT(eglUnbindWaylandDisplayWL
)
2423 EGL_ENTRYPOINT(eglQueryWaylandBufferWL
)
2424 EGL_ENTRYPOINT(eglCreateWaylandBufferFromImageWL
)
2425 EGL_ENTRYPOINT(eglPostSubBufferNV
)
2426 EGL_ENTRYPOINT(eglSwapBuffersWithDamageEXT
)
2427 EGL_ENTRYPOINT(eglSwapBuffersWithDamageKHR
)
2428 EGL_ENTRYPOINT(eglGetPlatformDisplayEXT
)
2429 EGL_ENTRYPOINT(eglCreatePlatformWindowSurfaceEXT
)
2430 EGL_ENTRYPOINT(eglCreatePlatformPixmapSurfaceEXT
)
2431 EGL_ENTRYPOINT(eglGetSyncValuesCHROMIUM
)
2432 EGL_ENTRYPOINT(eglExportDMABUFImageQueryMESA
)
2433 EGL_ENTRYPOINT(eglExportDMABUFImageMESA
)
2434 EGL_ENTRYPOINT(eglLabelObjectKHR
)
2435 EGL_ENTRYPOINT(eglDebugMessageControlKHR
)
2436 EGL_ENTRYPOINT(eglQueryDebugKHR
)
2437 EGL_ENTRYPOINT(eglDupNativeFenceFDANDROID
)
2438 #undef EGL_ENTRYPOINT
2444 RETURN_EGL_SUCCESS(NULL
, NULL
);
2446 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2449 if (strncmp(procname
, "egl", 3) == 0) {
2450 for (i
= 0; egl_functions
[i
].name
; i
++) {
2451 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
2452 ret
= egl_functions
[i
].function
;
2458 ret
= _eglGetDriverProc(procname
);
2460 RETURN_EGL_SUCCESS(NULL
, ret
);
2464 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2465 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2469 *disp
= _eglLockDisplay(dpy
);
2470 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2472 _eglUnlockDisplay(*disp
);
2473 return MESA_GLINTEROP_INVALID_DISPLAY
;
2476 *drv
= (*disp
)->Driver
;
2478 *ctx
= _eglLookupContext(context
, *disp
);
2480 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2481 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2482 _eglUnlockDisplay(*disp
);
2483 return MESA_GLINTEROP_INVALID_CONTEXT
;
2486 return MESA_GLINTEROP_SUCCESS
;
2490 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2491 struct mesa_glinterop_device_info
*out
)
2498 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2499 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2502 if (drv
->API
.GLInteropQueryDeviceInfo
)
2503 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2505 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2507 _eglUnlockDisplay(disp
);
2512 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2513 struct mesa_glinterop_export_in
*in
,
2514 struct mesa_glinterop_export_out
*out
)
2521 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2522 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2525 if (drv
->API
.GLInteropExportObject
)
2526 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2528 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2530 _eglUnlockDisplay(disp
);