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 "util/macros.h"
93 #include "eglglobals.h"
94 #include "eglcontext.h"
95 #include "egldisplay.h"
96 #include "egltypedefs.h"
97 #include "eglcurrent.h"
98 #include "egldriver.h"
99 #include "eglsurface.h"
100 #include "eglconfig.h"
101 #include "eglimage.h"
104 #include "GL/mesa_glinterop.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 struct _egl_entrypoint
{
166 static inline _EGLDriver
*
167 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
170 _eglError(EGL_BAD_DISPLAY
, msg
);
173 if (!disp
->Initialized
) {
174 _eglError(EGL_NOT_INITIALIZED
, msg
);
181 static inline _EGLDriver
*
182 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
184 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
188 _eglError(EGL_BAD_SURFACE
, msg
);
195 static inline _EGLDriver
*
196 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
198 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
202 _eglError(EGL_BAD_CONTEXT
, msg
);
209 static inline _EGLDriver
*
210 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
212 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
216 _eglError(EGL_BAD_CONFIG
, msg
);
223 static inline _EGLDriver
*
224 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
226 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
230 _eglError(EGL_BAD_PARAMETER
, msg
);
238 * Lookup and lock a display.
240 static inline _EGLDisplay
*
241 _eglLockDisplay(EGLDisplay display
)
243 _EGLDisplay
*dpy
= _eglLookupDisplay(display
);
245 mtx_lock(&dpy
->Mutex
);
254 _eglUnlockDisplay(_EGLDisplay
*dpy
)
256 mtx_unlock(&dpy
->Mutex
);
260 _eglSetFuncName(const char *funcName
, _EGLDisplay
*disp
, EGLenum objectType
, _EGLResource
*object
)
262 _EGLThreadInfo
*thr
= _eglGetCurrentThread();
263 if (!_eglIsCurrentThreadDummy()) {
264 thr
->CurrentFuncName
= funcName
;
265 thr
->CurrentObjectLabel
= NULL
;
267 if (objectType
== EGL_OBJECT_THREAD_KHR
)
268 thr
->CurrentObjectLabel
= thr
->Label
;
269 else if (objectType
== EGL_OBJECT_DISPLAY_KHR
&& disp
)
270 thr
->CurrentObjectLabel
= disp
->Label
;
272 thr
->CurrentObjectLabel
= object
->Label
;
277 _eglDebugReport(EGL_BAD_ALLOC
, funcName
, EGL_DEBUG_MSG_CRITICAL_KHR
, NULL
);
281 #define _EGL_FUNC_START(disp, objectType, object, ret) \
283 if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \
285 _eglUnlockDisplay(disp); \
291 * Convert an attribute list from EGLint[] to EGLAttrib[].
293 * Return an EGL error code. The output parameter out_attrib_list is modified
297 _eglConvertIntsToAttribs(const EGLint
*int_list
, EGLAttrib
**out_attrib_list
)
300 EGLAttrib
*attrib_list
;
303 while (int_list
[2*len
] != EGL_NONE
)
308 *out_attrib_list
= NULL
;
312 if (2*len
+ 1 > SIZE_MAX
/ sizeof(EGLAttrib
))
313 return EGL_BAD_ALLOC
;
315 attrib_list
= malloc((2*len
+ 1) * sizeof(EGLAttrib
));
317 return EGL_BAD_ALLOC
;
319 for (size_t i
= 0; i
< len
; ++i
) {
320 attrib_list
[2*i
+ 0] = int_list
[2*i
+ 0];
321 attrib_list
[2*i
+ 1] = int_list
[2*i
+ 1];
324 attrib_list
[2*len
] = EGL_NONE
;
326 *out_attrib_list
= attrib_list
;
332 _eglConvertAttribsToInt(const EGLAttrib
*attr_list
)
334 EGLint
*int_attribs
= NULL
;
336 /* Convert attributes from EGLAttrib[] to EGLint[] */
340 while (attr_list
[size
] != EGL_NONE
)
343 size
+= 1; /* add space for EGL_NONE */
345 int_attribs
= calloc(size
, sizeof(int_attribs
[0]));
349 for (i
= 0; i
< size
; i
++)
350 int_attribs
[i
] = attr_list
[i
];
357 * This is typically the first EGL function that an application calls.
358 * It associates a private _EGLDisplay object to the native display.
360 EGLDisplay EGLAPIENTRY
361 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
363 _EGLPlatformType plat
;
365 void *native_display_ptr
;
367 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
369 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
370 native_display_ptr
= (void*) nativeDisplay
;
372 plat
= _eglGetNativePlatform(native_display_ptr
);
373 dpy
= _eglFindDisplay(plat
, native_display_ptr
);
374 return _eglGetDisplayHandle(dpy
);
378 _eglGetPlatformDisplayCommon(EGLenum platform
, void *native_display
,
379 const EGLAttrib
*attrib_list
)
384 #ifdef HAVE_X11_PLATFORM
385 case EGL_PLATFORM_X11_EXT
:
386 dpy
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
389 #ifdef HAVE_DRM_PLATFORM
390 case EGL_PLATFORM_GBM_MESA
:
391 dpy
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
395 #ifdef HAVE_WAYLAND_PLATFORM
396 case EGL_PLATFORM_WAYLAND_EXT
:
397 dpy
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
401 #ifdef HAVE_SURFACELESS_PLATFORM
402 case EGL_PLATFORM_SURFACELESS_MESA
:
403 dpy
= _eglGetSurfacelessDisplay(native_display
, attrib_list
);
407 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
410 return _eglGetDisplayHandle(dpy
);
413 static EGLDisplay EGLAPIENTRY
414 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
415 const EGLint
*int_attribs
)
417 EGLAttrib
*attrib_list
;
420 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
422 if (_eglConvertIntsToAttribs(int_attribs
, &attrib_list
) != EGL_SUCCESS
)
423 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
425 display
= _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
430 EGLDisplay EGLAPIENTRY
431 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
432 const EGLAttrib
*attrib_list
)
434 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
435 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
439 * Copy the extension into the string and update the string pointer.
442 _eglAppendExtension(char **str
, const char *ext
)
445 size_t len
= strlen(ext
);
462 * Examine the individual extension enable/disable flags and recompute
463 * the driver's Extensions string.
466 _eglCreateExtensionsString(_EGLDisplay
*dpy
)
468 #define _EGL_CHECK_EXTENSION(ext) \
470 if (dpy->Extensions.ext) { \
471 _eglAppendExtension(&exts, "EGL_" #ext); \
472 assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
476 char *exts
= dpy
->ExtensionsString
;
478 /* Please keep these sorted alphabetically. */
479 _EGL_CHECK_EXTENSION(ANDROID_blob_cache
);
480 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
481 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
482 _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync
);
483 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
485 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
487 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
488 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
489 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
490 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers
);
491 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
493 _EGL_CHECK_EXTENSION(IMG_context_priority
);
495 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
496 _EGL_CHECK_EXTENSION(KHR_config_attribs
);
497 _EGL_CHECK_EXTENSION(KHR_context_flush_control
);
498 _EGL_CHECK_EXTENSION(KHR_create_context
);
499 _EGL_CHECK_EXTENSION(KHR_create_context_no_error
);
500 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
501 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
502 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
503 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
504 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
505 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
506 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
507 if (dpy
->Extensions
.KHR_image_base
&& dpy
->Extensions
.KHR_image_pixmap
)
508 dpy
->Extensions
.KHR_image
= EGL_TRUE
;
509 _EGL_CHECK_EXTENSION(KHR_image
);
510 _EGL_CHECK_EXTENSION(KHR_image_base
);
511 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
512 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
513 _EGL_CHECK_EXTENSION(KHR_partial_update
);
514 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
515 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
516 if (dpy
->Extensions
.EXT_swap_buffers_with_damage
)
517 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
518 _EGL_CHECK_EXTENSION(EXT_pixel_format_float
);
519 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
521 if (dpy
->Extensions
.KHR_no_config_context
)
522 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
523 _EGL_CHECK_EXTENSION(MESA_drm_image
);
524 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
526 _EGL_CHECK_EXTENSION(NOK_swap_region
);
527 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
529 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
531 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
532 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
534 #undef _EGL_CHECK_EXTENSION
538 _eglCreateAPIsString(_EGLDisplay
*dpy
)
540 if (dpy
->ClientAPIs
& EGL_OPENGL_BIT
)
541 strcat(dpy
->ClientAPIsString
, "OpenGL ");
543 if (dpy
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
544 dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
545 dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
546 strcat(dpy
->ClientAPIsString
, "OpenGL_ES ");
549 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
550 strcat(dpy
->ClientAPIsString
, "OpenVG ");
552 assert(strlen(dpy
->ClientAPIsString
) < sizeof(dpy
->ClientAPIsString
));
556 _eglComputeVersion(_EGLDisplay
*disp
)
560 if (disp
->Extensions
.KHR_fence_sync
&&
561 disp
->Extensions
.KHR_cl_event2
&&
562 disp
->Extensions
.KHR_wait_sync
&&
563 disp
->Extensions
.KHR_image_base
&&
564 disp
->Extensions
.KHR_gl_texture_2D_image
&&
565 disp
->Extensions
.KHR_gl_texture_3D_image
&&
566 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
567 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
568 disp
->Extensions
.KHR_create_context
&&
569 disp
->Extensions
.EXT_create_context_robustness
&&
570 disp
->Extensions
.KHR_get_all_proc_addresses
&&
571 disp
->Extensions
.KHR_gl_colorspace
&&
572 disp
->Extensions
.KHR_surfaceless_context
)
577 * This is typically the second EGL function that an application calls.
578 * Here we load/initialize the actual hardware driver.
580 EGLBoolean EGLAPIENTRY
581 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
583 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
585 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
588 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
590 if (!disp
->Initialized
) {
591 if (!_eglMatchDriver(disp
))
592 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
594 /* limit to APIs supported by core */
595 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
597 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
598 * classifies it as an EGL display extension, though conceptually it's an
599 * EGL client extension.
601 * From the EGL_KHR_get_all_proc_addresses spec:
603 * The EGL implementation must expose the name
604 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
605 * EGL_KHR_get_all_proc_addresses and supports
606 * EGL_EXT_client_extensions.
608 * Mesa unconditionally exposes both client extensions mentioned above,
609 * so the spec requires that each EGLDisplay unconditionally expose
610 * EGL_KHR_get_all_proc_addresses also.
612 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
614 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
615 * programs. It is driver agnostic and handled in the main EGL code.
617 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
619 _eglComputeVersion(disp
);
620 _eglCreateExtensionsString(disp
);
621 _eglCreateAPIsString(disp
);
622 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
623 "%d.%d (%s)", disp
->Version
/ 10, disp
->Version
% 10,
627 /* Update applications version of major and minor if not NULL */
628 if ((major
!= NULL
) && (minor
!= NULL
)) {
629 *major
= disp
->Version
/ 10;
630 *minor
= disp
->Version
% 10;
633 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
637 EGLBoolean EGLAPIENTRY
638 eglTerminate(EGLDisplay dpy
)
640 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
642 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
645 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
647 if (disp
->Initialized
) {
648 _EGLDriver
*drv
= disp
->Driver
;
650 drv
->API
.Terminate(drv
, disp
);
651 /* do not reset disp->Driver */
652 disp
->ClientAPIsString
[0] = 0;
653 disp
->Initialized
= EGL_FALSE
;
656 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
660 const char * EGLAPIENTRY
661 eglQueryString(EGLDisplay dpy
, EGLint name
)
666 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
667 const char *ret
= _eglGetClientExtensionString();
669 RETURN_EGL_SUCCESS(NULL
, ret
);
671 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
674 disp
= _eglLockDisplay(dpy
);
675 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
676 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
680 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
682 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
684 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
685 case EGL_CLIENT_APIS
:
686 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
688 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
693 EGLBoolean EGLAPIENTRY
694 eglGetConfigs(EGLDisplay dpy
, 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
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
706 RETURN_EGL_EVAL(disp
, ret
);
710 EGLBoolean EGLAPIENTRY
711 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
712 EGLint config_size
, EGLint
*num_config
)
714 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
718 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
720 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
721 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
722 config_size
, num_config
);
724 RETURN_EGL_EVAL(disp
, ret
);
728 EGLBoolean EGLAPIENTRY
729 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
730 EGLint attribute
, EGLint
*value
)
732 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
733 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
737 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
739 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
740 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
742 RETURN_EGL_EVAL(disp
, ret
);
746 EGLContext EGLAPIENTRY
747 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
748 const EGLint
*attrib_list
)
750 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
751 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
752 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
754 _EGLContext
*context
;
757 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
759 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
761 if (config
!= EGL_NO_CONFIG_KHR
)
762 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
763 else if (!disp
->Extensions
.KHR_no_config_context
)
764 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
766 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
767 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
769 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
770 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
772 RETURN_EGL_EVAL(disp
, ret
);
776 EGLBoolean EGLAPIENTRY
777 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
779 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
780 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
784 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
786 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
787 _eglUnlinkContext(context
);
788 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
790 RETURN_EGL_EVAL(disp
, ret
);
794 EGLBoolean EGLAPIENTRY
795 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
798 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
799 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
800 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
801 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
805 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
808 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
811 /* display is allowed to be uninitialized under certain condition */
812 if (!disp
->Initialized
) {
813 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
814 ctx
!= EGL_NO_CONTEXT
)
815 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
818 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
820 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
821 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
822 if (!draw_surf
|| !read_surf
) {
823 /* From the EGL 1.4 (20130211) spec:
825 * To release the current context without assigning a new one, set ctx
826 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
828 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
829 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
831 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
832 (!read_surf
&& read
!= EGL_NO_SURFACE
))
833 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
834 if (draw_surf
|| read_surf
)
835 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
838 /* If a native window underlying either draw or read is no longer valid,
839 * an EGL_BAD_NATIVE_WINDOW error is generated.
841 if (draw_surf
&& draw_surf
->Lost
)
842 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
843 if (read_surf
&& read_surf
->Lost
)
844 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
846 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
848 RETURN_EGL_EVAL(disp
, ret
);
852 EGLBoolean EGLAPIENTRY
853 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
854 EGLint attribute
, EGLint
*value
)
856 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
857 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
861 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
863 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
864 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
866 RETURN_EGL_EVAL(disp
, ret
);
871 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
872 void *native_window
, const EGLint
*attrib_list
)
874 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
880 if (native_window
== NULL
)
881 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
883 #ifdef HAVE_SURFACELESS_PLATFORM
884 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
885 /* From the EGL_MESA_platform_surfaceless spec (v1):
887 * eglCreatePlatformWindowSurface fails when called with a <display>
888 * that belongs to the surfaceless platform. It returns
889 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
890 * justification for this unconditional failure is that the
891 * surfaceless platform has no native windows, and therefore the
892 * <native_window> parameter is always invalid.
894 * This check must occur before checking the EGLConfig, which emits
897 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
901 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
903 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
904 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
906 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
908 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
910 RETURN_EGL_EVAL(disp
, ret
);
914 EGLSurface EGLAPIENTRY
915 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
916 EGLNativeWindowType window
, const EGLint
*attrib_list
)
918 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
920 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
921 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
922 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
927 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
929 #ifdef HAVE_X11_PLATFORM
930 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
931 /* The `native_window` parameter for the X11 platform differs between
932 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
933 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
934 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
935 * `Window*`. Convert `Window*` to `Window` because that's what
936 * dri2_x11_create_window_surface() expects.
938 return (void *)(* (Window
*) native_window
);
941 return native_window
;
944 static EGLSurface EGLAPIENTRY
945 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
947 const EGLint
*attrib_list
)
949 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
951 native_window
= _fixupNativeWindow(disp
, native_window
);
953 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
954 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
959 EGLSurface EGLAPIENTRY
960 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
962 const EGLAttrib
*attrib_list
)
964 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
968 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
970 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
971 if (attrib_list
&& !int_attribs
)
972 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
974 native_window
= _fixupNativeWindow(disp
, native_window
);
975 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
982 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
984 #ifdef HAVE_X11_PLATFORM
985 /* The `native_pixmap` parameter for the X11 platform differs between
986 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
987 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
988 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
989 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
990 * dri2_x11_create_pixmap_surface() expects.
992 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
993 return (void *)(* (Pixmap
*) native_pixmap
);
995 return native_pixmap
;
999 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1000 void *native_pixmap
, const EGLint
*attrib_list
)
1002 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1007 #if HAVE_SURFACELESS_PLATFORM
1008 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
1009 /* From the EGL_MESA_platform_surfaceless spec (v1):
1011 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1012 * also fails when called with a <display> that belongs to the
1013 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1014 * EGL_BAD_NATIVE_PIXMAP.
1016 * This check must occur before checking the EGLConfig, which emits
1019 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1023 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1025 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1026 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1028 if (native_pixmap
== NULL
)
1029 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1031 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1033 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1035 RETURN_EGL_EVAL(disp
, ret
);
1039 EGLSurface EGLAPIENTRY
1040 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1041 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1043 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1045 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1046 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1047 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1051 static EGLSurface EGLAPIENTRY
1052 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1053 void *native_pixmap
,
1054 const EGLint
*attrib_list
)
1056 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1058 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1059 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1060 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1065 EGLSurface EGLAPIENTRY
1066 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1067 void *native_pixmap
,
1068 const EGLAttrib
*attrib_list
)
1070 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1072 EGLint
*int_attribs
;
1074 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1076 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1077 if (attrib_list
&& !int_attribs
)
1078 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1080 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1081 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1088 EGLSurface EGLAPIENTRY
1089 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1090 const EGLint
*attrib_list
)
1092 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1093 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1098 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1099 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1101 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1102 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1104 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1105 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1107 RETURN_EGL_EVAL(disp
, ret
);
1111 EGLBoolean EGLAPIENTRY
1112 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1114 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1115 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1119 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1120 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1121 _eglUnlinkSurface(surf
);
1122 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1124 RETURN_EGL_EVAL(disp
, ret
);
1127 EGLBoolean EGLAPIENTRY
1128 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1129 EGLint attribute
, EGLint
*value
)
1131 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1132 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1136 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1137 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1138 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1140 RETURN_EGL_EVAL(disp
, ret
);
1143 EGLBoolean EGLAPIENTRY
1144 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1145 EGLint attribute
, EGLint value
)
1147 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1148 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1152 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1153 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1154 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1156 RETURN_EGL_EVAL(disp
, ret
);
1160 EGLBoolean EGLAPIENTRY
1161 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1163 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1164 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1168 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1169 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1170 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1172 RETURN_EGL_EVAL(disp
, ret
);
1176 EGLBoolean EGLAPIENTRY
1177 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1179 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1180 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1184 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1185 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1186 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1188 RETURN_EGL_EVAL(disp
, ret
);
1192 EGLBoolean EGLAPIENTRY
1193 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1195 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1196 _EGLContext
*ctx
= _eglGetCurrentContext();
1197 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1201 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1202 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1204 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1205 ctx
->Resource
.Display
!= disp
)
1206 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1208 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1209 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1211 interval
= CLAMP(interval
,
1212 surf
->Config
->MinSwapInterval
,
1213 surf
->Config
->MaxSwapInterval
);
1215 if (surf
->SwapInterval
!= interval
)
1216 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1221 surf
->SwapInterval
= interval
;
1223 RETURN_EGL_EVAL(disp
, ret
);
1227 EGLBoolean EGLAPIENTRY
1228 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1230 _EGLContext
*ctx
= _eglGetCurrentContext();
1231 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1232 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1236 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1237 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1239 /* surface must be bound to current context in EGL 1.4 */
1240 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1241 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1242 surf
!= ctx
->DrawSurface
)
1243 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1246 /* From the EGL 1.5 spec:
1248 * If eglSwapBuffers is called and the native window associated with
1249 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1253 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1255 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1257 /* EGL_KHR_partial_update
1258 * Frame boundary successfully reached,
1259 * reset damage region and reset BufferAgeRead
1262 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1263 surf
->BufferAgeRead
= EGL_FALSE
;
1266 RETURN_EGL_EVAL(disp
, ret
);
1271 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1272 EGLint
*rects
, EGLint n_rects
)
1274 _EGLContext
*ctx
= _eglGetCurrentContext();
1278 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1280 /* surface must be bound to current context in EGL 1.4 */
1281 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1282 surf
!= ctx
->DrawSurface
)
1283 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1285 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1286 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1288 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1290 /* EGL_KHR_partial_update
1291 * Frame boundary successfully reached,
1292 * reset damage region and reset BufferAgeRead
1295 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1296 surf
->BufferAgeRead
= EGL_FALSE
;
1299 RETURN_EGL_EVAL(disp
, ret
);
1302 static EGLBoolean EGLAPIENTRY
1303 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1304 EGLint
*rects
, EGLint n_rects
)
1306 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1307 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1308 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1309 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1312 static EGLBoolean EGLAPIENTRY
1313 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1314 EGLint
*rects
, EGLint n_rects
)
1316 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1317 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1318 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1319 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1323 * Clamp the rectangles so that they lie within the surface.
1327 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1328 EGLint
*rects
, EGLint n_rects
)
1331 EGLint surf_height
= surf
->Height
;
1332 EGLint surf_width
= surf
->Width
;
1334 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1335 EGLint x1
, y1
, x2
, y2
;
1338 x2
= rects
[i
+ 2] + x1
;
1339 y2
= rects
[i
+ 3] + y1
;
1341 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1342 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1343 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1344 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1348 static EGLBoolean EGLAPIENTRY
1349 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1350 EGLint
*rects
, EGLint n_rects
)
1352 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1353 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1354 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1355 _EGLContext
*ctx
= _eglGetCurrentContext();
1358 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1360 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1361 surf
->Type
!= EGL_WINDOW_BIT
||
1362 ctx
->DrawSurface
!= surf
||
1363 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1364 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1366 /* If the damage region is already set or
1367 * buffer age is not queried between
1368 * frame boundaries, throw bad access error
1371 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1372 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1374 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1375 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1378 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1380 RETURN_EGL_EVAL(disp
, ret
);
1383 EGLBoolean EGLAPIENTRY
1384 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1386 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1387 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1390 void *native_pixmap_ptr
;
1392 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1393 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1394 native_pixmap_ptr
= (void*) target
;
1396 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1397 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1399 RETURN_EGL_EVAL(disp
, ret
);
1404 _eglWaitClientCommon(void)
1406 _EGLContext
*ctx
= _eglGetCurrentContext();
1412 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1414 disp
= ctx
->Resource
.Display
;
1415 mtx_lock(&disp
->Mutex
);
1417 /* let bad current context imply bad current surface */
1418 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1419 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1420 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1422 /* a valid current context implies an initialized current display */
1423 assert(disp
->Initialized
);
1425 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1427 RETURN_EGL_EVAL(disp
, ret
);
1430 EGLBoolean EGLAPIENTRY
1433 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1434 return _eglWaitClientCommon();
1437 EGLBoolean EGLAPIENTRY
1440 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1441 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1442 return _eglWaitClientCommon();
1446 EGLBoolean EGLAPIENTRY
1447 eglWaitNative(EGLint engine
)
1449 _EGLContext
*ctx
= _eglGetCurrentContext();
1455 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1457 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1459 disp
= ctx
->Resource
.Display
;
1460 mtx_lock(&disp
->Mutex
);
1462 /* let bad current context imply bad current surface */
1463 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1464 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1465 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1467 /* a valid current context implies an initialized current display */
1468 assert(disp
->Initialized
);
1470 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1472 RETURN_EGL_EVAL(disp
, ret
);
1476 EGLDisplay EGLAPIENTRY
1477 eglGetCurrentDisplay(void)
1479 _EGLContext
*ctx
= _eglGetCurrentContext();
1482 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1484 RETURN_EGL_SUCCESS(NULL
, ret
);
1488 EGLContext EGLAPIENTRY
1489 eglGetCurrentContext(void)
1491 _EGLContext
*ctx
= _eglGetCurrentContext();
1494 ret
= _eglGetContextHandle(ctx
);
1496 RETURN_EGL_SUCCESS(NULL
, ret
);
1500 EGLSurface EGLAPIENTRY
1501 eglGetCurrentSurface(EGLint readdraw
)
1503 _EGLContext
*ctx
= _eglGetCurrentContext();
1504 EGLint err
= EGL_SUCCESS
;
1508 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1511 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1515 surf
= ctx
->DrawSurface
;
1518 surf
= ctx
->ReadSurface
;
1522 err
= EGL_BAD_PARAMETER
;
1526 ret
= _eglGetSurfaceHandle(surf
);
1528 RETURN_EGL_ERROR(NULL
, err
, ret
);
1535 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1536 EGLint e
= t
->LastError
;
1537 if (!_eglIsCurrentThreadDummy())
1538 t
->LastError
= EGL_SUCCESS
;
1548 * Specify the client API to use for subsequent calls including:
1549 * eglCreateContext()
1550 * eglGetCurrentContext()
1551 * eglGetCurrentDisplay()
1552 * eglGetCurrentSurface()
1553 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1556 * See section 3.7 "Rendering Context" in the EGL specification for details.
1558 EGLBoolean EGLAPIENTRY
1559 eglBindAPI(EGLenum api
)
1563 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1565 t
= _eglGetCurrentThread();
1566 if (_eglIsCurrentThreadDummy())
1567 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1569 if (!_eglIsApiValid(api
))
1570 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1572 t
->CurrentAPI
= api
;
1574 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1579 * Return the last value set with eglBindAPI().
1584 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1587 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1588 ret
= t
->CurrentAPI
;
1590 RETURN_EGL_SUCCESS(NULL
, ret
);
1594 EGLSurface EGLAPIENTRY
1595 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1596 EGLClientBuffer buffer
, EGLConfig config
,
1597 const EGLint
*attrib_list
)
1599 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1600 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1605 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1607 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1609 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1611 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1613 RETURN_EGL_EVAL(disp
, ret
);
1617 EGLBoolean EGLAPIENTRY
1618 eglReleaseThread(void)
1620 /* unbind current contexts */
1621 if (!_eglIsCurrentThreadDummy()) {
1622 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1623 _EGLContext
*ctx
= t
->CurrentContext
;
1625 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1628 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1631 mtx_lock(&disp
->Mutex
);
1633 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1634 mtx_unlock(&disp
->Mutex
);
1638 _eglDestroyCurrentThread();
1640 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1645 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1646 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1648 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1653 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1654 if (!disp
->Extensions
.KHR_image_base
)
1655 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1656 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1657 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1658 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1659 * <ctx> must be EGL_NO_CONTEXT..."
1661 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1662 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1664 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1666 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1668 RETURN_EGL_EVAL(disp
, ret
);
1671 static EGLImage EGLAPIENTRY
1672 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1673 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1675 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1676 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1677 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1681 EGLImage EGLAPIENTRY
1682 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1683 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1685 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1687 EGLint
*int_attribs
;
1689 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1691 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1692 if (attr_list
&& !int_attribs
)
1693 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1695 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1702 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1707 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1708 if (!disp
->Extensions
.KHR_image_base
)
1709 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1711 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1713 _eglUnlinkImage(img
);
1714 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1716 RETURN_EGL_EVAL(disp
, ret
);
1719 EGLBoolean EGLAPIENTRY
1720 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1722 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1723 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1724 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1725 return _eglDestroyImageCommon(disp
, img
);
1728 static EGLBoolean EGLAPIENTRY
1729 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1731 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1732 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1733 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1734 return _eglDestroyImageCommon(disp
, img
);
1739 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1740 EGLBoolean orig_is_EGLAttrib
,
1741 EGLenum invalid_type_error
)
1743 _EGLContext
*ctx
= _eglGetCurrentContext();
1748 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1750 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1751 /* There exist two EGLAttrib variants of eglCreateSync*:
1752 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1753 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1754 * support as a proxy for EGL 1.5 support, even though that's not
1755 * entirely correct (though _eglComputeVersion does the same).
1757 * The EGL spec provides no guidance on how to handle unsupported
1758 * functions. EGL_BAD_MATCH seems reasonable.
1760 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1763 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1764 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1765 * error is generated.
1768 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1769 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1771 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1772 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1773 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1774 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1777 case EGL_SYNC_FENCE_KHR
:
1778 if (!disp
->Extensions
.KHR_fence_sync
)
1779 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1781 case EGL_SYNC_REUSABLE_KHR
:
1782 if (!disp
->Extensions
.KHR_reusable_sync
)
1783 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1785 case EGL_SYNC_CL_EVENT_KHR
:
1786 if (!disp
->Extensions
.KHR_cl_event2
)
1787 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1789 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1790 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1791 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1794 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1797 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1798 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1800 RETURN_EGL_EVAL(disp
, ret
);
1804 static EGLSync EGLAPIENTRY
1805 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1807 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1808 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1811 EGLAttrib
*attrib_list
;
1814 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1815 attrib_list
= (EGLAttrib
*) int_list
;
1817 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1818 if (err
!= EGL_SUCCESS
)
1819 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1822 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1825 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1828 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1833 static EGLSync EGLAPIENTRY
1834 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1836 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1837 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1838 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1844 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1846 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1847 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1848 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1854 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1859 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1860 assert(disp
->Extensions
.KHR_reusable_sync
||
1861 disp
->Extensions
.KHR_fence_sync
||
1862 disp
->Extensions
.ANDROID_native_fence_sync
);
1865 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1867 RETURN_EGL_EVAL(disp
, ret
);
1870 EGLBoolean EGLAPIENTRY
1871 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1873 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1874 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1875 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1876 return _eglDestroySync(disp
, s
);
1879 static EGLBoolean EGLAPIENTRY
1880 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1882 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1883 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1884 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1885 return _eglDestroySync(disp
, s
);
1890 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1891 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1896 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1897 assert(disp
->Extensions
.KHR_reusable_sync
||
1898 disp
->Extensions
.KHR_fence_sync
||
1899 disp
->Extensions
.ANDROID_native_fence_sync
);
1901 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1902 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1904 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1905 * unlocked here to allow other threads also to be able to
1906 * go into waiting state.
1909 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1910 _eglUnlockDisplay(dpy
);
1912 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1915 * 'disp' is already unlocked for reusable sync type,
1916 * so passing 'NULL' to bypass unlocking display.
1918 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1919 RETURN_EGL_EVAL(NULL
, ret
);
1921 RETURN_EGL_EVAL(disp
, ret
);
1925 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
1926 EGLint flags
, EGLTime timeout
)
1928 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1929 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1930 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1931 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1934 static EGLint EGLAPIENTRY
1935 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
1936 EGLint flags
, EGLTime timeout
)
1938 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1939 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1940 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1941 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1946 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
1948 _EGLContext
*ctx
= _eglGetCurrentContext();
1952 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1953 assert(disp
->Extensions
.KHR_wait_sync
);
1955 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1956 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1957 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1959 /* the API doesn't allow any flags yet */
1961 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1963 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1965 RETURN_EGL_EVAL(disp
, ret
);
1968 static EGLint EGLAPIENTRY
1969 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1971 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1972 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1973 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1974 return _eglWaitSyncCommon(disp
, s
, flags
);
1978 EGLBoolean EGLAPIENTRY
1979 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1981 /* The KHR version returns EGLint, while the core version returns
1982 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1985 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1986 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1987 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1988 return _eglWaitSyncCommon(disp
, s
, flags
);
1992 static EGLBoolean EGLAPIENTRY
1993 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
1995 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1996 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2000 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2002 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2003 assert(disp
->Extensions
.KHR_reusable_sync
);
2004 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2006 RETURN_EGL_EVAL(disp
, ret
);
2011 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2016 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2017 assert(disp
->Extensions
.KHR_reusable_sync
||
2018 disp
->Extensions
.KHR_fence_sync
||
2019 disp
->Extensions
.ANDROID_native_fence_sync
);
2020 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2022 RETURN_EGL_EVAL(disp
, ret
);
2025 EGLBoolean EGLAPIENTRY
2026 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2028 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2029 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2030 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2031 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2035 static EGLBoolean EGLAPIENTRY
2036 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2038 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2039 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2043 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2046 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2049 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2051 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2053 * If any error occurs, <*value> is not modified.
2055 if (result
== EGL_FALSE
)
2062 static EGLint EGLAPIENTRY
2063 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2065 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2066 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2070 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2072 /* the spec doesn't seem to specify what happens if the fence
2073 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2076 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2077 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2079 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2080 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2081 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2083 RETURN_EGL_EVAL(disp
, ret
);
2086 static EGLBoolean EGLAPIENTRY
2087 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2088 EGLint numRects
, const EGLint
*rects
)
2090 _EGLContext
*ctx
= _eglGetCurrentContext();
2091 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2092 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2096 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2098 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2100 if (!disp
->Extensions
.NOK_swap_region
)
2101 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2103 /* surface must be bound to current context in EGL 1.4 */
2104 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2105 surf
!= ctx
->DrawSurface
)
2106 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2108 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2110 RETURN_EGL_EVAL(disp
, ret
);
2114 static EGLImage EGLAPIENTRY
2115 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2117 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2122 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2124 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2125 if (!disp
->Extensions
.MESA_drm_image
)
2126 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2128 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2129 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2131 RETURN_EGL_EVAL(disp
, ret
);
2134 static EGLBoolean EGLAPIENTRY
2135 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2136 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2138 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2139 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2143 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2145 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2146 assert(disp
->Extensions
.MESA_drm_image
);
2149 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2151 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2153 RETURN_EGL_EVAL(disp
, ret
);
2159 static EGLBoolean EGLAPIENTRY
2160 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2162 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2166 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2168 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2169 assert(disp
->Extensions
.WL_bind_wayland_display
);
2172 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2174 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2176 RETURN_EGL_EVAL(disp
, ret
);
2179 static EGLBoolean EGLAPIENTRY
2180 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2182 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2186 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2188 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2189 assert(disp
->Extensions
.WL_bind_wayland_display
);
2192 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2194 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2196 RETURN_EGL_EVAL(disp
, ret
);
2199 static EGLBoolean EGLAPIENTRY
2200 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2201 EGLint attribute
, EGLint
*value
)
2203 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2207 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2209 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2210 assert(disp
->Extensions
.WL_bind_wayland_display
);
2213 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2215 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2217 RETURN_EGL_EVAL(disp
, ret
);
2221 static struct wl_buffer
* EGLAPIENTRY
2222 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2224 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2227 struct wl_buffer
*ret
;
2229 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2231 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2232 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2233 RETURN_EGL_EVAL(disp
, NULL
);
2235 img
= _eglLookupImage(image
, disp
);
2238 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2240 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2242 RETURN_EGL_EVAL(disp
, ret
);
2245 static EGLBoolean EGLAPIENTRY
2246 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2247 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2249 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2250 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2254 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2256 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2258 if (!disp
->Extensions
.NV_post_sub_buffer
)
2259 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2261 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2263 RETURN_EGL_EVAL(disp
, ret
);
2266 static EGLBoolean EGLAPIENTRY
2267 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
2268 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2271 _EGLDisplay
*disp
= _eglLockDisplay(display
);
2272 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2276 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2278 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2279 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2280 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2282 if (!ust
|| !msc
|| !sbc
)
2283 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2285 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2287 RETURN_EGL_EVAL(disp
, ret
);
2290 static EGLBoolean EGLAPIENTRY
2291 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2292 EGLint
*fourcc
, EGLint
*nplanes
,
2293 EGLuint64KHR
*modifiers
)
2295 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2296 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2300 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2302 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2303 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2306 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2308 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2311 RETURN_EGL_EVAL(disp
, ret
);
2314 static EGLBoolean EGLAPIENTRY
2315 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2316 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2318 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2319 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2323 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2325 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2326 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2329 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2331 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2333 RETURN_EGL_EVAL(disp
, ret
);
2336 static EGLint EGLAPIENTRY
2337 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2340 _EGLDisplay
*disp
= NULL
;
2341 _EGLResourceType type
;
2343 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2345 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2346 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2348 if (!_eglIsCurrentThreadDummy()) {
2353 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2356 disp
= _eglLockDisplay(dpy
);
2358 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2360 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2361 if (dpy
!= (EGLDisplay
) object
)
2362 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2364 disp
->Label
= label
;
2365 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2368 switch (objectType
) {
2369 case EGL_OBJECT_CONTEXT_KHR
:
2370 type
= _EGL_RESOURCE_CONTEXT
;
2372 case EGL_OBJECT_SURFACE_KHR
:
2373 type
= _EGL_RESOURCE_SURFACE
;
2375 case EGL_OBJECT_IMAGE_KHR
:
2376 type
= _EGL_RESOURCE_IMAGE
;
2378 case EGL_OBJECT_SYNC_KHR
:
2379 type
= _EGL_RESOURCE_SYNC
;
2381 case EGL_OBJECT_STREAM_KHR
:
2383 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2386 if (_eglCheckResource(object
, type
, disp
)) {
2387 _EGLResource
*res
= (_EGLResource
*) object
;
2390 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2393 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2396 static EGLint EGLAPIENTRY
2397 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2398 const EGLAttrib
*attrib_list
)
2400 unsigned int newEnabled
;
2402 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2404 mtx_lock(_eglGlobal
.Mutex
);
2406 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2407 if (attrib_list
!= NULL
) {
2410 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2411 switch (attrib_list
[i
]) {
2412 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2413 case EGL_DEBUG_MSG_ERROR_KHR
:
2414 case EGL_DEBUG_MSG_WARN_KHR
:
2415 case EGL_DEBUG_MSG_INFO_KHR
:
2416 if (attrib_list
[i
+ 1])
2417 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2419 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2422 // On error, set the last error code, call the current
2423 // debug callback, and return the error code.
2424 mtx_unlock(_eglGlobal
.Mutex
);
2425 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2426 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2427 return EGL_BAD_ATTRIBUTE
;
2432 if (callback
!= NULL
) {
2433 _eglGlobal
.debugCallback
= callback
;
2434 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2436 _eglGlobal
.debugCallback
= NULL
;
2437 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2440 mtx_unlock(_eglGlobal
.Mutex
);
2444 static EGLBoolean EGLAPIENTRY
2445 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2447 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2449 mtx_lock(_eglGlobal
.Mutex
);
2451 switch (attribute
) {
2452 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2453 case EGL_DEBUG_MSG_ERROR_KHR
:
2454 case EGL_DEBUG_MSG_WARN_KHR
:
2455 case EGL_DEBUG_MSG_INFO_KHR
:
2456 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2461 case EGL_DEBUG_CALLBACK_KHR
:
2462 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2465 mtx_unlock(_eglGlobal
.Mutex
);
2466 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2467 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2471 mtx_unlock(_eglGlobal
.Mutex
);
2476 _eglFunctionCompare(const void *key
, const void *elem
)
2478 const char *procname
= key
;
2479 const struct _egl_entrypoint
*entrypoint
= elem
;
2480 return strcmp(procname
, entrypoint
->name
);
2483 static EGLBoolean EGLAPIENTRY
2484 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2485 EGLint
*formats
, EGLint
*num_formats
)
2487 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2491 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2493 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2495 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2498 RETURN_EGL_EVAL(disp
, ret
);
2501 static EGLBoolean EGLAPIENTRY
2502 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2503 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2504 EGLint
*num_modifiers
)
2506 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2510 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2512 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2514 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2515 modifiers
, external_only
,
2518 RETURN_EGL_EVAL(disp
, ret
);
2521 static void EGLAPIENTRY
2522 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2523 EGLGetBlobFuncANDROID get
)
2525 /* This function does not return anything so we cannot
2526 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2528 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2529 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2531 _eglUnlockDisplay(disp
);
2535 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2538 _eglUnlockDisplay(disp
);
2543 _eglError(EGL_BAD_PARAMETER
,
2544 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2545 _eglUnlockDisplay(disp
);
2549 if (disp
->BlobCacheSet
) {
2550 _eglError(EGL_BAD_PARAMETER
,
2551 "eglSetBlobCacheFuncsANDROID: functions already set");
2552 _eglUnlockDisplay(disp
);
2556 disp
->BlobCacheSet
= set
;
2557 disp
->BlobCacheGet
= get
;
2559 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2561 _eglUnlockDisplay(disp
);
2564 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2565 eglGetProcAddress(const char *procname
)
2567 static const struct _egl_entrypoint egl_functions
[] = {
2568 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2569 #include "eglentrypoint.h"
2570 #undef EGL_ENTRYPOINT
2572 _EGLProc ret
= NULL
;
2575 RETURN_EGL_SUCCESS(NULL
, NULL
);
2577 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2579 if (strncmp(procname
, "egl", 3) == 0) {
2580 const struct _egl_entrypoint
*entrypoint
=
2582 egl_functions
, ARRAY_SIZE(egl_functions
),
2583 sizeof(egl_functions
[0]),
2584 _eglFunctionCompare
);
2586 ret
= entrypoint
->function
;
2590 ret
= _eglGetDriverProc(procname
);
2592 RETURN_EGL_SUCCESS(NULL
, ret
);
2596 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2597 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2601 *disp
= _eglLockDisplay(dpy
);
2602 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2604 _eglUnlockDisplay(*disp
);
2605 return MESA_GLINTEROP_INVALID_DISPLAY
;
2608 *drv
= (*disp
)->Driver
;
2610 *ctx
= _eglLookupContext(context
, *disp
);
2612 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2613 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2614 _eglUnlockDisplay(*disp
);
2615 return MESA_GLINTEROP_INVALID_CONTEXT
;
2618 return MESA_GLINTEROP_SUCCESS
;
2622 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2623 struct mesa_glinterop_device_info
*out
)
2630 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2631 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2634 if (drv
->API
.GLInteropQueryDeviceInfo
)
2635 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2637 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2639 _eglUnlockDisplay(disp
);
2644 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2645 struct mesa_glinterop_export_in
*in
,
2646 struct mesa_glinterop_export_out
*out
)
2653 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2654 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2657 if (drv
->API
.GLInteropExportObject
)
2658 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2660 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2662 _eglUnlockDisplay(disp
);