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_fence_sync
);
498 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
499 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
500 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
501 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
502 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
503 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
504 if (dpy
->Extensions
.KHR_image_base
&& dpy
->Extensions
.KHR_image_pixmap
)
505 _eglAppendExtension(&exts
, "EGL_KHR_image");
506 _EGL_CHECK_EXTENSION(KHR_image_base
);
507 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
508 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
509 _EGL_CHECK_EXTENSION(KHR_partial_update
);
510 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
511 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
512 if (dpy
->Extensions
.EXT_swap_buffers_with_damage
)
513 _eglAppendExtension(&exts
, "EGL_KHR_swap_buffers_with_damage");
514 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
516 if (dpy
->Extensions
.KHR_no_config_context
)
517 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
518 _EGL_CHECK_EXTENSION(MESA_drm_image
);
519 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
521 _EGL_CHECK_EXTENSION(NOK_swap_region
);
522 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
524 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
526 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
527 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
529 #undef _EGL_CHECK_EXTENSION
533 _eglCreateAPIsString(_EGLDisplay
*dpy
)
535 if (dpy
->ClientAPIs
& EGL_OPENGL_BIT
)
536 strcat(dpy
->ClientAPIsString
, "OpenGL ");
538 if (dpy
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
539 dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
540 dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
541 strcat(dpy
->ClientAPIsString
, "OpenGL_ES ");
544 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
545 strcat(dpy
->ClientAPIsString
, "OpenVG ");
547 assert(strlen(dpy
->ClientAPIsString
) < sizeof(dpy
->ClientAPIsString
));
551 _eglComputeVersion(_EGLDisplay
*disp
)
555 if (disp
->Extensions
.KHR_fence_sync
&&
556 disp
->Extensions
.KHR_cl_event2
&&
557 disp
->Extensions
.KHR_wait_sync
&&
558 disp
->Extensions
.KHR_image_base
&&
559 disp
->Extensions
.KHR_gl_texture_2D_image
&&
560 disp
->Extensions
.KHR_gl_texture_3D_image
&&
561 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
562 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
563 disp
->Extensions
.KHR_create_context
&&
564 disp
->Extensions
.EXT_create_context_robustness
&&
565 disp
->Extensions
.KHR_get_all_proc_addresses
&&
566 disp
->Extensions
.KHR_gl_colorspace
&&
567 disp
->Extensions
.KHR_surfaceless_context
)
572 * This is typically the second EGL function that an application calls.
573 * Here we load/initialize the actual hardware driver.
575 EGLBoolean EGLAPIENTRY
576 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
578 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
580 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
583 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
585 if (!disp
->Initialized
) {
586 if (!_eglMatchDriver(disp
, EGL_FALSE
))
587 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
589 /* limit to APIs supported by core */
590 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
592 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
593 * classifies it as an EGL display extension, though conceptually it's an
594 * EGL client extension.
596 * From the EGL_KHR_get_all_proc_addresses spec:
598 * The EGL implementation must expose the name
599 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
600 * EGL_KHR_get_all_proc_addresses and supports
601 * EGL_EXT_client_extensions.
603 * Mesa unconditionally exposes both client extensions mentioned above,
604 * so the spec requires that each EGLDisplay unconditionally expose
605 * EGL_KHR_get_all_proc_addresses also.
607 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
609 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
610 * programs. It is driver agnostic and handled in the main EGL code.
612 disp
->Extensions
.KHR_config_attribs
= EGL_TRUE
;
614 _eglComputeVersion(disp
);
615 _eglCreateExtensionsString(disp
);
616 _eglCreateAPIsString(disp
);
617 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
618 "%d.%d (%s)", disp
->Version
/ 10, disp
->Version
% 10,
622 /* Update applications version of major and minor if not NULL */
623 if ((major
!= NULL
) && (minor
!= NULL
)) {
624 *major
= disp
->Version
/ 10;
625 *minor
= disp
->Version
% 10;
628 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
632 EGLBoolean EGLAPIENTRY
633 eglTerminate(EGLDisplay dpy
)
635 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
637 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
640 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
642 if (disp
->Initialized
) {
643 _EGLDriver
*drv
= disp
->Driver
;
645 drv
->API
.Terminate(drv
, disp
);
646 /* do not reset disp->Driver */
647 disp
->ClientAPIsString
[0] = 0;
648 disp
->Initialized
= EGL_FALSE
;
651 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
655 const char * EGLAPIENTRY
656 eglQueryString(EGLDisplay dpy
, EGLint name
)
661 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
662 const char *ret
= _eglGetClientExtensionString();
664 RETURN_EGL_SUCCESS(NULL
, ret
);
666 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
669 disp
= _eglLockDisplay(dpy
);
670 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, NULL
);
671 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
675 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
677 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
679 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
680 case EGL_CLIENT_APIS
:
681 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
683 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
688 EGLBoolean EGLAPIENTRY
689 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
690 EGLint config_size
, EGLint
*num_config
)
692 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
696 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
698 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
699 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
701 RETURN_EGL_EVAL(disp
, ret
);
705 EGLBoolean EGLAPIENTRY
706 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
707 EGLint config_size
, EGLint
*num_config
)
709 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
713 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
715 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
716 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
717 config_size
, num_config
);
719 RETURN_EGL_EVAL(disp
, ret
);
723 EGLBoolean EGLAPIENTRY
724 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
725 EGLint attribute
, EGLint
*value
)
727 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
728 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
732 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
734 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
735 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
737 RETURN_EGL_EVAL(disp
, ret
);
741 EGLContext EGLAPIENTRY
742 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
743 const EGLint
*attrib_list
)
745 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
746 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
747 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
749 _EGLContext
*context
;
752 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_CONTEXT
);
754 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
756 if (config
!= EGL_NO_CONFIG_KHR
)
757 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
758 else if (!disp
->Extensions
.KHR_no_config_context
)
759 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
761 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
762 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
764 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
765 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
767 RETURN_EGL_EVAL(disp
, ret
);
771 EGLBoolean EGLAPIENTRY
772 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
774 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
775 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
779 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
781 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
782 _eglUnlinkContext(context
);
783 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
785 RETURN_EGL_EVAL(disp
, ret
);
789 EGLBoolean EGLAPIENTRY
790 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
793 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
794 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
795 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
796 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
800 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
803 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
806 /* display is allowed to be uninitialized under certain condition */
807 if (!disp
->Initialized
) {
808 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
809 ctx
!= EGL_NO_CONTEXT
)
810 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
813 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
815 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
816 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
817 if (!draw_surf
|| !read_surf
) {
818 /* From the EGL 1.4 (20130211) spec:
820 * To release the current context without assigning a new one, set ctx
821 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
823 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
824 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
826 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
827 (!read_surf
&& read
!= EGL_NO_SURFACE
))
828 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
829 if (draw_surf
|| read_surf
)
830 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
833 /* If a native window underlying either draw or read is no longer valid,
834 * an EGL_BAD_NATIVE_WINDOW error is generated.
836 if (draw_surf
&& draw_surf
->Lost
)
837 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
838 if (read_surf
&& read_surf
->Lost
)
839 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
841 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
843 RETURN_EGL_EVAL(disp
, ret
);
847 EGLBoolean EGLAPIENTRY
848 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
849 EGLint attribute
, EGLint
*value
)
851 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
852 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
856 _EGL_FUNC_START(disp
, EGL_OBJECT_CONTEXT_KHR
, context
, EGL_FALSE
);
858 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
859 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
861 RETURN_EGL_EVAL(disp
, ret
);
866 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
867 void *native_window
, const EGLint
*attrib_list
)
869 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
875 if (native_window
== NULL
)
876 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
878 #ifdef HAVE_SURFACELESS_PLATFORM
879 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
880 /* From the EGL_MESA_platform_surfaceless spec (v1):
882 * eglCreatePlatformWindowSurface fails when called with a <display>
883 * that belongs to the surfaceless platform. It returns
884 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
885 * justification for this unconditional failure is that the
886 * surfaceless platform has no native windows, and therefore the
887 * <native_window> parameter is always invalid.
889 * This check must occur before checking the EGLConfig, which emits
892 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
896 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
898 if ((conf
->SurfaceType
& EGL_WINDOW_BIT
) == 0)
899 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
901 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
903 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
905 RETURN_EGL_EVAL(disp
, ret
);
909 EGLSurface EGLAPIENTRY
910 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
911 EGLNativeWindowType window
, const EGLint
*attrib_list
)
913 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
915 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
916 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
917 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
922 _fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
924 #ifdef HAVE_X11_PLATFORM
925 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
926 /* The `native_window` parameter for the X11 platform differs between
927 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
928 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
929 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
930 * `Window*`. Convert `Window*` to `Window` because that's what
931 * dri2_x11_create_window_surface() expects.
933 return (void *)(* (Window
*) native_window
);
936 return native_window
;
939 static EGLSurface EGLAPIENTRY
940 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
942 const EGLint
*attrib_list
)
944 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
946 native_window
= _fixupNativeWindow(disp
, native_window
);
948 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
949 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
954 EGLSurface EGLAPIENTRY
955 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
957 const EGLAttrib
*attrib_list
)
959 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
963 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
965 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
966 if (attrib_list
&& !int_attribs
)
967 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
969 native_window
= _fixupNativeWindow(disp
, native_window
);
970 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
977 _fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
979 #ifdef HAVE_X11_PLATFORM
980 /* The `native_pixmap` parameter for the X11 platform differs between
981 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
982 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
983 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
984 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
985 * dri2_x11_create_pixmap_surface() expects.
987 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
988 return (void *)(* (Pixmap
*) native_pixmap
);
990 return native_pixmap
;
994 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
995 void *native_pixmap
, const EGLint
*attrib_list
)
997 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1002 #if HAVE_SURFACELESS_PLATFORM
1003 if (disp
&& disp
->Platform
== _EGL_PLATFORM_SURFACELESS
) {
1004 /* From the EGL_MESA_platform_surfaceless spec (v1):
1006 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1007 * also fails when called with a <display> that belongs to the
1008 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1009 * EGL_BAD_NATIVE_PIXMAP.
1011 * This check must occur before checking the EGLConfig, which emits
1014 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
1018 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1020 if ((conf
->SurfaceType
& EGL_PIXMAP_BIT
) == 0)
1021 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1023 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
1025 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1027 RETURN_EGL_EVAL(disp
, ret
);
1031 EGLSurface EGLAPIENTRY
1032 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1033 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
1035 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1037 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1038 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
1039 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
1043 static EGLSurface EGLAPIENTRY
1044 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
1045 void *native_pixmap
,
1046 const EGLint
*attrib_list
)
1048 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1050 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1051 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1052 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1057 EGLSurface EGLAPIENTRY
1058 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
1059 void *native_pixmap
,
1060 const EGLAttrib
*attrib_list
)
1062 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1064 EGLint
*int_attribs
;
1066 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1068 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
1069 if (attrib_list
&& !int_attribs
)
1070 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
1072 native_pixmap
= _fixupNativePixmap(disp
, native_pixmap
);
1073 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
1080 EGLSurface EGLAPIENTRY
1081 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
1082 const EGLint
*attrib_list
)
1084 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1085 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1090 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1091 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1093 if ((conf
->SurfaceType
& EGL_PBUFFER_BIT
) == 0)
1094 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SURFACE
);
1096 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
1097 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1099 RETURN_EGL_EVAL(disp
, ret
);
1103 EGLBoolean EGLAPIENTRY
1104 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
1106 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1107 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1111 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1112 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1113 _eglUnlinkSurface(surf
);
1114 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
1116 RETURN_EGL_EVAL(disp
, ret
);
1119 EGLBoolean EGLAPIENTRY
1120 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
1121 EGLint attribute
, EGLint
*value
)
1123 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1124 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1128 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1129 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1130 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
1132 RETURN_EGL_EVAL(disp
, ret
);
1135 EGLBoolean EGLAPIENTRY
1136 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
1137 EGLint attribute
, EGLint value
)
1139 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1140 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1144 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1145 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1146 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
1148 RETURN_EGL_EVAL(disp
, ret
);
1152 EGLBoolean EGLAPIENTRY
1153 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1155 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1156 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1160 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1161 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1162 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
1164 RETURN_EGL_EVAL(disp
, ret
);
1168 EGLBoolean EGLAPIENTRY
1169 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
1171 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1172 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1176 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1177 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1178 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
1180 RETURN_EGL_EVAL(disp
, ret
);
1184 EGLBoolean EGLAPIENTRY
1185 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
1187 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1188 _EGLContext
*ctx
= _eglGetCurrentContext();
1189 _EGLSurface
*surf
= ctx
? ctx
->DrawSurface
: NULL
;
1193 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1194 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1196 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1197 ctx
->Resource
.Display
!= disp
)
1198 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1200 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1201 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1203 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1205 RETURN_EGL_EVAL(disp
, ret
);
1209 EGLBoolean EGLAPIENTRY
1210 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1212 _EGLContext
*ctx
= _eglGetCurrentContext();
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
);
1221 /* surface must be bound to current context in EGL 1.4 */
1222 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1223 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1224 surf
!= ctx
->DrawSurface
)
1225 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1228 /* From the EGL 1.5 spec:
1230 * If eglSwapBuffers is called and the native window associated with
1231 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1235 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_FALSE
);
1237 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1239 /* EGL_KHR_partial_update
1240 * Frame boundary successfully reached,
1241 * reset damage region and reset BufferAgeRead
1244 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1245 surf
->BufferAgeRead
= EGL_FALSE
;
1248 RETURN_EGL_EVAL(disp
, ret
);
1253 _eglSwapBuffersWithDamageCommon(_EGLDisplay
*disp
, _EGLSurface
*surf
,
1254 EGLint
*rects
, EGLint n_rects
)
1256 _EGLContext
*ctx
= _eglGetCurrentContext();
1260 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1262 /* surface must be bound to current context in EGL 1.4 */
1263 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1264 surf
!= ctx
->DrawSurface
)
1265 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1267 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1268 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1270 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1272 /* EGL_KHR_partial_update
1273 * Frame boundary successfully reached,
1274 * reset damage region and reset BufferAgeRead
1277 surf
->SetDamageRegionCalled
= EGL_FALSE
;
1278 surf
->BufferAgeRead
= EGL_FALSE
;
1281 RETURN_EGL_EVAL(disp
, ret
);
1284 static EGLBoolean EGLAPIENTRY
1285 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1286 EGLint
*rects
, EGLint n_rects
)
1288 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1289 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1290 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1291 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1294 static EGLBoolean EGLAPIENTRY
1295 eglSwapBuffersWithDamageKHR(EGLDisplay dpy
, EGLSurface surface
,
1296 EGLint
*rects
, EGLint n_rects
)
1298 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1299 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1300 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1301 return _eglSwapBuffersWithDamageCommon(disp
, surf
, rects
, n_rects
);
1305 * If the width of the passed rect is greater than the surface's
1306 * width then it is clamped to the width of the surface. Same with
1311 _eglSetDamageRegionKHRClampRects(_EGLDisplay
* disp
, _EGLSurface
* surf
,
1312 EGLint
*rects
, EGLint n_rects
)
1315 EGLint surf_height
= surf
->Height
;
1316 EGLint surf_width
= surf
->Width
;
1318 for (i
= 0; i
< (4 * n_rects
); i
+= 4) {
1319 EGLint x
, y
, rect_width
, rect_height
;
1322 rect_width
= rects
[i
+ 2];
1323 rect_height
= rects
[i
+ 3];
1325 if (rect_width
> surf_width
- x
)
1326 rects
[i
+ 2] = surf_width
- x
;
1328 if (rect_height
> surf_height
- y
)
1329 rects
[i
+ 3] = surf_height
- y
;
1333 static EGLBoolean EGLAPIENTRY
1334 eglSetDamageRegionKHR(EGLDisplay dpy
, EGLSurface surface
,
1335 EGLint
*rects
, EGLint n_rects
)
1337 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1338 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1339 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1340 _EGLContext
*ctx
= _eglGetCurrentContext();
1343 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1345 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1346 surf
->Type
!= EGL_WINDOW_BIT
||
1347 ctx
->DrawSurface
!= surf
||
1348 surf
->SwapBehavior
!= EGL_BUFFER_DESTROYED
)
1349 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1351 /* If the damage region is already set or
1352 * buffer age is not queried between
1353 * frame boundaries, throw bad access error
1356 if (surf
->SetDamageRegionCalled
|| !surf
->BufferAgeRead
)
1357 RETURN_EGL_ERROR(disp
, EGL_BAD_ACCESS
, EGL_FALSE
);
1359 _eglSetDamageRegionKHRClampRects(disp
, surf
, rects
, n_rects
);
1360 ret
= drv
->API
.SetDamageRegion(drv
, disp
, surf
, rects
, n_rects
);
1363 surf
->SetDamageRegionCalled
= EGL_TRUE
;
1365 RETURN_EGL_EVAL(disp
, ret
);
1368 EGLBoolean EGLAPIENTRY
1369 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1371 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1372 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1375 void *native_pixmap_ptr
;
1377 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
1378 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1379 native_pixmap_ptr
= (void*) target
;
1381 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1382 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
1383 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
1384 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1386 RETURN_EGL_EVAL(disp
, ret
);
1391 _eglWaitClientCommon(void)
1393 _EGLContext
*ctx
= _eglGetCurrentContext();
1399 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1401 disp
= ctx
->Resource
.Display
;
1402 mtx_lock(&disp
->Mutex
);
1404 /* let bad current context imply bad current surface */
1405 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1406 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1407 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1409 /* a valid current context implies an initialized current display */
1410 assert(disp
->Initialized
);
1412 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1414 RETURN_EGL_EVAL(disp
, ret
);
1417 EGLBoolean EGLAPIENTRY
1420 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1421 return _eglWaitClientCommon();
1424 EGLBoolean EGLAPIENTRY
1427 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1428 _EGL_FUNC_START(NULL
, EGL_OBJECT_CONTEXT_KHR
, _eglGetCurrentContext(), EGL_FALSE
);
1429 return _eglWaitClientCommon();
1433 EGLBoolean EGLAPIENTRY
1434 eglWaitNative(EGLint engine
)
1436 _EGLContext
*ctx
= _eglGetCurrentContext();
1442 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1444 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1446 disp
= ctx
->Resource
.Display
;
1447 mtx_lock(&disp
->Mutex
);
1449 /* let bad current context imply bad current surface */
1450 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1451 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1452 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1454 /* a valid current context implies an initialized current display */
1455 assert(disp
->Initialized
);
1457 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1459 RETURN_EGL_EVAL(disp
, ret
);
1463 EGLDisplay EGLAPIENTRY
1464 eglGetCurrentDisplay(void)
1466 _EGLContext
*ctx
= _eglGetCurrentContext();
1469 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1471 RETURN_EGL_SUCCESS(NULL
, ret
);
1475 EGLContext EGLAPIENTRY
1476 eglGetCurrentContext(void)
1478 _EGLContext
*ctx
= _eglGetCurrentContext();
1481 ret
= _eglGetContextHandle(ctx
);
1483 RETURN_EGL_SUCCESS(NULL
, ret
);
1487 EGLSurface EGLAPIENTRY
1488 eglGetCurrentSurface(EGLint readdraw
)
1490 _EGLContext
*ctx
= _eglGetCurrentContext();
1491 EGLint err
= EGL_SUCCESS
;
1495 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_NO_SURFACE
);
1498 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1502 surf
= ctx
->DrawSurface
;
1505 surf
= ctx
->ReadSurface
;
1509 err
= EGL_BAD_PARAMETER
;
1513 ret
= _eglGetSurfaceHandle(surf
);
1515 RETURN_EGL_ERROR(NULL
, err
, ret
);
1522 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1523 EGLint e
= t
->LastError
;
1524 if (!_eglIsCurrentThreadDummy())
1525 t
->LastError
= EGL_SUCCESS
;
1535 * Specify the client API to use for subsequent calls including:
1536 * eglCreateContext()
1537 * eglGetCurrentContext()
1538 * eglGetCurrentDisplay()
1539 * eglGetCurrentSurface()
1540 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1543 * See section 3.7 "Rendering Context" in the EGL specification for details.
1545 EGLBoolean EGLAPIENTRY
1546 eglBindAPI(EGLenum api
)
1550 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1552 t
= _eglGetCurrentThread();
1553 if (_eglIsCurrentThreadDummy())
1554 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1556 if (!_eglIsApiValid(api
))
1557 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1559 t
->CurrentAPI
= api
;
1561 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1566 * Return the last value set with eglBindAPI().
1571 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1574 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1575 ret
= t
->CurrentAPI
;
1577 RETURN_EGL_SUCCESS(NULL
, ret
);
1581 EGLSurface EGLAPIENTRY
1582 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1583 EGLClientBuffer buffer
, EGLConfig config
,
1584 const EGLint
*attrib_list
)
1586 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1587 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1592 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_SURFACE
);
1594 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1596 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1598 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1600 RETURN_EGL_EVAL(disp
, ret
);
1604 EGLBoolean EGLAPIENTRY
1605 eglReleaseThread(void)
1607 /* unbind current contexts */
1608 if (!_eglIsCurrentThreadDummy()) {
1609 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1610 _EGLContext
*ctx
= t
->CurrentContext
;
1612 _EGL_FUNC_START(NULL
, EGL_OBJECT_THREAD_KHR
, NULL
, EGL_FALSE
);
1615 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1618 mtx_lock(&disp
->Mutex
);
1620 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1621 mtx_unlock(&disp
->Mutex
);
1625 _eglDestroyCurrentThread();
1627 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1632 _eglCreateImageCommon(_EGLDisplay
*disp
, EGLContext ctx
, EGLenum target
,
1633 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1635 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1640 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1641 if (!disp
->Extensions
.KHR_image_base
)
1642 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1643 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1644 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1645 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1646 * <ctx> must be EGL_NO_CONTEXT..."
1648 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1649 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1651 img
= drv
->API
.CreateImageKHR(drv
,
1652 disp
, context
, target
, buffer
, attr_list
);
1653 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1655 RETURN_EGL_EVAL(disp
, ret
);
1658 static EGLImage EGLAPIENTRY
1659 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1660 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1662 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1663 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1664 return _eglCreateImageCommon(disp
, ctx
, target
, buffer
, attr_list
);
1668 EGLImage EGLAPIENTRY
1669 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1670 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1672 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1674 EGLint
*int_attribs
;
1676 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_NO_IMAGE_KHR
);
1678 int_attribs
= _eglConvertAttribsToInt(attr_list
);
1679 if (attr_list
&& !int_attribs
)
1680 RETURN_EGL_ERROR(disp
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1682 image
= _eglCreateImageCommon(disp
, ctx
, target
, buffer
, int_attribs
);
1689 _eglDestroyImageCommon(_EGLDisplay
*disp
, _EGLImage
*img
)
1694 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1695 if (!disp
->Extensions
.KHR_image_base
)
1696 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1698 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1700 _eglUnlinkImage(img
);
1701 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1703 RETURN_EGL_EVAL(disp
, ret
);
1706 EGLBoolean EGLAPIENTRY
1707 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1709 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1710 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1711 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1712 return _eglDestroyImageCommon(disp
, img
);
1715 static EGLBoolean EGLAPIENTRY
1716 eglDestroyImageKHR(EGLDisplay dpy
, EGLImage image
)
1718 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1719 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1720 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
1721 return _eglDestroyImageCommon(disp
, img
);
1726 _eglCreateSync(_EGLDisplay
*disp
, EGLenum type
, const EGLAttrib
*attrib_list
,
1727 EGLBoolean orig_is_EGLAttrib
,
1728 EGLenum invalid_type_error
)
1730 _EGLContext
*ctx
= _eglGetCurrentContext();
1735 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1737 if (!disp
->Extensions
.KHR_cl_event2
&& orig_is_EGLAttrib
) {
1738 /* There exist two EGLAttrib variants of eglCreateSync*:
1739 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1740 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1741 * support as a proxy for EGL 1.5 support, even though that's not
1742 * entirely correct (though _eglComputeVersion does the same).
1744 * The EGL spec provides no guidance on how to handle unsupported
1745 * functions. EGL_BAD_MATCH seems reasonable.
1747 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1750 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1751 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1752 * error is generated.
1755 (type
== EGL_SYNC_FENCE_KHR
|| type
== EGL_SYNC_NATIVE_FENCE_ANDROID
))
1756 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1758 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1759 if (ctx
&& (ctx
->Resource
.Display
!= disp
||
1760 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
))
1761 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1764 case EGL_SYNC_FENCE_KHR
:
1765 if (!disp
->Extensions
.KHR_fence_sync
)
1766 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1768 case EGL_SYNC_REUSABLE_KHR
:
1769 if (!disp
->Extensions
.KHR_reusable_sync
)
1770 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1772 case EGL_SYNC_CL_EVENT_KHR
:
1773 if (!disp
->Extensions
.KHR_cl_event2
)
1774 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1776 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
1777 if (!disp
->Extensions
.ANDROID_native_fence_sync
)
1778 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1781 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1784 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1785 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1787 RETURN_EGL_EVAL(disp
, ret
);
1791 static EGLSync EGLAPIENTRY
1792 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*int_list
)
1794 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1795 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1798 EGLAttrib
*attrib_list
;
1801 if (sizeof(int_list
[0]) == sizeof(attrib_list
[0])) {
1802 attrib_list
= (EGLAttrib
*) int_list
;
1804 err
= _eglConvertIntsToAttribs(int_list
, &attrib_list
);
1805 if (err
!= EGL_SUCCESS
)
1806 RETURN_EGL_ERROR(disp
, err
, EGL_NO_SYNC
);
1809 sync
= _eglCreateSync(disp
, type
, attrib_list
, EGL_FALSE
,
1812 if (sizeof(int_list
[0]) != sizeof(attrib_list
[0]))
1815 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1820 static EGLSync EGLAPIENTRY
1821 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1823 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1824 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1825 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1831 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1833 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1834 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
1835 return _eglCreateSync(disp
, type
, attrib_list
, EGL_TRUE
,
1841 _eglDestroySync(_EGLDisplay
*disp
, _EGLSync
*s
)
1846 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1847 assert(disp
->Extensions
.KHR_reusable_sync
||
1848 disp
->Extensions
.KHR_fence_sync
||
1849 disp
->Extensions
.ANDROID_native_fence_sync
);
1852 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1854 RETURN_EGL_EVAL(disp
, ret
);
1857 EGLBoolean EGLAPIENTRY
1858 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1860 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1861 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1862 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1863 return _eglDestroySync(disp
, s
);
1866 static EGLBoolean EGLAPIENTRY
1867 eglDestroySyncKHR(EGLDisplay dpy
, EGLSync sync
)
1869 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1870 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1871 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1872 return _eglDestroySync(disp
, s
);
1877 _eglClientWaitSyncCommon(_EGLDisplay
*disp
, EGLDisplay dpy
,
1878 _EGLSync
*s
, EGLint flags
, EGLTime timeout
)
1883 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1884 assert(disp
->Extensions
.KHR_reusable_sync
||
1885 disp
->Extensions
.KHR_fence_sync
||
1886 disp
->Extensions
.ANDROID_native_fence_sync
);
1888 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1889 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1891 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1892 * unlocked here to allow other threads also to be able to
1893 * go into waiting state.
1896 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1897 _eglUnlockDisplay(dpy
);
1899 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1902 * 'disp' is already unlocked for reusable sync type,
1903 * so passing 'NULL' to bypass unlocking display.
1905 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1906 RETURN_EGL_EVAL(NULL
, ret
);
1908 RETURN_EGL_EVAL(disp
, ret
);
1912 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
,
1913 EGLint flags
, EGLTime timeout
)
1915 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1916 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1917 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1918 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1921 static EGLint EGLAPIENTRY
1922 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
,
1923 EGLint flags
, EGLTime timeout
)
1925 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1926 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1927 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1928 return _eglClientWaitSyncCommon(disp
, dpy
, s
, flags
, timeout
);
1933 _eglWaitSyncCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint flags
)
1935 _EGLContext
*ctx
= _eglGetCurrentContext();
1939 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1940 assert(disp
->Extensions
.KHR_wait_sync
);
1942 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1943 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1944 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1946 /* the API doesn't allow any flags yet */
1948 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1950 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1952 RETURN_EGL_EVAL(disp
, ret
);
1955 static EGLint EGLAPIENTRY
1956 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1958 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1959 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1960 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1961 return _eglWaitSyncCommon(disp
, s
, flags
);
1965 EGLBoolean EGLAPIENTRY
1966 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1968 /* The KHR version returns EGLint, while the core version returns
1969 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1972 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1973 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1974 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1975 return _eglWaitSyncCommon(disp
, s
, flags
);
1979 static EGLBoolean EGLAPIENTRY
1980 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
1982 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1983 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1987 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
1989 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1990 assert(disp
->Extensions
.KHR_reusable_sync
);
1991 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
1993 RETURN_EGL_EVAL(disp
, ret
);
1998 _eglGetSyncAttribCommon(_EGLDisplay
*disp
, _EGLSync
*s
, EGLint attribute
, EGLAttrib
*value
)
2003 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
2004 assert(disp
->Extensions
.KHR_reusable_sync
||
2005 disp
->Extensions
.KHR_fence_sync
||
2006 disp
->Extensions
.ANDROID_native_fence_sync
);
2007 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
2009 RETURN_EGL_EVAL(disp
, ret
);
2012 EGLBoolean EGLAPIENTRY
2013 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
2015 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2016 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2017 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2018 return _eglGetSyncAttribCommon(disp
, s
, attribute
, value
);
2022 static EGLBoolean EGLAPIENTRY
2023 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
2025 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2026 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2030 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2033 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2036 result
= _eglGetSyncAttribCommon(disp
, s
, attribute
, &attrib
);
2038 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2040 * If any error occurs, <*value> is not modified.
2042 if (result
== EGL_FALSE
)
2049 static EGLint EGLAPIENTRY
2050 eglDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
)
2052 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2053 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
2057 _EGL_FUNC_START(disp
, EGL_OBJECT_SYNC_KHR
, s
, EGL_FALSE
);
2059 /* the spec doesn't seem to specify what happens if the fence
2060 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2063 if (!(s
&& (s
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
)))
2064 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_NATIVE_FENCE_FD_ANDROID
);
2066 _EGL_CHECK_SYNC(disp
, s
, EGL_NO_NATIVE_FENCE_FD_ANDROID
, drv
);
2067 assert(disp
->Extensions
.ANDROID_native_fence_sync
);
2068 ret
= drv
->API
.DupNativeFenceFDANDROID(drv
, disp
, s
);
2070 RETURN_EGL_EVAL(disp
, ret
);
2073 static EGLBoolean EGLAPIENTRY
2074 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
2075 EGLint numRects
, const EGLint
*rects
)
2077 _EGLContext
*ctx
= _eglGetCurrentContext();
2078 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2079 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2083 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2085 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2087 if (!disp
->Extensions
.NOK_swap_region
)
2088 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2090 /* surface must be bound to current context in EGL 1.4 */
2091 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
2092 surf
!= ctx
->DrawSurface
)
2093 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
2095 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
2097 RETURN_EGL_EVAL(disp
, ret
);
2101 static EGLImage EGLAPIENTRY
2102 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
2104 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2109 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2111 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
2112 if (!disp
->Extensions
.MESA_drm_image
)
2113 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
2115 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
2116 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
2118 RETURN_EGL_EVAL(disp
, ret
);
2121 static EGLBoolean EGLAPIENTRY
2122 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
2123 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2125 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2126 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2130 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2132 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2133 assert(disp
->Extensions
.MESA_drm_image
);
2136 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2138 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
2140 RETURN_EGL_EVAL(disp
, ret
);
2146 static EGLBoolean EGLAPIENTRY
2147 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2149 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2153 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2155 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2156 assert(disp
->Extensions
.WL_bind_wayland_display
);
2159 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2161 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
2163 RETURN_EGL_EVAL(disp
, ret
);
2166 static EGLBoolean EGLAPIENTRY
2167 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
2169 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2173 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2175 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2176 assert(disp
->Extensions
.WL_bind_wayland_display
);
2179 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2181 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
2183 RETURN_EGL_EVAL(disp
, ret
);
2186 static EGLBoolean EGLAPIENTRY
2187 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
2188 EGLint attribute
, EGLint
*value
)
2190 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2194 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2196 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2197 assert(disp
->Extensions
.WL_bind_wayland_display
);
2200 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2202 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
2204 RETURN_EGL_EVAL(disp
, ret
);
2208 static struct wl_buffer
* EGLAPIENTRY
2209 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
2211 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2214 struct wl_buffer
*ret
;
2216 _EGL_FUNC_START(disp
, EGL_OBJECT_DISPLAY_KHR
, NULL
, EGL_FALSE
);
2218 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
2219 if (!disp
->Extensions
.WL_create_wayland_buffer_from_image
)
2220 RETURN_EGL_EVAL(disp
, NULL
);
2222 img
= _eglLookupImage(image
, disp
);
2225 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
2227 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
2229 RETURN_EGL_EVAL(disp
, ret
);
2232 static EGLBoolean EGLAPIENTRY
2233 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
2234 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
2236 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2237 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2241 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2243 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2245 if (!disp
->Extensions
.NV_post_sub_buffer
)
2246 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2248 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
2250 RETURN_EGL_EVAL(disp
, ret
);
2253 static EGLBoolean EGLAPIENTRY
2254 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
2255 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2258 _EGLDisplay
*disp
= _eglLockDisplay(display
);
2259 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
2263 _EGL_FUNC_START(disp
, EGL_OBJECT_SURFACE_KHR
, surf
, EGL_FALSE
);
2265 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
2266 if (!disp
->Extensions
.CHROMIUM_sync_control
)
2267 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
2269 if (!ust
|| !msc
|| !sbc
)
2270 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2272 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
2274 RETURN_EGL_EVAL(disp
, ret
);
2277 static EGLBoolean EGLAPIENTRY
2278 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
2279 EGLint
*fourcc
, EGLint
*nplanes
,
2280 EGLuint64KHR
*modifiers
)
2282 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2283 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2287 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2289 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2290 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2293 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2295 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
2298 RETURN_EGL_EVAL(disp
, ret
);
2301 static EGLBoolean EGLAPIENTRY
2302 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
2303 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2305 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2306 _EGLImage
*img
= _eglLookupImage(image
, disp
);
2310 _EGL_FUNC_START(disp
, EGL_OBJECT_IMAGE_KHR
, img
, EGL_FALSE
);
2312 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2313 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
2316 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
2318 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
2320 RETURN_EGL_EVAL(disp
, ret
);
2323 static EGLint EGLAPIENTRY
2324 eglLabelObjectKHR(EGLDisplay dpy
, EGLenum objectType
, EGLObjectKHR object
,
2327 _EGLDisplay
*disp
= NULL
;
2328 _EGLResourceType type
;
2330 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2332 if (objectType
== EGL_OBJECT_THREAD_KHR
) {
2333 _EGLThreadInfo
*t
= _eglGetCurrentThread();
2335 if (!_eglIsCurrentThreadDummy()) {
2340 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_BAD_ALLOC
);
2343 disp
= _eglLockDisplay(dpy
);
2345 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_BAD_DISPLAY
);
2347 if (objectType
== EGL_OBJECT_DISPLAY_KHR
) {
2348 if (dpy
!= (EGLDisplay
) object
)
2349 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2351 disp
->Label
= label
;
2352 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2355 switch (objectType
) {
2356 case EGL_OBJECT_CONTEXT_KHR
:
2357 type
= _EGL_RESOURCE_CONTEXT
;
2359 case EGL_OBJECT_SURFACE_KHR
:
2360 type
= _EGL_RESOURCE_SURFACE
;
2362 case EGL_OBJECT_IMAGE_KHR
:
2363 type
= _EGL_RESOURCE_IMAGE
;
2365 case EGL_OBJECT_SYNC_KHR
:
2366 type
= _EGL_RESOURCE_SYNC
;
2368 case EGL_OBJECT_STREAM_KHR
:
2370 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2373 if (_eglCheckResource(object
, type
, disp
)) {
2374 _EGLResource
*res
= (_EGLResource
*) object
;
2377 RETURN_EGL_EVAL(disp
, EGL_SUCCESS
);
2380 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_BAD_PARAMETER
);
2384 _validDebugMessageLevel(EGLAttrib level
)
2386 return (level
>= EGL_DEBUG_MSG_CRITICAL_KHR
&&
2387 level
<= EGL_DEBUG_MSG_INFO_KHR
);
2390 static EGLint EGLAPIENTRY
2391 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback
,
2392 const EGLAttrib
*attrib_list
)
2394 unsigned int newEnabled
;
2396 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2398 mtx_lock(_eglGlobal
.Mutex
);
2400 newEnabled
= _eglGlobal
.debugTypesEnabled
;
2401 if (attrib_list
!= NULL
) {
2404 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
+= 2) {
2405 if (_validDebugMessageLevel(attrib_list
[i
])) {
2406 if (attrib_list
[i
+ 1])
2407 newEnabled
|= DebugBitFromType(attrib_list
[i
]);
2409 newEnabled
&= ~DebugBitFromType(attrib_list
[i
]);
2413 // On error, set the last error code, call the current
2414 // debug callback, and return the error code.
2415 mtx_unlock(_eglGlobal
.Mutex
);
2416 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2417 "Invalid attribute 0x%04lx", (unsigned long) attrib_list
[i
]);
2418 return EGL_BAD_ATTRIBUTE
;
2422 if (callback
!= NULL
) {
2423 _eglGlobal
.debugCallback
= callback
;
2424 _eglGlobal
.debugTypesEnabled
= newEnabled
;
2426 _eglGlobal
.debugCallback
= NULL
;
2427 _eglGlobal
.debugTypesEnabled
= _EGL_DEBUG_BIT_CRITICAL
| _EGL_DEBUG_BIT_ERROR
;
2430 mtx_unlock(_eglGlobal
.Mutex
);
2434 static EGLBoolean EGLAPIENTRY
2435 eglQueryDebugKHR(EGLint attribute
, EGLAttrib
*value
)
2437 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_BAD_ALLOC
);
2439 mtx_lock(_eglGlobal
.Mutex
);
2442 if (_validDebugMessageLevel(attribute
)) {
2443 if (_eglGlobal
.debugTypesEnabled
& DebugBitFromType(attribute
))
2450 if (attribute
== EGL_DEBUG_CALLBACK_KHR
) {
2451 *value
= (EGLAttrib
) _eglGlobal
.debugCallback
;
2455 mtx_unlock(_eglGlobal
.Mutex
);
2456 _eglReportError(EGL_BAD_ATTRIBUTE
, NULL
,
2457 "Invalid attribute 0x%04lx", (unsigned long) attribute
);
2461 mtx_unlock(_eglGlobal
.Mutex
);
2466 _eglFunctionCompare(const void *key
, const void *elem
)
2468 const char *procname
= key
;
2469 const struct _egl_entrypoint
*entrypoint
= elem
;
2470 return strcmp(procname
, entrypoint
->name
);
2473 static EGLBoolean EGLAPIENTRY
2474 eglQueryDmaBufFormatsEXT(EGLDisplay dpy
, EGLint max_formats
,
2475 EGLint
*formats
, EGLint
*num_formats
)
2477 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2481 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2483 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2485 ret
= drv
->API
.QueryDmaBufFormatsEXT(drv
, disp
, max_formats
, formats
,
2488 RETURN_EGL_EVAL(disp
, ret
);
2491 static EGLBoolean EGLAPIENTRY
2492 eglQueryDmaBufModifiersEXT(EGLDisplay dpy
, EGLint format
, EGLint max_modifiers
,
2493 EGLuint64KHR
*modifiers
, EGLBoolean
*external_only
,
2494 EGLint
*num_modifiers
)
2496 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
2500 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, EGL_FALSE
);
2502 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
2504 ret
= drv
->API
.QueryDmaBufModifiersEXT(drv
, disp
, format
, max_modifiers
,
2505 modifiers
, external_only
,
2508 RETURN_EGL_EVAL(disp
, ret
);
2511 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2512 eglGetProcAddress(const char *procname
)
2514 static const struct _egl_entrypoint egl_functions
[] = {
2515 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2516 #include "eglentrypoint.h"
2517 #undef EGL_ENTRYPOINT
2519 _EGLProc ret
= NULL
;
2522 RETURN_EGL_SUCCESS(NULL
, NULL
);
2524 _EGL_FUNC_START(NULL
, EGL_NONE
, NULL
, NULL
);
2526 if (strncmp(procname
, "egl", 3) == 0) {
2527 const struct _egl_entrypoint
*entrypoint
=
2529 egl_functions
, ARRAY_SIZE(egl_functions
),
2530 sizeof(egl_functions
[0]),
2531 _eglFunctionCompare
);
2533 ret
= entrypoint
->function
;
2537 ret
= _eglGetDriverProc(procname
);
2539 RETURN_EGL_SUCCESS(NULL
, ret
);
2543 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
2544 _EGLDisplay
**disp
, _EGLDriver
**drv
,
2548 *disp
= _eglLockDisplay(dpy
);
2549 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
2551 _eglUnlockDisplay(*disp
);
2552 return MESA_GLINTEROP_INVALID_DISPLAY
;
2555 *drv
= (*disp
)->Driver
;
2557 *ctx
= _eglLookupContext(context
, *disp
);
2559 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
2560 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
2561 _eglUnlockDisplay(*disp
);
2562 return MESA_GLINTEROP_INVALID_CONTEXT
;
2565 return MESA_GLINTEROP_SUCCESS
;
2569 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
2570 struct mesa_glinterop_device_info
*out
)
2577 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2578 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2581 if (drv
->API
.GLInteropQueryDeviceInfo
)
2582 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
2584 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2586 _eglUnlockDisplay(disp
);
2591 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
2592 struct mesa_glinterop_export_in
*in
,
2593 struct mesa_glinterop_export_out
*out
)
2600 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
2601 if (ret
!= MESA_GLINTEROP_SUCCESS
)
2604 if (drv
->API
.GLInteropExportObject
)
2605 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
2607 ret
= MESA_GLINTEROP_UNSUPPORTED
;
2609 _eglUnlockDisplay(disp
);