1 /**************************************************************************
3 * Copyright 2008 VMware, Inc.
4 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5 * Copyright 2010-2011 LunarG, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
32 * Public EGL API entrypoints
34 * Generally, we use the EGLDisplay parameter as a key to lookup the
35 * appropriate device driver handle, then jump though the driver's
36 * dispatch table to handle the function.
38 * That allows us the option of supporting multiple, simultaneous,
39 * heterogeneous hardware devices in the future.
41 * The EGLDisplay, EGLConfig, EGLContext and EGLSurface types are
42 * opaque handles. Internal objects are linked to a display to
45 * For each public API entry point, the opaque handles are looked up
46 * before being dispatched to the drivers. When it fails to look up
56 * is generated and the driver function is not called. An
57 * uninitialized EGLDisplay has no driver associated with it. When
58 * such display is detected,
64 * Some of the entry points use current display, context, or surface
65 * implicitly. For such entry points, the implicit objects are also
66 * checked before calling the driver function. Other than the
67 * errors listed above,
69 * EGL_BAD_CURRENT_SURFACE
71 * may also be generated.
73 * Notes on naming conventions:
75 * eglFooBar - public EGL function
76 * EGL_FOO_BAR - public EGL token
77 * EGLDatatype - public EGL datatype
79 * _eglFooBar - private EGL function
80 * _EGLDatatype - private EGL datatype, typedef'd struct
81 * _egl_struct - private EGL struct, non-typedef'd
89 #include "c99_compat.h"
90 #include "c11/threads.h"
91 #include "GL/mesa_glinterop.h"
92 #include "eglcompiler.h"
94 #include "eglglobals.h"
95 #include "eglcontext.h"
96 #include "egldisplay.h"
97 #include "egltypedefs.h"
98 #include "eglcurrent.h"
99 #include "egldriver.h"
100 #include "eglsurface.h"
101 #include "eglconfig.h"
102 #include "eglimage.h"
107 * Macros to help return an API entrypoint.
109 * These macros will unlock the display and record the error code.
111 #define RETURN_EGL_ERROR(disp, err, ret) \
114 _eglUnlockDisplay(disp); \
115 /* EGL error codes are non-zero */ \
117 _eglError(err, __func__); \
121 #define RETURN_EGL_SUCCESS(disp, ret) \
122 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
124 /* record EGL_SUCCESS only when ret evaluates to true */
125 #define RETURN_EGL_EVAL(disp, ret) \
126 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
130 * A bunch of macros and checks to simplify error checking.
133 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
135 drv = _eglCheckDisplay(disp, __func__); \
137 RETURN_EGL_ERROR(disp, 0, ret); \
140 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
142 drv = _eglCheck ## type(disp, obj, __func__); \
144 RETURN_EGL_ERROR(disp, 0, ret); \
147 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
148 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
150 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
151 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
153 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
154 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
156 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
157 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
160 static inline _EGLDriver
*
161 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
164 _eglError(EGL_BAD_DISPLAY
, msg
);
167 if (!disp
->Initialized
) {
168 _eglError(EGL_NOT_INITIALIZED
, msg
);
175 static inline _EGLDriver
*
176 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
178 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
182 _eglError(EGL_BAD_SURFACE
, msg
);
189 static inline _EGLDriver
*
190 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
192 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
196 _eglError(EGL_BAD_CONTEXT
, msg
);
203 static inline _EGLDriver
*
204 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
206 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
210 _eglError(EGL_BAD_CONFIG
, msg
);
217 static inline _EGLDriver
*
218 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
220 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
224 _eglError(EGL_BAD_PARAMETER
, msg
);
232 * Lookup and lock a display.
234 static inline _EGLDisplay
*
235 _eglLockDisplay(EGLDisplay display
)
237 _EGLDisplay
*dpy
= _eglLookupDisplay(display
);
239 mtx_lock(&dpy
->Mutex
);
248 _eglUnlockDisplay(_EGLDisplay
*dpy
)
250 mtx_unlock(&dpy
->Mutex
);
254 _eglSetFuncName(const char *funcName
, _EGLDisplay
*disp
, EGLenum objectType
, _EGLResource
*object
)
256 _EGLThreadInfo
*thr
= _eglGetCurrentThread();
257 if (!_eglIsCurrentThreadDummy()) {
258 thr
->CurrentFuncName
= funcName
;
259 thr
->CurrentObjectLabel
= NULL
;
261 if (objectType
== EGL_OBJECT_THREAD_KHR
)
262 thr
->CurrentObjectLabel
= thr
->Label
;
263 else if (objectType
== EGL_OBJECT_DISPLAY_KHR
&& disp
)
264 thr
->CurrentObjectLabel
= disp
->Label
;
266 thr
->CurrentObjectLabel
= object
->Label
;
271 _eglDebugReportFull(EGL_BAD_ALLOC
, funcName
, funcName
,
272 EGL_DEBUG_MSG_CRITICAL_KHR
, NULL
, NULL
);
276 #define _EGL_FUNC_START(disp, objectType, object, ret) \
278 if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \
280 _eglUnlockDisplay(disp); \
286 * Convert an attribute list from EGLint[] to EGLAttrib[].
288 * Return an EGL error code. The output parameter out_attrib_list is modified
292 _eglConvertIntsToAttribs(const EGLint
*int_list
, EGLAttrib
**out_attrib_list
)
295 EGLAttrib
*attrib_list
;
298 while (int_list
[2*len
] != EGL_NONE
)
303 *out_attrib_list
= NULL
;
307 if (2*len
+ 1 > SIZE_MAX
/ sizeof(EGLAttrib
))
308 return EGL_BAD_ALLOC
;
310 attrib_list
= malloc((2*len
+ 1) * sizeof(EGLAttrib
));
312 return EGL_BAD_ALLOC
;
314 for (size_t i
= 0; i
< len
; ++i
) {
315 attrib_list
[2*i
+ 0] = int_list
[2*i
+ 0];
316 attrib_list
[2*i
+ 1] = int_list
[2*i
+ 1];
319 attrib_list
[2*len
] = EGL_NONE
;
321 *out_attrib_list
= attrib_list
;
327 _eglConvertAttribsToInt(const EGLAttrib
*attr_list
)
329 EGLint
*int_attribs
= NULL
;
331 /* Convert attributes from EGLAttrib[] to EGLint[] */
335 while (attr_list
[size
] != EGL_NONE
)
338 size
+= 1; /* add space for EGL_NONE */
340 int_attribs
= calloc(size
, sizeof(int_attribs
[0]));
344 for (i
= 0; i
< size
; i
++)
345 int_attribs
[i
] = attr_list
[i
];
352 * This is typically the first EGL function that an application calls.
353 * It associates a private _EGLDisplay object to the native display.
355 EGLDisplay EGLAPIENTRY
356 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
358 _EGLPlatformType plat
;
360 void *native_display_ptr
;
362 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
364 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
365 native_display_ptr
= (void*) nativeDisplay
;
367 plat
= _eglGetNativePlatform(native_display_ptr
);
368 dpy
= _eglFindDisplay(plat
, native_display_ptr
);
369 return _eglGetDisplayHandle(dpy
);
373 _eglGetPlatformDisplayCommon(EGLenum platform
, void *native_display
,
374 const EGLint
*attrib_list
)
379 #ifdef HAVE_X11_PLATFORM
380 case EGL_PLATFORM_X11_EXT
:
381 dpy
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
384 #ifdef HAVE_DRM_PLATFORM
385 case EGL_PLATFORM_GBM_MESA
:
386 dpy
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
390 #ifdef HAVE_WAYLAND_PLATFORM
391 case EGL_PLATFORM_WAYLAND_EXT
:
392 dpy
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
397 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
400 return _eglGetDisplayHandle(dpy
);
403 static EGLDisplay EGLAPIENTRY
404 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
405 const EGLint
*attrib_list
)
407 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
408 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
411 EGLDisplay EGLAPIENTRY
412 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
413 const EGLAttrib
*attrib_list
)
418 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
420 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
421 if (attrib_list
&& !int_attribs
)
422 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
424 display
= _eglGetPlatformDisplayCommon(platform
, native_display
, int_attribs
);
430 * Copy the extension into the string and update the string pointer.
433 _eglAppendExtension(char **str
, const char *ext
)
436 size_t len
= strlen(ext
);
453 * Examine the individual extension enable/disable flags and recompute
454 * the driver's Extensions string.
457 _eglCreateExtensionsString(_EGLDisplay
*dpy
)
459 #define _EGL_CHECK_EXTENSION(ext) \
461 if (dpy->Extensions.ext) { \
462 _eglAppendExtension(&exts, "EGL_" #ext); \
463 assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
467 char *exts
= dpy
->ExtensionsString
;
469 /* Please keep these sorted alphabetically. */
470 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
471 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
472 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
474 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
476 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
477 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
478 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
479 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
481 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
482 _EGL_CHECK_EXTENSION(KHR_create_context
);
483 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
484 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
485 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
486 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
487 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
488 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
489 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
490 if (dpy
->Extensions
.KHR_image_base
&& dpy
->Extensions
.KHR_image_pixmap
)
491 _eglAppendExtension(&exts
, "EGL_KHR_image");
492 _EGL_CHECK_EXTENSION(KHR_image_base
);
493 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
494 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
495 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
496 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
497 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
499 if (dpy
->Extensions
.KHR_no_config_context
)
500 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
501 _EGL_CHECK_EXTENSION(MESA_drm_image
);
502 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
504 _EGL_CHECK_EXTENSION(NOK_swap_region
);
505 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
507 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
509 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
510 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
512 #undef _EGL_CHECK_EXTENSION
516 _eglCreateAPIsString(_EGLDisplay
*dpy
)
518 if (dpy
->ClientAPIs
& EGL_OPENGL_BIT
)
519 strcat(dpy
->ClientAPIsString
, "OpenGL ");
521 if (dpy
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
522 dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
523 dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
524 strcat(dpy
->ClientAPIsString
, "OpenGL_ES ");
527 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
528 strcat(dpy
->ClientAPIsString
, "OpenVG ");
530 assert(strlen(dpy
->ClientAPIsString
) < sizeof(dpy
->ClientAPIsString
));
534 _eglComputeVersion(_EGLDisplay
*disp
)
538 if (disp
->Extensions
.KHR_fence_sync
&&
539 disp
->Extensions
.KHR_cl_event2
&&
540 disp
->Extensions
.KHR_wait_sync
&&
541 disp
->Extensions
.KHR_image_base
&&
542 disp
->Extensions
.KHR_gl_texture_2D_image
&&
543 disp
->Extensions
.KHR_gl_texture_3D_image
&&
544 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
545 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
546 disp
->Extensions
.KHR_create_context
&&
547 disp
->Extensions
.EXT_create_context_robustness
&&
548 disp
->Extensions
.KHR_get_all_proc_addresses
&&
549 disp
->Extensions
.KHR_gl_colorspace
&&
550 disp
->Extensions
.KHR_surfaceless_context
)
555 * This is typically the second EGL function that an application calls.
556 * Here we load/initialize the actual hardware driver.
558 EGLBoolean EGLAPIENTRY
559 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
561 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
563 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
566 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
568 if (!disp
->Initialized
) {
569 if (!_eglMatchDriver(disp
, EGL_FALSE
))
570 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
572 /* limit to APIs supported by core */
573 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
575 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
576 * classifies it as an EGL display extension, though conceptually it's an
577 * EGL client extension.
579 * From the EGL_KHR_get_all_proc_addresses spec:
581 * The EGL implementation must expose the name
582 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
583 * EGL_KHR_get_all_proc_addresses and supports
584 * EGL_EXT_client_extensions.
586 * Mesa unconditionally exposes both client extensions mentioned above,
587 * so the spec requires that each EGLDisplay unconditionally expose
588 * EGL_KHR_get_all_proc_addresses also.
590 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
592 _eglComputeVersion(disp
);
593 _eglCreateExtensionsString(disp
);
594 _eglCreateAPIsString(disp
);
595 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
596 "%d.%d (%s)", disp
->Version
/ 10, disp
->Version
% 10,
600 /* Update applications version of major and minor if not NULL */
601 if ((major
!= NULL
) && (minor
!= NULL
)) {
602 *major
= disp
->Version
/ 10;
603 *minor
= disp
->Version
% 10;
606 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
610 EGLBoolean EGLAPIENTRY
611 eglTerminate(EGLDisplay dpy
)
613 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
615 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
618 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
620 if (disp
->Initialized
) {
621 _EGLDriver
*drv
= disp
->Driver
;
623 drv
->API
.Terminate(drv
, disp
);
624 /* do not reset disp->Driver */
625 disp
->ClientAPIsString
[0] = 0;
626 disp
->Initialized
= EGL_FALSE
;
629 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
633 const char * EGLAPIENTRY
634 eglQueryString(EGLDisplay dpy
, EGLint name
)
639 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
640 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
643 disp
= _eglLockDisplay(dpy
);
644 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
645 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
649 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
651 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
653 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
654 case EGL_CLIENT_APIS
:
655 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
657 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
662 EGLBoolean EGLAPIENTRY
663 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
664 EGLint config_size
, EGLint
*num_config
)
666 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
670 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
672 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
673 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
675 RETURN_EGL_EVAL(disp
, ret
);
679 EGLBoolean EGLAPIENTRY
680 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
681 EGLint config_size
, EGLint
*num_config
)
683 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
687 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
689 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
690 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
691 config_size
, num_config
);
693 RETURN_EGL_EVAL(disp
, ret
);
697 EGLBoolean EGLAPIENTRY
698 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
699 EGLint attribute
, EGLint
*value
)
701 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
702 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
706 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
708 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
709 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
711 RETURN_EGL_EVAL(disp
, ret
);
715 EGLContext EGLAPIENTRY
716 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
717 const EGLint
*attrib_list
)
719 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
720 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
721 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
723 _EGLContext
*context
;
726 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
728 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
730 if (!config
&& !disp
->Extensions
.KHR_no_config_context
)
731 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
733 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
734 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
736 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
737 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
739 RETURN_EGL_EVAL(disp
, ret
);
743 EGLBoolean EGLAPIENTRY
744 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
746 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
747 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
751 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
753 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
754 _eglUnlinkContext(context
);
755 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
757 RETURN_EGL_EVAL(disp
, ret
);
761 EGLBoolean EGLAPIENTRY
762 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
765 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
766 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
767 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
768 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
772 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
775 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
778 /* display is allowed to be uninitialized under certain condition */
779 if (!disp
->Initialized
) {
780 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
781 ctx
!= EGL_NO_CONTEXT
)
782 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
785 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
787 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
788 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
789 if (!draw_surf
|| !read_surf
) {
790 /* From the EGL 1.4 (20130211) spec:
792 * To release the current context without assigning a new one, set ctx
793 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
795 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
796 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
798 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
799 (!read_surf
&& read
!= EGL_NO_SURFACE
))
800 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
801 if (draw_surf
|| read_surf
)
802 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
805 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
807 RETURN_EGL_EVAL(disp
, ret
);
811 EGLBoolean EGLAPIENTRY
812 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
813 EGLint attribute
, EGLint
*value
)
815 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
816 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
820 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
822 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
823 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
825 RETURN_EGL_EVAL(disp
, ret
);
830 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
831 void *native_window
, const EGLint
*attrib_list
)
833 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
838 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
840 if (native_window
== NULL
)
841 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
843 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
845 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
847 RETURN_EGL_EVAL(disp
, ret
);
851 EGLSurface EGLAPIENTRY
852 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
853 EGLNativeWindowType window
, const EGLint
*attrib_list
)
855 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
857 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
858 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
859 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
864 fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
866 #ifdef HAVE_X11_PLATFORM
867 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
868 /* The `native_window` parameter for the X11 platform differs between
869 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
870 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
871 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
872 * `Window*`. Convert `Window*` to `Window` because that's what
873 * dri2_x11_create_window_surface() expects.
875 return (void *)(* (Window
*) native_window
);
878 return native_window
;
881 static EGLSurface EGLAPIENTRY
882 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
884 const EGLint
*attrib_list
)
886 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
888 native_window
= fixupNativeWindow(disp
, native_window
);
890 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
891 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
896 EGLSurface EGLAPIENTRY
897 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
899 const EGLAttrib
*attrib_list
)
901 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
905 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
907 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
908 if (attrib_list
&& !int_attribs
)
909 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
911 native_window
= fixupNativeWindow(disp
, native_window
);
912 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
919 fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
921 #ifdef HAVE_X11_PLATFORM
922 /* The `native_pixmap` parameter for the X11 platform differs between
923 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
924 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
925 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
926 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
927 * dri2_x11_create_pixmap_surface() expects.
929 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
930 return (void *)(* (Pixmap
*) native_pixmap
);
932 return native_pixmap
;
936 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
937 void *native_pixmap
, const EGLint
*attrib_list
)
939 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
944 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
945 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
947 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
949 RETURN_EGL_EVAL(disp
, ret
);
953 EGLSurface EGLAPIENTRY
954 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
955 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
957 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
959 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
960 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
961 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
965 static EGLSurface EGLAPIENTRY
966 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
968 const EGLint
*attrib_list
)
970 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
972 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
973 native_pixmap
= fixupNativePixmap(disp
, native_pixmap
);
974 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
979 EGLSurface EGLAPIENTRY
980 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
982 const EGLAttrib
*attrib_list
)
984 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
988 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
990 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
991 if (attrib_list
&& !int_attribs
)
992 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
994 native_pixmap
= fixupNativePixmap(disp
, native_pixmap
);
995 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1002 EGLSurface EGLAPIENTRY
1003 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1004 const EGLint
*attrib_list
)
1006 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1007 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1012 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1013 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1015 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1016 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1018 RETURN_EGL_EVAL(disp
, ret
);
1022 EGLBoolean EGLAPIENTRY
1023 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1025 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1026 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1030 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1031 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1032 _eglUnlinkSurface(surf
);
1033 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1035 RETURN_EGL_EVAL(disp
, ret
);
1038 EGLBoolean EGLAPIENTRY
1039 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1040 EGLint attribute
, EGLint
*value
)
1042 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1043 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1047 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1048 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1049 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1051 RETURN_EGL_EVAL(disp
, ret
);
1054 EGLBoolean EGLAPIENTRY
1055 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1056 EGLint attribute
, EGLint value
)
1058 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1059 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1063 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1064 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1065 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1067 RETURN_EGL_EVAL(disp
, ret
);
1071 EGLBoolean EGLAPIENTRY
1072 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1074 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1075 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1079 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1080 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1081 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1083 RETURN_EGL_EVAL(disp
, ret
);
1087 EGLBoolean EGLAPIENTRY
1088 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1090 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1091 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1095 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1096 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1097 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1099 RETURN_EGL_EVAL(disp
, ret
);
1103 EGLBoolean EGLAPIENTRY
1104 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1106 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1107 _EGLContext
*ctx
= _eglGetCurrentContext();
1108 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1112 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1113 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1115 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1116 ctx
->Resource
.Display
!= disp
)
1117 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1119 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1120 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1122 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1124 RETURN_EGL_EVAL(disp
, ret
);
1128 EGLBoolean EGLAPIENTRY
1129 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1131 _EGLContext
*ctx
= _eglGetCurrentContext();
1132 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1133 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1137 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1138 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1140 /* surface must be bound to current context in EGL 1.4 */
1141 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1142 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1143 surf
!= ctx
->DrawSurface
)
1144 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1147 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1149 RETURN_EGL_EVAL(disp
, ret
);
1153 static EGLBoolean EGLAPIENTRY
1154 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1155 EGLint
*rects
, EGLint n_rects
)
1157 _EGLContext
*ctx
= _eglGetCurrentContext();
1158 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1159 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1163 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1164 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1166 /* surface must be bound to current context in EGL 1.4 */
1167 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1168 surf
!= ctx
->DrawSurface
)
1169 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1171 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1172 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1174 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1176 RETURN_EGL_EVAL(disp
, ret
);
1179 EGLBoolean EGLAPIENTRY
1180 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1182 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1183 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1186 void *native_pixmap_ptr
;
1188 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1189 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1190 native_pixmap_ptr
= (void*) target
;
1192 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1193 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
1194 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
1195 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1197 RETURN_EGL_EVAL(disp
, ret
);
1202 _eglWaitClientCommon(void)
1204 _EGLContext
*ctx
= _eglGetCurrentContext();
1210 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1212 disp
= ctx
->Resource
.Display
;
1213 mtx_lock(&disp
->Mutex
);
1215 /* let bad current context imply bad current surface */
1216 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1217 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1218 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1220 /* a valid current context implies an initialized current display */
1221 assert(disp
->Initialized
);
1223 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1225 RETURN_EGL_EVAL(disp
, ret
);
1228 EGLBoolean EGLAPIENTRY
1231 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1232 return _eglWaitClientCommon();
1235 EGLBoolean EGLAPIENTRY
1238 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1239 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1240 return _eglWaitClientCommon();
1244 EGLBoolean EGLAPIENTRY
1245 eglWaitNative(EGLint engine
)
1247 _EGLContext
*ctx
= _eglGetCurrentContext();
1253 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1255 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1257 disp
= ctx
->Resource
.Display
;
1258 mtx_lock(&disp
->Mutex
);
1260 /* let bad current context imply bad current surface */
1261 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1262 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1263 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1265 /* a valid current context implies an initialized current display */
1266 assert(disp
->Initialized
);
1268 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1270 RETURN_EGL_EVAL(disp
, ret
);
1274 EGLDisplay EGLAPIENTRY
1275 eglGetCurrentDisplay(void)
1277 _EGLContext
*ctx
= _eglGetCurrentContext();
1280 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1282 RETURN_EGL_SUCCESS(NULL
, ret
);
1286 EGLContext EGLAPIENTRY
1287 eglGetCurrentContext(void)
1289 _EGLContext
*ctx
= _eglGetCurrentContext();
1292 ret
= _eglGetContextHandle(ctx
);
1294 RETURN_EGL_SUCCESS(NULL
, ret
);
1298 EGLSurface EGLAPIENTRY
1299 eglGetCurrentSurface(EGLint readdraw
)
1301 _EGLContext
*ctx
= _eglGetCurrentContext();
1302 EGLint err
= EGL_SUCCESS
;
1306 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1309 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1313 surf
= ctx
->DrawSurface
;
1316 surf
= ctx
->ReadSurface
;
1320 err
= EGL_BAD_PARAMETER
;
1324 ret
= _eglGetSurfaceHandle(surf
);
1326 RETURN_EGL_ERROR(NULL
, err
, ret
);
1333 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1334 EGLint e
= t
->LastError
;
1335 if (!_eglIsCurrentThreadDummy())
1336 t
->LastError
= EGL_SUCCESS
;
1346 * Specify the client API to use for subsequent calls including:
1347 * eglCreateContext()
1348 * eglGetCurrentContext()
1349 * eglGetCurrentDisplay()
1350 * eglGetCurrentSurface()
1351 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1354 * See section 3.7 "Rendering Context" in the EGL specification for details.
1356 EGLBoolean EGLAPIENTRY
1357 eglBindAPI(EGLenum api
)
1361 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1363 t
= _eglGetCurrentThread();
1364 if (_eglIsCurrentThreadDummy())
1365 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1367 if (!_eglIsApiValid(api
))
1368 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1370 t
->CurrentAPI
= api
;
1372 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1377 * Return the last value set with eglBindAPI().
1382 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1385 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1386 ret
= t
->CurrentAPI
;
1388 RETURN_EGL_SUCCESS(NULL
, ret
);
1392 EGLSurface EGLAPIENTRY
1393 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1394 EGLClientBuffer buffer
, EGLConfig config
,
1395 const EGLint
*attrib_list
)
1397 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1398 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1403 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1405 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1407 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1409 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1411 RETURN_EGL_EVAL(disp
, ret
);
1415 EGLBoolean EGLAPIENTRY
1416 eglReleaseThread(void)
1418 /* unbind current contexts */
1419 if (!_eglIsCurrentThreadDummy()) {
1420 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1421 _EGLContext
*ctx
= t
->CurrentContext
;
1423 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1426 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1429 mtx_lock(&disp
->Mutex
);
1431 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1432 mtx_unlock(&disp
->Mutex
);
1436 _eglDestroyCurrentThread();
1438 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1443 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1444 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1446 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1451 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1452 if (!disp
->Extensions
.KHR_image_base
)
1453 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1454 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1455 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1456 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1457 * <ctx> must be EGL_NO_CONTEXT..."
1459 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1460 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1462 img
= drv
->API
.CreateImageKHR(drv
,
1463 disp
, context
, target
, buffer
, attr_list
);
1464 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1466 RETURN_EGL_EVAL(disp
, ret
);
1469 static EGLImage EGLAPIENTRY
1470 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1471 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1473 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1474 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1475 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1479 EGLImage EGLAPIENTRY
1480 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1481 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1483 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1485 EGLint
*int_attribs
;
1487 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1489 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1490 if (attr_list
&& !int_attribs
)
1491 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1493 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1499 EGLBoolean EGLAPIENTRY
1500 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1502 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1503 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1507 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1509 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1510 if (!disp
->Extensions
.KHR_image_base
)
1511 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1513 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1515 _eglUnlinkImage(img
);
1516 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1518 RETURN_EGL_EVAL(disp
, ret
);
1523 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLint
*attrib_list
,
1524 const EGLAttrib
*attrib_list64
, EGLBoolean is64
,
1525 EGLenum invalid_type_error
)
1527 _EGLContext
*ctx
= _eglGetCurrentContext();
1532 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1534 if (!disp
->Extensions
.KHR_cl_event2
&& is64
) {
1535 /* There exist two EGLAttrib variants of eglCreateSync*:
1536 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1537 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1538 * support as a proxy for EGL 1.5 support, even though that's not
1539 * entirely correct (though _eglComputeVersion does the same).
1541 * The EGL spec provides no guidance on how to handle unsupported
1542 * functions. EGL_BAD_MATCH seems reasonable.
1544 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1547 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1548 if (!ctx
|| ctx
->Resource
.Display
!= disp
||
1549 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1550 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1553 case EGL_SYNC_FENCE_KHR
:
1554 if (!disp
->Extensions
.KHR_fence_sync
)
1555 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1557 case EGL_SYNC_REUSABLE_KHR
:
1558 if (!disp
->Extensions
.KHR_reusable_sync
)
1559 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1561 case EGL_SYNC_CL_EVENT_KHR
:
1562 if (!disp
->Extensions
.KHR_cl_event2
)
1563 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1566 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1569 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
, attrib_list64
);
1570 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1572 RETURN_EGL_EVAL(disp
, ret
);
1576 static EGLSync EGLAPIENTRY
1577 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*attrib_list
)
1579 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1580 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1581 return _eglCreateSync(disp
, type
, attrib_list
, NULL
, EGL_FALSE
,
1586 static EGLSync EGLAPIENTRY
1587 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1589 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1590 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1591 return _eglCreateSync(disp
, type
, NULL
, attrib_list
, EGL_TRUE
,
1597 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1599 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1600 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1601 return _eglCreateSync(disp
, type
, NULL
, attrib_list
, EGL_TRUE
,
1606 EGLBoolean EGLAPIENTRY
1607 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1609 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1610 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1614 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1616 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1617 assert(disp
->Extensions
.KHR_reusable_sync
||
1618 disp
->Extensions
.KHR_fence_sync
);
1621 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1623 RETURN_EGL_EVAL(disp
, ret
);
1628 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
, EGLTime timeout
)
1630 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1631 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1635 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1637 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1638 assert(disp
->Extensions
.KHR_reusable_sync
||
1639 disp
->Extensions
.KHR_fence_sync
);
1641 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1642 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1644 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1645 * unlocked here to allow other threads also to be able to
1646 * go into waiting state.
1649 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1650 _eglUnlockDisplay(dpy
);
1652 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1655 * 'disp' is already unlocked for reusable sync type,
1656 * so passing 'NULL' to bypass unlocking display.
1658 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1659 RETURN_EGL_EVAL(NULL
, ret
);
1661 RETURN_EGL_EVAL(disp
, ret
);
1666 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
1668 _EGLContext
*ctx
= _eglGetCurrentContext();
1672 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1673 assert(disp
->Extensions
.KHR_wait_sync
);
1675 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1676 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1677 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1679 /* the API doesn't allow any flags yet */
1681 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1683 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1685 RETURN_EGL_EVAL(disp
, ret
);
1688 static EGLint EGLAPIENTRY
1689 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1691 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1692 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1693 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1694 return _eglWaitSyncCommon(disp
, s
, flags
);
1698 EGLBoolean EGLAPIENTRY
1699 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1701 /* The KHR version returns EGLint, while the core version returns
1702 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1705 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1706 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1707 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1708 return _eglWaitSyncCommon(disp
, s
, flags
);
1712 static EGLBoolean EGLAPIENTRY
1713 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
1715 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1716 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1720 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1722 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1723 assert(disp
->Extensions
.KHR_reusable_sync
);
1724 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
1726 RETURN_EGL_EVAL(disp
, ret
);
1731 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
1736 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1737 assert(disp
->Extensions
.KHR_reusable_sync
||
1738 disp
->Extensions
.KHR_fence_sync
);
1739 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
1741 RETURN_EGL_EVAL(disp
, ret
);
1744 EGLBoolean EGLAPIENTRY
1745 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
1747 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1748 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1749 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1750 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
1754 static EGLBoolean EGLAPIENTRY
1755 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
1757 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1758 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1762 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1765 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1768 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
1770 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
1772 * If any error occurs, <*value> is not modified.
1774 if (result
== EGL_FALSE
)
1782 static EGLBoolean EGLAPIENTRY
1783 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
1784 EGLint numRects
, const EGLint
*rects
)
1786 _EGLContext
*ctx
= _eglGetCurrentContext();
1787 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1788 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1792 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1794 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1796 if (!disp
->Extensions
.NOK_swap_region
)
1797 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1799 /* surface must be bound to current context in EGL 1.4 */
1800 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1801 surf
!= ctx
->DrawSurface
)
1802 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1804 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
1806 RETURN_EGL_EVAL(disp
, ret
);
1810 static EGLImage EGLAPIENTRY
1811 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
1813 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1818 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1820 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1821 if (!disp
->Extensions
.MESA_drm_image
)
1822 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1824 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
1825 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1827 RETURN_EGL_EVAL(disp
, ret
);
1830 static EGLBoolean EGLAPIENTRY
1831 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
1832 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
1834 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1835 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1839 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1841 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1842 assert(disp
->Extensions
.MESA_drm_image
);
1845 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1847 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
1849 RETURN_EGL_EVAL(disp
, ret
);
1855 static EGLBoolean EGLAPIENTRY
1856 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1858 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1862 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1864 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1865 assert(disp
->Extensions
.WL_bind_wayland_display
);
1868 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1870 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
1872 RETURN_EGL_EVAL(disp
, ret
);
1875 static EGLBoolean EGLAPIENTRY
1876 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1878 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1882 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1884 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1885 assert(disp
->Extensions
.WL_bind_wayland_display
);
1888 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1890 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
1892 RETURN_EGL_EVAL(disp
, ret
);
1895 static EGLBoolean EGLAPIENTRY
1896 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
1897 EGLint attribute
, EGLint
*value
)
1899 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1903 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1905 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1906 assert(disp
->Extensions
.WL_bind_wayland_display
);
1909 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1911 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
1913 RETURN_EGL_EVAL(disp
, ret
);
1917 static struct wl_buffer
* EGLAPIENTRY
1918 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
1920 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1923 struct wl_buffer
*ret
;
1925 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1927 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
1928 assert(disp
->Extensions
.WL_create_wayland_buffer_from_image
);
1930 img
= _eglLookupImage(image
, disp
);
1933 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
1935 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
1937 RETURN_EGL_EVAL(disp
, ret
);
1940 static EGLBoolean EGLAPIENTRY
1941 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
1942 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
1944 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1945 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1949 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1951 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1953 if (!disp
->Extensions
.NV_post_sub_buffer
)
1954 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1956 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
1958 RETURN_EGL_EVAL(disp
, ret
);
1961 static EGLBoolean EGLAPIENTRY
1962 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
1963 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
1966 _EGLDisplay
*disp
= _eglLockDisplay(display
);
1967 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1971 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1973 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1974 if (!disp
->Extensions
.CHROMIUM_sync_control
)
1975 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1977 if (!ust
|| !msc
|| !sbc
)
1978 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1980 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
1982 RETURN_EGL_EVAL(disp
, ret
);
1985 static EGLBoolean EGLAPIENTRY
1986 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
1987 EGLint
*fourcc
, EGLint
*nplanes
,
1988 EGLuint64KHR
*modifiers
)
1990 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1991 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1995 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1997 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1998 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2001 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2003 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2006 RETURN_EGL_EVAL(disp
, ret
);
2009 static EGLBoolean EGLAPIENTRY
2010 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2011 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2013 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2014 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2018 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2020 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2021 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2024 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2026 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2028 RETURN_EGL_EVAL(disp
, ret
);
2031 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2032 eglGetProcAddress(const char *procname
)
2034 static const struct {
2037 } egl_functions
[] = {
2038 /* core functions queryable in the presence of
2039 * EGL_KHR_get_all_proc_addresses or EGL 1.5
2041 /* alphabetical order */
2042 { "eglBindAPI", (_EGLProc
) eglBindAPI
},
2043 { "eglBindTexImage", (_EGLProc
) eglBindTexImage
},
2044 { "eglChooseConfig", (_EGLProc
) eglChooseConfig
},
2045 { "eglCopyBuffers", (_EGLProc
) eglCopyBuffers
},
2046 { "eglCreateContext", (_EGLProc
) eglCreateContext
},
2047 { "eglCreatePbufferFromClientBuffer", (_EGLProc
) eglCreatePbufferFromClientBuffer
},
2048 { "eglCreatePbufferSurface", (_EGLProc
) eglCreatePbufferSurface
},
2049 { "eglCreatePixmapSurface", (_EGLProc
) eglCreatePixmapSurface
},
2050 { "eglCreateWindowSurface", (_EGLProc
) eglCreateWindowSurface
},
2051 { "eglDestroyContext", (_EGLProc
) eglDestroyContext
},
2052 { "eglDestroySurface", (_EGLProc
) eglDestroySurface
},
2053 { "eglGetConfigAttrib", (_EGLProc
) eglGetConfigAttrib
},
2054 { "eglGetConfigs", (_EGLProc
) eglGetConfigs
},
2055 { "eglGetCurrentContext", (_EGLProc
) eglGetCurrentContext
},
2056 { "eglGetCurrentDisplay", (_EGLProc
) eglGetCurrentDisplay
},
2057 { "eglGetCurrentSurface", (_EGLProc
) eglGetCurrentSurface
},
2058 { "eglGetDisplay", (_EGLProc
) eglGetDisplay
},
2059 { "eglGetError", (_EGLProc
) eglGetError
},
2060 { "eglGetProcAddress", (_EGLProc
) eglGetProcAddress
},
2061 { "eglInitialize", (_EGLProc
) eglInitialize
},
2062 { "eglMakeCurrent", (_EGLProc
) eglMakeCurrent
},
2063 { "eglQueryAPI", (_EGLProc
) eglQueryAPI
},
2064 { "eglQueryContext", (_EGLProc
) eglQueryContext
},
2065 { "eglQueryString", (_EGLProc
) eglQueryString
},
2066 { "eglQuerySurface", (_EGLProc
) eglQuerySurface
},
2067 { "eglReleaseTexImage", (_EGLProc
) eglReleaseTexImage
},
2068 { "eglReleaseThread", (_EGLProc
) eglReleaseThread
},
2069 { "eglSurfaceAttrib", (_EGLProc
) eglSurfaceAttrib
},
2070 { "eglSwapBuffers", (_EGLProc
) eglSwapBuffers
},
2071 { "eglSwapInterval", (_EGLProc
) eglSwapInterval
},
2072 { "eglTerminate", (_EGLProc
) eglTerminate
},
2073 { "eglWaitClient", (_EGLProc
) eglWaitClient
},
2074 { "eglWaitGL", (_EGLProc
) eglWaitGL
},
2075 { "eglWaitNative", (_EGLProc
) eglWaitNative
},
2076 { "eglCreateSync", (_EGLProc
) eglCreateSync
},
2077 { "eglDestroySync", (_EGLProc
) eglDestroySync
},
2078 { "eglClientWaitSync", (_EGLProc
) eglClientWaitSync
},
2079 { "eglGetSyncAttrib", (_EGLProc
) eglGetSyncAttrib
},
2080 { "eglWaitSync", (_EGLProc
) eglWaitSync
},
2081 { "eglCreateImage", (_EGLProc
) eglCreateImage
},
2082 { "eglDestroyImage", (_EGLProc
) eglDestroyImage
},
2083 { "eglGetPlatformDisplay", (_EGLProc
) eglGetPlatformDisplay
},
2084 { "eglCreatePlatformWindowSurface", (_EGLProc
) eglCreatePlatformWindowSurface
},
2085 { "eglCreatePlatformPixmapSurface", (_EGLProc
) eglCreatePlatformPixmapSurface
},
2086 { "eglCreateImageKHR", (_EGLProc
) eglCreateImageKHR
},
2087 { "eglDestroyImageKHR", (_EGLProc
) eglDestroyImage
},
2088 { "eglCreateSyncKHR", (_EGLProc
) eglCreateSyncKHR
},
2089 { "eglCreateSync64KHR", (_EGLProc
) eglCreateSync64KHR
},
2090 { "eglDestroySyncKHR", (_EGLProc
) eglDestroySync
},
2091 { "eglClientWaitSyncKHR", (_EGLProc
) eglClientWaitSync
},
2092 { "eglWaitSyncKHR", (_EGLProc
) eglWaitSyncKHR
},
2093 { "eglSignalSyncKHR", (_EGLProc
) eglSignalSyncKHR
},
2094 { "eglGetSyncAttribKHR", (_EGLProc
) eglGetSyncAttribKHR
},
2095 { "eglSwapBuffersRegionNOK", (_EGLProc
) eglSwapBuffersRegionNOK
},
2096 { "eglCreateDRMImageMESA", (_EGLProc
) eglCreateDRMImageMESA
},
2097 { "eglExportDRMImageMESA", (_EGLProc
) eglExportDRMImageMESA
},
2098 { "eglBindWaylandDisplayWL", (_EGLProc
) eglBindWaylandDisplayWL
},
2099 { "eglUnbindWaylandDisplayWL", (_EGLProc
) eglUnbindWaylandDisplayWL
},
2100 { "eglQueryWaylandBufferWL", (_EGLProc
) eglQueryWaylandBufferWL
},
2101 { "eglCreateWaylandBufferFromImageWL", (_EGLProc
) eglCreateWaylandBufferFromImageWL
},
2102 { "eglPostSubBufferNV", (_EGLProc
) eglPostSubBufferNV
},
2103 { "eglSwapBuffersWithDamageEXT", (_EGLProc
) eglSwapBuffersWithDamageEXT
},
2104 { "eglGetPlatformDisplayEXT", (_EGLProc
) eglGetPlatformDisplayEXT
},
2105 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc
) eglCreatePlatformWindowSurfaceEXT
},
2106 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc
) eglCreatePlatformPixmapSurfaceEXT
},
2107 { "eglGetSyncValuesCHROMIUM", (_EGLProc
) eglGetSyncValuesCHROMIUM
},
2108 { "eglExportDMABUFImageQueryMESA", (_EGLProc
) eglExportDMABUFImageQueryMESA
},
2109 { "eglExportDMABUFImageMESA", (_EGLProc
) eglExportDMABUFImageMESA
},
2116 RETURN_EGL_SUCCESS(NULL
, NULL
);
2118 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2121 if (strncmp(procname
, "egl", 3) == 0) {
2122 for (i
= 0; egl_functions
[i
].name
; i
++) {
2123 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
2124 ret
= egl_functions
[i
].function
;
2130 ret
= _eglGetDriverProc(procname
);
2132 RETURN_EGL_SUCCESS(NULL
, ret
);
2136 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2137 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2141 *disp
= _eglLockDisplay(dpy
);
2142 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2144 _eglUnlockDisplay(*disp
);
2145 return MESA_GLINTEROP_INVALID_DISPLAY
;
2148 *drv
= (*disp
)->Driver
;
2150 *ctx
= _eglLookupContext(context
, *disp
);
2152 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2153 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2154 _eglUnlockDisplay(*disp
);
2155 return MESA_GLINTEROP_INVALID_CONTEXT
;
2158 return MESA_GLINTEROP_SUCCESS
;
2162 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2163 struct mesa_glinterop_device_info
*out
)
2170 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2171 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2174 if (drv
->API
.GLInteropQueryDeviceInfo
)
2175 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2177 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2179 _eglUnlockDisplay(disp
);
2184 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2185 struct mesa_glinterop_export_in
*in
,
2186 struct mesa_glinterop_export_out
*out
)
2193 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2194 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2197 if (drv
->API
.GLInteropExportObject
)
2198 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2200 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2202 _eglUnlockDisplay(disp
);