1 /**************************************************************************
3 * Copyright 2008 VMware, Inc.
4 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5 * Copyright 2010-2011 LunarG, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
32 * Public EGL API entrypoints
34 * Generally, we use the EGLDisplay parameter as a key to lookup the
35 * appropriate device driver handle, then jump though the driver's
36 * dispatch table to handle the function.
38 * That allows us the option of supporting multiple, simultaneous,
39 * heterogeneous hardware devices in the future.
41 * The EGLDisplay, EGLConfig, EGLContext and EGLSurface types are
42 * opaque handles. Internal objects are linked to a display to
45 * For each public API entry point, the opaque handles are looked up
46 * before being dispatched to the drivers. When it fails to look up
56 * is generated and the driver function is not called. An
57 * uninitialized EGLDisplay has no driver associated with it. When
58 * such display is detected,
64 * Some of the entry points use current display, context, or surface
65 * implicitly. For such entry points, the implicit objects are also
66 * checked before calling the driver function. Other than the
67 * errors listed above,
69 * EGL_BAD_CURRENT_SURFACE
71 * may also be generated.
73 * Notes on naming conventions:
75 * eglFooBar - public EGL function
76 * EGL_FOO_BAR - public EGL token
77 * EGLDatatype - public EGL datatype
79 * _eglFooBar - private EGL function
80 * _EGLDatatype - private EGL datatype, typedef'd struct
81 * _egl_struct - private EGL struct, non-typedef'd
95 #include "c99_compat.h"
96 #include "c11/threads.h"
97 #include "util/macros.h"
100 #include "egldefines.h"
101 #include "eglglobals.h"
102 #include "eglcontext.h"
103 #include "egldisplay.h"
104 #include "egltypedefs.h"
105 #include "eglcurrent.h"
106 #include "egldevice.h"
107 #include "egldriver.h"
108 #include "eglsurface.h"
109 #include "eglconfig.h"
110 #include "eglimage.h"
113 #include "GL/mesa_glinterop.h"
116 * Macros to help return an API entrypoint.
118 * These macros will unlock the display and record the error code.
120 #define RETURN_EGL_ERROR(disp, err, ret) \
123 _eglUnlockDisplay(disp); \
124 /* EGL error codes are non-zero */ \
126 _eglError(err, __func__); \
130 #define RETURN_EGL_SUCCESS(disp, ret) \
131 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
133 /* record EGL_SUCCESS only when ret evaluates to true */
134 #define RETURN_EGL_EVAL(disp, ret) \
135 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
139 * A bunch of macros and checks to simplify error checking.
142 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
144 drv = _eglCheckDisplay(disp, __func__); \
146 RETURN_EGL_ERROR(disp, 0, ret); \
149 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
151 drv = _eglCheck ## type(disp, obj, __func__); \
153 RETURN_EGL_ERROR(disp, 0, ret); \
156 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
157 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
159 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
160 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
162 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
163 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
165 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
166 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
169 struct _egl_entrypoint
{
175 static inline _EGLDriver
*
176 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
179 _eglError(EGL_BAD_DISPLAY
, msg
);
182 if (!disp
->Initialized
) {
183 _eglError(EGL_NOT_INITIALIZED
, msg
);
190 static inline _EGLDriver
*
191 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
193 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
197 _eglError(EGL_BAD_SURFACE
, msg
);
204 static inline _EGLDriver
*
205 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
207 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
211 _eglError(EGL_BAD_CONTEXT
, msg
);
218 static inline _EGLDriver
*
219 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
221 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
225 _eglError(EGL_BAD_CONFIG
, msg
);
232 static inline _EGLDriver
*
233 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
235 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
239 _eglError(EGL_BAD_PARAMETER
, msg
);
247 * Lookup and lock a display.
249 static inline _EGLDisplay
*
250 _eglLockDisplay(EGLDisplay dpy
)
252 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
254 mtx_lock(&disp
->Mutex
);
263 _eglUnlockDisplay(_EGLDisplay
*disp
)
265 mtx_unlock(&disp
->Mutex
);
269 _eglSetFuncName(const char *funcName
, _EGLDisplay
*disp
, EGLenum objectType
, _EGLResource
*object
)
271 _EGLThreadInfo
*thr
= _eglGetCurrentThread();
272 if (!_eglIsCurrentThreadDummy()) {
273 thr
->CurrentFuncName
= funcName
;
274 thr
->CurrentObjectLabel
= NULL
;
276 if (objectType
== EGL_OBJECT_THREAD_KHR
)
277 thr
->CurrentObjectLabel
= thr
->Label
;
278 else if (objectType
== EGL_OBJECT_DISPLAY_KHR
&& disp
)
279 thr
->CurrentObjectLabel
= disp
->Label
;
281 thr
->CurrentObjectLabel
= object
->Label
;
286 _eglDebugReport(EGL_BAD_ALLOC
, funcName
, EGL_DEBUG_MSG_CRITICAL_KHR
, NULL
);
290 #define _EGL_FUNC_START(disp, objectType, object, ret) \
292 if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \
294 _eglUnlockDisplay(disp); \
300 * Convert an attribute list from EGLint[] to EGLAttrib[].
302 * Return an EGL error code. The output parameter out_attrib_list is modified
306 _eglConvertIntsToAttribs(const EGLint
*int_list
, EGLAttrib
**out_attrib_list
)
309 EGLAttrib
*attrib_list
;
312 while (int_list
[2*len
] != EGL_NONE
)
317 *out_attrib_list
= NULL
;
321 if (2*len
+ 1 > SIZE_MAX
/ sizeof(EGLAttrib
))
322 return EGL_BAD_ALLOC
;
324 attrib_list
= malloc((2*len
+ 1) * sizeof(EGLAttrib
));
326 return EGL_BAD_ALLOC
;
328 for (size_t i
= 0; i
< len
; ++i
) {
329 attrib_list
[2*i
+ 0] = int_list
[2*i
+ 0];
330 attrib_list
[2*i
+ 1] = int_list
[2*i
+ 1];
333 attrib_list
[2*len
] = EGL_NONE
;
335 *out_attrib_list
= attrib_list
;
341 _eglConvertAttribsToInt(const EGLAttrib
*attr_list
)
343 size_t size
= _eglNumAttribs(attr_list
);
344 EGLint
*int_attribs
= NULL
;
346 /* Convert attributes from EGLAttrib[] to EGLint[] */
348 int_attribs
= calloc(size
, sizeof(int_attribs
[0]));
352 for (size_t i
= 0; i
< size
; i
++)
353 int_attribs
[i
] = attr_list
[i
];
360 * This is typically the first EGL function that an application calls.
361 * It associates a private _EGLDisplay object to the native display.
363 EGLDisplay EGLAPIENTRY
364 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
366 _EGLPlatformType plat
;
368 void *native_display_ptr
;
370 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
372 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
373 native_display_ptr
= (void*) nativeDisplay
;
375 plat
= _eglGetNativePlatform(native_display_ptr
);
376 disp
= _eglFindDisplay(plat
, native_display_ptr
, NULL
);
377 return _eglGetDisplayHandle(disp
);
381 _eglGetPlatformDisplayCommon(EGLenum platform
, void *native_display
,
382 const EGLAttrib
*attrib_list
)
387 #ifdef HAVE_X11_PLATFORM
388 case EGL_PLATFORM_X11_EXT
:
389 disp
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
392 #ifdef HAVE_DRM_PLATFORM
393 case EGL_PLATFORM_GBM_MESA
:
394 disp
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
398 #ifdef HAVE_WAYLAND_PLATFORM
399 case EGL_PLATFORM_WAYLAND_EXT
:
400 disp
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
404 #ifdef HAVE_SURFACELESS_PLATFORM
405 case EGL_PLATFORM_SURFACELESS_MESA
:
406 disp
= _eglGetSurfacelessDisplay(native_display
, attrib_list
);
409 case EGL_PLATFORM_DEVICE_EXT
:
410 disp
= _eglGetDeviceDisplay(native_display
, attrib_list
);
413 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
416 return _eglGetDisplayHandle(disp
);
419 static EGLDisplay EGLAPIENTRY
420 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
421 const EGLint
*int_attribs
)
423 EGLAttrib
*attrib_list
;
426 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
428 if (_eglConvertIntsToAttribs(int_attribs
, &attrib_list
) != EGL_SUCCESS
)
429 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
431 disp
= _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
436 EGLDisplay EGLAPIENTRY
437 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
438 const EGLAttrib
*attrib_list
)
440 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
441 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
445 * Copy the extension into the string and update the string pointer.
448 _eglAppendExtension(char **str
, const char *ext
)
451 size_t len
= strlen(ext
);
468 * Examine the individual extension enable/disable flags and recompute
469 * the driver's Extensions string.
472 _eglCreateExtensionsString(_EGLDisplay
*disp
)
474 #define _EGL_CHECK_EXTENSION(ext) \
476 if (disp->Extensions.ext) { \
477 _eglAppendExtension(&exts, "EGL_" #ext); \
478 assert(exts <= disp->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
482 char *exts
= disp
->ExtensionsString
;
484 /* Please keep these sorted alphabetically. */
485 _EGL_CHECK_EXTENSION(ANDROID_blob_cache
);
486 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
487 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
488 _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync
);
489 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
491 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
493 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
494 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
495 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
496 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers
);
497 _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata
);
498 _EGL_CHECK_EXTENSION(EXT_surface_SMPTE2086_metadata
);
499 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
501 _EGL_CHECK_EXTENSION(IMG_context_priority
);
503 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
504 _EGL_CHECK_EXTENSION(KHR_config_attribs
);
505 _EGL_CHECK_EXTENSION(KHR_context_flush_control
);
506 _EGL_CHECK_EXTENSION(KHR_create_context
);
507 _EGL_CHECK_EXTENSION(KHR_create_context_no_error
);
508 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
509 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
510 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
511 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
512 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
513 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
514 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
515 if (disp
->Extensions
.KHR_image_base
&& disp
->Extensions
.KHR_image_pixmap
)
516 disp
->Extensions
.KHR_image
= EGL_TRUE
;
517 _EGL_CHECK_EXTENSION(KHR_image
);
518 _EGL_CHECK_EXTENSION(KHR_image_base
);
519 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
520 _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer
);
521 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
522 _EGL_CHECK_EXTENSION(KHR_partial_update
);
523 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
524 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
525 if (disp
->Extensions
.EXT_swap_buffers_with_damage
)
526 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
527 _EGL_CHECK_EXTENSION(EXT_pixel_format_float
);
528 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
530 if (disp
->Extensions
.KHR_no_config_context
)
531 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
532 _EGL_CHECK_EXTENSION(MESA_drm_image
);
533 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
534 _EGL_CHECK_EXTENSION(MESA_query_driver
);
536 _EGL_CHECK_EXTENSION(NOK_swap_region
);
537 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
539 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
541 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
542 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
544 #undef _EGL_CHECK_EXTENSION
548 _eglCreateAPIsString(_EGLDisplay
*disp
)
550 #define addstr(str) \
552 const size_t old_len = strlen(disp->ClientAPIsString); \
553 const size_t add_len = sizeof(str); \
554 const size_t max_len = sizeof(disp->ClientAPIsString) - 1; \
555 if (old_len + add_len <= max_len) \
556 strcat(disp->ClientAPIsString, str " "); \
558 assert(!"disp->ClientAPIsString is not large enough"); \
561 if (disp
->ClientAPIs
& EGL_OPENGL_BIT
)
564 if (disp
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
565 disp
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
566 disp
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
570 if (disp
->ClientAPIs
& EGL_OPENVG_BIT
)
577 _eglComputeVersion(_EGLDisplay
*disp
)
581 if (disp
->Extensions
.KHR_fence_sync
&&
582 disp
->Extensions
.KHR_cl_event2
&&
583 disp
->Extensions
.KHR_wait_sync
&&
584 disp
->Extensions
.KHR_image_base
&&
585 disp
->Extensions
.KHR_gl_texture_2D_image
&&
586 disp
->Extensions
.KHR_gl_texture_3D_image
&&
587 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
588 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
589 disp
->Extensions
.KHR_create_context
&&
590 disp
->Extensions
.EXT_create_context_robustness
&&
591 disp
->Extensions
.KHR_get_all_proc_addresses
&&
592 disp
->Extensions
.KHR_gl_colorspace
&&
593 disp
->Extensions
.KHR_surfaceless_context
)
598 * This is typically the second EGL function that an application calls.
599 * Here we load/initialize the actual hardware driver.
601 EGLBoolean EGLAPIENTRY
602 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
604 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
606 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
609 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
611 if (!disp
->Initialized
) {
612 if (!_eglMatchDriver(disp
))
613 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
615 /* limit to APIs supported by core */
616 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
618 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
619 * classifies it as an EGL display extension, though conceptually it's an
620 * EGL client extension.
622 * From the EGL_KHR_get_all_proc_addresses spec:
624 * The EGL implementation must expose the name
625 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
626 * EGL_KHR_get_all_proc_addresses and supports
627 * EGL_EXT_client_extensions.
629 * Mesa unconditionally exposes both client extensions mentioned above,
630 * so the spec requires that each EGLDisplay unconditionally expose
631 * EGL_KHR_get_all_proc_addresses also.
633 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
635 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
636 * programs. It is driver agnostic and handled in the main EGL code.
638 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
640 _eglComputeVersion(disp
);
641 _eglCreateExtensionsString(disp
);
642 _eglCreateAPIsString(disp
);
643 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
644 "%d.%d", disp
->Version
/ 10, disp
->Version
% 10);
647 /* Update applications version of major and minor if not NULL */
648 if ((major
!= NULL
) && (minor
!= NULL
)) {
649 *major
= disp
->Version
/ 10;
650 *minor
= disp
->Version
% 10;
653 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
657 EGLBoolean EGLAPIENTRY
658 eglTerminate(EGLDisplay dpy
)
660 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
662 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
665 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
667 if (disp
->Initialized
) {
668 _EGLDriver
*drv
= disp
->Driver
;
670 drv
->API
.Terminate(drv
, disp
);
671 /* do not reset disp->Driver */
672 disp
->ClientAPIsString
[0] = 0;
673 disp
->Initialized
= EGL_FALSE
;
676 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
680 const char * EGLAPIENTRY
681 eglQueryString(EGLDisplay dpy
, EGLint name
)
686 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
687 const char *ret
= _eglGetClientExtensionString();
689 RETURN_EGL_SUCCESS(NULL
, ret
);
691 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
694 disp
= _eglLockDisplay(dpy
);
695 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
696 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
700 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
702 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
704 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
705 case EGL_CLIENT_APIS
:
706 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
708 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
713 EGLBoolean EGLAPIENTRY
714 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
715 EGLint config_size
, EGLint
*num_config
)
717 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
721 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
723 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
726 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
728 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
730 RETURN_EGL_EVAL(disp
, ret
);
734 EGLBoolean EGLAPIENTRY
735 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
736 EGLint config_size
, EGLint
*num_config
)
738 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
742 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
744 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
747 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
749 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
750 config_size
, num_config
);
752 RETURN_EGL_EVAL(disp
, ret
);
756 EGLBoolean EGLAPIENTRY
757 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
758 EGLint attribute
, EGLint
*value
)
760 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
761 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
765 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
767 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
768 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
770 RETURN_EGL_EVAL(disp
, ret
);
774 EGLContext EGLAPIENTRY
775 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
776 const EGLint
*attrib_list
)
778 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
779 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
780 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
782 _EGLContext
*context
;
785 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
787 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
789 if (config
!= EGL_NO_CONFIG_KHR
)
790 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
791 else if (!disp
->Extensions
.KHR_no_config_context
)
792 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
794 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
795 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
797 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
798 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
800 RETURN_EGL_EVAL(disp
, ret
);
804 EGLBoolean EGLAPIENTRY
805 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
807 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
808 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
812 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
814 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
815 _eglUnlinkContext(context
);
816 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
818 RETURN_EGL_EVAL(disp
, ret
);
822 EGLBoolean EGLAPIENTRY
823 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
826 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
827 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
828 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
829 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
833 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
836 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
839 /* display is allowed to be uninitialized under certain condition */
840 if (!disp
->Initialized
) {
841 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
842 ctx
!= EGL_NO_CONTEXT
)
843 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
846 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
848 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
849 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
850 if (!draw_surf
|| !read_surf
) {
851 /* From the EGL 1.4 (20130211) spec:
853 * To release the current context without assigning a new one, set ctx
854 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
856 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
857 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
859 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
860 (!read_surf
&& read
!= EGL_NO_SURFACE
))
861 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
862 if (draw_surf
|| read_surf
)
863 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
866 /* If a native window underlying either draw or read is no longer valid,
867 * an EGL_BAD_NATIVE_WINDOW error is generated.
869 if (draw_surf
&& draw_surf
->Lost
)
870 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
871 if (read_surf
&& read_surf
->Lost
)
872 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
874 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
876 RETURN_EGL_EVAL(disp
, ret
);
880 EGLBoolean EGLAPIENTRY
881 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
882 EGLint attribute
, EGLint
*value
)
884 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
885 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
889 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
891 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
892 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
894 RETURN_EGL_EVAL(disp
, ret
);
898 /* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says
899 * that if native_surface was already used to create a window or pixmap, we
900 * can't create a new one. This is what this function checks for.
903 _eglNativeSurfaceAlreadyUsed(_EGLDisplay
*disp
, void *native_surface
)
907 list
= disp
->ResourceLists
[_EGL_RESOURCE_SURFACE
];
909 _EGLSurface
*surf
= (_EGLSurface
*) list
;
913 if (surf
->Type
== EGL_PBUFFER_BIT
)
916 if (surf
->NativeSurface
== native_surface
)
925 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
926 void *native_window
, const EGLint
*attrib_list
)
928 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
934 if (native_window
== NULL
)
935 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
937 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
938 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
939 /* From the EGL_MESA_platform_surfaceless spec (v1):
941 * eglCreatePlatformWindowSurface fails when called with a <display>
942 * that belongs to the surfaceless platform. It returns
943 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
944 * justification for this unconditional failure is that the
945 * surfaceless platform has no native windows, and therefore the
946 * <native_window> parameter is always invalid.
948 * This check must occur before checking the EGLConfig, which emits
951 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
954 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
956 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
957 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
959 if (_eglNativeSurfaceAlreadyUsed(disp
, native_window
))
960 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
962 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
964 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
966 RETURN_EGL_EVAL(disp
, ret
);
970 EGLSurface EGLAPIENTRY
971 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
972 EGLNativeWindowType window
, const EGLint
*attrib_list
)
974 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
976 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
977 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
978 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
983 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
985 #ifdef HAVE_X11_PLATFORM
986 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
987 /* The `native_window` parameter for the X11 platform differs between
988 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
989 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
990 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
991 * `Window*`. Convert `Window*` to `Window` because that's what
992 * dri2_x11_create_window_surface() expects.
994 return (void *)(* (Window
*) native_window
);
997 return native_window
;
1000 static EGLSurface EGLAPIENTRY
1001 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1002 void *native_window
,
1003 const EGLint
*attrib_list
)
1005 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1007 native_window
= _fixupNativeWindow(disp
, native_window
);
1009 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1010 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1015 EGLSurface EGLAPIENTRY
1016 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
1017 void *native_window
,
1018 const EGLAttrib
*attrib_list
)
1020 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1022 EGLint
*int_attribs
;
1024 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1026 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1027 if (attrib_list
&& !int_attribs
)
1028 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1030 native_window
= _fixupNativeWindow(disp
, native_window
);
1031 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1038 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
1040 #ifdef HAVE_X11_PLATFORM
1041 /* The `native_pixmap` parameter for the X11 platform differs between
1042 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1043 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1044 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1045 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1046 * dri2_x11_create_pixmap_surface() expects.
1048 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
1049 return (void *)(* (Pixmap
*) native_pixmap
);
1051 return native_pixmap
;
1055 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1056 void *native_pixmap
, const EGLint
*attrib_list
)
1058 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1063 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
1064 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
1065 /* From the EGL_MESA_platform_surfaceless spec (v1):
1067 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1068 * also fails when called with a <display> that belongs to the
1069 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1070 * EGL_BAD_NATIVE_PIXMAP.
1072 * This check must occur before checking the EGLConfig, which emits
1075 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1078 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1080 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1081 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1083 if (native_pixmap
== NULL
)
1084 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1086 if (_eglNativeSurfaceAlreadyUsed(disp
, native_pixmap
))
1087 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1089 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1091 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1093 RETURN_EGL_EVAL(disp
, ret
);
1097 EGLSurface EGLAPIENTRY
1098 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1099 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1101 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1103 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1104 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1105 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1109 static EGLSurface EGLAPIENTRY
1110 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1111 void *native_pixmap
,
1112 const EGLint
*attrib_list
)
1114 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1116 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1117 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1118 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1123 EGLSurface EGLAPIENTRY
1124 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1125 void *native_pixmap
,
1126 const EGLAttrib
*attrib_list
)
1128 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1130 EGLint
*int_attribs
;
1132 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1134 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1135 if (attrib_list
&& !int_attribs
)
1136 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1138 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1139 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1146 EGLSurface EGLAPIENTRY
1147 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1148 const EGLint
*attrib_list
)
1150 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1151 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1156 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1157 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1159 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1160 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1162 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1163 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1165 RETURN_EGL_EVAL(disp
, ret
);
1169 EGLBoolean EGLAPIENTRY
1170 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1172 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1173 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1177 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1178 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1179 _eglUnlinkSurface(surf
);
1180 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1182 RETURN_EGL_EVAL(disp
, ret
);
1185 EGLBoolean EGLAPIENTRY
1186 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1187 EGLint attribute
, EGLint
*value
)
1189 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1190 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1194 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1195 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1196 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1198 RETURN_EGL_EVAL(disp
, ret
);
1201 EGLBoolean EGLAPIENTRY
1202 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1203 EGLint attribute
, EGLint value
)
1205 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1206 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1210 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1211 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1212 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1214 RETURN_EGL_EVAL(disp
, ret
);
1218 EGLBoolean EGLAPIENTRY
1219 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1221 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1222 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1226 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1227 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1228 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1230 RETURN_EGL_EVAL(disp
, ret
);
1234 EGLBoolean EGLAPIENTRY
1235 eglReleaseTexImage(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
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1246 RETURN_EGL_EVAL(disp
, ret
);
1250 EGLBoolean EGLAPIENTRY
1251 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1253 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1254 _EGLContext
*ctx
= _eglGetCurrentContext();
1255 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1259 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1260 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1262 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1263 ctx
->Resource
.Display
!= disp
)
1264 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1266 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1267 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1269 if (surf
->Type
!= EGL_WINDOW_BIT
)
1270 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1272 interval
= CLAMP(interval
,
1273 surf
->Config
->MinSwapInterval
,
1274 surf
->Config
->MaxSwapInterval
);
1276 if (surf
->SwapInterval
!= interval
)
1277 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1282 surf
->SwapInterval
= interval
;
1284 RETURN_EGL_EVAL(disp
, ret
);
1288 EGLBoolean EGLAPIENTRY
1289 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1291 _EGLContext
*ctx
= _eglGetCurrentContext();
1292 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1293 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1297 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1298 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1300 /* surface must be bound to current context in EGL 1.4 */
1301 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1302 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1303 surf
!= ctx
->DrawSurface
)
1304 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1307 if (surf
->Type
!= EGL_WINDOW_BIT
)
1308 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1310 /* From the EGL 1.5 spec:
1312 * If eglSwapBuffers is called and the native window associated with
1313 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1317 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1319 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1321 /* EGL_KHR_partial_update
1322 * Frame boundary successfully reached,
1323 * reset damage region and reset BufferAgeRead
1326 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1327 surf
->BufferAgeRead
= EGL_FALSE
;
1330 RETURN_EGL_EVAL(disp
, ret
);
1335 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1336 EGLint
*rects
, EGLint n_rects
)
1338 _EGLContext
*ctx
= _eglGetCurrentContext();
1342 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1344 /* surface must be bound to current context in EGL 1.4 */
1345 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1346 surf
!= ctx
->DrawSurface
)
1347 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1349 if (surf
->Type
!= EGL_WINDOW_BIT
)
1350 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1352 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1353 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1355 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1357 /* EGL_KHR_partial_update
1358 * Frame boundary successfully reached,
1359 * reset damage region and reset BufferAgeRead
1362 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1363 surf
->BufferAgeRead
= EGL_FALSE
;
1366 RETURN_EGL_EVAL(disp
, ret
);
1369 static EGLBoolean EGLAPIENTRY
1370 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1371 EGLint
*rects
, EGLint n_rects
)
1373 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1374 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1375 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1376 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1379 static EGLBoolean EGLAPIENTRY
1380 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1381 EGLint
*rects
, EGLint n_rects
)
1383 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1384 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1385 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1386 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1390 * Clamp the rectangles so that they lie within the surface.
1394 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1395 EGLint
*rects
, EGLint n_rects
)
1398 EGLint surf_height
= surf
->Height
;
1399 EGLint surf_width
= surf
->Width
;
1401 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1402 EGLint x1
, y1
, x2
, y2
;
1405 x2
= rects
[i
+ 2] + x1
;
1406 y2
= rects
[i
+ 3] + y1
;
1408 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1409 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1410 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1411 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1415 static EGLBoolean EGLAPIENTRY
1416 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1417 EGLint
*rects
, EGLint n_rects
)
1419 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1420 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1421 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1422 _EGLContext
*ctx
= _eglGetCurrentContext();
1425 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1427 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1428 surf
->Type
!= EGL_WINDOW_BIT
||
1429 ctx
->DrawSurface
!= surf
||
1430 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1431 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1433 /* If the damage region is already set or
1434 * buffer age is not queried between
1435 * frame boundaries, throw bad access error
1438 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1439 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1441 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1442 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1445 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1447 RETURN_EGL_EVAL(disp
, ret
);
1450 EGLBoolean EGLAPIENTRY
1451 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1453 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1454 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1457 void *native_pixmap_ptr
;
1459 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1460 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1461 native_pixmap_ptr
= (void*) target
;
1463 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1464 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1466 RETURN_EGL_EVAL(disp
, ret
);
1471 _eglWaitClientCommon(void)
1473 _EGLContext
*ctx
= _eglGetCurrentContext();
1479 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1481 disp
= ctx
->Resource
.Display
;
1482 mtx_lock(&disp
->Mutex
);
1484 /* let bad current context imply bad current surface */
1485 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1486 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1487 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1489 /* a valid current context implies an initialized current display */
1490 assert(disp
->Initialized
);
1492 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1494 RETURN_EGL_EVAL(disp
, ret
);
1497 EGLBoolean EGLAPIENTRY
1500 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1501 return _eglWaitClientCommon();
1504 EGLBoolean EGLAPIENTRY
1507 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1508 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1509 return _eglWaitClientCommon();
1513 EGLBoolean EGLAPIENTRY
1514 eglWaitNative(EGLint engine
)
1516 _EGLContext
*ctx
= _eglGetCurrentContext();
1522 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1524 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1526 disp
= ctx
->Resource
.Display
;
1527 mtx_lock(&disp
->Mutex
);
1529 /* let bad current context imply bad current surface */
1530 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1531 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1532 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1534 /* a valid current context implies an initialized current display */
1535 assert(disp
->Initialized
);
1537 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1539 RETURN_EGL_EVAL(disp
, ret
);
1543 EGLDisplay EGLAPIENTRY
1544 eglGetCurrentDisplay(void)
1546 _EGLContext
*ctx
= _eglGetCurrentContext();
1549 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1551 RETURN_EGL_SUCCESS(NULL
, ret
);
1555 EGLContext EGLAPIENTRY
1556 eglGetCurrentContext(void)
1558 _EGLContext
*ctx
= _eglGetCurrentContext();
1561 ret
= _eglGetContextHandle(ctx
);
1563 RETURN_EGL_SUCCESS(NULL
, ret
);
1567 EGLSurface EGLAPIENTRY
1568 eglGetCurrentSurface(EGLint readdraw
)
1570 _EGLContext
*ctx
= _eglGetCurrentContext();
1571 EGLint err
= EGL_SUCCESS
;
1575 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1578 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1582 surf
= ctx
->DrawSurface
;
1585 surf
= ctx
->ReadSurface
;
1589 err
= EGL_BAD_PARAMETER
;
1593 ret
= _eglGetSurfaceHandle(surf
);
1595 RETURN_EGL_ERROR(NULL
, err
, ret
);
1602 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1603 EGLint e
= t
->LastError
;
1604 if (!_eglIsCurrentThreadDummy())
1605 t
->LastError
= EGL_SUCCESS
;
1615 * Specify the client API to use for subsequent calls including:
1616 * eglCreateContext()
1617 * eglGetCurrentContext()
1618 * eglGetCurrentDisplay()
1619 * eglGetCurrentSurface()
1620 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1623 * See section 3.7 "Rendering Context" in the EGL specification for details.
1625 EGLBoolean EGLAPIENTRY
1626 eglBindAPI(EGLenum api
)
1630 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1632 t
= _eglGetCurrentThread();
1633 if (_eglIsCurrentThreadDummy())
1634 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1636 if (!_eglIsApiValid(api
))
1637 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1639 t
->CurrentAPI
= api
;
1641 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1646 * Return the last value set with eglBindAPI().
1651 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1654 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1655 ret
= t
->CurrentAPI
;
1657 RETURN_EGL_SUCCESS(NULL
, ret
);
1661 EGLSurface EGLAPIENTRY
1662 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1663 EGLClientBuffer buffer
, EGLConfig config
,
1664 const EGLint
*attrib_list
)
1666 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1667 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1672 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1674 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1676 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1678 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1680 RETURN_EGL_EVAL(disp
, ret
);
1684 EGLBoolean EGLAPIENTRY
1685 eglReleaseThread(void)
1687 /* unbind current contexts */
1688 if (!_eglIsCurrentThreadDummy()) {
1689 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1690 _EGLContext
*ctx
= t
->CurrentContext
;
1692 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1695 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1698 mtx_lock(&disp
->Mutex
);
1700 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1701 mtx_unlock(&disp
->Mutex
);
1705 _eglDestroyCurrentThread();
1707 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1712 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1713 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1715 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1720 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1721 if (!disp
->Extensions
.KHR_image_base
)
1722 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1723 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1724 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1725 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1726 * <ctx> must be EGL_NO_CONTEXT..."
1728 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1729 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1731 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1733 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1735 RETURN_EGL_EVAL(disp
, ret
);
1738 static EGLImage EGLAPIENTRY
1739 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1740 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1742 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1743 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1744 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1748 EGLImage EGLAPIENTRY
1749 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1750 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1752 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1754 EGLint
*int_attribs
;
1756 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1758 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1759 if (attr_list
&& !int_attribs
)
1760 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1762 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1769 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1774 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1775 if (!disp
->Extensions
.KHR_image_base
)
1776 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1778 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1780 _eglUnlinkImage(img
);
1781 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1783 RETURN_EGL_EVAL(disp
, ret
);
1786 EGLBoolean EGLAPIENTRY
1787 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1789 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1790 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1791 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1792 return _eglDestroyImageCommon(disp
, img
);
1795 static EGLBoolean EGLAPIENTRY
1796 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1798 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1799 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1800 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1801 return _eglDestroyImageCommon(disp
, img
);
1806 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1807 EGLBoolean orig_is_EGLAttrib
,
1808 EGLenum invalid_type_error
)
1810 _EGLContext
*ctx
= _eglGetCurrentContext();
1815 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1817 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1818 /* There exist two EGLAttrib variants of eglCreateSync*:
1819 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1820 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1821 * support as a proxy for EGL 1.5 support, even though that's not
1822 * entirely correct (though _eglComputeVersion does the same).
1824 * The EGL spec provides no guidance on how to handle unsupported
1825 * functions. EGL_BAD_MATCH seems reasonable.
1827 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1830 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1831 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1832 * error is generated.
1835 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1836 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1838 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1839 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1840 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1841 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1844 case EGL_SYNC_FENCE_KHR
:
1845 if (!disp
->Extensions
.KHR_fence_sync
)
1846 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1848 case EGL_SYNC_REUSABLE_KHR
:
1849 if (!disp
->Extensions
.KHR_reusable_sync
)
1850 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1852 case EGL_SYNC_CL_EVENT_KHR
:
1853 if (!disp
->Extensions
.KHR_cl_event2
)
1854 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1856 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1857 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1858 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1861 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1864 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1865 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1867 RETURN_EGL_EVAL(disp
, ret
);
1871 static EGLSync EGLAPIENTRY
1872 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1874 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1875 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1878 EGLAttrib
*attrib_list
;
1881 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1882 attrib_list
= (EGLAttrib
*) int_list
;
1884 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1885 if (err
!= EGL_SUCCESS
)
1886 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1889 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1892 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1895 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1900 static EGLSync EGLAPIENTRY
1901 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1903 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1904 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1905 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1911 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1913 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1914 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1915 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1921 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1926 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1927 assert(disp
->Extensions
.KHR_reusable_sync
||
1928 disp
->Extensions
.KHR_fence_sync
||
1929 disp
->Extensions
.ANDROID_native_fence_sync
);
1932 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1934 RETURN_EGL_EVAL(disp
, ret
);
1937 EGLBoolean EGLAPIENTRY
1938 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1940 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1941 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1942 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1943 return _eglDestroySync(disp
, s
);
1946 static EGLBoolean EGLAPIENTRY
1947 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1949 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1950 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1951 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1952 return _eglDestroySync(disp
, s
);
1957 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1958 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1963 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1964 assert(disp
->Extensions
.KHR_reusable_sync
||
1965 disp
->Extensions
.KHR_fence_sync
||
1966 disp
->Extensions
.ANDROID_native_fence_sync
);
1968 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1969 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1971 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1972 * unlocked here to allow other threads also to be able to
1973 * go into waiting state.
1976 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1977 _eglUnlockDisplay(dpy
);
1979 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1982 * 'disp' is already unlocked for reusable sync type,
1983 * so passing 'NULL' to bypass unlocking display.
1985 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1986 RETURN_EGL_EVAL(NULL
, ret
);
1988 RETURN_EGL_EVAL(disp
, ret
);
1992 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
1993 EGLint flags
, EGLTime timeout
)
1995 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1996 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1997 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1998 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2001 static EGLint EGLAPIENTRY
2002 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
2003 EGLint flags
, EGLTime timeout
)
2005 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2006 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2007 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2008 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2013 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
2015 _EGLContext
*ctx
= _eglGetCurrentContext();
2019 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2020 assert(disp
->Extensions
.KHR_wait_sync
);
2022 /* return an error if the client API doesn't support GL_OES_EGL_sync */
2023 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
2024 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
2026 /* the API doesn't allow any flags yet */
2028 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2030 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
2032 RETURN_EGL_EVAL(disp
, ret
);
2035 static EGLint EGLAPIENTRY
2036 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2038 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2039 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2040 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2041 return _eglWaitSyncCommon(disp
, s
, flags
);
2045 EGLBoolean EGLAPIENTRY
2046 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2048 /* The KHR version returns EGLint, while the core version returns
2049 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2052 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2053 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2054 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2055 return _eglWaitSyncCommon(disp
, s
, flags
);
2059 static EGLBoolean EGLAPIENTRY
2060 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2062 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2063 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2067 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2069 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2070 assert(disp
->Extensions
.KHR_reusable_sync
);
2071 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2073 RETURN_EGL_EVAL(disp
, ret
);
2078 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2083 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2084 assert(disp
->Extensions
.KHR_reusable_sync
||
2085 disp
->Extensions
.KHR_fence_sync
||
2086 disp
->Extensions
.ANDROID_native_fence_sync
);
2087 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2089 RETURN_EGL_EVAL(disp
, ret
);
2092 EGLBoolean EGLAPIENTRY
2093 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2095 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2096 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2097 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2098 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2102 static EGLBoolean EGLAPIENTRY
2103 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2105 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2106 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2110 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2113 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2116 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2118 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2120 * If any error occurs, <*value> is not modified.
2122 if (result
== EGL_FALSE
)
2129 static EGLint EGLAPIENTRY
2130 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2132 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2133 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2137 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2139 /* the spec doesn't seem to specify what happens if the fence
2140 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2143 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2144 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2146 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2147 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2148 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2150 RETURN_EGL_EVAL(disp
, ret
);
2153 static EGLBoolean EGLAPIENTRY
2154 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2155 EGLint numRects
, const EGLint
*rects
)
2157 _EGLContext
*ctx
= _eglGetCurrentContext();
2158 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2159 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2163 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2165 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2167 if (!disp
->Extensions
.NOK_swap_region
)
2168 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2170 /* surface must be bound to current context in EGL 1.4 */
2171 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2172 surf
!= ctx
->DrawSurface
)
2173 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2175 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2177 RETURN_EGL_EVAL(disp
, ret
);
2181 static EGLImage EGLAPIENTRY
2182 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2184 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2189 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2191 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2192 if (!disp
->Extensions
.MESA_drm_image
)
2193 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2195 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2196 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2198 RETURN_EGL_EVAL(disp
, ret
);
2201 static EGLBoolean EGLAPIENTRY
2202 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2203 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2205 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2206 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2210 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2212 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2213 assert(disp
->Extensions
.MESA_drm_image
);
2216 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2218 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2220 RETURN_EGL_EVAL(disp
, ret
);
2226 static EGLBoolean EGLAPIENTRY
2227 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2229 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2233 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2235 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2236 assert(disp
->Extensions
.WL_bind_wayland_display
);
2239 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2241 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2243 RETURN_EGL_EVAL(disp
, ret
);
2246 static EGLBoolean EGLAPIENTRY
2247 eglUnbindWaylandDisplayWL(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
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2263 RETURN_EGL_EVAL(disp
, ret
);
2266 static EGLBoolean EGLAPIENTRY
2267 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2268 EGLint attribute
, EGLint
*value
)
2270 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2274 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2276 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2277 assert(disp
->Extensions
.WL_bind_wayland_display
);
2280 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2282 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2284 RETURN_EGL_EVAL(disp
, ret
);
2288 static struct wl_buffer
* EGLAPIENTRY
2289 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2291 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2294 struct wl_buffer
*ret
;
2296 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2298 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2299 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2300 RETURN_EGL_EVAL(disp
, NULL
);
2302 img
= _eglLookupImage(image
, disp
);
2305 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2307 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2309 RETURN_EGL_EVAL(disp
, ret
);
2312 static EGLBoolean EGLAPIENTRY
2313 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2314 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2316 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2317 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2321 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2323 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2325 if (!disp
->Extensions
.NV_post_sub_buffer
)
2326 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2328 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2330 RETURN_EGL_EVAL(disp
, ret
);
2333 static EGLBoolean EGLAPIENTRY
2334 eglGetSyncValuesCHROMIUM(EGLDisplay dpy
, EGLSurface surface
,
2335 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2338 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2339 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2343 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2345 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2346 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2347 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2349 if (!ust
|| !msc
|| !sbc
)
2350 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2352 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2354 RETURN_EGL_EVAL(disp
, ret
);
2357 static EGLBoolean EGLAPIENTRY
2358 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2359 EGLint
*fourcc
, EGLint
*nplanes
,
2360 EGLuint64KHR
*modifiers
)
2362 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2363 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2367 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2369 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2370 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2373 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2375 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2378 RETURN_EGL_EVAL(disp
, ret
);
2381 static EGLBoolean EGLAPIENTRY
2382 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2383 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2385 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2386 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2390 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2392 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2393 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2396 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2398 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2400 RETURN_EGL_EVAL(disp
, ret
);
2403 static EGLint EGLAPIENTRY
2404 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2407 _EGLDisplay
*disp
= NULL
;
2408 _EGLResourceType type
;
2410 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2412 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2413 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2415 if (!_eglIsCurrentThreadDummy()) {
2420 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2423 disp
= _eglLockDisplay(dpy
);
2425 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2427 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2428 if (dpy
!= (EGLDisplay
) object
)
2429 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2431 disp
->Label
= label
;
2432 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2435 switch (objectType
) {
2436 case EGL_OBJECT_CONTEXT_KHR
:
2437 type
= _EGL_RESOURCE_CONTEXT
;
2439 case EGL_OBJECT_SURFACE_KHR
:
2440 type
= _EGL_RESOURCE_SURFACE
;
2442 case EGL_OBJECT_IMAGE_KHR
:
2443 type
= _EGL_RESOURCE_IMAGE
;
2445 case EGL_OBJECT_SYNC_KHR
:
2446 type
= _EGL_RESOURCE_SYNC
;
2448 case EGL_OBJECT_STREAM_KHR
:
2450 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2453 if (_eglCheckResource(object
, type
, disp
)) {
2454 _EGLResource
*res
= (_EGLResource
*) object
;
2457 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2460 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2463 static EGLint EGLAPIENTRY
2464 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2465 const EGLAttrib
*attrib_list
)
2467 unsigned int newEnabled
;
2469 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2471 mtx_lock(_eglGlobal
.Mutex
);
2473 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2474 if (attrib_list
!= NULL
) {
2477 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2478 switch (attrib_list
[i
]) {
2479 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2480 case EGL_DEBUG_MSG_ERROR_KHR
:
2481 case EGL_DEBUG_MSG_WARN_KHR
:
2482 case EGL_DEBUG_MSG_INFO_KHR
:
2483 if (attrib_list
[i
+ 1])
2484 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2486 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2489 // On error, set the last error code, call the current
2490 // debug callback, and return the error code.
2491 mtx_unlock(_eglGlobal
.Mutex
);
2492 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2493 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2494 return EGL_BAD_ATTRIBUTE
;
2499 if (callback
!= NULL
) {
2500 _eglGlobal
.debugCallback
= callback
;
2501 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2503 _eglGlobal
.debugCallback
= NULL
;
2504 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2507 mtx_unlock(_eglGlobal
.Mutex
);
2511 static EGLBoolean EGLAPIENTRY
2512 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2514 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2516 mtx_lock(_eglGlobal
.Mutex
);
2518 switch (attribute
) {
2519 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2520 case EGL_DEBUG_MSG_ERROR_KHR
:
2521 case EGL_DEBUG_MSG_WARN_KHR
:
2522 case EGL_DEBUG_MSG_INFO_KHR
:
2523 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2528 case EGL_DEBUG_CALLBACK_KHR
:
2529 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2532 mtx_unlock(_eglGlobal
.Mutex
);
2533 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2534 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2538 mtx_unlock(_eglGlobal
.Mutex
);
2543 _eglFunctionCompare(const void *key
, const void *elem
)
2545 const char *procname
= key
;
2546 const struct _egl_entrypoint
*entrypoint
= elem
;
2547 return strcmp(procname
, entrypoint
->name
);
2550 static EGLBoolean EGLAPIENTRY
2551 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2552 EGLint
*formats
, EGLint
*num_formats
)
2554 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2558 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2560 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2562 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2565 RETURN_EGL_EVAL(disp
, ret
);
2568 static EGLBoolean EGLAPIENTRY
2569 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2570 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2571 EGLint
*num_modifiers
)
2573 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2577 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2579 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2581 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2582 modifiers
, external_only
,
2585 RETURN_EGL_EVAL(disp
, ret
);
2588 static void EGLAPIENTRY
2589 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2590 EGLGetBlobFuncANDROID get
)
2592 /* This function does not return anything so we cannot
2593 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2595 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2596 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2598 _eglUnlockDisplay(disp
);
2602 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2605 _eglUnlockDisplay(disp
);
2610 _eglError(EGL_BAD_PARAMETER
,
2611 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2612 _eglUnlockDisplay(disp
);
2616 if (disp
->BlobCacheSet
) {
2617 _eglError(EGL_BAD_PARAMETER
,
2618 "eglSetBlobCacheFuncsANDROID: functions already set");
2619 _eglUnlockDisplay(disp
);
2623 disp
->BlobCacheSet
= set
;
2624 disp
->BlobCacheGet
= get
;
2626 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2628 _eglUnlockDisplay(disp
);
2631 static EGLBoolean EGLAPIENTRY
2632 eglQueryDeviceAttribEXT(EGLDeviceEXT device
,
2636 _EGLDevice
*dev
= _eglLookupDevice(device
);
2639 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2641 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, EGL_FALSE
);
2643 ret
= _eglQueryDeviceAttribEXT(dev
, attribute
, value
);
2644 RETURN_EGL_EVAL(NULL
, ret
);
2647 static const char * EGLAPIENTRY
2648 eglQueryDeviceStringEXT(EGLDeviceEXT device
,
2651 _EGLDevice
*dev
= _eglLookupDevice(device
);
2653 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2655 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, NULL
);
2657 RETURN_EGL_EVAL(NULL
, _eglQueryDeviceStringEXT(dev
, name
));
2660 static EGLBoolean EGLAPIENTRY
2661 eglQueryDevicesEXT(EGLint max_devices
,
2662 EGLDeviceEXT
*devices
,
2663 EGLint
*num_devices
)
2667 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2668 ret
= _eglQueryDevicesEXT(max_devices
, (_EGLDevice
**) devices
,
2670 RETURN_EGL_EVAL(NULL
, ret
);
2673 static EGLBoolean EGLAPIENTRY
2674 eglQueryDisplayAttribEXT(EGLDisplay dpy
,
2678 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2681 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2682 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2684 switch (attribute
) {
2685 case EGL_DEVICE_EXT
:
2686 *value
= (EGLAttrib
) disp
->Device
;
2689 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
2691 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
2694 static char * EGLAPIENTRY
2695 eglGetDisplayDriverConfig(EGLDisplay dpy
)
2697 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2701 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2702 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2704 assert(disp
->Extensions
.MESA_query_driver
);
2706 ret
= drv
->API
.QueryDriverConfig(disp
);
2707 RETURN_EGL_EVAL(disp
, ret
);
2710 static const char * EGLAPIENTRY
2711 eglGetDisplayDriverName(EGLDisplay dpy
)
2713 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2717 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2718 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2720 assert(disp
->Extensions
.MESA_query_driver
);
2722 ret
= drv
->API
.QueryDriverName(disp
);
2723 RETURN_EGL_EVAL(disp
, ret
);
2726 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2727 eglGetProcAddress(const char *procname
)
2729 static const struct _egl_entrypoint egl_functions
[] = {
2730 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2731 #include "eglentrypoint.h"
2732 #undef EGL_ENTRYPOINT
2734 _EGLProc ret
= NULL
;
2737 RETURN_EGL_SUCCESS(NULL
, NULL
);
2739 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2741 if (strncmp(procname
, "egl", 3) == 0) {
2742 const struct _egl_entrypoint
*entrypoint
=
2744 egl_functions
, ARRAY_SIZE(egl_functions
),
2745 sizeof(egl_functions
[0]),
2746 _eglFunctionCompare
);
2748 ret
= entrypoint
->function
;
2752 ret
= _eglGetDriverProc(procname
);
2754 RETURN_EGL_SUCCESS(NULL
, ret
);
2758 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2759 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2763 *disp
= _eglLockDisplay(dpy
);
2764 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2766 _eglUnlockDisplay(*disp
);
2767 return MESA_GLINTEROP_INVALID_DISPLAY
;
2770 *drv
= (*disp
)->Driver
;
2772 *ctx
= _eglLookupContext(context
, *disp
);
2774 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2775 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2776 _eglUnlockDisplay(*disp
);
2777 return MESA_GLINTEROP_INVALID_CONTEXT
;
2780 return MESA_GLINTEROP_SUCCESS
;
2784 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2785 struct mesa_glinterop_device_info
*out
)
2792 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2793 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2796 if (drv
->API
.GLInteropQueryDeviceInfo
)
2797 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2799 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2801 _eglUnlockDisplay(disp
);
2806 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2807 struct mesa_glinterop_export_in
*in
,
2808 struct mesa_glinterop_export_out
*out
)
2815 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2816 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2819 if (drv
->API
.GLInteropExportObject
)
2820 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2822 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2824 _eglUnlockDisplay(disp
);