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"
94 #include "egldefines.h"
95 #include "eglglobals.h"
96 #include "eglcontext.h"
97 #include "egldisplay.h"
98 #include "egltypedefs.h"
99 #include "eglcurrent.h"
100 #include "egldevice.h"
101 #include "egldriver.h"
102 #include "eglsurface.h"
103 #include "eglconfig.h"
104 #include "eglimage.h"
107 #include "GL/mesa_glinterop.h"
110 * Macros to help return an API entrypoint.
112 * These macros will unlock the display and record the error code.
114 #define RETURN_EGL_ERROR(disp, err, ret) \
117 _eglUnlockDisplay(disp); \
118 /* EGL error codes are non-zero */ \
120 _eglError(err, __func__); \
124 #define RETURN_EGL_SUCCESS(disp, ret) \
125 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
127 /* record EGL_SUCCESS only when ret evaluates to true */
128 #define RETURN_EGL_EVAL(disp, ret) \
129 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
133 * A bunch of macros and checks to simplify error checking.
136 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
138 drv = _eglCheckDisplay(disp, __func__); \
140 RETURN_EGL_ERROR(disp, 0, ret); \
143 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
145 drv = _eglCheck ## type(disp, obj, __func__); \
147 RETURN_EGL_ERROR(disp, 0, ret); \
150 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
151 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
153 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
154 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
156 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
157 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
159 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
160 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
163 struct _egl_entrypoint
{
169 static inline _EGLDriver
*
170 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
173 _eglError(EGL_BAD_DISPLAY
, msg
);
176 if (!disp
->Initialized
) {
177 _eglError(EGL_NOT_INITIALIZED
, msg
);
184 static inline _EGLDriver
*
185 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
187 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
191 _eglError(EGL_BAD_SURFACE
, msg
);
198 static inline _EGLDriver
*
199 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
201 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
205 _eglError(EGL_BAD_CONTEXT
, msg
);
212 static inline _EGLDriver
*
213 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
215 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
219 _eglError(EGL_BAD_CONFIG
, msg
);
226 static inline _EGLDriver
*
227 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
229 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
233 _eglError(EGL_BAD_PARAMETER
, msg
);
241 * Lookup and lock a display.
243 static inline _EGLDisplay
*
244 _eglLockDisplay(EGLDisplay display
)
246 _EGLDisplay
*dpy
= _eglLookupDisplay(display
);
248 mtx_lock(&dpy
->Mutex
);
257 _eglUnlockDisplay(_EGLDisplay
*dpy
)
259 mtx_unlock(&dpy
->Mutex
);
263 _eglSetFuncName(const char *funcName
, _EGLDisplay
*disp
, EGLenum objectType
, _EGLResource
*object
)
265 _EGLThreadInfo
*thr
= _eglGetCurrentThread();
266 if (!_eglIsCurrentThreadDummy()) {
267 thr
->CurrentFuncName
= funcName
;
268 thr
->CurrentObjectLabel
= NULL
;
270 if (objectType
== EGL_OBJECT_THREAD_KHR
)
271 thr
->CurrentObjectLabel
= thr
->Label
;
272 else if (objectType
== EGL_OBJECT_DISPLAY_KHR
&& disp
)
273 thr
->CurrentObjectLabel
= disp
->Label
;
275 thr
->CurrentObjectLabel
= object
->Label
;
280 _eglDebugReport(EGL_BAD_ALLOC
, funcName
, EGL_DEBUG_MSG_CRITICAL_KHR
, NULL
);
284 #define _EGL_FUNC_START(disp, objectType, object, ret) \
286 if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \
288 _eglUnlockDisplay(disp); \
294 * Convert an attribute list from EGLint[] to EGLAttrib[].
296 * Return an EGL error code. The output parameter out_attrib_list is modified
300 _eglConvertIntsToAttribs(const EGLint
*int_list
, EGLAttrib
**out_attrib_list
)
303 EGLAttrib
*attrib_list
;
306 while (int_list
[2*len
] != EGL_NONE
)
311 *out_attrib_list
= NULL
;
315 if (2*len
+ 1 > SIZE_MAX
/ sizeof(EGLAttrib
))
316 return EGL_BAD_ALLOC
;
318 attrib_list
= malloc((2*len
+ 1) * sizeof(EGLAttrib
));
320 return EGL_BAD_ALLOC
;
322 for (size_t i
= 0; i
< len
; ++i
) {
323 attrib_list
[2*i
+ 0] = int_list
[2*i
+ 0];
324 attrib_list
[2*i
+ 1] = int_list
[2*i
+ 1];
327 attrib_list
[2*len
] = EGL_NONE
;
329 *out_attrib_list
= attrib_list
;
335 _eglConvertAttribsToInt(const EGLAttrib
*attr_list
)
337 EGLint
*int_attribs
= NULL
;
339 /* Convert attributes from EGLAttrib[] to EGLint[] */
343 while (attr_list
[size
] != EGL_NONE
)
346 size
+= 1; /* add space for EGL_NONE */
348 int_attribs
= calloc(size
, sizeof(int_attribs
[0]));
352 for (i
= 0; i
< size
; i
++)
353 int_attribs
[i
] = attr_list
[i
];
360 * This is typically the first EGL function that an application calls.
361 * It associates a private _EGLDisplay object to the native display.
363 EGLDisplay EGLAPIENTRY
364 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
366 _EGLPlatformType plat
;
368 void *native_display_ptr
;
370 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
372 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
373 native_display_ptr
= (void*) nativeDisplay
;
375 plat
= _eglGetNativePlatform(native_display_ptr
);
376 dpy
= _eglFindDisplay(plat
, native_display_ptr
);
377 return _eglGetDisplayHandle(dpy
);
381 _eglGetPlatformDisplayCommon(EGLenum platform
, void *native_display
,
382 const EGLAttrib
*attrib_list
)
387 #ifdef HAVE_X11_PLATFORM
388 case EGL_PLATFORM_X11_EXT
:
389 dpy
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
392 #ifdef HAVE_DRM_PLATFORM
393 case EGL_PLATFORM_GBM_MESA
:
394 dpy
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
398 #ifdef HAVE_WAYLAND_PLATFORM
399 case EGL_PLATFORM_WAYLAND_EXT
:
400 dpy
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
404 #ifdef HAVE_SURFACELESS_PLATFORM
405 case EGL_PLATFORM_SURFACELESS_MESA
:
406 dpy
= _eglGetSurfacelessDisplay(native_display
, attrib_list
);
410 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
413 return _eglGetDisplayHandle(dpy
);
416 static EGLDisplay EGLAPIENTRY
417 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
418 const EGLint
*int_attribs
)
420 EGLAttrib
*attrib_list
;
423 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
425 if (_eglConvertIntsToAttribs(int_attribs
, &attrib_list
) != EGL_SUCCESS
)
426 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
428 display
= _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
433 EGLDisplay EGLAPIENTRY
434 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
435 const EGLAttrib
*attrib_list
)
437 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
438 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
442 * Copy the extension into the string and update the string pointer.
445 _eglAppendExtension(char **str
, const char *ext
)
448 size_t len
= strlen(ext
);
465 * Examine the individual extension enable/disable flags and recompute
466 * the driver's Extensions string.
469 _eglCreateExtensionsString(_EGLDisplay
*dpy
)
471 #define _EGL_CHECK_EXTENSION(ext) \
473 if (dpy->Extensions.ext) { \
474 _eglAppendExtension(&exts, "EGL_" #ext); \
475 assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
479 char *exts
= dpy
->ExtensionsString
;
481 /* Please keep these sorted alphabetically. */
482 _EGL_CHECK_EXTENSION(ANDROID_blob_cache
);
483 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
484 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
485 _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync
);
486 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
488 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
490 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
491 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
492 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
493 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers
);
494 _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata
);
495 _EGL_CHECK_EXTENSION(EXT_surface_SMPTE2086_metadata
);
496 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
498 _EGL_CHECK_EXTENSION(IMG_context_priority
);
500 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
501 _EGL_CHECK_EXTENSION(KHR_config_attribs
);
502 _EGL_CHECK_EXTENSION(KHR_context_flush_control
);
503 _EGL_CHECK_EXTENSION(KHR_create_context
);
504 _EGL_CHECK_EXTENSION(KHR_create_context_no_error
);
505 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
506 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
507 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
508 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
509 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
510 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
511 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
512 if (dpy
->Extensions
.KHR_image_base
&& dpy
->Extensions
.KHR_image_pixmap
)
513 dpy
->Extensions
.KHR_image
= EGL_TRUE
;
514 _EGL_CHECK_EXTENSION(KHR_image
);
515 _EGL_CHECK_EXTENSION(KHR_image_base
);
516 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
517 _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer
);
518 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
519 _EGL_CHECK_EXTENSION(KHR_partial_update
);
520 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
521 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
522 if (dpy
->Extensions
.EXT_swap_buffers_with_damage
)
523 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
524 _EGL_CHECK_EXTENSION(EXT_pixel_format_float
);
525 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
527 if (dpy
->Extensions
.KHR_no_config_context
)
528 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
529 _EGL_CHECK_EXTENSION(MESA_drm_image
);
530 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
532 _EGL_CHECK_EXTENSION(NOK_swap_region
);
533 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
535 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
537 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
538 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
540 #undef _EGL_CHECK_EXTENSION
544 _eglCreateAPIsString(_EGLDisplay
*dpy
)
546 #define addstr(str) \
548 const size_t old_len = strlen(dpy->ClientAPIsString); \
549 const size_t add_len = sizeof(str); \
550 const size_t max_len = sizeof(dpy->ClientAPIsString) - 1; \
551 if (old_len + add_len <= max_len) \
552 strcat(dpy->ClientAPIsString, str " "); \
554 assert(!"dpy->ClientAPIsString is not large enough"); \
557 if (dpy
->ClientAPIs
& EGL_OPENGL_BIT
)
560 if (dpy
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
561 dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
562 dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
566 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
573 _eglComputeVersion(_EGLDisplay
*disp
)
577 if (disp
->Extensions
.KHR_fence_sync
&&
578 disp
->Extensions
.KHR_cl_event2
&&
579 disp
->Extensions
.KHR_wait_sync
&&
580 disp
->Extensions
.KHR_image_base
&&
581 disp
->Extensions
.KHR_gl_texture_2D_image
&&
582 disp
->Extensions
.KHR_gl_texture_3D_image
&&
583 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
584 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
585 disp
->Extensions
.KHR_create_context
&&
586 disp
->Extensions
.EXT_create_context_robustness
&&
587 disp
->Extensions
.KHR_get_all_proc_addresses
&&
588 disp
->Extensions
.KHR_gl_colorspace
&&
589 disp
->Extensions
.KHR_surfaceless_context
)
594 * This is typically the second EGL function that an application calls.
595 * Here we load/initialize the actual hardware driver.
597 EGLBoolean EGLAPIENTRY
598 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
600 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
602 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
605 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
607 if (!disp
->Initialized
) {
608 if (!_eglMatchDriver(disp
))
609 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
611 /* limit to APIs supported by core */
612 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
614 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
615 * classifies it as an EGL display extension, though conceptually it's an
616 * EGL client extension.
618 * From the EGL_KHR_get_all_proc_addresses spec:
620 * The EGL implementation must expose the name
621 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
622 * EGL_KHR_get_all_proc_addresses and supports
623 * EGL_EXT_client_extensions.
625 * Mesa unconditionally exposes both client extensions mentioned above,
626 * so the spec requires that each EGLDisplay unconditionally expose
627 * EGL_KHR_get_all_proc_addresses also.
629 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
631 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
632 * programs. It is driver agnostic and handled in the main EGL code.
634 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
636 _eglComputeVersion(disp
);
637 _eglCreateExtensionsString(disp
);
638 _eglCreateAPIsString(disp
);
639 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
640 "%d.%d", disp
->Version
/ 10, disp
->Version
% 10);
643 /* Update applications version of major and minor if not NULL */
644 if ((major
!= NULL
) && (minor
!= NULL
)) {
645 *major
= disp
->Version
/ 10;
646 *minor
= disp
->Version
% 10;
649 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
653 EGLBoolean EGLAPIENTRY
654 eglTerminate(EGLDisplay dpy
)
656 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
658 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
661 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
663 if (disp
->Initialized
) {
664 _EGLDriver
*drv
= disp
->Driver
;
666 drv
->API
.Terminate(drv
, disp
);
667 /* do not reset disp->Driver */
668 disp
->ClientAPIsString
[0] = 0;
669 disp
->Initialized
= EGL_FALSE
;
672 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
676 const char * EGLAPIENTRY
677 eglQueryString(EGLDisplay dpy
, EGLint name
)
682 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
683 const char *ret
= _eglGetClientExtensionString();
685 RETURN_EGL_SUCCESS(NULL
, ret
);
687 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
690 disp
= _eglLockDisplay(dpy
);
691 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
692 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
696 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
698 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
700 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
701 case EGL_CLIENT_APIS
:
702 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
704 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
709 EGLBoolean EGLAPIENTRY
710 eglGetConfigs(EGLDisplay dpy
, 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
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
722 RETURN_EGL_EVAL(disp
, ret
);
726 EGLBoolean EGLAPIENTRY
727 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
728 EGLint config_size
, EGLint
*num_config
)
730 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
734 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
736 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
737 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
738 config_size
, num_config
);
740 RETURN_EGL_EVAL(disp
, ret
);
744 EGLBoolean EGLAPIENTRY
745 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
746 EGLint attribute
, EGLint
*value
)
748 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
749 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
753 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
755 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
756 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
758 RETURN_EGL_EVAL(disp
, ret
);
762 EGLContext EGLAPIENTRY
763 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
764 const EGLint
*attrib_list
)
766 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
767 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
768 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
770 _EGLContext
*context
;
773 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
775 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
777 if (config
!= EGL_NO_CONFIG_KHR
)
778 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
779 else if (!disp
->Extensions
.KHR_no_config_context
)
780 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
782 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
783 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
785 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
786 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
788 RETURN_EGL_EVAL(disp
, ret
);
792 EGLBoolean EGLAPIENTRY
793 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
795 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
796 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
800 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
802 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
803 _eglUnlinkContext(context
);
804 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
806 RETURN_EGL_EVAL(disp
, ret
);
810 EGLBoolean EGLAPIENTRY
811 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
814 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
815 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
816 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
817 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
821 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
824 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
827 /* display is allowed to be uninitialized under certain condition */
828 if (!disp
->Initialized
) {
829 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
830 ctx
!= EGL_NO_CONTEXT
)
831 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
834 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
836 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
837 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
838 if (!draw_surf
|| !read_surf
) {
839 /* From the EGL 1.4 (20130211) spec:
841 * To release the current context without assigning a new one, set ctx
842 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
844 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
845 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
847 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
848 (!read_surf
&& read
!= EGL_NO_SURFACE
))
849 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
850 if (draw_surf
|| read_surf
)
851 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
854 /* If a native window underlying either draw or read is no longer valid,
855 * an EGL_BAD_NATIVE_WINDOW error is generated.
857 if (draw_surf
&& draw_surf
->Lost
)
858 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
859 if (read_surf
&& read_surf
->Lost
)
860 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
862 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
864 RETURN_EGL_EVAL(disp
, ret
);
868 EGLBoolean EGLAPIENTRY
869 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
870 EGLint attribute
, EGLint
*value
)
872 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
873 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
877 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
879 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
880 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
882 RETURN_EGL_EVAL(disp
, ret
);
887 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
888 void *native_window
, const EGLint
*attrib_list
)
890 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
896 if (native_window
== NULL
)
897 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
899 #ifdef HAVE_SURFACELESS_PLATFORM
900 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
901 /* From the EGL_MESA_platform_surfaceless spec (v1):
903 * eglCreatePlatformWindowSurface fails when called with a <display>
904 * that belongs to the surfaceless platform. It returns
905 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
906 * justification for this unconditional failure is that the
907 * surfaceless platform has no native windows, and therefore the
908 * <native_window> parameter is always invalid.
910 * This check must occur before checking the EGLConfig, which emits
913 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
917 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
919 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
920 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
922 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
924 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
926 RETURN_EGL_EVAL(disp
, ret
);
930 EGLSurface EGLAPIENTRY
931 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
932 EGLNativeWindowType window
, const EGLint
*attrib_list
)
934 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
936 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
937 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
938 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
943 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
945 #ifdef HAVE_X11_PLATFORM
946 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
947 /* The `native_window` parameter for the X11 platform differs between
948 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
949 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
950 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
951 * `Window*`. Convert `Window*` to `Window` because that's what
952 * dri2_x11_create_window_surface() expects.
954 return (void *)(* (Window
*) native_window
);
957 return native_window
;
960 static EGLSurface EGLAPIENTRY
961 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
963 const EGLint
*attrib_list
)
965 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
967 native_window
= _fixupNativeWindow(disp
, native_window
);
969 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
970 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
975 EGLSurface EGLAPIENTRY
976 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
978 const EGLAttrib
*attrib_list
)
980 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
984 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
986 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
987 if (attrib_list
&& !int_attribs
)
988 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
990 native_window
= _fixupNativeWindow(disp
, native_window
);
991 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
998 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
1000 #ifdef HAVE_X11_PLATFORM
1001 /* The `native_pixmap` parameter for the X11 platform differs between
1002 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1003 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1004 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1005 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1006 * dri2_x11_create_pixmap_surface() expects.
1008 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
1009 return (void *)(* (Pixmap
*) native_pixmap
);
1011 return native_pixmap
;
1015 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1016 void *native_pixmap
, const EGLint
*attrib_list
)
1018 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1023 #if HAVE_SURFACELESS_PLATFORM
1024 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
1025 /* From the EGL_MESA_platform_surfaceless spec (v1):
1027 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1028 * also fails when called with a <display> that belongs to the
1029 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1030 * EGL_BAD_NATIVE_PIXMAP.
1032 * This check must occur before checking the EGLConfig, which emits
1035 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1039 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1041 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1042 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1044 if (native_pixmap
== NULL
)
1045 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1047 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1049 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1051 RETURN_EGL_EVAL(disp
, ret
);
1055 EGLSurface EGLAPIENTRY
1056 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1057 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1059 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1061 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1062 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1063 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1067 static EGLSurface EGLAPIENTRY
1068 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1069 void *native_pixmap
,
1070 const EGLint
*attrib_list
)
1072 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1074 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1075 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1076 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1081 EGLSurface EGLAPIENTRY
1082 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1083 void *native_pixmap
,
1084 const EGLAttrib
*attrib_list
)
1086 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1088 EGLint
*int_attribs
;
1090 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1092 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1093 if (attrib_list
&& !int_attribs
)
1094 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1096 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1097 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1104 EGLSurface EGLAPIENTRY
1105 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1106 const EGLint
*attrib_list
)
1108 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1109 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1114 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1115 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1117 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1118 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1120 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1121 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1123 RETURN_EGL_EVAL(disp
, ret
);
1127 EGLBoolean EGLAPIENTRY
1128 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
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 _eglUnlinkSurface(surf
);
1138 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1140 RETURN_EGL_EVAL(disp
, ret
);
1143 EGLBoolean EGLAPIENTRY
1144 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1145 EGLint attribute
, EGLint
*value
)
1147 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1148 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1152 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1153 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1154 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1156 RETURN_EGL_EVAL(disp
, ret
);
1159 EGLBoolean EGLAPIENTRY
1160 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1161 EGLint attribute
, EGLint value
)
1163 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1164 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1168 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1169 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1170 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1172 RETURN_EGL_EVAL(disp
, ret
);
1176 EGLBoolean EGLAPIENTRY
1177 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1179 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1180 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1184 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1185 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1186 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1188 RETURN_EGL_EVAL(disp
, ret
);
1192 EGLBoolean EGLAPIENTRY
1193 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1195 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1196 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1200 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1201 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1202 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1204 RETURN_EGL_EVAL(disp
, ret
);
1208 EGLBoolean EGLAPIENTRY
1209 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1211 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1212 _EGLContext
*ctx
= _eglGetCurrentContext();
1213 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1217 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1218 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1220 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1221 ctx
->Resource
.Display
!= disp
)
1222 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1224 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1225 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1227 if (surf
->Type
!= EGL_WINDOW_BIT
)
1228 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1230 interval
= CLAMP(interval
,
1231 surf
->Config
->MinSwapInterval
,
1232 surf
->Config
->MaxSwapInterval
);
1234 if (surf
->SwapInterval
!= interval
)
1235 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1240 surf
->SwapInterval
= interval
;
1242 RETURN_EGL_EVAL(disp
, ret
);
1246 EGLBoolean EGLAPIENTRY
1247 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1249 _EGLContext
*ctx
= _eglGetCurrentContext();
1250 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1251 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1255 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1256 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1258 /* surface must be bound to current context in EGL 1.4 */
1259 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1260 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1261 surf
!= ctx
->DrawSurface
)
1262 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1265 if (surf
->Type
!= EGL_WINDOW_BIT
)
1266 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1268 /* From the EGL 1.5 spec:
1270 * If eglSwapBuffers is called and the native window associated with
1271 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1275 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1277 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1279 /* EGL_KHR_partial_update
1280 * Frame boundary successfully reached,
1281 * reset damage region and reset BufferAgeRead
1284 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1285 surf
->BufferAgeRead
= EGL_FALSE
;
1288 RETURN_EGL_EVAL(disp
, ret
);
1293 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1294 EGLint
*rects
, EGLint n_rects
)
1296 _EGLContext
*ctx
= _eglGetCurrentContext();
1300 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1302 /* surface must be bound to current context in EGL 1.4 */
1303 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1304 surf
!= ctx
->DrawSurface
)
1305 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1307 if (surf
->Type
!= EGL_WINDOW_BIT
)
1308 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1310 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1311 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1313 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1315 /* EGL_KHR_partial_update
1316 * Frame boundary successfully reached,
1317 * reset damage region and reset BufferAgeRead
1320 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1321 surf
->BufferAgeRead
= EGL_FALSE
;
1324 RETURN_EGL_EVAL(disp
, ret
);
1327 static EGLBoolean EGLAPIENTRY
1328 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1329 EGLint
*rects
, EGLint n_rects
)
1331 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1332 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1333 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1334 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1337 static EGLBoolean EGLAPIENTRY
1338 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1339 EGLint
*rects
, EGLint n_rects
)
1341 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1342 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1343 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1344 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1348 * Clamp the rectangles so that they lie within the surface.
1352 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1353 EGLint
*rects
, EGLint n_rects
)
1356 EGLint surf_height
= surf
->Height
;
1357 EGLint surf_width
= surf
->Width
;
1359 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1360 EGLint x1
, y1
, x2
, y2
;
1363 x2
= rects
[i
+ 2] + x1
;
1364 y2
= rects
[i
+ 3] + y1
;
1366 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1367 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1368 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1369 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1373 static EGLBoolean EGLAPIENTRY
1374 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1375 EGLint
*rects
, EGLint n_rects
)
1377 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1378 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1379 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1380 _EGLContext
*ctx
= _eglGetCurrentContext();
1383 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1385 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1386 surf
->Type
!= EGL_WINDOW_BIT
||
1387 ctx
->DrawSurface
!= surf
||
1388 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1389 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1391 /* If the damage region is already set or
1392 * buffer age is not queried between
1393 * frame boundaries, throw bad access error
1396 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1397 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1399 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1400 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1403 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1405 RETURN_EGL_EVAL(disp
, ret
);
1408 EGLBoolean EGLAPIENTRY
1409 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1411 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1412 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1415 void *native_pixmap_ptr
;
1417 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1418 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1419 native_pixmap_ptr
= (void*) target
;
1421 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1422 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1424 RETURN_EGL_EVAL(disp
, ret
);
1429 _eglWaitClientCommon(void)
1431 _EGLContext
*ctx
= _eglGetCurrentContext();
1437 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1439 disp
= ctx
->Resource
.Display
;
1440 mtx_lock(&disp
->Mutex
);
1442 /* let bad current context imply bad current surface */
1443 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1444 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1445 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1447 /* a valid current context implies an initialized current display */
1448 assert(disp
->Initialized
);
1450 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1452 RETURN_EGL_EVAL(disp
, ret
);
1455 EGLBoolean EGLAPIENTRY
1458 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1459 return _eglWaitClientCommon();
1462 EGLBoolean EGLAPIENTRY
1465 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1466 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1467 return _eglWaitClientCommon();
1471 EGLBoolean EGLAPIENTRY
1472 eglWaitNative(EGLint engine
)
1474 _EGLContext
*ctx
= _eglGetCurrentContext();
1480 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1482 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1484 disp
= ctx
->Resource
.Display
;
1485 mtx_lock(&disp
->Mutex
);
1487 /* let bad current context imply bad current surface */
1488 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1489 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1490 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1492 /* a valid current context implies an initialized current display */
1493 assert(disp
->Initialized
);
1495 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1497 RETURN_EGL_EVAL(disp
, ret
);
1501 EGLDisplay EGLAPIENTRY
1502 eglGetCurrentDisplay(void)
1504 _EGLContext
*ctx
= _eglGetCurrentContext();
1507 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1509 RETURN_EGL_SUCCESS(NULL
, ret
);
1513 EGLContext EGLAPIENTRY
1514 eglGetCurrentContext(void)
1516 _EGLContext
*ctx
= _eglGetCurrentContext();
1519 ret
= _eglGetContextHandle(ctx
);
1521 RETURN_EGL_SUCCESS(NULL
, ret
);
1525 EGLSurface EGLAPIENTRY
1526 eglGetCurrentSurface(EGLint readdraw
)
1528 _EGLContext
*ctx
= _eglGetCurrentContext();
1529 EGLint err
= EGL_SUCCESS
;
1533 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1536 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1540 surf
= ctx
->DrawSurface
;
1543 surf
= ctx
->ReadSurface
;
1547 err
= EGL_BAD_PARAMETER
;
1551 ret
= _eglGetSurfaceHandle(surf
);
1553 RETURN_EGL_ERROR(NULL
, err
, ret
);
1560 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1561 EGLint e
= t
->LastError
;
1562 if (!_eglIsCurrentThreadDummy())
1563 t
->LastError
= EGL_SUCCESS
;
1573 * Specify the client API to use for subsequent calls including:
1574 * eglCreateContext()
1575 * eglGetCurrentContext()
1576 * eglGetCurrentDisplay()
1577 * eglGetCurrentSurface()
1578 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1581 * See section 3.7 "Rendering Context" in the EGL specification for details.
1583 EGLBoolean EGLAPIENTRY
1584 eglBindAPI(EGLenum api
)
1588 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1590 t
= _eglGetCurrentThread();
1591 if (_eglIsCurrentThreadDummy())
1592 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1594 if (!_eglIsApiValid(api
))
1595 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1597 t
->CurrentAPI
= api
;
1599 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1604 * Return the last value set with eglBindAPI().
1609 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1612 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1613 ret
= t
->CurrentAPI
;
1615 RETURN_EGL_SUCCESS(NULL
, ret
);
1619 EGLSurface EGLAPIENTRY
1620 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1621 EGLClientBuffer buffer
, EGLConfig config
,
1622 const EGLint
*attrib_list
)
1624 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1625 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1630 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1632 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1634 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1636 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1638 RETURN_EGL_EVAL(disp
, ret
);
1642 EGLBoolean EGLAPIENTRY
1643 eglReleaseThread(void)
1645 /* unbind current contexts */
1646 if (!_eglIsCurrentThreadDummy()) {
1647 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1648 _EGLContext
*ctx
= t
->CurrentContext
;
1650 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1653 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1656 mtx_lock(&disp
->Mutex
);
1658 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1659 mtx_unlock(&disp
->Mutex
);
1663 _eglDestroyCurrentThread();
1665 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1670 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1671 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1673 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1678 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1679 if (!disp
->Extensions
.KHR_image_base
)
1680 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1681 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1682 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1683 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1684 * <ctx> must be EGL_NO_CONTEXT..."
1686 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1687 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1689 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1691 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1693 RETURN_EGL_EVAL(disp
, ret
);
1696 static EGLImage EGLAPIENTRY
1697 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1698 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1700 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1701 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1702 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1706 EGLImage EGLAPIENTRY
1707 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1708 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1710 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1712 EGLint
*int_attribs
;
1714 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1716 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1717 if (attr_list
&& !int_attribs
)
1718 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1720 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1727 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1732 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1733 if (!disp
->Extensions
.KHR_image_base
)
1734 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1736 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1738 _eglUnlinkImage(img
);
1739 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1741 RETURN_EGL_EVAL(disp
, ret
);
1744 EGLBoolean EGLAPIENTRY
1745 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1747 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1748 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1749 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1750 return _eglDestroyImageCommon(disp
, img
);
1753 static EGLBoolean EGLAPIENTRY
1754 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1756 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1757 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1758 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1759 return _eglDestroyImageCommon(disp
, img
);
1764 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1765 EGLBoolean orig_is_EGLAttrib
,
1766 EGLenum invalid_type_error
)
1768 _EGLContext
*ctx
= _eglGetCurrentContext();
1773 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1775 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1776 /* There exist two EGLAttrib variants of eglCreateSync*:
1777 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1778 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1779 * support as a proxy for EGL 1.5 support, even though that's not
1780 * entirely correct (though _eglComputeVersion does the same).
1782 * The EGL spec provides no guidance on how to handle unsupported
1783 * functions. EGL_BAD_MATCH seems reasonable.
1785 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1788 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1789 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1790 * error is generated.
1793 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1794 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1796 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1797 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1798 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1799 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1802 case EGL_SYNC_FENCE_KHR
:
1803 if (!disp
->Extensions
.KHR_fence_sync
)
1804 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1806 case EGL_SYNC_REUSABLE_KHR
:
1807 if (!disp
->Extensions
.KHR_reusable_sync
)
1808 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1810 case EGL_SYNC_CL_EVENT_KHR
:
1811 if (!disp
->Extensions
.KHR_cl_event2
)
1812 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1814 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1815 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1816 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1819 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1822 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1823 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1825 RETURN_EGL_EVAL(disp
, ret
);
1829 static EGLSync EGLAPIENTRY
1830 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1832 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1833 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1836 EGLAttrib
*attrib_list
;
1839 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1840 attrib_list
= (EGLAttrib
*) int_list
;
1842 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1843 if (err
!= EGL_SUCCESS
)
1844 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1847 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1850 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1853 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1858 static EGLSync EGLAPIENTRY
1859 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1861 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1862 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1863 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1869 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1871 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1872 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1873 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1879 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1884 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1885 assert(disp
->Extensions
.KHR_reusable_sync
||
1886 disp
->Extensions
.KHR_fence_sync
||
1887 disp
->Extensions
.ANDROID_native_fence_sync
);
1890 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1892 RETURN_EGL_EVAL(disp
, ret
);
1895 EGLBoolean EGLAPIENTRY
1896 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1898 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1899 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1900 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1901 return _eglDestroySync(disp
, s
);
1904 static EGLBoolean EGLAPIENTRY
1905 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1907 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1908 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1909 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1910 return _eglDestroySync(disp
, s
);
1915 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1916 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1921 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1922 assert(disp
->Extensions
.KHR_reusable_sync
||
1923 disp
->Extensions
.KHR_fence_sync
||
1924 disp
->Extensions
.ANDROID_native_fence_sync
);
1926 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1927 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1929 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1930 * unlocked here to allow other threads also to be able to
1931 * go into waiting state.
1934 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1935 _eglUnlockDisplay(dpy
);
1937 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1940 * 'disp' is already unlocked for reusable sync type,
1941 * so passing 'NULL' to bypass unlocking display.
1943 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1944 RETURN_EGL_EVAL(NULL
, ret
);
1946 RETURN_EGL_EVAL(disp
, ret
);
1950 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
1951 EGLint flags
, EGLTime timeout
)
1953 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1954 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1955 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1956 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1959 static EGLint EGLAPIENTRY
1960 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
1961 EGLint flags
, EGLTime timeout
)
1963 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1964 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1965 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1966 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1971 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
1973 _EGLContext
*ctx
= _eglGetCurrentContext();
1977 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1978 assert(disp
->Extensions
.KHR_wait_sync
);
1980 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1981 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1982 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1984 /* the API doesn't allow any flags yet */
1986 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1988 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1990 RETURN_EGL_EVAL(disp
, ret
);
1993 static EGLint EGLAPIENTRY
1994 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1996 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1997 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1998 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1999 return _eglWaitSyncCommon(disp
, s
, flags
);
2003 EGLBoolean EGLAPIENTRY
2004 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2006 /* The KHR version returns EGLint, while the core version returns
2007 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2010 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2011 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2012 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2013 return _eglWaitSyncCommon(disp
, s
, flags
);
2017 static EGLBoolean EGLAPIENTRY
2018 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2020 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2021 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2025 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2027 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2028 assert(disp
->Extensions
.KHR_reusable_sync
);
2029 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2031 RETURN_EGL_EVAL(disp
, ret
);
2036 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2041 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2042 assert(disp
->Extensions
.KHR_reusable_sync
||
2043 disp
->Extensions
.KHR_fence_sync
||
2044 disp
->Extensions
.ANDROID_native_fence_sync
);
2045 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2047 RETURN_EGL_EVAL(disp
, ret
);
2050 EGLBoolean EGLAPIENTRY
2051 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2053 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2054 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2055 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2056 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2060 static EGLBoolean EGLAPIENTRY
2061 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2063 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2064 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2068 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2071 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2074 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2076 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2078 * If any error occurs, <*value> is not modified.
2080 if (result
== EGL_FALSE
)
2087 static EGLint EGLAPIENTRY
2088 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2090 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2091 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2095 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2097 /* the spec doesn't seem to specify what happens if the fence
2098 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2101 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2102 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2104 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2105 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2106 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2108 RETURN_EGL_EVAL(disp
, ret
);
2111 static EGLBoolean EGLAPIENTRY
2112 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2113 EGLint numRects
, const EGLint
*rects
)
2115 _EGLContext
*ctx
= _eglGetCurrentContext();
2116 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2117 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2121 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2123 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2125 if (!disp
->Extensions
.NOK_swap_region
)
2126 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2128 /* surface must be bound to current context in EGL 1.4 */
2129 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2130 surf
!= ctx
->DrawSurface
)
2131 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2133 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2135 RETURN_EGL_EVAL(disp
, ret
);
2139 static EGLImage EGLAPIENTRY
2140 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2142 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2147 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2149 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2150 if (!disp
->Extensions
.MESA_drm_image
)
2151 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2153 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2154 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2156 RETURN_EGL_EVAL(disp
, ret
);
2159 static EGLBoolean EGLAPIENTRY
2160 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2161 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2163 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2164 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2168 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2170 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2171 assert(disp
->Extensions
.MESA_drm_image
);
2174 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2176 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2178 RETURN_EGL_EVAL(disp
, ret
);
2184 static EGLBoolean EGLAPIENTRY
2185 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2187 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2191 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2193 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2194 assert(disp
->Extensions
.WL_bind_wayland_display
);
2197 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2199 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2201 RETURN_EGL_EVAL(disp
, ret
);
2204 static EGLBoolean EGLAPIENTRY
2205 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
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
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2221 RETURN_EGL_EVAL(disp
, ret
);
2224 static EGLBoolean EGLAPIENTRY
2225 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2226 EGLint attribute
, EGLint
*value
)
2228 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2232 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2234 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2235 assert(disp
->Extensions
.WL_bind_wayland_display
);
2238 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2240 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2242 RETURN_EGL_EVAL(disp
, ret
);
2246 static struct wl_buffer
* EGLAPIENTRY
2247 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2249 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2252 struct wl_buffer
*ret
;
2254 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2256 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2257 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2258 RETURN_EGL_EVAL(disp
, NULL
);
2260 img
= _eglLookupImage(image
, disp
);
2263 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2265 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2267 RETURN_EGL_EVAL(disp
, ret
);
2270 static EGLBoolean EGLAPIENTRY
2271 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2272 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2274 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2275 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2279 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2281 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2283 if (!disp
->Extensions
.NV_post_sub_buffer
)
2284 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2286 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2288 RETURN_EGL_EVAL(disp
, ret
);
2291 static EGLBoolean EGLAPIENTRY
2292 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
2293 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2296 _EGLDisplay
*disp
= _eglLockDisplay(display
);
2297 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2301 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2303 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2304 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2305 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2307 if (!ust
|| !msc
|| !sbc
)
2308 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2310 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2312 RETURN_EGL_EVAL(disp
, ret
);
2315 static EGLBoolean EGLAPIENTRY
2316 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2317 EGLint
*fourcc
, EGLint
*nplanes
,
2318 EGLuint64KHR
*modifiers
)
2320 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2321 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2325 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2327 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2328 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2331 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2333 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2336 RETURN_EGL_EVAL(disp
, ret
);
2339 static EGLBoolean EGLAPIENTRY
2340 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2341 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2343 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2344 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2348 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2350 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2351 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2354 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2356 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2358 RETURN_EGL_EVAL(disp
, ret
);
2361 static EGLint EGLAPIENTRY
2362 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2365 _EGLDisplay
*disp
= NULL
;
2366 _EGLResourceType type
;
2368 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2370 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2371 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2373 if (!_eglIsCurrentThreadDummy()) {
2378 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2381 disp
= _eglLockDisplay(dpy
);
2383 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2385 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2386 if (dpy
!= (EGLDisplay
) object
)
2387 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2389 disp
->Label
= label
;
2390 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2393 switch (objectType
) {
2394 case EGL_OBJECT_CONTEXT_KHR
:
2395 type
= _EGL_RESOURCE_CONTEXT
;
2397 case EGL_OBJECT_SURFACE_KHR
:
2398 type
= _EGL_RESOURCE_SURFACE
;
2400 case EGL_OBJECT_IMAGE_KHR
:
2401 type
= _EGL_RESOURCE_IMAGE
;
2403 case EGL_OBJECT_SYNC_KHR
:
2404 type
= _EGL_RESOURCE_SYNC
;
2406 case EGL_OBJECT_STREAM_KHR
:
2408 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2411 if (_eglCheckResource(object
, type
, disp
)) {
2412 _EGLResource
*res
= (_EGLResource
*) object
;
2415 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2418 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2421 static EGLint EGLAPIENTRY
2422 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2423 const EGLAttrib
*attrib_list
)
2425 unsigned int newEnabled
;
2427 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2429 mtx_lock(_eglGlobal
.Mutex
);
2431 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2432 if (attrib_list
!= NULL
) {
2435 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2436 switch (attrib_list
[i
]) {
2437 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2438 case EGL_DEBUG_MSG_ERROR_KHR
:
2439 case EGL_DEBUG_MSG_WARN_KHR
:
2440 case EGL_DEBUG_MSG_INFO_KHR
:
2441 if (attrib_list
[i
+ 1])
2442 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2444 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2447 // On error, set the last error code, call the current
2448 // debug callback, and return the error code.
2449 mtx_unlock(_eglGlobal
.Mutex
);
2450 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2451 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2452 return EGL_BAD_ATTRIBUTE
;
2457 if (callback
!= NULL
) {
2458 _eglGlobal
.debugCallback
= callback
;
2459 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2461 _eglGlobal
.debugCallback
= NULL
;
2462 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2465 mtx_unlock(_eglGlobal
.Mutex
);
2469 static EGLBoolean EGLAPIENTRY
2470 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2472 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2474 mtx_lock(_eglGlobal
.Mutex
);
2476 switch (attribute
) {
2477 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2478 case EGL_DEBUG_MSG_ERROR_KHR
:
2479 case EGL_DEBUG_MSG_WARN_KHR
:
2480 case EGL_DEBUG_MSG_INFO_KHR
:
2481 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2486 case EGL_DEBUG_CALLBACK_KHR
:
2487 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2490 mtx_unlock(_eglGlobal
.Mutex
);
2491 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2492 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2496 mtx_unlock(_eglGlobal
.Mutex
);
2501 _eglFunctionCompare(const void *key
, const void *elem
)
2503 const char *procname
= key
;
2504 const struct _egl_entrypoint
*entrypoint
= elem
;
2505 return strcmp(procname
, entrypoint
->name
);
2508 static EGLBoolean EGLAPIENTRY
2509 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2510 EGLint
*formats
, EGLint
*num_formats
)
2512 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2516 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2518 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2520 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2523 RETURN_EGL_EVAL(disp
, ret
);
2526 static EGLBoolean EGLAPIENTRY
2527 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2528 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2529 EGLint
*num_modifiers
)
2531 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2535 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2537 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2539 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2540 modifiers
, external_only
,
2543 RETURN_EGL_EVAL(disp
, ret
);
2546 static void EGLAPIENTRY
2547 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2548 EGLGetBlobFuncANDROID get
)
2550 /* This function does not return anything so we cannot
2551 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2553 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2554 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2556 _eglUnlockDisplay(disp
);
2560 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2563 _eglUnlockDisplay(disp
);
2568 _eglError(EGL_BAD_PARAMETER
,
2569 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2570 _eglUnlockDisplay(disp
);
2574 if (disp
->BlobCacheSet
) {
2575 _eglError(EGL_BAD_PARAMETER
,
2576 "eglSetBlobCacheFuncsANDROID: functions already set");
2577 _eglUnlockDisplay(disp
);
2581 disp
->BlobCacheSet
= set
;
2582 disp
->BlobCacheGet
= get
;
2584 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2586 _eglUnlockDisplay(disp
);
2589 static EGLBoolean EGLAPIENTRY
2590 eglQueryDeviceAttribEXT(EGLDeviceEXT device
,
2594 _EGLDevice
*dev
= _eglLookupDevice(device
);
2597 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2599 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, EGL_FALSE
);
2601 ret
= _eglQueryDeviceAttribEXT(dev
, attribute
, value
);
2602 RETURN_EGL_EVAL(NULL
, ret
);
2605 static const char * EGLAPIENTRY
2606 eglQueryDeviceStringEXT(EGLDeviceEXT device
,
2609 _EGLDevice
*dev
= _eglLookupDevice(device
);
2611 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2613 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, NULL
);
2615 RETURN_EGL_EVAL(NULL
, _eglQueryDeviceStringEXT(dev
, name
));
2618 static EGLBoolean EGLAPIENTRY
2619 eglQueryDevicesEXT(EGLint max_devices
,
2620 EGLDeviceEXT
*devices
,
2621 EGLint
*num_devices
)
2625 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2626 ret
= _eglQueryDevicesEXT(max_devices
, (_EGLDevice
**) devices
,
2628 RETURN_EGL_EVAL(NULL
, ret
);
2631 static EGLBoolean EGLAPIENTRY
2632 eglQueryDisplayAttribEXT(EGLDisplay dpy
,
2636 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2639 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2640 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2642 switch (attribute
) {
2643 case EGL_DEVICE_EXT
:
2644 *value
= (EGLAttrib
) disp
->Device
;
2647 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
2649 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
2652 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2653 eglGetProcAddress(const char *procname
)
2655 static const struct _egl_entrypoint egl_functions
[] = {
2656 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2657 #include "eglentrypoint.h"
2658 #undef EGL_ENTRYPOINT
2660 _EGLProc ret
= NULL
;
2663 RETURN_EGL_SUCCESS(NULL
, NULL
);
2665 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2667 if (strncmp(procname
, "egl", 3) == 0) {
2668 const struct _egl_entrypoint
*entrypoint
=
2670 egl_functions
, ARRAY_SIZE(egl_functions
),
2671 sizeof(egl_functions
[0]),
2672 _eglFunctionCompare
);
2674 ret
= entrypoint
->function
;
2678 ret
= _eglGetDriverProc(procname
);
2680 RETURN_EGL_SUCCESS(NULL
, ret
);
2684 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2685 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2689 *disp
= _eglLockDisplay(dpy
);
2690 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2692 _eglUnlockDisplay(*disp
);
2693 return MESA_GLINTEROP_INVALID_DISPLAY
;
2696 *drv
= (*disp
)->Driver
;
2698 *ctx
= _eglLookupContext(context
, *disp
);
2700 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2701 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2702 _eglUnlockDisplay(*disp
);
2703 return MESA_GLINTEROP_INVALID_CONTEXT
;
2706 return MESA_GLINTEROP_SUCCESS
;
2710 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2711 struct mesa_glinterop_device_info
*out
)
2718 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2719 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2722 if (drv
->API
.GLInteropQueryDeviceInfo
)
2723 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2725 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2727 _eglUnlockDisplay(disp
);
2732 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2733 struct mesa_glinterop_export_in
*in
,
2734 struct mesa_glinterop_export_out
*out
)
2741 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2742 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2745 if (drv
->API
.GLInteropExportObject
)
2746 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2748 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2750 _eglUnlockDisplay(disp
);