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(EXT_pixel_format_float
);
518 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
520 if (dpy
->Extensions
.KHR_no_config_context
)
521 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
522 _EGL_CHECK_EXTENSION(MESA_drm_image
);
523 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
525 _EGL_CHECK_EXTENSION(NOK_swap_region
);
526 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
528 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
530 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
531 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
533 #undef _EGL_CHECK_EXTENSION
537 _eglCreateAPIsString(_EGLDisplay
*dpy
)
539 if (dpy
->ClientAPIs
& EGL_OPENGL_BIT
)
540 strcat(dpy
->ClientAPIsString
, "OpenGL ");
542 if (dpy
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
543 dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
544 dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
545 strcat(dpy
->ClientAPIsString
, "OpenGL_ES ");
548 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
549 strcat(dpy
->ClientAPIsString
, "OpenVG ");
551 assert(strlen(dpy
->ClientAPIsString
) < sizeof(dpy
->ClientAPIsString
));
555 _eglComputeVersion(_EGLDisplay
*disp
)
559 if (disp
->Extensions
.KHR_fence_sync
&&
560 disp
->Extensions
.KHR_cl_event2
&&
561 disp
->Extensions
.KHR_wait_sync
&&
562 disp
->Extensions
.KHR_image_base
&&
563 disp
->Extensions
.KHR_gl_texture_2D_image
&&
564 disp
->Extensions
.KHR_gl_texture_3D_image
&&
565 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
566 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
567 disp
->Extensions
.KHR_create_context
&&
568 disp
->Extensions
.EXT_create_context_robustness
&&
569 disp
->Extensions
.KHR_get_all_proc_addresses
&&
570 disp
->Extensions
.KHR_gl_colorspace
&&
571 disp
->Extensions
.KHR_surfaceless_context
)
576 * This is typically the second EGL function that an application calls.
577 * Here we load/initialize the actual hardware driver.
579 EGLBoolean EGLAPIENTRY
580 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
582 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
584 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
587 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
589 if (!disp
->Initialized
) {
590 if (!_eglMatchDriver(disp
))
591 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
593 /* limit to APIs supported by core */
594 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
596 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
597 * classifies it as an EGL display extension, though conceptually it's an
598 * EGL client extension.
600 * From the EGL_KHR_get_all_proc_addresses spec:
602 * The EGL implementation must expose the name
603 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
604 * EGL_KHR_get_all_proc_addresses and supports
605 * EGL_EXT_client_extensions.
607 * Mesa unconditionally exposes both client extensions mentioned above,
608 * so the spec requires that each EGLDisplay unconditionally expose
609 * EGL_KHR_get_all_proc_addresses also.
611 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
613 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
614 * programs. It is driver agnostic and handled in the main EGL code.
616 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
618 _eglComputeVersion(disp
);
619 _eglCreateExtensionsString(disp
);
620 _eglCreateAPIsString(disp
);
621 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
622 "%d.%d (%s)", disp
->Version
/ 10, disp
->Version
% 10,
626 /* Update applications version of major and minor if not NULL */
627 if ((major
!= NULL
) && (minor
!= NULL
)) {
628 *major
= disp
->Version
/ 10;
629 *minor
= disp
->Version
% 10;
632 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
636 EGLBoolean EGLAPIENTRY
637 eglTerminate(EGLDisplay dpy
)
639 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
641 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
644 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
646 if (disp
->Initialized
) {
647 _EGLDriver
*drv
= disp
->Driver
;
649 drv
->API
.Terminate(drv
, disp
);
650 /* do not reset disp->Driver */
651 disp
->ClientAPIsString
[0] = 0;
652 disp
->Initialized
= EGL_FALSE
;
655 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
659 const char * EGLAPIENTRY
660 eglQueryString(EGLDisplay dpy
, EGLint name
)
665 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
666 const char *ret
= _eglGetClientExtensionString();
668 RETURN_EGL_SUCCESS(NULL
, ret
);
670 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
673 disp
= _eglLockDisplay(dpy
);
674 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
675 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
679 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
681 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
683 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
684 case EGL_CLIENT_APIS
:
685 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
687 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
692 EGLBoolean EGLAPIENTRY
693 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
694 EGLint config_size
, EGLint
*num_config
)
696 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
700 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
702 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
703 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
705 RETURN_EGL_EVAL(disp
, ret
);
709 EGLBoolean EGLAPIENTRY
710 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
711 EGLint config_size
, EGLint
*num_config
)
713 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
717 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
719 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
720 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
721 config_size
, num_config
);
723 RETURN_EGL_EVAL(disp
, ret
);
727 EGLBoolean EGLAPIENTRY
728 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
729 EGLint attribute
, EGLint
*value
)
731 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
732 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
736 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
738 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
739 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
741 RETURN_EGL_EVAL(disp
, ret
);
745 EGLContext EGLAPIENTRY
746 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
747 const EGLint
*attrib_list
)
749 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
750 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
751 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
753 _EGLContext
*context
;
756 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
758 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
760 if (config
!= EGL_NO_CONFIG_KHR
)
761 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
762 else if (!disp
->Extensions
.KHR_no_config_context
)
763 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
765 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
766 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
768 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
769 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
771 RETURN_EGL_EVAL(disp
, ret
);
775 EGLBoolean EGLAPIENTRY
776 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
778 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
779 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
783 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
785 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
786 _eglUnlinkContext(context
);
787 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
789 RETURN_EGL_EVAL(disp
, ret
);
793 EGLBoolean EGLAPIENTRY
794 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
797 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
798 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
799 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
800 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
804 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
807 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
810 /* display is allowed to be uninitialized under certain condition */
811 if (!disp
->Initialized
) {
812 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
813 ctx
!= EGL_NO_CONTEXT
)
814 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
817 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
819 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
820 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
821 if (!draw_surf
|| !read_surf
) {
822 /* From the EGL 1.4 (20130211) spec:
824 * To release the current context without assigning a new one, set ctx
825 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
827 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
828 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
830 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
831 (!read_surf
&& read
!= EGL_NO_SURFACE
))
832 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
833 if (draw_surf
|| read_surf
)
834 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
837 /* If a native window underlying either draw or read is no longer valid,
838 * an EGL_BAD_NATIVE_WINDOW error is generated.
840 if (draw_surf
&& draw_surf
->Lost
)
841 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
842 if (read_surf
&& read_surf
->Lost
)
843 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
845 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
847 RETURN_EGL_EVAL(disp
, ret
);
851 EGLBoolean EGLAPIENTRY
852 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
853 EGLint attribute
, EGLint
*value
)
855 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
856 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
860 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
862 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
863 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
865 RETURN_EGL_EVAL(disp
, ret
);
870 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
871 void *native_window
, const EGLint
*attrib_list
)
873 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
879 if (native_window
== NULL
)
880 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
882 #ifdef HAVE_SURFACELESS_PLATFORM
883 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
884 /* From the EGL_MESA_platform_surfaceless spec (v1):
886 * eglCreatePlatformWindowSurface fails when called with a <display>
887 * that belongs to the surfaceless platform. It returns
888 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
889 * justification for this unconditional failure is that the
890 * surfaceless platform has no native windows, and therefore the
891 * <native_window> parameter is always invalid.
893 * This check must occur before checking the EGLConfig, which emits
896 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
900 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
902 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
903 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
905 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
907 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
909 RETURN_EGL_EVAL(disp
, ret
);
913 EGLSurface EGLAPIENTRY
914 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
915 EGLNativeWindowType window
, const EGLint
*attrib_list
)
917 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
919 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
920 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
921 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
926 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
928 #ifdef HAVE_X11_PLATFORM
929 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
930 /* The `native_window` parameter for the X11 platform differs between
931 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
932 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
933 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
934 * `Window*`. Convert `Window*` to `Window` because that's what
935 * dri2_x11_create_window_surface() expects.
937 return (void *)(* (Window
*) native_window
);
940 return native_window
;
943 static EGLSurface EGLAPIENTRY
944 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
946 const EGLint
*attrib_list
)
948 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
950 native_window
= _fixupNativeWindow(disp
, native_window
);
952 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
953 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
958 EGLSurface EGLAPIENTRY
959 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
961 const EGLAttrib
*attrib_list
)
963 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
967 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
969 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
970 if (attrib_list
&& !int_attribs
)
971 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
973 native_window
= _fixupNativeWindow(disp
, native_window
);
974 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
981 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
983 #ifdef HAVE_X11_PLATFORM
984 /* The `native_pixmap` parameter for the X11 platform differs between
985 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
986 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
987 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
988 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
989 * dri2_x11_create_pixmap_surface() expects.
991 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
992 return (void *)(* (Pixmap
*) native_pixmap
);
994 return native_pixmap
;
998 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
999 void *native_pixmap
, const EGLint
*attrib_list
)
1001 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1006 #if HAVE_SURFACELESS_PLATFORM
1007 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
1008 /* From the EGL_MESA_platform_surfaceless spec (v1):
1010 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1011 * also fails when called with a <display> that belongs to the
1012 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1013 * EGL_BAD_NATIVE_PIXMAP.
1015 * This check must occur before checking the EGLConfig, which emits
1018 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1022 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1024 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1025 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1027 if (native_pixmap
== NULL
)
1028 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1030 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1032 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1034 RETURN_EGL_EVAL(disp
, ret
);
1038 EGLSurface EGLAPIENTRY
1039 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1040 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1042 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1044 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1045 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1046 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1050 static EGLSurface EGLAPIENTRY
1051 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1052 void *native_pixmap
,
1053 const EGLint
*attrib_list
)
1055 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1057 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1058 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1059 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1064 EGLSurface EGLAPIENTRY
1065 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1066 void *native_pixmap
,
1067 const EGLAttrib
*attrib_list
)
1069 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1071 EGLint
*int_attribs
;
1073 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1075 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1076 if (attrib_list
&& !int_attribs
)
1077 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1079 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1080 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1087 EGLSurface EGLAPIENTRY
1088 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1089 const EGLint
*attrib_list
)
1091 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1092 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1097 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1098 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1100 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1101 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1103 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1104 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1106 RETURN_EGL_EVAL(disp
, ret
);
1110 EGLBoolean EGLAPIENTRY
1111 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1113 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1114 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1118 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1119 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1120 _eglUnlinkSurface(surf
);
1121 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1123 RETURN_EGL_EVAL(disp
, ret
);
1126 EGLBoolean EGLAPIENTRY
1127 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1128 EGLint attribute
, EGLint
*value
)
1130 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1131 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1135 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1136 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1137 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1139 RETURN_EGL_EVAL(disp
, ret
);
1142 EGLBoolean EGLAPIENTRY
1143 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1144 EGLint attribute
, EGLint value
)
1146 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1147 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1151 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1152 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1153 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1155 RETURN_EGL_EVAL(disp
, ret
);
1159 EGLBoolean EGLAPIENTRY
1160 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1162 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1163 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1167 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1168 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1169 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1171 RETURN_EGL_EVAL(disp
, ret
);
1175 EGLBoolean EGLAPIENTRY
1176 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1178 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1179 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1183 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1184 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1185 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1187 RETURN_EGL_EVAL(disp
, ret
);
1191 EGLBoolean EGLAPIENTRY
1192 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1194 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1195 _EGLContext
*ctx
= _eglGetCurrentContext();
1196 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1200 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1201 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1203 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1204 ctx
->Resource
.Display
!= disp
)
1205 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1207 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1208 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1210 interval
= CLAMP(interval
,
1211 surf
->Config
->MinSwapInterval
,
1212 surf
->Config
->MaxSwapInterval
);
1214 if (surf
->SwapInterval
!= interval
)
1215 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1220 surf
->SwapInterval
= interval
;
1222 RETURN_EGL_EVAL(disp
, ret
);
1226 EGLBoolean EGLAPIENTRY
1227 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1229 _EGLContext
*ctx
= _eglGetCurrentContext();
1230 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1231 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1235 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1236 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1238 /* surface must be bound to current context in EGL 1.4 */
1239 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1240 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1241 surf
!= ctx
->DrawSurface
)
1242 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1245 /* From the EGL 1.5 spec:
1247 * If eglSwapBuffers is called and the native window associated with
1248 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1252 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1254 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1256 /* EGL_KHR_partial_update
1257 * Frame boundary successfully reached,
1258 * reset damage region and reset BufferAgeRead
1261 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1262 surf
->BufferAgeRead
= EGL_FALSE
;
1265 RETURN_EGL_EVAL(disp
, ret
);
1270 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1271 EGLint
*rects
, EGLint n_rects
)
1273 _EGLContext
*ctx
= _eglGetCurrentContext();
1277 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1279 /* surface must be bound to current context in EGL 1.4 */
1280 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1281 surf
!= ctx
->DrawSurface
)
1282 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1284 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1285 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1287 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1289 /* EGL_KHR_partial_update
1290 * Frame boundary successfully reached,
1291 * reset damage region and reset BufferAgeRead
1294 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1295 surf
->BufferAgeRead
= EGL_FALSE
;
1298 RETURN_EGL_EVAL(disp
, ret
);
1301 static EGLBoolean EGLAPIENTRY
1302 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1303 EGLint
*rects
, EGLint n_rects
)
1305 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1306 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1307 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1308 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1311 static EGLBoolean EGLAPIENTRY
1312 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1313 EGLint
*rects
, EGLint n_rects
)
1315 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1316 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1317 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1318 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1322 * If the width of the passed rect is greater than the surface's
1323 * width then it is clamped to the width of the surface. Same with
1328 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1329 EGLint
*rects
, EGLint n_rects
)
1332 EGLint surf_height
= surf
->Height
;
1333 EGLint surf_width
= surf
->Width
;
1335 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1336 EGLint x
, y
, rect_width
, rect_height
;
1339 rect_width
= rects
[i
+ 2];
1340 rect_height
= rects
[i
+ 3];
1342 if (rect_width
> surf_width
- x
)
1343 rects
[i
+ 2] = surf_width
- x
;
1345 if (rect_height
> surf_height
- y
)
1346 rects
[i
+ 3] = surf_height
- y
;
1350 static EGLBoolean EGLAPIENTRY
1351 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1352 EGLint
*rects
, EGLint n_rects
)
1354 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1355 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1356 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1357 _EGLContext
*ctx
= _eglGetCurrentContext();
1360 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1362 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1363 surf
->Type
!= EGL_WINDOW_BIT
||
1364 ctx
->DrawSurface
!= surf
||
1365 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1366 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1368 /* If the damage region is already set or
1369 * buffer age is not queried between
1370 * frame boundaries, throw bad access error
1373 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1374 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1376 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1377 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1380 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1382 RETURN_EGL_EVAL(disp
, ret
);
1385 EGLBoolean EGLAPIENTRY
1386 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1388 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1389 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1392 void *native_pixmap_ptr
;
1394 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1395 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1396 native_pixmap_ptr
= (void*) target
;
1398 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1399 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
1400 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
1401 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1403 RETURN_EGL_EVAL(disp
, ret
);
1408 _eglWaitClientCommon(void)
1410 _EGLContext
*ctx
= _eglGetCurrentContext();
1416 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1418 disp
= ctx
->Resource
.Display
;
1419 mtx_lock(&disp
->Mutex
);
1421 /* let bad current context imply bad current surface */
1422 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1423 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1424 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1426 /* a valid current context implies an initialized current display */
1427 assert(disp
->Initialized
);
1429 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1431 RETURN_EGL_EVAL(disp
, ret
);
1434 EGLBoolean EGLAPIENTRY
1437 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1438 return _eglWaitClientCommon();
1441 EGLBoolean EGLAPIENTRY
1444 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1445 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1446 return _eglWaitClientCommon();
1450 EGLBoolean EGLAPIENTRY
1451 eglWaitNative(EGLint engine
)
1453 _EGLContext
*ctx
= _eglGetCurrentContext();
1459 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1461 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1463 disp
= ctx
->Resource
.Display
;
1464 mtx_lock(&disp
->Mutex
);
1466 /* let bad current context imply bad current surface */
1467 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1468 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1469 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1471 /* a valid current context implies an initialized current display */
1472 assert(disp
->Initialized
);
1474 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1476 RETURN_EGL_EVAL(disp
, ret
);
1480 EGLDisplay EGLAPIENTRY
1481 eglGetCurrentDisplay(void)
1483 _EGLContext
*ctx
= _eglGetCurrentContext();
1486 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1488 RETURN_EGL_SUCCESS(NULL
, ret
);
1492 EGLContext EGLAPIENTRY
1493 eglGetCurrentContext(void)
1495 _EGLContext
*ctx
= _eglGetCurrentContext();
1498 ret
= _eglGetContextHandle(ctx
);
1500 RETURN_EGL_SUCCESS(NULL
, ret
);
1504 EGLSurface EGLAPIENTRY
1505 eglGetCurrentSurface(EGLint readdraw
)
1507 _EGLContext
*ctx
= _eglGetCurrentContext();
1508 EGLint err
= EGL_SUCCESS
;
1512 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1515 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1519 surf
= ctx
->DrawSurface
;
1522 surf
= ctx
->ReadSurface
;
1526 err
= EGL_BAD_PARAMETER
;
1530 ret
= _eglGetSurfaceHandle(surf
);
1532 RETURN_EGL_ERROR(NULL
, err
, ret
);
1539 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1540 EGLint e
= t
->LastError
;
1541 if (!_eglIsCurrentThreadDummy())
1542 t
->LastError
= EGL_SUCCESS
;
1552 * Specify the client API to use for subsequent calls including:
1553 * eglCreateContext()
1554 * eglGetCurrentContext()
1555 * eglGetCurrentDisplay()
1556 * eglGetCurrentSurface()
1557 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1560 * See section 3.7 "Rendering Context" in the EGL specification for details.
1562 EGLBoolean EGLAPIENTRY
1563 eglBindAPI(EGLenum api
)
1567 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1569 t
= _eglGetCurrentThread();
1570 if (_eglIsCurrentThreadDummy())
1571 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1573 if (!_eglIsApiValid(api
))
1574 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1576 t
->CurrentAPI
= api
;
1578 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1583 * Return the last value set with eglBindAPI().
1588 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1591 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1592 ret
= t
->CurrentAPI
;
1594 RETURN_EGL_SUCCESS(NULL
, ret
);
1598 EGLSurface EGLAPIENTRY
1599 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1600 EGLClientBuffer buffer
, EGLConfig config
,
1601 const EGLint
*attrib_list
)
1603 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1604 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1609 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1611 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1613 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1615 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1617 RETURN_EGL_EVAL(disp
, ret
);
1621 EGLBoolean EGLAPIENTRY
1622 eglReleaseThread(void)
1624 /* unbind current contexts */
1625 if (!_eglIsCurrentThreadDummy()) {
1626 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1627 _EGLContext
*ctx
= t
->CurrentContext
;
1629 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1632 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1635 mtx_lock(&disp
->Mutex
);
1637 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1638 mtx_unlock(&disp
->Mutex
);
1642 _eglDestroyCurrentThread();
1644 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1649 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1650 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1652 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1657 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1658 if (!disp
->Extensions
.KHR_image_base
)
1659 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1660 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1661 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1662 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1663 * <ctx> must be EGL_NO_CONTEXT..."
1665 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1666 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1668 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1670 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1672 RETURN_EGL_EVAL(disp
, ret
);
1675 static EGLImage EGLAPIENTRY
1676 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1677 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1679 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1680 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1681 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1685 EGLImage EGLAPIENTRY
1686 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1687 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1689 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1691 EGLint
*int_attribs
;
1693 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1695 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1696 if (attr_list
&& !int_attribs
)
1697 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1699 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1706 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1711 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1712 if (!disp
->Extensions
.KHR_image_base
)
1713 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1715 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1717 _eglUnlinkImage(img
);
1718 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1720 RETURN_EGL_EVAL(disp
, ret
);
1723 EGLBoolean EGLAPIENTRY
1724 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1726 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1727 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1728 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1729 return _eglDestroyImageCommon(disp
, img
);
1732 static EGLBoolean EGLAPIENTRY
1733 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1735 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1736 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1737 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1738 return _eglDestroyImageCommon(disp
, img
);
1743 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1744 EGLBoolean orig_is_EGLAttrib
,
1745 EGLenum invalid_type_error
)
1747 _EGLContext
*ctx
= _eglGetCurrentContext();
1752 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1754 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1755 /* There exist two EGLAttrib variants of eglCreateSync*:
1756 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1757 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1758 * support as a proxy for EGL 1.5 support, even though that's not
1759 * entirely correct (though _eglComputeVersion does the same).
1761 * The EGL spec provides no guidance on how to handle unsupported
1762 * functions. EGL_BAD_MATCH seems reasonable.
1764 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1767 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1768 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1769 * error is generated.
1772 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1773 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1775 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1776 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1777 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1778 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1781 case EGL_SYNC_FENCE_KHR
:
1782 if (!disp
->Extensions
.KHR_fence_sync
)
1783 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1785 case EGL_SYNC_REUSABLE_KHR
:
1786 if (!disp
->Extensions
.KHR_reusable_sync
)
1787 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1789 case EGL_SYNC_CL_EVENT_KHR
:
1790 if (!disp
->Extensions
.KHR_cl_event2
)
1791 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1793 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1794 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1795 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1798 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1801 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1802 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1804 RETURN_EGL_EVAL(disp
, ret
);
1808 static EGLSync EGLAPIENTRY
1809 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1811 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1812 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1815 EGLAttrib
*attrib_list
;
1818 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1819 attrib_list
= (EGLAttrib
*) int_list
;
1821 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1822 if (err
!= EGL_SUCCESS
)
1823 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1826 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1829 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1832 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1837 static EGLSync EGLAPIENTRY
1838 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1840 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1841 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1842 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1848 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1850 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1851 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1852 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1858 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1863 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1864 assert(disp
->Extensions
.KHR_reusable_sync
||
1865 disp
->Extensions
.KHR_fence_sync
||
1866 disp
->Extensions
.ANDROID_native_fence_sync
);
1869 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1871 RETURN_EGL_EVAL(disp
, ret
);
1874 EGLBoolean EGLAPIENTRY
1875 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1877 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1878 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1879 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1880 return _eglDestroySync(disp
, s
);
1883 static EGLBoolean EGLAPIENTRY
1884 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1886 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1887 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1888 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1889 return _eglDestroySync(disp
, s
);
1894 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1895 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1900 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1901 assert(disp
->Extensions
.KHR_reusable_sync
||
1902 disp
->Extensions
.KHR_fence_sync
||
1903 disp
->Extensions
.ANDROID_native_fence_sync
);
1905 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1906 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1908 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1909 * unlocked here to allow other threads also to be able to
1910 * go into waiting state.
1913 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1914 _eglUnlockDisplay(dpy
);
1916 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1919 * 'disp' is already unlocked for reusable sync type,
1920 * so passing 'NULL' to bypass unlocking display.
1922 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1923 RETURN_EGL_EVAL(NULL
, ret
);
1925 RETURN_EGL_EVAL(disp
, ret
);
1929 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
1930 EGLint flags
, EGLTime timeout
)
1932 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1933 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1934 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1935 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1938 static EGLint EGLAPIENTRY
1939 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
1940 EGLint flags
, EGLTime timeout
)
1942 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1943 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1944 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1945 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1950 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
1952 _EGLContext
*ctx
= _eglGetCurrentContext();
1956 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1957 assert(disp
->Extensions
.KHR_wait_sync
);
1959 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1960 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1961 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1963 /* the API doesn't allow any flags yet */
1965 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1967 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1969 RETURN_EGL_EVAL(disp
, ret
);
1972 static EGLint EGLAPIENTRY
1973 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1975 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1976 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1977 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1978 return _eglWaitSyncCommon(disp
, s
, flags
);
1982 EGLBoolean EGLAPIENTRY
1983 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1985 /* The KHR version returns EGLint, while the core version returns
1986 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1989 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1990 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1991 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1992 return _eglWaitSyncCommon(disp
, s
, flags
);
1996 static EGLBoolean EGLAPIENTRY
1997 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
1999 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2000 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2004 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2006 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2007 assert(disp
->Extensions
.KHR_reusable_sync
);
2008 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2010 RETURN_EGL_EVAL(disp
, ret
);
2015 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2020 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2021 assert(disp
->Extensions
.KHR_reusable_sync
||
2022 disp
->Extensions
.KHR_fence_sync
||
2023 disp
->Extensions
.ANDROID_native_fence_sync
);
2024 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2026 RETURN_EGL_EVAL(disp
, ret
);
2029 EGLBoolean EGLAPIENTRY
2030 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2032 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2033 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2034 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2035 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2039 static EGLBoolean EGLAPIENTRY
2040 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2042 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2043 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2047 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2050 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2053 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2055 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2057 * If any error occurs, <*value> is not modified.
2059 if (result
== EGL_FALSE
)
2066 static EGLint EGLAPIENTRY
2067 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2069 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2070 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2074 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2076 /* the spec doesn't seem to specify what happens if the fence
2077 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2080 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2081 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2083 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2084 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2085 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2087 RETURN_EGL_EVAL(disp
, ret
);
2090 static EGLBoolean EGLAPIENTRY
2091 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2092 EGLint numRects
, const EGLint
*rects
)
2094 _EGLContext
*ctx
= _eglGetCurrentContext();
2095 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2096 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2100 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2102 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2104 if (!disp
->Extensions
.NOK_swap_region
)
2105 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2107 /* surface must be bound to current context in EGL 1.4 */
2108 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2109 surf
!= ctx
->DrawSurface
)
2110 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2112 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2114 RETURN_EGL_EVAL(disp
, ret
);
2118 static EGLImage EGLAPIENTRY
2119 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2121 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2126 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2128 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2129 if (!disp
->Extensions
.MESA_drm_image
)
2130 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2132 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2133 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2135 RETURN_EGL_EVAL(disp
, ret
);
2138 static EGLBoolean EGLAPIENTRY
2139 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2140 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2142 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2143 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2147 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2149 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2150 assert(disp
->Extensions
.MESA_drm_image
);
2153 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2155 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2157 RETURN_EGL_EVAL(disp
, ret
);
2163 static EGLBoolean EGLAPIENTRY
2164 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2166 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2170 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2172 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2173 assert(disp
->Extensions
.WL_bind_wayland_display
);
2176 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2178 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2180 RETURN_EGL_EVAL(disp
, ret
);
2183 static EGLBoolean EGLAPIENTRY
2184 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2186 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2190 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2192 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2193 assert(disp
->Extensions
.WL_bind_wayland_display
);
2196 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2198 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2200 RETURN_EGL_EVAL(disp
, ret
);
2203 static EGLBoolean EGLAPIENTRY
2204 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2205 EGLint attribute
, EGLint
*value
)
2207 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2211 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2213 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2214 assert(disp
->Extensions
.WL_bind_wayland_display
);
2217 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2219 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2221 RETURN_EGL_EVAL(disp
, ret
);
2225 static struct wl_buffer
* EGLAPIENTRY
2226 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2228 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2231 struct wl_buffer
*ret
;
2233 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2235 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2236 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2237 RETURN_EGL_EVAL(disp
, NULL
);
2239 img
= _eglLookupImage(image
, disp
);
2242 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2244 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2246 RETURN_EGL_EVAL(disp
, ret
);
2249 static EGLBoolean EGLAPIENTRY
2250 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2251 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2253 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2254 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2258 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2260 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2262 if (!disp
->Extensions
.NV_post_sub_buffer
)
2263 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2265 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2267 RETURN_EGL_EVAL(disp
, ret
);
2270 static EGLBoolean EGLAPIENTRY
2271 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
2272 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2275 _EGLDisplay
*disp
= _eglLockDisplay(display
);
2276 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2280 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2282 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2283 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2284 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2286 if (!ust
|| !msc
|| !sbc
)
2287 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2289 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2291 RETURN_EGL_EVAL(disp
, ret
);
2294 static EGLBoolean EGLAPIENTRY
2295 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2296 EGLint
*fourcc
, EGLint
*nplanes
,
2297 EGLuint64KHR
*modifiers
)
2299 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2300 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2304 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2306 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2307 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2310 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2312 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2315 RETURN_EGL_EVAL(disp
, ret
);
2318 static EGLBoolean EGLAPIENTRY
2319 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2320 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2322 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2323 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2327 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2329 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2330 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2333 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2335 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2337 RETURN_EGL_EVAL(disp
, ret
);
2340 static EGLint EGLAPIENTRY
2341 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2344 _EGLDisplay
*disp
= NULL
;
2345 _EGLResourceType type
;
2347 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2349 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2350 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2352 if (!_eglIsCurrentThreadDummy()) {
2357 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2360 disp
= _eglLockDisplay(dpy
);
2362 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2364 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2365 if (dpy
!= (EGLDisplay
) object
)
2366 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2368 disp
->Label
= label
;
2369 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2372 switch (objectType
) {
2373 case EGL_OBJECT_CONTEXT_KHR
:
2374 type
= _EGL_RESOURCE_CONTEXT
;
2376 case EGL_OBJECT_SURFACE_KHR
:
2377 type
= _EGL_RESOURCE_SURFACE
;
2379 case EGL_OBJECT_IMAGE_KHR
:
2380 type
= _EGL_RESOURCE_IMAGE
;
2382 case EGL_OBJECT_SYNC_KHR
:
2383 type
= _EGL_RESOURCE_SYNC
;
2385 case EGL_OBJECT_STREAM_KHR
:
2387 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2390 if (_eglCheckResource(object
, type
, disp
)) {
2391 _EGLResource
*res
= (_EGLResource
*) object
;
2394 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2397 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2400 static EGLint EGLAPIENTRY
2401 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2402 const EGLAttrib
*attrib_list
)
2404 unsigned int newEnabled
;
2406 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2408 mtx_lock(_eglGlobal
.Mutex
);
2410 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2411 if (attrib_list
!= NULL
) {
2414 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2415 switch (attrib_list
[i
]) {
2416 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2417 case EGL_DEBUG_MSG_ERROR_KHR
:
2418 case EGL_DEBUG_MSG_WARN_KHR
:
2419 case EGL_DEBUG_MSG_INFO_KHR
:
2420 if (attrib_list
[i
+ 1])
2421 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2423 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2426 // On error, set the last error code, call the current
2427 // debug callback, and return the error code.
2428 mtx_unlock(_eglGlobal
.Mutex
);
2429 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2430 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2431 return EGL_BAD_ATTRIBUTE
;
2436 if (callback
!= NULL
) {
2437 _eglGlobal
.debugCallback
= callback
;
2438 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2440 _eglGlobal
.debugCallback
= NULL
;
2441 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2444 mtx_unlock(_eglGlobal
.Mutex
);
2448 static EGLBoolean EGLAPIENTRY
2449 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2451 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2453 mtx_lock(_eglGlobal
.Mutex
);
2455 switch (attribute
) {
2456 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2457 case EGL_DEBUG_MSG_ERROR_KHR
:
2458 case EGL_DEBUG_MSG_WARN_KHR
:
2459 case EGL_DEBUG_MSG_INFO_KHR
:
2460 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2465 case EGL_DEBUG_CALLBACK_KHR
:
2466 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2469 mtx_unlock(_eglGlobal
.Mutex
);
2470 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2471 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2475 mtx_unlock(_eglGlobal
.Mutex
);
2480 _eglFunctionCompare(const void *key
, const void *elem
)
2482 const char *procname
= key
;
2483 const struct _egl_entrypoint
*entrypoint
= elem
;
2484 return strcmp(procname
, entrypoint
->name
);
2487 static EGLBoolean EGLAPIENTRY
2488 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2489 EGLint
*formats
, EGLint
*num_formats
)
2491 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2495 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2497 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2499 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2502 RETURN_EGL_EVAL(disp
, ret
);
2505 static EGLBoolean EGLAPIENTRY
2506 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2507 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2508 EGLint
*num_modifiers
)
2510 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2514 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2516 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2518 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2519 modifiers
, external_only
,
2522 RETURN_EGL_EVAL(disp
, ret
);
2525 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2526 eglGetProcAddress(const char *procname
)
2528 static const struct _egl_entrypoint egl_functions
[] = {
2529 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2530 #include "eglentrypoint.h"
2531 #undef EGL_ENTRYPOINT
2533 _EGLProc ret
= NULL
;
2536 RETURN_EGL_SUCCESS(NULL
, NULL
);
2538 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2540 if (strncmp(procname
, "egl", 3) == 0) {
2541 const struct _egl_entrypoint
*entrypoint
=
2543 egl_functions
, ARRAY_SIZE(egl_functions
),
2544 sizeof(egl_functions
[0]),
2545 _eglFunctionCompare
);
2547 ret
= entrypoint
->function
;
2551 ret
= _eglGetDriverProc(procname
);
2553 RETURN_EGL_SUCCESS(NULL
, ret
);
2557 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2558 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2562 *disp
= _eglLockDisplay(dpy
);
2563 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2565 _eglUnlockDisplay(*disp
);
2566 return MESA_GLINTEROP_INVALID_DISPLAY
;
2569 *drv
= (*disp
)->Driver
;
2571 *ctx
= _eglLookupContext(context
, *disp
);
2573 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2574 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2575 _eglUnlockDisplay(*disp
);
2576 return MESA_GLINTEROP_INVALID_CONTEXT
;
2579 return MESA_GLINTEROP_SUCCESS
;
2583 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2584 struct mesa_glinterop_device_info
*out
)
2591 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2592 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2595 if (drv
->API
.GLInteropQueryDeviceInfo
)
2596 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2598 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2600 _eglUnlockDisplay(disp
);
2605 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2606 struct mesa_glinterop_export_in
*in
,
2607 struct mesa_glinterop_export_out
*out
)
2614 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2615 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2618 if (drv
->API
.GLInteropExportObject
)
2619 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2621 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2623 _eglUnlockDisplay(disp
);