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 EGLint
*int_attribs
= NULL
;
345 /* Convert attributes from EGLAttrib[] to EGLint[] */
349 while (attr_list
[size
] != EGL_NONE
)
352 size
+= 1; /* add space for EGL_NONE */
354 int_attribs
= calloc(size
, sizeof(int_attribs
[0]));
358 for (i
= 0; i
< size
; i
++)
359 int_attribs
[i
] = attr_list
[i
];
366 * This is typically the first EGL function that an application calls.
367 * It associates a private _EGLDisplay object to the native display.
369 EGLDisplay EGLAPIENTRY
370 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
372 _EGLPlatformType plat
;
374 void *native_display_ptr
;
376 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
378 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
379 native_display_ptr
= (void*) nativeDisplay
;
381 plat
= _eglGetNativePlatform(native_display_ptr
);
382 disp
= _eglFindDisplay(plat
, native_display_ptr
);
383 return _eglGetDisplayHandle(disp
);
387 _eglGetPlatformDisplayCommon(EGLenum platform
, void *native_display
,
388 const EGLAttrib
*attrib_list
)
393 #ifdef HAVE_X11_PLATFORM
394 case EGL_PLATFORM_X11_EXT
:
395 disp
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
398 #ifdef HAVE_DRM_PLATFORM
399 case EGL_PLATFORM_GBM_MESA
:
400 disp
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
404 #ifdef HAVE_WAYLAND_PLATFORM
405 case EGL_PLATFORM_WAYLAND_EXT
:
406 disp
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
410 #ifdef HAVE_SURFACELESS_PLATFORM
411 case EGL_PLATFORM_SURFACELESS_MESA
:
412 disp
= _eglGetSurfacelessDisplay(native_display
, attrib_list
);
416 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
419 return _eglGetDisplayHandle(disp
);
422 static EGLDisplay EGLAPIENTRY
423 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
424 const EGLint
*int_attribs
)
426 EGLAttrib
*attrib_list
;
429 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
431 if (_eglConvertIntsToAttribs(int_attribs
, &attrib_list
) != EGL_SUCCESS
)
432 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
434 disp
= _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
439 EGLDisplay EGLAPIENTRY
440 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
441 const EGLAttrib
*attrib_list
)
443 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
444 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
448 * Copy the extension into the string and update the string pointer.
451 _eglAppendExtension(char **str
, const char *ext
)
454 size_t len
= strlen(ext
);
471 * Examine the individual extension enable/disable flags and recompute
472 * the driver's Extensions string.
475 _eglCreateExtensionsString(_EGLDisplay
*disp
)
477 #define _EGL_CHECK_EXTENSION(ext) \
479 if (disp->Extensions.ext) { \
480 _eglAppendExtension(&exts, "EGL_" #ext); \
481 assert(exts <= disp->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
485 char *exts
= disp
->ExtensionsString
;
487 /* Please keep these sorted alphabetically. */
488 _EGL_CHECK_EXTENSION(ANDROID_blob_cache
);
489 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
490 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
491 _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync
);
492 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
494 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
496 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
497 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
498 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
499 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers
);
500 _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata
);
501 _EGL_CHECK_EXTENSION(EXT_surface_SMPTE2086_metadata
);
502 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
504 _EGL_CHECK_EXTENSION(IMG_context_priority
);
506 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
507 _EGL_CHECK_EXTENSION(KHR_config_attribs
);
508 _EGL_CHECK_EXTENSION(KHR_context_flush_control
);
509 _EGL_CHECK_EXTENSION(KHR_create_context
);
510 _EGL_CHECK_EXTENSION(KHR_create_context_no_error
);
511 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
512 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
513 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
514 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
515 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
516 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
517 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
518 if (disp
->Extensions
.KHR_image_base
&& disp
->Extensions
.KHR_image_pixmap
)
519 disp
->Extensions
.KHR_image
= EGL_TRUE
;
520 _EGL_CHECK_EXTENSION(KHR_image
);
521 _EGL_CHECK_EXTENSION(KHR_image_base
);
522 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
523 _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer
);
524 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
525 _EGL_CHECK_EXTENSION(KHR_partial_update
);
526 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
527 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
528 if (disp
->Extensions
.EXT_swap_buffers_with_damage
)
529 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
530 _EGL_CHECK_EXTENSION(EXT_pixel_format_float
);
531 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
533 if (disp
->Extensions
.KHR_no_config_context
)
534 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
535 _EGL_CHECK_EXTENSION(MESA_drm_image
);
536 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
537 _EGL_CHECK_EXTENSION(MESA_query_driver
);
539 _EGL_CHECK_EXTENSION(NOK_swap_region
);
540 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
542 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
544 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
545 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
547 #undef _EGL_CHECK_EXTENSION
551 _eglCreateAPIsString(_EGLDisplay
*disp
)
553 #define addstr(str) \
555 const size_t old_len = strlen(disp->ClientAPIsString); \
556 const size_t add_len = sizeof(str); \
557 const size_t max_len = sizeof(disp->ClientAPIsString) - 1; \
558 if (old_len + add_len <= max_len) \
559 strcat(disp->ClientAPIsString, str " "); \
561 assert(!"disp->ClientAPIsString is not large enough"); \
564 if (disp
->ClientAPIs
& EGL_OPENGL_BIT
)
567 if (disp
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
568 disp
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
569 disp
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
573 if (disp
->ClientAPIs
& EGL_OPENVG_BIT
)
580 _eglComputeVersion(_EGLDisplay
*disp
)
584 if (disp
->Extensions
.KHR_fence_sync
&&
585 disp
->Extensions
.KHR_cl_event2
&&
586 disp
->Extensions
.KHR_wait_sync
&&
587 disp
->Extensions
.KHR_image_base
&&
588 disp
->Extensions
.KHR_gl_texture_2D_image
&&
589 disp
->Extensions
.KHR_gl_texture_3D_image
&&
590 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
591 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
592 disp
->Extensions
.KHR_create_context
&&
593 disp
->Extensions
.EXT_create_context_robustness
&&
594 disp
->Extensions
.KHR_get_all_proc_addresses
&&
595 disp
->Extensions
.KHR_gl_colorspace
&&
596 disp
->Extensions
.KHR_surfaceless_context
)
601 * This is typically the second EGL function that an application calls.
602 * Here we load/initialize the actual hardware driver.
604 EGLBoolean EGLAPIENTRY
605 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
607 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
609 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
612 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
614 if (!disp
->Initialized
) {
615 if (!_eglMatchDriver(disp
))
616 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
618 /* limit to APIs supported by core */
619 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
621 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
622 * classifies it as an EGL display extension, though conceptually it's an
623 * EGL client extension.
625 * From the EGL_KHR_get_all_proc_addresses spec:
627 * The EGL implementation must expose the name
628 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
629 * EGL_KHR_get_all_proc_addresses and supports
630 * EGL_EXT_client_extensions.
632 * Mesa unconditionally exposes both client extensions mentioned above,
633 * so the spec requires that each EGLDisplay unconditionally expose
634 * EGL_KHR_get_all_proc_addresses also.
636 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
638 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
639 * programs. It is driver agnostic and handled in the main EGL code.
641 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
643 _eglComputeVersion(disp
);
644 _eglCreateExtensionsString(disp
);
645 _eglCreateAPIsString(disp
);
646 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
647 "%d.%d", disp
->Version
/ 10, disp
->Version
% 10);
650 /* Update applications version of major and minor if not NULL */
651 if ((major
!= NULL
) && (minor
!= NULL
)) {
652 *major
= disp
->Version
/ 10;
653 *minor
= disp
->Version
% 10;
656 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
660 EGLBoolean EGLAPIENTRY
661 eglTerminate(EGLDisplay dpy
)
663 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
665 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
668 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
670 if (disp
->Initialized
) {
671 _EGLDriver
*drv
= disp
->Driver
;
673 drv
->API
.Terminate(drv
, disp
);
674 /* do not reset disp->Driver */
675 disp
->ClientAPIsString
[0] = 0;
676 disp
->Initialized
= EGL_FALSE
;
679 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
683 const char * EGLAPIENTRY
684 eglQueryString(EGLDisplay dpy
, EGLint name
)
689 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
690 const char *ret
= _eglGetClientExtensionString();
692 RETURN_EGL_SUCCESS(NULL
, ret
);
694 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
697 disp
= _eglLockDisplay(dpy
);
698 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
699 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
703 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
705 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
707 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
708 case EGL_CLIENT_APIS
:
709 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
711 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
716 EGLBoolean EGLAPIENTRY
717 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
718 EGLint config_size
, EGLint
*num_config
)
720 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
724 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
726 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
727 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
729 RETURN_EGL_EVAL(disp
, ret
);
733 EGLBoolean EGLAPIENTRY
734 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
735 EGLint config_size
, EGLint
*num_config
)
737 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
741 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
743 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
744 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
745 config_size
, num_config
);
747 RETURN_EGL_EVAL(disp
, ret
);
751 EGLBoolean EGLAPIENTRY
752 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
753 EGLint attribute
, EGLint
*value
)
755 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
756 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
760 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
762 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
763 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
765 RETURN_EGL_EVAL(disp
, ret
);
769 EGLContext EGLAPIENTRY
770 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
771 const EGLint
*attrib_list
)
773 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
774 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
775 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
777 _EGLContext
*context
;
780 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
782 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
784 if (config
!= EGL_NO_CONFIG_KHR
)
785 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
786 else if (!disp
->Extensions
.KHR_no_config_context
)
787 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
789 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
790 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
792 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
793 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
795 RETURN_EGL_EVAL(disp
, ret
);
799 EGLBoolean EGLAPIENTRY
800 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
802 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
803 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
807 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
809 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
810 _eglUnlinkContext(context
);
811 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
813 RETURN_EGL_EVAL(disp
, ret
);
817 EGLBoolean EGLAPIENTRY
818 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
821 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
822 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
823 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
824 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
828 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
831 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
834 /* display is allowed to be uninitialized under certain condition */
835 if (!disp
->Initialized
) {
836 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
837 ctx
!= EGL_NO_CONTEXT
)
838 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
841 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
843 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
844 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
845 if (!draw_surf
|| !read_surf
) {
846 /* From the EGL 1.4 (20130211) spec:
848 * To release the current context without assigning a new one, set ctx
849 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
851 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
852 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
854 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
855 (!read_surf
&& read
!= EGL_NO_SURFACE
))
856 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
857 if (draw_surf
|| read_surf
)
858 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
861 /* If a native window underlying either draw or read is no longer valid,
862 * an EGL_BAD_NATIVE_WINDOW error is generated.
864 if (draw_surf
&& draw_surf
->Lost
)
865 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
866 if (read_surf
&& read_surf
->Lost
)
867 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
869 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
871 RETURN_EGL_EVAL(disp
, ret
);
875 EGLBoolean EGLAPIENTRY
876 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
877 EGLint attribute
, EGLint
*value
)
879 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
880 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
884 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
886 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
887 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
889 RETURN_EGL_EVAL(disp
, ret
);
894 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
895 void *native_window
, const EGLint
*attrib_list
)
897 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
903 if (native_window
== NULL
)
904 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
906 #ifdef HAVE_SURFACELESS_PLATFORM
907 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
908 /* From the EGL_MESA_platform_surfaceless spec (v1):
910 * eglCreatePlatformWindowSurface fails when called with a <display>
911 * that belongs to the surfaceless platform. It returns
912 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
913 * justification for this unconditional failure is that the
914 * surfaceless platform has no native windows, and therefore the
915 * <native_window> parameter is always invalid.
917 * This check must occur before checking the EGLConfig, which emits
920 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
924 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
926 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
927 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
929 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
931 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
933 RETURN_EGL_EVAL(disp
, ret
);
937 EGLSurface EGLAPIENTRY
938 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
939 EGLNativeWindowType window
, const EGLint
*attrib_list
)
941 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
943 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
944 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
945 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
950 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
952 #ifdef HAVE_X11_PLATFORM
953 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
954 /* The `native_window` parameter for the X11 platform differs between
955 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
956 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
957 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
958 * `Window*`. Convert `Window*` to `Window` because that's what
959 * dri2_x11_create_window_surface() expects.
961 return (void *)(* (Window
*) native_window
);
964 return native_window
;
967 static EGLSurface EGLAPIENTRY
968 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
970 const EGLint
*attrib_list
)
972 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
974 native_window
= _fixupNativeWindow(disp
, native_window
);
976 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
977 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
982 EGLSurface EGLAPIENTRY
983 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
985 const EGLAttrib
*attrib_list
)
987 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
991 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
993 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
994 if (attrib_list
&& !int_attribs
)
995 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
997 native_window
= _fixupNativeWindow(disp
, native_window
);
998 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1005 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
1007 #ifdef HAVE_X11_PLATFORM
1008 /* The `native_pixmap` parameter for the X11 platform differs between
1009 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1010 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1011 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1012 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1013 * dri2_x11_create_pixmap_surface() expects.
1015 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
1016 return (void *)(* (Pixmap
*) native_pixmap
);
1018 return native_pixmap
;
1022 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1023 void *native_pixmap
, const EGLint
*attrib_list
)
1025 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1030 #if HAVE_SURFACELESS_PLATFORM
1031 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
1032 /* From the EGL_MESA_platform_surfaceless spec (v1):
1034 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1035 * also fails when called with a <display> that belongs to the
1036 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1037 * EGL_BAD_NATIVE_PIXMAP.
1039 * This check must occur before checking the EGLConfig, which emits
1042 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1046 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1048 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1049 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1051 if (native_pixmap
== NULL
)
1052 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1054 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1056 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1058 RETURN_EGL_EVAL(disp
, ret
);
1062 EGLSurface EGLAPIENTRY
1063 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1064 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1066 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1068 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1069 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1070 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1074 static EGLSurface EGLAPIENTRY
1075 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1076 void *native_pixmap
,
1077 const EGLint
*attrib_list
)
1079 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1081 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1082 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1083 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1088 EGLSurface EGLAPIENTRY
1089 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1090 void *native_pixmap
,
1091 const EGLAttrib
*attrib_list
)
1093 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1095 EGLint
*int_attribs
;
1097 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1099 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1100 if (attrib_list
&& !int_attribs
)
1101 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1103 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1104 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1111 EGLSurface EGLAPIENTRY
1112 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1113 const EGLint
*attrib_list
)
1115 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1116 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1121 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1122 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1124 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1125 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1127 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1128 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1130 RETURN_EGL_EVAL(disp
, ret
);
1134 EGLBoolean EGLAPIENTRY
1135 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1137 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1138 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1142 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1143 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1144 _eglUnlinkSurface(surf
);
1145 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1147 RETURN_EGL_EVAL(disp
, ret
);
1150 EGLBoolean EGLAPIENTRY
1151 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1152 EGLint attribute
, EGLint
*value
)
1154 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1155 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1159 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1160 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1161 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1163 RETURN_EGL_EVAL(disp
, ret
);
1166 EGLBoolean EGLAPIENTRY
1167 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1168 EGLint attribute
, EGLint value
)
1170 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1171 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1175 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1176 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1177 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1179 RETURN_EGL_EVAL(disp
, ret
);
1183 EGLBoolean EGLAPIENTRY
1184 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1186 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1187 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1191 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1192 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1193 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1195 RETURN_EGL_EVAL(disp
, ret
);
1199 EGLBoolean EGLAPIENTRY
1200 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1202 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1203 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1207 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1208 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1209 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1211 RETURN_EGL_EVAL(disp
, ret
);
1215 EGLBoolean EGLAPIENTRY
1216 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1218 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1219 _EGLContext
*ctx
= _eglGetCurrentContext();
1220 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1224 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1225 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1227 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1228 ctx
->Resource
.Display
!= disp
)
1229 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1231 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1232 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1234 if (surf
->Type
!= EGL_WINDOW_BIT
)
1235 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1237 interval
= CLAMP(interval
,
1238 surf
->Config
->MinSwapInterval
,
1239 surf
->Config
->MaxSwapInterval
);
1241 if (surf
->SwapInterval
!= interval
)
1242 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1247 surf
->SwapInterval
= interval
;
1249 RETURN_EGL_EVAL(disp
, ret
);
1253 EGLBoolean EGLAPIENTRY
1254 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1256 _EGLContext
*ctx
= _eglGetCurrentContext();
1257 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1258 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1262 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1263 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1265 /* surface must be bound to current context in EGL 1.4 */
1266 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1267 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1268 surf
!= ctx
->DrawSurface
)
1269 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1272 if (surf
->Type
!= EGL_WINDOW_BIT
)
1273 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1275 /* From the EGL 1.5 spec:
1277 * If eglSwapBuffers is called and the native window associated with
1278 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1282 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1284 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1286 /* EGL_KHR_partial_update
1287 * Frame boundary successfully reached,
1288 * reset damage region and reset BufferAgeRead
1291 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1292 surf
->BufferAgeRead
= EGL_FALSE
;
1295 RETURN_EGL_EVAL(disp
, ret
);
1300 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1301 EGLint
*rects
, EGLint n_rects
)
1303 _EGLContext
*ctx
= _eglGetCurrentContext();
1307 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1309 /* surface must be bound to current context in EGL 1.4 */
1310 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1311 surf
!= ctx
->DrawSurface
)
1312 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1314 if (surf
->Type
!= EGL_WINDOW_BIT
)
1315 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1317 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1318 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1320 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1322 /* EGL_KHR_partial_update
1323 * Frame boundary successfully reached,
1324 * reset damage region and reset BufferAgeRead
1327 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1328 surf
->BufferAgeRead
= EGL_FALSE
;
1331 RETURN_EGL_EVAL(disp
, ret
);
1334 static EGLBoolean EGLAPIENTRY
1335 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1336 EGLint
*rects
, EGLint n_rects
)
1338 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1339 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1340 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1341 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1344 static EGLBoolean EGLAPIENTRY
1345 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1346 EGLint
*rects
, EGLint n_rects
)
1348 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1349 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1350 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1351 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1355 * Clamp the rectangles so that they lie within the surface.
1359 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1360 EGLint
*rects
, EGLint n_rects
)
1363 EGLint surf_height
= surf
->Height
;
1364 EGLint surf_width
= surf
->Width
;
1366 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1367 EGLint x1
, y1
, x2
, y2
;
1370 x2
= rects
[i
+ 2] + x1
;
1371 y2
= rects
[i
+ 3] + y1
;
1373 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1374 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1375 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1376 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1380 static EGLBoolean EGLAPIENTRY
1381 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1382 EGLint
*rects
, EGLint n_rects
)
1384 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1385 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1386 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1387 _EGLContext
*ctx
= _eglGetCurrentContext();
1390 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1392 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1393 surf
->Type
!= EGL_WINDOW_BIT
||
1394 ctx
->DrawSurface
!= surf
||
1395 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1396 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1398 /* If the damage region is already set or
1399 * buffer age is not queried between
1400 * frame boundaries, throw bad access error
1403 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1404 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1406 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1407 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1410 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1412 RETURN_EGL_EVAL(disp
, ret
);
1415 EGLBoolean EGLAPIENTRY
1416 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1418 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1419 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1422 void *native_pixmap_ptr
;
1424 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1425 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1426 native_pixmap_ptr
= (void*) target
;
1428 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1429 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1431 RETURN_EGL_EVAL(disp
, ret
);
1436 _eglWaitClientCommon(void)
1438 _EGLContext
*ctx
= _eglGetCurrentContext();
1444 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1446 disp
= ctx
->Resource
.Display
;
1447 mtx_lock(&disp
->Mutex
);
1449 /* let bad current context imply bad current surface */
1450 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1451 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1452 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1454 /* a valid current context implies an initialized current display */
1455 assert(disp
->Initialized
);
1457 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1459 RETURN_EGL_EVAL(disp
, ret
);
1462 EGLBoolean EGLAPIENTRY
1465 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1466 return _eglWaitClientCommon();
1469 EGLBoolean EGLAPIENTRY
1472 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1473 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1474 return _eglWaitClientCommon();
1478 EGLBoolean EGLAPIENTRY
1479 eglWaitNative(EGLint engine
)
1481 _EGLContext
*ctx
= _eglGetCurrentContext();
1487 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1489 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1491 disp
= ctx
->Resource
.Display
;
1492 mtx_lock(&disp
->Mutex
);
1494 /* let bad current context imply bad current surface */
1495 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1496 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1497 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1499 /* a valid current context implies an initialized current display */
1500 assert(disp
->Initialized
);
1502 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1504 RETURN_EGL_EVAL(disp
, ret
);
1508 EGLDisplay EGLAPIENTRY
1509 eglGetCurrentDisplay(void)
1511 _EGLContext
*ctx
= _eglGetCurrentContext();
1514 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1516 RETURN_EGL_SUCCESS(NULL
, ret
);
1520 EGLContext EGLAPIENTRY
1521 eglGetCurrentContext(void)
1523 _EGLContext
*ctx
= _eglGetCurrentContext();
1526 ret
= _eglGetContextHandle(ctx
);
1528 RETURN_EGL_SUCCESS(NULL
, ret
);
1532 EGLSurface EGLAPIENTRY
1533 eglGetCurrentSurface(EGLint readdraw
)
1535 _EGLContext
*ctx
= _eglGetCurrentContext();
1536 EGLint err
= EGL_SUCCESS
;
1540 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1543 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1547 surf
= ctx
->DrawSurface
;
1550 surf
= ctx
->ReadSurface
;
1554 err
= EGL_BAD_PARAMETER
;
1558 ret
= _eglGetSurfaceHandle(surf
);
1560 RETURN_EGL_ERROR(NULL
, err
, ret
);
1567 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1568 EGLint e
= t
->LastError
;
1569 if (!_eglIsCurrentThreadDummy())
1570 t
->LastError
= EGL_SUCCESS
;
1580 * Specify the client API to use for subsequent calls including:
1581 * eglCreateContext()
1582 * eglGetCurrentContext()
1583 * eglGetCurrentDisplay()
1584 * eglGetCurrentSurface()
1585 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1588 * See section 3.7 "Rendering Context" in the EGL specification for details.
1590 EGLBoolean EGLAPIENTRY
1591 eglBindAPI(EGLenum api
)
1595 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1597 t
= _eglGetCurrentThread();
1598 if (_eglIsCurrentThreadDummy())
1599 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1601 if (!_eglIsApiValid(api
))
1602 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1604 t
->CurrentAPI
= api
;
1606 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1611 * Return the last value set with eglBindAPI().
1616 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1619 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1620 ret
= t
->CurrentAPI
;
1622 RETURN_EGL_SUCCESS(NULL
, ret
);
1626 EGLSurface EGLAPIENTRY
1627 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1628 EGLClientBuffer buffer
, EGLConfig config
,
1629 const EGLint
*attrib_list
)
1631 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1632 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1637 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1639 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1641 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1643 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1645 RETURN_EGL_EVAL(disp
, ret
);
1649 EGLBoolean EGLAPIENTRY
1650 eglReleaseThread(void)
1652 /* unbind current contexts */
1653 if (!_eglIsCurrentThreadDummy()) {
1654 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1655 _EGLContext
*ctx
= t
->CurrentContext
;
1657 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1660 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1663 mtx_lock(&disp
->Mutex
);
1665 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1666 mtx_unlock(&disp
->Mutex
);
1670 _eglDestroyCurrentThread();
1672 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1677 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1678 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1680 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1685 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1686 if (!disp
->Extensions
.KHR_image_base
)
1687 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1688 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1689 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1690 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1691 * <ctx> must be EGL_NO_CONTEXT..."
1693 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1694 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1696 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1698 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1700 RETURN_EGL_EVAL(disp
, ret
);
1703 static EGLImage EGLAPIENTRY
1704 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1705 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1707 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1708 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1709 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1713 EGLImage EGLAPIENTRY
1714 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1715 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1717 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1719 EGLint
*int_attribs
;
1721 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1723 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1724 if (attr_list
&& !int_attribs
)
1725 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1727 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1734 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1739 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1740 if (!disp
->Extensions
.KHR_image_base
)
1741 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1743 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1745 _eglUnlinkImage(img
);
1746 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1748 RETURN_EGL_EVAL(disp
, ret
);
1751 EGLBoolean EGLAPIENTRY
1752 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1754 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1755 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1756 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1757 return _eglDestroyImageCommon(disp
, img
);
1760 static EGLBoolean EGLAPIENTRY
1761 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1763 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1764 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1765 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1766 return _eglDestroyImageCommon(disp
, img
);
1771 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1772 EGLBoolean orig_is_EGLAttrib
,
1773 EGLenum invalid_type_error
)
1775 _EGLContext
*ctx
= _eglGetCurrentContext();
1780 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1782 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1783 /* There exist two EGLAttrib variants of eglCreateSync*:
1784 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1785 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1786 * support as a proxy for EGL 1.5 support, even though that's not
1787 * entirely correct (though _eglComputeVersion does the same).
1789 * The EGL spec provides no guidance on how to handle unsupported
1790 * functions. EGL_BAD_MATCH seems reasonable.
1792 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1795 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1796 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1797 * error is generated.
1800 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1801 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1803 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1804 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1805 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1806 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1809 case EGL_SYNC_FENCE_KHR
:
1810 if (!disp
->Extensions
.KHR_fence_sync
)
1811 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1813 case EGL_SYNC_REUSABLE_KHR
:
1814 if (!disp
->Extensions
.KHR_reusable_sync
)
1815 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1817 case EGL_SYNC_CL_EVENT_KHR
:
1818 if (!disp
->Extensions
.KHR_cl_event2
)
1819 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1821 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1822 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1823 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1826 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1829 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1830 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1832 RETURN_EGL_EVAL(disp
, ret
);
1836 static EGLSync EGLAPIENTRY
1837 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1839 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1840 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1843 EGLAttrib
*attrib_list
;
1846 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1847 attrib_list
= (EGLAttrib
*) int_list
;
1849 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1850 if (err
!= EGL_SUCCESS
)
1851 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1854 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1857 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1860 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1865 static EGLSync EGLAPIENTRY
1866 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1868 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1869 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1870 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1876 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1878 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1879 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1880 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1886 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1891 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1892 assert(disp
->Extensions
.KHR_reusable_sync
||
1893 disp
->Extensions
.KHR_fence_sync
||
1894 disp
->Extensions
.ANDROID_native_fence_sync
);
1897 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1899 RETURN_EGL_EVAL(disp
, ret
);
1902 EGLBoolean EGLAPIENTRY
1903 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1905 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1906 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1907 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1908 return _eglDestroySync(disp
, s
);
1911 static EGLBoolean EGLAPIENTRY
1912 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1914 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1915 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1916 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1917 return _eglDestroySync(disp
, s
);
1922 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1923 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1928 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1929 assert(disp
->Extensions
.KHR_reusable_sync
||
1930 disp
->Extensions
.KHR_fence_sync
||
1931 disp
->Extensions
.ANDROID_native_fence_sync
);
1933 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1934 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1936 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1937 * unlocked here to allow other threads also to be able to
1938 * go into waiting state.
1941 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1942 _eglUnlockDisplay(dpy
);
1944 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1947 * 'disp' is already unlocked for reusable sync type,
1948 * so passing 'NULL' to bypass unlocking display.
1950 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1951 RETURN_EGL_EVAL(NULL
, ret
);
1953 RETURN_EGL_EVAL(disp
, ret
);
1957 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
1958 EGLint flags
, EGLTime timeout
)
1960 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1961 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1962 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1963 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1966 static EGLint EGLAPIENTRY
1967 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
1968 EGLint flags
, EGLTime timeout
)
1970 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1971 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1972 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1973 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1978 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
1980 _EGLContext
*ctx
= _eglGetCurrentContext();
1984 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1985 assert(disp
->Extensions
.KHR_wait_sync
);
1987 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1988 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1989 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1991 /* the API doesn't allow any flags yet */
1993 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1995 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1997 RETURN_EGL_EVAL(disp
, ret
);
2000 static EGLint EGLAPIENTRY
2001 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2003 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2004 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2005 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2006 return _eglWaitSyncCommon(disp
, s
, flags
);
2010 EGLBoolean EGLAPIENTRY
2011 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2013 /* The KHR version returns EGLint, while the core version returns
2014 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2017 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2018 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2019 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2020 return _eglWaitSyncCommon(disp
, s
, flags
);
2024 static EGLBoolean EGLAPIENTRY
2025 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2027 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2028 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2032 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2034 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2035 assert(disp
->Extensions
.KHR_reusable_sync
);
2036 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2038 RETURN_EGL_EVAL(disp
, ret
);
2043 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2048 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2049 assert(disp
->Extensions
.KHR_reusable_sync
||
2050 disp
->Extensions
.KHR_fence_sync
||
2051 disp
->Extensions
.ANDROID_native_fence_sync
);
2052 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2054 RETURN_EGL_EVAL(disp
, ret
);
2057 EGLBoolean EGLAPIENTRY
2058 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2060 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2061 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2062 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2063 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2067 static EGLBoolean EGLAPIENTRY
2068 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2070 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2071 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2075 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2078 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2081 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2083 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2085 * If any error occurs, <*value> is not modified.
2087 if (result
== EGL_FALSE
)
2094 static EGLint EGLAPIENTRY
2095 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2097 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2098 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2102 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2104 /* the spec doesn't seem to specify what happens if the fence
2105 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2108 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2109 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2111 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2112 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2113 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2115 RETURN_EGL_EVAL(disp
, ret
);
2118 static EGLBoolean EGLAPIENTRY
2119 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2120 EGLint numRects
, const EGLint
*rects
)
2122 _EGLContext
*ctx
= _eglGetCurrentContext();
2123 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2124 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2128 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2130 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2132 if (!disp
->Extensions
.NOK_swap_region
)
2133 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2135 /* surface must be bound to current context in EGL 1.4 */
2136 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2137 surf
!= ctx
->DrawSurface
)
2138 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2140 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2142 RETURN_EGL_EVAL(disp
, ret
);
2146 static EGLImage EGLAPIENTRY
2147 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2149 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2154 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2156 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2157 if (!disp
->Extensions
.MESA_drm_image
)
2158 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2160 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2161 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2163 RETURN_EGL_EVAL(disp
, ret
);
2166 static EGLBoolean EGLAPIENTRY
2167 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2168 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2170 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2171 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2175 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2177 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2178 assert(disp
->Extensions
.MESA_drm_image
);
2181 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2183 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2185 RETURN_EGL_EVAL(disp
, ret
);
2191 static EGLBoolean EGLAPIENTRY
2192 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2194 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2198 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2200 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2201 assert(disp
->Extensions
.WL_bind_wayland_display
);
2204 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2206 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2208 RETURN_EGL_EVAL(disp
, ret
);
2211 static EGLBoolean EGLAPIENTRY
2212 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2214 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2218 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2220 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2221 assert(disp
->Extensions
.WL_bind_wayland_display
);
2224 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2226 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2228 RETURN_EGL_EVAL(disp
, ret
);
2231 static EGLBoolean EGLAPIENTRY
2232 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2233 EGLint attribute
, EGLint
*value
)
2235 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2239 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2241 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2242 assert(disp
->Extensions
.WL_bind_wayland_display
);
2245 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2247 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2249 RETURN_EGL_EVAL(disp
, ret
);
2253 static struct wl_buffer
* EGLAPIENTRY
2254 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2256 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2259 struct wl_buffer
*ret
;
2261 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2263 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2264 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2265 RETURN_EGL_EVAL(disp
, NULL
);
2267 img
= _eglLookupImage(image
, disp
);
2270 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2272 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2274 RETURN_EGL_EVAL(disp
, ret
);
2277 static EGLBoolean EGLAPIENTRY
2278 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2279 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2281 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2282 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2286 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2288 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2290 if (!disp
->Extensions
.NV_post_sub_buffer
)
2291 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2293 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2295 RETURN_EGL_EVAL(disp
, ret
);
2298 static EGLBoolean EGLAPIENTRY
2299 eglGetSyncValuesCHROMIUM(EGLDisplay dpy
, EGLSurface surface
,
2300 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2303 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2304 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2308 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2310 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2311 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2312 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2314 if (!ust
|| !msc
|| !sbc
)
2315 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2317 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2319 RETURN_EGL_EVAL(disp
, ret
);
2322 static EGLBoolean EGLAPIENTRY
2323 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2324 EGLint
*fourcc
, EGLint
*nplanes
,
2325 EGLuint64KHR
*modifiers
)
2327 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2328 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2332 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2334 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2335 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2338 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2340 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2343 RETURN_EGL_EVAL(disp
, ret
);
2346 static EGLBoolean EGLAPIENTRY
2347 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2348 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2350 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2351 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2355 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2357 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2358 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2361 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2363 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2365 RETURN_EGL_EVAL(disp
, ret
);
2368 static EGLint EGLAPIENTRY
2369 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2372 _EGLDisplay
*disp
= NULL
;
2373 _EGLResourceType type
;
2375 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2377 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2378 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2380 if (!_eglIsCurrentThreadDummy()) {
2385 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2388 disp
= _eglLockDisplay(dpy
);
2390 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2392 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2393 if (dpy
!= (EGLDisplay
) object
)
2394 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2396 disp
->Label
= label
;
2397 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2400 switch (objectType
) {
2401 case EGL_OBJECT_CONTEXT_KHR
:
2402 type
= _EGL_RESOURCE_CONTEXT
;
2404 case EGL_OBJECT_SURFACE_KHR
:
2405 type
= _EGL_RESOURCE_SURFACE
;
2407 case EGL_OBJECT_IMAGE_KHR
:
2408 type
= _EGL_RESOURCE_IMAGE
;
2410 case EGL_OBJECT_SYNC_KHR
:
2411 type
= _EGL_RESOURCE_SYNC
;
2413 case EGL_OBJECT_STREAM_KHR
:
2415 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2418 if (_eglCheckResource(object
, type
, disp
)) {
2419 _EGLResource
*res
= (_EGLResource
*) object
;
2422 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2425 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2428 static EGLint EGLAPIENTRY
2429 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2430 const EGLAttrib
*attrib_list
)
2432 unsigned int newEnabled
;
2434 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2436 mtx_lock(_eglGlobal
.Mutex
);
2438 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2439 if (attrib_list
!= NULL
) {
2442 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2443 switch (attrib_list
[i
]) {
2444 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2445 case EGL_DEBUG_MSG_ERROR_KHR
:
2446 case EGL_DEBUG_MSG_WARN_KHR
:
2447 case EGL_DEBUG_MSG_INFO_KHR
:
2448 if (attrib_list
[i
+ 1])
2449 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2451 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2454 // On error, set the last error code, call the current
2455 // debug callback, and return the error code.
2456 mtx_unlock(_eglGlobal
.Mutex
);
2457 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2458 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2459 return EGL_BAD_ATTRIBUTE
;
2464 if (callback
!= NULL
) {
2465 _eglGlobal
.debugCallback
= callback
;
2466 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2468 _eglGlobal
.debugCallback
= NULL
;
2469 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2472 mtx_unlock(_eglGlobal
.Mutex
);
2476 static EGLBoolean EGLAPIENTRY
2477 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2479 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2481 mtx_lock(_eglGlobal
.Mutex
);
2483 switch (attribute
) {
2484 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2485 case EGL_DEBUG_MSG_ERROR_KHR
:
2486 case EGL_DEBUG_MSG_WARN_KHR
:
2487 case EGL_DEBUG_MSG_INFO_KHR
:
2488 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2493 case EGL_DEBUG_CALLBACK_KHR
:
2494 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2497 mtx_unlock(_eglGlobal
.Mutex
);
2498 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2499 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2503 mtx_unlock(_eglGlobal
.Mutex
);
2508 _eglFunctionCompare(const void *key
, const void *elem
)
2510 const char *procname
= key
;
2511 const struct _egl_entrypoint
*entrypoint
= elem
;
2512 return strcmp(procname
, entrypoint
->name
);
2515 static EGLBoolean EGLAPIENTRY
2516 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2517 EGLint
*formats
, EGLint
*num_formats
)
2519 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2523 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2525 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2527 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2530 RETURN_EGL_EVAL(disp
, ret
);
2533 static EGLBoolean EGLAPIENTRY
2534 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2535 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2536 EGLint
*num_modifiers
)
2538 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2542 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2544 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2546 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2547 modifiers
, external_only
,
2550 RETURN_EGL_EVAL(disp
, ret
);
2553 static void EGLAPIENTRY
2554 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2555 EGLGetBlobFuncANDROID get
)
2557 /* This function does not return anything so we cannot
2558 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2560 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2561 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2563 _eglUnlockDisplay(disp
);
2567 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2570 _eglUnlockDisplay(disp
);
2575 _eglError(EGL_BAD_PARAMETER
,
2576 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2577 _eglUnlockDisplay(disp
);
2581 if (disp
->BlobCacheSet
) {
2582 _eglError(EGL_BAD_PARAMETER
,
2583 "eglSetBlobCacheFuncsANDROID: functions already set");
2584 _eglUnlockDisplay(disp
);
2588 disp
->BlobCacheSet
= set
;
2589 disp
->BlobCacheGet
= get
;
2591 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2593 _eglUnlockDisplay(disp
);
2596 static EGLBoolean EGLAPIENTRY
2597 eglQueryDeviceAttribEXT(EGLDeviceEXT device
,
2601 _EGLDevice
*dev
= _eglLookupDevice(device
);
2604 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2606 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, EGL_FALSE
);
2608 ret
= _eglQueryDeviceAttribEXT(dev
, attribute
, value
);
2609 RETURN_EGL_EVAL(NULL
, ret
);
2612 static const char * EGLAPIENTRY
2613 eglQueryDeviceStringEXT(EGLDeviceEXT device
,
2616 _EGLDevice
*dev
= _eglLookupDevice(device
);
2618 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2620 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, NULL
);
2622 RETURN_EGL_EVAL(NULL
, _eglQueryDeviceStringEXT(dev
, name
));
2625 static EGLBoolean EGLAPIENTRY
2626 eglQueryDevicesEXT(EGLint max_devices
,
2627 EGLDeviceEXT
*devices
,
2628 EGLint
*num_devices
)
2632 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2633 ret
= _eglQueryDevicesEXT(max_devices
, (_EGLDevice
**) devices
,
2635 RETURN_EGL_EVAL(NULL
, ret
);
2638 static EGLBoolean EGLAPIENTRY
2639 eglQueryDisplayAttribEXT(EGLDisplay dpy
,
2643 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2646 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2647 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2649 switch (attribute
) {
2650 case EGL_DEVICE_EXT
:
2651 *value
= (EGLAttrib
) disp
->Device
;
2654 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
2656 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
2659 static char * EGLAPIENTRY
2660 eglGetDisplayDriverConfig(EGLDisplay dpy
)
2662 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2666 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2667 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2669 assert(disp
->Extensions
.MESA_query_driver
);
2671 ret
= drv
->API
.QueryDriverConfig(disp
);
2672 RETURN_EGL_EVAL(disp
, ret
);
2675 static const char * EGLAPIENTRY
2676 eglGetDisplayDriverName(EGLDisplay dpy
)
2678 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2682 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2683 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2685 assert(disp
->Extensions
.MESA_query_driver
);
2687 ret
= drv
->API
.QueryDriverName(disp
);
2688 RETURN_EGL_EVAL(disp
, ret
);
2691 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2692 eglGetProcAddress(const char *procname
)
2694 static const struct _egl_entrypoint egl_functions
[] = {
2695 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2696 #include "eglentrypoint.h"
2697 #undef EGL_ENTRYPOINT
2699 _EGLProc ret
= NULL
;
2702 RETURN_EGL_SUCCESS(NULL
, NULL
);
2704 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2706 if (strncmp(procname
, "egl", 3) == 0) {
2707 const struct _egl_entrypoint
*entrypoint
=
2709 egl_functions
, ARRAY_SIZE(egl_functions
),
2710 sizeof(egl_functions
[0]),
2711 _eglFunctionCompare
);
2713 ret
= entrypoint
->function
;
2717 ret
= _eglGetDriverProc(procname
);
2719 RETURN_EGL_SUCCESS(NULL
, ret
);
2723 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2724 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2728 *disp
= _eglLockDisplay(dpy
);
2729 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2731 _eglUnlockDisplay(*disp
);
2732 return MESA_GLINTEROP_INVALID_DISPLAY
;
2735 *drv
= (*disp
)->Driver
;
2737 *ctx
= _eglLookupContext(context
, *disp
);
2739 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2740 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2741 _eglUnlockDisplay(*disp
);
2742 return MESA_GLINTEROP_INVALID_CONTEXT
;
2745 return MESA_GLINTEROP_SUCCESS
;
2749 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2750 struct mesa_glinterop_device_info
*out
)
2757 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2758 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2761 if (drv
->API
.GLInteropQueryDeviceInfo
)
2762 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2764 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2766 _eglUnlockDisplay(disp
);
2771 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2772 struct mesa_glinterop_export_in
*in
,
2773 struct mesa_glinterop_export_out
*out
)
2780 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2781 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2784 if (drv
->API
.GLInteropExportObject
)
2785 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2787 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2789 _eglUnlockDisplay(disp
);