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
95 #include "c99_compat.h"
96 #include "c11/threads.h"
97 #include "util/macros.h"
100 #include "egldefines.h"
101 #include "eglglobals.h"
102 #include "eglcontext.h"
103 #include "egldisplay.h"
104 #include "egltypedefs.h"
105 #include "eglcurrent.h"
106 #include "egldevice.h"
107 #include "egldriver.h"
108 #include "eglsurface.h"
109 #include "eglconfig.h"
110 #include "eglimage.h"
113 #include "GL/mesa_glinterop.h"
116 * Macros to help return an API entrypoint.
118 * These macros will unlock the display and record the error code.
120 #define RETURN_EGL_ERROR(disp, err, ret) \
123 _eglUnlockDisplay(disp); \
124 /* EGL error codes are non-zero */ \
126 _eglError(err, __func__); \
130 #define RETURN_EGL_SUCCESS(disp, ret) \
131 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
133 /* record EGL_SUCCESS only when ret evaluates to true */
134 #define RETURN_EGL_EVAL(disp, ret) \
135 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
139 * A bunch of macros and checks to simplify error checking.
142 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
144 drv = _eglCheckDisplay(disp, __func__); \
146 RETURN_EGL_ERROR(disp, 0, ret); \
149 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
151 drv = _eglCheck ## type(disp, obj, __func__); \
153 RETURN_EGL_ERROR(disp, 0, ret); \
156 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
157 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
159 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
160 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
162 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
163 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
165 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
166 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
169 struct _egl_entrypoint
{
175 static inline _EGLDriver
*
176 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
179 _eglError(EGL_BAD_DISPLAY
, msg
);
182 if (!disp
->Initialized
) {
183 _eglError(EGL_NOT_INITIALIZED
, msg
);
190 static inline _EGLDriver
*
191 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
193 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
197 _eglError(EGL_BAD_SURFACE
, msg
);
204 static inline _EGLDriver
*
205 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
207 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
211 _eglError(EGL_BAD_CONTEXT
, msg
);
218 static inline _EGLDriver
*
219 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
221 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
225 _eglError(EGL_BAD_CONFIG
, msg
);
232 static inline _EGLDriver
*
233 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
235 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
239 _eglError(EGL_BAD_PARAMETER
, msg
);
247 * Lookup and lock a display.
249 static inline _EGLDisplay
*
250 _eglLockDisplay(EGLDisplay dpy
)
252 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
254 mtx_lock(&disp
->Mutex
);
263 _eglUnlockDisplay(_EGLDisplay
*disp
)
265 mtx_unlock(&disp
->Mutex
);
269 _eglSetFuncName(const char *funcName
, _EGLDisplay
*disp
, EGLenum objectType
, _EGLResource
*object
)
271 _EGLThreadInfo
*thr
= _eglGetCurrentThread();
272 if (!_eglIsCurrentThreadDummy()) {
273 thr
->CurrentFuncName
= funcName
;
274 thr
->CurrentObjectLabel
= NULL
;
276 if (objectType
== EGL_OBJECT_THREAD_KHR
)
277 thr
->CurrentObjectLabel
= thr
->Label
;
278 else if (objectType
== EGL_OBJECT_DISPLAY_KHR
&& disp
)
279 thr
->CurrentObjectLabel
= disp
->Label
;
281 thr
->CurrentObjectLabel
= object
->Label
;
286 _eglDebugReport(EGL_BAD_ALLOC
, funcName
, EGL_DEBUG_MSG_CRITICAL_KHR
, NULL
);
290 #define _EGL_FUNC_START(disp, objectType, object, ret) \
292 if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \
294 _eglUnlockDisplay(disp); \
300 * Convert an attribute list from EGLint[] to EGLAttrib[].
302 * Return an EGL error code. The output parameter out_attrib_list is modified
306 _eglConvertIntsToAttribs(const EGLint
*int_list
, EGLAttrib
**out_attrib_list
)
309 EGLAttrib
*attrib_list
;
312 while (int_list
[2*len
] != EGL_NONE
)
317 *out_attrib_list
= NULL
;
321 if (2*len
+ 1 > SIZE_MAX
/ sizeof(EGLAttrib
))
322 return EGL_BAD_ALLOC
;
324 attrib_list
= malloc((2*len
+ 1) * sizeof(EGLAttrib
));
326 return EGL_BAD_ALLOC
;
328 for (size_t i
= 0; i
< len
; ++i
) {
329 attrib_list
[2*i
+ 0] = int_list
[2*i
+ 0];
330 attrib_list
[2*i
+ 1] = int_list
[2*i
+ 1];
333 attrib_list
[2*len
] = EGL_NONE
;
335 *out_attrib_list
= attrib_list
;
341 _eglConvertAttribsToInt(const EGLAttrib
*attr_list
)
343 size_t size
= _eglNumAttribs(attr_list
);
344 EGLint
*int_attribs
= NULL
;
346 /* Convert attributes from EGLAttrib[] to EGLint[] */
348 int_attribs
= calloc(size
, sizeof(int_attribs
[0]));
352 for (size_t 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 disp
= _eglFindDisplay(plat
, native_display_ptr
, NULL
);
377 return _eglGetDisplayHandle(disp
);
381 _eglGetPlatformDisplayCommon(EGLenum platform
, void *native_display
,
382 const EGLAttrib
*attrib_list
)
387 #ifdef HAVE_X11_PLATFORM
388 case EGL_PLATFORM_X11_EXT
:
389 disp
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
392 #ifdef HAVE_DRM_PLATFORM
393 case EGL_PLATFORM_GBM_MESA
:
394 disp
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
398 #ifdef HAVE_WAYLAND_PLATFORM
399 case EGL_PLATFORM_WAYLAND_EXT
:
400 disp
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
404 #ifdef HAVE_SURFACELESS_PLATFORM
405 case EGL_PLATFORM_SURFACELESS_MESA
:
406 disp
= _eglGetSurfacelessDisplay(native_display
, attrib_list
);
409 #ifdef HAVE_ANDROID_PLATFORM
410 case EGL_PLATFORM_ANDROID_KHR
:
411 disp
= _eglGetAndroidDisplay(native_display
, attrib_list
);
414 case EGL_PLATFORM_DEVICE_EXT
:
415 disp
= _eglGetDeviceDisplay(native_display
, attrib_list
);
418 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
421 return _eglGetDisplayHandle(disp
);
424 static EGLDisplay EGLAPIENTRY
425 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
426 const EGLint
*int_attribs
)
428 EGLAttrib
*attrib_list
;
431 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
433 if (_eglConvertIntsToAttribs(int_attribs
, &attrib_list
) != EGL_SUCCESS
)
434 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
436 disp
= _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
441 EGLDisplay EGLAPIENTRY
442 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
443 const EGLAttrib
*attrib_list
)
445 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
446 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
450 * Copy the extension into the string and update the string pointer.
453 _eglAppendExtension(char **str
, const char *ext
)
456 size_t len
= strlen(ext
);
473 * Examine the individual extension enable/disable flags and recompute
474 * the driver's Extensions string.
477 _eglCreateExtensionsString(_EGLDisplay
*disp
)
479 #define _EGL_CHECK_EXTENSION(ext) \
481 if (disp->Extensions.ext) { \
482 _eglAppendExtension(&exts, "EGL_" #ext); \
483 assert(exts <= disp->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
487 char *exts
= disp
->ExtensionsString
;
489 /* Please keep these sorted alphabetically. */
490 _EGL_CHECK_EXTENSION(ANDROID_blob_cache
);
491 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
492 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
493 _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync
);
494 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
496 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
498 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
499 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
500 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
501 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers
);
502 _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata
);
503 _EGL_CHECK_EXTENSION(EXT_surface_SMPTE2086_metadata
);
504 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
506 _EGL_CHECK_EXTENSION(IMG_context_priority
);
508 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
509 _EGL_CHECK_EXTENSION(KHR_config_attribs
);
510 _EGL_CHECK_EXTENSION(KHR_context_flush_control
);
511 _EGL_CHECK_EXTENSION(KHR_create_context
);
512 _EGL_CHECK_EXTENSION(KHR_create_context_no_error
);
513 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
514 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
515 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
516 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
517 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
518 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
519 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
520 if (disp
->Extensions
.KHR_image_base
&& disp
->Extensions
.KHR_image_pixmap
)
521 disp
->Extensions
.KHR_image
= EGL_TRUE
;
522 _EGL_CHECK_EXTENSION(KHR_image
);
523 _EGL_CHECK_EXTENSION(KHR_image_base
);
524 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
525 _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer
);
526 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
527 _EGL_CHECK_EXTENSION(KHR_partial_update
);
528 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
529 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
530 if (disp
->Extensions
.EXT_swap_buffers_with_damage
)
531 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
532 _EGL_CHECK_EXTENSION(EXT_pixel_format_float
);
533 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
535 if (disp
->Extensions
.KHR_no_config_context
)
536 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
537 _EGL_CHECK_EXTENSION(MESA_drm_image
);
538 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
539 _EGL_CHECK_EXTENSION(MESA_query_driver
);
541 _EGL_CHECK_EXTENSION(NOK_swap_region
);
542 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
544 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
546 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
547 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
549 #undef _EGL_CHECK_EXTENSION
553 _eglCreateAPIsString(_EGLDisplay
*disp
)
555 #define addstr(str) \
557 const size_t old_len = strlen(disp->ClientAPIsString); \
558 const size_t add_len = sizeof(str); \
559 const size_t max_len = sizeof(disp->ClientAPIsString) - 1; \
560 if (old_len + add_len <= max_len) \
561 strcat(disp->ClientAPIsString, str " "); \
563 assert(!"disp->ClientAPIsString is not large enough"); \
566 if (disp
->ClientAPIs
& EGL_OPENGL_BIT
)
569 if (disp
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
570 disp
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
571 disp
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
575 if (disp
->ClientAPIs
& EGL_OPENVG_BIT
)
582 _eglComputeVersion(_EGLDisplay
*disp
)
586 if (disp
->Extensions
.KHR_fence_sync
&&
587 disp
->Extensions
.KHR_cl_event2
&&
588 disp
->Extensions
.KHR_wait_sync
&&
589 disp
->Extensions
.KHR_image_base
&&
590 disp
->Extensions
.KHR_gl_texture_2D_image
&&
591 disp
->Extensions
.KHR_gl_texture_3D_image
&&
592 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
593 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
594 disp
->Extensions
.KHR_create_context
&&
595 disp
->Extensions
.EXT_create_context_robustness
&&
596 disp
->Extensions
.KHR_get_all_proc_addresses
&&
597 disp
->Extensions
.KHR_gl_colorspace
&&
598 disp
->Extensions
.KHR_surfaceless_context
)
603 * This is typically the second EGL function that an application calls.
604 * Here we load/initialize the actual hardware driver.
606 EGLBoolean EGLAPIENTRY
607 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
609 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
611 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
614 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
616 if (!disp
->Initialized
) {
617 if (!_eglMatchDriver(disp
))
618 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
620 /* limit to APIs supported by core */
621 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
623 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
624 * classifies it as an EGL display extension, though conceptually it's an
625 * EGL client extension.
627 * From the EGL_KHR_get_all_proc_addresses spec:
629 * The EGL implementation must expose the name
630 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
631 * EGL_KHR_get_all_proc_addresses and supports
632 * EGL_EXT_client_extensions.
634 * Mesa unconditionally exposes both client extensions mentioned above,
635 * so the spec requires that each EGLDisplay unconditionally expose
636 * EGL_KHR_get_all_proc_addresses also.
638 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
640 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
641 * programs. It is driver agnostic and handled in the main EGL code.
643 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
645 _eglComputeVersion(disp
);
646 _eglCreateExtensionsString(disp
);
647 _eglCreateAPIsString(disp
);
648 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
649 "%d.%d", disp
->Version
/ 10, disp
->Version
% 10);
652 /* Update applications version of major and minor if not NULL */
653 if ((major
!= NULL
) && (minor
!= NULL
)) {
654 *major
= disp
->Version
/ 10;
655 *minor
= disp
->Version
% 10;
658 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
662 EGLBoolean EGLAPIENTRY
663 eglTerminate(EGLDisplay dpy
)
665 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
667 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
670 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
672 if (disp
->Initialized
) {
673 _EGLDriver
*drv
= disp
->Driver
;
675 drv
->API
.Terminate(drv
, disp
);
676 /* do not reset disp->Driver */
677 disp
->ClientAPIsString
[0] = 0;
678 disp
->Initialized
= EGL_FALSE
;
680 /* Reset blob cache funcs on terminate. */
681 disp
->BlobCacheSet
= NULL
;
682 disp
->BlobCacheGet
= NULL
;
685 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
689 const char * EGLAPIENTRY
690 eglQueryString(EGLDisplay dpy
, EGLint name
)
696 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
697 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
701 disp
= _eglLockDisplay(dpy
);
702 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
703 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
707 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
709 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
711 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
712 case EGL_CLIENT_APIS
:
713 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
715 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
720 EGLBoolean EGLAPIENTRY
721 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
722 EGLint config_size
, EGLint
*num_config
)
724 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
728 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
730 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
733 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
735 ret
= _eglGetConfigs(drv
, disp
, configs
, config_size
, num_config
);
737 RETURN_EGL_EVAL(disp
, ret
);
741 EGLBoolean EGLAPIENTRY
742 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
743 EGLint config_size
, EGLint
*num_config
)
745 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
749 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
751 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
754 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
756 ret
= _eglChooseConfig(drv
, disp
, attrib_list
, configs
,
757 config_size
, num_config
);
759 RETURN_EGL_EVAL(disp
, ret
);
763 EGLBoolean EGLAPIENTRY
764 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
765 EGLint attribute
, EGLint
*value
)
767 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
768 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
772 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
774 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
776 ret
= _eglGetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
778 RETURN_EGL_EVAL(disp
, ret
);
782 EGLContext EGLAPIENTRY
783 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
784 const EGLint
*attrib_list
)
786 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
787 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
788 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
790 _EGLContext
*context
;
793 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
795 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
797 if (config
!= EGL_NO_CONFIG_KHR
)
798 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
799 else if (!disp
->Extensions
.KHR_no_config_context
)
800 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
802 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
803 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
805 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
806 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
808 RETURN_EGL_EVAL(disp
, ret
);
812 EGLBoolean EGLAPIENTRY
813 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
815 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
816 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
820 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
822 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
823 _eglUnlinkContext(context
);
824 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
826 RETURN_EGL_EVAL(disp
, ret
);
830 EGLBoolean EGLAPIENTRY
831 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
834 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
835 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
836 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
837 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
841 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
844 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
847 /* display is allowed to be uninitialized under certain condition */
848 if (!disp
->Initialized
) {
849 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
850 ctx
!= EGL_NO_CONTEXT
)
851 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
854 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
856 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
857 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
858 if (!draw_surf
|| !read_surf
) {
859 /* From the EGL 1.4 (20130211) spec:
861 * To release the current context without assigning a new one, set ctx
862 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
864 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
865 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
867 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
868 (!read_surf
&& read
!= EGL_NO_SURFACE
))
869 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
870 if (draw_surf
|| read_surf
)
871 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
874 /* If a native window underlying either draw or read is no longer valid,
875 * an EGL_BAD_NATIVE_WINDOW error is generated.
877 if (draw_surf
&& draw_surf
->Lost
)
878 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
879 if (read_surf
&& read_surf
->Lost
)
880 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
882 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
884 RETURN_EGL_EVAL(disp
, ret
);
888 EGLBoolean EGLAPIENTRY
889 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
890 EGLint attribute
, EGLint
*value
)
892 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
893 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
897 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
899 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
901 ret
= _eglQueryContext(drv
, disp
, context
, attribute
, value
);
903 RETURN_EGL_EVAL(disp
, ret
);
907 /* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says
908 * that if native_surface was already used to create a window or pixmap, we
909 * can't create a new one. This is what this function checks for.
912 _eglNativeSurfaceAlreadyUsed(_EGLDisplay
*disp
, void *native_surface
)
916 list
= disp
->ResourceLists
[_EGL_RESOURCE_SURFACE
];
918 _EGLSurface
*surf
= (_EGLSurface
*) list
;
922 if (surf
->Type
== EGL_PBUFFER_BIT
)
925 if (surf
->NativeSurface
== native_surface
)
934 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
935 void *native_window
, const EGLint
*attrib_list
)
937 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
943 if (native_window
== NULL
)
944 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
946 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
947 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
948 /* From the EGL_MESA_platform_surfaceless spec (v1):
950 * eglCreatePlatformWindowSurface fails when called with a <display>
951 * that belongs to the surfaceless platform. It returns
952 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
953 * justification for this unconditional failure is that the
954 * surfaceless platform has no native windows, and therefore the
955 * <native_window> parameter is always invalid.
957 * This check must occur before checking the EGLConfig, which emits
960 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
963 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
965 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
966 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
968 if (_eglNativeSurfaceAlreadyUsed(disp
, native_window
))
969 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
971 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
973 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
975 RETURN_EGL_EVAL(disp
, ret
);
979 EGLSurface EGLAPIENTRY
980 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
981 EGLNativeWindowType window
, const EGLint
*attrib_list
)
983 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
985 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
986 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
987 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
992 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
994 #ifdef HAVE_X11_PLATFORM
995 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
996 /* The `native_window` parameter for the X11 platform differs between
997 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
998 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
999 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
1000 * `Window*`. Convert `Window*` to `Window` because that's what
1001 * dri2_x11_create_window_surface() expects.
1003 return (void *)(* (Window
*) native_window
);
1006 return native_window
;
1009 static EGLSurface EGLAPIENTRY
1010 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1011 void *native_window
,
1012 const EGLint
*attrib_list
)
1014 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1016 native_window
= _fixupNativeWindow(disp
, native_window
);
1018 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1019 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1024 EGLSurface EGLAPIENTRY
1025 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
1026 void *native_window
,
1027 const EGLAttrib
*attrib_list
)
1029 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1031 EGLint
*int_attribs
;
1033 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1035 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1036 if (attrib_list
&& !int_attribs
)
1037 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1039 native_window
= _fixupNativeWindow(disp
, native_window
);
1040 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1047 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
1049 #ifdef HAVE_X11_PLATFORM
1050 /* The `native_pixmap` parameter for the X11 platform differs between
1051 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1052 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1053 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1054 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1055 * dri2_x11_create_pixmap_surface() expects.
1057 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
1058 return (void *)(* (Pixmap
*) native_pixmap
);
1060 return native_pixmap
;
1064 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1065 void *native_pixmap
, const EGLint
*attrib_list
)
1067 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1072 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
1073 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
1074 /* From the EGL_MESA_platform_surfaceless spec (v1):
1076 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1077 * also fails when called with a <display> that belongs to the
1078 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1079 * EGL_BAD_NATIVE_PIXMAP.
1081 * This check must occur before checking the EGLConfig, which emits
1084 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1087 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1089 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1090 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1092 if (native_pixmap
== NULL
)
1093 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1095 if (_eglNativeSurfaceAlreadyUsed(disp
, native_pixmap
))
1096 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1098 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1100 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1102 RETURN_EGL_EVAL(disp
, ret
);
1106 EGLSurface EGLAPIENTRY
1107 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1108 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1110 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1112 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1113 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1114 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1118 static EGLSurface EGLAPIENTRY
1119 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1120 void *native_pixmap
,
1121 const EGLint
*attrib_list
)
1123 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1125 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1126 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1127 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1132 EGLSurface EGLAPIENTRY
1133 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1134 void *native_pixmap
,
1135 const EGLAttrib
*attrib_list
)
1137 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1139 EGLint
*int_attribs
;
1141 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1143 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1144 if (attrib_list
&& !int_attribs
)
1145 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1147 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1148 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1155 EGLSurface EGLAPIENTRY
1156 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1157 const EGLint
*attrib_list
)
1159 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1160 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1165 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1166 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1168 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1169 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1171 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1172 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1174 RETURN_EGL_EVAL(disp
, ret
);
1178 EGLBoolean EGLAPIENTRY
1179 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1181 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1182 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1186 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1187 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1188 _eglUnlinkSurface(surf
);
1189 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1191 RETURN_EGL_EVAL(disp
, ret
);
1194 EGLBoolean EGLAPIENTRY
1195 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1196 EGLint attribute
, EGLint
*value
)
1198 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1199 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1203 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1204 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1206 if (drv
->API
.QuerySurface
)
1207 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1209 ret
= _eglQuerySurface(drv
, disp
, surf
, attribute
, value
);
1211 RETURN_EGL_EVAL(disp
, ret
);
1214 EGLBoolean EGLAPIENTRY
1215 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1216 EGLint attribute
, EGLint value
)
1218 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1219 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1223 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1224 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1226 ret
= _eglSurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1228 RETURN_EGL_EVAL(disp
, ret
);
1232 EGLBoolean EGLAPIENTRY
1233 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1235 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1236 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1240 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1241 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1242 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1244 RETURN_EGL_EVAL(disp
, ret
);
1248 EGLBoolean EGLAPIENTRY
1249 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1251 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1252 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1256 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1257 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1258 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1260 RETURN_EGL_EVAL(disp
, ret
);
1264 EGLBoolean EGLAPIENTRY
1265 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1267 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1268 _EGLContext
*ctx
= _eglGetCurrentContext();
1269 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1273 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1274 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1276 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1277 ctx
->Resource
.Display
!= disp
)
1278 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1280 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1281 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1283 if (surf
->Type
!= EGL_WINDOW_BIT
)
1284 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1286 interval
= CLAMP(interval
,
1287 surf
->Config
->MinSwapInterval
,
1288 surf
->Config
->MaxSwapInterval
);
1290 if (surf
->SwapInterval
!= interval
) {
1291 if (drv
->API
.SwapInterval
)
1292 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1294 ret
= _eglSwapInterval(drv
, disp
, surf
, interval
);
1301 surf
->SwapInterval
= interval
;
1303 RETURN_EGL_EVAL(disp
, ret
);
1307 EGLBoolean EGLAPIENTRY
1308 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1310 _EGLContext
*ctx
= _eglGetCurrentContext();
1311 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1312 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1316 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1317 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1319 /* surface must be bound to current context in EGL 1.4 */
1320 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1321 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1322 surf
!= ctx
->DrawSurface
)
1323 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1326 if (surf
->Type
!= EGL_WINDOW_BIT
)
1327 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1329 /* From the EGL 1.5 spec:
1331 * If eglSwapBuffers is called and the native window associated with
1332 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1336 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1338 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1340 /* EGL_KHR_partial_update
1341 * Frame boundary successfully reached,
1342 * reset damage region and reset BufferAgeRead
1345 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1346 surf
->BufferAgeRead
= EGL_FALSE
;
1349 RETURN_EGL_EVAL(disp
, ret
);
1354 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1355 EGLint
*rects
, EGLint n_rects
)
1357 _EGLContext
*ctx
= _eglGetCurrentContext();
1361 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1363 /* surface must be bound to current context in EGL 1.4 */
1364 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1365 surf
!= ctx
->DrawSurface
)
1366 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1368 if (surf
->Type
!= EGL_WINDOW_BIT
)
1369 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1371 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1372 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1374 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1376 /* EGL_KHR_partial_update
1377 * Frame boundary successfully reached,
1378 * reset damage region and reset BufferAgeRead
1381 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1382 surf
->BufferAgeRead
= EGL_FALSE
;
1385 RETURN_EGL_EVAL(disp
, ret
);
1388 static EGLBoolean EGLAPIENTRY
1389 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1390 EGLint
*rects
, EGLint n_rects
)
1392 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1393 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1394 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1395 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1398 static EGLBoolean EGLAPIENTRY
1399 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1400 EGLint
*rects
, EGLint n_rects
)
1402 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1403 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1404 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1405 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1409 * Clamp the rectangles so that they lie within the surface.
1413 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1414 EGLint
*rects
, EGLint n_rects
)
1417 EGLint surf_height
= surf
->Height
;
1418 EGLint surf_width
= surf
->Width
;
1420 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1421 EGLint x1
, y1
, x2
, y2
;
1424 x2
= rects
[i
+ 2] + x1
;
1425 y2
= rects
[i
+ 3] + y1
;
1427 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1428 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1429 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1430 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1434 static EGLBoolean EGLAPIENTRY
1435 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1436 EGLint
*rects
, EGLint n_rects
)
1438 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1439 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1440 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1441 _EGLContext
*ctx
= _eglGetCurrentContext();
1444 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1446 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1447 surf
->Type
!= EGL_WINDOW_BIT
||
1448 ctx
->DrawSurface
!= surf
||
1449 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1450 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1452 /* If the damage region is already set or
1453 * buffer age is not queried between
1454 * frame boundaries, throw bad access error
1457 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1458 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1460 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1461 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1464 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1466 RETURN_EGL_EVAL(disp
, ret
);
1469 EGLBoolean EGLAPIENTRY
1470 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1472 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1473 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1476 void *native_pixmap_ptr
;
1478 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1479 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1480 native_pixmap_ptr
= (void*) target
;
1482 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1483 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1485 RETURN_EGL_EVAL(disp
, ret
);
1490 _eglWaitClientCommon(void)
1492 _EGLContext
*ctx
= _eglGetCurrentContext();
1498 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1500 disp
= ctx
->Resource
.Display
;
1501 mtx_lock(&disp
->Mutex
);
1503 /* let bad current context imply bad current surface */
1504 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1505 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1506 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1508 /* a valid current context implies an initialized current display */
1509 assert(disp
->Initialized
);
1511 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1513 RETURN_EGL_EVAL(disp
, ret
);
1516 EGLBoolean EGLAPIENTRY
1519 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1520 return _eglWaitClientCommon();
1523 EGLBoolean EGLAPIENTRY
1526 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1527 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1528 return _eglWaitClientCommon();
1532 EGLBoolean EGLAPIENTRY
1533 eglWaitNative(EGLint engine
)
1535 _EGLContext
*ctx
= _eglGetCurrentContext();
1541 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1543 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1545 disp
= ctx
->Resource
.Display
;
1546 mtx_lock(&disp
->Mutex
);
1548 /* let bad current context imply bad current surface */
1549 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1550 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1551 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1553 /* a valid current context implies an initialized current display */
1554 assert(disp
->Initialized
);
1556 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1558 RETURN_EGL_EVAL(disp
, ret
);
1562 EGLDisplay EGLAPIENTRY
1563 eglGetCurrentDisplay(void)
1565 _EGLContext
*ctx
= _eglGetCurrentContext();
1568 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1570 RETURN_EGL_SUCCESS(NULL
, ret
);
1574 EGLContext EGLAPIENTRY
1575 eglGetCurrentContext(void)
1577 _EGLContext
*ctx
= _eglGetCurrentContext();
1580 ret
= _eglGetContextHandle(ctx
);
1582 RETURN_EGL_SUCCESS(NULL
, ret
);
1586 EGLSurface EGLAPIENTRY
1587 eglGetCurrentSurface(EGLint readdraw
)
1589 _EGLContext
*ctx
= _eglGetCurrentContext();
1590 EGLint err
= EGL_SUCCESS
;
1594 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1597 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1601 surf
= ctx
->DrawSurface
;
1604 surf
= ctx
->ReadSurface
;
1608 err
= EGL_BAD_PARAMETER
;
1612 ret
= _eglGetSurfaceHandle(surf
);
1614 RETURN_EGL_ERROR(NULL
, err
, ret
);
1621 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1622 EGLint e
= t
->LastError
;
1623 if (!_eglIsCurrentThreadDummy())
1624 t
->LastError
= EGL_SUCCESS
;
1634 * Specify the client API to use for subsequent calls including:
1635 * eglCreateContext()
1636 * eglGetCurrentContext()
1637 * eglGetCurrentDisplay()
1638 * eglGetCurrentSurface()
1639 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1642 * See section 3.7 "Rendering Context" in the EGL specification for details.
1644 EGLBoolean EGLAPIENTRY
1645 eglBindAPI(EGLenum api
)
1649 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1651 t
= _eglGetCurrentThread();
1652 if (_eglIsCurrentThreadDummy())
1653 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1655 if (!_eglIsApiValid(api
))
1656 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1658 t
->CurrentAPI
= api
;
1660 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1665 * Return the last value set with eglBindAPI().
1670 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1673 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1674 ret
= t
->CurrentAPI
;
1676 RETURN_EGL_SUCCESS(NULL
, ret
);
1680 EGLSurface EGLAPIENTRY
1681 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1682 EGLClientBuffer buffer
, EGLConfig config
,
1683 const EGLint
*attrib_list
)
1685 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1686 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1689 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1691 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1693 /* OpenVG is not supported */
1694 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1698 EGLBoolean EGLAPIENTRY
1699 eglReleaseThread(void)
1701 /* unbind current contexts */
1702 if (!_eglIsCurrentThreadDummy()) {
1703 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1704 _EGLContext
*ctx
= t
->CurrentContext
;
1706 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1709 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1712 mtx_lock(&disp
->Mutex
);
1714 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1715 mtx_unlock(&disp
->Mutex
);
1719 _eglDestroyCurrentThread();
1721 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1726 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1727 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1729 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1734 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1735 if (!disp
->Extensions
.KHR_image_base
)
1736 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1737 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1738 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1739 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1740 * <ctx> must be EGL_NO_CONTEXT..."
1742 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1743 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1745 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1747 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1749 RETURN_EGL_EVAL(disp
, ret
);
1752 static EGLImage EGLAPIENTRY
1753 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1754 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1756 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1757 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1758 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1762 EGLImage EGLAPIENTRY
1763 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1764 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1766 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1768 EGLint
*int_attribs
;
1770 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1772 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1773 if (attr_list
&& !int_attribs
)
1774 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1776 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1783 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1788 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1789 if (!disp
->Extensions
.KHR_image_base
)
1790 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1792 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1794 _eglUnlinkImage(img
);
1795 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1797 RETURN_EGL_EVAL(disp
, ret
);
1800 EGLBoolean EGLAPIENTRY
1801 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1803 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1804 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1805 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1806 return _eglDestroyImageCommon(disp
, img
);
1809 static EGLBoolean EGLAPIENTRY
1810 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1812 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1813 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1814 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1815 return _eglDestroyImageCommon(disp
, img
);
1820 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1821 EGLBoolean orig_is_EGLAttrib
,
1822 EGLenum invalid_type_error
)
1824 _EGLContext
*ctx
= _eglGetCurrentContext();
1829 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1831 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1832 /* There exist two EGLAttrib variants of eglCreateSync*:
1833 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1834 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1835 * support as a proxy for EGL 1.5 support, even though that's not
1836 * entirely correct (though _eglComputeVersion does the same).
1838 * The EGL spec provides no guidance on how to handle unsupported
1839 * functions. EGL_BAD_MATCH seems reasonable.
1841 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1844 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1845 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1846 * error is generated.
1849 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1850 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1852 /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */
1853 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1854 (ctx
->ClientAPI
!= EGL_OPENGL_ES_API
&&
1855 ctx
->ClientAPI
!= EGL_OPENGL_API
)))
1856 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1859 case EGL_SYNC_FENCE_KHR
:
1860 if (!disp
->Extensions
.KHR_fence_sync
)
1861 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1863 case EGL_SYNC_REUSABLE_KHR
:
1864 if (!disp
->Extensions
.KHR_reusable_sync
)
1865 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1867 case EGL_SYNC_CL_EVENT_KHR
:
1868 if (!disp
->Extensions
.KHR_cl_event2
)
1869 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1871 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1872 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1873 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1876 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1879 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1880 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1882 RETURN_EGL_EVAL(disp
, ret
);
1886 static EGLSync EGLAPIENTRY
1887 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1889 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1890 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1893 EGLAttrib
*attrib_list
;
1896 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1897 attrib_list
= (EGLAttrib
*) int_list
;
1899 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1900 if (err
!= EGL_SUCCESS
)
1901 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1904 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1907 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1910 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1915 static EGLSync EGLAPIENTRY
1916 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1918 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1919 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1920 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1926 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1928 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1929 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1930 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1936 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1941 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1942 assert(disp
->Extensions
.KHR_reusable_sync
||
1943 disp
->Extensions
.KHR_fence_sync
||
1944 disp
->Extensions
.ANDROID_native_fence_sync
);
1947 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1949 RETURN_EGL_EVAL(disp
, ret
);
1952 EGLBoolean EGLAPIENTRY
1953 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1955 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1956 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1957 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1958 return _eglDestroySync(disp
, s
);
1961 static EGLBoolean EGLAPIENTRY
1962 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1964 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1965 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1966 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1967 return _eglDestroySync(disp
, s
);
1972 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1973 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1978 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1979 assert(disp
->Extensions
.KHR_reusable_sync
||
1980 disp
->Extensions
.KHR_fence_sync
||
1981 disp
->Extensions
.ANDROID_native_fence_sync
);
1983 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1984 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1986 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1987 * unlocked here to allow other threads also to be able to
1988 * go into waiting state.
1991 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1992 _eglUnlockDisplay(dpy
);
1994 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1997 * 'disp' is already unlocked for reusable sync type,
1998 * so passing 'NULL' to bypass unlocking display.
2000 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
2001 RETURN_EGL_EVAL(NULL
, ret
);
2003 RETURN_EGL_EVAL(disp
, ret
);
2007 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
2008 EGLint flags
, EGLTime timeout
)
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 _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2016 static EGLint EGLAPIENTRY
2017 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
2018 EGLint flags
, EGLTime timeout
)
2020 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2021 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2022 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2023 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2028 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
2030 _EGLContext
*ctx
= _eglGetCurrentContext();
2034 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2035 assert(disp
->Extensions
.KHR_wait_sync
);
2037 /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */
2038 if (ctx
== EGL_NO_CONTEXT
||
2039 (ctx
->ClientAPI
!= EGL_OPENGL_ES_API
&&
2040 ctx
->ClientAPI
!= EGL_OPENGL_API
))
2041 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
2043 /* the API doesn't allow any flags yet */
2045 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2047 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
2049 RETURN_EGL_EVAL(disp
, ret
);
2052 static EGLint EGLAPIENTRY
2053 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2055 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2056 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2057 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2058 return _eglWaitSyncCommon(disp
, s
, flags
);
2062 EGLBoolean EGLAPIENTRY
2063 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2065 /* The KHR version returns EGLint, while the core version returns
2066 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2069 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2070 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2071 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2072 return _eglWaitSyncCommon(disp
, s
, flags
);
2076 static EGLBoolean EGLAPIENTRY
2077 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2079 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2080 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2084 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2086 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2087 assert(disp
->Extensions
.KHR_reusable_sync
);
2088 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2090 RETURN_EGL_EVAL(disp
, ret
);
2095 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2100 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2101 assert(disp
->Extensions
.KHR_reusable_sync
||
2102 disp
->Extensions
.KHR_fence_sync
||
2103 disp
->Extensions
.ANDROID_native_fence_sync
);
2105 ret
= _eglGetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2107 RETURN_EGL_EVAL(disp
, ret
);
2110 EGLBoolean EGLAPIENTRY
2111 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2113 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2114 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2115 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2118 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2120 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2124 static EGLBoolean EGLAPIENTRY
2125 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2127 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2128 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2132 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2135 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2138 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2140 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2142 * If any error occurs, <*value> is not modified.
2144 if (result
== EGL_FALSE
)
2151 static EGLint EGLAPIENTRY
2152 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2154 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2155 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2159 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2161 /* the spec doesn't seem to specify what happens if the fence
2162 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2165 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2166 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2168 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2169 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2170 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2172 RETURN_EGL_EVAL(disp
, ret
);
2175 static EGLBoolean EGLAPIENTRY
2176 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2177 EGLint numRects
, const EGLint
*rects
)
2179 _EGLContext
*ctx
= _eglGetCurrentContext();
2180 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2181 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2185 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2187 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2189 if (!disp
->Extensions
.NOK_swap_region
)
2190 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2192 /* surface must be bound to current context in EGL 1.4 */
2193 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2194 surf
!= ctx
->DrawSurface
)
2195 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2197 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2199 RETURN_EGL_EVAL(disp
, ret
);
2203 static EGLImage EGLAPIENTRY
2204 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2206 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2211 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2213 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2214 if (!disp
->Extensions
.MESA_drm_image
)
2215 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2217 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2218 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2220 RETURN_EGL_EVAL(disp
, ret
);
2223 static EGLBoolean EGLAPIENTRY
2224 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2225 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2227 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2228 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2232 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2234 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2235 assert(disp
->Extensions
.MESA_drm_image
);
2238 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2240 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2242 RETURN_EGL_EVAL(disp
, ret
);
2248 static EGLBoolean EGLAPIENTRY
2249 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2251 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2255 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2257 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2258 assert(disp
->Extensions
.WL_bind_wayland_display
);
2261 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2263 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2265 RETURN_EGL_EVAL(disp
, ret
);
2268 static EGLBoolean EGLAPIENTRY
2269 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2271 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2275 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2277 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2278 assert(disp
->Extensions
.WL_bind_wayland_display
);
2281 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2283 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2285 RETURN_EGL_EVAL(disp
, ret
);
2288 static EGLBoolean EGLAPIENTRY
2289 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2290 EGLint attribute
, EGLint
*value
)
2292 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2296 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2298 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2299 assert(disp
->Extensions
.WL_bind_wayland_display
);
2302 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2304 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2306 RETURN_EGL_EVAL(disp
, ret
);
2310 static struct wl_buffer
* EGLAPIENTRY
2311 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2313 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2316 struct wl_buffer
*ret
;
2318 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2320 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2321 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2322 RETURN_EGL_EVAL(disp
, NULL
);
2324 img
= _eglLookupImage(image
, disp
);
2327 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2329 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2331 RETURN_EGL_EVAL(disp
, ret
);
2334 static EGLBoolean EGLAPIENTRY
2335 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2336 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2338 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2339 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2343 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2345 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2347 if (!disp
->Extensions
.NV_post_sub_buffer
)
2348 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2350 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2352 RETURN_EGL_EVAL(disp
, ret
);
2355 static EGLBoolean EGLAPIENTRY
2356 eglGetSyncValuesCHROMIUM(EGLDisplay dpy
, EGLSurface surface
,
2357 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2360 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2361 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2365 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2367 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2368 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2369 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2371 if (!ust
|| !msc
|| !sbc
)
2372 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2374 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2376 RETURN_EGL_EVAL(disp
, ret
);
2379 static EGLBoolean EGLAPIENTRY
2380 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2381 EGLint
*fourcc
, EGLint
*nplanes
,
2382 EGLuint64KHR
*modifiers
)
2384 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2385 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2389 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2391 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2392 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2395 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2397 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2400 RETURN_EGL_EVAL(disp
, ret
);
2403 static EGLBoolean EGLAPIENTRY
2404 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2405 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2407 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2408 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2412 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2414 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2415 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2418 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2420 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2422 RETURN_EGL_EVAL(disp
, ret
);
2425 static EGLint EGLAPIENTRY
2426 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2429 _EGLDisplay
*disp
= NULL
;
2430 _EGLResourceType type
;
2432 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2434 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2435 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2437 if (!_eglIsCurrentThreadDummy()) {
2442 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2445 disp
= _eglLockDisplay(dpy
);
2447 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2449 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2450 if (dpy
!= (EGLDisplay
) object
)
2451 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2453 disp
->Label
= label
;
2454 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2457 switch (objectType
) {
2458 case EGL_OBJECT_CONTEXT_KHR
:
2459 type
= _EGL_RESOURCE_CONTEXT
;
2461 case EGL_OBJECT_SURFACE_KHR
:
2462 type
= _EGL_RESOURCE_SURFACE
;
2464 case EGL_OBJECT_IMAGE_KHR
:
2465 type
= _EGL_RESOURCE_IMAGE
;
2467 case EGL_OBJECT_SYNC_KHR
:
2468 type
= _EGL_RESOURCE_SYNC
;
2470 case EGL_OBJECT_STREAM_KHR
:
2472 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2475 if (_eglCheckResource(object
, type
, disp
)) {
2476 _EGLResource
*res
= (_EGLResource
*) object
;
2479 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2482 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2485 static EGLint EGLAPIENTRY
2486 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2487 const EGLAttrib
*attrib_list
)
2489 unsigned int newEnabled
;
2491 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2493 mtx_lock(_eglGlobal
.Mutex
);
2495 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2496 if (attrib_list
!= NULL
) {
2499 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2500 switch (attrib_list
[i
]) {
2501 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2502 case EGL_DEBUG_MSG_ERROR_KHR
:
2503 case EGL_DEBUG_MSG_WARN_KHR
:
2504 case EGL_DEBUG_MSG_INFO_KHR
:
2505 if (attrib_list
[i
+ 1])
2506 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2508 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2511 // On error, set the last error code, call the current
2512 // debug callback, and return the error code.
2513 mtx_unlock(_eglGlobal
.Mutex
);
2514 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2515 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2516 return EGL_BAD_ATTRIBUTE
;
2521 if (callback
!= NULL
) {
2522 _eglGlobal
.debugCallback
= callback
;
2523 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2525 _eglGlobal
.debugCallback
= NULL
;
2526 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2529 mtx_unlock(_eglGlobal
.Mutex
);
2533 static EGLBoolean EGLAPIENTRY
2534 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2536 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2538 mtx_lock(_eglGlobal
.Mutex
);
2540 switch (attribute
) {
2541 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2542 case EGL_DEBUG_MSG_ERROR_KHR
:
2543 case EGL_DEBUG_MSG_WARN_KHR
:
2544 case EGL_DEBUG_MSG_INFO_KHR
:
2545 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2550 case EGL_DEBUG_CALLBACK_KHR
:
2551 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2554 mtx_unlock(_eglGlobal
.Mutex
);
2555 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2556 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2560 mtx_unlock(_eglGlobal
.Mutex
);
2565 _eglFunctionCompare(const void *key
, const void *elem
)
2567 const char *procname
= key
;
2568 const struct _egl_entrypoint
*entrypoint
= elem
;
2569 return strcmp(procname
, entrypoint
->name
);
2572 static EGLBoolean EGLAPIENTRY
2573 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2574 EGLint
*formats
, EGLint
*num_formats
)
2576 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2580 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2582 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2584 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2587 RETURN_EGL_EVAL(disp
, ret
);
2590 static EGLBoolean EGLAPIENTRY
2591 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2592 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2593 EGLint
*num_modifiers
)
2595 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2599 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2601 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2603 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2604 modifiers
, external_only
,
2607 RETURN_EGL_EVAL(disp
, ret
);
2610 static void EGLAPIENTRY
2611 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2612 EGLGetBlobFuncANDROID get
)
2614 /* This function does not return anything so we cannot
2615 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2617 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2618 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2620 _eglUnlockDisplay(disp
);
2624 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2627 _eglUnlockDisplay(disp
);
2632 _eglError(EGL_BAD_PARAMETER
,
2633 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2634 _eglUnlockDisplay(disp
);
2638 if (disp
->BlobCacheSet
) {
2639 _eglError(EGL_BAD_PARAMETER
,
2640 "eglSetBlobCacheFuncsANDROID: functions already set");
2641 _eglUnlockDisplay(disp
);
2645 disp
->BlobCacheSet
= set
;
2646 disp
->BlobCacheGet
= get
;
2648 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2650 _eglUnlockDisplay(disp
);
2653 static EGLBoolean EGLAPIENTRY
2654 eglQueryDeviceAttribEXT(EGLDeviceEXT device
,
2658 _EGLDevice
*dev
= _eglLookupDevice(device
);
2661 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2663 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, EGL_FALSE
);
2665 ret
= _eglQueryDeviceAttribEXT(dev
, attribute
, value
);
2666 RETURN_EGL_EVAL(NULL
, ret
);
2669 static const char * EGLAPIENTRY
2670 eglQueryDeviceStringEXT(EGLDeviceEXT device
,
2673 _EGLDevice
*dev
= _eglLookupDevice(device
);
2675 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2677 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, NULL
);
2679 RETURN_EGL_EVAL(NULL
, _eglQueryDeviceStringEXT(dev
, name
));
2682 static EGLBoolean EGLAPIENTRY
2683 eglQueryDevicesEXT(EGLint max_devices
,
2684 EGLDeviceEXT
*devices
,
2685 EGLint
*num_devices
)
2689 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2690 ret
= _eglQueryDevicesEXT(max_devices
, (_EGLDevice
**) devices
,
2692 RETURN_EGL_EVAL(NULL
, ret
);
2695 static EGLBoolean EGLAPIENTRY
2696 eglQueryDisplayAttribEXT(EGLDisplay dpy
,
2700 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2703 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2704 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2706 switch (attribute
) {
2707 case EGL_DEVICE_EXT
:
2708 *value
= (EGLAttrib
) disp
->Device
;
2711 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
2713 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
2716 static char * EGLAPIENTRY
2717 eglGetDisplayDriverConfig(EGLDisplay dpy
)
2719 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2723 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2724 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2726 assert(disp
->Extensions
.MESA_query_driver
);
2728 ret
= drv
->API
.QueryDriverConfig(disp
);
2729 RETURN_EGL_EVAL(disp
, ret
);
2732 static const char * EGLAPIENTRY
2733 eglGetDisplayDriverName(EGLDisplay dpy
)
2735 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2739 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2740 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2742 assert(disp
->Extensions
.MESA_query_driver
);
2744 ret
= drv
->API
.QueryDriverName(disp
);
2745 RETURN_EGL_EVAL(disp
, ret
);
2748 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2749 eglGetProcAddress(const char *procname
)
2751 static const struct _egl_entrypoint egl_functions
[] = {
2752 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2753 #include "eglentrypoint.h"
2754 #undef EGL_ENTRYPOINT
2756 _EGLProc ret
= NULL
;
2759 RETURN_EGL_SUCCESS(NULL
, NULL
);
2761 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2763 if (strncmp(procname
, "egl", 3) == 0) {
2764 const struct _egl_entrypoint
*entrypoint
=
2766 egl_functions
, ARRAY_SIZE(egl_functions
),
2767 sizeof(egl_functions
[0]),
2768 _eglFunctionCompare
);
2770 ret
= entrypoint
->function
;
2774 ret
= _eglGetDriverProc(procname
);
2776 RETURN_EGL_SUCCESS(NULL
, ret
);
2780 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2781 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2785 *disp
= _eglLockDisplay(dpy
);
2786 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2788 _eglUnlockDisplay(*disp
);
2789 return MESA_GLINTEROP_INVALID_DISPLAY
;
2792 *drv
= (*disp
)->Driver
;
2794 *ctx
= _eglLookupContext(context
, *disp
);
2796 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2797 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2798 _eglUnlockDisplay(*disp
);
2799 return MESA_GLINTEROP_INVALID_CONTEXT
;
2802 return MESA_GLINTEROP_SUCCESS
;
2806 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2807 struct mesa_glinterop_device_info
*out
)
2814 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2815 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2818 if (drv
->API
.GLInteropQueryDeviceInfo
)
2819 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2821 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2823 _eglUnlockDisplay(disp
);
2828 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2829 struct mesa_glinterop_export_in
*in
,
2830 struct mesa_glinterop_export_out
*out
)
2837 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2838 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2841 if (drv
->API
.GLInteropExportObject
)
2842 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2844 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2846 _eglUnlockDisplay(disp
);