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
89 #include "c99_compat.h"
90 #include "c11/threads.h"
91 #include "GL/mesa_glinterop.h"
92 #include "util/macros.h"
94 #include "eglglobals.h"
95 #include "eglcontext.h"
96 #include "egldisplay.h"
97 #include "egltypedefs.h"
98 #include "eglcurrent.h"
99 #include "egldriver.h"
100 #include "eglsurface.h"
101 #include "eglconfig.h"
102 #include "eglimage.h"
107 * Macros to help return an API entrypoint.
109 * These macros will unlock the display and record the error code.
111 #define RETURN_EGL_ERROR(disp, err, ret) \
114 _eglUnlockDisplay(disp); \
115 /* EGL error codes are non-zero */ \
117 _eglError(err, __func__); \
121 #define RETURN_EGL_SUCCESS(disp, ret) \
122 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
124 /* record EGL_SUCCESS only when ret evaluates to true */
125 #define RETURN_EGL_EVAL(disp, ret) \
126 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
130 * A bunch of macros and checks to simplify error checking.
133 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
135 drv = _eglCheckDisplay(disp, __func__); \
137 RETURN_EGL_ERROR(disp, 0, ret); \
140 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
142 drv = _eglCheck ## type(disp, obj, __func__); \
144 RETURN_EGL_ERROR(disp, 0, ret); \
147 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
148 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
150 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
151 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
153 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
154 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
156 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
157 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
160 struct _egl_entrypoint
{
166 static inline _EGLDriver
*
167 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
170 _eglError(EGL_BAD_DISPLAY
, msg
);
173 if (!disp
->Initialized
) {
174 _eglError(EGL_NOT_INITIALIZED
, msg
);
181 static inline _EGLDriver
*
182 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
184 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
188 _eglError(EGL_BAD_SURFACE
, msg
);
195 static inline _EGLDriver
*
196 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
198 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
202 _eglError(EGL_BAD_CONTEXT
, msg
);
209 static inline _EGLDriver
*
210 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
212 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
216 _eglError(EGL_BAD_CONFIG
, msg
);
223 static inline _EGLDriver
*
224 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
226 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
230 _eglError(EGL_BAD_PARAMETER
, msg
);
238 * Lookup and lock a display.
240 static inline _EGLDisplay
*
241 _eglLockDisplay(EGLDisplay display
)
243 _EGLDisplay
*dpy
= _eglLookupDisplay(display
);
245 mtx_lock(&dpy
->Mutex
);
254 _eglUnlockDisplay(_EGLDisplay
*dpy
)
256 mtx_unlock(&dpy
->Mutex
);
260 _eglSetFuncName(const char *funcName
, _EGLDisplay
*disp
, EGLenum objectType
, _EGLResource
*object
)
262 _EGLThreadInfo
*thr
= _eglGetCurrentThread();
263 if (!_eglIsCurrentThreadDummy()) {
264 thr
->CurrentFuncName
= funcName
;
265 thr
->CurrentObjectLabel
= NULL
;
267 if (objectType
== EGL_OBJECT_THREAD_KHR
)
268 thr
->CurrentObjectLabel
= thr
->Label
;
269 else if (objectType
== EGL_OBJECT_DISPLAY_KHR
&& disp
)
270 thr
->CurrentObjectLabel
= disp
->Label
;
272 thr
->CurrentObjectLabel
= object
->Label
;
277 _eglDebugReportFull(EGL_BAD_ALLOC
, funcName
, funcName
,
278 EGL_DEBUG_MSG_CRITICAL_KHR
, NULL
, NULL
);
282 #define _EGL_FUNC_START(disp, objectType, object, ret) \
284 if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \
286 _eglUnlockDisplay(disp); \
292 * Convert an attribute list from EGLint[] to EGLAttrib[].
294 * Return an EGL error code. The output parameter out_attrib_list is modified
298 _eglConvertIntsToAttribs(const EGLint
*int_list
, EGLAttrib
**out_attrib_list
)
301 EGLAttrib
*attrib_list
;
304 while (int_list
[2*len
] != EGL_NONE
)
309 *out_attrib_list
= NULL
;
313 if (2*len
+ 1 > SIZE_MAX
/ sizeof(EGLAttrib
))
314 return EGL_BAD_ALLOC
;
316 attrib_list
= malloc((2*len
+ 1) * sizeof(EGLAttrib
));
318 return EGL_BAD_ALLOC
;
320 for (size_t i
= 0; i
< len
; ++i
) {
321 attrib_list
[2*i
+ 0] = int_list
[2*i
+ 0];
322 attrib_list
[2*i
+ 1] = int_list
[2*i
+ 1];
325 attrib_list
[2*len
] = EGL_NONE
;
327 *out_attrib_list
= attrib_list
;
333 _eglConvertAttribsToInt(const EGLAttrib
*attr_list
)
335 EGLint
*int_attribs
= NULL
;
337 /* Convert attributes from EGLAttrib[] to EGLint[] */
341 while (attr_list
[size
] != EGL_NONE
)
344 size
+= 1; /* add space for EGL_NONE */
346 int_attribs
= calloc(size
, sizeof(int_attribs
[0]));
350 for (i
= 0; i
< size
; i
++)
351 int_attribs
[i
] = attr_list
[i
];
358 * This is typically the first EGL function that an application calls.
359 * It associates a private _EGLDisplay object to the native display.
361 EGLDisplay EGLAPIENTRY
362 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
364 _EGLPlatformType plat
;
366 void *native_display_ptr
;
368 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
370 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
371 native_display_ptr
= (void*) nativeDisplay
;
373 plat
= _eglGetNativePlatform(native_display_ptr
);
374 dpy
= _eglFindDisplay(plat
, native_display_ptr
);
375 return _eglGetDisplayHandle(dpy
);
379 _eglGetPlatformDisplayCommon(EGLenum platform
, void *native_display
,
380 const EGLint
*attrib_list
)
385 #ifdef HAVE_X11_PLATFORM
386 case EGL_PLATFORM_X11_EXT
:
387 dpy
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
390 #ifdef HAVE_DRM_PLATFORM
391 case EGL_PLATFORM_GBM_MESA
:
392 dpy
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
396 #ifdef HAVE_WAYLAND_PLATFORM
397 case EGL_PLATFORM_WAYLAND_EXT
:
398 dpy
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
402 #ifdef HAVE_SURFACELESS_PLATFORM
403 case EGL_PLATFORM_SURFACELESS_MESA
:
404 dpy
= _eglGetSurfacelessDisplay(native_display
, attrib_list
);
408 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
411 return _eglGetDisplayHandle(dpy
);
414 static EGLDisplay EGLAPIENTRY
415 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
416 const EGLint
*attrib_list
)
418 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
419 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
422 EGLDisplay EGLAPIENTRY
423 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
424 const EGLAttrib
*attrib_list
)
429 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_NO_DISPLAY
);
431 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
432 if (attrib_list
&& !int_attribs
)
433 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
435 display
= _eglGetPlatformDisplayCommon(platform
, native_display
, int_attribs
);
441 * Copy the extension into the string and update the string pointer.
444 _eglAppendExtension(char **str
, const char *ext
)
447 size_t len
= strlen(ext
);
464 * Examine the individual extension enable/disable flags and recompute
465 * the driver's Extensions string.
468 _eglCreateExtensionsString(_EGLDisplay
*dpy
)
470 #define _EGL_CHECK_EXTENSION(ext) \
472 if (dpy->Extensions.ext) { \
473 _eglAppendExtension(&exts, "EGL_" #ext); \
474 assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
478 char *exts
= dpy
->ExtensionsString
;
480 /* Please keep these sorted alphabetically. */
481 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
482 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
483 _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync
);
484 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
486 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
488 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
489 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
490 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
491 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers
);
492 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
494 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
495 _EGL_CHECK_EXTENSION(KHR_config_attribs
);
496 _EGL_CHECK_EXTENSION(KHR_create_context
);
497 _EGL_CHECK_EXTENSION(KHR_create_context_no_error
);
498 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
499 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
500 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
501 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
502 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
503 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
504 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
505 if (dpy
->Extensions
.KHR_image_base
&& dpy
->Extensions
.KHR_image_pixmap
)
506 _eglAppendExtension(&exts
, "EGL_KHR_image");
507 _EGL_CHECK_EXTENSION(KHR_image_base
);
508 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
509 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
510 _EGL_CHECK_EXTENSION(KHR_partial_update
);
511 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
512 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
513 if (dpy
->Extensions
.EXT_swap_buffers_with_damage
)
514 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
515 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
517 if (dpy
->Extensions
.KHR_no_config_context
)
518 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
519 _EGL_CHECK_EXTENSION(MESA_drm_image
);
520 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
522 _EGL_CHECK_EXTENSION(NOK_swap_region
);
523 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
525 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
527 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
528 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
530 #undef _EGL_CHECK_EXTENSION
534 _eglCreateAPIsString(_EGLDisplay
*dpy
)
536 if (dpy
->ClientAPIs
& EGL_OPENGL_BIT
)
537 strcat(dpy
->ClientAPIsString
, "OpenGL ");
539 if (dpy
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
540 dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
541 dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
542 strcat(dpy
->ClientAPIsString
, "OpenGL_ES ");
545 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
546 strcat(dpy
->ClientAPIsString
, "OpenVG ");
548 assert(strlen(dpy
->ClientAPIsString
) < sizeof(dpy
->ClientAPIsString
));
552 _eglComputeVersion(_EGLDisplay
*disp
)
556 if (disp
->Extensions
.KHR_fence_sync
&&
557 disp
->Extensions
.KHR_cl_event2
&&
558 disp
->Extensions
.KHR_wait_sync
&&
559 disp
->Extensions
.KHR_image_base
&&
560 disp
->Extensions
.KHR_gl_texture_2D_image
&&
561 disp
->Extensions
.KHR_gl_texture_3D_image
&&
562 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
563 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
564 disp
->Extensions
.KHR_create_context
&&
565 disp
->Extensions
.EXT_create_context_robustness
&&
566 disp
->Extensions
.KHR_get_all_proc_addresses
&&
567 disp
->Extensions
.KHR_gl_colorspace
&&
568 disp
->Extensions
.KHR_surfaceless_context
)
573 * This is typically the second EGL function that an application calls.
574 * Here we load/initialize the actual hardware driver.
576 EGLBoolean EGLAPIENTRY
577 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
579 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
581 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
584 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
586 if (!disp
->Initialized
) {
587 if (!_eglMatchDriver(disp
, EGL_FALSE
))
588 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
590 /* limit to APIs supported by core */
591 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
593 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
594 * classifies it as an EGL display extension, though conceptually it's an
595 * EGL client extension.
597 * From the EGL_KHR_get_all_proc_addresses spec:
599 * The EGL implementation must expose the name
600 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
601 * EGL_KHR_get_all_proc_addresses and supports
602 * EGL_EXT_client_extensions.
604 * Mesa unconditionally exposes both client extensions mentioned above,
605 * so the spec requires that each EGLDisplay unconditionally expose
606 * EGL_KHR_get_all_proc_addresses also.
608 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
610 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
611 * programs. It is driver agnostic and handled in the main EGL code.
613 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
615 _eglComputeVersion(disp
);
616 _eglCreateExtensionsString(disp
);
617 _eglCreateAPIsString(disp
);
618 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
619 "%d.%d (%s)", disp
->Version
/ 10, disp
->Version
% 10,
623 /* Update applications version of major and minor if not NULL */
624 if ((major
!= NULL
) && (minor
!= NULL
)) {
625 *major
= disp
->Version
/ 10;
626 *minor
= disp
->Version
% 10;
629 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
633 EGLBoolean EGLAPIENTRY
634 eglTerminate(EGLDisplay dpy
)
636 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
638 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
641 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
643 if (disp
->Initialized
) {
644 _EGLDriver
*drv
= disp
->Driver
;
646 drv
->API
.Terminate(drv
, disp
);
647 /* do not reset disp->Driver */
648 disp
->ClientAPIsString
[0] = 0;
649 disp
->Initialized
= EGL_FALSE
;
652 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
656 const char * EGLAPIENTRY
657 eglQueryString(EGLDisplay dpy
, EGLint name
)
662 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
663 const char *ret
= _eglGetClientExtensionString();
665 RETURN_EGL_SUCCESS(NULL
, ret
);
667 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
670 disp
= _eglLockDisplay(dpy
);
671 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
672 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
676 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
678 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
680 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
681 case EGL_CLIENT_APIS
:
682 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
684 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
689 EGLBoolean EGLAPIENTRY
690 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
691 EGLint config_size
, EGLint
*num_config
)
693 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
697 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
699 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
700 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
702 RETURN_EGL_EVAL(disp
, ret
);
706 EGLBoolean EGLAPIENTRY
707 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
708 EGLint config_size
, EGLint
*num_config
)
710 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
714 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
716 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
717 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
718 config_size
, num_config
);
720 RETURN_EGL_EVAL(disp
, ret
);
724 EGLBoolean EGLAPIENTRY
725 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
726 EGLint attribute
, EGLint
*value
)
728 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
729 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
733 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
735 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
736 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
738 RETURN_EGL_EVAL(disp
, ret
);
742 EGLContext EGLAPIENTRY
743 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
744 const EGLint
*attrib_list
)
746 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
747 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
748 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
750 _EGLContext
*context
;
753 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
755 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
757 if (config
!= EGL_NO_CONFIG_KHR
)
758 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
759 else if (!disp
->Extensions
.KHR_no_config_context
)
760 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
762 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
763 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
765 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
766 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
768 RETURN_EGL_EVAL(disp
, ret
);
772 EGLBoolean EGLAPIENTRY
773 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
775 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
776 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
780 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
782 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
783 _eglUnlinkContext(context
);
784 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
786 RETURN_EGL_EVAL(disp
, ret
);
790 EGLBoolean EGLAPIENTRY
791 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
794 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
795 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
796 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
797 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
801 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
804 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
807 /* display is allowed to be uninitialized under certain condition */
808 if (!disp
->Initialized
) {
809 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
810 ctx
!= EGL_NO_CONTEXT
)
811 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
814 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
816 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
817 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
818 if (!draw_surf
|| !read_surf
) {
819 /* From the EGL 1.4 (20130211) spec:
821 * To release the current context without assigning a new one, set ctx
822 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
824 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
825 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
827 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
828 (!read_surf
&& read
!= EGL_NO_SURFACE
))
829 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
830 if (draw_surf
|| read_surf
)
831 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
834 /* If a native window underlying either draw or read is no longer valid,
835 * an EGL_BAD_NATIVE_WINDOW error is generated.
837 if (draw_surf
&& draw_surf
->Lost
)
838 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
839 if (read_surf
&& read_surf
->Lost
)
840 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
842 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
844 RETURN_EGL_EVAL(disp
, ret
);
848 EGLBoolean EGLAPIENTRY
849 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
850 EGLint attribute
, EGLint
*value
)
852 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
853 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
857 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
859 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
860 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
862 RETURN_EGL_EVAL(disp
, ret
);
867 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
868 void *native_window
, const EGLint
*attrib_list
)
870 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
876 if (native_window
== NULL
)
877 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
879 #ifdef HAVE_SURFACELESS_PLATFORM
880 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
881 /* From the EGL_MESA_platform_surfaceless spec (v1):
883 * eglCreatePlatformWindowSurface fails when called with a <display>
884 * that belongs to the surfaceless platform. It returns
885 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
886 * justification for this unconditional failure is that the
887 * surfaceless platform has no native windows, and therefore the
888 * <native_window> parameter is always invalid.
890 * This check must occur before checking the EGLConfig, which emits
893 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
897 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
899 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
900 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
902 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
904 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
906 RETURN_EGL_EVAL(disp
, ret
);
910 EGLSurface EGLAPIENTRY
911 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
912 EGLNativeWindowType window
, const EGLint
*attrib_list
)
914 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
916 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
917 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
918 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
923 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
925 #ifdef HAVE_X11_PLATFORM
926 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
927 /* The `native_window` parameter for the X11 platform differs between
928 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
929 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
930 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
931 * `Window*`. Convert `Window*` to `Window` because that's what
932 * dri2_x11_create_window_surface() expects.
934 return (void *)(* (Window
*) native_window
);
937 return native_window
;
940 static EGLSurface EGLAPIENTRY
941 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
943 const EGLint
*attrib_list
)
945 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
947 native_window
= _fixupNativeWindow(disp
, native_window
);
949 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
950 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
955 EGLSurface EGLAPIENTRY
956 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
958 const EGLAttrib
*attrib_list
)
960 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
964 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
966 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
967 if (attrib_list
&& !int_attribs
)
968 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
970 native_window
= _fixupNativeWindow(disp
, native_window
);
971 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
978 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
980 #ifdef HAVE_X11_PLATFORM
981 /* The `native_pixmap` parameter for the X11 platform differs between
982 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
983 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
984 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
985 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
986 * dri2_x11_create_pixmap_surface() expects.
988 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
989 return (void *)(* (Pixmap
*) native_pixmap
);
991 return native_pixmap
;
995 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
996 void *native_pixmap
, const EGLint
*attrib_list
)
998 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1003 #if HAVE_SURFACELESS_PLATFORM
1004 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
1005 /* From the EGL_MESA_platform_surfaceless spec (v1):
1007 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1008 * also fails when called with a <display> that belongs to the
1009 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1010 * EGL_BAD_NATIVE_PIXMAP.
1012 * This check must occur before checking the EGLConfig, which emits
1015 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1019 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1021 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1022 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1024 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1026 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1028 RETURN_EGL_EVAL(disp
, ret
);
1032 EGLSurface EGLAPIENTRY
1033 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1034 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1036 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1038 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1039 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1040 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1044 static EGLSurface EGLAPIENTRY
1045 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1046 void *native_pixmap
,
1047 const EGLint
*attrib_list
)
1049 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1051 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1052 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1053 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1058 EGLSurface EGLAPIENTRY
1059 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1060 void *native_pixmap
,
1061 const EGLAttrib
*attrib_list
)
1063 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1065 EGLint
*int_attribs
;
1067 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1069 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1070 if (attrib_list
&& !int_attribs
)
1071 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1073 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1074 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1081 EGLSurface EGLAPIENTRY
1082 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1083 const EGLint
*attrib_list
)
1085 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1086 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1091 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1092 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1094 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1095 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1097 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1098 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1100 RETURN_EGL_EVAL(disp
, ret
);
1104 EGLBoolean EGLAPIENTRY
1105 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1107 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1108 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1112 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1113 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1114 _eglUnlinkSurface(surf
);
1115 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1117 RETURN_EGL_EVAL(disp
, ret
);
1120 EGLBoolean EGLAPIENTRY
1121 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1122 EGLint attribute
, EGLint
*value
)
1124 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1125 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1129 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1130 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1131 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1133 RETURN_EGL_EVAL(disp
, ret
);
1136 EGLBoolean EGLAPIENTRY
1137 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1138 EGLint attribute
, EGLint value
)
1140 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1141 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1145 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1146 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1147 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1149 RETURN_EGL_EVAL(disp
, ret
);
1153 EGLBoolean EGLAPIENTRY
1154 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1156 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1157 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1161 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1162 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1163 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1165 RETURN_EGL_EVAL(disp
, ret
);
1169 EGLBoolean EGLAPIENTRY
1170 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
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 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1181 RETURN_EGL_EVAL(disp
, ret
);
1185 EGLBoolean EGLAPIENTRY
1186 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1188 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1189 _EGLContext
*ctx
= _eglGetCurrentContext();
1190 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1194 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1195 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1197 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1198 ctx
->Resource
.Display
!= disp
)
1199 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1201 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1202 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1204 interval
= CLAMP(interval
,
1205 surf
->Config
->MinSwapInterval
,
1206 surf
->Config
->MaxSwapInterval
);
1208 if (surf
->SwapInterval
!= interval
&& drv
->API
.SwapInterval
)
1209 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1214 surf
->SwapInterval
= interval
;
1216 RETURN_EGL_EVAL(disp
, ret
);
1220 EGLBoolean EGLAPIENTRY
1221 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1223 _EGLContext
*ctx
= _eglGetCurrentContext();
1224 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1225 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1229 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1230 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1232 /* surface must be bound to current context in EGL 1.4 */
1233 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1234 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1235 surf
!= ctx
->DrawSurface
)
1236 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1239 /* From the EGL 1.5 spec:
1241 * If eglSwapBuffers is called and the native window associated with
1242 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1246 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1248 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1250 /* EGL_KHR_partial_update
1251 * Frame boundary successfully reached,
1252 * reset damage region and reset BufferAgeRead
1255 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1256 surf
->BufferAgeRead
= EGL_FALSE
;
1259 RETURN_EGL_EVAL(disp
, ret
);
1264 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1265 EGLint
*rects
, EGLint n_rects
)
1267 _EGLContext
*ctx
= _eglGetCurrentContext();
1271 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1273 /* surface must be bound to current context in EGL 1.4 */
1274 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1275 surf
!= ctx
->DrawSurface
)
1276 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1278 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1279 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1281 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1283 /* EGL_KHR_partial_update
1284 * Frame boundary successfully reached,
1285 * reset damage region and reset BufferAgeRead
1288 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1289 surf
->BufferAgeRead
= EGL_FALSE
;
1292 RETURN_EGL_EVAL(disp
, ret
);
1295 static EGLBoolean EGLAPIENTRY
1296 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1297 EGLint
*rects
, EGLint n_rects
)
1299 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1300 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1301 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1302 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1305 static EGLBoolean EGLAPIENTRY
1306 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1307 EGLint
*rects
, EGLint n_rects
)
1309 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1310 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1311 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1312 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1316 * If the width of the passed rect is greater than the surface's
1317 * width then it is clamped to the width of the surface. Same with
1322 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1323 EGLint
*rects
, EGLint n_rects
)
1326 EGLint surf_height
= surf
->Height
;
1327 EGLint surf_width
= surf
->Width
;
1329 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1330 EGLint x
, y
, rect_width
, rect_height
;
1333 rect_width
= rects
[i
+ 2];
1334 rect_height
= rects
[i
+ 3];
1336 if (rect_width
> surf_width
- x
)
1337 rects
[i
+ 2] = surf_width
- x
;
1339 if (rect_height
> surf_height
- y
)
1340 rects
[i
+ 3] = surf_height
- y
;
1344 static EGLBoolean EGLAPIENTRY
1345 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1346 EGLint
*rects
, EGLint n_rects
)
1348 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1349 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1350 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1351 _EGLContext
*ctx
= _eglGetCurrentContext();
1354 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1356 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1357 surf
->Type
!= EGL_WINDOW_BIT
||
1358 ctx
->DrawSurface
!= surf
||
1359 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1360 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1362 /* If the damage region is already set or
1363 * buffer age is not queried between
1364 * frame boundaries, throw bad access error
1367 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1368 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1370 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1371 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1374 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1376 RETURN_EGL_EVAL(disp
, ret
);
1379 EGLBoolean EGLAPIENTRY
1380 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1382 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1383 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1386 void *native_pixmap_ptr
;
1388 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1389 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1390 native_pixmap_ptr
= (void*) target
;
1392 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1393 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
1394 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
1395 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1397 RETURN_EGL_EVAL(disp
, ret
);
1402 _eglWaitClientCommon(void)
1404 _EGLContext
*ctx
= _eglGetCurrentContext();
1410 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1412 disp
= ctx
->Resource
.Display
;
1413 mtx_lock(&disp
->Mutex
);
1415 /* let bad current context imply bad current surface */
1416 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1417 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1418 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1420 /* a valid current context implies an initialized current display */
1421 assert(disp
->Initialized
);
1423 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1425 RETURN_EGL_EVAL(disp
, ret
);
1428 EGLBoolean EGLAPIENTRY
1431 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1432 return _eglWaitClientCommon();
1435 EGLBoolean EGLAPIENTRY
1438 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1439 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1440 return _eglWaitClientCommon();
1444 EGLBoolean EGLAPIENTRY
1445 eglWaitNative(EGLint engine
)
1447 _EGLContext
*ctx
= _eglGetCurrentContext();
1453 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1455 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1457 disp
= ctx
->Resource
.Display
;
1458 mtx_lock(&disp
->Mutex
);
1460 /* let bad current context imply bad current surface */
1461 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1462 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1463 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1465 /* a valid current context implies an initialized current display */
1466 assert(disp
->Initialized
);
1468 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1470 RETURN_EGL_EVAL(disp
, ret
);
1474 EGLDisplay EGLAPIENTRY
1475 eglGetCurrentDisplay(void)
1477 _EGLContext
*ctx
= _eglGetCurrentContext();
1480 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1482 RETURN_EGL_SUCCESS(NULL
, ret
);
1486 EGLContext EGLAPIENTRY
1487 eglGetCurrentContext(void)
1489 _EGLContext
*ctx
= _eglGetCurrentContext();
1492 ret
= _eglGetContextHandle(ctx
);
1494 RETURN_EGL_SUCCESS(NULL
, ret
);
1498 EGLSurface EGLAPIENTRY
1499 eglGetCurrentSurface(EGLint readdraw
)
1501 _EGLContext
*ctx
= _eglGetCurrentContext();
1502 EGLint err
= EGL_SUCCESS
;
1506 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1509 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1513 surf
= ctx
->DrawSurface
;
1516 surf
= ctx
->ReadSurface
;
1520 err
= EGL_BAD_PARAMETER
;
1524 ret
= _eglGetSurfaceHandle(surf
);
1526 RETURN_EGL_ERROR(NULL
, err
, ret
);
1533 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1534 EGLint e
= t
->LastError
;
1535 if (!_eglIsCurrentThreadDummy())
1536 t
->LastError
= EGL_SUCCESS
;
1546 * Specify the client API to use for subsequent calls including:
1547 * eglCreateContext()
1548 * eglGetCurrentContext()
1549 * eglGetCurrentDisplay()
1550 * eglGetCurrentSurface()
1551 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1554 * See section 3.7 "Rendering Context" in the EGL specification for details.
1556 EGLBoolean EGLAPIENTRY
1557 eglBindAPI(EGLenum api
)
1561 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1563 t
= _eglGetCurrentThread();
1564 if (_eglIsCurrentThreadDummy())
1565 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1567 if (!_eglIsApiValid(api
))
1568 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1570 t
->CurrentAPI
= api
;
1572 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1577 * Return the last value set with eglBindAPI().
1582 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1585 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1586 ret
= t
->CurrentAPI
;
1588 RETURN_EGL_SUCCESS(NULL
, ret
);
1592 EGLSurface EGLAPIENTRY
1593 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1594 EGLClientBuffer buffer
, EGLConfig config
,
1595 const EGLint
*attrib_list
)
1597 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1598 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1603 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1605 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1607 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1609 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1611 RETURN_EGL_EVAL(disp
, ret
);
1615 EGLBoolean EGLAPIENTRY
1616 eglReleaseThread(void)
1618 /* unbind current contexts */
1619 if (!_eglIsCurrentThreadDummy()) {
1620 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1621 _EGLContext
*ctx
= t
->CurrentContext
;
1623 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1626 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1629 mtx_lock(&disp
->Mutex
);
1631 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1632 mtx_unlock(&disp
->Mutex
);
1636 _eglDestroyCurrentThread();
1638 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1643 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1644 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1646 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1651 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1652 if (!disp
->Extensions
.KHR_image_base
)
1653 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1654 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1655 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1656 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1657 * <ctx> must be EGL_NO_CONTEXT..."
1659 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1660 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1662 img
= drv
->API
.CreateImageKHR(drv
,
1663 disp
, context
, target
, buffer
, attr_list
);
1664 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1666 RETURN_EGL_EVAL(disp
, ret
);
1669 static EGLImage EGLAPIENTRY
1670 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1671 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1673 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1674 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1675 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1679 EGLImage EGLAPIENTRY
1680 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1681 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1683 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1685 EGLint
*int_attribs
;
1687 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1689 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1690 if (attr_list
&& !int_attribs
)
1691 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1693 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1700 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1705 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1706 if (!disp
->Extensions
.KHR_image_base
)
1707 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1709 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1711 _eglUnlinkImage(img
);
1712 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1714 RETURN_EGL_EVAL(disp
, ret
);
1717 EGLBoolean EGLAPIENTRY
1718 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1720 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1721 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1722 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1723 return _eglDestroyImageCommon(disp
, img
);
1726 static EGLBoolean EGLAPIENTRY
1727 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1729 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1730 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1731 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1732 return _eglDestroyImageCommon(disp
, img
);
1737 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1738 EGLBoolean orig_is_EGLAttrib
,
1739 EGLenum invalid_type_error
)
1741 _EGLContext
*ctx
= _eglGetCurrentContext();
1746 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1748 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1749 /* There exist two EGLAttrib variants of eglCreateSync*:
1750 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1751 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1752 * support as a proxy for EGL 1.5 support, even though that's not
1753 * entirely correct (though _eglComputeVersion does the same).
1755 * The EGL spec provides no guidance on how to handle unsupported
1756 * functions. EGL_BAD_MATCH seems reasonable.
1758 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1761 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1762 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1763 * error is generated.
1766 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1767 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1769 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1770 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1771 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1772 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1775 case EGL_SYNC_FENCE_KHR
:
1776 if (!disp
->Extensions
.KHR_fence_sync
)
1777 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1779 case EGL_SYNC_REUSABLE_KHR
:
1780 if (!disp
->Extensions
.KHR_reusable_sync
)
1781 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1783 case EGL_SYNC_CL_EVENT_KHR
:
1784 if (!disp
->Extensions
.KHR_cl_event2
)
1785 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1787 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1788 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1789 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1792 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1795 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1796 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1798 RETURN_EGL_EVAL(disp
, ret
);
1802 static EGLSync EGLAPIENTRY
1803 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1805 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1806 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1809 EGLAttrib
*attrib_list
;
1812 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1813 attrib_list
= (EGLAttrib
*) int_list
;
1815 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1816 if (err
!= EGL_SUCCESS
)
1817 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1820 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1823 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1826 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1831 static EGLSync EGLAPIENTRY
1832 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1834 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1835 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1836 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1842 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1844 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1845 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1846 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1852 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1857 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1858 assert(disp
->Extensions
.KHR_reusable_sync
||
1859 disp
->Extensions
.KHR_fence_sync
||
1860 disp
->Extensions
.ANDROID_native_fence_sync
);
1863 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1865 RETURN_EGL_EVAL(disp
, ret
);
1868 EGLBoolean EGLAPIENTRY
1869 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1871 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1872 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1873 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1874 return _eglDestroySync(disp
, s
);
1877 static EGLBoolean EGLAPIENTRY
1878 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1880 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1881 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1882 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1883 return _eglDestroySync(disp
, s
);
1888 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1889 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1894 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1895 assert(disp
->Extensions
.KHR_reusable_sync
||
1896 disp
->Extensions
.KHR_fence_sync
||
1897 disp
->Extensions
.ANDROID_native_fence_sync
);
1899 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1900 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1902 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1903 * unlocked here to allow other threads also to be able to
1904 * go into waiting state.
1907 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1908 _eglUnlockDisplay(dpy
);
1910 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1913 * 'disp' is already unlocked for reusable sync type,
1914 * so passing 'NULL' to bypass unlocking display.
1916 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1917 RETURN_EGL_EVAL(NULL
, ret
);
1919 RETURN_EGL_EVAL(disp
, ret
);
1923 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
1924 EGLint flags
, EGLTime timeout
)
1926 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1927 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1928 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1929 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1932 static EGLint EGLAPIENTRY
1933 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
1934 EGLint flags
, EGLTime timeout
)
1936 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1937 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1938 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1939 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1944 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
1946 _EGLContext
*ctx
= _eglGetCurrentContext();
1950 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1951 assert(disp
->Extensions
.KHR_wait_sync
);
1953 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1954 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1955 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1957 /* the API doesn't allow any flags yet */
1959 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1961 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1963 RETURN_EGL_EVAL(disp
, ret
);
1966 static EGLint EGLAPIENTRY
1967 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1969 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1970 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1971 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1972 return _eglWaitSyncCommon(disp
, s
, flags
);
1976 EGLBoolean EGLAPIENTRY
1977 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1979 /* The KHR version returns EGLint, while the core version returns
1980 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1983 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1984 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1985 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1986 return _eglWaitSyncCommon(disp
, s
, flags
);
1990 static EGLBoolean EGLAPIENTRY
1991 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
1993 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1994 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1998 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2000 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2001 assert(disp
->Extensions
.KHR_reusable_sync
);
2002 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
2004 RETURN_EGL_EVAL(disp
, ret
);
2009 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2014 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2015 assert(disp
->Extensions
.KHR_reusable_sync
||
2016 disp
->Extensions
.KHR_fence_sync
||
2017 disp
->Extensions
.ANDROID_native_fence_sync
);
2018 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2020 RETURN_EGL_EVAL(disp
, ret
);
2023 EGLBoolean EGLAPIENTRY
2024 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2026 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2027 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2028 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2029 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2033 static EGLBoolean EGLAPIENTRY
2034 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2036 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2037 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2041 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2044 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2047 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2049 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2051 * If any error occurs, <*value> is not modified.
2053 if (result
== EGL_FALSE
)
2060 static EGLint EGLAPIENTRY
2061 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2063 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2064 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2068 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2070 /* the spec doesn't seem to specify what happens if the fence
2071 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2074 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2075 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2077 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2078 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2079 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2081 RETURN_EGL_EVAL(disp
, ret
);
2084 static EGLBoolean EGLAPIENTRY
2085 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2086 EGLint numRects
, const EGLint
*rects
)
2088 _EGLContext
*ctx
= _eglGetCurrentContext();
2089 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2090 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2094 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2096 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2098 if (!disp
->Extensions
.NOK_swap_region
)
2099 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2101 /* surface must be bound to current context in EGL 1.4 */
2102 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2103 surf
!= ctx
->DrawSurface
)
2104 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2106 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2108 RETURN_EGL_EVAL(disp
, ret
);
2112 static EGLImage EGLAPIENTRY
2113 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2115 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2120 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2122 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2123 if (!disp
->Extensions
.MESA_drm_image
)
2124 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2126 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2127 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2129 RETURN_EGL_EVAL(disp
, ret
);
2132 static EGLBoolean EGLAPIENTRY
2133 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2134 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2136 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2137 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2141 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2143 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2144 assert(disp
->Extensions
.MESA_drm_image
);
2147 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2149 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2151 RETURN_EGL_EVAL(disp
, ret
);
2157 static EGLBoolean EGLAPIENTRY
2158 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2160 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2164 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2166 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2167 assert(disp
->Extensions
.WL_bind_wayland_display
);
2170 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2172 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2174 RETURN_EGL_EVAL(disp
, ret
);
2177 static EGLBoolean EGLAPIENTRY
2178 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2180 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2184 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2186 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2187 assert(disp
->Extensions
.WL_bind_wayland_display
);
2190 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2192 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2194 RETURN_EGL_EVAL(disp
, ret
);
2197 static EGLBoolean EGLAPIENTRY
2198 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2199 EGLint attribute
, EGLint
*value
)
2201 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2205 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2207 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2208 assert(disp
->Extensions
.WL_bind_wayland_display
);
2211 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2213 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2215 RETURN_EGL_EVAL(disp
, ret
);
2219 static struct wl_buffer
* EGLAPIENTRY
2220 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2222 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2225 struct wl_buffer
*ret
;
2227 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2229 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2230 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2231 RETURN_EGL_EVAL(disp
, NULL
);
2233 img
= _eglLookupImage(image
, disp
);
2236 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2238 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2240 RETURN_EGL_EVAL(disp
, ret
);
2243 static EGLBoolean EGLAPIENTRY
2244 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2245 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2247 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2248 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2252 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2254 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2256 if (!disp
->Extensions
.NV_post_sub_buffer
)
2257 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2259 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2261 RETURN_EGL_EVAL(disp
, ret
);
2264 static EGLBoolean EGLAPIENTRY
2265 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
2266 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2269 _EGLDisplay
*disp
= _eglLockDisplay(display
);
2270 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2274 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2276 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2277 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2278 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2280 if (!ust
|| !msc
|| !sbc
)
2281 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2283 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2285 RETURN_EGL_EVAL(disp
, ret
);
2288 static EGLBoolean EGLAPIENTRY
2289 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2290 EGLint
*fourcc
, EGLint
*nplanes
,
2291 EGLuint64KHR
*modifiers
)
2293 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2294 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2298 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2300 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2301 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2304 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2306 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2309 RETURN_EGL_EVAL(disp
, ret
);
2312 static EGLBoolean EGLAPIENTRY
2313 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2314 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2316 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2317 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2321 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2323 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2324 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2327 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2329 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2331 RETURN_EGL_EVAL(disp
, ret
);
2334 static EGLint EGLAPIENTRY
2335 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2338 _EGLDisplay
*disp
= NULL
;
2339 _EGLResourceType type
;
2341 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2343 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2344 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2346 if (!_eglIsCurrentThreadDummy()) {
2351 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2354 disp
= _eglLockDisplay(dpy
);
2356 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2358 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2359 if (dpy
!= (EGLDisplay
) object
)
2360 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2362 disp
->Label
= label
;
2363 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2366 switch (objectType
) {
2367 case EGL_OBJECT_CONTEXT_KHR
:
2368 type
= _EGL_RESOURCE_CONTEXT
;
2370 case EGL_OBJECT_SURFACE_KHR
:
2371 type
= _EGL_RESOURCE_SURFACE
;
2373 case EGL_OBJECT_IMAGE_KHR
:
2374 type
= _EGL_RESOURCE_IMAGE
;
2376 case EGL_OBJECT_SYNC_KHR
:
2377 type
= _EGL_RESOURCE_SYNC
;
2379 case EGL_OBJECT_STREAM_KHR
:
2381 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2384 if (_eglCheckResource(object
, type
, disp
)) {
2385 _EGLResource
*res
= (_EGLResource
*) object
;
2388 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2391 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2395 _validDebugMessageLevel(EGLAttrib level
)
2397 return (level
>= EGL_DEBUG_MSG_CRITICAL_KHR
&&
2398 level
<= EGL_DEBUG_MSG_INFO_KHR
);
2401 static EGLint EGLAPIENTRY
2402 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2403 const EGLAttrib
*attrib_list
)
2405 unsigned int newEnabled
;
2407 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2409 mtx_lock(_eglGlobal
.Mutex
);
2411 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2412 if (attrib_list
!= NULL
) {
2415 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2416 if (_validDebugMessageLevel(attrib_list
[i
])) {
2417 if (attrib_list
[i
+ 1])
2418 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2420 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2424 // On error, set the last error code, call the current
2425 // debug callback, and return the error code.
2426 mtx_unlock(_eglGlobal
.Mutex
);
2427 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2428 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2429 return EGL_BAD_ATTRIBUTE
;
2433 if (callback
!= NULL
) {
2434 _eglGlobal
.debugCallback
= callback
;
2435 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2437 _eglGlobal
.debugCallback
= NULL
;
2438 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2441 mtx_unlock(_eglGlobal
.Mutex
);
2445 static EGLBoolean EGLAPIENTRY
2446 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2448 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2450 mtx_lock(_eglGlobal
.Mutex
);
2453 if (_validDebugMessageLevel(attribute
)) {
2454 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2461 if (attribute
== EGL_DEBUG_CALLBACK_KHR
) {
2462 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2466 mtx_unlock(_eglGlobal
.Mutex
);
2467 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2468 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2472 mtx_unlock(_eglGlobal
.Mutex
);
2477 _eglFunctionCompare(const void *key
, const void *elem
)
2479 const char *procname
= key
;
2480 const struct _egl_entrypoint
*entrypoint
= elem
;
2481 return strcmp(procname
, entrypoint
->name
);
2484 static EGLBoolean EGLAPIENTRY
2485 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2486 EGLint
*formats
, EGLint
*num_formats
)
2488 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2492 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2494 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2496 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2499 RETURN_EGL_EVAL(disp
, ret
);
2502 static EGLBoolean EGLAPIENTRY
2503 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2504 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2505 EGLint
*num_modifiers
)
2507 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2511 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2513 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2515 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2516 modifiers
, external_only
,
2519 RETURN_EGL_EVAL(disp
, ret
);
2522 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2523 eglGetProcAddress(const char *procname
)
2525 static const struct _egl_entrypoint egl_functions
[] = {
2526 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2527 #include "eglentrypoint.h"
2528 #undef EGL_ENTRYPOINT
2530 _EGLProc ret
= NULL
;
2533 RETURN_EGL_SUCCESS(NULL
, NULL
);
2535 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2537 if (strncmp(procname
, "egl", 3) == 0) {
2538 const struct _egl_entrypoint
*entrypoint
=
2540 egl_functions
, ARRAY_SIZE(egl_functions
),
2541 sizeof(egl_functions
[0]),
2542 _eglFunctionCompare
);
2544 ret
= entrypoint
->function
;
2548 ret
= _eglGetDriverProc(procname
);
2550 RETURN_EGL_SUCCESS(NULL
, ret
);
2554 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2555 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2559 *disp
= _eglLockDisplay(dpy
);
2560 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2562 _eglUnlockDisplay(*disp
);
2563 return MESA_GLINTEROP_INVALID_DISPLAY
;
2566 *drv
= (*disp
)->Driver
;
2568 *ctx
= _eglLookupContext(context
, *disp
);
2570 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2571 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2572 _eglUnlockDisplay(*disp
);
2573 return MESA_GLINTEROP_INVALID_CONTEXT
;
2576 return MESA_GLINTEROP_SUCCESS
;
2580 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2581 struct mesa_glinterop_device_info
*out
)
2588 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2589 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2592 if (drv
->API
.GLInteropQueryDeviceInfo
)
2593 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2595 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2597 _eglUnlockDisplay(disp
);
2602 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2603 struct mesa_glinterop_export_in
*in
,
2604 struct mesa_glinterop_export_out
*out
)
2611 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2612 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2615 if (drv
->API
.GLInteropExportObject
)
2616 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2618 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2620 _eglUnlockDisplay(disp
);