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
);
724 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
726 RETURN_EGL_EVAL(disp
, ret
);
730 EGLBoolean EGLAPIENTRY
731 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
732 EGLint config_size
, EGLint
*num_config
)
734 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
738 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
740 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
741 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
742 config_size
, num_config
);
744 RETURN_EGL_EVAL(disp
, ret
);
748 EGLBoolean EGLAPIENTRY
749 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
750 EGLint attribute
, EGLint
*value
)
752 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
753 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
757 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
759 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
760 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
762 RETURN_EGL_EVAL(disp
, ret
);
766 EGLContext EGLAPIENTRY
767 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
768 const EGLint
*attrib_list
)
770 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
771 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
772 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
774 _EGLContext
*context
;
777 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
779 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
781 if (config
!= EGL_NO_CONFIG_KHR
)
782 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
783 else if (!disp
->Extensions
.KHR_no_config_context
)
784 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
786 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
787 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
789 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
790 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
792 RETURN_EGL_EVAL(disp
, ret
);
796 EGLBoolean EGLAPIENTRY
797 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
799 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
800 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
804 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
806 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
807 _eglUnlinkContext(context
);
808 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
810 RETURN_EGL_EVAL(disp
, ret
);
814 EGLBoolean EGLAPIENTRY
815 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
818 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
819 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
820 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
821 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
825 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
828 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
831 /* display is allowed to be uninitialized under certain condition */
832 if (!disp
->Initialized
) {
833 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
834 ctx
!= EGL_NO_CONTEXT
)
835 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
838 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
840 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
841 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
842 if (!draw_surf
|| !read_surf
) {
843 /* From the EGL 1.4 (20130211) spec:
845 * To release the current context without assigning a new one, set ctx
846 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
848 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
849 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
851 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
852 (!read_surf
&& read
!= EGL_NO_SURFACE
))
853 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
854 if (draw_surf
|| read_surf
)
855 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
858 /* If a native window underlying either draw or read is no longer valid,
859 * an EGL_BAD_NATIVE_WINDOW error is generated.
861 if (draw_surf
&& draw_surf
->Lost
)
862 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
863 if (read_surf
&& read_surf
->Lost
)
864 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
866 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
868 RETURN_EGL_EVAL(disp
, ret
);
872 EGLBoolean EGLAPIENTRY
873 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
874 EGLint attribute
, EGLint
*value
)
876 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
877 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
881 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
883 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
884 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
886 RETURN_EGL_EVAL(disp
, ret
);
890 /* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says
891 * that if native_surface was already used to create a window or pixmap, we
892 * can't create a new one. This is what this function checks for.
895 _eglNativeSurfaceAlreadyUsed(_EGLDisplay
*disp
, void *native_surface
)
899 list
= disp
->ResourceLists
[_EGL_RESOURCE_SURFACE
];
901 _EGLSurface
*surf
= (_EGLSurface
*) list
;
905 if (surf
->Type
== EGL_PBUFFER_BIT
)
908 if (surf
->NativeSurface
== native_surface
)
917 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
918 void *native_window
, const EGLint
*attrib_list
)
920 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
926 if (native_window
== NULL
)
927 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
929 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
930 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
931 /* From the EGL_MESA_platform_surfaceless spec (v1):
933 * eglCreatePlatformWindowSurface fails when called with a <display>
934 * that belongs to the surfaceless platform. It returns
935 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
936 * justification for this unconditional failure is that the
937 * surfaceless platform has no native windows, and therefore the
938 * <native_window> parameter is always invalid.
940 * This check must occur before checking the EGLConfig, which emits
943 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
946 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
948 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
949 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
951 if (_eglNativeSurfaceAlreadyUsed(disp
, native_window
))
952 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
954 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
956 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
958 RETURN_EGL_EVAL(disp
, ret
);
962 EGLSurface EGLAPIENTRY
963 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
964 EGLNativeWindowType window
, const EGLint
*attrib_list
)
966 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
968 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
969 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
970 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
975 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
977 #ifdef HAVE_X11_PLATFORM
978 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
979 /* The `native_window` parameter for the X11 platform differs between
980 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
981 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
982 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
983 * `Window*`. Convert `Window*` to `Window` because that's what
984 * dri2_x11_create_window_surface() expects.
986 return (void *)(* (Window
*) native_window
);
989 return native_window
;
992 static EGLSurface EGLAPIENTRY
993 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
995 const EGLint
*attrib_list
)
997 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
999 native_window
= _fixupNativeWindow(disp
, native_window
);
1001 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1002 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1007 EGLSurface EGLAPIENTRY
1008 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
1009 void *native_window
,
1010 const EGLAttrib
*attrib_list
)
1012 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1014 EGLint
*int_attribs
;
1016 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1018 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1019 if (attrib_list
&& !int_attribs
)
1020 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1022 native_window
= _fixupNativeWindow(disp
, native_window
);
1023 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
1030 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
1032 #ifdef HAVE_X11_PLATFORM
1033 /* The `native_pixmap` parameter for the X11 platform differs between
1034 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1035 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1036 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1037 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1038 * dri2_x11_create_pixmap_surface() expects.
1040 if (disp
&& disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
1041 return (void *)(* (Pixmap
*) native_pixmap
);
1043 return native_pixmap
;
1047 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
1048 void *native_pixmap
, const EGLint
*attrib_list
)
1050 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1055 if (disp
&& (disp
->Platform
== _EGL_PLATFORM_SURFACELESS
||
1056 disp
->Platform
== _EGL_PLATFORM_DEVICE
)) {
1057 /* From the EGL_MESA_platform_surfaceless spec (v1):
1059 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1060 * also fails when called with a <display> that belongs to the
1061 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1062 * EGL_BAD_NATIVE_PIXMAP.
1064 * This check must occur before checking the EGLConfig, which emits
1067 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1070 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1072 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1073 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1075 if (native_pixmap
== NULL
)
1076 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1078 if (_eglNativeSurfaceAlreadyUsed(disp
, native_pixmap
))
1079 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1081 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1083 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1085 RETURN_EGL_EVAL(disp
, ret
);
1089 EGLSurface EGLAPIENTRY
1090 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1091 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1093 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1095 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1096 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1097 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1101 static EGLSurface EGLAPIENTRY
1102 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1103 void *native_pixmap
,
1104 const EGLint
*attrib_list
)
1106 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1108 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1109 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1110 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1115 EGLSurface EGLAPIENTRY
1116 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1117 void *native_pixmap
,
1118 const EGLAttrib
*attrib_list
)
1120 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1122 EGLint
*int_attribs
;
1124 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1126 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1127 if (attrib_list
&& !int_attribs
)
1128 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1130 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1131 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1138 EGLSurface EGLAPIENTRY
1139 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1140 const EGLint
*attrib_list
)
1142 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1143 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1148 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1149 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1151 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1152 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1154 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1155 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1157 RETURN_EGL_EVAL(disp
, ret
);
1161 EGLBoolean EGLAPIENTRY
1162 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1164 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1165 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1169 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1170 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1171 _eglUnlinkSurface(surf
);
1172 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1174 RETURN_EGL_EVAL(disp
, ret
);
1177 EGLBoolean EGLAPIENTRY
1178 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1179 EGLint attribute
, EGLint
*value
)
1181 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1182 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1186 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1187 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1188 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1190 RETURN_EGL_EVAL(disp
, ret
);
1193 EGLBoolean EGLAPIENTRY
1194 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1195 EGLint attribute
, EGLint value
)
1197 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1198 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1202 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1203 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1204 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1206 RETURN_EGL_EVAL(disp
, ret
);
1210 EGLBoolean EGLAPIENTRY
1211 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1213 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1214 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1218 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1219 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1220 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1222 RETURN_EGL_EVAL(disp
, ret
);
1226 EGLBoolean EGLAPIENTRY
1227 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1229 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1230 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1234 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1235 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1236 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1238 RETURN_EGL_EVAL(disp
, ret
);
1242 EGLBoolean EGLAPIENTRY
1243 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1245 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1246 _EGLContext
*ctx
= _eglGetCurrentContext();
1247 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1251 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1252 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1254 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1255 ctx
->Resource
.Display
!= disp
)
1256 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1258 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1259 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1261 if (surf
->Type
!= EGL_WINDOW_BIT
)
1262 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1264 interval
= CLAMP(interval
,
1265 surf
->Config
->MinSwapInterval
,
1266 surf
->Config
->MaxSwapInterval
);
1268 if (surf
->SwapInterval
!= interval
)
1269 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1274 surf
->SwapInterval
= interval
;
1276 RETURN_EGL_EVAL(disp
, ret
);
1280 EGLBoolean EGLAPIENTRY
1281 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1283 _EGLContext
*ctx
= _eglGetCurrentContext();
1284 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1285 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1289 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1290 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1292 /* surface must be bound to current context in EGL 1.4 */
1293 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1294 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1295 surf
!= ctx
->DrawSurface
)
1296 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1299 if (surf
->Type
!= EGL_WINDOW_BIT
)
1300 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1302 /* From the EGL 1.5 spec:
1304 * If eglSwapBuffers is called and the native window associated with
1305 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1309 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1311 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1313 /* EGL_KHR_partial_update
1314 * Frame boundary successfully reached,
1315 * reset damage region and reset BufferAgeRead
1318 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1319 surf
->BufferAgeRead
= EGL_FALSE
;
1322 RETURN_EGL_EVAL(disp
, ret
);
1327 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1328 EGLint
*rects
, EGLint n_rects
)
1330 _EGLContext
*ctx
= _eglGetCurrentContext();
1334 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1336 /* surface must be bound to current context in EGL 1.4 */
1337 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1338 surf
!= ctx
->DrawSurface
)
1339 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1341 if (surf
->Type
!= EGL_WINDOW_BIT
)
1342 RETURN_EGL_EVAL(disp
, EGL_TRUE
);
1344 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1345 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1347 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1349 /* EGL_KHR_partial_update
1350 * Frame boundary successfully reached,
1351 * reset damage region and reset BufferAgeRead
1354 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1355 surf
->BufferAgeRead
= EGL_FALSE
;
1358 RETURN_EGL_EVAL(disp
, ret
);
1361 static EGLBoolean EGLAPIENTRY
1362 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1363 EGLint
*rects
, EGLint n_rects
)
1365 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1366 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1367 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1368 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1371 static EGLBoolean EGLAPIENTRY
1372 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1373 EGLint
*rects
, EGLint n_rects
)
1375 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1376 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1377 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1378 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1382 * Clamp the rectangles so that they lie within the surface.
1386 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1387 EGLint
*rects
, EGLint n_rects
)
1390 EGLint surf_height
= surf
->Height
;
1391 EGLint surf_width
= surf
->Width
;
1393 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1394 EGLint x1
, y1
, x2
, y2
;
1397 x2
= rects
[i
+ 2] + x1
;
1398 y2
= rects
[i
+ 3] + y1
;
1400 rects
[i
] = CLAMP(x1
, 0, surf_width
);
1401 rects
[i
+ 1] = CLAMP(y1
, 0, surf_height
);
1402 rects
[i
+ 2] = CLAMP(x2
, 0, surf_width
) - rects
[i
];
1403 rects
[i
+ 3] = CLAMP(y2
, 0, surf_height
) - rects
[i
+ 1];
1407 static EGLBoolean EGLAPIENTRY
1408 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1409 EGLint
*rects
, EGLint n_rects
)
1411 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1412 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1413 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1414 _EGLContext
*ctx
= _eglGetCurrentContext();
1417 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1419 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1420 surf
->Type
!= EGL_WINDOW_BIT
||
1421 ctx
->DrawSurface
!= surf
||
1422 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1423 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1425 /* If the damage region is already set or
1426 * buffer age is not queried between
1427 * frame boundaries, throw bad access error
1430 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1431 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1433 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1434 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1437 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1439 RETURN_EGL_EVAL(disp
, ret
);
1442 EGLBoolean EGLAPIENTRY
1443 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1445 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1446 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1449 void *native_pixmap_ptr
;
1451 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1452 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1453 native_pixmap_ptr
= (void*) target
;
1455 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1456 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1458 RETURN_EGL_EVAL(disp
, ret
);
1463 _eglWaitClientCommon(void)
1465 _EGLContext
*ctx
= _eglGetCurrentContext();
1471 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1473 disp
= ctx
->Resource
.Display
;
1474 mtx_lock(&disp
->Mutex
);
1476 /* let bad current context imply bad current surface */
1477 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1478 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1479 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1481 /* a valid current context implies an initialized current display */
1482 assert(disp
->Initialized
);
1484 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1486 RETURN_EGL_EVAL(disp
, ret
);
1489 EGLBoolean EGLAPIENTRY
1492 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1493 return _eglWaitClientCommon();
1496 EGLBoolean EGLAPIENTRY
1499 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1500 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1501 return _eglWaitClientCommon();
1505 EGLBoolean EGLAPIENTRY
1506 eglWaitNative(EGLint engine
)
1508 _EGLContext
*ctx
= _eglGetCurrentContext();
1514 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1516 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1518 disp
= ctx
->Resource
.Display
;
1519 mtx_lock(&disp
->Mutex
);
1521 /* let bad current context imply bad current surface */
1522 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1523 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1524 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1526 /* a valid current context implies an initialized current display */
1527 assert(disp
->Initialized
);
1529 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1531 RETURN_EGL_EVAL(disp
, ret
);
1535 EGLDisplay EGLAPIENTRY
1536 eglGetCurrentDisplay(void)
1538 _EGLContext
*ctx
= _eglGetCurrentContext();
1541 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1543 RETURN_EGL_SUCCESS(NULL
, ret
);
1547 EGLContext EGLAPIENTRY
1548 eglGetCurrentContext(void)
1550 _EGLContext
*ctx
= _eglGetCurrentContext();
1553 ret
= _eglGetContextHandle(ctx
);
1555 RETURN_EGL_SUCCESS(NULL
, ret
);
1559 EGLSurface EGLAPIENTRY
1560 eglGetCurrentSurface(EGLint readdraw
)
1562 _EGLContext
*ctx
= _eglGetCurrentContext();
1563 EGLint err
= EGL_SUCCESS
;
1567 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1570 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1574 surf
= ctx
->DrawSurface
;
1577 surf
= ctx
->ReadSurface
;
1581 err
= EGL_BAD_PARAMETER
;
1585 ret
= _eglGetSurfaceHandle(surf
);
1587 RETURN_EGL_ERROR(NULL
, err
, ret
);
1594 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1595 EGLint e
= t
->LastError
;
1596 if (!_eglIsCurrentThreadDummy())
1597 t
->LastError
= EGL_SUCCESS
;
1607 * Specify the client API to use for subsequent calls including:
1608 * eglCreateContext()
1609 * eglGetCurrentContext()
1610 * eglGetCurrentDisplay()
1611 * eglGetCurrentSurface()
1612 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1615 * See section 3.7 "Rendering Context" in the EGL specification for details.
1617 EGLBoolean EGLAPIENTRY
1618 eglBindAPI(EGLenum api
)
1622 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1624 t
= _eglGetCurrentThread();
1625 if (_eglIsCurrentThreadDummy())
1626 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1628 if (!_eglIsApiValid(api
))
1629 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1631 t
->CurrentAPI
= api
;
1633 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1638 * Return the last value set with eglBindAPI().
1643 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1646 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1647 ret
= t
->CurrentAPI
;
1649 RETURN_EGL_SUCCESS(NULL
, ret
);
1653 EGLSurface EGLAPIENTRY
1654 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1655 EGLClientBuffer buffer
, EGLConfig config
,
1656 const EGLint
*attrib_list
)
1658 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1659 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1664 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1666 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1668 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1670 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1672 RETURN_EGL_EVAL(disp
, ret
);
1676 EGLBoolean EGLAPIENTRY
1677 eglReleaseThread(void)
1679 /* unbind current contexts */
1680 if (!_eglIsCurrentThreadDummy()) {
1681 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1682 _EGLContext
*ctx
= t
->CurrentContext
;
1684 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1687 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1690 mtx_lock(&disp
->Mutex
);
1692 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1693 mtx_unlock(&disp
->Mutex
);
1697 _eglDestroyCurrentThread();
1699 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1704 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1705 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1707 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1712 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1713 if (!disp
->Extensions
.KHR_image_base
)
1714 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1715 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1716 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1717 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1718 * <ctx> must be EGL_NO_CONTEXT..."
1720 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1721 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1723 img
= drv
->API
.CreateImageKHR(drv
, disp
, context
, target
,
1725 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1727 RETURN_EGL_EVAL(disp
, ret
);
1730 static EGLImage EGLAPIENTRY
1731 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1732 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1734 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1735 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1736 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1740 EGLImage EGLAPIENTRY
1741 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1742 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1744 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1746 EGLint
*int_attribs
;
1748 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1750 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1751 if (attr_list
&& !int_attribs
)
1752 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1754 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1761 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1766 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1767 if (!disp
->Extensions
.KHR_image_base
)
1768 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1770 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1772 _eglUnlinkImage(img
);
1773 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1775 RETURN_EGL_EVAL(disp
, ret
);
1778 EGLBoolean EGLAPIENTRY
1779 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1781 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1782 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1783 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1784 return _eglDestroyImageCommon(disp
, img
);
1787 static EGLBoolean EGLAPIENTRY
1788 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1790 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1791 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1792 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1793 return _eglDestroyImageCommon(disp
, img
);
1798 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1799 EGLBoolean orig_is_EGLAttrib
,
1800 EGLenum invalid_type_error
)
1802 _EGLContext
*ctx
= _eglGetCurrentContext();
1807 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1809 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1810 /* There exist two EGLAttrib variants of eglCreateSync*:
1811 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1812 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1813 * support as a proxy for EGL 1.5 support, even though that's not
1814 * entirely correct (though _eglComputeVersion does the same).
1816 * The EGL spec provides no guidance on how to handle unsupported
1817 * functions. EGL_BAD_MATCH seems reasonable.
1819 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1822 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1823 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1824 * error is generated.
1827 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1828 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1830 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1831 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1832 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1833 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1836 case EGL_SYNC_FENCE_KHR
:
1837 if (!disp
->Extensions
.KHR_fence_sync
)
1838 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1840 case EGL_SYNC_REUSABLE_KHR
:
1841 if (!disp
->Extensions
.KHR_reusable_sync
)
1842 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1844 case EGL_SYNC_CL_EVENT_KHR
:
1845 if (!disp
->Extensions
.KHR_cl_event2
)
1846 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1848 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1849 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1850 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1853 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1856 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1857 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1859 RETURN_EGL_EVAL(disp
, ret
);
1863 static EGLSync EGLAPIENTRY
1864 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1866 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1867 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1870 EGLAttrib
*attrib_list
;
1873 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1874 attrib_list
= (EGLAttrib
*) int_list
;
1876 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1877 if (err
!= EGL_SUCCESS
)
1878 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1881 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1884 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1887 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1892 static EGLSync EGLAPIENTRY
1893 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1895 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1896 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1897 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1903 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1905 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1906 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1907 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1913 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1918 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1919 assert(disp
->Extensions
.KHR_reusable_sync
||
1920 disp
->Extensions
.KHR_fence_sync
||
1921 disp
->Extensions
.ANDROID_native_fence_sync
);
1924 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1926 RETURN_EGL_EVAL(disp
, ret
);
1929 EGLBoolean EGLAPIENTRY
1930 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1932 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1933 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1934 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1935 return _eglDestroySync(disp
, s
);
1938 static EGLBoolean EGLAPIENTRY
1939 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1941 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1942 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1943 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1944 return _eglDestroySync(disp
, s
);
1949 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1950 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1955 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1956 assert(disp
->Extensions
.KHR_reusable_sync
||
1957 disp
->Extensions
.KHR_fence_sync
||
1958 disp
->Extensions
.ANDROID_native_fence_sync
);
1960 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1961 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1963 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1964 * unlocked here to allow other threads also to be able to
1965 * go into waiting state.
1968 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1969 _eglUnlockDisplay(dpy
);
1971 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1974 * 'disp' is already unlocked for reusable sync type,
1975 * so passing 'NULL' to bypass unlocking display.
1977 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1978 RETURN_EGL_EVAL(NULL
, ret
);
1980 RETURN_EGL_EVAL(disp
, ret
);
1984 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
1985 EGLint flags
, EGLTime timeout
)
1987 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1988 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1989 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1990 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1993 static EGLint EGLAPIENTRY
1994 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
1995 EGLint flags
, EGLTime timeout
)
1997 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1998 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1999 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2000 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
2005 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
2007 _EGLContext
*ctx
= _eglGetCurrentContext();
2011 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2012 assert(disp
->Extensions
.KHR_wait_sync
);
2014 /* return an error if the client API doesn't support GL_OES_EGL_sync */
2015 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
2016 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
2018 /* the API doesn't allow any flags yet */
2020 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2022 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
2024 RETURN_EGL_EVAL(disp
, ret
);
2027 static EGLint EGLAPIENTRY
2028 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2030 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2031 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2032 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2033 return _eglWaitSyncCommon(disp
, s
, flags
);
2037 EGLBoolean EGLAPIENTRY
2038 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
2040 /* The KHR version returns EGLint, while the core version returns
2041 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2044 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2045 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2046 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2047 return _eglWaitSyncCommon(disp
, s
, flags
);
2051 static EGLBoolean EGLAPIENTRY
2052 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
2054 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2055 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2059 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2061 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2062 assert(disp
->Extensions
.KHR_reusable_sync
);
2063 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2065 RETURN_EGL_EVAL(disp
, ret
);
2070 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2075 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2076 assert(disp
->Extensions
.KHR_reusable_sync
||
2077 disp
->Extensions
.KHR_fence_sync
||
2078 disp
->Extensions
.ANDROID_native_fence_sync
);
2079 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2081 RETURN_EGL_EVAL(disp
, ret
);
2084 EGLBoolean EGLAPIENTRY
2085 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2087 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2088 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2089 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2090 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2094 static EGLBoolean EGLAPIENTRY
2095 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2097 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2098 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2102 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2105 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2108 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2110 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2112 * If any error occurs, <*value> is not modified.
2114 if (result
== EGL_FALSE
)
2121 static EGLint EGLAPIENTRY
2122 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2124 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2125 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2129 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2131 /* the spec doesn't seem to specify what happens if the fence
2132 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2135 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2136 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2138 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2139 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2140 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2142 RETURN_EGL_EVAL(disp
, ret
);
2145 static EGLBoolean EGLAPIENTRY
2146 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2147 EGLint numRects
, const EGLint
*rects
)
2149 _EGLContext
*ctx
= _eglGetCurrentContext();
2150 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2151 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2155 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2157 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2159 if (!disp
->Extensions
.NOK_swap_region
)
2160 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2162 /* surface must be bound to current context in EGL 1.4 */
2163 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2164 surf
!= ctx
->DrawSurface
)
2165 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2167 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2169 RETURN_EGL_EVAL(disp
, ret
);
2173 static EGLImage EGLAPIENTRY
2174 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2176 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2181 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2183 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2184 if (!disp
->Extensions
.MESA_drm_image
)
2185 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2187 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2188 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2190 RETURN_EGL_EVAL(disp
, ret
);
2193 static EGLBoolean EGLAPIENTRY
2194 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2195 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2197 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2198 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2202 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2204 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2205 assert(disp
->Extensions
.MESA_drm_image
);
2208 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2210 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2212 RETURN_EGL_EVAL(disp
, ret
);
2218 static EGLBoolean EGLAPIENTRY
2219 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2221 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2225 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2227 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2228 assert(disp
->Extensions
.WL_bind_wayland_display
);
2231 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2233 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2235 RETURN_EGL_EVAL(disp
, ret
);
2238 static EGLBoolean EGLAPIENTRY
2239 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2241 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2245 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2247 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2248 assert(disp
->Extensions
.WL_bind_wayland_display
);
2251 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2253 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2255 RETURN_EGL_EVAL(disp
, ret
);
2258 static EGLBoolean EGLAPIENTRY
2259 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2260 EGLint attribute
, EGLint
*value
)
2262 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2266 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2268 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2269 assert(disp
->Extensions
.WL_bind_wayland_display
);
2272 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2274 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2276 RETURN_EGL_EVAL(disp
, ret
);
2280 static struct wl_buffer
* EGLAPIENTRY
2281 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2283 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2286 struct wl_buffer
*ret
;
2288 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2290 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2291 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2292 RETURN_EGL_EVAL(disp
, NULL
);
2294 img
= _eglLookupImage(image
, disp
);
2297 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2299 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2301 RETURN_EGL_EVAL(disp
, ret
);
2304 static EGLBoolean EGLAPIENTRY
2305 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2306 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2308 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2309 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2313 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2315 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2317 if (!disp
->Extensions
.NV_post_sub_buffer
)
2318 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2320 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2322 RETURN_EGL_EVAL(disp
, ret
);
2325 static EGLBoolean EGLAPIENTRY
2326 eglGetSyncValuesCHROMIUM(EGLDisplay dpy
, EGLSurface surface
,
2327 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2330 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2331 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2335 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2337 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2338 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2339 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2341 if (!ust
|| !msc
|| !sbc
)
2342 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2344 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2346 RETURN_EGL_EVAL(disp
, ret
);
2349 static EGLBoolean EGLAPIENTRY
2350 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2351 EGLint
*fourcc
, EGLint
*nplanes
,
2352 EGLuint64KHR
*modifiers
)
2354 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2355 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2359 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2361 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2362 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2365 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2367 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2370 RETURN_EGL_EVAL(disp
, ret
);
2373 static EGLBoolean EGLAPIENTRY
2374 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2375 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2377 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2378 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2382 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2384 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2385 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2388 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2390 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2392 RETURN_EGL_EVAL(disp
, ret
);
2395 static EGLint EGLAPIENTRY
2396 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2399 _EGLDisplay
*disp
= NULL
;
2400 _EGLResourceType type
;
2402 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2404 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2405 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2407 if (!_eglIsCurrentThreadDummy()) {
2412 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2415 disp
= _eglLockDisplay(dpy
);
2417 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2419 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2420 if (dpy
!= (EGLDisplay
) object
)
2421 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2423 disp
->Label
= label
;
2424 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2427 switch (objectType
) {
2428 case EGL_OBJECT_CONTEXT_KHR
:
2429 type
= _EGL_RESOURCE_CONTEXT
;
2431 case EGL_OBJECT_SURFACE_KHR
:
2432 type
= _EGL_RESOURCE_SURFACE
;
2434 case EGL_OBJECT_IMAGE_KHR
:
2435 type
= _EGL_RESOURCE_IMAGE
;
2437 case EGL_OBJECT_SYNC_KHR
:
2438 type
= _EGL_RESOURCE_SYNC
;
2440 case EGL_OBJECT_STREAM_KHR
:
2442 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2445 if (_eglCheckResource(object
, type
, disp
)) {
2446 _EGLResource
*res
= (_EGLResource
*) object
;
2449 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2452 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2455 static EGLint EGLAPIENTRY
2456 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2457 const EGLAttrib
*attrib_list
)
2459 unsigned int newEnabled
;
2461 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2463 mtx_lock(_eglGlobal
.Mutex
);
2465 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2466 if (attrib_list
!= NULL
) {
2469 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2470 switch (attrib_list
[i
]) {
2471 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2472 case EGL_DEBUG_MSG_ERROR_KHR
:
2473 case EGL_DEBUG_MSG_WARN_KHR
:
2474 case EGL_DEBUG_MSG_INFO_KHR
:
2475 if (attrib_list
[i
+ 1])
2476 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2478 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2481 // On error, set the last error code, call the current
2482 // debug callback, and return the error code.
2483 mtx_unlock(_eglGlobal
.Mutex
);
2484 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2485 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2486 return EGL_BAD_ATTRIBUTE
;
2491 if (callback
!= NULL
) {
2492 _eglGlobal
.debugCallback
= callback
;
2493 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2495 _eglGlobal
.debugCallback
= NULL
;
2496 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2499 mtx_unlock(_eglGlobal
.Mutex
);
2503 static EGLBoolean EGLAPIENTRY
2504 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2506 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2508 mtx_lock(_eglGlobal
.Mutex
);
2510 switch (attribute
) {
2511 case EGL_DEBUG_MSG_CRITICAL_KHR
:
2512 case EGL_DEBUG_MSG_ERROR_KHR
:
2513 case EGL_DEBUG_MSG_WARN_KHR
:
2514 case EGL_DEBUG_MSG_INFO_KHR
:
2515 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2520 case EGL_DEBUG_CALLBACK_KHR
:
2521 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2524 mtx_unlock(_eglGlobal
.Mutex
);
2525 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2526 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2530 mtx_unlock(_eglGlobal
.Mutex
);
2535 _eglFunctionCompare(const void *key
, const void *elem
)
2537 const char *procname
= key
;
2538 const struct _egl_entrypoint
*entrypoint
= elem
;
2539 return strcmp(procname
, entrypoint
->name
);
2542 static EGLBoolean EGLAPIENTRY
2543 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2544 EGLint
*formats
, EGLint
*num_formats
)
2546 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2550 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2552 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2554 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2557 RETURN_EGL_EVAL(disp
, ret
);
2560 static EGLBoolean EGLAPIENTRY
2561 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2562 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2563 EGLint
*num_modifiers
)
2565 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2569 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2571 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2573 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2574 modifiers
, external_only
,
2577 RETURN_EGL_EVAL(disp
, ret
);
2580 static void EGLAPIENTRY
2581 eglSetBlobCacheFuncsANDROID(EGLDisplay
*dpy
, EGLSetBlobFuncANDROID set
,
2582 EGLGetBlobFuncANDROID get
)
2584 /* This function does not return anything so we cannot
2585 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2587 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2588 if (!_eglSetFuncName(__func__
, disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
)) {
2590 _eglUnlockDisplay(disp
);
2594 _EGLDriver
*drv
= _eglCheckDisplay(disp
, __func__
);
2597 _eglUnlockDisplay(disp
);
2602 _eglError(EGL_BAD_PARAMETER
,
2603 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2604 _eglUnlockDisplay(disp
);
2608 if (disp
->BlobCacheSet
) {
2609 _eglError(EGL_BAD_PARAMETER
,
2610 "eglSetBlobCacheFuncsANDROID: functions already set");
2611 _eglUnlockDisplay(disp
);
2615 disp
->BlobCacheSet
= set
;
2616 disp
->BlobCacheGet
= get
;
2618 drv
->API
.SetBlobCacheFuncsANDROID(drv
, disp
, set
, get
);
2620 _eglUnlockDisplay(disp
);
2623 static EGLBoolean EGLAPIENTRY
2624 eglQueryDeviceAttribEXT(EGLDeviceEXT device
,
2628 _EGLDevice
*dev
= _eglLookupDevice(device
);
2631 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2633 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, EGL_FALSE
);
2635 ret
= _eglQueryDeviceAttribEXT(dev
, attribute
, value
);
2636 RETURN_EGL_EVAL(NULL
, ret
);
2639 static const char * EGLAPIENTRY
2640 eglQueryDeviceStringEXT(EGLDeviceEXT device
,
2643 _EGLDevice
*dev
= _eglLookupDevice(device
);
2645 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2647 RETURN_EGL_ERROR(NULL
, EGL_BAD_DEVICE_EXT
, NULL
);
2649 RETURN_EGL_EVAL(NULL
, _eglQueryDeviceStringEXT(dev
, name
));
2652 static EGLBoolean EGLAPIENTRY
2653 eglQueryDevicesEXT(EGLint max_devices
,
2654 EGLDeviceEXT
*devices
,
2655 EGLint
*num_devices
)
2659 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2660 ret
= _eglQueryDevicesEXT(max_devices
, (_EGLDevice
**) devices
,
2662 RETURN_EGL_EVAL(NULL
, ret
);
2665 static EGLBoolean EGLAPIENTRY
2666 eglQueryDisplayAttribEXT(EGLDisplay dpy
,
2670 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2673 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2674 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2676 switch (attribute
) {
2677 case EGL_DEVICE_EXT
:
2678 *value
= (EGLAttrib
) disp
->Device
;
2681 RETURN_EGL_ERROR(disp
, EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
2683 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
2686 static char * EGLAPIENTRY
2687 eglGetDisplayDriverConfig(EGLDisplay dpy
)
2689 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2693 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2694 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2696 assert(disp
->Extensions
.MESA_query_driver
);
2698 ret
= drv
->API
.QueryDriverConfig(disp
);
2699 RETURN_EGL_EVAL(disp
, ret
);
2702 static const char * EGLAPIENTRY
2703 eglGetDisplayDriverName(EGLDisplay dpy
)
2705 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2709 _EGL_FUNC_START(disp
, EGL_NONE
, NULL
, NULL
);
2710 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2712 assert(disp
->Extensions
.MESA_query_driver
);
2714 ret
= drv
->API
.QueryDriverName(disp
);
2715 RETURN_EGL_EVAL(disp
, ret
);
2718 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2719 eglGetProcAddress(const char *procname
)
2721 static const struct _egl_entrypoint egl_functions
[] = {
2722 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2723 #include "eglentrypoint.h"
2724 #undef EGL_ENTRYPOINT
2726 _EGLProc ret
= NULL
;
2729 RETURN_EGL_SUCCESS(NULL
, NULL
);
2731 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2733 if (strncmp(procname
, "egl", 3) == 0) {
2734 const struct _egl_entrypoint
*entrypoint
=
2736 egl_functions
, ARRAY_SIZE(egl_functions
),
2737 sizeof(egl_functions
[0]),
2738 _eglFunctionCompare
);
2740 ret
= entrypoint
->function
;
2744 ret
= _eglGetDriverProc(procname
);
2746 RETURN_EGL_SUCCESS(NULL
, ret
);
2750 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2751 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2755 *disp
= _eglLockDisplay(dpy
);
2756 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2758 _eglUnlockDisplay(*disp
);
2759 return MESA_GLINTEROP_INVALID_DISPLAY
;
2762 *drv
= (*disp
)->Driver
;
2764 *ctx
= _eglLookupContext(context
, *disp
);
2766 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2767 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2768 _eglUnlockDisplay(*disp
);
2769 return MESA_GLINTEROP_INVALID_CONTEXT
;
2772 return MESA_GLINTEROP_SUCCESS
;
2776 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2777 struct mesa_glinterop_device_info
*out
)
2784 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2785 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2788 if (drv
->API
.GLInteropQueryDeviceInfo
)
2789 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2791 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2793 _eglUnlockDisplay(disp
);
2798 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2799 struct mesa_glinterop_export_in
*in
,
2800 struct mesa_glinterop_export_out
*out
)
2807 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2808 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2811 if (drv
->API
.GLInteropExportObject
)
2812 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2814 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2816 _eglUnlockDisplay(disp
);