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 dpy
->ClientAPIs
& EGL_OPENGL_ES2_BIT
||
436 dpy
->ClientAPIs
& EGL_OPENGL_ES3_BIT_KHR
) {
437 strcat(dpy
->ClientAPIsString
, "OpenGL_ES ");
440 if (dpy
->ClientAPIs
& EGL_OPENVG_BIT
)
441 strcat(dpy
->ClientAPIsString
, "OpenVG ");
443 assert(strlen(dpy
->ClientAPIsString
) < sizeof(dpy
->ClientAPIsString
));
447 _eglComputeVersion(_EGLDisplay
*disp
)
451 if (disp
->Extensions
.KHR_fence_sync
&&
452 disp
->Extensions
.KHR_cl_event2
&&
453 disp
->Extensions
.KHR_wait_sync
&&
454 disp
->Extensions
.KHR_image_base
&&
455 disp
->Extensions
.KHR_gl_texture_2D_image
&&
456 disp
->Extensions
.KHR_gl_texture_3D_image
&&
457 disp
->Extensions
.KHR_gl_texture_cubemap_image
&&
458 disp
->Extensions
.KHR_gl_renderbuffer_image
&&
459 disp
->Extensions
.KHR_create_context
&&
460 disp
->Extensions
.EXT_create_context_robustness
&&
461 disp
->Extensions
.KHR_get_all_proc_addresses
&&
462 disp
->Extensions
.KHR_gl_colorspace
&&
463 disp
->Extensions
.KHR_surfaceless_context
)
468 * This is typically the second EGL function that an application calls.
469 * Here we load/initialize the actual hardware driver.
471 EGLBoolean EGLAPIENTRY
472 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
474 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
477 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
479 if (!disp
->Initialized
) {
480 if (!_eglMatchDriver(disp
, EGL_FALSE
))
481 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
483 /* limit to APIs supported by core */
484 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
486 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
487 * classifies it as an EGL display extension, though conceptually it's an
488 * EGL client extension.
490 * From the EGL_KHR_get_all_proc_addresses spec:
492 * The EGL implementation must expose the name
493 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
494 * EGL_KHR_get_all_proc_addresses and supports
495 * EGL_EXT_client_extensions.
497 * Mesa unconditionally exposes both client extensions mentioned above,
498 * so the spec requires that each EGLDisplay unconditionally expose
499 * EGL_KHR_get_all_proc_addresses also.
501 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
503 _eglComputeVersion(disp
);
504 _eglCreateExtensionsString(disp
);
505 _eglCreateAPIsString(disp
);
506 snprintf(disp
->VersionString
, sizeof(disp
->VersionString
),
507 "%d.%d (%s)", disp
->Version
/ 10, disp
->Version
% 10,
511 /* Update applications version of major and minor if not NULL */
512 if ((major
!= NULL
) && (minor
!= NULL
)) {
513 *major
= disp
->Version
/ 10;
514 *minor
= disp
->Version
% 10;
517 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
521 EGLBoolean EGLAPIENTRY
522 eglTerminate(EGLDisplay dpy
)
524 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
527 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
529 if (disp
->Initialized
) {
530 _EGLDriver
*drv
= disp
->Driver
;
532 drv
->API
.Terminate(drv
, disp
);
533 /* do not reset disp->Driver */
534 disp
->ClientAPIsString
[0] = 0;
535 disp
->Initialized
= EGL_FALSE
;
538 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
542 const char * EGLAPIENTRY
543 eglQueryString(EGLDisplay dpy
, EGLint name
)
548 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
549 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
552 disp
= _eglLockDisplay(dpy
);
553 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
557 RETURN_EGL_SUCCESS(disp
, _EGL_VENDOR_STRING
);
559 RETURN_EGL_SUCCESS(disp
, disp
->VersionString
);
561 RETURN_EGL_SUCCESS(disp
, disp
->ExtensionsString
);
562 case EGL_CLIENT_APIS
:
563 RETURN_EGL_SUCCESS(disp
, disp
->ClientAPIsString
);
565 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
570 EGLBoolean EGLAPIENTRY
571 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
572 EGLint config_size
, EGLint
*num_config
)
574 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
578 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
579 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
581 RETURN_EGL_EVAL(disp
, ret
);
585 EGLBoolean EGLAPIENTRY
586 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
587 EGLint config_size
, EGLint
*num_config
)
589 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
593 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
594 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
595 config_size
, num_config
);
597 RETURN_EGL_EVAL(disp
, ret
);
601 EGLBoolean EGLAPIENTRY
602 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
603 EGLint attribute
, EGLint
*value
)
605 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
606 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
610 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
611 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
613 RETURN_EGL_EVAL(disp
, ret
);
617 EGLContext EGLAPIENTRY
618 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
619 const EGLint
*attrib_list
)
621 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
622 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
623 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
625 _EGLContext
*context
;
628 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
630 if (!config
&& !disp
->Extensions
.MESA_configless_context
)
631 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
633 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
634 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
636 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
637 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
639 RETURN_EGL_EVAL(disp
, ret
);
643 EGLBoolean EGLAPIENTRY
644 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
646 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
647 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
651 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
652 _eglUnlinkContext(context
);
653 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
655 RETURN_EGL_EVAL(disp
, ret
);
659 EGLBoolean EGLAPIENTRY
660 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
663 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
664 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
665 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
666 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
671 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
674 /* display is allowed to be uninitialized under certain condition */
675 if (!disp
->Initialized
) {
676 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
677 ctx
!= EGL_NO_CONTEXT
)
678 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
681 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
683 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
684 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
685 if (!draw_surf
|| !read_surf
) {
686 /* From the EGL 1.4 (20130211) spec:
688 * To release the current context without assigning a new one, set ctx
689 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
691 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
692 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
694 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
695 (!read_surf
&& read
!= EGL_NO_SURFACE
))
696 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
697 if (draw_surf
|| read_surf
)
698 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
701 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
703 RETURN_EGL_EVAL(disp
, ret
);
707 EGLBoolean EGLAPIENTRY
708 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
709 EGLint attribute
, EGLint
*value
)
711 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
712 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
716 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
717 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
719 RETURN_EGL_EVAL(disp
, ret
);
724 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
725 void *native_window
, const EGLint
*attrib_list
)
727 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
732 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
734 if (native_window
== NULL
)
735 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
737 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
739 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
741 RETURN_EGL_EVAL(disp
, ret
);
745 EGLSurface EGLAPIENTRY
746 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
747 EGLNativeWindowType window
, const EGLint
*attrib_list
)
749 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
750 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
751 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
756 static EGLSurface EGLAPIENTRY
757 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
759 const EGLint
*attrib_list
)
761 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
763 #ifdef HAVE_X11_PLATFORM
764 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
765 /* The `native_window` parameter for the X11 platform differs between
766 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
767 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
768 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
769 * `Window*`. Convert `Window*` to `Window` because that's what
770 * dri2_x11_create_window_surface() expects.
772 native_window
= (void*) (* (Window
*) native_window
);
776 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
781 EGLSurface EGLAPIENTRY
782 eglCreatePlatformWindowSurface(EGLDisplay dpy
, EGLConfig config
,
784 const EGLAttrib
*attrib_list
)
787 EGLint
*int_attribs
= _eglConvertAttribsToInt(attrib_list
);
789 if (attrib_list
&& !int_attribs
)
790 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
792 surface
= eglCreatePlatformWindowSurfaceEXT(dpy
, config
, native_window
,
800 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
801 void *native_pixmap
, const EGLint
*attrib_list
)
803 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
808 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
809 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
811 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
813 RETURN_EGL_EVAL(disp
, ret
);
817 EGLSurface EGLAPIENTRY
818 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
819 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
821 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
822 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
823 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
827 static EGLSurface EGLAPIENTRY
828 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
830 const EGLint
*attrib_list
)
832 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
834 #ifdef HAVE_X11_PLATFORM
835 /* The `native_pixmap` parameter for the X11 platform differs between
836 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
837 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
838 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
839 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
840 * dri2_x11_create_pixmap_surface() expects.
842 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
) {
843 native_pixmap
= (void*) (* (Pixmap
*) native_pixmap
);
847 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
852 EGLSurface EGLAPIENTRY
853 eglCreatePlatformPixmapSurface(EGLDisplay dpy
, EGLConfig config
,
855 const EGLAttrib
*attrib_list
)
858 EGLint
*int_attribs
= _eglConvertAttribsToInt(attrib_list
);
860 if (attrib_list
&& !int_attribs
)
861 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
863 surface
= eglCreatePlatformPixmapSurfaceEXT(dpy
, config
, native_pixmap
,
870 EGLSurface EGLAPIENTRY
871 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
872 const EGLint
*attrib_list
)
874 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
875 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
880 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
882 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
883 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
885 RETURN_EGL_EVAL(disp
, ret
);
889 EGLBoolean EGLAPIENTRY
890 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
892 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
893 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
897 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
898 _eglUnlinkSurface(surf
);
899 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
901 RETURN_EGL_EVAL(disp
, ret
);
904 EGLBoolean EGLAPIENTRY
905 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
906 EGLint attribute
, EGLint
*value
)
908 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
909 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
913 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
914 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
916 RETURN_EGL_EVAL(disp
, ret
);
919 EGLBoolean EGLAPIENTRY
920 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
921 EGLint attribute
, EGLint value
)
923 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
924 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
928 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
929 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
931 RETURN_EGL_EVAL(disp
, ret
);
935 EGLBoolean EGLAPIENTRY
936 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
938 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
939 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
943 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
944 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
946 RETURN_EGL_EVAL(disp
, ret
);
950 EGLBoolean EGLAPIENTRY
951 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
953 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
954 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
958 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
959 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
961 RETURN_EGL_EVAL(disp
, ret
);
965 EGLBoolean EGLAPIENTRY
966 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
968 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
969 _EGLContext
*ctx
= _eglGetCurrentContext();
974 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
976 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
977 ctx
->Resource
.Display
!= disp
)
978 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
980 surf
= ctx
->DrawSurface
;
981 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
982 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
984 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
986 RETURN_EGL_EVAL(disp
, ret
);
990 EGLBoolean EGLAPIENTRY
991 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
993 _EGLContext
*ctx
= _eglGetCurrentContext();
994 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
995 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
999 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1001 /* surface must be bound to current context in EGL 1.4 */
1002 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1003 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1004 surf
!= ctx
->DrawSurface
)
1005 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1008 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1010 RETURN_EGL_EVAL(disp
, ret
);
1014 static EGLBoolean EGLAPIENTRY
1015 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
1016 EGLint
*rects
, EGLint n_rects
)
1018 _EGLContext
*ctx
= _eglGetCurrentContext();
1019 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1020 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1024 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1026 /* surface must be bound to current context in EGL 1.4 */
1027 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1028 surf
!= ctx
->DrawSurface
)
1029 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1031 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
1032 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1034 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
1036 RETURN_EGL_EVAL(disp
, ret
);
1039 EGLBoolean EGLAPIENTRY
1040 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
1042 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1043 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1046 void *native_pixmap_ptr
;
1048 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
1049 native_pixmap_ptr
= (void*) target
;
1051 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1052 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
1053 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
1054 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
1056 RETURN_EGL_EVAL(disp
, ret
);
1060 EGLBoolean EGLAPIENTRY
1063 _EGLContext
*ctx
= _eglGetCurrentContext();
1069 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1071 disp
= ctx
->Resource
.Display
;
1072 mtx_lock(&disp
->Mutex
);
1074 /* let bad current context imply bad current surface */
1075 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1076 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1077 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1079 /* a valid current context implies an initialized current display */
1080 assert(disp
->Initialized
);
1082 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
1084 RETURN_EGL_EVAL(disp
, ret
);
1088 EGLBoolean EGLAPIENTRY
1091 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1092 EGLint api_index
= t
->CurrentAPIIndex
;
1093 EGLint es_index
= _eglConvertApiToIndex(EGL_OPENGL_ES_API
);
1096 if (api_index
!= es_index
&& _eglIsCurrentThreadDummy())
1097 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1099 t
->CurrentAPIIndex
= es_index
;
1100 ret
= eglWaitClient();
1101 t
->CurrentAPIIndex
= api_index
;
1106 EGLBoolean EGLAPIENTRY
1107 eglWaitNative(EGLint engine
)
1109 _EGLContext
*ctx
= _eglGetCurrentContext();
1115 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1117 disp
= ctx
->Resource
.Display
;
1118 mtx_lock(&disp
->Mutex
);
1120 /* let bad current context imply bad current surface */
1121 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1122 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
1123 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
1125 /* a valid current context implies an initialized current display */
1126 assert(disp
->Initialized
);
1128 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
1130 RETURN_EGL_EVAL(disp
, ret
);
1134 EGLDisplay EGLAPIENTRY
1135 eglGetCurrentDisplay(void)
1137 _EGLContext
*ctx
= _eglGetCurrentContext();
1140 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
1142 RETURN_EGL_SUCCESS(NULL
, ret
);
1146 EGLContext EGLAPIENTRY
1147 eglGetCurrentContext(void)
1149 _EGLContext
*ctx
= _eglGetCurrentContext();
1152 ret
= _eglGetContextHandle(ctx
);
1154 RETURN_EGL_SUCCESS(NULL
, ret
);
1158 EGLSurface EGLAPIENTRY
1159 eglGetCurrentSurface(EGLint readdraw
)
1161 _EGLContext
*ctx
= _eglGetCurrentContext();
1162 EGLint err
= EGL_SUCCESS
;
1167 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1171 surf
= ctx
->DrawSurface
;
1174 surf
= ctx
->ReadSurface
;
1178 err
= EGL_BAD_PARAMETER
;
1182 ret
= _eglGetSurfaceHandle(surf
);
1184 RETURN_EGL_ERROR(NULL
, err
, ret
);
1191 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1192 EGLint e
= t
->LastError
;
1193 if (!_eglIsCurrentThreadDummy())
1194 t
->LastError
= EGL_SUCCESS
;
1204 * Specify the client API to use for subsequent calls including:
1205 * eglCreateContext()
1206 * eglGetCurrentContext()
1207 * eglGetCurrentDisplay()
1208 * eglGetCurrentSurface()
1209 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1212 * See section 3.7 "Rendering Context" in the EGL specification for details.
1214 EGLBoolean EGLAPIENTRY
1215 eglBindAPI(EGLenum api
)
1217 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1219 if (_eglIsCurrentThreadDummy())
1220 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1222 if (!_eglIsApiValid(api
))
1223 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1225 t
->CurrentAPIIndex
= _eglConvertApiToIndex(api
);
1227 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1232 * Return the last value set with eglBindAPI().
1237 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1240 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1241 ret
= _eglConvertApiFromIndex(t
->CurrentAPIIndex
);
1243 RETURN_EGL_SUCCESS(NULL
, ret
);
1247 EGLSurface EGLAPIENTRY
1248 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1249 EGLClientBuffer buffer
, EGLConfig config
,
1250 const EGLint
*attrib_list
)
1252 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1253 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1258 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1260 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1262 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1264 RETURN_EGL_EVAL(disp
, ret
);
1268 EGLBoolean EGLAPIENTRY
1269 eglReleaseThread(void)
1271 /* unbind current contexts */
1272 if (!_eglIsCurrentThreadDummy()) {
1273 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1274 EGLint api_index
= t
->CurrentAPIIndex
;
1277 for (i
= 0; i
< _EGL_API_NUM_APIS
; i
++) {
1278 _EGLContext
*ctx
= t
->CurrentContexts
[i
];
1280 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1283 t
->CurrentAPIIndex
= i
;
1285 mtx_lock(&disp
->Mutex
);
1287 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1288 mtx_unlock(&disp
->Mutex
);
1292 t
->CurrentAPIIndex
= api_index
;
1295 _eglDestroyCurrentThread();
1297 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1301 static EGLImage EGLAPIENTRY
1302 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1303 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1305 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1306 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1311 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1312 if (!disp
->Extensions
.KHR_image_base
)
1313 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1314 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1315 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1316 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1317 * <ctx> must be EGL_NO_CONTEXT..."
1319 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1320 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1322 img
= drv
->API
.CreateImageKHR(drv
,
1323 disp
, context
, target
, buffer
, attr_list
);
1324 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1326 RETURN_EGL_EVAL(disp
, ret
);
1330 EGLImage EGLAPIENTRY
1331 eglCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1332 EGLClientBuffer buffer
, const EGLAttrib
*attr_list
)
1335 EGLint
*int_attribs
= _eglConvertAttribsToInt(attr_list
);
1337 if (attr_list
&& !int_attribs
)
1338 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_NO_IMAGE
);
1340 image
= eglCreateImageKHR(dpy
, ctx
, target
, buffer
, int_attribs
);
1346 EGLBoolean EGLAPIENTRY
1347 eglDestroyImage(EGLDisplay dpy
, EGLImage image
)
1349 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1350 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1354 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1355 if (!disp
->Extensions
.KHR_image_base
)
1356 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1358 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1360 _eglUnlinkImage(img
);
1361 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1363 RETURN_EGL_EVAL(disp
, ret
);
1368 _eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLint
*attrib_list
,
1369 const EGLAttrib
*attrib_list64
, EGLBoolean is64
,
1370 EGLenum invalid_type_error
)
1372 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1373 _EGLContext
*ctx
= _eglGetCurrentContext();
1378 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1380 if (!disp
->Extensions
.KHR_cl_event2
&& is64
)
1381 RETURN_EGL_EVAL(disp
, EGL_NO_SYNC_KHR
);
1383 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1384 if (!ctx
|| ctx
->Resource
.Display
!= dpy
||
1385 ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1386 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_NO_SYNC_KHR
);
1389 case EGL_SYNC_FENCE_KHR
:
1390 if (!disp
->Extensions
.KHR_fence_sync
)
1391 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1393 case EGL_SYNC_REUSABLE_KHR
:
1394 if (!disp
->Extensions
.KHR_reusable_sync
)
1395 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1397 case EGL_SYNC_CL_EVENT_KHR
:
1398 if (!disp
->Extensions
.KHR_cl_event2
)
1399 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1402 RETURN_EGL_ERROR(disp
, invalid_type_error
, EGL_NO_SYNC_KHR
);
1405 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
, attrib_list64
);
1406 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1408 RETURN_EGL_EVAL(disp
, ret
);
1412 static EGLSync EGLAPIENTRY
1413 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*attrib_list
)
1415 return _eglCreateSync(dpy
, type
, attrib_list
, NULL
, EGL_FALSE
,
1420 static EGLSync EGLAPIENTRY
1421 eglCreateSync64KHR(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1423 return _eglCreateSync(dpy
, type
, NULL
, attrib_list
, EGL_TRUE
,
1429 eglCreateSync(EGLDisplay dpy
, EGLenum type
, const EGLAttrib
*attrib_list
)
1431 return _eglCreateSync(dpy
, type
, NULL
, attrib_list
, EGL_TRUE
,
1436 EGLBoolean EGLAPIENTRY
1437 eglDestroySync(EGLDisplay dpy
, EGLSync sync
)
1439 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1440 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1444 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1445 assert(disp
->Extensions
.KHR_reusable_sync
||
1446 disp
->Extensions
.KHR_fence_sync
);
1449 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1451 RETURN_EGL_EVAL(disp
, ret
);
1456 eglClientWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
, EGLTime timeout
)
1458 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1459 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1463 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1464 assert(disp
->Extensions
.KHR_reusable_sync
||
1465 disp
->Extensions
.KHR_fence_sync
);
1467 if (s
->SyncStatus
== EGL_SIGNALED_KHR
)
1468 RETURN_EGL_EVAL(disp
, EGL_CONDITION_SATISFIED_KHR
);
1470 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1471 * unlocked here to allow other threads also to be able to
1472 * go into waiting state.
1475 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1476 _eglUnlockDisplay(dpy
);
1478 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1481 * 'disp' is already unlocked for reusable sync type,
1482 * so passing 'NULL' to bypass unlocking display.
1484 if (s
->Type
== EGL_SYNC_REUSABLE_KHR
)
1485 RETURN_EGL_EVAL(NULL
, ret
);
1487 RETURN_EGL_EVAL(disp
, ret
);
1491 static EGLint EGLAPIENTRY
1492 eglWaitSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1494 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1495 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1496 _EGLContext
*ctx
= _eglGetCurrentContext();
1500 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1501 assert(disp
->Extensions
.KHR_wait_sync
);
1503 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1504 if (ctx
== EGL_NO_CONTEXT
|| ctx
->ClientAPI
!= EGL_OPENGL_ES_API
)
1505 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
1507 /* the API doesn't allow any flags yet */
1509 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1511 ret
= drv
->API
.WaitSyncKHR(drv
, disp
, s
);
1513 RETURN_EGL_EVAL(disp
, ret
);
1517 EGLBoolean EGLAPIENTRY
1518 eglWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
)
1520 /* The KHR version returns EGLint, while the core version returns
1521 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1524 return eglWaitSyncKHR(dpy
, sync
, flags
);
1528 static EGLBoolean EGLAPIENTRY
1529 eglSignalSyncKHR(EGLDisplay dpy
, EGLSync sync
, EGLenum mode
)
1531 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1532 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1536 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1537 assert(disp
->Extensions
.KHR_reusable_sync
);
1538 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
1540 RETURN_EGL_EVAL(disp
, ret
);
1544 EGLBoolean EGLAPIENTRY
1545 eglGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLAttrib
*value
)
1547 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1548 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1552 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1553 assert(disp
->Extensions
.KHR_reusable_sync
||
1554 disp
->Extensions
.KHR_fence_sync
);
1555 ret
= drv
->API
.GetSyncAttrib(drv
, disp
, s
, attribute
, value
);
1557 RETURN_EGL_EVAL(disp
, ret
);
1561 static EGLBoolean EGLAPIENTRY
1562 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
, EGLint
*value
)
1568 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1571 result
= eglGetSyncAttrib(dpy
, sync
, attribute
, &attrib
);
1573 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
1575 * If any error occurs, <*value> is not modified.
1577 if (result
== EGL_FALSE
)
1585 static EGLBoolean EGLAPIENTRY
1586 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
1587 EGLint numRects
, const EGLint
*rects
)
1589 _EGLContext
*ctx
= _eglGetCurrentContext();
1590 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1591 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1595 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1597 if (!disp
->Extensions
.NOK_swap_region
)
1598 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1600 /* surface must be bound to current context in EGL 1.4 */
1601 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1602 surf
!= ctx
->DrawSurface
)
1603 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1605 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
1607 RETURN_EGL_EVAL(disp
, ret
);
1611 static EGLImage EGLAPIENTRY
1612 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
1614 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1619 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1620 if (!disp
->Extensions
.MESA_drm_image
)
1621 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1623 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
1624 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1626 RETURN_EGL_EVAL(disp
, ret
);
1629 static EGLBoolean EGLAPIENTRY
1630 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImage image
,
1631 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
1633 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1634 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1638 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1639 assert(disp
->Extensions
.MESA_drm_image
);
1642 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1644 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
1646 RETURN_EGL_EVAL(disp
, ret
);
1652 static EGLBoolean EGLAPIENTRY
1653 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1655 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1659 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1660 assert(disp
->Extensions
.WL_bind_wayland_display
);
1663 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1665 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
1667 RETURN_EGL_EVAL(disp
, ret
);
1670 static EGLBoolean EGLAPIENTRY
1671 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1673 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1677 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1678 assert(disp
->Extensions
.WL_bind_wayland_display
);
1681 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1683 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
1685 RETURN_EGL_EVAL(disp
, ret
);
1688 static EGLBoolean EGLAPIENTRY
1689 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
1690 EGLint attribute
, EGLint
*value
)
1692 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1696 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1697 assert(disp
->Extensions
.WL_bind_wayland_display
);
1700 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1702 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
1704 RETURN_EGL_EVAL(disp
, ret
);
1708 static struct wl_buffer
* EGLAPIENTRY
1709 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImage image
)
1711 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1714 struct wl_buffer
*ret
;
1716 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
1717 assert(disp
->Extensions
.WL_create_wayland_buffer_from_image
);
1719 img
= _eglLookupImage(image
, disp
);
1722 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
1724 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
1726 RETURN_EGL_EVAL(disp
, ret
);
1729 static EGLBoolean EGLAPIENTRY
1730 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
1731 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
1733 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1734 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1738 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1740 if (!disp
->Extensions
.NV_post_sub_buffer
)
1741 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1743 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
1745 RETURN_EGL_EVAL(disp
, ret
);
1748 static EGLBoolean EGLAPIENTRY
1749 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
1750 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
1753 _EGLDisplay
*disp
= _eglLockDisplay(display
);
1754 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1758 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1759 if (!disp
->Extensions
.CHROMIUM_sync_control
)
1760 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1762 if (!ust
|| !msc
|| !sbc
)
1763 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1765 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
1767 RETURN_EGL_EVAL(disp
, ret
);
1770 static EGLBoolean EGLAPIENTRY
1771 eglExportDMABUFImageQueryMESA(EGLDisplay dpy
, EGLImage image
,
1772 EGLint
*fourcc
, EGLint
*nplanes
,
1773 EGLuint64KHR
*modifiers
)
1775 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1776 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1780 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1781 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
1784 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1786 ret
= drv
->API
.ExportDMABUFImageQueryMESA(drv
, disp
, img
, fourcc
, nplanes
,
1789 RETURN_EGL_EVAL(disp
, ret
);
1792 static EGLBoolean EGLAPIENTRY
1793 eglExportDMABUFImageMESA(EGLDisplay dpy
, EGLImage image
,
1794 int *fds
, EGLint
*strides
, EGLint
*offsets
)
1796 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1797 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1801 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1802 assert(disp
->Extensions
.MESA_image_dma_buf_export
);
1805 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1807 ret
= drv
->API
.ExportDMABUFImageMESA(drv
, disp
, img
, fds
, strides
, offsets
);
1809 RETURN_EGL_EVAL(disp
, ret
);
1812 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
1813 eglGetProcAddress(const char *procname
)
1815 static const struct {
1818 } egl_functions
[] = {
1819 /* core functions queryable in the presence of
1820 * EGL_KHR_get_all_proc_addresses or EGL 1.5
1822 /* alphabetical order */
1823 { "eglBindAPI", (_EGLProc
) eglBindAPI
},
1824 { "eglBindTexImage", (_EGLProc
) eglBindTexImage
},
1825 { "eglChooseConfig", (_EGLProc
) eglChooseConfig
},
1826 { "eglCopyBuffers", (_EGLProc
) eglCopyBuffers
},
1827 { "eglCreateContext", (_EGLProc
) eglCreateContext
},
1828 { "eglCreatePbufferFromClientBuffer", (_EGLProc
) eglCreatePbufferFromClientBuffer
},
1829 { "eglCreatePbufferSurface", (_EGLProc
) eglCreatePbufferSurface
},
1830 { "eglCreatePixmapSurface", (_EGLProc
) eglCreatePixmapSurface
},
1831 { "eglCreateWindowSurface", (_EGLProc
) eglCreateWindowSurface
},
1832 { "eglDestroyContext", (_EGLProc
) eglDestroyContext
},
1833 { "eglDestroySurface", (_EGLProc
) eglDestroySurface
},
1834 { "eglGetConfigAttrib", (_EGLProc
) eglGetConfigAttrib
},
1835 { "eglGetConfigs", (_EGLProc
) eglGetConfigs
},
1836 { "eglGetCurrentContext", (_EGLProc
) eglGetCurrentContext
},
1837 { "eglGetCurrentDisplay", (_EGLProc
) eglGetCurrentDisplay
},
1838 { "eglGetCurrentSurface", (_EGLProc
) eglGetCurrentSurface
},
1839 { "eglGetDisplay", (_EGLProc
) eglGetDisplay
},
1840 { "eglGetError", (_EGLProc
) eglGetError
},
1841 { "eglGetProcAddress", (_EGLProc
) eglGetProcAddress
},
1842 { "eglInitialize", (_EGLProc
) eglInitialize
},
1843 { "eglMakeCurrent", (_EGLProc
) eglMakeCurrent
},
1844 { "eglQueryAPI", (_EGLProc
) eglQueryAPI
},
1845 { "eglQueryContext", (_EGLProc
) eglQueryContext
},
1846 { "eglQueryString", (_EGLProc
) eglQueryString
},
1847 { "eglQuerySurface", (_EGLProc
) eglQuerySurface
},
1848 { "eglReleaseTexImage", (_EGLProc
) eglReleaseTexImage
},
1849 { "eglReleaseThread", (_EGLProc
) eglReleaseThread
},
1850 { "eglSurfaceAttrib", (_EGLProc
) eglSurfaceAttrib
},
1851 { "eglSwapBuffers", (_EGLProc
) eglSwapBuffers
},
1852 { "eglSwapInterval", (_EGLProc
) eglSwapInterval
},
1853 { "eglTerminate", (_EGLProc
) eglTerminate
},
1854 { "eglWaitClient", (_EGLProc
) eglWaitClient
},
1855 { "eglWaitGL", (_EGLProc
) eglWaitGL
},
1856 { "eglWaitNative", (_EGLProc
) eglWaitNative
},
1857 { "eglCreateSync", (_EGLProc
) eglCreateSync
},
1858 { "eglDestroySync", (_EGLProc
) eglDestroySync
},
1859 { "eglClientWaitSync", (_EGLProc
) eglClientWaitSync
},
1860 { "eglGetSyncAttrib", (_EGLProc
) eglGetSyncAttrib
},
1861 { "eglWaitSync", (_EGLProc
) eglWaitSync
},
1862 { "eglCreateImage", (_EGLProc
) eglCreateImage
},
1863 { "eglDestroyImage", (_EGLProc
) eglDestroyImage
},
1864 { "eglGetPlatformDisplay", (_EGLProc
) eglGetPlatformDisplay
},
1865 { "eglCreatePlatformWindowSurface", (_EGLProc
) eglCreatePlatformWindowSurface
},
1866 { "eglCreatePlatformPixmapSurface", (_EGLProc
) eglCreatePlatformPixmapSurface
},
1867 { "eglCreateImageKHR", (_EGLProc
) eglCreateImageKHR
},
1868 { "eglDestroyImageKHR", (_EGLProc
) eglDestroyImage
},
1869 { "eglCreateSyncKHR", (_EGLProc
) eglCreateSyncKHR
},
1870 { "eglCreateSync64KHR", (_EGLProc
) eglCreateSync64KHR
},
1871 { "eglDestroySyncKHR", (_EGLProc
) eglDestroySync
},
1872 { "eglClientWaitSyncKHR", (_EGLProc
) eglClientWaitSync
},
1873 { "eglWaitSyncKHR", (_EGLProc
) eglWaitSyncKHR
},
1874 { "eglSignalSyncKHR", (_EGLProc
) eglSignalSyncKHR
},
1875 { "eglGetSyncAttribKHR", (_EGLProc
) eglGetSyncAttribKHR
},
1876 { "eglSwapBuffersRegionNOK", (_EGLProc
) eglSwapBuffersRegionNOK
},
1877 { "eglCreateDRMImageMESA", (_EGLProc
) eglCreateDRMImageMESA
},
1878 { "eglExportDRMImageMESA", (_EGLProc
) eglExportDRMImageMESA
},
1879 { "eglBindWaylandDisplayWL", (_EGLProc
) eglBindWaylandDisplayWL
},
1880 { "eglUnbindWaylandDisplayWL", (_EGLProc
) eglUnbindWaylandDisplayWL
},
1881 { "eglQueryWaylandBufferWL", (_EGLProc
) eglQueryWaylandBufferWL
},
1882 { "eglCreateWaylandBufferFromImageWL", (_EGLProc
) eglCreateWaylandBufferFromImageWL
},
1883 { "eglPostSubBufferNV", (_EGLProc
) eglPostSubBufferNV
},
1884 { "eglSwapBuffersWithDamageEXT", (_EGLProc
) eglSwapBuffersWithDamageEXT
},
1885 { "eglGetPlatformDisplayEXT", (_EGLProc
) eglGetPlatformDisplayEXT
},
1886 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc
) eglCreatePlatformWindowSurfaceEXT
},
1887 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc
) eglCreatePlatformPixmapSurfaceEXT
},
1888 { "eglGetSyncValuesCHROMIUM", (_EGLProc
) eglGetSyncValuesCHROMIUM
},
1889 { "eglExportDMABUFImageQueryMESA", (_EGLProc
) eglExportDMABUFImageQueryMESA
},
1890 { "eglExportDMABUFImageMESA", (_EGLProc
) eglExportDMABUFImageMESA
},
1897 RETURN_EGL_SUCCESS(NULL
, NULL
);
1900 if (strncmp(procname
, "egl", 3) == 0) {
1901 for (i
= 0; egl_functions
[i
].name
; i
++) {
1902 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
1903 ret
= egl_functions
[i
].function
;
1909 ret
= _eglGetDriverProc(procname
);
1911 RETURN_EGL_SUCCESS(NULL
, ret
);
1915 _eglLockDisplayInterop(EGLDisplay dpy
, EGLContext context
,
1916 _EGLDisplay
**disp
, _EGLDriver
**drv
,
1920 *disp
= _eglLockDisplay(dpy
);
1921 if (!*disp
|| !(*disp
)->Initialized
|| !(*disp
)->Driver
) {
1923 _eglUnlockDisplay(*disp
);
1924 return MESA_GLINTEROP_INVALID_DISPLAY
;
1927 *drv
= (*disp
)->Driver
;
1929 *ctx
= _eglLookupContext(context
, *disp
);
1931 ((*ctx
)->ClientAPI
!= EGL_OPENGL_API
&&
1932 (*ctx
)->ClientAPI
!= EGL_OPENGL_ES_API
)) {
1933 _eglUnlockDisplay(*disp
);
1934 return MESA_GLINTEROP_INVALID_CONTEXT
;
1937 return MESA_GLINTEROP_SUCCESS
;
1941 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy
, EGLContext context
,
1942 struct mesa_glinterop_device_info
*out
)
1949 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
1950 if (ret
!= MESA_GLINTEROP_SUCCESS
)
1953 if (drv
->API
.GLInteropQueryDeviceInfo
)
1954 ret
= drv
->API
.GLInteropQueryDeviceInfo(disp
, ctx
, out
);
1956 ret
= MESA_GLINTEROP_UNSUPPORTED
;
1958 _eglUnlockDisplay(disp
);
1963 MesaGLInteropEGLExportObject(EGLDisplay dpy
, EGLContext context
,
1964 struct mesa_glinterop_export_in
*in
,
1965 struct mesa_glinterop_export_out
*out
)
1972 ret
= _eglLockDisplayInterop(dpy
, context
, &disp
, &drv
, &ctx
);
1973 if (ret
!= MESA_GLINTEROP_SUCCESS
)
1976 if (drv
->API
.GLInteropExportObject
)
1977 ret
= drv
->API
.GLInteropExportObject(disp
, ctx
, in
, out
);
1979 ret
= MESA_GLINTEROP_UNSUPPORTED
;
1981 _eglUnlockDisplay(disp
);