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
);
299 _eglGetPlatformDisplayCommon(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 static EGLDisplay EGLAPIENTRY
330 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
331 const EGLint
*attrib_list
)
333 return _eglGetPlatformDisplayCommon(platform
, native_display
, attrib_list
);
336 EGLDisplay EGLAPIENTRY
337 eglGetPlatformDisplay(EGLenum platform
, void *native_display
,
338 const EGLAttrib
*attrib_list
)
343 int_attribs
= _eglConvertAttribsToInt(attrib_list
);
344 if (attrib_list
&& !int_attribs
)
345 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, NULL
);
347 display
= _eglGetPlatformDisplayCommon(platform
, native_display
, int_attribs
);
353 * Copy the extension into the string and update the string pointer.
356 _eglAppendExtension(char **str
, const char *ext
)
359 size_t len
= strlen(ext
);
376 * Examine the individual extension enable/disable flags and recompute
377 * the driver's Extensions string.
380 _eglCreateExtensionsString(_EGLDisplay
*dpy
)
382 #define _EGL_CHECK_EXTENSION(ext) \
384 if (dpy->Extensions.ext) { \
385 _eglAppendExtension(&exts, "EGL_" #ext); \
386 assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
390 char *exts
= dpy
->ExtensionsString
;
392 /* Please keep these sorted alphabetically. */
393 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target
);
394 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer
);
395 _EGL_CHECK_EXTENSION(ANDROID_recordable
);
397 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control
);
399 _EGL_CHECK_EXTENSION(EXT_buffer_age
);
400 _EGL_CHECK_EXTENSION(EXT_create_context_robustness
);
401 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import
);
402 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage
);
404 _EGL_CHECK_EXTENSION(KHR_cl_event2
);
405 _EGL_CHECK_EXTENSION(KHR_create_context
);
406 _EGL_CHECK_EXTENSION(KHR_fence_sync
);
407 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses
);
408 _EGL_CHECK_EXTENSION(KHR_gl_colorspace
);
409 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image
);
410 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image
);
411 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image
);
412 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image
);
413 if (dpy
->Extensions
.KHR_image_base
&& dpy
->Extensions
.KHR_image_pixmap
)
414 _eglAppendExtension(&exts
, "EGL_KHR_image");
415 _EGL_CHECK_EXTENSION(KHR_image_base
);
416 _EGL_CHECK_EXTENSION(KHR_image_pixmap
);
417 _EGL_CHECK_EXTENSION(KHR_no_config_context
);
418 _EGL_CHECK_EXTENSION(KHR_reusable_sync
);
419 _EGL_CHECK_EXTENSION(KHR_surfaceless_context
);
420 _EGL_CHECK_EXTENSION(KHR_wait_sync
);
422 if (dpy
->Extensions
.KHR_no_config_context
)
423 _eglAppendExtension(&exts
, "EGL_MESA_configless_context");
424 _EGL_CHECK_EXTENSION(MESA_drm_image
);
425 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export
);
427 _EGL_CHECK_EXTENSION(NOK_swap_region
);
428 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap
);
430 _EGL_CHECK_EXTENSION(NV_post_sub_buffer
);
432 _EGL_CHECK_EXTENSION(WL_bind_wayland_display
);
433 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image
);
435 #undef _EGL_CHECK_EXTENSION
439 _eglCreateAPIsString(_EGLDisplay
*dpy
)
441 if (dpy
->ClientAPIs
& EGL_OPENGL_BIT
)
442 strcat(dpy
->ClientAPIsString
, "OpenGL ");
444 if (dpy
->ClientAPIs
& EGL_OPENGL_ES_BIT
||
445 dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
446 dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
447 strcat(dpy
->ClientAPIsString
, "OpenGL_ES ");
450 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
451 strcat(dpy
->ClientAPIsString
, "OpenVG ");
453 assert(strlen(dpy
->ClientAPIsString
) < sizeof(dpy
->ClientAPIsString
));
457 _eglComputeVersion(_EGLDisplay
*disp
)
461 if (disp
->Extensions
.KHR_fence_sync
&&
462 disp
->Extensions
.KHR_cl_event2
&&
463 disp
->Extensions
.KHR_wait_sync
&&
464 disp
->Extensions
.KHR_image_base
&&
465 disp
->Extensions
.KHR_gl_texture_2D_image
&&
466 disp
->Extensions
.KHR_gl_texture_3D_image
&&
467 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
468 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
469 disp
->Extensions
.KHR_create_context
&&
470 disp
->Extensions
.EXT_create_context_robustness
&&
471 disp
->Extensions
.KHR_get_all_proc_addresses
&&
472 disp
->Extensions
.KHR_gl_colorspace
&&
473 disp
->Extensions
.KHR_surfaceless_context
)
478 * This is typically the second EGL function that an application calls.
479 * Here we load/initialize the actual hardware driver.
481 EGLBoolean EGLAPIENTRY
482 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
484 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
487 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
489 if (!disp
->Initialized
) {
490 if (!_eglMatchDriver(disp
, EGL_FALSE
))
491 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
493 /* limit to APIs supported by core */
494 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
496 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
497 * classifies it as an EGL display extension, though conceptually it's an
498 * EGL client extension.
500 * From the EGL_KHR_get_all_proc_addresses spec:
502 * The EGL implementation must expose the name
503 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
504 * EGL_KHR_get_all_proc_addresses and supports
505 * EGL_EXT_client_extensions.
507 * Mesa unconditionally exposes both client extensions mentioned above,
508 * so the spec requires that each EGLDisplay unconditionally expose
509 * EGL_KHR_get_all_proc_addresses also.
511 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
513 _eglComputeVersion(disp
);
514 _eglCreateExtensionsString(disp
);
515 _eglCreateAPIsString(disp
);
516 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
517 "%d.%d (%s)", disp
->Version
/ 10, disp
->Version
% 10,
521 /* Update applications version of major and minor if not NULL */
522 if ((major
!= NULL
) && (minor
!= NULL
)) {
523 *major
= disp
->Version
/ 10;
524 *minor
= disp
->Version
% 10;
527 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
531 EGLBoolean EGLAPIENTRY
532 eglTerminate(EGLDisplay dpy
)
534 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
537 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
539 if (disp
->Initialized
) {
540 _EGLDriver
*drv
= disp
->Driver
;
542 drv
->API
.Terminate(drv
, disp
);
543 /* do not reset disp->Driver */
544 disp
->ClientAPIsString
[0] = 0;
545 disp
->Initialized
= EGL_FALSE
;
548 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
552 const char * EGLAPIENTRY
553 eglQueryString(EGLDisplay dpy
, EGLint name
)
558 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
559 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
562 disp
= _eglLockDisplay(dpy
);
563 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
567 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
569 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
571 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
572 case EGL_CLIENT_APIS
:
573 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
575 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
580 EGLBoolean EGLAPIENTRY
581 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
582 EGLint config_size
, EGLint
*num_config
)
584 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
588 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
589 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
591 RETURN_EGL_EVAL(disp
, ret
);
595 EGLBoolean EGLAPIENTRY
596 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
597 EGLint config_size
, EGLint
*num_config
)
599 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
603 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
604 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
605 config_size
, num_config
);
607 RETURN_EGL_EVAL(disp
, ret
);
611 EGLBoolean EGLAPIENTRY
612 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
613 EGLint attribute
, EGLint
*value
)
615 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
616 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
620 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
621 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
623 RETURN_EGL_EVAL(disp
, ret
);
627 EGLContext EGLAPIENTRY
628 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
629 const EGLint
*attrib_list
)
631 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
632 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
633 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
635 _EGLContext
*context
;
638 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
640 if (!config
&& !disp
->Extensions
.KHR_no_config_context
)
641 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
643 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
644 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
646 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
647 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
649 RETURN_EGL_EVAL(disp
, ret
);
653 EGLBoolean EGLAPIENTRY
654 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
656 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
657 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
661 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
662 _eglUnlinkContext(context
);
663 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
665 RETURN_EGL_EVAL(disp
, ret
);
669 EGLBoolean EGLAPIENTRY
670 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
673 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
674 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
675 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
676 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
681 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
684 /* display is allowed to be uninitialized under certain condition */
685 if (!disp
->Initialized
) {
686 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
687 ctx
!= EGL_NO_CONTEXT
)
688 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
691 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
693 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
694 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
695 if (!draw_surf
|| !read_surf
) {
696 /* From the EGL 1.4 (20130211) spec:
698 * To release the current context without assigning a new one, set ctx
699 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
701 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
702 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
704 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
705 (!read_surf
&& read
!= EGL_NO_SURFACE
))
706 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
707 if (draw_surf
|| read_surf
)
708 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
711 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
713 RETURN_EGL_EVAL(disp
, ret
);
717 EGLBoolean EGLAPIENTRY
718 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
719 EGLint attribute
, EGLint
*value
)
721 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
722 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
726 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
727 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
729 RETURN_EGL_EVAL(disp
, ret
);
734 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
735 void *native_window
, const EGLint
*attrib_list
)
737 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
742 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
744 if (native_window
== NULL
)
745 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
747 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
749 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
751 RETURN_EGL_EVAL(disp
, ret
);
755 EGLSurface EGLAPIENTRY
756 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
757 EGLNativeWindowType window
, const EGLint
*attrib_list
)
759 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
760 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
761 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
766 fixupNativeWindow(_EGLDisplay
*disp
, void *native_window
)
768 #ifdef HAVE_X11_PLATFORM
769 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
770 /* The `native_window` parameter for the X11 platform differs between
771 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
772 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
773 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
774 * `Window*`. Convert `Window*` to `Window` because that's what
775 * dri2_x11_create_window_surface() expects.
777 return (void *)(* (Window
*) native_window
);
780 return native_window
;
783 static EGLSurface EGLAPIENTRY
784 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
786 const EGLint
*attrib_list
)
788 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
790 native_window
= fixupNativeWindow(disp
, native_window
);
792 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
797 EGLSurface EGLAPIENTRY
798 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
800 const EGLAttrib
*attrib_list
)
802 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
804 EGLint
*int_attribs
= _eglConvertAttribsToInt(attrib_list
);
806 if (attrib_list
&& !int_attribs
)
807 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
809 native_window
= fixupNativeWindow(disp
, native_window
);
810 surface
= _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
817 fixupNativePixmap(_EGLDisplay
*disp
, void *native_pixmap
)
819 #ifdef HAVE_X11_PLATFORM
820 /* The `native_pixmap` parameter for the X11 platform differs between
821 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
822 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
823 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
824 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
825 * dri2_x11_create_pixmap_surface() expects.
827 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
)
828 return (void *)(* (Pixmap
*) native_pixmap
);
830 return native_pixmap
;
834 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
835 void *native_pixmap
, const EGLint
*attrib_list
)
837 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
842 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
843 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
845 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
847 RETURN_EGL_EVAL(disp
, ret
);
851 EGLSurface EGLAPIENTRY
852 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
853 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
855 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
856 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
857 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
861 static EGLSurface EGLAPIENTRY
862 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
864 const EGLint
*attrib_list
)
866 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
868 native_pixmap
= fixupNativePixmap(disp
, native_pixmap
);
869 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
874 EGLSurface EGLAPIENTRY
875 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
877 const EGLAttrib
*attrib_list
)
879 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
881 EGLint
*int_attribs
= _eglConvertAttribsToInt(attrib_list
);
883 if (attrib_list
&& !int_attribs
)
884 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
886 native_pixmap
= fixupNativePixmap(disp
, native_pixmap
);
887 surface
= _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
894 EGLSurface EGLAPIENTRY
895 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
896 const EGLint
*attrib_list
)
898 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
899 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
904 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
906 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
907 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
909 RETURN_EGL_EVAL(disp
, ret
);
913 EGLBoolean EGLAPIENTRY
914 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
916 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
917 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
921 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
922 _eglUnlinkSurface(surf
);
923 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
925 RETURN_EGL_EVAL(disp
, ret
);
928 EGLBoolean EGLAPIENTRY
929 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
930 EGLint attribute
, EGLint
*value
)
932 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
933 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
937 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
938 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
940 RETURN_EGL_EVAL(disp
, ret
);
943 EGLBoolean EGLAPIENTRY
944 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
945 EGLint attribute
, EGLint value
)
947 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
948 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
952 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
953 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
955 RETURN_EGL_EVAL(disp
, ret
);
959 EGLBoolean EGLAPIENTRY
960 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
962 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
963 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
967 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
968 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
970 RETURN_EGL_EVAL(disp
, ret
);
974 EGLBoolean EGLAPIENTRY
975 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
977 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
978 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
982 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
983 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
985 RETURN_EGL_EVAL(disp
, ret
);
989 EGLBoolean EGLAPIENTRY
990 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
992 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
993 _EGLContext
*ctx
= _eglGetCurrentContext();
998 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1000 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1001 ctx
->Resource
.Display
!= disp
)
1002 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1004 surf
= ctx
->DrawSurface
;
1005 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
1006 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1008 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
1010 RETURN_EGL_EVAL(disp
, ret
);
1014 EGLBoolean EGLAPIENTRY
1015 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
1017 _EGLContext
*ctx
= _eglGetCurrentContext();
1018 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1019 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1023 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1025 /* surface must be bound to current context in EGL 1.4 */
1026 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1027 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1028 surf
!= ctx
->DrawSurface
)
1029 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1032 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1034 RETURN_EGL_EVAL(disp
, ret
);
1038 static EGLBoolean EGLAPIENTRY
1039 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1040 EGLint
*rects
, EGLint n_rects
)
1042 _EGLContext
*ctx
= _eglGetCurrentContext();
1043 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1044 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1048 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1050 /* surface must be bound to current context in EGL 1.4 */
1051 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1052 surf
!= ctx
->DrawSurface
)
1053 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1055 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1056 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1058 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1060 RETURN_EGL_EVAL(disp
, ret
);
1063 EGLBoolean EGLAPIENTRY
1064 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1066 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1067 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1070 void *native_pixmap_ptr
;
1072 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1073 native_pixmap_ptr
= (void*) target
;
1075 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1076 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
1077 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
1078 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1080 RETURN_EGL_EVAL(disp
, ret
);
1084 EGLBoolean EGLAPIENTRY
1087 _EGLContext
*ctx
= _eglGetCurrentContext();
1093 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1095 disp
= ctx
->Resource
.Display
;
1096 mtx_lock(&disp
->Mutex
);
1098 /* let bad current context imply bad current surface */
1099 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1100 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1101 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1103 /* a valid current context implies an initialized current display */
1104 assert(disp
->Initialized
);
1106 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1108 RETURN_EGL_EVAL(disp
, ret
);
1112 EGLBoolean EGLAPIENTRY
1115 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1116 return eglWaitClient();
1120 EGLBoolean EGLAPIENTRY
1121 eglWaitNative(EGLint engine
)
1123 _EGLContext
*ctx
= _eglGetCurrentContext();
1129 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1131 disp
= ctx
->Resource
.Display
;
1132 mtx_lock(&disp
->Mutex
);
1134 /* let bad current context imply bad current surface */
1135 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1136 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1137 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1139 /* a valid current context implies an initialized current display */
1140 assert(disp
->Initialized
);
1142 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1144 RETURN_EGL_EVAL(disp
, ret
);
1148 EGLDisplay EGLAPIENTRY
1149 eglGetCurrentDisplay(void)
1151 _EGLContext
*ctx
= _eglGetCurrentContext();
1154 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1156 RETURN_EGL_SUCCESS(NULL
, ret
);
1160 EGLContext EGLAPIENTRY
1161 eglGetCurrentContext(void)
1163 _EGLContext
*ctx
= _eglGetCurrentContext();
1166 ret
= _eglGetContextHandle(ctx
);
1168 RETURN_EGL_SUCCESS(NULL
, ret
);
1172 EGLSurface EGLAPIENTRY
1173 eglGetCurrentSurface(EGLint readdraw
)
1175 _EGLContext
*ctx
= _eglGetCurrentContext();
1176 EGLint err
= EGL_SUCCESS
;
1181 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1185 surf
= ctx
->DrawSurface
;
1188 surf
= ctx
->ReadSurface
;
1192 err
= EGL_BAD_PARAMETER
;
1196 ret
= _eglGetSurfaceHandle(surf
);
1198 RETURN_EGL_ERROR(NULL
, err
, ret
);
1205 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1206 EGLint e
= t
->LastError
;
1207 if (!_eglIsCurrentThreadDummy())
1208 t
->LastError
= EGL_SUCCESS
;
1218 * Specify the client API to use for subsequent calls including:
1219 * eglCreateContext()
1220 * eglGetCurrentContext()
1221 * eglGetCurrentDisplay()
1222 * eglGetCurrentSurface()
1223 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1226 * See section 3.7 "Rendering Context" in the EGL specification for details.
1228 EGLBoolean EGLAPIENTRY
1229 eglBindAPI(EGLenum api
)
1231 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1233 if (_eglIsCurrentThreadDummy())
1234 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1236 if (!_eglIsApiValid(api
))
1237 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1239 t
->CurrentAPI
= api
;
1241 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1246 * Return the last value set with eglBindAPI().
1251 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1254 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1255 ret
= t
->CurrentAPI
;
1257 RETURN_EGL_SUCCESS(NULL
, ret
);
1261 EGLSurface EGLAPIENTRY
1262 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1263 EGLClientBuffer buffer
, EGLConfig config
,
1264 const EGLint
*attrib_list
)
1266 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1267 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1272 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1274 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1276 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1278 RETURN_EGL_EVAL(disp
, ret
);
1282 EGLBoolean EGLAPIENTRY
1283 eglReleaseThread(void)
1285 /* unbind current contexts */
1286 if (!_eglIsCurrentThreadDummy()) {
1287 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1289 _EGLContext
*ctx
= t
->CurrentContext
;
1291 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1294 mtx_lock(&disp
->Mutex
);
1296 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1297 mtx_unlock(&disp
->Mutex
);
1301 _eglDestroyCurrentThread();
1303 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1307 static EGLImage EGLAPIENTRY
1308 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1309 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1311 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1312 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1317 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1318 if (!disp
->Extensions
.KHR_image_base
)
1319 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1320 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1321 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1322 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1323 * <ctx> must be EGL_NO_CONTEXT..."
1325 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1326 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1328 img
= drv
->API
.CreateImageKHR(drv
,
1329 disp
, context
, target
, buffer
, attr_list
);
1330 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1332 RETURN_EGL_EVAL(disp
, ret
);
1336 EGLImage EGLAPIENTRY
1337 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1338 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1341 EGLint
*int_attribs
= _eglConvertAttribsToInt(attr_list
);
1343 if (attr_list
&& !int_attribs
)
1344 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1346 image
= eglCreateImageKHR(dpy
, ctx
, target
, buffer
, int_attribs
);
1352 EGLBoolean EGLAPIENTRY
1353 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1355 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1356 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1360 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1361 if (!disp
->Extensions
.KHR_image_base
)
1362 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1364 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1366 _eglUnlinkImage(img
);
1367 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1369 RETURN_EGL_EVAL(disp
, ret
);
1374 _eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLint
*attrib_list
,
1375 const EGLAttrib
*attrib_list64
, EGLBoolean is64
,
1376 EGLenum invalid_type_error
)
1378 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1379 _EGLContext
*ctx
= _eglGetCurrentContext();
1384 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1386 if (!disp
->Extensions
.KHR_cl_event2
&& is64
)
1387 RETURN_EGL_EVAL(disp
, EGL_NO_SYNC_KHR
);
1389 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1390 if (!ctx
|| ctx
->Resource
.Display
!= dpy
||
1391 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1392 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1395 case EGL_SYNC_FENCE_KHR
:
1396 if (!disp
->Extensions
.KHR_fence_sync
)
1397 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1399 case EGL_SYNC_REUSABLE_KHR
:
1400 if (!disp
->Extensions
.KHR_reusable_sync
)
1401 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1403 case EGL_SYNC_CL_EVENT_KHR
:
1404 if (!disp
->Extensions
.KHR_cl_event2
)
1405 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1408 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1411 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
, attrib_list64
);
1412 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1414 RETURN_EGL_EVAL(disp
, ret
);
1418 static EGLSync EGLAPIENTRY
1419 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*attrib_list
)
1421 return _eglCreateSync(dpy
, type
, attrib_list
, NULL
, EGL_FALSE
,
1426 static EGLSync EGLAPIENTRY
1427 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1429 return _eglCreateSync(dpy
, type
, NULL
, attrib_list
, EGL_TRUE
,
1435 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1437 return _eglCreateSync(dpy
, type
, NULL
, attrib_list
, EGL_TRUE
,
1442 EGLBoolean EGLAPIENTRY
1443 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1445 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1446 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1450 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1451 assert(disp
->Extensions
.KHR_reusable_sync
||
1452 disp
->Extensions
.KHR_fence_sync
);
1455 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1457 RETURN_EGL_EVAL(disp
, ret
);
1462 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
, EGLTime timeout
)
1464 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1465 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1469 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1470 assert(disp
->Extensions
.KHR_reusable_sync
||
1471 disp
->Extensions
.KHR_fence_sync
);
1473 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1474 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1476 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1477 * unlocked here to allow other threads also to be able to
1478 * go into waiting state.
1481 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1482 _eglUnlockDisplay(dpy
);
1484 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1487 * 'disp' is already unlocked for reusable sync type,
1488 * so passing 'NULL' to bypass unlocking display.
1490 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1491 RETURN_EGL_EVAL(NULL
, ret
);
1493 RETURN_EGL_EVAL(disp
, ret
);
1497 static EGLint EGLAPIENTRY
1498 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1500 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1501 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1502 _EGLContext
*ctx
= _eglGetCurrentContext();
1506 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1507 assert(disp
->Extensions
.KHR_wait_sync
);
1509 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1510 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1511 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1513 /* the API doesn't allow any flags yet */
1515 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1517 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1519 RETURN_EGL_EVAL(disp
, ret
);
1523 EGLBoolean EGLAPIENTRY
1524 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1526 /* The KHR version returns EGLint, while the core version returns
1527 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1530 return eglWaitSyncKHR(dpy
, sync
, flags
);
1534 static EGLBoolean EGLAPIENTRY
1535 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
1537 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1538 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1542 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1543 assert(disp
->Extensions
.KHR_reusable_sync
);
1544 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
1546 RETURN_EGL_EVAL(disp
, ret
);
1550 EGLBoolean EGLAPIENTRY
1551 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
1553 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1554 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1558 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1559 assert(disp
->Extensions
.KHR_reusable_sync
||
1560 disp
->Extensions
.KHR_fence_sync
);
1561 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
1563 RETURN_EGL_EVAL(disp
, ret
);
1567 static EGLBoolean EGLAPIENTRY
1568 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
1574 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1577 result
= eglGetSyncAttrib(dpy
, sync
, attribute
, &attrib
);
1579 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
1581 * If any error occurs, <*value> is not modified.
1583 if (result
== EGL_FALSE
)
1591 static EGLBoolean EGLAPIENTRY
1592 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
1593 EGLint numRects
, const EGLint
*rects
)
1595 _EGLContext
*ctx
= _eglGetCurrentContext();
1596 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1597 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1601 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1603 if (!disp
->Extensions
.NOK_swap_region
)
1604 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1606 /* surface must be bound to current context in EGL 1.4 */
1607 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1608 surf
!= ctx
->DrawSurface
)
1609 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1611 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
1613 RETURN_EGL_EVAL(disp
, ret
);
1617 static EGLImage EGLAPIENTRY
1618 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
1620 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1625 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1626 if (!disp
->Extensions
.MESA_drm_image
)
1627 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1629 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
1630 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1632 RETURN_EGL_EVAL(disp
, ret
);
1635 static EGLBoolean EGLAPIENTRY
1636 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
1637 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
1639 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1640 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1644 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1645 assert(disp
->Extensions
.MESA_drm_image
);
1648 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1650 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
1652 RETURN_EGL_EVAL(disp
, ret
);
1658 static EGLBoolean EGLAPIENTRY
1659 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1661 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1665 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1666 assert(disp
->Extensions
.WL_bind_wayland_display
);
1669 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1671 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
1673 RETURN_EGL_EVAL(disp
, ret
);
1676 static EGLBoolean EGLAPIENTRY
1677 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1679 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1683 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1684 assert(disp
->Extensions
.WL_bind_wayland_display
);
1687 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1689 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
1691 RETURN_EGL_EVAL(disp
, ret
);
1694 static EGLBoolean EGLAPIENTRY
1695 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
1696 EGLint attribute
, EGLint
*value
)
1698 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1702 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1703 assert(disp
->Extensions
.WL_bind_wayland_display
);
1706 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1708 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
1710 RETURN_EGL_EVAL(disp
, ret
);
1714 static struct wl_buffer
* EGLAPIENTRY
1715 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
1717 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1720 struct wl_buffer
*ret
;
1722 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
1723 assert(disp
->Extensions
.WL_create_wayland_buffer_from_image
);
1725 img
= _eglLookupImage(image
, disp
);
1728 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
1730 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
1732 RETURN_EGL_EVAL(disp
, ret
);
1735 static EGLBoolean EGLAPIENTRY
1736 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
1737 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
1739 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1740 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1744 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1746 if (!disp
->Extensions
.NV_post_sub_buffer
)
1747 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1749 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
1751 RETURN_EGL_EVAL(disp
, ret
);
1754 static EGLBoolean EGLAPIENTRY
1755 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
1756 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
1759 _EGLDisplay
*disp
= _eglLockDisplay(display
);
1760 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1764 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1765 if (!disp
->Extensions
.CHROMIUM_sync_control
)
1766 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1768 if (!ust
|| !msc
|| !sbc
)
1769 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1771 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
1773 RETURN_EGL_EVAL(disp
, ret
);
1776 static EGLBoolean EGLAPIENTRY
1777 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
1778 EGLint
*fourcc
, EGLint
*nplanes
,
1779 EGLuint64KHR
*modifiers
)
1781 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1782 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1786 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1787 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
1790 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1792 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
1795 RETURN_EGL_EVAL(disp
, ret
);
1798 static EGLBoolean EGLAPIENTRY
1799 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
1800 int *fds
, EGLint
*strides
, EGLint
*offsets
)
1802 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1803 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1807 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1808 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
1811 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1813 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
1815 RETURN_EGL_EVAL(disp
, ret
);
1818 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
1819 eglGetProcAddress(const char *procname
)
1821 static const struct {
1824 } egl_functions
[] = {
1825 /* core functions queryable in the presence of
1826 * EGL_KHR_get_all_proc_addresses or EGL 1.5
1828 /* alphabetical order */
1829 { "eglBindAPI", (_EGLProc
) eglBindAPI
},
1830 { "eglBindTexImage", (_EGLProc
) eglBindTexImage
},
1831 { "eglChooseConfig", (_EGLProc
) eglChooseConfig
},
1832 { "eglCopyBuffers", (_EGLProc
) eglCopyBuffers
},
1833 { "eglCreateContext", (_EGLProc
) eglCreateContext
},
1834 { "eglCreatePbufferFromClientBuffer", (_EGLProc
) eglCreatePbufferFromClientBuffer
},
1835 { "eglCreatePbufferSurface", (_EGLProc
) eglCreatePbufferSurface
},
1836 { "eglCreatePixmapSurface", (_EGLProc
) eglCreatePixmapSurface
},
1837 { "eglCreateWindowSurface", (_EGLProc
) eglCreateWindowSurface
},
1838 { "eglDestroyContext", (_EGLProc
) eglDestroyContext
},
1839 { "eglDestroySurface", (_EGLProc
) eglDestroySurface
},
1840 { "eglGetConfigAttrib", (_EGLProc
) eglGetConfigAttrib
},
1841 { "eglGetConfigs", (_EGLProc
) eglGetConfigs
},
1842 { "eglGetCurrentContext", (_EGLProc
) eglGetCurrentContext
},
1843 { "eglGetCurrentDisplay", (_EGLProc
) eglGetCurrentDisplay
},
1844 { "eglGetCurrentSurface", (_EGLProc
) eglGetCurrentSurface
},
1845 { "eglGetDisplay", (_EGLProc
) eglGetDisplay
},
1846 { "eglGetError", (_EGLProc
) eglGetError
},
1847 { "eglGetProcAddress", (_EGLProc
) eglGetProcAddress
},
1848 { "eglInitialize", (_EGLProc
) eglInitialize
},
1849 { "eglMakeCurrent", (_EGLProc
) eglMakeCurrent
},
1850 { "eglQueryAPI", (_EGLProc
) eglQueryAPI
},
1851 { "eglQueryContext", (_EGLProc
) eglQueryContext
},
1852 { "eglQueryString", (_EGLProc
) eglQueryString
},
1853 { "eglQuerySurface", (_EGLProc
) eglQuerySurface
},
1854 { "eglReleaseTexImage", (_EGLProc
) eglReleaseTexImage
},
1855 { "eglReleaseThread", (_EGLProc
) eglReleaseThread
},
1856 { "eglSurfaceAttrib", (_EGLProc
) eglSurfaceAttrib
},
1857 { "eglSwapBuffers", (_EGLProc
) eglSwapBuffers
},
1858 { "eglSwapInterval", (_EGLProc
) eglSwapInterval
},
1859 { "eglTerminate", (_EGLProc
) eglTerminate
},
1860 { "eglWaitClient", (_EGLProc
) eglWaitClient
},
1861 { "eglWaitGL", (_EGLProc
) eglWaitGL
},
1862 { "eglWaitNative", (_EGLProc
) eglWaitNative
},
1863 { "eglCreateSync", (_EGLProc
) eglCreateSync
},
1864 { "eglDestroySync", (_EGLProc
) eglDestroySync
},
1865 { "eglClientWaitSync", (_EGLProc
) eglClientWaitSync
},
1866 { "eglGetSyncAttrib", (_EGLProc
) eglGetSyncAttrib
},
1867 { "eglWaitSync", (_EGLProc
) eglWaitSync
},
1868 { "eglCreateImage", (_EGLProc
) eglCreateImage
},
1869 { "eglDestroyImage", (_EGLProc
) eglDestroyImage
},
1870 { "eglGetPlatformDisplay", (_EGLProc
) eglGetPlatformDisplay
},
1871 { "eglCreatePlatformWindowSurface", (_EGLProc
) eglCreatePlatformWindowSurface
},
1872 { "eglCreatePlatformPixmapSurface", (_EGLProc
) eglCreatePlatformPixmapSurface
},
1873 { "eglCreateImageKHR", (_EGLProc
) eglCreateImageKHR
},
1874 { "eglDestroyImageKHR", (_EGLProc
) eglDestroyImage
},
1875 { "eglCreateSyncKHR", (_EGLProc
) eglCreateSyncKHR
},
1876 { "eglCreateSync64KHR", (_EGLProc
) eglCreateSync64KHR
},
1877 { "eglDestroySyncKHR", (_EGLProc
) eglDestroySync
},
1878 { "eglClientWaitSyncKHR", (_EGLProc
) eglClientWaitSync
},
1879 { "eglWaitSyncKHR", (_EGLProc
) eglWaitSyncKHR
},
1880 { "eglSignalSyncKHR", (_EGLProc
) eglSignalSyncKHR
},
1881 { "eglGetSyncAttribKHR", (_EGLProc
) eglGetSyncAttribKHR
},
1882 { "eglSwapBuffersRegionNOK", (_EGLProc
) eglSwapBuffersRegionNOK
},
1883 { "eglCreateDRMImageMESA", (_EGLProc
) eglCreateDRMImageMESA
},
1884 { "eglExportDRMImageMESA", (_EGLProc
) eglExportDRMImageMESA
},
1885 { "eglBindWaylandDisplayWL", (_EGLProc
) eglBindWaylandDisplayWL
},
1886 { "eglUnbindWaylandDisplayWL", (_EGLProc
) eglUnbindWaylandDisplayWL
},
1887 { "eglQueryWaylandBufferWL", (_EGLProc
) eglQueryWaylandBufferWL
},
1888 { "eglCreateWaylandBufferFromImageWL", (_EGLProc
) eglCreateWaylandBufferFromImageWL
},
1889 { "eglPostSubBufferNV", (_EGLProc
) eglPostSubBufferNV
},
1890 { "eglSwapBuffersWithDamageEXT", (_EGLProc
) eglSwapBuffersWithDamageEXT
},
1891 { "eglGetPlatformDisplayEXT", (_EGLProc
) eglGetPlatformDisplayEXT
},
1892 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc
) eglCreatePlatformWindowSurfaceEXT
},
1893 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc
) eglCreatePlatformPixmapSurfaceEXT
},
1894 { "eglGetSyncValuesCHROMIUM", (_EGLProc
) eglGetSyncValuesCHROMIUM
},
1895 { "eglExportDMABUFImageQueryMESA", (_EGLProc
) eglExportDMABUFImageQueryMESA
},
1896 { "eglExportDMABUFImageMESA", (_EGLProc
) eglExportDMABUFImageMESA
},
1903 RETURN_EGL_SUCCESS(NULL
, NULL
);
1906 if (strncmp(procname
, "egl", 3) == 0) {
1907 for (i
= 0; egl_functions
[i
].name
; i
++) {
1908 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
1909 ret
= egl_functions
[i
].function
;
1915 ret
= _eglGetDriverProc(procname
);
1917 RETURN_EGL_SUCCESS(NULL
, ret
);
1921 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
1922 _EGLDisplay
**disp
, _EGLDriver
**drv
,
1926 *disp
= _eglLockDisplay(dpy
);
1927 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
1929 _eglUnlockDisplay(*disp
);
1930 return MESA_GLINTEROP_INVALID_DISPLAY
;
1933 *drv
= (*disp
)->Driver
;
1935 *ctx
= _eglLookupContext(context
, *disp
);
1937 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
1938 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
1939 _eglUnlockDisplay(*disp
);
1940 return MESA_GLINTEROP_INVALID_CONTEXT
;
1943 return MESA_GLINTEROP_SUCCESS
;
1947 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
1948 struct mesa_glinterop_device_info
*out
)
1955 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
1956 if (ret
!= MESA_GLINTEROP_SUCCESS
)
1959 if (drv
->API
.GLInteropQueryDeviceInfo
)
1960 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
1962 ret
= MESA_GLINTEROP_UNSUPPORTED
;
1964 _eglUnlockDisplay(disp
);
1969 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
1970 struct mesa_glinterop_export_in
*in
,
1971 struct mesa_glinterop_export_out
*out
)
1978 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
1979 if (ret
!= MESA_GLINTEROP_SUCCESS
)
1982 if (drv
->API
.GLInteropExportObject
)
1983 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
1985 ret
= MESA_GLINTEROP_UNSUPPORTED
;
1987 _eglUnlockDisplay(disp
);