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 EGLint
*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
*attrib_list
)
417 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
418 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
421 EGLDisplay EGLAPIENTRY
422 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
423 const EGLAttrib
*attrib_list
)
428 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
430 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
431 if (attrib_list
&& !int_attribs
)
432 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
434 display
= _eglGetPlatformDisplayCommon(platform
, native_display
, int_attribs
);
440 * Copy the extension into the string and update the string pointer.
443 _eglAppendExtension(char **str
, const char *ext
)
446 size_t len
= strlen(ext
);
463 * Examine the individual extension enable/disable flags and recompute
464 * the driver's Extensions string.
467 _eglCreateExtensionsString(_EGLDisplay
*dpy
)
469 #define _EGL_CHECK_EXTENSION(ext) \
471 if (dpy->Extensions.ext) { \
472 _eglAppendExtension(&exts, "EGL_" #ext); \
473 assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
477 char *exts
= dpy
->ExtensionsString
;
479 /* Please keep these sorted alphabetically. */
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 _eglAppendExtension(&exts
, "EGL_KHR_image");
509 _EGL_CHECK_EXTENSION(KHR_image_base
);
510 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
511 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
512 _EGL_CHECK_EXTENSION(KHR_partial_update
);
513 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
514 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
515 if (dpy
->Extensions
.EXT_swap_buffers_with_damage
)
516 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
517 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
519 if (dpy
->Extensions
.KHR_no_config_context
)
520 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
521 _EGL_CHECK_EXTENSION(MESA_drm_image
);
522 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
524 _EGL_CHECK_EXTENSION(NOK_swap_region
);
525 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
527 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
529 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
530 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
532 #undef _EGL_CHECK_EXTENSION
536 _eglCreateAPIsString(_EGLDisplay
*dpy
)
538 if (dpy
->ClientAPIs
& EGL_OPENGL_BIT
)
539 strcat(dpy
->ClientAPIsString
, "OpenGL ");
541 if (dpy
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
542 dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
543 dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
544 strcat(dpy
->ClientAPIsString
, "OpenGL_ES ");
547 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
548 strcat(dpy
->ClientAPIsString
, "OpenVG ");
550 assert(strlen(dpy
->ClientAPIsString
) < sizeof(dpy
->ClientAPIsString
));
554 _eglComputeVersion(_EGLDisplay
*disp
)
558 if (disp
->Extensions
.KHR_fence_sync
&&
559 disp
->Extensions
.KHR_cl_event2
&&
560 disp
->Extensions
.KHR_wait_sync
&&
561 disp
->Extensions
.KHR_image_base
&&
562 disp
->Extensions
.KHR_gl_texture_2D_image
&&
563 disp
->Extensions
.KHR_gl_texture_3D_image
&&
564 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
565 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
566 disp
->Extensions
.KHR_create_context
&&
567 disp
->Extensions
.EXT_create_context_robustness
&&
568 disp
->Extensions
.KHR_get_all_proc_addresses
&&
569 disp
->Extensions
.KHR_gl_colorspace
&&
570 disp
->Extensions
.KHR_surfaceless_context
)
575 * This is typically the second EGL function that an application calls.
576 * Here we load/initialize the actual hardware driver.
578 EGLBoolean EGLAPIENTRY
579 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
581 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
583 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
586 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
588 if (!disp
->Initialized
) {
589 if (!_eglMatchDriver(disp
))
590 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
592 /* limit to APIs supported by core */
593 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
595 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
596 * classifies it as an EGL display extension, though conceptually it's an
597 * EGL client extension.
599 * From the EGL_KHR_get_all_proc_addresses spec:
601 * The EGL implementation must expose the name
602 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
603 * EGL_KHR_get_all_proc_addresses and supports
604 * EGL_EXT_client_extensions.
606 * Mesa unconditionally exposes both client extensions mentioned above,
607 * so the spec requires that each EGLDisplay unconditionally expose
608 * EGL_KHR_get_all_proc_addresses also.
610 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
612 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
613 * programs. It is driver agnostic and handled in the main EGL code.
615 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
617 _eglComputeVersion(disp
);
618 _eglCreateExtensionsString(disp
);
619 _eglCreateAPIsString(disp
);
620 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
621 "%d.%d (%s)", disp
->Version
/ 10, disp
->Version
% 10,
625 /* Update applications version of major and minor if not NULL */
626 if ((major
!= NULL
) && (minor
!= NULL
)) {
627 *major
= disp
->Version
/ 10;
628 *minor
= disp
->Version
% 10;
631 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
635 EGLBoolean EGLAPIENTRY
636 eglTerminate(EGLDisplay dpy
)
638 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
640 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
643 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
645 if (disp
->Initialized
) {
646 _EGLDriver
*drv
= disp
->Driver
;
648 drv
->API
.Terminate(drv
, disp
);
649 /* do not reset disp->Driver */
650 disp
->ClientAPIsString
[0] = 0;
651 disp
->Initialized
= EGL_FALSE
;
654 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
658 const char * EGLAPIENTRY
659 eglQueryString(EGLDisplay dpy
, EGLint name
)
664 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
665 const char *ret
= _eglGetClientExtensionString();
667 RETURN_EGL_SUCCESS(NULL
, ret
);
669 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
672 disp
= _eglLockDisplay(dpy
);
673 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
674 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
678 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
680 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
682 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
683 case EGL_CLIENT_APIS
:
684 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
686 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
691 EGLBoolean EGLAPIENTRY
692 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
693 EGLint config_size
, EGLint
*num_config
)
695 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
699 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
701 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
702 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
704 RETURN_EGL_EVAL(disp
, ret
);
708 EGLBoolean EGLAPIENTRY
709 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
710 EGLint config_size
, EGLint
*num_config
)
712 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
716 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
718 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
719 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
720 config_size
, num_config
);
722 RETURN_EGL_EVAL(disp
, ret
);
726 EGLBoolean EGLAPIENTRY
727 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
728 EGLint attribute
, EGLint
*value
)
730 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
731 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
735 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
737 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
738 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
740 RETURN_EGL_EVAL(disp
, ret
);
744 EGLContext EGLAPIENTRY
745 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
746 const EGLint
*attrib_list
)
748 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
749 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
750 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
752 _EGLContext
*context
;
755 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
757 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
759 if (config
!= EGL_NO_CONFIG_KHR
)
760 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
761 else if (!disp
->Extensions
.KHR_no_config_context
)
762 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
764 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
765 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
767 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
768 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
770 RETURN_EGL_EVAL(disp
, ret
);
774 EGLBoolean EGLAPIENTRY
775 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
777 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
778 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
782 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
784 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
785 _eglUnlinkContext(context
);
786 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
788 RETURN_EGL_EVAL(disp
, ret
);
792 EGLBoolean EGLAPIENTRY
793 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
796 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
797 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
798 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
799 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
803 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
806 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
809 /* display is allowed to be uninitialized under certain condition */
810 if (!disp
->Initialized
) {
811 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
812 ctx
!= EGL_NO_CONTEXT
)
813 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
816 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
818 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
819 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
820 if (!draw_surf
|| !read_surf
) {
821 /* From the EGL 1.4 (20130211) spec:
823 * To release the current context without assigning a new one, set ctx
824 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
826 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
827 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
829 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
830 (!read_surf
&& read
!= EGL_NO_SURFACE
))
831 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
832 if (draw_surf
|| read_surf
)
833 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
836 /* If a native window underlying either draw or read is no longer valid,
837 * an EGL_BAD_NATIVE_WINDOW error is generated.
839 if (draw_surf
&& draw_surf
->Lost
)
840 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
841 if (read_surf
&& read_surf
->Lost
)
842 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
844 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
846 RETURN_EGL_EVAL(disp
, ret
);
850 EGLBoolean EGLAPIENTRY
851 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
852 EGLint attribute
, EGLint
*value
)
854 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
855 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
859 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
861 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
862 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
864 RETURN_EGL_EVAL(disp
, ret
);
869 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
870 void *native_window
, const EGLint
*attrib_list
)
872 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
878 if (native_window
== NULL
)
879 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
881 #ifdef HAVE_SURFACELESS_PLATFORM
882 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
883 /* From the EGL_MESA_platform_surfaceless spec (v1):
885 * eglCreatePlatformWindowSurface fails when called with a <display>
886 * that belongs to the surfaceless platform. It returns
887 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
888 * justification for this unconditional failure is that the
889 * surfaceless platform has no native windows, and therefore the
890 * <native_window> parameter is always invalid.
892 * This check must occur before checking the EGLConfig, which emits
895 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
899 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
901 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
902 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
904 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
906 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
908 RETURN_EGL_EVAL(disp
, ret
);
912 EGLSurface EGLAPIENTRY
913 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
914 EGLNativeWindowType window
, const EGLint
*attrib_list
)
916 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
918 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
919 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
920 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
925 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
927 #ifdef HAVE_X11_PLATFORM
928 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
929 /* The `native_window` parameter for the X11 platform differs between
930 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
931 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
932 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
933 * `Window*`. Convert `Window*` to `Window` because that's what
934 * dri2_x11_create_window_surface() expects.
936 return (void *)(* (Window
*) native_window
);
939 return native_window
;
942 static EGLSurface EGLAPIENTRY
943 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
945 const EGLint
*attrib_list
)
947 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
949 native_window
= _fixupNativeWindow(disp
, native_window
);
951 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
952 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
957 EGLSurface EGLAPIENTRY
958 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
960 const EGLAttrib
*attrib_list
)
962 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
966 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
968 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
969 if (attrib_list
&& !int_attribs
)
970 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
972 native_window
= _fixupNativeWindow(disp
, native_window
);
973 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
980 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
982 #ifdef HAVE_X11_PLATFORM
983 /* The `native_pixmap` parameter for the X11 platform differs between
984 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
985 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
986 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
987 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
988 * dri2_x11_create_pixmap_surface() expects.
990 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
991 return (void *)(* (Pixmap
*) native_pixmap
);
993 return native_pixmap
;
997 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
998 void *native_pixmap
, const EGLint
*attrib_list
)
1000 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1005 #if HAVE_SURFACELESS_PLATFORM
1006 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
1007 /* From the EGL_MESA_platform_surfaceless spec (v1):
1009 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1010 * also fails when called with a <display> that belongs to the
1011 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1012 * EGL_BAD_NATIVE_PIXMAP.
1014 * This check must occur before checking the EGLConfig, which emits
1017 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1021 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1023 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1024 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1026 if (native_pixmap
== NULL
)
1027 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1029 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1031 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1033 RETURN_EGL_EVAL(disp
, ret
);
1037 EGLSurface EGLAPIENTRY
1038 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1039 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1041 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1043 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1044 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1045 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1049 static EGLSurface EGLAPIENTRY
1050 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1051 void *native_pixmap
,
1052 const EGLint
*attrib_list
)
1054 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1056 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1057 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1058 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1063 EGLSurface EGLAPIENTRY
1064 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1065 void *native_pixmap
,
1066 const EGLAttrib
*attrib_list
)
1068 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1070 EGLint
*int_attribs
;
1072 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1074 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1075 if (attrib_list
&& !int_attribs
)
1076 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1078 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1079 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1086 EGLSurface EGLAPIENTRY
1087 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1088 const EGLint
*attrib_list
)
1090 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1091 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1096 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1097 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1099 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1100 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1102 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1103 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1105 RETURN_EGL_EVAL(disp
, ret
);
1109 EGLBoolean EGLAPIENTRY
1110 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1112 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1113 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1117 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1118 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1119 _eglUnlinkSurface(surf
);
1120 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1122 RETURN_EGL_EVAL(disp
, ret
);
1125 EGLBoolean EGLAPIENTRY
1126 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1127 EGLint attribute
, EGLint
*value
)
1129 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1130 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1134 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1135 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1136 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1138 RETURN_EGL_EVAL(disp
, ret
);
1141 EGLBoolean EGLAPIENTRY
1142 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1143 EGLint attribute
, EGLint value
)
1145 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1146 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1150 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1151 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1152 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1154 RETURN_EGL_EVAL(disp
, ret
);
1158 EGLBoolean EGLAPIENTRY
1159 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1161 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1162 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1166 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1167 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1168 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1170 RETURN_EGL_EVAL(disp
, ret
);
1174 EGLBoolean EGLAPIENTRY
1175 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1177 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1178 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1182 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1183 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1184 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1186 RETURN_EGL_EVAL(disp
, ret
);
1190 EGLBoolean EGLAPIENTRY
1191 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1193 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1194 _EGLContext
*ctx
= _eglGetCurrentContext();
1195 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1199 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1200 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1202 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1203 ctx
->Resource
.Display
!= disp
)
1204 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1206 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1207 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1209 interval
= CLAMP(interval
,
1210 surf
->Config
->MinSwapInterval
,
1211 surf
->Config
->MaxSwapInterval
);
1213 if (surf
->SwapInterval
!= interval
)
1214 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1219 surf
->SwapInterval
= interval
;
1221 RETURN_EGL_EVAL(disp
, ret
);
1225 EGLBoolean EGLAPIENTRY
1226 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1228 _EGLContext
*ctx
= _eglGetCurrentContext();
1229 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1230 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1234 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1235 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1237 /* surface must be bound to current context in EGL 1.4 */
1238 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1239 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1240 surf
!= ctx
->DrawSurface
)
1241 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1244 /* From the EGL 1.5 spec:
1246 * If eglSwapBuffers is called and the native window associated with
1247 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1251 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1253 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1255 /* EGL_KHR_partial_update
1256 * Frame boundary successfully reached,
1257 * reset damage region and reset BufferAgeRead
1260 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1261 surf
->BufferAgeRead
= EGL_FALSE
;
1264 RETURN_EGL_EVAL(disp
, ret
);
1269 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1270 EGLint
*rects
, EGLint n_rects
)
1272 _EGLContext
*ctx
= _eglGetCurrentContext();
1276 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1278 /* surface must be bound to current context in EGL 1.4 */
1279 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1280 surf
!= ctx
->DrawSurface
)
1281 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1283 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1284 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1286 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1288 /* EGL_KHR_partial_update
1289 * Frame boundary successfully reached,
1290 * reset damage region and reset BufferAgeRead
1293 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1294 surf
->BufferAgeRead
= EGL_FALSE
;
1297 RETURN_EGL_EVAL(disp
, ret
);
1300 static EGLBoolean EGLAPIENTRY
1301 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1302 EGLint
*rects
, EGLint n_rects
)
1304 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1305 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1306 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1307 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1310 static EGLBoolean EGLAPIENTRY
1311 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1312 EGLint
*rects
, EGLint n_rects
)
1314 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1315 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1316 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1317 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1321 * If the width of the passed rect is greater than the surface's
1322 * width then it is clamped to the width of the surface. Same with
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 x
, y
, rect_width
, rect_height
;
1338 rect_width
= rects
[i
+ 2];
1339 rect_height
= rects
[i
+ 3];
1341 if (rect_width
> surf_width
- x
)
1342 rects
[i
+ 2] = surf_width
- x
;
1344 if (rect_height
> surf_height
- y
)
1345 rects
[i
+ 3] = surf_height
- y
;
1349 static EGLBoolean EGLAPIENTRY
1350 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1351 EGLint
*rects
, EGLint n_rects
)
1353 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1354 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1355 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1356 _EGLContext
*ctx
= _eglGetCurrentContext();
1359 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1361 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1362 surf
->Type
!= EGL_WINDOW_BIT
||
1363 ctx
->DrawSurface
!= surf
||
1364 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1365 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1367 /* If the damage region is already set or
1368 * buffer age is not queried between
1369 * frame boundaries, throw bad access error
1372 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1373 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1375 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1376 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1379 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1381 RETURN_EGL_EVAL(disp
, ret
);
1384 EGLBoolean EGLAPIENTRY
1385 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1387 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1388 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1391 void *native_pixmap_ptr
;
1393 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1394 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1395 native_pixmap_ptr
= (void*) target
;
1397 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1398 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
1399 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
1400 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1402 RETURN_EGL_EVAL(disp
, ret
);
1407 _eglWaitClientCommon(void)
1409 _EGLContext
*ctx
= _eglGetCurrentContext();
1415 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1417 disp
= ctx
->Resource
.Display
;
1418 mtx_lock(&disp
->Mutex
);
1420 /* let bad current context imply bad current surface */
1421 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1422 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1423 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1425 /* a valid current context implies an initialized current display */
1426 assert(disp
->Initialized
);
1428 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1430 RETURN_EGL_EVAL(disp
, ret
);
1433 EGLBoolean EGLAPIENTRY
1436 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1437 return _eglWaitClientCommon();
1440 EGLBoolean EGLAPIENTRY
1443 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1444 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1445 return _eglWaitClientCommon();
1449 EGLBoolean EGLAPIENTRY
1450 eglWaitNative(EGLint engine
)
1452 _EGLContext
*ctx
= _eglGetCurrentContext();
1458 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1460 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1462 disp
= ctx
->Resource
.Display
;
1463 mtx_lock(&disp
->Mutex
);
1465 /* let bad current context imply bad current surface */
1466 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1467 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1468 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1470 /* a valid current context implies an initialized current display */
1471 assert(disp
->Initialized
);
1473 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1475 RETURN_EGL_EVAL(disp
, ret
);
1479 EGLDisplay EGLAPIENTRY
1480 eglGetCurrentDisplay(void)
1482 _EGLContext
*ctx
= _eglGetCurrentContext();
1485 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1487 RETURN_EGL_SUCCESS(NULL
, ret
);
1491 EGLContext EGLAPIENTRY
1492 eglGetCurrentContext(void)
1494 _EGLContext
*ctx
= _eglGetCurrentContext();
1497 ret
= _eglGetContextHandle(ctx
);
1499 RETURN_EGL_SUCCESS(NULL
, ret
);
1503 EGLSurface EGLAPIENTRY
1504 eglGetCurrentSurface(EGLint readdraw
)
1506 _EGLContext
*ctx
= _eglGetCurrentContext();
1507 EGLint err
= EGL_SUCCESS
;
1511 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1514 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1518 surf
= ctx
->DrawSurface
;
1521 surf
= ctx
->ReadSurface
;
1525 err
= EGL_BAD_PARAMETER
;
1529 ret
= _eglGetSurfaceHandle(surf
);
1531 RETURN_EGL_ERROR(NULL
, err
, ret
);
1538 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1539 EGLint e
= t
->LastError
;
1540 if (!_eglIsCurrentThreadDummy())
1541 t
->LastError
= EGL_SUCCESS
;
1551 * Specify the client API to use for subsequent calls including:
1552 * eglCreateContext()
1553 * eglGetCurrentContext()
1554 * eglGetCurrentDisplay()
1555 * eglGetCurrentSurface()
1556 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1559 * See section 3.7 "Rendering Context" in the EGL specification for details.
1561 EGLBoolean EGLAPIENTRY
1562 eglBindAPI(EGLenum api
)
1566 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1568 t
= _eglGetCurrentThread();
1569 if (_eglIsCurrentThreadDummy())
1570 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1572 if (!_eglIsApiValid(api
))
1573 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1575 t
->CurrentAPI
= api
;
1577 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1582 * Return the last value set with eglBindAPI().
1587 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1590 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1591 ret
= t
->CurrentAPI
;
1593 RETURN_EGL_SUCCESS(NULL
, ret
);
1597 EGLSurface EGLAPIENTRY
1598 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1599 EGLClientBuffer buffer
, EGLConfig config
,
1600 const EGLint
*attrib_list
)
1602 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1603 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1608 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1610 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1612 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1614 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1616 RETURN_EGL_EVAL(disp
, ret
);
1620 EGLBoolean EGLAPIENTRY
1621 eglReleaseThread(void)
1623 /* unbind current contexts */
1624 if (!_eglIsCurrentThreadDummy()) {
1625 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1626 _EGLContext
*ctx
= t
->CurrentContext
;
1628 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1631 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1634 mtx_lock(&disp
->Mutex
);
1636 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1637 mtx_unlock(&disp
->Mutex
);
1641 _eglDestroyCurrentThread();
1643 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1648 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1649 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1651 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1656 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1657 if (!disp
->Extensions
.KHR_image_base
)
1658 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1659 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1660 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1661 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1662 * <ctx> must be EGL_NO_CONTEXT..."
1664 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1665 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1667 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1669 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1671 RETURN_EGL_EVAL(disp
, ret
);
1674 static EGLImage EGLAPIENTRY
1675 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1676 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1678 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1679 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1680 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1684 EGLImage EGLAPIENTRY
1685 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1686 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1688 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1690 EGLint
*int_attribs
;
1692 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1694 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1695 if (attr_list
&& !int_attribs
)
1696 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1698 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1705 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1710 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1711 if (!disp
->Extensions
.KHR_image_base
)
1712 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1714 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1716 _eglUnlinkImage(img
);
1717 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1719 RETURN_EGL_EVAL(disp
, ret
);
1722 EGLBoolean EGLAPIENTRY
1723 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1725 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1726 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1727 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1728 return _eglDestroyImageCommon(disp
, img
);
1731 static EGLBoolean EGLAPIENTRY
1732 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1734 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1735 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1736 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1737 return _eglDestroyImageCommon(disp
, img
);
1742 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1743 EGLBoolean orig_is_EGLAttrib
,
1744 EGLenum invalid_type_error
)
1746 _EGLContext
*ctx
= _eglGetCurrentContext();
1751 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1753 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1754 /* There exist two EGLAttrib variants of eglCreateSync*:
1755 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1756 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1757 * support as a proxy for EGL 1.5 support, even though that's not
1758 * entirely correct (though _eglComputeVersion does the same).
1760 * The EGL spec provides no guidance on how to handle unsupported
1761 * functions. EGL_BAD_MATCH seems reasonable.
1763 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1766 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1767 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1768 * error is generated.
1771 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1772 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1774 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1775 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1776 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1777 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1780 case EGL_SYNC_FENCE_KHR
:
1781 if (!disp
->Extensions
.KHR_fence_sync
)
1782 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1784 case EGL_SYNC_REUSABLE_KHR
:
1785 if (!disp
->Extensions
.KHR_reusable_sync
)
1786 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1788 case EGL_SYNC_CL_EVENT_KHR
:
1789 if (!disp
->Extensions
.KHR_cl_event2
)
1790 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1792 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1793 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1794 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1797 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1800 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1801 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1803 RETURN_EGL_EVAL(disp
, ret
);
1807 static EGLSync EGLAPIENTRY
1808 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1810 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1811 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1814 EGLAttrib
*attrib_list
;
1817 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1818 attrib_list
= (EGLAttrib
*) int_list
;
1820 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1821 if (err
!= EGL_SUCCESS
)
1822 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1825 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1828 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1831 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1836 static EGLSync EGLAPIENTRY
1837 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1839 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1840 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1841 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1847 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1849 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1850 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1851 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1857 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1862 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1863 assert(disp
->Extensions
.KHR_reusable_sync
||
1864 disp
->Extensions
.KHR_fence_sync
||
1865 disp
->Extensions
.ANDROID_native_fence_sync
);
1868 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1870 RETURN_EGL_EVAL(disp
, ret
);
1873 EGLBoolean EGLAPIENTRY
1874 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1876 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1877 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1878 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1879 return _eglDestroySync(disp
, s
);
1882 static EGLBoolean EGLAPIENTRY
1883 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1885 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1886 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1887 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1888 return _eglDestroySync(disp
, s
);
1893 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1894 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1899 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1900 assert(disp
->Extensions
.KHR_reusable_sync
||
1901 disp
->Extensions
.KHR_fence_sync
||
1902 disp
->Extensions
.ANDROID_native_fence_sync
);
1904 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1905 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1907 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1908 * unlocked here to allow other threads also to be able to
1909 * go into waiting state.
1912 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1913 _eglUnlockDisplay(dpy
);
1915 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1918 * 'disp' is already unlocked for reusable sync type,
1919 * so passing 'NULL' to bypass unlocking display.
1921 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1922 RETURN_EGL_EVAL(NULL
, ret
);
1924 RETURN_EGL_EVAL(disp
, ret
);
1928 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
1929 EGLint flags
, EGLTime timeout
)
1931 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1932 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1933 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1934 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1937 static EGLint EGLAPIENTRY
1938 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
1939 EGLint flags
, EGLTime timeout
)
1941 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1942 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1943 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1944 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1949 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
1951 _EGLContext
*ctx
= _eglGetCurrentContext();
1955 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1956 assert(disp
->Extensions
.KHR_wait_sync
);
1958 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1959 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1960 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1962 /* the API doesn't allow any flags yet */
1964 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1966 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1968 RETURN_EGL_EVAL(disp
, ret
);
1971 static EGLint EGLAPIENTRY
1972 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1974 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1975 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1976 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1977 return _eglWaitSyncCommon(disp
, s
, flags
);
1981 EGLBoolean EGLAPIENTRY
1982 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1984 /* The KHR version returns EGLint, while the core version returns
1985 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1988 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1989 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1990 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1991 return _eglWaitSyncCommon(disp
, s
, flags
);
1995 static EGLBoolean EGLAPIENTRY
1996 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
1998 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1999 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2003 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2005 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2006 assert(disp
->Extensions
.KHR_reusable_sync
);
2007 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2009 RETURN_EGL_EVAL(disp
, ret
);
2014 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2019 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2020 assert(disp
->Extensions
.KHR_reusable_sync
||
2021 disp
->Extensions
.KHR_fence_sync
||
2022 disp
->Extensions
.ANDROID_native_fence_sync
);
2023 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2025 RETURN_EGL_EVAL(disp
, ret
);
2028 EGLBoolean EGLAPIENTRY
2029 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2031 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2032 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2033 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2034 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2038 static EGLBoolean EGLAPIENTRY
2039 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2041 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2042 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2046 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2049 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2052 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2054 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2056 * If any error occurs, <*value> is not modified.
2058 if (result
== EGL_FALSE
)
2065 static EGLint EGLAPIENTRY
2066 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2068 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2069 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2073 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2075 /* the spec doesn't seem to specify what happens if the fence
2076 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2079 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2080 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2082 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2083 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2084 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2086 RETURN_EGL_EVAL(disp
, ret
);
2089 static EGLBoolean EGLAPIENTRY
2090 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2091 EGLint numRects
, const EGLint
*rects
)
2093 _EGLContext
*ctx
= _eglGetCurrentContext();
2094 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2095 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2099 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2101 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2103 if (!disp
->Extensions
.NOK_swap_region
)
2104 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2106 /* surface must be bound to current context in EGL 1.4 */
2107 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2108 surf
!= ctx
->DrawSurface
)
2109 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2111 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2113 RETURN_EGL_EVAL(disp
, ret
);
2117 static EGLImage EGLAPIENTRY
2118 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2120 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2125 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2127 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2128 if (!disp
->Extensions
.MESA_drm_image
)
2129 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2131 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2132 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2134 RETURN_EGL_EVAL(disp
, ret
);
2137 static EGLBoolean EGLAPIENTRY
2138 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2139 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2141 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2142 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2146 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2148 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2149 assert(disp
->Extensions
.MESA_drm_image
);
2152 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2154 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2156 RETURN_EGL_EVAL(disp
, ret
);
2162 static EGLBoolean EGLAPIENTRY
2163 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2165 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2169 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2171 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2172 assert(disp
->Extensions
.WL_bind_wayland_display
);
2175 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2177 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2179 RETURN_EGL_EVAL(disp
, ret
);
2182 static EGLBoolean EGLAPIENTRY
2183 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2185 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2189 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2191 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2192 assert(disp
->Extensions
.WL_bind_wayland_display
);
2195 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2197 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2199 RETURN_EGL_EVAL(disp
, ret
);
2202 static EGLBoolean EGLAPIENTRY
2203 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2204 EGLint attribute
, EGLint
*value
)
2206 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2210 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2212 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2213 assert(disp
->Extensions
.WL_bind_wayland_display
);
2216 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2218 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2220 RETURN_EGL_EVAL(disp
, ret
);
2224 static struct wl_buffer
* EGLAPIENTRY
2225 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2227 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2230 struct wl_buffer
*ret
;
2232 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2234 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2235 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2236 RETURN_EGL_EVAL(disp
, NULL
);
2238 img
= _eglLookupImage(image
, disp
);
2241 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2243 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2245 RETURN_EGL_EVAL(disp
, ret
);
2248 static EGLBoolean EGLAPIENTRY
2249 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2250 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2252 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2253 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2257 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2259 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2261 if (!disp
->Extensions
.NV_post_sub_buffer
)
2262 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2264 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2266 RETURN_EGL_EVAL(disp
, ret
);
2269 static EGLBoolean EGLAPIENTRY
2270 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
2271 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2274 _EGLDisplay
*disp
= _eglLockDisplay(display
);
2275 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2279 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2281 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2282 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2283 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2285 if (!ust
|| !msc
|| !sbc
)
2286 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2288 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2290 RETURN_EGL_EVAL(disp
, ret
);
2293 static EGLBoolean EGLAPIENTRY
2294 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2295 EGLint
*fourcc
, EGLint
*nplanes
,
2296 EGLuint64KHR
*modifiers
)
2298 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2299 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2303 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2305 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2306 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2309 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2311 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2314 RETURN_EGL_EVAL(disp
, ret
);
2317 static EGLBoolean EGLAPIENTRY
2318 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2319 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2321 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2322 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2326 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2328 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2329 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2332 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2334 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2336 RETURN_EGL_EVAL(disp
, ret
);
2339 static EGLint EGLAPIENTRY
2340 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2343 _EGLDisplay
*disp
= NULL
;
2344 _EGLResourceType type
;
2346 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2348 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2349 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2351 if (!_eglIsCurrentThreadDummy()) {
2356 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2359 disp
= _eglLockDisplay(dpy
);
2361 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2363 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2364 if (dpy
!= (EGLDisplay
) object
)
2365 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2367 disp
->Label
= label
;
2368 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2371 switch (objectType
) {
2372 case EGL_OBJECT_CONTEXT_KHR
:
2373 type
= _EGL_RESOURCE_CONTEXT
;
2375 case EGL_OBJECT_SURFACE_KHR
:
2376 type
= _EGL_RESOURCE_SURFACE
;
2378 case EGL_OBJECT_IMAGE_KHR
:
2379 type
= _EGL_RESOURCE_IMAGE
;
2381 case EGL_OBJECT_SYNC_KHR
:
2382 type
= _EGL_RESOURCE_SYNC
;
2384 case EGL_OBJECT_STREAM_KHR
:
2386 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2389 if (_eglCheckResource(object
, type
, disp
)) {
2390 _EGLResource
*res
= (_EGLResource
*) object
;
2393 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2396 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2399 static EGLint EGLAPIENTRY
2400 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2401 const EGLAttrib
*attrib_list
)
2403 unsigned int newEnabled
;
2405 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2407 mtx_lock(_eglGlobal
.Mutex
);
2409 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2410 if (attrib_list
!= NULL
) {
2413 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2414 switch (attrib_list
[i
]) {
2415 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2416 case EGL_DEBUG_MSG_ERROR_KHR
:
2417 case EGL_DEBUG_MSG_WARN_KHR
:
2418 case EGL_DEBUG_MSG_INFO_KHR
:
2419 if (attrib_list
[i
+ 1])
2420 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2422 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2425 // On error, set the last error code, call the current
2426 // debug callback, and return the error code.
2427 mtx_unlock(_eglGlobal
.Mutex
);
2428 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2429 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2430 return EGL_BAD_ATTRIBUTE
;
2435 if (callback
!= NULL
) {
2436 _eglGlobal
.debugCallback
= callback
;
2437 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2439 _eglGlobal
.debugCallback
= NULL
;
2440 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2443 mtx_unlock(_eglGlobal
.Mutex
);
2447 static EGLBoolean EGLAPIENTRY
2448 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2450 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2452 mtx_lock(_eglGlobal
.Mutex
);
2454 switch (attribute
) {
2455 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2456 case EGL_DEBUG_MSG_ERROR_KHR
:
2457 case EGL_DEBUG_MSG_WARN_KHR
:
2458 case EGL_DEBUG_MSG_INFO_KHR
:
2459 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2464 case EGL_DEBUG_CALLBACK_KHR
:
2465 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2468 mtx_unlock(_eglGlobal
.Mutex
);
2469 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2470 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2474 mtx_unlock(_eglGlobal
.Mutex
);
2479 _eglFunctionCompare(const void *key
, const void *elem
)
2481 const char *procname
= key
;
2482 const struct _egl_entrypoint
*entrypoint
= elem
;
2483 return strcmp(procname
, entrypoint
->name
);
2486 static EGLBoolean EGLAPIENTRY
2487 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2488 EGLint
*formats
, EGLint
*num_formats
)
2490 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2494 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2496 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2498 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2501 RETURN_EGL_EVAL(disp
, ret
);
2504 static EGLBoolean EGLAPIENTRY
2505 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2506 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2507 EGLint
*num_modifiers
)
2509 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2513 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2515 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2517 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2518 modifiers
, external_only
,
2521 RETURN_EGL_EVAL(disp
, ret
);
2524 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2525 eglGetProcAddress(const char *procname
)
2527 static const struct _egl_entrypoint egl_functions
[] = {
2528 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2529 #include "eglentrypoint.h"
2530 #undef EGL_ENTRYPOINT
2532 _EGLProc ret
= NULL
;
2535 RETURN_EGL_SUCCESS(NULL
, NULL
);
2537 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2539 if (strncmp(procname
, "egl", 3) == 0) {
2540 const struct _egl_entrypoint
*entrypoint
=
2542 egl_functions
, ARRAY_SIZE(egl_functions
),
2543 sizeof(egl_functions
[0]),
2544 _eglFunctionCompare
);
2546 ret
= entrypoint
->function
;
2550 ret
= _eglGetDriverProc(procname
);
2552 RETURN_EGL_SUCCESS(NULL
, ret
);
2556 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2557 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2561 *disp
= _eglLockDisplay(dpy
);
2562 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2564 _eglUnlockDisplay(*disp
);
2565 return MESA_GLINTEROP_INVALID_DISPLAY
;
2568 *drv
= (*disp
)->Driver
;
2570 *ctx
= _eglLookupContext(context
, *disp
);
2572 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2573 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2574 _eglUnlockDisplay(*disp
);
2575 return MESA_GLINTEROP_INVALID_CONTEXT
;
2578 return MESA_GLINTEROP_SUCCESS
;
2582 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2583 struct mesa_glinterop_device_info
*out
)
2590 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2591 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2594 if (drv
->API
.GLInteropQueryDeviceInfo
)
2595 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2597 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2599 _eglUnlockDisplay(disp
);
2604 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2605 struct mesa_glinterop_export_in
*in
,
2606 struct mesa_glinterop_export_out
*out
)
2613 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2614 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2617 if (drv
->API
.GLInteropExportObject
)
2618 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2620 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2622 _eglUnlockDisplay(disp
);