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 case EGL_PLATFORM_DEVICE_EXT
:
410 disp
= _eglGetDeviceDisplay(native_display
, attrib_list
);
413 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
416 return _eglGetDisplayHandle(disp
);
419 static EGLDisplay EGLAPIENTRY
420 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
421 const EGLint
*int_attribs
)
423 EGLAttrib
*attrib_list
;
426 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
428 if (_eglConvertIntsToAttribs(int_attribs
, &attrib_list
) != EGL_SUCCESS
)
429 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
431 disp
= _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
436 EGLDisplay EGLAPIENTRY
437 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
438 const EGLAttrib
*attrib_list
)
440 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
441 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
445 * Copy the extension into the string and update the string pointer.
448 _eglAppendExtension(char **str
, const char *ext
)
451 size_t len
= strlen(ext
);
468 * Examine the individual extension enable/disable flags and recompute
469 * the driver's Extensions string.
472 _eglCreateExtensionsString(_EGLDisplay
*disp
)
474 #define _EGL_CHECK_EXTENSION(ext) \
476 if (disp->Extensions.ext) { \
477 _eglAppendExtension(&exts, "EGL_" #ext); \
478 assert(exts <= disp->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
482 char *exts
= disp
->ExtensionsString
;
484 /* Please keep these sorted alphabetically. */
485 _EGL_CHECK_EXTENSION(ANDROID_blob_cache
);
486 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
487 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
488 _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync
);
489 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
491 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
493 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
494 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
495 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
496 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers
);
497 _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata
);
498 _EGL_CHECK_EXTENSION(EXT_surface_SMPTE2086_metadata
);
499 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
501 _EGL_CHECK_EXTENSION(IMG_context_priority
);
503 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
504 _EGL_CHECK_EXTENSION(KHR_config_attribs
);
505 _EGL_CHECK_EXTENSION(KHR_context_flush_control
);
506 _EGL_CHECK_EXTENSION(KHR_create_context
);
507 _EGL_CHECK_EXTENSION(KHR_create_context_no_error
);
508 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
509 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
510 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
511 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
512 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
513 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
514 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
515 if (disp
->Extensions
.KHR_image_base
&& disp
->Extensions
.KHR_image_pixmap
)
516 disp
->Extensions
.KHR_image
= EGL_TRUE
;
517 _EGL_CHECK_EXTENSION(KHR_image
);
518 _EGL_CHECK_EXTENSION(KHR_image_base
);
519 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
520 _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer
);
521 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
522 _EGL_CHECK_EXTENSION(KHR_partial_update
);
523 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
524 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
525 if (disp
->Extensions
.EXT_swap_buffers_with_damage
)
526 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
527 _EGL_CHECK_EXTENSION(EXT_pixel_format_float
);
528 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
530 if (disp
->Extensions
.KHR_no_config_context
)
531 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
532 _EGL_CHECK_EXTENSION(MESA_drm_image
);
533 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
534 _EGL_CHECK_EXTENSION(MESA_query_driver
);
536 _EGL_CHECK_EXTENSION(NOK_swap_region
);
537 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
539 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
541 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
542 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
544 #undef _EGL_CHECK_EXTENSION
548 _eglCreateAPIsString(_EGLDisplay
*disp
)
550 #define addstr(str) \
552 const size_t old_len = strlen(disp->ClientAPIsString); \
553 const size_t add_len = sizeof(str); \
554 const size_t max_len = sizeof(disp->ClientAPIsString) - 1; \
555 if (old_len + add_len <= max_len) \
556 strcat(disp->ClientAPIsString, str " "); \
558 assert(!"disp->ClientAPIsString is not large enough"); \
561 if (disp
->ClientAPIs
& EGL_OPENGL_BIT
)
564 if (disp
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
565 disp
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
566 disp
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
570 if (disp
->ClientAPIs
& EGL_OPENVG_BIT
)
577 _eglComputeVersion(_EGLDisplay
*disp
)
581 if (disp
->Extensions
.KHR_fence_sync
&&
582 disp
->Extensions
.KHR_cl_event2
&&
583 disp
->Extensions
.KHR_wait_sync
&&
584 disp
->Extensions
.KHR_image_base
&&
585 disp
->Extensions
.KHR_gl_texture_2D_image
&&
586 disp
->Extensions
.KHR_gl_texture_3D_image
&&
587 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
588 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
589 disp
->Extensions
.KHR_create_context
&&
590 disp
->Extensions
.EXT_create_context_robustness
&&
591 disp
->Extensions
.KHR_get_all_proc_addresses
&&
592 disp
->Extensions
.KHR_gl_colorspace
&&
593 disp
->Extensions
.KHR_surfaceless_context
)
598 * This is typically the second EGL function that an application calls.
599 * Here we load/initialize the actual hardware driver.
601 EGLBoolean EGLAPIENTRY
602 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
604 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
606 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
609 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
611 if (!disp
->Initialized
) {
612 if (!_eglMatchDriver(disp
))
613 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
615 /* limit to APIs supported by core */
616 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
618 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
619 * classifies it as an EGL display extension, though conceptually it's an
620 * EGL client extension.
622 * From the EGL_KHR_get_all_proc_addresses spec:
624 * The EGL implementation must expose the name
625 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
626 * EGL_KHR_get_all_proc_addresses and supports
627 * EGL_EXT_client_extensions.
629 * Mesa unconditionally exposes both client extensions mentioned above,
630 * so the spec requires that each EGLDisplay unconditionally expose
631 * EGL_KHR_get_all_proc_addresses also.
633 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
635 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
636 * programs. It is driver agnostic and handled in the main EGL code.
638 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
640 _eglComputeVersion(disp
);
641 _eglCreateExtensionsString(disp
);
642 _eglCreateAPIsString(disp
);
643 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
644 "%d.%d", disp
->Version
/ 10, disp
->Version
% 10);
647 /* Update applications version of major and minor if not NULL */
648 if ((major
!= NULL
) && (minor
!= NULL
)) {
649 *major
= disp
->Version
/ 10;
650 *minor
= disp
->Version
% 10;
653 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
657 EGLBoolean EGLAPIENTRY
658 eglTerminate(EGLDisplay dpy
)
660 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
662 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
665 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
667 if (disp
->Initialized
) {
668 _EGLDriver
*drv
= disp
->Driver
;
670 drv
->API
.Terminate(drv
, disp
);
671 /* do not reset disp->Driver */
672 disp
->ClientAPIsString
[0] = 0;
673 disp
->Initialized
= EGL_FALSE
;
676 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
680 const char * EGLAPIENTRY
681 eglQueryString(EGLDisplay dpy
, EGLint name
)
686 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
687 const char *ret
= _eglGetClientExtensionString();
689 RETURN_EGL_SUCCESS(NULL
, ret
);
691 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
694 disp
= _eglLockDisplay(dpy
);
695 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
696 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
700 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
702 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
704 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
705 case EGL_CLIENT_APIS
:
706 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
708 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
713 EGLBoolean EGLAPIENTRY
714 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
715 EGLint config_size
, EGLint
*num_config
)
717 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
721 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
723 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
726 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
728 if (drv
->API
.GetConfigs
)
729 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
731 ret
= _eglGetConfigs(drv
, disp
, configs
, config_size
, num_config
);
733 RETURN_EGL_EVAL(disp
, ret
);
737 EGLBoolean EGLAPIENTRY
738 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
739 EGLint config_size
, EGLint
*num_config
)
741 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
745 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
747 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
750 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
752 if (drv
->API
.ChooseConfig
)
753 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
754 config_size
, num_config
);
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
);
775 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
777 RETURN_EGL_EVAL(disp
, ret
);
781 EGLContext EGLAPIENTRY
782 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
783 const EGLint
*attrib_list
)
785 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
786 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
787 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
789 _EGLContext
*context
;
792 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
794 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
796 if (config
!= EGL_NO_CONFIG_KHR
)
797 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
798 else if (!disp
->Extensions
.KHR_no_config_context
)
799 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
801 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
802 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
804 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
805 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
807 RETURN_EGL_EVAL(disp
, ret
);
811 EGLBoolean EGLAPIENTRY
812 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
814 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
815 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
819 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
821 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
822 _eglUnlinkContext(context
);
823 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
825 RETURN_EGL_EVAL(disp
, ret
);
829 EGLBoolean EGLAPIENTRY
830 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
833 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
834 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
835 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
836 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
840 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
843 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
846 /* display is allowed to be uninitialized under certain condition */
847 if (!disp
->Initialized
) {
848 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
849 ctx
!= EGL_NO_CONTEXT
)
850 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
853 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
855 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
856 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
857 if (!draw_surf
|| !read_surf
) {
858 /* From the EGL 1.4 (20130211) spec:
860 * To release the current context without assigning a new one, set ctx
861 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
863 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
864 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
866 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
867 (!read_surf
&& read
!= EGL_NO_SURFACE
))
868 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
869 if (draw_surf
|| read_surf
)
870 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
873 /* If a native window underlying either draw or read is no longer valid,
874 * an EGL_BAD_NATIVE_WINDOW error is generated.
876 if (draw_surf
&& draw_surf
->Lost
)
877 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
878 if (read_surf
&& read_surf
->Lost
)
879 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
881 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
883 RETURN_EGL_EVAL(disp
, ret
);
887 EGLBoolean EGLAPIENTRY
888 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
889 EGLint attribute
, EGLint
*value
)
891 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
892 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
896 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
898 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
899 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
901 RETURN_EGL_EVAL(disp
, ret
);
905 /* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says
906 * that if native_surface was already used to create a window or pixmap, we
907 * can't create a new one. This is what this function checks for.
910 _eglNativeSurfaceAlreadyUsed(_EGLDisplay
*disp
, void *native_surface
)
914 list
= disp
->ResourceLists
[_EGL_RESOURCE_SURFACE
];
916 _EGLSurface
*surf
= (_EGLSurface
*) list
;
920 if (surf
->Type
== EGL_PBUFFER_BIT
)
923 if (surf
->NativeSurface
== native_surface
)
932 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
933 void *native_window
, const EGLint
*attrib_list
)
935 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
941 if (native_window
== NULL
)
942 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
944 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
945 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
946 /* From the EGL_MESA_platform_surfaceless spec (v1):
948 * eglCreatePlatformWindowSurface fails when called with a <display>
949 * that belongs to the surfaceless platform. It returns
950 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
951 * justification for this unconditional failure is that the
952 * surfaceless platform has no native windows, and therefore the
953 * <native_window> parameter is always invalid.
955 * This check must occur before checking the EGLConfig, which emits
958 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
961 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
963 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
964 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
966 if (_eglNativeSurfaceAlreadyUsed(disp
, native_window
))
967 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
969 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
971 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
973 RETURN_EGL_EVAL(disp
, ret
);
977 EGLSurface EGLAPIENTRY
978 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
979 EGLNativeWindowType window
, const EGLint
*attrib_list
)
981 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
983 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
984 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
985 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
990 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
992 #ifdef HAVE_X11_PLATFORM
993 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
994 /* The `native_window` parameter for the X11 platform differs between
995 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
996 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
997 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
998 * `Window*`. Convert `Window*` to `Window` because that's what
999 * dri2_x11_create_window_surface() expects.
1001 return (void *)(* (Window
*) native_window
);
1004 return native_window
;
1007 static EGLSurface EGLAPIENTRY
1008 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1009 void *native_window
,
1010 const EGLint
*attrib_list
)
1012 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1014 native_window
= _fixupNativeWindow(disp
, native_window
);
1016 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1017 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1022 EGLSurface EGLAPIENTRY
1023 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
1024 void *native_window
,
1025 const EGLAttrib
*attrib_list
)
1027 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1029 EGLint
*int_attribs
;
1031 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1033 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1034 if (attrib_list
&& !int_attribs
)
1035 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1037 native_window
= _fixupNativeWindow(disp
, native_window
);
1038 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1045 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
1047 #ifdef HAVE_X11_PLATFORM
1048 /* The `native_pixmap` parameter for the X11 platform differs between
1049 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1050 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1051 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1052 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1053 * dri2_x11_create_pixmap_surface() expects.
1055 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
1056 return (void *)(* (Pixmap
*) native_pixmap
);
1058 return native_pixmap
;
1062 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1063 void *native_pixmap
, const EGLint
*attrib_list
)
1065 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1070 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
1071 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
1072 /* From the EGL_MESA_platform_surfaceless spec (v1):
1074 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1075 * also fails when called with a <display> that belongs to the
1076 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1077 * EGL_BAD_NATIVE_PIXMAP.
1079 * This check must occur before checking the EGLConfig, which emits
1082 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1085 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1087 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1088 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1090 if (native_pixmap
== NULL
)
1091 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1093 if (_eglNativeSurfaceAlreadyUsed(disp
, native_pixmap
))
1094 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1096 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1098 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1100 RETURN_EGL_EVAL(disp
, ret
);
1104 EGLSurface EGLAPIENTRY
1105 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1106 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1108 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1110 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1111 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1112 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1116 static EGLSurface EGLAPIENTRY
1117 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1118 void *native_pixmap
,
1119 const EGLint
*attrib_list
)
1121 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1123 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1124 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1125 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1130 EGLSurface EGLAPIENTRY
1131 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1132 void *native_pixmap
,
1133 const EGLAttrib
*attrib_list
)
1135 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1137 EGLint
*int_attribs
;
1139 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1141 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1142 if (attrib_list
&& !int_attribs
)
1143 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1145 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1146 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1153 EGLSurface EGLAPIENTRY
1154 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1155 const EGLint
*attrib_list
)
1157 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1158 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1163 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1164 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1166 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1167 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1169 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1170 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1172 RETURN_EGL_EVAL(disp
, ret
);
1176 EGLBoolean EGLAPIENTRY
1177 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
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 _eglUnlinkSurface(surf
);
1187 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1189 RETURN_EGL_EVAL(disp
, ret
);
1192 EGLBoolean EGLAPIENTRY
1193 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1194 EGLint attribute
, EGLint
*value
)
1196 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1197 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1201 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1202 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1203 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1205 RETURN_EGL_EVAL(disp
, ret
);
1208 EGLBoolean EGLAPIENTRY
1209 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1210 EGLint attribute
, EGLint value
)
1212 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1213 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1217 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1218 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1219 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1221 RETURN_EGL_EVAL(disp
, ret
);
1225 EGLBoolean EGLAPIENTRY
1226 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1228 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1229 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1233 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1234 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1235 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1237 RETURN_EGL_EVAL(disp
, ret
);
1241 EGLBoolean EGLAPIENTRY
1242 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1244 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1245 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1249 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1250 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1251 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1253 RETURN_EGL_EVAL(disp
, ret
);
1257 EGLBoolean EGLAPIENTRY
1258 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1260 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1261 _EGLContext
*ctx
= _eglGetCurrentContext();
1262 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1266 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1267 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1269 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1270 ctx
->Resource
.Display
!= disp
)
1271 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1273 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1274 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1276 if (surf
->Type
!= EGL_WINDOW_BIT
)
1277 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1279 interval
= CLAMP(interval
,
1280 surf
->Config
->MinSwapInterval
,
1281 surf
->Config
->MaxSwapInterval
);
1283 if (surf
->SwapInterval
!= interval
)
1284 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1289 surf
->SwapInterval
= interval
;
1291 RETURN_EGL_EVAL(disp
, ret
);
1295 EGLBoolean EGLAPIENTRY
1296 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1298 _EGLContext
*ctx
= _eglGetCurrentContext();
1299 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1300 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1304 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1305 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1307 /* surface must be bound to current context in EGL 1.4 */
1308 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1309 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1310 surf
!= ctx
->DrawSurface
)
1311 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1314 if (surf
->Type
!= EGL_WINDOW_BIT
)
1315 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1317 /* From the EGL 1.5 spec:
1319 * If eglSwapBuffers is called and the native window associated with
1320 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1324 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1326 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1328 /* EGL_KHR_partial_update
1329 * Frame boundary successfully reached,
1330 * reset damage region and reset BufferAgeRead
1333 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1334 surf
->BufferAgeRead
= EGL_FALSE
;
1337 RETURN_EGL_EVAL(disp
, ret
);
1342 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1343 EGLint
*rects
, EGLint n_rects
)
1345 _EGLContext
*ctx
= _eglGetCurrentContext();
1349 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1351 /* surface must be bound to current context in EGL 1.4 */
1352 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1353 surf
!= ctx
->DrawSurface
)
1354 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1356 if (surf
->Type
!= EGL_WINDOW_BIT
)
1357 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1359 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1360 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1362 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1364 /* EGL_KHR_partial_update
1365 * Frame boundary successfully reached,
1366 * reset damage region and reset BufferAgeRead
1369 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1370 surf
->BufferAgeRead
= EGL_FALSE
;
1373 RETURN_EGL_EVAL(disp
, ret
);
1376 static EGLBoolean EGLAPIENTRY
1377 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1378 EGLint
*rects
, EGLint n_rects
)
1380 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1381 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1382 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1383 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1386 static EGLBoolean EGLAPIENTRY
1387 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1388 EGLint
*rects
, EGLint n_rects
)
1390 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1391 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1392 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1393 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1397 * Clamp the rectangles so that they lie within the surface.
1401 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1402 EGLint
*rects
, EGLint n_rects
)
1405 EGLint surf_height
= surf
->Height
;
1406 EGLint surf_width
= surf
->Width
;
1408 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1409 EGLint x1
, y1
, x2
, y2
;
1412 x2
= rects
[i
+ 2] + x1
;
1413 y2
= rects
[i
+ 3] + y1
;
1415 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1416 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1417 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1418 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1422 static EGLBoolean EGLAPIENTRY
1423 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1424 EGLint
*rects
, EGLint n_rects
)
1426 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1427 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1428 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1429 _EGLContext
*ctx
= _eglGetCurrentContext();
1432 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1434 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1435 surf
->Type
!= EGL_WINDOW_BIT
||
1436 ctx
->DrawSurface
!= surf
||
1437 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1438 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1440 /* If the damage region is already set or
1441 * buffer age is not queried between
1442 * frame boundaries, throw bad access error
1445 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1446 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1448 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1449 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1452 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1454 RETURN_EGL_EVAL(disp
, ret
);
1457 EGLBoolean EGLAPIENTRY
1458 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1460 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1461 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1464 void *native_pixmap_ptr
;
1466 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1467 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1468 native_pixmap_ptr
= (void*) target
;
1470 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1471 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1473 RETURN_EGL_EVAL(disp
, ret
);
1478 _eglWaitClientCommon(void)
1480 _EGLContext
*ctx
= _eglGetCurrentContext();
1486 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1488 disp
= ctx
->Resource
.Display
;
1489 mtx_lock(&disp
->Mutex
);
1491 /* let bad current context imply bad current surface */
1492 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1493 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1494 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1496 /* a valid current context implies an initialized current display */
1497 assert(disp
->Initialized
);
1499 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1501 RETURN_EGL_EVAL(disp
, ret
);
1504 EGLBoolean EGLAPIENTRY
1507 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1508 return _eglWaitClientCommon();
1511 EGLBoolean EGLAPIENTRY
1514 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1515 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1516 return _eglWaitClientCommon();
1520 EGLBoolean EGLAPIENTRY
1521 eglWaitNative(EGLint engine
)
1523 _EGLContext
*ctx
= _eglGetCurrentContext();
1529 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1531 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1533 disp
= ctx
->Resource
.Display
;
1534 mtx_lock(&disp
->Mutex
);
1536 /* let bad current context imply bad current surface */
1537 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1538 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1539 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1541 /* a valid current context implies an initialized current display */
1542 assert(disp
->Initialized
);
1544 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1546 RETURN_EGL_EVAL(disp
, ret
);
1550 EGLDisplay EGLAPIENTRY
1551 eglGetCurrentDisplay(void)
1553 _EGLContext
*ctx
= _eglGetCurrentContext();
1556 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1558 RETURN_EGL_SUCCESS(NULL
, ret
);
1562 EGLContext EGLAPIENTRY
1563 eglGetCurrentContext(void)
1565 _EGLContext
*ctx
= _eglGetCurrentContext();
1568 ret
= _eglGetContextHandle(ctx
);
1570 RETURN_EGL_SUCCESS(NULL
, ret
);
1574 EGLSurface EGLAPIENTRY
1575 eglGetCurrentSurface(EGLint readdraw
)
1577 _EGLContext
*ctx
= _eglGetCurrentContext();
1578 EGLint err
= EGL_SUCCESS
;
1582 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1585 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1589 surf
= ctx
->DrawSurface
;
1592 surf
= ctx
->ReadSurface
;
1596 err
= EGL_BAD_PARAMETER
;
1600 ret
= _eglGetSurfaceHandle(surf
);
1602 RETURN_EGL_ERROR(NULL
, err
, ret
);
1609 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1610 EGLint e
= t
->LastError
;
1611 if (!_eglIsCurrentThreadDummy())
1612 t
->LastError
= EGL_SUCCESS
;
1622 * Specify the client API to use for subsequent calls including:
1623 * eglCreateContext()
1624 * eglGetCurrentContext()
1625 * eglGetCurrentDisplay()
1626 * eglGetCurrentSurface()
1627 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1630 * See section 3.7 "Rendering Context" in the EGL specification for details.
1632 EGLBoolean EGLAPIENTRY
1633 eglBindAPI(EGLenum api
)
1637 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1639 t
= _eglGetCurrentThread();
1640 if (_eglIsCurrentThreadDummy())
1641 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1643 if (!_eglIsApiValid(api
))
1644 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1646 t
->CurrentAPI
= api
;
1648 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1653 * Return the last value set with eglBindAPI().
1658 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1661 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1662 ret
= t
->CurrentAPI
;
1664 RETURN_EGL_SUCCESS(NULL
, ret
);
1668 EGLSurface EGLAPIENTRY
1669 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1670 EGLClientBuffer buffer
, EGLConfig config
,
1671 const EGLint
*attrib_list
)
1673 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1674 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1679 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1681 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1683 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1685 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1687 RETURN_EGL_EVAL(disp
, ret
);
1691 EGLBoolean EGLAPIENTRY
1692 eglReleaseThread(void)
1694 /* unbind current contexts */
1695 if (!_eglIsCurrentThreadDummy()) {
1696 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1697 _EGLContext
*ctx
= t
->CurrentContext
;
1699 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1702 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1705 mtx_lock(&disp
->Mutex
);
1707 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1708 mtx_unlock(&disp
->Mutex
);
1712 _eglDestroyCurrentThread();
1714 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1719 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1720 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1722 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1727 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1728 if (!disp
->Extensions
.KHR_image_base
)
1729 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1730 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1731 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1732 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1733 * <ctx> must be EGL_NO_CONTEXT..."
1735 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1736 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1738 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1740 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1742 RETURN_EGL_EVAL(disp
, ret
);
1745 static EGLImage EGLAPIENTRY
1746 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1747 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1749 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1750 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1751 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1755 EGLImage EGLAPIENTRY
1756 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1757 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1759 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1761 EGLint
*int_attribs
;
1763 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1765 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1766 if (attr_list
&& !int_attribs
)
1767 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1769 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1776 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1781 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1782 if (!disp
->Extensions
.KHR_image_base
)
1783 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1785 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1787 _eglUnlinkImage(img
);
1788 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1790 RETURN_EGL_EVAL(disp
, ret
);
1793 EGLBoolean EGLAPIENTRY
1794 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1796 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1797 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1798 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1799 return _eglDestroyImageCommon(disp
, img
);
1802 static EGLBoolean EGLAPIENTRY
1803 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1805 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1806 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1807 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1808 return _eglDestroyImageCommon(disp
, img
);
1813 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1814 EGLBoolean orig_is_EGLAttrib
,
1815 EGLenum invalid_type_error
)
1817 _EGLContext
*ctx
= _eglGetCurrentContext();
1822 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1824 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1825 /* There exist two EGLAttrib variants of eglCreateSync*:
1826 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1827 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1828 * support as a proxy for EGL 1.5 support, even though that's not
1829 * entirely correct (though _eglComputeVersion does the same).
1831 * The EGL spec provides no guidance on how to handle unsupported
1832 * functions. EGL_BAD_MATCH seems reasonable.
1834 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1837 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1838 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1839 * error is generated.
1842 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1843 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1845 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1846 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1847 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1848 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1851 case EGL_SYNC_FENCE_KHR
:
1852 if (!disp
->Extensions
.KHR_fence_sync
)
1853 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1855 case EGL_SYNC_REUSABLE_KHR
:
1856 if (!disp
->Extensions
.KHR_reusable_sync
)
1857 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1859 case EGL_SYNC_CL_EVENT_KHR
:
1860 if (!disp
->Extensions
.KHR_cl_event2
)
1861 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1863 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1864 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1865 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1868 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1871 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1872 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1874 RETURN_EGL_EVAL(disp
, ret
);
1878 static EGLSync EGLAPIENTRY
1879 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1881 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1882 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1885 EGLAttrib
*attrib_list
;
1888 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1889 attrib_list
= (EGLAttrib
*) int_list
;
1891 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1892 if (err
!= EGL_SUCCESS
)
1893 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1896 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1899 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1902 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1907 static EGLSync EGLAPIENTRY
1908 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1910 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1911 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1912 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1918 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1920 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1921 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1922 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1928 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1933 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1934 assert(disp
->Extensions
.KHR_reusable_sync
||
1935 disp
->Extensions
.KHR_fence_sync
||
1936 disp
->Extensions
.ANDROID_native_fence_sync
);
1939 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1941 RETURN_EGL_EVAL(disp
, ret
);
1944 EGLBoolean EGLAPIENTRY
1945 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1947 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1948 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1949 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1950 return _eglDestroySync(disp
, s
);
1953 static EGLBoolean EGLAPIENTRY
1954 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1956 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1957 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1958 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1959 return _eglDestroySync(disp
, s
);
1964 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1965 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1970 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1971 assert(disp
->Extensions
.KHR_reusable_sync
||
1972 disp
->Extensions
.KHR_fence_sync
||
1973 disp
->Extensions
.ANDROID_native_fence_sync
);
1975 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1976 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1978 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1979 * unlocked here to allow other threads also to be able to
1980 * go into waiting state.
1983 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1984 _eglUnlockDisplay(dpy
);
1986 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1989 * 'disp' is already unlocked for reusable sync type,
1990 * so passing 'NULL' to bypass unlocking display.
1992 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1993 RETURN_EGL_EVAL(NULL
, ret
);
1995 RETURN_EGL_EVAL(disp
, ret
);
1999 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
2000 EGLint flags
, EGLTime timeout
)
2002 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2003 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2004 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2005 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2008 static EGLint EGLAPIENTRY
2009 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
2010 EGLint flags
, EGLTime timeout
)
2012 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2013 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2014 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2015 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2020 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
2022 _EGLContext
*ctx
= _eglGetCurrentContext();
2026 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2027 assert(disp
->Extensions
.KHR_wait_sync
);
2029 /* return an error if the client API doesn't support GL_OES_EGL_sync */
2030 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
2031 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
2033 /* the API doesn't allow any flags yet */
2035 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2037 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
2039 RETURN_EGL_EVAL(disp
, ret
);
2042 static EGLint EGLAPIENTRY
2043 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2045 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2046 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2047 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2048 return _eglWaitSyncCommon(disp
, s
, flags
);
2052 EGLBoolean EGLAPIENTRY
2053 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2055 /* The KHR version returns EGLint, while the core version returns
2056 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2059 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2060 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2061 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2062 return _eglWaitSyncCommon(disp
, s
, flags
);
2066 static EGLBoolean EGLAPIENTRY
2067 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2069 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2070 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2074 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2076 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2077 assert(disp
->Extensions
.KHR_reusable_sync
);
2078 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2080 RETURN_EGL_EVAL(disp
, ret
);
2085 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2090 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2091 assert(disp
->Extensions
.KHR_reusable_sync
||
2092 disp
->Extensions
.KHR_fence_sync
||
2093 disp
->Extensions
.ANDROID_native_fence_sync
);
2094 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2096 RETURN_EGL_EVAL(disp
, ret
);
2099 EGLBoolean EGLAPIENTRY
2100 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2102 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2103 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2104 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2105 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2109 static EGLBoolean EGLAPIENTRY
2110 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2112 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2113 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2117 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2120 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2123 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2125 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2127 * If any error occurs, <*value> is not modified.
2129 if (result
== EGL_FALSE
)
2136 static EGLint EGLAPIENTRY
2137 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2139 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2140 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2144 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2146 /* the spec doesn't seem to specify what happens if the fence
2147 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2150 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2151 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2153 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2154 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2155 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2157 RETURN_EGL_EVAL(disp
, ret
);
2160 static EGLBoolean EGLAPIENTRY
2161 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2162 EGLint numRects
, const EGLint
*rects
)
2164 _EGLContext
*ctx
= _eglGetCurrentContext();
2165 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2166 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2170 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2172 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2174 if (!disp
->Extensions
.NOK_swap_region
)
2175 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2177 /* surface must be bound to current context in EGL 1.4 */
2178 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2179 surf
!= ctx
->DrawSurface
)
2180 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2182 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2184 RETURN_EGL_EVAL(disp
, ret
);
2188 static EGLImage EGLAPIENTRY
2189 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2191 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2196 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2198 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2199 if (!disp
->Extensions
.MESA_drm_image
)
2200 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2202 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2203 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2205 RETURN_EGL_EVAL(disp
, ret
);
2208 static EGLBoolean EGLAPIENTRY
2209 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2210 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2212 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2213 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2217 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2219 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2220 assert(disp
->Extensions
.MESA_drm_image
);
2223 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2225 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2227 RETURN_EGL_EVAL(disp
, ret
);
2233 static EGLBoolean EGLAPIENTRY
2234 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2236 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2240 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2242 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2243 assert(disp
->Extensions
.WL_bind_wayland_display
);
2246 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2248 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2250 RETURN_EGL_EVAL(disp
, ret
);
2253 static EGLBoolean EGLAPIENTRY
2254 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2256 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2260 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2262 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2263 assert(disp
->Extensions
.WL_bind_wayland_display
);
2266 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2268 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2270 RETURN_EGL_EVAL(disp
, ret
);
2273 static EGLBoolean EGLAPIENTRY
2274 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2275 EGLint attribute
, EGLint
*value
)
2277 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2281 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2283 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2284 assert(disp
->Extensions
.WL_bind_wayland_display
);
2287 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2289 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2291 RETURN_EGL_EVAL(disp
, ret
);
2295 static struct wl_buffer
* EGLAPIENTRY
2296 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2298 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2301 struct wl_buffer
*ret
;
2303 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2305 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2306 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2307 RETURN_EGL_EVAL(disp
, NULL
);
2309 img
= _eglLookupImage(image
, disp
);
2312 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2314 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2316 RETURN_EGL_EVAL(disp
, ret
);
2319 static EGLBoolean EGLAPIENTRY
2320 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2321 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2323 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2324 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2328 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2330 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2332 if (!disp
->Extensions
.NV_post_sub_buffer
)
2333 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2335 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2337 RETURN_EGL_EVAL(disp
, ret
);
2340 static EGLBoolean EGLAPIENTRY
2341 eglGetSyncValuesCHROMIUM(EGLDisplay dpy
, EGLSurface surface
,
2342 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2345 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2346 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2350 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2352 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2353 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2354 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2356 if (!ust
|| !msc
|| !sbc
)
2357 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2359 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2361 RETURN_EGL_EVAL(disp
, ret
);
2364 static EGLBoolean EGLAPIENTRY
2365 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2366 EGLint
*fourcc
, EGLint
*nplanes
,
2367 EGLuint64KHR
*modifiers
)
2369 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2370 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2374 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2376 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2377 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2380 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2382 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2385 RETURN_EGL_EVAL(disp
, ret
);
2388 static EGLBoolean EGLAPIENTRY
2389 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2390 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2392 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2393 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2397 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2399 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2400 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2403 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2405 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2407 RETURN_EGL_EVAL(disp
, ret
);
2410 static EGLint EGLAPIENTRY
2411 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2414 _EGLDisplay
*disp
= NULL
;
2415 _EGLResourceType type
;
2417 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2419 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2420 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2422 if (!_eglIsCurrentThreadDummy()) {
2427 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2430 disp
= _eglLockDisplay(dpy
);
2432 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2434 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2435 if (dpy
!= (EGLDisplay
) object
)
2436 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2438 disp
->Label
= label
;
2439 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2442 switch (objectType
) {
2443 case EGL_OBJECT_CONTEXT_KHR
:
2444 type
= _EGL_RESOURCE_CONTEXT
;
2446 case EGL_OBJECT_SURFACE_KHR
:
2447 type
= _EGL_RESOURCE_SURFACE
;
2449 case EGL_OBJECT_IMAGE_KHR
:
2450 type
= _EGL_RESOURCE_IMAGE
;
2452 case EGL_OBJECT_SYNC_KHR
:
2453 type
= _EGL_RESOURCE_SYNC
;
2455 case EGL_OBJECT_STREAM_KHR
:
2457 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2460 if (_eglCheckResource(object
, type
, disp
)) {
2461 _EGLResource
*res
= (_EGLResource
*) object
;
2464 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2467 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2470 static EGLint EGLAPIENTRY
2471 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2472 const EGLAttrib
*attrib_list
)
2474 unsigned int newEnabled
;
2476 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2478 mtx_lock(_eglGlobal
.Mutex
);
2480 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2481 if (attrib_list
!= NULL
) {
2484 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2485 switch (attrib_list
[i
]) {
2486 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2487 case EGL_DEBUG_MSG_ERROR_KHR
:
2488 case EGL_DEBUG_MSG_WARN_KHR
:
2489 case EGL_DEBUG_MSG_INFO_KHR
:
2490 if (attrib_list
[i
+ 1])
2491 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2493 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2496 // On error, set the last error code, call the current
2497 // debug callback, and return the error code.
2498 mtx_unlock(_eglGlobal
.Mutex
);
2499 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2500 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2501 return EGL_BAD_ATTRIBUTE
;
2506 if (callback
!= NULL
) {
2507 _eglGlobal
.debugCallback
= callback
;
2508 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2510 _eglGlobal
.debugCallback
= NULL
;
2511 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2514 mtx_unlock(_eglGlobal
.Mutex
);
2518 static EGLBoolean EGLAPIENTRY
2519 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2521 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2523 mtx_lock(_eglGlobal
.Mutex
);
2525 switch (attribute
) {
2526 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2527 case EGL_DEBUG_MSG_ERROR_KHR
:
2528 case EGL_DEBUG_MSG_WARN_KHR
:
2529 case EGL_DEBUG_MSG_INFO_KHR
:
2530 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2535 case EGL_DEBUG_CALLBACK_KHR
:
2536 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2539 mtx_unlock(_eglGlobal
.Mutex
);
2540 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2541 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2545 mtx_unlock(_eglGlobal
.Mutex
);
2550 _eglFunctionCompare(const void *key
, const void *elem
)
2552 const char *procname
= key
;
2553 const struct _egl_entrypoint
*entrypoint
= elem
;
2554 return strcmp(procname
, entrypoint
->name
);
2557 static EGLBoolean EGLAPIENTRY
2558 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2559 EGLint
*formats
, EGLint
*num_formats
)
2561 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2565 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2567 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2569 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2572 RETURN_EGL_EVAL(disp
, ret
);
2575 static EGLBoolean EGLAPIENTRY
2576 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2577 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2578 EGLint
*num_modifiers
)
2580 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2584 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2586 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2588 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2589 modifiers
, external_only
,
2592 RETURN_EGL_EVAL(disp
, ret
);
2595 static void EGLAPIENTRY
2596 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2597 EGLGetBlobFuncANDROID get
)
2599 /* This function does not return anything so we cannot
2600 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2602 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2603 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2605 _eglUnlockDisplay(disp
);
2609 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2612 _eglUnlockDisplay(disp
);
2617 _eglError(EGL_BAD_PARAMETER
,
2618 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2619 _eglUnlockDisplay(disp
);
2623 if (disp
->BlobCacheSet
) {
2624 _eglError(EGL_BAD_PARAMETER
,
2625 "eglSetBlobCacheFuncsANDROID: functions already set");
2626 _eglUnlockDisplay(disp
);
2630 disp
->BlobCacheSet
= set
;
2631 disp
->BlobCacheGet
= get
;
2633 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2635 _eglUnlockDisplay(disp
);
2638 static EGLBoolean EGLAPIENTRY
2639 eglQueryDeviceAttribEXT(EGLDeviceEXT device
,
2643 _EGLDevice
*dev
= _eglLookupDevice(device
);
2646 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2648 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, EGL_FALSE
);
2650 ret
= _eglQueryDeviceAttribEXT(dev
, attribute
, value
);
2651 RETURN_EGL_EVAL(NULL
, ret
);
2654 static const char * EGLAPIENTRY
2655 eglQueryDeviceStringEXT(EGLDeviceEXT device
,
2658 _EGLDevice
*dev
= _eglLookupDevice(device
);
2660 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2662 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, NULL
);
2664 RETURN_EGL_EVAL(NULL
, _eglQueryDeviceStringEXT(dev
, name
));
2667 static EGLBoolean EGLAPIENTRY
2668 eglQueryDevicesEXT(EGLint max_devices
,
2669 EGLDeviceEXT
*devices
,
2670 EGLint
*num_devices
)
2674 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2675 ret
= _eglQueryDevicesEXT(max_devices
, (_EGLDevice
**) devices
,
2677 RETURN_EGL_EVAL(NULL
, ret
);
2680 static EGLBoolean EGLAPIENTRY
2681 eglQueryDisplayAttribEXT(EGLDisplay dpy
,
2685 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2688 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2689 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2691 switch (attribute
) {
2692 case EGL_DEVICE_EXT
:
2693 *value
= (EGLAttrib
) disp
->Device
;
2696 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
2698 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
2701 static char * EGLAPIENTRY
2702 eglGetDisplayDriverConfig(EGLDisplay dpy
)
2704 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2708 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2709 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2711 assert(disp
->Extensions
.MESA_query_driver
);
2713 ret
= drv
->API
.QueryDriverConfig(disp
);
2714 RETURN_EGL_EVAL(disp
, ret
);
2717 static const char * EGLAPIENTRY
2718 eglGetDisplayDriverName(EGLDisplay dpy
)
2720 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2724 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2725 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2727 assert(disp
->Extensions
.MESA_query_driver
);
2729 ret
= drv
->API
.QueryDriverName(disp
);
2730 RETURN_EGL_EVAL(disp
, ret
);
2733 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2734 eglGetProcAddress(const char *procname
)
2736 static const struct _egl_entrypoint egl_functions
[] = {
2737 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2738 #include "eglentrypoint.h"
2739 #undef EGL_ENTRYPOINT
2741 _EGLProc ret
= NULL
;
2744 RETURN_EGL_SUCCESS(NULL
, NULL
);
2746 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2748 if (strncmp(procname
, "egl", 3) == 0) {
2749 const struct _egl_entrypoint
*entrypoint
=
2751 egl_functions
, ARRAY_SIZE(egl_functions
),
2752 sizeof(egl_functions
[0]),
2753 _eglFunctionCompare
);
2755 ret
= entrypoint
->function
;
2759 ret
= _eglGetDriverProc(procname
);
2761 RETURN_EGL_SUCCESS(NULL
, ret
);
2765 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2766 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2770 *disp
= _eglLockDisplay(dpy
);
2771 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2773 _eglUnlockDisplay(*disp
);
2774 return MESA_GLINTEROP_INVALID_DISPLAY
;
2777 *drv
= (*disp
)->Driver
;
2779 *ctx
= _eglLookupContext(context
, *disp
);
2781 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2782 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2783 _eglUnlockDisplay(*disp
);
2784 return MESA_GLINTEROP_INVALID_CONTEXT
;
2787 return MESA_GLINTEROP_SUCCESS
;
2791 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2792 struct mesa_glinterop_device_info
*out
)
2799 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2800 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2803 if (drv
->API
.GLInteropQueryDeviceInfo
)
2804 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2806 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2808 _eglUnlockDisplay(disp
);
2813 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2814 struct mesa_glinterop_export_in
*in
,
2815 struct mesa_glinterop_export_out
*out
)
2822 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2823 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2826 if (drv
->API
.GLInteropExportObject
)
2827 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2829 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2831 _eglUnlockDisplay(disp
);