1 /**************************************************************************
3 * Copyright 2008 VMware, Inc.
4 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5 * Copyright 2010-2011 LunarG, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
32 * Public EGL API entrypoints
34 * Generally, we use the EGLDisplay parameter as a key to lookup the
35 * appropriate device driver handle, then jump though the driver's
36 * dispatch table to handle the function.
38 * That allows us the option of supporting multiple, simultaneous,
39 * heterogeneous hardware devices in the future.
41 * The EGLDisplay, EGLConfig, EGLContext and EGLSurface types are
42 * opaque handles. Internal objects are linked to a display to
45 * For each public API entry point, the opaque handles are looked up
46 * before being dispatched to the drivers. When it fails to look up
56 * is generated and the driver function is not called. An
57 * uninitialized EGLDisplay has no driver associated with it. When
58 * such display is detected,
64 * Some of the entry points use current display, context, or surface
65 * implicitly. For such entry points, the implicit objects are also
66 * checked before calling the driver function. Other than the
67 * errors listed above,
69 * EGL_BAD_CURRENT_SURFACE
71 * may also be generated.
73 * Notes on naming conventions:
75 * eglFooBar - public EGL function
76 * EGL_FOO_BAR - public EGL token
77 * EGLDatatype - public EGL datatype
79 * _eglFooBar - private EGL function
80 * _EGLDatatype - private EGL datatype, typedef'd struct
81 * _egl_struct - private EGL struct, non-typedef'd
89 #include "c99_compat.h"
90 #include "c11/threads.h"
91 #include "util/macros.h"
93 #include "eglglobals.h"
94 #include "eglcontext.h"
95 #include "egldisplay.h"
96 #include "egltypedefs.h"
97 #include "eglcurrent.h"
98 #include "egldriver.h"
99 #include "eglsurface.h"
100 #include "eglconfig.h"
101 #include "eglimage.h"
104 #include "GL/mesa_glinterop.h"
107 * Macros to help return an API entrypoint.
109 * These macros will unlock the display and record the error code.
111 #define RETURN_EGL_ERROR(disp, err, ret) \
114 _eglUnlockDisplay(disp); \
115 /* EGL error codes are non-zero */ \
117 _eglError(err, __func__); \
121 #define RETURN_EGL_SUCCESS(disp, ret) \
122 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
124 /* record EGL_SUCCESS only when ret evaluates to true */
125 #define RETURN_EGL_EVAL(disp, ret) \
126 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
130 * A bunch of macros and checks to simplify error checking.
133 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
135 drv = _eglCheckDisplay(disp, __func__); \
137 RETURN_EGL_ERROR(disp, 0, ret); \
140 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
142 drv = _eglCheck ## type(disp, obj, __func__); \
144 RETURN_EGL_ERROR(disp, 0, ret); \
147 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
148 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
150 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
151 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
153 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
154 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
156 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
157 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
160 struct _egl_entrypoint
{
166 static inline _EGLDriver
*
167 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
170 _eglError(EGL_BAD_DISPLAY
, msg
);
173 if (!disp
->Initialized
) {
174 _eglError(EGL_NOT_INITIALIZED
, msg
);
181 static inline _EGLDriver
*
182 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
184 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
188 _eglError(EGL_BAD_SURFACE
, msg
);
195 static inline _EGLDriver
*
196 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
198 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
202 _eglError(EGL_BAD_CONTEXT
, msg
);
209 static inline _EGLDriver
*
210 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
212 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
216 _eglError(EGL_BAD_CONFIG
, msg
);
223 static inline _EGLDriver
*
224 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
226 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
230 _eglError(EGL_BAD_PARAMETER
, msg
);
238 * Lookup and lock a display.
240 static inline _EGLDisplay
*
241 _eglLockDisplay(EGLDisplay display
)
243 _EGLDisplay
*dpy
= _eglLookupDisplay(display
);
245 mtx_lock(&dpy
->Mutex
);
254 _eglUnlockDisplay(_EGLDisplay
*dpy
)
256 mtx_unlock(&dpy
->Mutex
);
260 _eglSetFuncName(const char *funcName
, _EGLDisplay
*disp
, EGLenum objectType
, _EGLResource
*object
)
262 _EGLThreadInfo
*thr
= _eglGetCurrentThread();
263 if (!_eglIsCurrentThreadDummy()) {
264 thr
->CurrentFuncName
= funcName
;
265 thr
->CurrentObjectLabel
= NULL
;
267 if (objectType
== EGL_OBJECT_THREAD_KHR
)
268 thr
->CurrentObjectLabel
= thr
->Label
;
269 else if (objectType
== EGL_OBJECT_DISPLAY_KHR
&& disp
)
270 thr
->CurrentObjectLabel
= disp
->Label
;
272 thr
->CurrentObjectLabel
= object
->Label
;
277 _eglDebugReport(EGL_BAD_ALLOC
, funcName
, EGL_DEBUG_MSG_CRITICAL_KHR
, NULL
);
281 #define _EGL_FUNC_START(disp, objectType, object, ret) \
283 if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \
285 _eglUnlockDisplay(disp); \
291 * Convert an attribute list from EGLint[] to EGLAttrib[].
293 * Return an EGL error code. The output parameter out_attrib_list is modified
297 _eglConvertIntsToAttribs(const EGLint
*int_list
, EGLAttrib
**out_attrib_list
)
300 EGLAttrib
*attrib_list
;
303 while (int_list
[2*len
] != EGL_NONE
)
308 *out_attrib_list
= NULL
;
312 if (2*len
+ 1 > SIZE_MAX
/ sizeof(EGLAttrib
))
313 return EGL_BAD_ALLOC
;
315 attrib_list
= malloc((2*len
+ 1) * sizeof(EGLAttrib
));
317 return EGL_BAD_ALLOC
;
319 for (size_t i
= 0; i
< len
; ++i
) {
320 attrib_list
[2*i
+ 0] = int_list
[2*i
+ 0];
321 attrib_list
[2*i
+ 1] = int_list
[2*i
+ 1];
324 attrib_list
[2*len
] = EGL_NONE
;
326 *out_attrib_list
= attrib_list
;
332 _eglConvertAttribsToInt(const EGLAttrib
*attr_list
)
334 EGLint
*int_attribs
= NULL
;
336 /* Convert attributes from EGLAttrib[] to EGLint[] */
340 while (attr_list
[size
] != EGL_NONE
)
343 size
+= 1; /* add space for EGL_NONE */
345 int_attribs
= calloc(size
, sizeof(int_attribs
[0]));
349 for (i
= 0; i
< size
; i
++)
350 int_attribs
[i
] = attr_list
[i
];
357 * This is typically the first EGL function that an application calls.
358 * It associates a private _EGLDisplay object to the native display.
360 EGLDisplay EGLAPIENTRY
361 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
363 _EGLPlatformType plat
;
365 void *native_display_ptr
;
367 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
369 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
370 native_display_ptr
= (void*) nativeDisplay
;
372 plat
= _eglGetNativePlatform(native_display_ptr
);
373 dpy
= _eglFindDisplay(plat
, native_display_ptr
);
374 return _eglGetDisplayHandle(dpy
);
378 _eglGetPlatformDisplayCommon(EGLenum platform
, void *native_display
,
379 const EGLAttrib
*attrib_list
)
384 #ifdef HAVE_X11_PLATFORM
385 case EGL_PLATFORM_X11_EXT
:
386 dpy
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
389 #ifdef HAVE_DRM_PLATFORM
390 case EGL_PLATFORM_GBM_MESA
:
391 dpy
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
395 #ifdef HAVE_WAYLAND_PLATFORM
396 case EGL_PLATFORM_WAYLAND_EXT
:
397 dpy
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
401 #ifdef HAVE_SURFACELESS_PLATFORM
402 case EGL_PLATFORM_SURFACELESS_MESA
:
403 dpy
= _eglGetSurfacelessDisplay(native_display
, attrib_list
);
407 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
410 return _eglGetDisplayHandle(dpy
);
413 static EGLDisplay EGLAPIENTRY
414 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
415 const EGLint
*int_attribs
)
417 EGLAttrib
*attrib_list
;
420 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
422 if (_eglConvertIntsToAttribs(int_attribs
, &attrib_list
) != EGL_SUCCESS
)
423 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
425 display
= _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
430 EGLDisplay EGLAPIENTRY
431 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
432 const EGLAttrib
*attrib_list
)
434 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
435 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
439 * Copy the extension into the string and update the string pointer.
442 _eglAppendExtension(char **str
, const char *ext
)
445 size_t len
= strlen(ext
);
462 * Examine the individual extension enable/disable flags and recompute
463 * the driver's Extensions string.
466 _eglCreateExtensionsString(_EGLDisplay
*dpy
)
468 #define _EGL_CHECK_EXTENSION(ext) \
470 if (dpy->Extensions.ext) { \
471 _eglAppendExtension(&exts, "EGL_" #ext); \
472 assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
476 char *exts
= dpy
->ExtensionsString
;
478 /* Please keep these sorted alphabetically. */
479 _EGL_CHECK_EXTENSION(ANDROID_blob_cache
);
480 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
481 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
482 _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync
);
483 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
485 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
487 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
488 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
489 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
490 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers
);
491 _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata
);
492 _EGL_CHECK_EXTENSION(EXT_surface_SMPTE2086_metadata
);
493 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
495 _EGL_CHECK_EXTENSION(IMG_context_priority
);
497 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
498 _EGL_CHECK_EXTENSION(KHR_config_attribs
);
499 _EGL_CHECK_EXTENSION(KHR_context_flush_control
);
500 _EGL_CHECK_EXTENSION(KHR_create_context
);
501 _EGL_CHECK_EXTENSION(KHR_create_context_no_error
);
502 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
503 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
504 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
505 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
506 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
507 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
508 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
509 if (dpy
->Extensions
.KHR_image_base
&& dpy
->Extensions
.KHR_image_pixmap
)
510 dpy
->Extensions
.KHR_image
= EGL_TRUE
;
511 _EGL_CHECK_EXTENSION(KHR_image
);
512 _EGL_CHECK_EXTENSION(KHR_image_base
);
513 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
514 _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer
);
515 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
516 _EGL_CHECK_EXTENSION(KHR_partial_update
);
517 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
518 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
519 if (dpy
->Extensions
.EXT_swap_buffers_with_damage
)
520 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
521 _EGL_CHECK_EXTENSION(EXT_pixel_format_float
);
522 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
524 if (dpy
->Extensions
.KHR_no_config_context
)
525 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
526 _EGL_CHECK_EXTENSION(MESA_drm_image
);
527 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
529 _EGL_CHECK_EXTENSION(NOK_swap_region
);
530 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
532 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
534 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
535 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
537 #undef _EGL_CHECK_EXTENSION
541 _eglCreateAPIsString(_EGLDisplay
*dpy
)
543 #define addstr(str) \
545 const size_t old_len = strlen(dpy->ClientAPIsString); \
546 const size_t add_len = sizeof(str); \
547 const size_t max_len = sizeof(dpy->ClientAPIsString) - 1; \
548 if (old_len + add_len <= max_len) \
549 strcat(dpy->ClientAPIsString, str " "); \
551 assert(!"dpy->ClientAPIsString is not large enough"); \
554 if (dpy
->ClientAPIs
& EGL_OPENGL_BIT
)
557 if (dpy
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
558 dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
559 dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
563 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
570 _eglComputeVersion(_EGLDisplay
*disp
)
574 if (disp
->Extensions
.KHR_fence_sync
&&
575 disp
->Extensions
.KHR_cl_event2
&&
576 disp
->Extensions
.KHR_wait_sync
&&
577 disp
->Extensions
.KHR_image_base
&&
578 disp
->Extensions
.KHR_gl_texture_2D_image
&&
579 disp
->Extensions
.KHR_gl_texture_3D_image
&&
580 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
581 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
582 disp
->Extensions
.KHR_create_context
&&
583 disp
->Extensions
.EXT_create_context_robustness
&&
584 disp
->Extensions
.KHR_get_all_proc_addresses
&&
585 disp
->Extensions
.KHR_gl_colorspace
&&
586 disp
->Extensions
.KHR_surfaceless_context
)
591 * This is typically the second EGL function that an application calls.
592 * Here we load/initialize the actual hardware driver.
594 EGLBoolean EGLAPIENTRY
595 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
597 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
599 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
602 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
604 if (!disp
->Initialized
) {
605 if (!_eglMatchDriver(disp
))
606 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
608 /* limit to APIs supported by core */
609 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
611 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
612 * classifies it as an EGL display extension, though conceptually it's an
613 * EGL client extension.
615 * From the EGL_KHR_get_all_proc_addresses spec:
617 * The EGL implementation must expose the name
618 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
619 * EGL_KHR_get_all_proc_addresses and supports
620 * EGL_EXT_client_extensions.
622 * Mesa unconditionally exposes both client extensions mentioned above,
623 * so the spec requires that each EGLDisplay unconditionally expose
624 * EGL_KHR_get_all_proc_addresses also.
626 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
628 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
629 * programs. It is driver agnostic and handled in the main EGL code.
631 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
633 _eglComputeVersion(disp
);
634 _eglCreateExtensionsString(disp
);
635 _eglCreateAPIsString(disp
);
636 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
637 "%d.%d", disp
->Version
/ 10, disp
->Version
% 10);
640 /* Update applications version of major and minor if not NULL */
641 if ((major
!= NULL
) && (minor
!= NULL
)) {
642 *major
= disp
->Version
/ 10;
643 *minor
= disp
->Version
% 10;
646 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
650 EGLBoolean EGLAPIENTRY
651 eglTerminate(EGLDisplay dpy
)
653 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
655 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
658 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
660 if (disp
->Initialized
) {
661 _EGLDriver
*drv
= disp
->Driver
;
663 drv
->API
.Terminate(drv
, disp
);
664 /* do not reset disp->Driver */
665 disp
->ClientAPIsString
[0] = 0;
666 disp
->Initialized
= EGL_FALSE
;
669 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
673 const char * EGLAPIENTRY
674 eglQueryString(EGLDisplay dpy
, EGLint name
)
679 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
680 const char *ret
= _eglGetClientExtensionString();
682 RETURN_EGL_SUCCESS(NULL
, ret
);
684 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
687 disp
= _eglLockDisplay(dpy
);
688 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
689 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
693 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
695 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
697 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
698 case EGL_CLIENT_APIS
:
699 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
701 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
706 EGLBoolean EGLAPIENTRY
707 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
708 EGLint config_size
, EGLint
*num_config
)
710 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
714 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
716 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
717 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
719 RETURN_EGL_EVAL(disp
, ret
);
723 EGLBoolean EGLAPIENTRY
724 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
725 EGLint config_size
, EGLint
*num_config
)
727 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
731 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
733 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
734 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
735 config_size
, num_config
);
737 RETURN_EGL_EVAL(disp
, ret
);
741 EGLBoolean EGLAPIENTRY
742 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
743 EGLint attribute
, EGLint
*value
)
745 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
746 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
750 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
752 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
753 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
755 RETURN_EGL_EVAL(disp
, ret
);
759 EGLContext EGLAPIENTRY
760 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
761 const EGLint
*attrib_list
)
763 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
764 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
765 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
767 _EGLContext
*context
;
770 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
772 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
774 if (config
!= EGL_NO_CONFIG_KHR
)
775 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
776 else if (!disp
->Extensions
.KHR_no_config_context
)
777 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
779 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
780 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
782 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
783 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
785 RETURN_EGL_EVAL(disp
, ret
);
789 EGLBoolean EGLAPIENTRY
790 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
792 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
793 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
797 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
799 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
800 _eglUnlinkContext(context
);
801 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
803 RETURN_EGL_EVAL(disp
, ret
);
807 EGLBoolean EGLAPIENTRY
808 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
811 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
812 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
813 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
814 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
818 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
821 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
824 /* display is allowed to be uninitialized under certain condition */
825 if (!disp
->Initialized
) {
826 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
827 ctx
!= EGL_NO_CONTEXT
)
828 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
831 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
833 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
834 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
835 if (!draw_surf
|| !read_surf
) {
836 /* From the EGL 1.4 (20130211) spec:
838 * To release the current context without assigning a new one, set ctx
839 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
841 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
842 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
844 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
845 (!read_surf
&& read
!= EGL_NO_SURFACE
))
846 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
847 if (draw_surf
|| read_surf
)
848 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
851 /* If a native window underlying either draw or read is no longer valid,
852 * an EGL_BAD_NATIVE_WINDOW error is generated.
854 if (draw_surf
&& draw_surf
->Lost
)
855 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
856 if (read_surf
&& read_surf
->Lost
)
857 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
859 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
861 RETURN_EGL_EVAL(disp
, ret
);
865 EGLBoolean EGLAPIENTRY
866 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
867 EGLint attribute
, EGLint
*value
)
869 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
870 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
874 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
876 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
877 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
879 RETURN_EGL_EVAL(disp
, ret
);
884 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
885 void *native_window
, const EGLint
*attrib_list
)
887 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
893 if (native_window
== NULL
)
894 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
896 #ifdef HAVE_SURFACELESS_PLATFORM
897 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
898 /* From the EGL_MESA_platform_surfaceless spec (v1):
900 * eglCreatePlatformWindowSurface fails when called with a <display>
901 * that belongs to the surfaceless platform. It returns
902 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
903 * justification for this unconditional failure is that the
904 * surfaceless platform has no native windows, and therefore the
905 * <native_window> parameter is always invalid.
907 * This check must occur before checking the EGLConfig, which emits
910 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
914 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
916 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
917 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
919 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
921 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
923 RETURN_EGL_EVAL(disp
, ret
);
927 EGLSurface EGLAPIENTRY
928 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
929 EGLNativeWindowType window
, const EGLint
*attrib_list
)
931 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
933 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
934 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
935 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
940 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
942 #ifdef HAVE_X11_PLATFORM
943 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
944 /* The `native_window` parameter for the X11 platform differs between
945 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
946 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
947 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
948 * `Window*`. Convert `Window*` to `Window` because that's what
949 * dri2_x11_create_window_surface() expects.
951 return (void *)(* (Window
*) native_window
);
954 return native_window
;
957 static EGLSurface EGLAPIENTRY
958 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
960 const EGLint
*attrib_list
)
962 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
964 native_window
= _fixupNativeWindow(disp
, native_window
);
966 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
967 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
972 EGLSurface EGLAPIENTRY
973 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
975 const EGLAttrib
*attrib_list
)
977 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
981 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
983 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
984 if (attrib_list
&& !int_attribs
)
985 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
987 native_window
= _fixupNativeWindow(disp
, native_window
);
988 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
995 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
997 #ifdef HAVE_X11_PLATFORM
998 /* The `native_pixmap` parameter for the X11 platform differs between
999 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1000 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1001 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1002 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1003 * dri2_x11_create_pixmap_surface() expects.
1005 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
1006 return (void *)(* (Pixmap
*) native_pixmap
);
1008 return native_pixmap
;
1012 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1013 void *native_pixmap
, const EGLint
*attrib_list
)
1015 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1020 #if HAVE_SURFACELESS_PLATFORM
1021 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
1022 /* From the EGL_MESA_platform_surfaceless spec (v1):
1024 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1025 * also fails when called with a <display> that belongs to the
1026 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1027 * EGL_BAD_NATIVE_PIXMAP.
1029 * This check must occur before checking the EGLConfig, which emits
1032 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1036 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1038 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1039 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1041 if (native_pixmap
== NULL
)
1042 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1044 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1046 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1048 RETURN_EGL_EVAL(disp
, ret
);
1052 EGLSurface EGLAPIENTRY
1053 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1054 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1056 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1058 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1059 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1060 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1064 static EGLSurface EGLAPIENTRY
1065 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1066 void *native_pixmap
,
1067 const EGLint
*attrib_list
)
1069 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1071 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1072 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1073 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1078 EGLSurface EGLAPIENTRY
1079 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1080 void *native_pixmap
,
1081 const EGLAttrib
*attrib_list
)
1083 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1085 EGLint
*int_attribs
;
1087 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1089 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1090 if (attrib_list
&& !int_attribs
)
1091 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1093 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1094 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1101 EGLSurface EGLAPIENTRY
1102 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1103 const EGLint
*attrib_list
)
1105 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1106 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1111 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1112 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1114 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1115 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1117 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1118 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1120 RETURN_EGL_EVAL(disp
, ret
);
1124 EGLBoolean EGLAPIENTRY
1125 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1127 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1128 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1132 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1133 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1134 _eglUnlinkSurface(surf
);
1135 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1137 RETURN_EGL_EVAL(disp
, ret
);
1140 EGLBoolean EGLAPIENTRY
1141 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1142 EGLint attribute
, EGLint
*value
)
1144 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1145 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1149 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1150 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1151 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1153 RETURN_EGL_EVAL(disp
, ret
);
1156 EGLBoolean EGLAPIENTRY
1157 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1158 EGLint attribute
, EGLint value
)
1160 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1161 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1165 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1166 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1167 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1169 RETURN_EGL_EVAL(disp
, ret
);
1173 EGLBoolean EGLAPIENTRY
1174 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1176 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1177 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1181 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1182 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1183 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1185 RETURN_EGL_EVAL(disp
, ret
);
1189 EGLBoolean EGLAPIENTRY
1190 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1192 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1193 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1197 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1198 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1199 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1201 RETURN_EGL_EVAL(disp
, ret
);
1205 EGLBoolean EGLAPIENTRY
1206 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1208 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1209 _EGLContext
*ctx
= _eglGetCurrentContext();
1210 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1214 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1215 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1217 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1218 ctx
->Resource
.Display
!= disp
)
1219 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1221 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1222 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1224 if (surf
->Type
!= EGL_WINDOW_BIT
)
1225 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1227 interval
= CLAMP(interval
,
1228 surf
->Config
->MinSwapInterval
,
1229 surf
->Config
->MaxSwapInterval
);
1231 if (surf
->SwapInterval
!= interval
)
1232 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1237 surf
->SwapInterval
= interval
;
1239 RETURN_EGL_EVAL(disp
, ret
);
1243 EGLBoolean EGLAPIENTRY
1244 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1246 _EGLContext
*ctx
= _eglGetCurrentContext();
1247 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1248 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1252 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1253 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1255 /* surface must be bound to current context in EGL 1.4 */
1256 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1257 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1258 surf
!= ctx
->DrawSurface
)
1259 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1262 if (surf
->Type
!= EGL_WINDOW_BIT
)
1263 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1265 /* From the EGL 1.5 spec:
1267 * If eglSwapBuffers is called and the native window associated with
1268 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1272 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1274 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1276 /* EGL_KHR_partial_update
1277 * Frame boundary successfully reached,
1278 * reset damage region and reset BufferAgeRead
1281 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1282 surf
->BufferAgeRead
= EGL_FALSE
;
1285 RETURN_EGL_EVAL(disp
, ret
);
1290 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1291 EGLint
*rects
, EGLint n_rects
)
1293 _EGLContext
*ctx
= _eglGetCurrentContext();
1297 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1299 /* surface must be bound to current context in EGL 1.4 */
1300 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1301 surf
!= ctx
->DrawSurface
)
1302 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1304 if (surf
->Type
!= EGL_WINDOW_BIT
)
1305 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1307 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1308 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1310 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1312 /* EGL_KHR_partial_update
1313 * Frame boundary successfully reached,
1314 * reset damage region and reset BufferAgeRead
1317 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1318 surf
->BufferAgeRead
= EGL_FALSE
;
1321 RETURN_EGL_EVAL(disp
, ret
);
1324 static EGLBoolean EGLAPIENTRY
1325 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1326 EGLint
*rects
, EGLint n_rects
)
1328 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1329 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1330 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1331 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1334 static EGLBoolean EGLAPIENTRY
1335 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1336 EGLint
*rects
, EGLint n_rects
)
1338 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1339 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1340 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1341 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1345 * Clamp the rectangles so that they lie within the surface.
1349 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1350 EGLint
*rects
, EGLint n_rects
)
1353 EGLint surf_height
= surf
->Height
;
1354 EGLint surf_width
= surf
->Width
;
1356 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1357 EGLint x1
, y1
, x2
, y2
;
1360 x2
= rects
[i
+ 2] + x1
;
1361 y2
= rects
[i
+ 3] + y1
;
1363 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1364 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1365 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1366 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1370 static EGLBoolean EGLAPIENTRY
1371 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1372 EGLint
*rects
, EGLint n_rects
)
1374 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1375 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1376 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1377 _EGLContext
*ctx
= _eglGetCurrentContext();
1380 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1382 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1383 surf
->Type
!= EGL_WINDOW_BIT
||
1384 ctx
->DrawSurface
!= surf
||
1385 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1386 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1388 /* If the damage region is already set or
1389 * buffer age is not queried between
1390 * frame boundaries, throw bad access error
1393 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1394 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1396 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1397 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1400 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1402 RETURN_EGL_EVAL(disp
, ret
);
1405 EGLBoolean EGLAPIENTRY
1406 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1408 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1409 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1412 void *native_pixmap_ptr
;
1414 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1415 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1416 native_pixmap_ptr
= (void*) target
;
1418 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1419 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1421 RETURN_EGL_EVAL(disp
, ret
);
1426 _eglWaitClientCommon(void)
1428 _EGLContext
*ctx
= _eglGetCurrentContext();
1434 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1436 disp
= ctx
->Resource
.Display
;
1437 mtx_lock(&disp
->Mutex
);
1439 /* let bad current context imply bad current surface */
1440 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1441 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1442 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1444 /* a valid current context implies an initialized current display */
1445 assert(disp
->Initialized
);
1447 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1449 RETURN_EGL_EVAL(disp
, ret
);
1452 EGLBoolean EGLAPIENTRY
1455 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1456 return _eglWaitClientCommon();
1459 EGLBoolean EGLAPIENTRY
1462 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1463 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1464 return _eglWaitClientCommon();
1468 EGLBoolean EGLAPIENTRY
1469 eglWaitNative(EGLint engine
)
1471 _EGLContext
*ctx
= _eglGetCurrentContext();
1477 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1479 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1481 disp
= ctx
->Resource
.Display
;
1482 mtx_lock(&disp
->Mutex
);
1484 /* let bad current context imply bad current surface */
1485 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1486 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1487 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1489 /* a valid current context implies an initialized current display */
1490 assert(disp
->Initialized
);
1492 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1494 RETURN_EGL_EVAL(disp
, ret
);
1498 EGLDisplay EGLAPIENTRY
1499 eglGetCurrentDisplay(void)
1501 _EGLContext
*ctx
= _eglGetCurrentContext();
1504 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1506 RETURN_EGL_SUCCESS(NULL
, ret
);
1510 EGLContext EGLAPIENTRY
1511 eglGetCurrentContext(void)
1513 _EGLContext
*ctx
= _eglGetCurrentContext();
1516 ret
= _eglGetContextHandle(ctx
);
1518 RETURN_EGL_SUCCESS(NULL
, ret
);
1522 EGLSurface EGLAPIENTRY
1523 eglGetCurrentSurface(EGLint readdraw
)
1525 _EGLContext
*ctx
= _eglGetCurrentContext();
1526 EGLint err
= EGL_SUCCESS
;
1530 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1533 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1537 surf
= ctx
->DrawSurface
;
1540 surf
= ctx
->ReadSurface
;
1544 err
= EGL_BAD_PARAMETER
;
1548 ret
= _eglGetSurfaceHandle(surf
);
1550 RETURN_EGL_ERROR(NULL
, err
, ret
);
1557 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1558 EGLint e
= t
->LastError
;
1559 if (!_eglIsCurrentThreadDummy())
1560 t
->LastError
= EGL_SUCCESS
;
1570 * Specify the client API to use for subsequent calls including:
1571 * eglCreateContext()
1572 * eglGetCurrentContext()
1573 * eglGetCurrentDisplay()
1574 * eglGetCurrentSurface()
1575 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1578 * See section 3.7 "Rendering Context" in the EGL specification for details.
1580 EGLBoolean EGLAPIENTRY
1581 eglBindAPI(EGLenum api
)
1585 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1587 t
= _eglGetCurrentThread();
1588 if (_eglIsCurrentThreadDummy())
1589 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1591 if (!_eglIsApiValid(api
))
1592 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1594 t
->CurrentAPI
= api
;
1596 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1601 * Return the last value set with eglBindAPI().
1606 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1609 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1610 ret
= t
->CurrentAPI
;
1612 RETURN_EGL_SUCCESS(NULL
, ret
);
1616 EGLSurface EGLAPIENTRY
1617 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1618 EGLClientBuffer buffer
, EGLConfig config
,
1619 const EGLint
*attrib_list
)
1621 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1622 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1627 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1629 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1631 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1633 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1635 RETURN_EGL_EVAL(disp
, ret
);
1639 EGLBoolean EGLAPIENTRY
1640 eglReleaseThread(void)
1642 /* unbind current contexts */
1643 if (!_eglIsCurrentThreadDummy()) {
1644 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1645 _EGLContext
*ctx
= t
->CurrentContext
;
1647 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1650 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1653 mtx_lock(&disp
->Mutex
);
1655 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1656 mtx_unlock(&disp
->Mutex
);
1660 _eglDestroyCurrentThread();
1662 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1667 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1668 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1670 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1675 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1676 if (!disp
->Extensions
.KHR_image_base
)
1677 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1678 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1679 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1680 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1681 * <ctx> must be EGL_NO_CONTEXT..."
1683 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1684 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1686 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1688 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1690 RETURN_EGL_EVAL(disp
, ret
);
1693 static EGLImage EGLAPIENTRY
1694 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1695 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1697 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1698 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1699 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1703 EGLImage EGLAPIENTRY
1704 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1705 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1707 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1709 EGLint
*int_attribs
;
1711 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1713 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1714 if (attr_list
&& !int_attribs
)
1715 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1717 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1724 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1729 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1730 if (!disp
->Extensions
.KHR_image_base
)
1731 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1733 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1735 _eglUnlinkImage(img
);
1736 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1738 RETURN_EGL_EVAL(disp
, ret
);
1741 EGLBoolean EGLAPIENTRY
1742 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1744 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1745 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1746 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1747 return _eglDestroyImageCommon(disp
, img
);
1750 static EGLBoolean EGLAPIENTRY
1751 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1753 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1754 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1755 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1756 return _eglDestroyImageCommon(disp
, img
);
1761 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1762 EGLBoolean orig_is_EGLAttrib
,
1763 EGLenum invalid_type_error
)
1765 _EGLContext
*ctx
= _eglGetCurrentContext();
1770 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1772 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1773 /* There exist two EGLAttrib variants of eglCreateSync*:
1774 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1775 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1776 * support as a proxy for EGL 1.5 support, even though that's not
1777 * entirely correct (though _eglComputeVersion does the same).
1779 * The EGL spec provides no guidance on how to handle unsupported
1780 * functions. EGL_BAD_MATCH seems reasonable.
1782 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1785 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1786 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1787 * error is generated.
1790 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1791 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1793 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1794 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1795 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1796 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1799 case EGL_SYNC_FENCE_KHR
:
1800 if (!disp
->Extensions
.KHR_fence_sync
)
1801 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1803 case EGL_SYNC_REUSABLE_KHR
:
1804 if (!disp
->Extensions
.KHR_reusable_sync
)
1805 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1807 case EGL_SYNC_CL_EVENT_KHR
:
1808 if (!disp
->Extensions
.KHR_cl_event2
)
1809 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1811 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1812 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1813 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1816 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1819 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1820 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1822 RETURN_EGL_EVAL(disp
, ret
);
1826 static EGLSync EGLAPIENTRY
1827 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1829 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1830 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1833 EGLAttrib
*attrib_list
;
1836 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1837 attrib_list
= (EGLAttrib
*) int_list
;
1839 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1840 if (err
!= EGL_SUCCESS
)
1841 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1844 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1847 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1850 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1855 static EGLSync EGLAPIENTRY
1856 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1858 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1859 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1860 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1866 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1868 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1869 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1870 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1876 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1881 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1882 assert(disp
->Extensions
.KHR_reusable_sync
||
1883 disp
->Extensions
.KHR_fence_sync
||
1884 disp
->Extensions
.ANDROID_native_fence_sync
);
1887 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1889 RETURN_EGL_EVAL(disp
, ret
);
1892 EGLBoolean EGLAPIENTRY
1893 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1895 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1896 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1897 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1898 return _eglDestroySync(disp
, s
);
1901 static EGLBoolean EGLAPIENTRY
1902 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1904 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1905 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1906 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1907 return _eglDestroySync(disp
, s
);
1912 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1913 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1918 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1919 assert(disp
->Extensions
.KHR_reusable_sync
||
1920 disp
->Extensions
.KHR_fence_sync
||
1921 disp
->Extensions
.ANDROID_native_fence_sync
);
1923 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1924 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1926 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1927 * unlocked here to allow other threads also to be able to
1928 * go into waiting state.
1931 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1932 _eglUnlockDisplay(dpy
);
1934 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1937 * 'disp' is already unlocked for reusable sync type,
1938 * so passing 'NULL' to bypass unlocking display.
1940 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1941 RETURN_EGL_EVAL(NULL
, ret
);
1943 RETURN_EGL_EVAL(disp
, ret
);
1947 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
1948 EGLint flags
, EGLTime timeout
)
1950 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1951 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1952 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1953 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1956 static EGLint EGLAPIENTRY
1957 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
1958 EGLint flags
, EGLTime timeout
)
1960 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1961 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1962 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1963 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1968 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
1970 _EGLContext
*ctx
= _eglGetCurrentContext();
1974 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1975 assert(disp
->Extensions
.KHR_wait_sync
);
1977 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1978 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1979 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1981 /* the API doesn't allow any flags yet */
1983 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1985 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1987 RETURN_EGL_EVAL(disp
, ret
);
1990 static EGLint EGLAPIENTRY
1991 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1993 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1994 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1995 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1996 return _eglWaitSyncCommon(disp
, s
, flags
);
2000 EGLBoolean EGLAPIENTRY
2001 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2003 /* The KHR version returns EGLint, while the core version returns
2004 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2007 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2008 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2009 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2010 return _eglWaitSyncCommon(disp
, s
, flags
);
2014 static EGLBoolean EGLAPIENTRY
2015 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2017 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2018 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2022 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2024 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2025 assert(disp
->Extensions
.KHR_reusable_sync
);
2026 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2028 RETURN_EGL_EVAL(disp
, ret
);
2033 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2038 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2039 assert(disp
->Extensions
.KHR_reusable_sync
||
2040 disp
->Extensions
.KHR_fence_sync
||
2041 disp
->Extensions
.ANDROID_native_fence_sync
);
2042 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2044 RETURN_EGL_EVAL(disp
, ret
);
2047 EGLBoolean EGLAPIENTRY
2048 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2050 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2051 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2052 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2053 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2057 static EGLBoolean EGLAPIENTRY
2058 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2060 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2061 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2065 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2068 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2071 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2073 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2075 * If any error occurs, <*value> is not modified.
2077 if (result
== EGL_FALSE
)
2084 static EGLint EGLAPIENTRY
2085 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2087 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2088 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2092 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2094 /* the spec doesn't seem to specify what happens if the fence
2095 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2098 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2099 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2101 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2102 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2103 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2105 RETURN_EGL_EVAL(disp
, ret
);
2108 static EGLBoolean EGLAPIENTRY
2109 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2110 EGLint numRects
, const EGLint
*rects
)
2112 _EGLContext
*ctx
= _eglGetCurrentContext();
2113 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2114 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2118 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2120 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2122 if (!disp
->Extensions
.NOK_swap_region
)
2123 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2125 /* surface must be bound to current context in EGL 1.4 */
2126 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2127 surf
!= ctx
->DrawSurface
)
2128 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2130 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2132 RETURN_EGL_EVAL(disp
, ret
);
2136 static EGLImage EGLAPIENTRY
2137 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2139 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2144 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2146 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2147 if (!disp
->Extensions
.MESA_drm_image
)
2148 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2150 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2151 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2153 RETURN_EGL_EVAL(disp
, ret
);
2156 static EGLBoolean EGLAPIENTRY
2157 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2158 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2160 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2161 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2165 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2167 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2168 assert(disp
->Extensions
.MESA_drm_image
);
2171 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2173 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2175 RETURN_EGL_EVAL(disp
, ret
);
2181 static EGLBoolean EGLAPIENTRY
2182 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2184 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2188 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2190 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2191 assert(disp
->Extensions
.WL_bind_wayland_display
);
2194 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2196 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2198 RETURN_EGL_EVAL(disp
, ret
);
2201 static EGLBoolean EGLAPIENTRY
2202 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2204 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2208 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2210 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2211 assert(disp
->Extensions
.WL_bind_wayland_display
);
2214 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2216 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2218 RETURN_EGL_EVAL(disp
, ret
);
2221 static EGLBoolean EGLAPIENTRY
2222 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2223 EGLint attribute
, EGLint
*value
)
2225 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2229 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2231 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2232 assert(disp
->Extensions
.WL_bind_wayland_display
);
2235 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2237 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2239 RETURN_EGL_EVAL(disp
, ret
);
2243 static struct wl_buffer
* EGLAPIENTRY
2244 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2246 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2249 struct wl_buffer
*ret
;
2251 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2253 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2254 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2255 RETURN_EGL_EVAL(disp
, NULL
);
2257 img
= _eglLookupImage(image
, disp
);
2260 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2262 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2264 RETURN_EGL_EVAL(disp
, ret
);
2267 static EGLBoolean EGLAPIENTRY
2268 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2269 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2271 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2272 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2276 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2278 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2280 if (!disp
->Extensions
.NV_post_sub_buffer
)
2281 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2283 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2285 RETURN_EGL_EVAL(disp
, ret
);
2288 static EGLBoolean EGLAPIENTRY
2289 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
2290 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2293 _EGLDisplay
*disp
= _eglLockDisplay(display
);
2294 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2298 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2300 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2301 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2302 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2304 if (!ust
|| !msc
|| !sbc
)
2305 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2307 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2309 RETURN_EGL_EVAL(disp
, ret
);
2312 static EGLBoolean EGLAPIENTRY
2313 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2314 EGLint
*fourcc
, EGLint
*nplanes
,
2315 EGLuint64KHR
*modifiers
)
2317 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2318 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2322 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2324 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2325 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2328 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2330 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2333 RETURN_EGL_EVAL(disp
, ret
);
2336 static EGLBoolean EGLAPIENTRY
2337 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2338 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2340 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2341 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2345 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2347 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2348 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2351 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2353 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2355 RETURN_EGL_EVAL(disp
, ret
);
2358 static EGLint EGLAPIENTRY
2359 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2362 _EGLDisplay
*disp
= NULL
;
2363 _EGLResourceType type
;
2365 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2367 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2368 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2370 if (!_eglIsCurrentThreadDummy()) {
2375 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2378 disp
= _eglLockDisplay(dpy
);
2380 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2382 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2383 if (dpy
!= (EGLDisplay
) object
)
2384 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2386 disp
->Label
= label
;
2387 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2390 switch (objectType
) {
2391 case EGL_OBJECT_CONTEXT_KHR
:
2392 type
= _EGL_RESOURCE_CONTEXT
;
2394 case EGL_OBJECT_SURFACE_KHR
:
2395 type
= _EGL_RESOURCE_SURFACE
;
2397 case EGL_OBJECT_IMAGE_KHR
:
2398 type
= _EGL_RESOURCE_IMAGE
;
2400 case EGL_OBJECT_SYNC_KHR
:
2401 type
= _EGL_RESOURCE_SYNC
;
2403 case EGL_OBJECT_STREAM_KHR
:
2405 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2408 if (_eglCheckResource(object
, type
, disp
)) {
2409 _EGLResource
*res
= (_EGLResource
*) object
;
2412 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2415 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2418 static EGLint EGLAPIENTRY
2419 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2420 const EGLAttrib
*attrib_list
)
2422 unsigned int newEnabled
;
2424 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2426 mtx_lock(_eglGlobal
.Mutex
);
2428 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2429 if (attrib_list
!= NULL
) {
2432 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2433 switch (attrib_list
[i
]) {
2434 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2435 case EGL_DEBUG_MSG_ERROR_KHR
:
2436 case EGL_DEBUG_MSG_WARN_KHR
:
2437 case EGL_DEBUG_MSG_INFO_KHR
:
2438 if (attrib_list
[i
+ 1])
2439 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2441 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2444 // On error, set the last error code, call the current
2445 // debug callback, and return the error code.
2446 mtx_unlock(_eglGlobal
.Mutex
);
2447 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2448 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2449 return EGL_BAD_ATTRIBUTE
;
2454 if (callback
!= NULL
) {
2455 _eglGlobal
.debugCallback
= callback
;
2456 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2458 _eglGlobal
.debugCallback
= NULL
;
2459 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2462 mtx_unlock(_eglGlobal
.Mutex
);
2466 static EGLBoolean EGLAPIENTRY
2467 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2469 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2471 mtx_lock(_eglGlobal
.Mutex
);
2473 switch (attribute
) {
2474 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2475 case EGL_DEBUG_MSG_ERROR_KHR
:
2476 case EGL_DEBUG_MSG_WARN_KHR
:
2477 case EGL_DEBUG_MSG_INFO_KHR
:
2478 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2483 case EGL_DEBUG_CALLBACK_KHR
:
2484 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2487 mtx_unlock(_eglGlobal
.Mutex
);
2488 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2489 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2493 mtx_unlock(_eglGlobal
.Mutex
);
2498 _eglFunctionCompare(const void *key
, const void *elem
)
2500 const char *procname
= key
;
2501 const struct _egl_entrypoint
*entrypoint
= elem
;
2502 return strcmp(procname
, entrypoint
->name
);
2505 static EGLBoolean EGLAPIENTRY
2506 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2507 EGLint
*formats
, EGLint
*num_formats
)
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
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2520 RETURN_EGL_EVAL(disp
, ret
);
2523 static EGLBoolean EGLAPIENTRY
2524 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2525 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2526 EGLint
*num_modifiers
)
2528 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2532 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2534 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2536 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2537 modifiers
, external_only
,
2540 RETURN_EGL_EVAL(disp
, ret
);
2543 static void EGLAPIENTRY
2544 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2545 EGLGetBlobFuncANDROID get
)
2547 /* This function does not return anything so we cannot
2548 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2550 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2551 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2553 _eglUnlockDisplay(disp
);
2557 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2560 _eglUnlockDisplay(disp
);
2565 _eglError(EGL_BAD_PARAMETER
,
2566 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2567 _eglUnlockDisplay(disp
);
2571 if (disp
->BlobCacheSet
) {
2572 _eglError(EGL_BAD_PARAMETER
,
2573 "eglSetBlobCacheFuncsANDROID: functions already set");
2574 _eglUnlockDisplay(disp
);
2578 disp
->BlobCacheSet
= set
;
2579 disp
->BlobCacheGet
= get
;
2581 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2583 _eglUnlockDisplay(disp
);
2586 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2587 eglGetProcAddress(const char *procname
)
2589 static const struct _egl_entrypoint egl_functions
[] = {
2590 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2591 #include "eglentrypoint.h"
2592 #undef EGL_ENTRYPOINT
2594 _EGLProc ret
= NULL
;
2597 RETURN_EGL_SUCCESS(NULL
, NULL
);
2599 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2601 if (strncmp(procname
, "egl", 3) == 0) {
2602 const struct _egl_entrypoint
*entrypoint
=
2604 egl_functions
, ARRAY_SIZE(egl_functions
),
2605 sizeof(egl_functions
[0]),
2606 _eglFunctionCompare
);
2608 ret
= entrypoint
->function
;
2612 ret
= _eglGetDriverProc(procname
);
2614 RETURN_EGL_SUCCESS(NULL
, ret
);
2618 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2619 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2623 *disp
= _eglLockDisplay(dpy
);
2624 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2626 _eglUnlockDisplay(*disp
);
2627 return MESA_GLINTEROP_INVALID_DISPLAY
;
2630 *drv
= (*disp
)->Driver
;
2632 *ctx
= _eglLookupContext(context
, *disp
);
2634 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2635 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2636 _eglUnlockDisplay(*disp
);
2637 return MESA_GLINTEROP_INVALID_CONTEXT
;
2640 return MESA_GLINTEROP_SUCCESS
;
2644 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2645 struct mesa_glinterop_device_info
*out
)
2652 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2653 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2656 if (drv
->API
.GLInteropQueryDeviceInfo
)
2657 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2659 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2661 _eglUnlockDisplay(disp
);
2666 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2667 struct mesa_glinterop_export_in
*in
,
2668 struct mesa_glinterop_export_out
*out
)
2675 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2676 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2679 if (drv
->API
.GLInteropExportObject
)
2680 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2682 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2684 _eglUnlockDisplay(disp
);