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 "eglcompiler.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 static inline _EGLDriver
*
161 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
164 _eglError(EGL_BAD_DISPLAY
, msg
);
167 if (!disp
->Initialized
) {
168 _eglError(EGL_NOT_INITIALIZED
, msg
);
175 static inline _EGLDriver
*
176 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
178 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
182 _eglError(EGL_BAD_SURFACE
, msg
);
189 static inline _EGLDriver
*
190 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
192 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
196 _eglError(EGL_BAD_CONTEXT
, msg
);
203 static inline _EGLDriver
*
204 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
206 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
210 _eglError(EGL_BAD_CONFIG
, msg
);
217 static inline _EGLDriver
*
218 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
220 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
224 _eglError(EGL_BAD_PARAMETER
, msg
);
232 * Lookup and lock a display.
234 static inline _EGLDisplay
*
235 _eglLockDisplay(EGLDisplay display
)
237 _EGLDisplay
*dpy
= _eglLookupDisplay(display
);
239 mtx_lock(&dpy
->Mutex
);
248 _eglUnlockDisplay(_EGLDisplay
*dpy
)
250 mtx_unlock(&dpy
->Mutex
);
255 _eglConvertAttribsToInt(const EGLAttrib
*attr_list
)
257 EGLint
*int_attribs
= NULL
;
259 /* Convert attributes from EGLAttrib[] to EGLint[] */
263 while (attr_list
[size
] != EGL_NONE
)
266 size
+= 1; /* add space for EGL_NONE */
268 int_attribs
= calloc(size
, sizeof(int_attribs
[0]));
272 for (i
= 0; i
< size
; i
++)
273 int_attribs
[i
] = attr_list
[i
];
280 * This is typically the first EGL function that an application calls.
281 * It associates a private _EGLDisplay object to the native display.
283 EGLDisplay EGLAPIENTRY
284 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
286 _EGLPlatformType plat
;
288 void *native_display_ptr
;
290 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
291 native_display_ptr
= (void*) nativeDisplay
;
293 plat
= _eglGetNativePlatform(native_display_ptr
);
294 dpy
= _eglFindDisplay(plat
, native_display_ptr
);
295 return _eglGetDisplayHandle(dpy
);
298 static EGLDisplay EGLAPIENTRY
299 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
300 const EGLint
*attrib_list
)
305 #ifdef HAVE_X11_PLATFORM
306 case EGL_PLATFORM_X11_EXT
:
307 dpy
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
310 #ifdef HAVE_DRM_PLATFORM
311 case EGL_PLATFORM_GBM_MESA
:
312 dpy
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
316 #ifdef HAVE_WAYLAND_PLATFORM
317 case EGL_PLATFORM_WAYLAND_EXT
:
318 dpy
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
323 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
326 return _eglGetDisplayHandle(dpy
);
329 EGLDisplay EGLAPIENTRY
330 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
331 const EGLAttrib
*attrib_list
)
334 EGLint
*int_attribs
= _eglConvertAttribsToInt(attrib_list
);
336 if (attrib_list
&& !int_attribs
)
337 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
339 display
= eglGetPlatformDisplayEXT(platform
, native_display
, int_attribs
);
345 * Copy the extension into the string and update the string pointer.
348 _eglAppendExtension(char **str
, const char *ext
)
351 size_t len
= strlen(ext
);
368 * Examine the individual extension enable/disable flags and recompute
369 * the driver's Extensions string.
372 _eglCreateExtensionsString(_EGLDisplay
*dpy
)
374 #define _EGL_CHECK_EXTENSION(ext) \
376 if (dpy->Extensions.ext) { \
377 _eglAppendExtension(&exts, "EGL_" #ext); \
378 assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
382 char *exts
= dpy
->ExtensionsString
;
384 /* Please keep these sorted alphabetically. */
385 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
386 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
387 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
389 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
391 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
392 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
393 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
394 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
396 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
397 _EGL_CHECK_EXTENSION(KHR_create_context
);
398 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
399 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
400 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
401 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
402 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
403 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
404 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
405 if (dpy
->Extensions
.KHR_image_base
&& dpy
->Extensions
.KHR_image_pixmap
)
406 _eglAppendExtension(&exts
, "EGL_KHR_image");
407 _EGL_CHECK_EXTENSION(KHR_image_base
);
408 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
409 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
410 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
411 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
413 _EGL_CHECK_EXTENSION(MESA_configless_context
);
414 _EGL_CHECK_EXTENSION(MESA_drm_image
);
415 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
417 _EGL_CHECK_EXTENSION(NOK_swap_region
);
418 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
420 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
422 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
423 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
425 #undef _EGL_CHECK_EXTENSION
429 _eglCreateAPIsString(_EGLDisplay
*dpy
)
431 if (dpy
->ClientAPIs
& EGL_OPENGL_BIT
)
432 strcat(dpy
->ClientAPIsString
, "OpenGL ");
434 if (dpy
->ClientAPIs
& EGL_OPENGL_ES_BIT
)
435 strcat(dpy
->ClientAPIsString
, "OpenGL_ES ");
437 if (dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
)
438 strcat(dpy
->ClientAPIsString
, "OpenGL_ES2 ");
440 if (dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
)
441 strcat(dpy
->ClientAPIsString
, "OpenGL_ES3 ");
443 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
444 strcat(dpy
->ClientAPIsString
, "OpenVG ");
446 assert(strlen(dpy
->ClientAPIsString
) < sizeof(dpy
->ClientAPIsString
));
450 _eglComputeVersion(_EGLDisplay
*disp
)
454 if (disp
->Extensions
.KHR_fence_sync
&&
455 disp
->Extensions
.KHR_cl_event2
&&
456 disp
->Extensions
.KHR_wait_sync
&&
457 disp
->Extensions
.KHR_image_base
&&
458 disp
->Extensions
.KHR_gl_texture_2D_image
&&
459 disp
->Extensions
.KHR_gl_texture_3D_image
&&
460 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
461 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
462 disp
->Extensions
.KHR_create_context
&&
463 disp
->Extensions
.EXT_create_context_robustness
&&
464 disp
->Extensions
.KHR_get_all_proc_addresses
&&
465 disp
->Extensions
.KHR_gl_colorspace
&&
466 disp
->Extensions
.KHR_surfaceless_context
)
471 * This is typically the second EGL function that an application calls.
472 * Here we load/initialize the actual hardware driver.
474 EGLBoolean EGLAPIENTRY
475 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
477 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
480 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
482 if (!disp
->Initialized
) {
483 if (!_eglMatchDriver(disp
, EGL_FALSE
))
484 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
486 /* limit to APIs supported by core */
487 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
489 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
490 * classifies it as an EGL display extension, though conceptually it's an
491 * EGL client extension.
493 * From the EGL_KHR_get_all_proc_addresses spec:
495 * The EGL implementation must expose the name
496 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
497 * EGL_KHR_get_all_proc_addresses and supports
498 * EGL_EXT_client_extensions.
500 * Mesa unconditionally exposes both client extensions mentioned above,
501 * so the spec requires that each EGLDisplay unconditionally expose
502 * EGL_KHR_get_all_proc_addresses also.
504 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
506 _eglComputeVersion(disp
);
507 _eglCreateExtensionsString(disp
);
508 _eglCreateAPIsString(disp
);
509 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
510 "%d.%d (%s)", disp
->Version
/ 10, disp
->Version
% 10,
514 /* Update applications version of major and minor if not NULL */
515 if ((major
!= NULL
) && (minor
!= NULL
)) {
516 *major
= disp
->Version
/ 10;
517 *minor
= disp
->Version
% 10;
520 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
524 EGLBoolean EGLAPIENTRY
525 eglTerminate(EGLDisplay dpy
)
527 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
530 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
532 if (disp
->Initialized
) {
533 _EGLDriver
*drv
= disp
->Driver
;
535 drv
->API
.Terminate(drv
, disp
);
536 /* do not reset disp->Driver */
537 disp
->ClientAPIsString
[0] = 0;
538 disp
->Initialized
= EGL_FALSE
;
541 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
545 const char * EGLAPIENTRY
546 eglQueryString(EGLDisplay dpy
, EGLint name
)
551 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
552 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
555 disp
= _eglLockDisplay(dpy
);
556 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
560 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
562 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
564 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
565 case EGL_CLIENT_APIS
:
566 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
568 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
573 EGLBoolean EGLAPIENTRY
574 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
575 EGLint config_size
, EGLint
*num_config
)
577 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
581 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
582 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
584 RETURN_EGL_EVAL(disp
, ret
);
588 EGLBoolean EGLAPIENTRY
589 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
590 EGLint config_size
, EGLint
*num_config
)
592 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
596 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
597 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
598 config_size
, num_config
);
600 RETURN_EGL_EVAL(disp
, ret
);
604 EGLBoolean EGLAPIENTRY
605 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
606 EGLint attribute
, EGLint
*value
)
608 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
609 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
613 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
614 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
616 RETURN_EGL_EVAL(disp
, ret
);
620 EGLContext EGLAPIENTRY
621 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
622 const EGLint
*attrib_list
)
624 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
625 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
626 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
628 _EGLContext
*context
;
631 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
633 if (!config
&& !disp
->Extensions
.MESA_configless_context
)
634 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
636 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
637 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
639 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
640 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
642 RETURN_EGL_EVAL(disp
, ret
);
646 EGLBoolean EGLAPIENTRY
647 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
649 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
650 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
654 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
655 _eglUnlinkContext(context
);
656 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
658 RETURN_EGL_EVAL(disp
, ret
);
662 EGLBoolean EGLAPIENTRY
663 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
666 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
667 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
668 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
669 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
674 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
677 /* display is allowed to be uninitialized under certain condition */
678 if (!disp
->Initialized
) {
679 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
680 ctx
!= EGL_NO_CONTEXT
)
681 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
684 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
686 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
687 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
688 if (!draw_surf
|| !read_surf
) {
689 /* From the EGL 1.4 (20130211) spec:
691 * To release the current context without assigning a new one, set ctx
692 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
694 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
695 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
697 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
698 (!read_surf
&& read
!= EGL_NO_SURFACE
))
699 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
700 if (draw_surf
|| read_surf
)
701 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
704 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
706 RETURN_EGL_EVAL(disp
, ret
);
710 EGLBoolean EGLAPIENTRY
711 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
712 EGLint attribute
, EGLint
*value
)
714 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
715 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
719 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
720 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
722 RETURN_EGL_EVAL(disp
, ret
);
727 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
728 void *native_window
, const EGLint
*attrib_list
)
730 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
735 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
737 if (native_window
== NULL
)
738 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
740 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
742 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
744 RETURN_EGL_EVAL(disp
, ret
);
748 EGLSurface EGLAPIENTRY
749 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
750 EGLNativeWindowType window
, const EGLint
*attrib_list
)
752 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
753 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
754 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
759 static EGLSurface EGLAPIENTRY
760 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
762 const EGLint
*attrib_list
)
764 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
766 #ifdef HAVE_X11_PLATFORM
767 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
768 /* The `native_window` parameter for the X11 platform differs between
769 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
770 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
771 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
772 * `Window*`. Convert `Window*` to `Window` because that's what
773 * dri2_x11_create_window_surface() expects.
775 native_window
= (void*) (* (Window
*) native_window
);
779 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
784 EGLSurface EGLAPIENTRY
785 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
787 const EGLAttrib
*attrib_list
)
790 EGLint
*int_attribs
= _eglConvertAttribsToInt(attrib_list
);
792 if (attrib_list
&& !int_attribs
)
793 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
795 surface
= eglCreatePlatformWindowSurfaceEXT(dpy
, config
, native_window
,
803 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
804 void *native_pixmap
, const EGLint
*attrib_list
)
806 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
811 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
812 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
814 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
816 RETURN_EGL_EVAL(disp
, ret
);
820 EGLSurface EGLAPIENTRY
821 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
822 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
824 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
825 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
826 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
830 static EGLSurface EGLAPIENTRY
831 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
833 const EGLint
*attrib_list
)
835 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
837 #ifdef HAVE_X11_PLATFORM
838 /* The `native_pixmap` parameter for the X11 platform differs between
839 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
840 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
841 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
842 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
843 * dri2_x11_create_pixmap_surface() expects.
845 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
) {
846 native_pixmap
= (void*) (* (Pixmap
*) native_pixmap
);
850 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
855 EGLSurface EGLAPIENTRY
856 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
858 const EGLAttrib
*attrib_list
)
861 EGLint
*int_attribs
= _eglConvertAttribsToInt(attrib_list
);
863 if (attrib_list
&& !int_attribs
)
864 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
866 surface
= eglCreatePlatformPixmapSurfaceEXT(dpy
, config
, native_pixmap
,
873 EGLSurface EGLAPIENTRY
874 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
875 const EGLint
*attrib_list
)
877 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
878 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
883 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
885 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
886 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
888 RETURN_EGL_EVAL(disp
, ret
);
892 EGLBoolean EGLAPIENTRY
893 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
895 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
896 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
900 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
901 _eglUnlinkSurface(surf
);
902 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
904 RETURN_EGL_EVAL(disp
, ret
);
907 EGLBoolean EGLAPIENTRY
908 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
909 EGLint attribute
, EGLint
*value
)
911 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
912 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
916 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
917 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
919 RETURN_EGL_EVAL(disp
, ret
);
922 EGLBoolean EGLAPIENTRY
923 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
924 EGLint attribute
, EGLint value
)
926 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
927 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
931 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
932 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
934 RETURN_EGL_EVAL(disp
, ret
);
938 EGLBoolean EGLAPIENTRY
939 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
941 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
942 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
946 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
947 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
949 RETURN_EGL_EVAL(disp
, ret
);
953 EGLBoolean EGLAPIENTRY
954 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
956 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
957 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
961 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
962 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
964 RETURN_EGL_EVAL(disp
, ret
);
968 EGLBoolean EGLAPIENTRY
969 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
971 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
972 _EGLContext
*ctx
= _eglGetCurrentContext();
977 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
979 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
980 ctx
->Resource
.Display
!= disp
)
981 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
983 surf
= ctx
->DrawSurface
;
984 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
985 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
987 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
989 RETURN_EGL_EVAL(disp
, ret
);
993 EGLBoolean EGLAPIENTRY
994 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
996 _EGLContext
*ctx
= _eglGetCurrentContext();
997 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
998 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1002 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1004 /* surface must be bound to current context in EGL 1.4 */
1005 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1006 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1007 surf
!= ctx
->DrawSurface
)
1008 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1011 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1013 RETURN_EGL_EVAL(disp
, ret
);
1017 static EGLBoolean EGLAPIENTRY
1018 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1019 EGLint
*rects
, EGLint n_rects
)
1021 _EGLContext
*ctx
= _eglGetCurrentContext();
1022 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1023 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1027 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1029 /* surface must be bound to current context in EGL 1.4 */
1030 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1031 surf
!= ctx
->DrawSurface
)
1032 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1034 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1035 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1037 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1039 RETURN_EGL_EVAL(disp
, ret
);
1042 EGLBoolean EGLAPIENTRY
1043 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1045 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1046 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1049 void *native_pixmap_ptr
;
1051 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1052 native_pixmap_ptr
= (void*) target
;
1054 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1055 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
1056 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
1057 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1059 RETURN_EGL_EVAL(disp
, ret
);
1063 EGLBoolean EGLAPIENTRY
1066 _EGLContext
*ctx
= _eglGetCurrentContext();
1072 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1074 disp
= ctx
->Resource
.Display
;
1075 mtx_lock(&disp
->Mutex
);
1077 /* let bad current context imply bad current surface */
1078 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1079 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1080 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1082 /* a valid current context implies an initialized current display */
1083 assert(disp
->Initialized
);
1085 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1087 RETURN_EGL_EVAL(disp
, ret
);
1091 EGLBoolean EGLAPIENTRY
1094 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1095 EGLint api_index
= t
->CurrentAPIIndex
;
1096 EGLint es_index
= _eglConvertApiToIndex(EGL_OPENGL_ES_API
);
1099 if (api_index
!= es_index
&& _eglIsCurrentThreadDummy())
1100 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1102 t
->CurrentAPIIndex
= es_index
;
1103 ret
= eglWaitClient();
1104 t
->CurrentAPIIndex
= api_index
;
1109 EGLBoolean EGLAPIENTRY
1110 eglWaitNative(EGLint engine
)
1112 _EGLContext
*ctx
= _eglGetCurrentContext();
1118 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1120 disp
= ctx
->Resource
.Display
;
1121 mtx_lock(&disp
->Mutex
);
1123 /* let bad current context imply bad current surface */
1124 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1125 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1126 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1128 /* a valid current context implies an initialized current display */
1129 assert(disp
->Initialized
);
1131 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1133 RETURN_EGL_EVAL(disp
, ret
);
1137 EGLDisplay EGLAPIENTRY
1138 eglGetCurrentDisplay(void)
1140 _EGLContext
*ctx
= _eglGetCurrentContext();
1143 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1145 RETURN_EGL_SUCCESS(NULL
, ret
);
1149 EGLContext EGLAPIENTRY
1150 eglGetCurrentContext(void)
1152 _EGLContext
*ctx
= _eglGetCurrentContext();
1155 ret
= _eglGetContextHandle(ctx
);
1157 RETURN_EGL_SUCCESS(NULL
, ret
);
1161 EGLSurface EGLAPIENTRY
1162 eglGetCurrentSurface(EGLint readdraw
)
1164 _EGLContext
*ctx
= _eglGetCurrentContext();
1165 EGLint err
= EGL_SUCCESS
;
1170 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1174 surf
= ctx
->DrawSurface
;
1177 surf
= ctx
->ReadSurface
;
1181 err
= EGL_BAD_PARAMETER
;
1185 ret
= _eglGetSurfaceHandle(surf
);
1187 RETURN_EGL_ERROR(NULL
, err
, ret
);
1194 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1195 EGLint e
= t
->LastError
;
1196 if (!_eglIsCurrentThreadDummy())
1197 t
->LastError
= EGL_SUCCESS
;
1207 * Specify the client API to use for subsequent calls including:
1208 * eglCreateContext()
1209 * eglGetCurrentContext()
1210 * eglGetCurrentDisplay()
1211 * eglGetCurrentSurface()
1212 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1215 * See section 3.7 "Rendering Context" in the EGL specification for details.
1217 EGLBoolean EGLAPIENTRY
1218 eglBindAPI(EGLenum api
)
1220 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1222 if (_eglIsCurrentThreadDummy())
1223 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1225 if (!_eglIsApiValid(api
))
1226 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1228 t
->CurrentAPIIndex
= _eglConvertApiToIndex(api
);
1230 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1235 * Return the last value set with eglBindAPI().
1240 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1243 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1244 ret
= _eglConvertApiFromIndex(t
->CurrentAPIIndex
);
1246 RETURN_EGL_SUCCESS(NULL
, ret
);
1250 EGLSurface EGLAPIENTRY
1251 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1252 EGLClientBuffer buffer
, EGLConfig config
,
1253 const EGLint
*attrib_list
)
1255 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1256 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1261 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1263 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1265 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1267 RETURN_EGL_EVAL(disp
, ret
);
1271 EGLBoolean EGLAPIENTRY
1272 eglReleaseThread(void)
1274 /* unbind current contexts */
1275 if (!_eglIsCurrentThreadDummy()) {
1276 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1277 EGLint api_index
= t
->CurrentAPIIndex
;
1280 for (i
= 0; i
< _EGL_API_NUM_APIS
; i
++) {
1281 _EGLContext
*ctx
= t
->CurrentContexts
[i
];
1283 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1286 t
->CurrentAPIIndex
= i
;
1288 mtx_lock(&disp
->Mutex
);
1290 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1291 mtx_unlock(&disp
->Mutex
);
1295 t
->CurrentAPIIndex
= api_index
;
1298 _eglDestroyCurrentThread();
1300 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1304 static EGLImage EGLAPIENTRY
1305 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1306 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1308 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1309 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1314 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1315 if (!disp
->Extensions
.KHR_image_base
)
1316 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1317 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1318 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1319 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1320 * <ctx> must be EGL_NO_CONTEXT..."
1322 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1323 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1325 img
= drv
->API
.CreateImageKHR(drv
,
1326 disp
, context
, target
, buffer
, attr_list
);
1327 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1329 RETURN_EGL_EVAL(disp
, ret
);
1333 EGLImage EGLAPIENTRY
1334 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1335 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1338 EGLint
*int_attribs
= _eglConvertAttribsToInt(attr_list
);
1340 if (attr_list
&& !int_attribs
)
1341 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1343 image
= eglCreateImageKHR(dpy
, ctx
, target
, buffer
, int_attribs
);
1349 EGLBoolean EGLAPIENTRY
1350 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1352 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1353 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1357 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1358 if (!disp
->Extensions
.KHR_image_base
)
1359 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1361 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1363 _eglUnlinkImage(img
);
1364 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1366 RETURN_EGL_EVAL(disp
, ret
);
1371 _eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLint
*attrib_list
,
1372 const EGLAttrib
*attrib_list64
, EGLBoolean is64
,
1373 EGLenum invalid_type_error
)
1375 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1376 _EGLContext
*ctx
= _eglGetCurrentContext();
1381 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1383 if (!disp
->Extensions
.KHR_cl_event2
&& is64
)
1384 RETURN_EGL_EVAL(disp
, EGL_NO_SYNC_KHR
);
1386 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1387 if (!ctx
|| ctx
->Resource
.Display
!= dpy
||
1388 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1389 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1392 case EGL_SYNC_FENCE_KHR
:
1393 if (!disp
->Extensions
.KHR_fence_sync
)
1394 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1396 case EGL_SYNC_REUSABLE_KHR
:
1397 if (!disp
->Extensions
.KHR_reusable_sync
)
1398 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1400 case EGL_SYNC_CL_EVENT_KHR
:
1401 if (!disp
->Extensions
.KHR_cl_event2
)
1402 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1405 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1408 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
, attrib_list64
);
1409 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1411 RETURN_EGL_EVAL(disp
, ret
);
1415 static EGLSync EGLAPIENTRY
1416 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*attrib_list
)
1418 return _eglCreateSync(dpy
, type
, attrib_list
, NULL
, EGL_FALSE
,
1423 static EGLSync EGLAPIENTRY
1424 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1426 return _eglCreateSync(dpy
, type
, NULL
, attrib_list
, EGL_TRUE
,
1432 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1434 return _eglCreateSync(dpy
, type
, NULL
, attrib_list
, EGL_TRUE
,
1439 EGLBoolean EGLAPIENTRY
1440 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1442 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1443 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1447 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1448 assert(disp
->Extensions
.KHR_reusable_sync
||
1449 disp
->Extensions
.KHR_fence_sync
);
1452 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1454 RETURN_EGL_EVAL(disp
, ret
);
1459 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
, EGLTime timeout
)
1461 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1462 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1466 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1467 assert(disp
->Extensions
.KHR_reusable_sync
||
1468 disp
->Extensions
.KHR_fence_sync
);
1470 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1471 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1473 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1474 * unlocked here to allow other threads also to be able to
1475 * go into waiting state.
1478 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1479 _eglUnlockDisplay(dpy
);
1481 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1484 * 'disp' is already unlocked for reusable sync type,
1485 * so passing 'NULL' to bypass unlocking display.
1487 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1488 RETURN_EGL_EVAL(NULL
, ret
);
1490 RETURN_EGL_EVAL(disp
, ret
);
1494 static EGLint EGLAPIENTRY
1495 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1497 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1498 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1499 _EGLContext
*ctx
= _eglGetCurrentContext();
1503 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1504 assert(disp
->Extensions
.KHR_wait_sync
);
1506 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1507 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1508 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1510 /* the API doesn't allow any flags yet */
1512 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1514 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1516 RETURN_EGL_EVAL(disp
, ret
);
1520 EGLBoolean EGLAPIENTRY
1521 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1523 /* The KHR version returns EGLint, while the core version returns
1524 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1527 return eglWaitSyncKHR(dpy
, sync
, flags
);
1531 static EGLBoolean EGLAPIENTRY
1532 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
1534 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1535 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1539 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1540 assert(disp
->Extensions
.KHR_reusable_sync
);
1541 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
1543 RETURN_EGL_EVAL(disp
, ret
);
1547 EGLBoolean EGLAPIENTRY
1548 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
1550 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1551 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1555 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1556 assert(disp
->Extensions
.KHR_reusable_sync
||
1557 disp
->Extensions
.KHR_fence_sync
);
1558 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
1560 RETURN_EGL_EVAL(disp
, ret
);
1564 static EGLBoolean EGLAPIENTRY
1565 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
1571 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1574 result
= eglGetSyncAttrib(dpy
, sync
, attribute
, &attrib
);
1576 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
1578 * If any error occurs, <*value> is not modified.
1580 if (result
== EGL_FALSE
)
1588 static EGLBoolean EGLAPIENTRY
1589 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
1590 EGLint numRects
, const EGLint
*rects
)
1592 _EGLContext
*ctx
= _eglGetCurrentContext();
1593 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1594 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1598 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1600 if (!disp
->Extensions
.NOK_swap_region
)
1601 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1603 /* surface must be bound to current context in EGL 1.4 */
1604 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1605 surf
!= ctx
->DrawSurface
)
1606 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1608 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
1610 RETURN_EGL_EVAL(disp
, ret
);
1614 static EGLImage EGLAPIENTRY
1615 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
1617 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1622 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1623 if (!disp
->Extensions
.MESA_drm_image
)
1624 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1626 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
1627 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1629 RETURN_EGL_EVAL(disp
, ret
);
1632 static EGLBoolean EGLAPIENTRY
1633 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
1634 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
1636 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1637 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1641 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1642 assert(disp
->Extensions
.MESA_drm_image
);
1645 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1647 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
1649 RETURN_EGL_EVAL(disp
, ret
);
1655 static EGLBoolean EGLAPIENTRY
1656 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1658 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1662 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1663 assert(disp
->Extensions
.WL_bind_wayland_display
);
1666 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1668 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
1670 RETURN_EGL_EVAL(disp
, ret
);
1673 static EGLBoolean EGLAPIENTRY
1674 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1676 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1680 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1681 assert(disp
->Extensions
.WL_bind_wayland_display
);
1684 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1686 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
1688 RETURN_EGL_EVAL(disp
, ret
);
1691 static EGLBoolean EGLAPIENTRY
1692 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
1693 EGLint attribute
, EGLint
*value
)
1695 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1699 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1700 assert(disp
->Extensions
.WL_bind_wayland_display
);
1703 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1705 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
1707 RETURN_EGL_EVAL(disp
, ret
);
1711 static struct wl_buffer
* EGLAPIENTRY
1712 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
1714 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1717 struct wl_buffer
*ret
;
1719 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
1720 assert(disp
->Extensions
.WL_create_wayland_buffer_from_image
);
1722 img
= _eglLookupImage(image
, disp
);
1725 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
1727 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
1729 RETURN_EGL_EVAL(disp
, ret
);
1732 static EGLBoolean EGLAPIENTRY
1733 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
1734 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
1736 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1737 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1741 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1743 if (!disp
->Extensions
.NV_post_sub_buffer
)
1744 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1746 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
1748 RETURN_EGL_EVAL(disp
, ret
);
1751 static EGLBoolean EGLAPIENTRY
1752 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
1753 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
1756 _EGLDisplay
*disp
= _eglLockDisplay(display
);
1757 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1761 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1762 if (!disp
->Extensions
.CHROMIUM_sync_control
)
1763 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1765 if (!ust
|| !msc
|| !sbc
)
1766 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1768 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
1770 RETURN_EGL_EVAL(disp
, ret
);
1773 static EGLBoolean EGLAPIENTRY
1774 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
1775 EGLint
*fourcc
, EGLint
*nplanes
,
1776 EGLuint64KHR
*modifiers
)
1778 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1779 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1783 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1784 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
1787 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1789 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
1792 RETURN_EGL_EVAL(disp
, ret
);
1795 static EGLBoolean EGLAPIENTRY
1796 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
1797 int *fds
, EGLint
*strides
, EGLint
*offsets
)
1799 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1800 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1804 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1805 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
1808 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1810 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
1812 RETURN_EGL_EVAL(disp
, ret
);
1815 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
1816 eglGetProcAddress(const char *procname
)
1818 static const struct {
1821 } egl_functions
[] = {
1822 /* core functions queryable in the presence of
1823 * EGL_KHR_get_all_proc_addresses or EGL 1.5
1825 /* alphabetical order */
1826 { "eglBindAPI", (_EGLProc
) eglBindAPI
},
1827 { "eglBindTexImage", (_EGLProc
) eglBindTexImage
},
1828 { "eglChooseConfig", (_EGLProc
) eglChooseConfig
},
1829 { "eglCopyBuffers", (_EGLProc
) eglCopyBuffers
},
1830 { "eglCreateContext", (_EGLProc
) eglCreateContext
},
1831 { "eglCreatePbufferFromClientBuffer", (_EGLProc
) eglCreatePbufferFromClientBuffer
},
1832 { "eglCreatePbufferSurface", (_EGLProc
) eglCreatePbufferSurface
},
1833 { "eglCreatePixmapSurface", (_EGLProc
) eglCreatePixmapSurface
},
1834 { "eglCreateWindowSurface", (_EGLProc
) eglCreateWindowSurface
},
1835 { "eglDestroyContext", (_EGLProc
) eglDestroyContext
},
1836 { "eglDestroySurface", (_EGLProc
) eglDestroySurface
},
1837 { "eglGetConfigAttrib", (_EGLProc
) eglGetConfigAttrib
},
1838 { "eglGetConfigs", (_EGLProc
) eglGetConfigs
},
1839 { "eglGetCurrentContext", (_EGLProc
) eglGetCurrentContext
},
1840 { "eglGetCurrentDisplay", (_EGLProc
) eglGetCurrentDisplay
},
1841 { "eglGetCurrentSurface", (_EGLProc
) eglGetCurrentSurface
},
1842 { "eglGetDisplay", (_EGLProc
) eglGetDisplay
},
1843 { "eglGetError", (_EGLProc
) eglGetError
},
1844 { "eglGetProcAddress", (_EGLProc
) eglGetProcAddress
},
1845 { "eglInitialize", (_EGLProc
) eglInitialize
},
1846 { "eglMakeCurrent", (_EGLProc
) eglMakeCurrent
},
1847 { "eglQueryAPI", (_EGLProc
) eglQueryAPI
},
1848 { "eglQueryContext", (_EGLProc
) eglQueryContext
},
1849 { "eglQueryString", (_EGLProc
) eglQueryString
},
1850 { "eglQuerySurface", (_EGLProc
) eglQuerySurface
},
1851 { "eglReleaseTexImage", (_EGLProc
) eglReleaseTexImage
},
1852 { "eglReleaseThread", (_EGLProc
) eglReleaseThread
},
1853 { "eglSurfaceAttrib", (_EGLProc
) eglSurfaceAttrib
},
1854 { "eglSwapBuffers", (_EGLProc
) eglSwapBuffers
},
1855 { "eglSwapInterval", (_EGLProc
) eglSwapInterval
},
1856 { "eglTerminate", (_EGLProc
) eglTerminate
},
1857 { "eglWaitClient", (_EGLProc
) eglWaitClient
},
1858 { "eglWaitGL", (_EGLProc
) eglWaitGL
},
1859 { "eglWaitNative", (_EGLProc
) eglWaitNative
},
1860 { "eglCreateSync", (_EGLProc
) eglCreateSync
},
1861 { "eglDestroySync", (_EGLProc
) eglDestroySync
},
1862 { "eglClientWaitSync", (_EGLProc
) eglClientWaitSync
},
1863 { "eglGetSyncAttrib", (_EGLProc
) eglGetSyncAttrib
},
1864 { "eglWaitSync", (_EGLProc
) eglWaitSync
},
1865 { "eglCreateImage", (_EGLProc
) eglCreateImage
},
1866 { "eglDestroyImage", (_EGLProc
) eglDestroyImage
},
1867 { "eglGetPlatformDisplay", (_EGLProc
) eglGetPlatformDisplay
},
1868 { "eglCreatePlatformWindowSurface", (_EGLProc
) eglCreatePlatformWindowSurface
},
1869 { "eglCreatePlatformPixmapSurface", (_EGLProc
) eglCreatePlatformPixmapSurface
},
1870 { "eglCreateImageKHR", (_EGLProc
) eglCreateImageKHR
},
1871 { "eglDestroyImageKHR", (_EGLProc
) eglDestroyImage
},
1872 { "eglCreateSyncKHR", (_EGLProc
) eglCreateSyncKHR
},
1873 { "eglCreateSync64KHR", (_EGLProc
) eglCreateSync64KHR
},
1874 { "eglDestroySyncKHR", (_EGLProc
) eglDestroySync
},
1875 { "eglClientWaitSyncKHR", (_EGLProc
) eglClientWaitSync
},
1876 { "eglWaitSyncKHR", (_EGLProc
) eglWaitSyncKHR
},
1877 { "eglSignalSyncKHR", (_EGLProc
) eglSignalSyncKHR
},
1878 { "eglGetSyncAttribKHR", (_EGLProc
) eglGetSyncAttribKHR
},
1879 { "eglSwapBuffersRegionNOK", (_EGLProc
) eglSwapBuffersRegionNOK
},
1880 { "eglCreateDRMImageMESA", (_EGLProc
) eglCreateDRMImageMESA
},
1881 { "eglExportDRMImageMESA", (_EGLProc
) eglExportDRMImageMESA
},
1882 { "eglBindWaylandDisplayWL", (_EGLProc
) eglBindWaylandDisplayWL
},
1883 { "eglUnbindWaylandDisplayWL", (_EGLProc
) eglUnbindWaylandDisplayWL
},
1884 { "eglQueryWaylandBufferWL", (_EGLProc
) eglQueryWaylandBufferWL
},
1885 { "eglCreateWaylandBufferFromImageWL", (_EGLProc
) eglCreateWaylandBufferFromImageWL
},
1886 { "eglPostSubBufferNV", (_EGLProc
) eglPostSubBufferNV
},
1887 { "eglSwapBuffersWithDamageEXT", (_EGLProc
) eglSwapBuffersWithDamageEXT
},
1888 { "eglGetPlatformDisplayEXT", (_EGLProc
) eglGetPlatformDisplayEXT
},
1889 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc
) eglCreatePlatformWindowSurfaceEXT
},
1890 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc
) eglCreatePlatformPixmapSurfaceEXT
},
1891 { "eglGetSyncValuesCHROMIUM", (_EGLProc
) eglGetSyncValuesCHROMIUM
},
1892 { "eglExportDMABUFImageQueryMESA", (_EGLProc
) eglExportDMABUFImageQueryMESA
},
1893 { "eglExportDMABUFImageMESA", (_EGLProc
) eglExportDMABUFImageMESA
},
1900 RETURN_EGL_SUCCESS(NULL
, NULL
);
1903 if (strncmp(procname
, "egl", 3) == 0) {
1904 for (i
= 0; egl_functions
[i
].name
; i
++) {
1905 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
1906 ret
= egl_functions
[i
].function
;
1912 ret
= _eglGetDriverProc(procname
);
1914 RETURN_EGL_SUCCESS(NULL
, ret
);
1918 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
1919 _EGLDisplay
**disp
, _EGLDriver
**drv
,
1923 *disp
= _eglLockDisplay(dpy
);
1924 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
1926 _eglUnlockDisplay(*disp
);
1927 return MESA_GLINTEROP_INVALID_DISPLAY
;
1930 *drv
= (*disp
)->Driver
;
1932 *ctx
= _eglLookupContext(context
, *disp
);
1934 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
1935 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
1936 _eglUnlockDisplay(*disp
);
1937 return MESA_GLINTEROP_INVALID_CONTEXT
;
1940 return MESA_GLINTEROP_SUCCESS
;
1943 GLAPI
int GLAPIENTRY
1944 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
1945 mesa_glinterop_device_info
*out
)
1952 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
1953 if (ret
!= MESA_GLINTEROP_SUCCESS
)
1956 if (drv
->API
.GLInteropQueryDeviceInfo
)
1957 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
1959 ret
= MESA_GLINTEROP_UNSUPPORTED
;
1961 _eglUnlockDisplay(disp
);
1965 GLAPI
int GLAPIENTRY
1966 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
1967 const mesa_glinterop_export_in
*in
,
1968 mesa_glinterop_export_out
*out
)
1975 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
1976 if (ret
!= MESA_GLINTEROP_SUCCESS
)
1979 if (drv
->API
.GLInteropExportObject
)
1980 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
1982 ret
= MESA_GLINTEROP_UNSUPPORTED
;
1984 _eglUnlockDisplay(disp
);