1 /**************************************************************************
3 * Copyright 2008 VMware, Inc.
4 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5 * Copyright 2010-2011 LunarG, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
32 * Public EGL API entrypoints
34 * Generally, we use the EGLDisplay parameter as a key to lookup the
35 * appropriate device driver handle, then jump though the driver's
36 * dispatch table to handle the function.
38 * That allows us the option of supporting multiple, simultaneous,
39 * heterogeneous hardware devices in the future.
41 * The EGLDisplay, EGLConfig, EGLContext and EGLSurface types are
42 * opaque handles. Internal objects are linked to a display to
45 * For each public API entry point, the opaque handles are looked up
46 * before being dispatched to the drivers. When it fails to look up
56 * is generated and the driver function is not called. An
57 * uninitialized EGLDisplay has no driver associated with it. When
58 * such display is detected,
64 * Some of the entry points use current display, context, or surface
65 * implicitly. For such entry points, the implicit objects are also
66 * checked before calling the driver function. Other than the
67 * errors listed above,
69 * EGL_BAD_CURRENT_SURFACE
71 * may also be generated.
73 * Notes on naming conventions:
75 * eglFooBar - public EGL function
76 * EGL_FOO_BAR - public EGL token
77 * EGLDatatype - public EGL datatype
79 * _eglFooBar - private EGL function
80 * _EGLDatatype - private EGL datatype, typedef'd struct
81 * _egl_struct - private EGL struct, non-typedef'd
95 #include "c99_compat.h"
96 #include "c11/threads.h"
97 #include "util/macros.h"
100 #include "egldefines.h"
101 #include "eglglobals.h"
102 #include "eglcontext.h"
103 #include "egldisplay.h"
104 #include "egltypedefs.h"
105 #include "eglcurrent.h"
106 #include "egldevice.h"
107 #include "egldriver.h"
108 #include "eglsurface.h"
109 #include "eglconfig.h"
110 #include "eglimage.h"
113 #include "GL/mesa_glinterop.h"
116 * Macros to help return an API entrypoint.
118 * These macros will unlock the display and record the error code.
120 #define RETURN_EGL_ERROR(disp, err, ret) \
123 _eglUnlockDisplay(disp); \
124 /* EGL error codes are non-zero */ \
126 _eglError(err, __func__); \
130 #define RETURN_EGL_SUCCESS(disp, ret) \
131 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
133 /* record EGL_SUCCESS only when ret evaluates to true */
134 #define RETURN_EGL_EVAL(disp, ret) \
135 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
139 * A bunch of macros and checks to simplify error checking.
142 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
144 drv = _eglCheckDisplay(disp, __func__); \
146 RETURN_EGL_ERROR(disp, 0, ret); \
149 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
151 drv = _eglCheck ## type(disp, obj, __func__); \
153 RETURN_EGL_ERROR(disp, 0, ret); \
156 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
157 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
159 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
160 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
162 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
163 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
165 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
166 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
169 struct _egl_entrypoint
{
175 static inline _EGLDriver
*
176 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
179 _eglError(EGL_BAD_DISPLAY
, msg
);
182 if (!disp
->Initialized
) {
183 _eglError(EGL_NOT_INITIALIZED
, msg
);
190 static inline _EGLDriver
*
191 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
193 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
197 _eglError(EGL_BAD_SURFACE
, msg
);
204 static inline _EGLDriver
*
205 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
207 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
211 _eglError(EGL_BAD_CONTEXT
, msg
);
218 static inline _EGLDriver
*
219 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
221 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
225 _eglError(EGL_BAD_CONFIG
, msg
);
232 static inline _EGLDriver
*
233 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
235 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
239 _eglError(EGL_BAD_PARAMETER
, msg
);
247 * Lookup and lock a display.
249 static inline _EGLDisplay
*
250 _eglLockDisplay(EGLDisplay dpy
)
252 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
254 mtx_lock(&disp
->Mutex
);
263 _eglUnlockDisplay(_EGLDisplay
*disp
)
265 mtx_unlock(&disp
->Mutex
);
269 _eglSetFuncName(const char *funcName
, _EGLDisplay
*disp
, EGLenum objectType
, _EGLResource
*object
)
271 _EGLThreadInfo
*thr
= _eglGetCurrentThread();
272 if (!_eglIsCurrentThreadDummy()) {
273 thr
->CurrentFuncName
= funcName
;
274 thr
->CurrentObjectLabel
= NULL
;
276 if (objectType
== EGL_OBJECT_THREAD_KHR
)
277 thr
->CurrentObjectLabel
= thr
->Label
;
278 else if (objectType
== EGL_OBJECT_DISPLAY_KHR
&& disp
)
279 thr
->CurrentObjectLabel
= disp
->Label
;
281 thr
->CurrentObjectLabel
= object
->Label
;
286 _eglDebugReport(EGL_BAD_ALLOC
, funcName
, EGL_DEBUG_MSG_CRITICAL_KHR
, NULL
);
290 #define _EGL_FUNC_START(disp, objectType, object, ret) \
292 if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \
294 _eglUnlockDisplay(disp); \
300 * Convert an attribute list from EGLint[] to EGLAttrib[].
302 * Return an EGL error code. The output parameter out_attrib_list is modified
306 _eglConvertIntsToAttribs(const EGLint
*int_list
, EGLAttrib
**out_attrib_list
)
309 EGLAttrib
*attrib_list
;
312 while (int_list
[2*len
] != EGL_NONE
)
317 *out_attrib_list
= NULL
;
321 if (2*len
+ 1 > SIZE_MAX
/ sizeof(EGLAttrib
))
322 return EGL_BAD_ALLOC
;
324 attrib_list
= malloc((2*len
+ 1) * sizeof(EGLAttrib
));
326 return EGL_BAD_ALLOC
;
328 for (size_t i
= 0; i
< len
; ++i
) {
329 attrib_list
[2*i
+ 0] = int_list
[2*i
+ 0];
330 attrib_list
[2*i
+ 1] = int_list
[2*i
+ 1];
333 attrib_list
[2*len
] = EGL_NONE
;
335 *out_attrib_list
= attrib_list
;
341 _eglConvertAttribsToInt(const EGLAttrib
*attr_list
)
343 size_t size
= _eglNumAttribs(attr_list
);
344 EGLint
*int_attribs
= NULL
;
346 /* Convert attributes from EGLAttrib[] to EGLint[] */
348 int_attribs
= calloc(size
, sizeof(int_attribs
[0]));
352 for (size_t i
= 0; i
< size
; i
++)
353 int_attribs
[i
] = attr_list
[i
];
360 * This is typically the first EGL function that an application calls.
361 * It associates a private _EGLDisplay object to the native display.
363 EGLDisplay EGLAPIENTRY
364 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
366 _EGLPlatformType plat
;
368 void *native_display_ptr
;
370 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
372 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
373 native_display_ptr
= (void*) nativeDisplay
;
375 plat
= _eglGetNativePlatform(native_display_ptr
);
376 disp
= _eglFindDisplay(plat
, native_display_ptr
, NULL
);
377 return _eglGetDisplayHandle(disp
);
381 _eglGetPlatformDisplayCommon(EGLenum platform
, void *native_display
,
382 const EGLAttrib
*attrib_list
)
387 #ifdef HAVE_X11_PLATFORM
388 case EGL_PLATFORM_X11_EXT
:
389 disp
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
392 #ifdef HAVE_DRM_PLATFORM
393 case EGL_PLATFORM_GBM_MESA
:
394 disp
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
398 #ifdef HAVE_WAYLAND_PLATFORM
399 case EGL_PLATFORM_WAYLAND_EXT
:
400 disp
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
404 #ifdef HAVE_SURFACELESS_PLATFORM
405 case EGL_PLATFORM_SURFACELESS_MESA
:
406 disp
= _eglGetSurfacelessDisplay(native_display
, attrib_list
);
409 #ifdef HAVE_ANDROID_PLATFORM
410 case EGL_PLATFORM_ANDROID_KHR
:
411 disp
= _eglGetAndroidDisplay(native_display
, attrib_list
);
414 case EGL_PLATFORM_DEVICE_EXT
:
415 disp
= _eglGetDeviceDisplay(native_display
, attrib_list
);
418 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
421 return _eglGetDisplayHandle(disp
);
424 static EGLDisplay EGLAPIENTRY
425 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
426 const EGLint
*int_attribs
)
428 EGLAttrib
*attrib_list
;
431 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
433 if (_eglConvertIntsToAttribs(int_attribs
, &attrib_list
) != EGL_SUCCESS
)
434 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
436 disp
= _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
441 EGLDisplay EGLAPIENTRY
442 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
443 const EGLAttrib
*attrib_list
)
445 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
446 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
450 * Copy the extension into the string and update the string pointer.
453 _eglAppendExtension(char **str
, const char *ext
)
456 size_t len
= strlen(ext
);
473 * Examine the individual extension enable/disable flags and recompute
474 * the driver's Extensions string.
477 _eglCreateExtensionsString(_EGLDisplay
*disp
)
479 #define _EGL_CHECK_EXTENSION(ext) \
481 if (disp->Extensions.ext) { \
482 _eglAppendExtension(&exts, "EGL_" #ext); \
483 assert(exts <= disp->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
487 char *exts
= disp
->ExtensionsString
;
489 /* Please keep these sorted alphabetically. */
490 _EGL_CHECK_EXTENSION(ANDROID_blob_cache
);
491 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
492 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
493 _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync
);
494 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
496 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
498 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
499 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
500 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
501 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers
);
502 _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata
);
503 _EGL_CHECK_EXTENSION(EXT_surface_SMPTE2086_metadata
);
504 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
506 _EGL_CHECK_EXTENSION(IMG_context_priority
);
508 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
509 _EGL_CHECK_EXTENSION(KHR_config_attribs
);
510 _EGL_CHECK_EXTENSION(KHR_context_flush_control
);
511 _EGL_CHECK_EXTENSION(KHR_create_context
);
512 _EGL_CHECK_EXTENSION(KHR_create_context_no_error
);
513 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
514 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
515 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
516 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
517 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
518 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
519 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
520 if (disp
->Extensions
.KHR_image_base
&& disp
->Extensions
.KHR_image_pixmap
)
521 disp
->Extensions
.KHR_image
= EGL_TRUE
;
522 _EGL_CHECK_EXTENSION(KHR_image
);
523 _EGL_CHECK_EXTENSION(KHR_image_base
);
524 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
525 _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer
);
526 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
527 _EGL_CHECK_EXTENSION(KHR_partial_update
);
528 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
529 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
530 if (disp
->Extensions
.EXT_swap_buffers_with_damage
)
531 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
532 _EGL_CHECK_EXTENSION(EXT_pixel_format_float
);
533 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
535 if (disp
->Extensions
.KHR_no_config_context
)
536 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
537 _EGL_CHECK_EXTENSION(MESA_drm_image
);
538 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
539 _EGL_CHECK_EXTENSION(MESA_query_driver
);
541 _EGL_CHECK_EXTENSION(NOK_swap_region
);
542 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
544 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
546 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
547 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
549 #undef _EGL_CHECK_EXTENSION
553 _eglCreateAPIsString(_EGLDisplay
*disp
)
555 #define addstr(str) \
557 const size_t old_len = strlen(disp->ClientAPIsString); \
558 const size_t add_len = sizeof(str); \
559 const size_t max_len = sizeof(disp->ClientAPIsString) - 1; \
560 if (old_len + add_len <= max_len) \
561 strcat(disp->ClientAPIsString, str " "); \
563 assert(!"disp->ClientAPIsString is not large enough"); \
566 if (disp
->ClientAPIs
& EGL_OPENGL_BIT
)
569 if (disp
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
570 disp
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
571 disp
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
575 if (disp
->ClientAPIs
& EGL_OPENVG_BIT
)
582 _eglComputeVersion(_EGLDisplay
*disp
)
586 if (disp
->Extensions
.KHR_fence_sync
&&
587 disp
->Extensions
.KHR_cl_event2
&&
588 disp
->Extensions
.KHR_wait_sync
&&
589 disp
->Extensions
.KHR_image_base
&&
590 disp
->Extensions
.KHR_gl_texture_2D_image
&&
591 disp
->Extensions
.KHR_gl_texture_3D_image
&&
592 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
593 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
594 disp
->Extensions
.KHR_create_context
&&
595 disp
->Extensions
.EXT_create_context_robustness
&&
596 disp
->Extensions
.KHR_get_all_proc_addresses
&&
597 disp
->Extensions
.KHR_gl_colorspace
&&
598 disp
->Extensions
.KHR_surfaceless_context
)
603 * This is typically the second EGL function that an application calls.
604 * Here we load/initialize the actual hardware driver.
606 EGLBoolean EGLAPIENTRY
607 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
609 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
611 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
614 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
616 if (!disp
->Initialized
) {
617 if (!_eglMatchDriver(disp
))
618 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
620 /* limit to APIs supported by core */
621 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
623 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
624 * classifies it as an EGL display extension, though conceptually it's an
625 * EGL client extension.
627 * From the EGL_KHR_get_all_proc_addresses spec:
629 * The EGL implementation must expose the name
630 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
631 * EGL_KHR_get_all_proc_addresses and supports
632 * EGL_EXT_client_extensions.
634 * Mesa unconditionally exposes both client extensions mentioned above,
635 * so the spec requires that each EGLDisplay unconditionally expose
636 * EGL_KHR_get_all_proc_addresses also.
638 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
640 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
641 * programs. It is driver agnostic and handled in the main EGL code.
643 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
645 _eglComputeVersion(disp
);
646 _eglCreateExtensionsString(disp
);
647 _eglCreateAPIsString(disp
);
648 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
649 "%d.%d", disp
->Version
/ 10, disp
->Version
% 10);
652 /* Update applications version of major and minor if not NULL */
653 if ((major
!= NULL
) && (minor
!= NULL
)) {
654 *major
= disp
->Version
/ 10;
655 *minor
= disp
->Version
% 10;
658 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
662 EGLBoolean EGLAPIENTRY
663 eglTerminate(EGLDisplay dpy
)
665 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
667 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
670 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
672 if (disp
->Initialized
) {
673 _EGLDriver
*drv
= disp
->Driver
;
675 drv
->API
.Terminate(drv
, disp
);
676 /* do not reset disp->Driver */
677 disp
->ClientAPIsString
[0] = 0;
678 disp
->Initialized
= EGL_FALSE
;
680 /* Reset blob cache funcs on terminate. */
681 disp
->BlobCacheSet
= NULL
;
682 disp
->BlobCacheGet
= NULL
;
685 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
689 const char * EGLAPIENTRY
690 eglQueryString(EGLDisplay dpy
, EGLint name
)
695 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
696 const char *ret
= _eglGetClientExtensionString();
698 RETURN_EGL_SUCCESS(NULL
, ret
);
700 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
703 disp
= _eglLockDisplay(dpy
);
704 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
705 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
709 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
711 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
713 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
714 case EGL_CLIENT_APIS
:
715 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
717 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
722 EGLBoolean EGLAPIENTRY
723 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
724 EGLint config_size
, EGLint
*num_config
)
726 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
730 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
732 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
735 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
737 ret
= _eglGetConfigs(drv
, disp
, configs
, config_size
, num_config
);
739 RETURN_EGL_EVAL(disp
, ret
);
743 EGLBoolean EGLAPIENTRY
744 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
745 EGLint config_size
, EGLint
*num_config
)
747 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
751 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
753 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
756 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
758 ret
= _eglChooseConfig(drv
, disp
, attrib_list
, configs
,
759 config_size
, num_config
);
761 RETURN_EGL_EVAL(disp
, ret
);
765 EGLBoolean EGLAPIENTRY
766 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
767 EGLint attribute
, EGLint
*value
)
769 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
770 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
774 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
776 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
778 ret
= _eglGetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
780 RETURN_EGL_EVAL(disp
, ret
);
784 EGLContext EGLAPIENTRY
785 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
786 const EGLint
*attrib_list
)
788 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
789 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
790 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
792 _EGLContext
*context
;
795 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
797 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
799 if (config
!= EGL_NO_CONFIG_KHR
)
800 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
801 else if (!disp
->Extensions
.KHR_no_config_context
)
802 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
804 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
805 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
807 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
808 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
810 RETURN_EGL_EVAL(disp
, ret
);
814 EGLBoolean EGLAPIENTRY
815 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
817 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
818 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
822 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
824 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
825 _eglUnlinkContext(context
);
826 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
828 RETURN_EGL_EVAL(disp
, ret
);
832 EGLBoolean EGLAPIENTRY
833 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
836 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
837 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
838 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
839 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
843 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
846 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
849 /* display is allowed to be uninitialized under certain condition */
850 if (!disp
->Initialized
) {
851 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
852 ctx
!= EGL_NO_CONTEXT
)
853 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
856 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
858 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
859 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
860 if (!draw_surf
|| !read_surf
) {
861 /* From the EGL 1.4 (20130211) spec:
863 * To release the current context without assigning a new one, set ctx
864 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
866 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
867 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
869 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
870 (!read_surf
&& read
!= EGL_NO_SURFACE
))
871 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
872 if (draw_surf
|| read_surf
)
873 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
876 /* If a native window underlying either draw or read is no longer valid,
877 * an EGL_BAD_NATIVE_WINDOW error is generated.
879 if (draw_surf
&& draw_surf
->Lost
)
880 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
881 if (read_surf
&& read_surf
->Lost
)
882 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
884 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
886 RETURN_EGL_EVAL(disp
, ret
);
890 EGLBoolean EGLAPIENTRY
891 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
892 EGLint attribute
, EGLint
*value
)
894 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
895 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
899 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
901 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
903 ret
= _eglQueryContext(drv
, disp
, context
, attribute
, value
);
905 RETURN_EGL_EVAL(disp
, ret
);
909 /* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says
910 * that if native_surface was already used to create a window or pixmap, we
911 * can't create a new one. This is what this function checks for.
914 _eglNativeSurfaceAlreadyUsed(_EGLDisplay
*disp
, void *native_surface
)
918 list
= disp
->ResourceLists
[_EGL_RESOURCE_SURFACE
];
920 _EGLSurface
*surf
= (_EGLSurface
*) list
;
924 if (surf
->Type
== EGL_PBUFFER_BIT
)
927 if (surf
->NativeSurface
== native_surface
)
936 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
937 void *native_window
, const EGLint
*attrib_list
)
939 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
945 if (native_window
== NULL
)
946 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
948 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
949 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
950 /* From the EGL_MESA_platform_surfaceless spec (v1):
952 * eglCreatePlatformWindowSurface fails when called with a <display>
953 * that belongs to the surfaceless platform. It returns
954 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
955 * justification for this unconditional failure is that the
956 * surfaceless platform has no native windows, and therefore the
957 * <native_window> parameter is always invalid.
959 * This check must occur before checking the EGLConfig, which emits
962 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
965 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
967 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
968 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
970 if (_eglNativeSurfaceAlreadyUsed(disp
, native_window
))
971 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
973 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
975 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
977 RETURN_EGL_EVAL(disp
, ret
);
981 EGLSurface EGLAPIENTRY
982 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
983 EGLNativeWindowType window
, const EGLint
*attrib_list
)
985 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
987 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
988 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
989 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
994 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
996 #ifdef HAVE_X11_PLATFORM
997 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
998 /* The `native_window` parameter for the X11 platform differs between
999 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1000 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
1001 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
1002 * `Window*`. Convert `Window*` to `Window` because that's what
1003 * dri2_x11_create_window_surface() expects.
1005 return (void *)(* (Window
*) native_window
);
1008 return native_window
;
1011 static EGLSurface EGLAPIENTRY
1012 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1013 void *native_window
,
1014 const EGLint
*attrib_list
)
1016 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1018 native_window
= _fixupNativeWindow(disp
, native_window
);
1020 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1021 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1026 EGLSurface EGLAPIENTRY
1027 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
1028 void *native_window
,
1029 const EGLAttrib
*attrib_list
)
1031 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1033 EGLint
*int_attribs
;
1035 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1037 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1038 if (attrib_list
&& !int_attribs
)
1039 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1041 native_window
= _fixupNativeWindow(disp
, native_window
);
1042 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1049 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
1051 #ifdef HAVE_X11_PLATFORM
1052 /* The `native_pixmap` parameter for the X11 platform differs between
1053 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1054 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1055 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1056 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1057 * dri2_x11_create_pixmap_surface() expects.
1059 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
1060 return (void *)(* (Pixmap
*) native_pixmap
);
1062 return native_pixmap
;
1066 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1067 void *native_pixmap
, const EGLint
*attrib_list
)
1069 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1074 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
1075 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
1076 /* From the EGL_MESA_platform_surfaceless spec (v1):
1078 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1079 * also fails when called with a <display> that belongs to the
1080 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1081 * EGL_BAD_NATIVE_PIXMAP.
1083 * This check must occur before checking the EGLConfig, which emits
1086 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1089 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1091 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1092 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1094 if (native_pixmap
== NULL
)
1095 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1097 if (_eglNativeSurfaceAlreadyUsed(disp
, native_pixmap
))
1098 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1100 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1102 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1104 RETURN_EGL_EVAL(disp
, ret
);
1108 EGLSurface EGLAPIENTRY
1109 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1110 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1112 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1114 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1115 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1116 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1120 static EGLSurface EGLAPIENTRY
1121 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1122 void *native_pixmap
,
1123 const EGLint
*attrib_list
)
1125 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1127 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1128 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1129 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1134 EGLSurface EGLAPIENTRY
1135 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1136 void *native_pixmap
,
1137 const EGLAttrib
*attrib_list
)
1139 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1141 EGLint
*int_attribs
;
1143 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1145 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1146 if (attrib_list
&& !int_attribs
)
1147 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1149 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1150 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1157 EGLSurface EGLAPIENTRY
1158 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1159 const EGLint
*attrib_list
)
1161 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1162 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1167 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1168 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1170 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1171 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1173 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1174 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1176 RETURN_EGL_EVAL(disp
, ret
);
1180 EGLBoolean EGLAPIENTRY
1181 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1183 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1184 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1188 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1189 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1190 _eglUnlinkSurface(surf
);
1191 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1193 RETURN_EGL_EVAL(disp
, ret
);
1196 EGLBoolean EGLAPIENTRY
1197 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1198 EGLint attribute
, EGLint
*value
)
1200 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1201 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1205 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1206 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1208 if (drv
->API
.QuerySurface
)
1209 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1211 ret
= _eglQuerySurface(drv
, disp
, surf
, attribute
, value
);
1213 RETURN_EGL_EVAL(disp
, ret
);
1216 EGLBoolean EGLAPIENTRY
1217 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1218 EGLint attribute
, EGLint value
)
1220 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1221 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1225 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1226 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1228 ret
= _eglSurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1230 RETURN_EGL_EVAL(disp
, ret
);
1234 EGLBoolean EGLAPIENTRY
1235 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1237 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1238 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1242 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1243 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1244 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1246 RETURN_EGL_EVAL(disp
, ret
);
1250 EGLBoolean EGLAPIENTRY
1251 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1253 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1254 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1258 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1259 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1260 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1262 RETURN_EGL_EVAL(disp
, ret
);
1266 EGLBoolean EGLAPIENTRY
1267 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1269 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1270 _EGLContext
*ctx
= _eglGetCurrentContext();
1271 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1275 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1276 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1278 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1279 ctx
->Resource
.Display
!= disp
)
1280 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1282 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1283 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1285 if (surf
->Type
!= EGL_WINDOW_BIT
)
1286 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1288 interval
= CLAMP(interval
,
1289 surf
->Config
->MinSwapInterval
,
1290 surf
->Config
->MaxSwapInterval
);
1292 if (surf
->SwapInterval
!= interval
) {
1293 if (drv
->API
.SwapInterval
)
1294 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1296 ret
= _eglSwapInterval(drv
, disp
, surf
, interval
);
1303 surf
->SwapInterval
= interval
;
1305 RETURN_EGL_EVAL(disp
, ret
);
1309 EGLBoolean EGLAPIENTRY
1310 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1312 _EGLContext
*ctx
= _eglGetCurrentContext();
1313 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1314 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1318 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1319 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1321 /* surface must be bound to current context in EGL 1.4 */
1322 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1323 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1324 surf
!= ctx
->DrawSurface
)
1325 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1328 if (surf
->Type
!= EGL_WINDOW_BIT
)
1329 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1331 /* From the EGL 1.5 spec:
1333 * If eglSwapBuffers is called and the native window associated with
1334 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1338 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1340 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1342 /* EGL_KHR_partial_update
1343 * Frame boundary successfully reached,
1344 * reset damage region and reset BufferAgeRead
1347 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1348 surf
->BufferAgeRead
= EGL_FALSE
;
1351 RETURN_EGL_EVAL(disp
, ret
);
1356 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1357 EGLint
*rects
, EGLint n_rects
)
1359 _EGLContext
*ctx
= _eglGetCurrentContext();
1363 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1365 /* surface must be bound to current context in EGL 1.4 */
1366 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1367 surf
!= ctx
->DrawSurface
)
1368 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1370 if (surf
->Type
!= EGL_WINDOW_BIT
)
1371 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1373 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1374 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1376 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1378 /* EGL_KHR_partial_update
1379 * Frame boundary successfully reached,
1380 * reset damage region and reset BufferAgeRead
1383 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1384 surf
->BufferAgeRead
= EGL_FALSE
;
1387 RETURN_EGL_EVAL(disp
, ret
);
1390 static EGLBoolean EGLAPIENTRY
1391 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1392 EGLint
*rects
, EGLint n_rects
)
1394 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1395 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1396 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1397 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1400 static EGLBoolean EGLAPIENTRY
1401 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1402 EGLint
*rects
, EGLint n_rects
)
1404 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1405 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1406 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1407 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1411 * Clamp the rectangles so that they lie within the surface.
1415 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1416 EGLint
*rects
, EGLint n_rects
)
1419 EGLint surf_height
= surf
->Height
;
1420 EGLint surf_width
= surf
->Width
;
1422 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1423 EGLint x1
, y1
, x2
, y2
;
1426 x2
= rects
[i
+ 2] + x1
;
1427 y2
= rects
[i
+ 3] + y1
;
1429 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1430 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1431 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1432 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1436 static EGLBoolean EGLAPIENTRY
1437 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1438 EGLint
*rects
, EGLint n_rects
)
1440 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1441 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1442 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1443 _EGLContext
*ctx
= _eglGetCurrentContext();
1446 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1448 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1449 surf
->Type
!= EGL_WINDOW_BIT
||
1450 ctx
->DrawSurface
!= surf
||
1451 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1452 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1454 /* If the damage region is already set or
1455 * buffer age is not queried between
1456 * frame boundaries, throw bad access error
1459 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1460 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1462 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1463 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1466 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1468 RETURN_EGL_EVAL(disp
, ret
);
1471 EGLBoolean EGLAPIENTRY
1472 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1474 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1475 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1478 void *native_pixmap_ptr
;
1480 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1481 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1482 native_pixmap_ptr
= (void*) target
;
1484 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1485 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1487 RETURN_EGL_EVAL(disp
, ret
);
1492 _eglWaitClientCommon(void)
1494 _EGLContext
*ctx
= _eglGetCurrentContext();
1500 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1502 disp
= ctx
->Resource
.Display
;
1503 mtx_lock(&disp
->Mutex
);
1505 /* let bad current context imply bad current surface */
1506 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1507 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1508 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1510 /* a valid current context implies an initialized current display */
1511 assert(disp
->Initialized
);
1513 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1515 RETURN_EGL_EVAL(disp
, ret
);
1518 EGLBoolean EGLAPIENTRY
1521 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1522 return _eglWaitClientCommon();
1525 EGLBoolean EGLAPIENTRY
1528 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1529 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1530 return _eglWaitClientCommon();
1534 EGLBoolean EGLAPIENTRY
1535 eglWaitNative(EGLint engine
)
1537 _EGLContext
*ctx
= _eglGetCurrentContext();
1543 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1545 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1547 disp
= ctx
->Resource
.Display
;
1548 mtx_lock(&disp
->Mutex
);
1550 /* let bad current context imply bad current surface */
1551 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1552 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1553 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1555 /* a valid current context implies an initialized current display */
1556 assert(disp
->Initialized
);
1558 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1560 RETURN_EGL_EVAL(disp
, ret
);
1564 EGLDisplay EGLAPIENTRY
1565 eglGetCurrentDisplay(void)
1567 _EGLContext
*ctx
= _eglGetCurrentContext();
1570 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1572 RETURN_EGL_SUCCESS(NULL
, ret
);
1576 EGLContext EGLAPIENTRY
1577 eglGetCurrentContext(void)
1579 _EGLContext
*ctx
= _eglGetCurrentContext();
1582 ret
= _eglGetContextHandle(ctx
);
1584 RETURN_EGL_SUCCESS(NULL
, ret
);
1588 EGLSurface EGLAPIENTRY
1589 eglGetCurrentSurface(EGLint readdraw
)
1591 _EGLContext
*ctx
= _eglGetCurrentContext();
1592 EGLint err
= EGL_SUCCESS
;
1596 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1599 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1603 surf
= ctx
->DrawSurface
;
1606 surf
= ctx
->ReadSurface
;
1610 err
= EGL_BAD_PARAMETER
;
1614 ret
= _eglGetSurfaceHandle(surf
);
1616 RETURN_EGL_ERROR(NULL
, err
, ret
);
1623 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1624 EGLint e
= t
->LastError
;
1625 if (!_eglIsCurrentThreadDummy())
1626 t
->LastError
= EGL_SUCCESS
;
1636 * Specify the client API to use for subsequent calls including:
1637 * eglCreateContext()
1638 * eglGetCurrentContext()
1639 * eglGetCurrentDisplay()
1640 * eglGetCurrentSurface()
1641 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1644 * See section 3.7 "Rendering Context" in the EGL specification for details.
1646 EGLBoolean EGLAPIENTRY
1647 eglBindAPI(EGLenum api
)
1651 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1653 t
= _eglGetCurrentThread();
1654 if (_eglIsCurrentThreadDummy())
1655 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1657 if (!_eglIsApiValid(api
))
1658 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1660 t
->CurrentAPI
= api
;
1662 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1667 * Return the last value set with eglBindAPI().
1672 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1675 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1676 ret
= t
->CurrentAPI
;
1678 RETURN_EGL_SUCCESS(NULL
, ret
);
1682 EGLSurface EGLAPIENTRY
1683 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1684 EGLClientBuffer buffer
, EGLConfig config
,
1685 const EGLint
*attrib_list
)
1687 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1688 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1691 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1693 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1695 /* OpenVG is not supported */
1696 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1700 EGLBoolean EGLAPIENTRY
1701 eglReleaseThread(void)
1703 /* unbind current contexts */
1704 if (!_eglIsCurrentThreadDummy()) {
1705 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1706 _EGLContext
*ctx
= t
->CurrentContext
;
1708 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1711 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1714 mtx_lock(&disp
->Mutex
);
1716 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1717 mtx_unlock(&disp
->Mutex
);
1721 _eglDestroyCurrentThread();
1723 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1728 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1729 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1731 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1736 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1737 if (!disp
->Extensions
.KHR_image_base
)
1738 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1739 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1740 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1741 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1742 * <ctx> must be EGL_NO_CONTEXT..."
1744 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1745 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1747 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1749 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1751 RETURN_EGL_EVAL(disp
, ret
);
1754 static EGLImage EGLAPIENTRY
1755 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1756 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1758 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1759 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1760 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1764 EGLImage EGLAPIENTRY
1765 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1766 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1768 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1770 EGLint
*int_attribs
;
1772 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1774 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1775 if (attr_list
&& !int_attribs
)
1776 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1778 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1785 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1790 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1791 if (!disp
->Extensions
.KHR_image_base
)
1792 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1794 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1796 _eglUnlinkImage(img
);
1797 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1799 RETURN_EGL_EVAL(disp
, ret
);
1802 EGLBoolean EGLAPIENTRY
1803 eglDestroyImage(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
);
1811 static EGLBoolean EGLAPIENTRY
1812 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1814 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1815 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1816 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1817 return _eglDestroyImageCommon(disp
, img
);
1822 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1823 EGLBoolean orig_is_EGLAttrib
,
1824 EGLenum invalid_type_error
)
1826 _EGLContext
*ctx
= _eglGetCurrentContext();
1831 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1833 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1834 /* There exist two EGLAttrib variants of eglCreateSync*:
1835 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1836 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1837 * support as a proxy for EGL 1.5 support, even though that's not
1838 * entirely correct (though _eglComputeVersion does the same).
1840 * The EGL spec provides no guidance on how to handle unsupported
1841 * functions. EGL_BAD_MATCH seems reasonable.
1843 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1846 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1847 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1848 * error is generated.
1851 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1852 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1854 /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */
1855 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1856 (ctx
->ClientAPI
!= EGL_OPENGL_ES_API
&&
1857 ctx
->ClientAPI
!= EGL_OPENGL_API
)))
1858 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1861 case EGL_SYNC_FENCE_KHR
:
1862 if (!disp
->Extensions
.KHR_fence_sync
)
1863 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1865 case EGL_SYNC_REUSABLE_KHR
:
1866 if (!disp
->Extensions
.KHR_reusable_sync
)
1867 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1869 case EGL_SYNC_CL_EVENT_KHR
:
1870 if (!disp
->Extensions
.KHR_cl_event2
)
1871 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1873 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1874 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1875 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1878 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1881 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1882 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1884 RETURN_EGL_EVAL(disp
, ret
);
1888 static EGLSync EGLAPIENTRY
1889 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1891 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1892 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1895 EGLAttrib
*attrib_list
;
1898 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1899 attrib_list
= (EGLAttrib
*) int_list
;
1901 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1902 if (err
!= EGL_SUCCESS
)
1903 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1906 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1909 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1912 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1917 static EGLSync EGLAPIENTRY
1918 eglCreateSync64KHR(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 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1930 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1931 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1932 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1938 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1943 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1944 assert(disp
->Extensions
.KHR_reusable_sync
||
1945 disp
->Extensions
.KHR_fence_sync
||
1946 disp
->Extensions
.ANDROID_native_fence_sync
);
1949 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1951 RETURN_EGL_EVAL(disp
, ret
);
1954 EGLBoolean EGLAPIENTRY
1955 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1957 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1958 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1959 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1960 return _eglDestroySync(disp
, s
);
1963 static EGLBoolean EGLAPIENTRY
1964 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1966 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1967 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1968 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1969 return _eglDestroySync(disp
, s
);
1974 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1975 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1980 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1981 assert(disp
->Extensions
.KHR_reusable_sync
||
1982 disp
->Extensions
.KHR_fence_sync
||
1983 disp
->Extensions
.ANDROID_native_fence_sync
);
1985 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1986 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1988 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1989 * unlocked here to allow other threads also to be able to
1990 * go into waiting state.
1993 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1994 _eglUnlockDisplay(dpy
);
1996 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1999 * 'disp' is already unlocked for reusable sync type,
2000 * so passing 'NULL' to bypass unlocking display.
2002 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
2003 RETURN_EGL_EVAL(NULL
, ret
);
2005 RETURN_EGL_EVAL(disp
, ret
);
2009 eglClientWaitSync(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
);
2018 static EGLint EGLAPIENTRY
2019 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
2020 EGLint flags
, EGLTime timeout
)
2022 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2023 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2024 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2025 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2030 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
2032 _EGLContext
*ctx
= _eglGetCurrentContext();
2036 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2037 assert(disp
->Extensions
.KHR_wait_sync
);
2039 /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */
2040 if (ctx
== EGL_NO_CONTEXT
||
2041 (ctx
->ClientAPI
!= EGL_OPENGL_ES_API
&&
2042 ctx
->ClientAPI
!= EGL_OPENGL_API
))
2043 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
2045 /* the API doesn't allow any flags yet */
2047 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2049 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
2051 RETURN_EGL_EVAL(disp
, ret
);
2054 static EGLint EGLAPIENTRY
2055 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2057 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2058 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2059 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2060 return _eglWaitSyncCommon(disp
, s
, flags
);
2064 EGLBoolean EGLAPIENTRY
2065 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2067 /* The KHR version returns EGLint, while the core version returns
2068 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2071 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2072 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2073 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2074 return _eglWaitSyncCommon(disp
, s
, flags
);
2078 static EGLBoolean EGLAPIENTRY
2079 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2081 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2082 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2086 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2088 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2089 assert(disp
->Extensions
.KHR_reusable_sync
);
2090 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2092 RETURN_EGL_EVAL(disp
, ret
);
2097 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2102 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2103 assert(disp
->Extensions
.KHR_reusable_sync
||
2104 disp
->Extensions
.KHR_fence_sync
||
2105 disp
->Extensions
.ANDROID_native_fence_sync
);
2107 ret
= _eglGetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2109 RETURN_EGL_EVAL(disp
, ret
);
2112 EGLBoolean EGLAPIENTRY
2113 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2115 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2116 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2117 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2118 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2122 static EGLBoolean EGLAPIENTRY
2123 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2125 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2126 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2130 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2133 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2136 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2138 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2140 * If any error occurs, <*value> is not modified.
2142 if (result
== EGL_FALSE
)
2149 static EGLint EGLAPIENTRY
2150 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2152 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2153 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2157 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2159 /* the spec doesn't seem to specify what happens if the fence
2160 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2163 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2164 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2166 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2167 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2168 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2170 RETURN_EGL_EVAL(disp
, ret
);
2173 static EGLBoolean EGLAPIENTRY
2174 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2175 EGLint numRects
, const EGLint
*rects
)
2177 _EGLContext
*ctx
= _eglGetCurrentContext();
2178 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2179 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2183 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2185 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2187 if (!disp
->Extensions
.NOK_swap_region
)
2188 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2190 /* surface must be bound to current context in EGL 1.4 */
2191 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2192 surf
!= ctx
->DrawSurface
)
2193 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2195 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2197 RETURN_EGL_EVAL(disp
, ret
);
2201 static EGLImage EGLAPIENTRY
2202 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2204 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2209 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2211 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2212 if (!disp
->Extensions
.MESA_drm_image
)
2213 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2215 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2216 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2218 RETURN_EGL_EVAL(disp
, ret
);
2221 static EGLBoolean EGLAPIENTRY
2222 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2223 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2225 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2226 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2230 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2232 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2233 assert(disp
->Extensions
.MESA_drm_image
);
2236 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2238 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2240 RETURN_EGL_EVAL(disp
, ret
);
2246 static EGLBoolean EGLAPIENTRY
2247 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2249 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2253 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2255 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2256 assert(disp
->Extensions
.WL_bind_wayland_display
);
2259 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2261 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2263 RETURN_EGL_EVAL(disp
, ret
);
2266 static EGLBoolean EGLAPIENTRY
2267 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2269 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2273 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2275 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2276 assert(disp
->Extensions
.WL_bind_wayland_display
);
2279 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2281 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2283 RETURN_EGL_EVAL(disp
, ret
);
2286 static EGLBoolean EGLAPIENTRY
2287 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2288 EGLint attribute
, EGLint
*value
)
2290 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2294 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2296 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2297 assert(disp
->Extensions
.WL_bind_wayland_display
);
2300 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2302 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2304 RETURN_EGL_EVAL(disp
, ret
);
2308 static struct wl_buffer
* EGLAPIENTRY
2309 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2311 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2314 struct wl_buffer
*ret
;
2316 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2318 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2319 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2320 RETURN_EGL_EVAL(disp
, NULL
);
2322 img
= _eglLookupImage(image
, disp
);
2325 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2327 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2329 RETURN_EGL_EVAL(disp
, ret
);
2332 static EGLBoolean EGLAPIENTRY
2333 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2334 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2336 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2337 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2341 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2343 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2345 if (!disp
->Extensions
.NV_post_sub_buffer
)
2346 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2348 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2350 RETURN_EGL_EVAL(disp
, ret
);
2353 static EGLBoolean EGLAPIENTRY
2354 eglGetSyncValuesCHROMIUM(EGLDisplay dpy
, EGLSurface surface
,
2355 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2358 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2359 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2363 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2365 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2366 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2367 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2369 if (!ust
|| !msc
|| !sbc
)
2370 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2372 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2374 RETURN_EGL_EVAL(disp
, ret
);
2377 static EGLBoolean EGLAPIENTRY
2378 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2379 EGLint
*fourcc
, EGLint
*nplanes
,
2380 EGLuint64KHR
*modifiers
)
2382 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2383 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2387 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2389 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2390 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2393 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2395 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2398 RETURN_EGL_EVAL(disp
, ret
);
2401 static EGLBoolean EGLAPIENTRY
2402 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2403 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2405 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2406 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2410 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2412 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2413 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2416 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2418 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2420 RETURN_EGL_EVAL(disp
, ret
);
2423 static EGLint EGLAPIENTRY
2424 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2427 _EGLDisplay
*disp
= NULL
;
2428 _EGLResourceType type
;
2430 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2432 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2433 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2435 if (!_eglIsCurrentThreadDummy()) {
2440 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2443 disp
= _eglLockDisplay(dpy
);
2445 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2447 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2448 if (dpy
!= (EGLDisplay
) object
)
2449 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2451 disp
->Label
= label
;
2452 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2455 switch (objectType
) {
2456 case EGL_OBJECT_CONTEXT_KHR
:
2457 type
= _EGL_RESOURCE_CONTEXT
;
2459 case EGL_OBJECT_SURFACE_KHR
:
2460 type
= _EGL_RESOURCE_SURFACE
;
2462 case EGL_OBJECT_IMAGE_KHR
:
2463 type
= _EGL_RESOURCE_IMAGE
;
2465 case EGL_OBJECT_SYNC_KHR
:
2466 type
= _EGL_RESOURCE_SYNC
;
2468 case EGL_OBJECT_STREAM_KHR
:
2470 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2473 if (_eglCheckResource(object
, type
, disp
)) {
2474 _EGLResource
*res
= (_EGLResource
*) object
;
2477 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2480 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2483 static EGLint EGLAPIENTRY
2484 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2485 const EGLAttrib
*attrib_list
)
2487 unsigned int newEnabled
;
2489 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2491 mtx_lock(_eglGlobal
.Mutex
);
2493 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2494 if (attrib_list
!= NULL
) {
2497 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2498 switch (attrib_list
[i
]) {
2499 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2500 case EGL_DEBUG_MSG_ERROR_KHR
:
2501 case EGL_DEBUG_MSG_WARN_KHR
:
2502 case EGL_DEBUG_MSG_INFO_KHR
:
2503 if (attrib_list
[i
+ 1])
2504 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2506 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2509 // On error, set the last error code, call the current
2510 // debug callback, and return the error code.
2511 mtx_unlock(_eglGlobal
.Mutex
);
2512 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2513 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2514 return EGL_BAD_ATTRIBUTE
;
2519 if (callback
!= NULL
) {
2520 _eglGlobal
.debugCallback
= callback
;
2521 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2523 _eglGlobal
.debugCallback
= NULL
;
2524 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2527 mtx_unlock(_eglGlobal
.Mutex
);
2531 static EGLBoolean EGLAPIENTRY
2532 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2534 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2536 mtx_lock(_eglGlobal
.Mutex
);
2538 switch (attribute
) {
2539 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2540 case EGL_DEBUG_MSG_ERROR_KHR
:
2541 case EGL_DEBUG_MSG_WARN_KHR
:
2542 case EGL_DEBUG_MSG_INFO_KHR
:
2543 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2548 case EGL_DEBUG_CALLBACK_KHR
:
2549 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2552 mtx_unlock(_eglGlobal
.Mutex
);
2553 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2554 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2558 mtx_unlock(_eglGlobal
.Mutex
);
2563 _eglFunctionCompare(const void *key
, const void *elem
)
2565 const char *procname
= key
;
2566 const struct _egl_entrypoint
*entrypoint
= elem
;
2567 return strcmp(procname
, entrypoint
->name
);
2570 static EGLBoolean EGLAPIENTRY
2571 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2572 EGLint
*formats
, EGLint
*num_formats
)
2574 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2578 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2580 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2582 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2585 RETURN_EGL_EVAL(disp
, ret
);
2588 static EGLBoolean EGLAPIENTRY
2589 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2590 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2591 EGLint
*num_modifiers
)
2593 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2597 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2599 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2601 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2602 modifiers
, external_only
,
2605 RETURN_EGL_EVAL(disp
, ret
);
2608 static void EGLAPIENTRY
2609 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2610 EGLGetBlobFuncANDROID get
)
2612 /* This function does not return anything so we cannot
2613 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2615 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2616 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2618 _eglUnlockDisplay(disp
);
2622 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2625 _eglUnlockDisplay(disp
);
2630 _eglError(EGL_BAD_PARAMETER
,
2631 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2632 _eglUnlockDisplay(disp
);
2636 if (disp
->BlobCacheSet
) {
2637 _eglError(EGL_BAD_PARAMETER
,
2638 "eglSetBlobCacheFuncsANDROID: functions already set");
2639 _eglUnlockDisplay(disp
);
2643 disp
->BlobCacheSet
= set
;
2644 disp
->BlobCacheGet
= get
;
2646 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2648 _eglUnlockDisplay(disp
);
2651 static EGLBoolean EGLAPIENTRY
2652 eglQueryDeviceAttribEXT(EGLDeviceEXT device
,
2656 _EGLDevice
*dev
= _eglLookupDevice(device
);
2659 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2661 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, EGL_FALSE
);
2663 ret
= _eglQueryDeviceAttribEXT(dev
, attribute
, value
);
2664 RETURN_EGL_EVAL(NULL
, ret
);
2667 static const char * EGLAPIENTRY
2668 eglQueryDeviceStringEXT(EGLDeviceEXT device
,
2671 _EGLDevice
*dev
= _eglLookupDevice(device
);
2673 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2675 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, NULL
);
2677 RETURN_EGL_EVAL(NULL
, _eglQueryDeviceStringEXT(dev
, name
));
2680 static EGLBoolean EGLAPIENTRY
2681 eglQueryDevicesEXT(EGLint max_devices
,
2682 EGLDeviceEXT
*devices
,
2683 EGLint
*num_devices
)
2687 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2688 ret
= _eglQueryDevicesEXT(max_devices
, (_EGLDevice
**) devices
,
2690 RETURN_EGL_EVAL(NULL
, ret
);
2693 static EGLBoolean EGLAPIENTRY
2694 eglQueryDisplayAttribEXT(EGLDisplay dpy
,
2698 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2701 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2702 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2704 switch (attribute
) {
2705 case EGL_DEVICE_EXT
:
2706 *value
= (EGLAttrib
) disp
->Device
;
2709 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
2711 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
2714 static char * EGLAPIENTRY
2715 eglGetDisplayDriverConfig(EGLDisplay dpy
)
2717 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2721 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2722 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2724 assert(disp
->Extensions
.MESA_query_driver
);
2726 ret
= drv
->API
.QueryDriverConfig(disp
);
2727 RETURN_EGL_EVAL(disp
, ret
);
2730 static const char * EGLAPIENTRY
2731 eglGetDisplayDriverName(EGLDisplay dpy
)
2733 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2737 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2738 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2740 assert(disp
->Extensions
.MESA_query_driver
);
2742 ret
= drv
->API
.QueryDriverName(disp
);
2743 RETURN_EGL_EVAL(disp
, ret
);
2746 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2747 eglGetProcAddress(const char *procname
)
2749 static const struct _egl_entrypoint egl_functions
[] = {
2750 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2751 #include "eglentrypoint.h"
2752 #undef EGL_ENTRYPOINT
2754 _EGLProc ret
= NULL
;
2757 RETURN_EGL_SUCCESS(NULL
, NULL
);
2759 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2761 if (strncmp(procname
, "egl", 3) == 0) {
2762 const struct _egl_entrypoint
*entrypoint
=
2764 egl_functions
, ARRAY_SIZE(egl_functions
),
2765 sizeof(egl_functions
[0]),
2766 _eglFunctionCompare
);
2768 ret
= entrypoint
->function
;
2772 ret
= _eglGetDriverProc(procname
);
2774 RETURN_EGL_SUCCESS(NULL
, ret
);
2778 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2779 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2783 *disp
= _eglLockDisplay(dpy
);
2784 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2786 _eglUnlockDisplay(*disp
);
2787 return MESA_GLINTEROP_INVALID_DISPLAY
;
2790 *drv
= (*disp
)->Driver
;
2792 *ctx
= _eglLookupContext(context
, *disp
);
2794 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2795 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2796 _eglUnlockDisplay(*disp
);
2797 return MESA_GLINTEROP_INVALID_CONTEXT
;
2800 return MESA_GLINTEROP_SUCCESS
;
2804 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2805 struct mesa_glinterop_device_info
*out
)
2812 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2813 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2816 if (drv
->API
.GLInteropQueryDeviceInfo
)
2817 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2819 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2821 _eglUnlockDisplay(disp
);
2826 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2827 struct mesa_glinterop_export_in
*in
,
2828 struct mesa_glinterop_export_out
*out
)
2835 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2836 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2839 if (drv
->API
.GLInteropExportObject
)
2840 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2842 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2844 _eglUnlockDisplay(disp
);