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"
91 #include "eglglobals.h"
92 #include "eglcontext.h"
93 #include "egldisplay.h"
94 #include "egltypedefs.h"
95 #include "eglcurrent.h"
96 #include "egldriver.h"
97 #include "eglsurface.h"
98 #include "eglconfig.h"
99 #include "eglscreen.h"
101 #include "eglimage.h"
106 * Macros to help return an API entrypoint.
108 * These macros will unlock the display and record the error code.
110 #define RETURN_EGL_ERROR(disp, err, ret) \
113 _eglUnlockDisplay(disp); \
114 /* EGL error codes are non-zero */ \
116 _eglError(err, __func__); \
120 #define RETURN_EGL_SUCCESS(disp, ret) \
121 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
123 /* record EGL_SUCCESS only when ret evaluates to true */
124 #define RETURN_EGL_EVAL(disp, ret) \
125 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
129 * A bunch of macros and checks to simplify error checking.
132 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
134 drv = _eglCheckDisplay(disp, __func__); \
136 RETURN_EGL_ERROR(disp, 0, ret); \
139 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
141 drv = _eglCheck ## type(disp, obj, __func__); \
143 RETURN_EGL_ERROR(disp, 0, ret); \
146 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
147 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
149 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
150 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
152 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
153 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
155 #define _EGL_CHECK_SCREEN(disp, scrn, ret, drv) \
156 _EGL_CHECK_OBJECT(disp, Screen, scrn, ret, drv)
158 #define _EGL_CHECK_MODE(disp, m, ret, drv) \
159 _EGL_CHECK_OBJECT(disp, Mode, m, ret, drv)
161 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
162 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
165 static inline _EGLDriver
*
166 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
169 _eglError(EGL_BAD_DISPLAY
, msg
);
172 if (!disp
->Initialized
) {
173 _eglError(EGL_NOT_INITIALIZED
, msg
);
180 static inline _EGLDriver
*
181 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
183 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
187 _eglError(EGL_BAD_SURFACE
, msg
);
194 static inline _EGLDriver
*
195 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
197 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
201 _eglError(EGL_BAD_CONTEXT
, msg
);
208 static inline _EGLDriver
*
209 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
211 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
215 _eglError(EGL_BAD_CONFIG
, msg
);
222 static inline _EGLDriver
*
223 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
225 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
229 _eglError(EGL_BAD_PARAMETER
, msg
);
236 #ifdef EGL_MESA_screen_surface
239 static inline _EGLDriver
*
240 _eglCheckScreen(_EGLDisplay
*disp
, _EGLScreen
*scrn
, const char *msg
)
242 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
246 _eglError(EGL_BAD_SCREEN_MESA
, msg
);
253 static inline _EGLDriver
*
254 _eglCheckMode(_EGLDisplay
*disp
, _EGLMode
*m
, const char *msg
)
256 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
260 _eglError(EGL_BAD_MODE_MESA
, msg
);
267 #endif /* EGL_MESA_screen_surface */
271 * Lookup and lock a display.
273 static inline _EGLDisplay
*
274 _eglLockDisplay(EGLDisplay display
)
276 _EGLDisplay
*dpy
= _eglLookupDisplay(display
);
278 _eglLockMutex(&dpy
->Mutex
);
287 _eglUnlockDisplay(_EGLDisplay
*dpy
)
289 _eglUnlockMutex(&dpy
->Mutex
);
294 * This is typically the first EGL function that an application calls.
295 * It associates a private _EGLDisplay object to the native display.
297 EGLDisplay EGLAPIENTRY
298 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
300 _EGLPlatformType plat
;
302 void *native_display_ptr
;
304 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
305 native_display_ptr
= (void*) nativeDisplay
;
307 plat
= _eglGetNativePlatform(native_display_ptr
);
308 dpy
= _eglFindDisplay(plat
, native_display_ptr
);
309 return _eglGetDisplayHandle(dpy
);
312 EGLDisplay EGLAPIENTRY
313 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
314 const EGLint
*attrib_list
)
319 #ifdef HAVE_X11_PLATFORM
320 case EGL_PLATFORM_X11_EXT
:
321 dpy
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
324 #ifdef HAVE_DRM_PLATFORM
325 case EGL_PLATFORM_GBM_MESA
:
326 dpy
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
330 #ifdef HAVE_WAYLAND_PLATFORM
331 case EGL_PLATFORM_WAYLAND_EXT
:
332 dpy
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
337 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
340 return _eglGetDisplayHandle(dpy
);
344 * This is typically the second EGL function that an application calls.
345 * Here we load/initialize the actual hardware driver.
347 EGLBoolean EGLAPIENTRY
348 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
350 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
353 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
355 if (!disp
->Initialized
) {
356 if (!_eglMatchDriver(disp
, EGL_FALSE
))
357 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
359 /* limit to APIs supported by core */
360 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
362 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
363 * classifies it as an EGL display extension, though conceptually it's an
364 * EGL client extension.
366 * From the EGL_KHR_get_all_proc_addresses spec:
368 * The EGL implementation must expose the name
369 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
370 * EGL_KHR_get_all_proc_addresses and supports
371 * EGL_EXT_client_extensions.
373 * Mesa unconditionally exposes both client extensions mentioned above,
374 * so the spec requires that each EGLDisplay unconditionally expose
375 * EGL_KHR_get_all_proc_addresses also.
377 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
380 /* Update applications version of major and minor if not NULL */
381 if ((major
!= NULL
) && (minor
!= NULL
)) {
382 *major
= disp
->VersionMajor
;
383 *minor
= disp
->VersionMinor
;
386 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
390 EGLBoolean EGLAPIENTRY
391 eglTerminate(EGLDisplay dpy
)
393 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
396 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
398 if (disp
->Initialized
) {
399 _EGLDriver
*drv
= disp
->Driver
;
401 drv
->API
.Terminate(drv
, disp
);
402 /* do not reset disp->Driver */
403 disp
->Initialized
= EGL_FALSE
;
406 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
410 const char * EGLAPIENTRY
411 eglQueryString(EGLDisplay dpy
, EGLint name
)
417 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
418 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
421 disp
= _eglLockDisplay(dpy
);
422 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
423 ret
= drv
->API
.QueryString(drv
, disp
, name
);
425 RETURN_EGL_EVAL(disp
, ret
);
429 EGLBoolean EGLAPIENTRY
430 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
431 EGLint config_size
, EGLint
*num_config
)
433 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
437 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
438 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
440 RETURN_EGL_EVAL(disp
, ret
);
444 EGLBoolean EGLAPIENTRY
445 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
446 EGLint config_size
, EGLint
*num_config
)
448 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
452 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
453 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
454 config_size
, num_config
);
456 RETURN_EGL_EVAL(disp
, ret
);
460 EGLBoolean EGLAPIENTRY
461 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
462 EGLint attribute
, EGLint
*value
)
464 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
465 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
469 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
470 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
472 RETURN_EGL_EVAL(disp
, ret
);
476 EGLContext EGLAPIENTRY
477 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
478 const EGLint
*attrib_list
)
480 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
481 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
482 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
484 _EGLContext
*context
;
487 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
489 if (!config
&& !disp
->Extensions
.MESA_configless_context
)
490 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
492 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
493 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
495 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
496 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
498 RETURN_EGL_EVAL(disp
, ret
);
502 EGLBoolean EGLAPIENTRY
503 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
505 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
506 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
510 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
511 _eglUnlinkContext(context
);
512 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
514 RETURN_EGL_EVAL(disp
, ret
);
518 EGLBoolean EGLAPIENTRY
519 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
522 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
523 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
524 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
525 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
530 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
533 /* display is allowed to be uninitialized under certain condition */
534 if (!disp
->Initialized
) {
535 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
536 ctx
!= EGL_NO_CONTEXT
)
537 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
540 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
542 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
543 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
544 if (!draw_surf
|| !read_surf
) {
545 /* From the EGL 1.4 (20130211) spec:
547 * To release the current context without assigning a new one, set ctx
548 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
550 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
551 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
553 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
554 (!read_surf
&& read
!= EGL_NO_SURFACE
))
555 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
556 if (draw_surf
|| read_surf
)
557 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
560 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
562 RETURN_EGL_EVAL(disp
, ret
);
566 EGLBoolean EGLAPIENTRY
567 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
568 EGLint attribute
, EGLint
*value
)
570 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
571 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
575 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
576 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
578 RETURN_EGL_EVAL(disp
, ret
);
583 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
584 void *native_window
, const EGLint
*attrib_list
)
586 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
591 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
593 if (native_window
== NULL
)
594 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
596 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
598 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
600 RETURN_EGL_EVAL(disp
, ret
);
604 EGLSurface EGLAPIENTRY
605 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
606 EGLNativeWindowType window
, const EGLint
*attrib_list
)
608 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
609 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
610 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
615 EGLSurface EGLAPIENTRY
616 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
618 const EGLint
*attrib_list
)
620 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
622 #ifdef HAVE_X11_PLATFORM
623 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
624 /* The `native_window` parameter for the X11 platform differs between
625 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
626 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
627 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
628 * `Window*`. Convert `Window*` to `Window` because that's what
629 * dri2_x11_create_window_surface() expects.
631 native_window
= (void*) (* (Window
*) native_window
);
635 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
641 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
642 void *native_pixmap
, const EGLint
*attrib_list
)
644 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
649 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
650 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
652 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
654 RETURN_EGL_EVAL(disp
, ret
);
658 EGLSurface EGLAPIENTRY
659 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
660 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
662 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
663 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
664 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
668 EGLSurface EGLAPIENTRY
669 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
671 const EGLint
*attrib_list
)
673 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
675 #ifdef HAVE_X11_PLATFORM
676 /* The `native_pixmap` parameter for the X11 platform differs between
677 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
678 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
679 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
680 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
681 * dri2_x11_create_pixmap_surface() expects.
683 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
) {
684 native_pixmap
= (void*) (* (Pixmap
*) native_pixmap
);
688 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
693 EGLSurface EGLAPIENTRY
694 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
695 const EGLint
*attrib_list
)
697 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
698 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
703 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
705 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
706 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
708 RETURN_EGL_EVAL(disp
, ret
);
712 EGLBoolean EGLAPIENTRY
713 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
715 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
716 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
720 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
721 _eglUnlinkSurface(surf
);
722 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
724 RETURN_EGL_EVAL(disp
, ret
);
727 EGLBoolean EGLAPIENTRY
728 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
729 EGLint attribute
, EGLint
*value
)
731 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
732 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
736 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
737 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
739 RETURN_EGL_EVAL(disp
, ret
);
742 EGLBoolean EGLAPIENTRY
743 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
744 EGLint attribute
, EGLint value
)
746 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
747 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
751 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
752 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
754 RETURN_EGL_EVAL(disp
, ret
);
758 EGLBoolean EGLAPIENTRY
759 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
761 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
762 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
766 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
767 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
769 RETURN_EGL_EVAL(disp
, ret
);
773 EGLBoolean EGLAPIENTRY
774 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
776 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
777 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
781 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
782 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
784 RETURN_EGL_EVAL(disp
, ret
);
788 EGLBoolean EGLAPIENTRY
789 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
791 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
792 _EGLContext
*ctx
= _eglGetCurrentContext();
797 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
799 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
800 ctx
->Resource
.Display
!= disp
)
801 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
803 surf
= ctx
->DrawSurface
;
804 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
805 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
807 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
809 RETURN_EGL_EVAL(disp
, ret
);
813 EGLBoolean EGLAPIENTRY
814 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
816 _EGLContext
*ctx
= _eglGetCurrentContext();
817 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
818 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
822 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
824 /* surface must be bound to current context in EGL 1.4 */
825 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
826 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
827 surf
!= ctx
->DrawSurface
)
828 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
831 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
833 RETURN_EGL_EVAL(disp
, ret
);
837 #ifdef EGL_EXT_swap_buffers_with_damage
839 EGLBoolean EGLAPIENTRY
840 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
841 EGLint
*rects
, EGLint n_rects
)
843 _EGLContext
*ctx
= _eglGetCurrentContext();
844 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
845 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
849 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
851 /* surface must be bound to current context in EGL 1.4 */
852 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
853 surf
!= ctx
->DrawSurface
)
854 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
856 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
857 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
859 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
861 RETURN_EGL_EVAL(disp
, ret
);
864 #endif /* EGL_EXT_swap_buffers_with_damage */
866 EGLBoolean EGLAPIENTRY
867 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
869 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
870 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
873 void *native_pixmap_ptr
;
875 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
876 native_pixmap_ptr
= (void*) target
;
878 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
879 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
880 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
881 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
883 RETURN_EGL_EVAL(disp
, ret
);
887 EGLBoolean EGLAPIENTRY
890 _EGLContext
*ctx
= _eglGetCurrentContext();
896 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
898 disp
= ctx
->Resource
.Display
;
899 _eglLockMutex(&disp
->Mutex
);
901 /* let bad current context imply bad current surface */
902 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
903 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
904 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
906 /* a valid current context implies an initialized current display */
907 assert(disp
->Initialized
);
909 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
911 RETURN_EGL_EVAL(disp
, ret
);
915 EGLBoolean EGLAPIENTRY
918 _EGLThreadInfo
*t
= _eglGetCurrentThread();
919 EGLint api_index
= t
->CurrentAPIIndex
;
920 EGLint es_index
= _eglConvertApiToIndex(EGL_OPENGL_ES_API
);
923 if (api_index
!= es_index
&& _eglIsCurrentThreadDummy())
924 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
926 t
->CurrentAPIIndex
= es_index
;
927 ret
= eglWaitClient();
928 t
->CurrentAPIIndex
= api_index
;
933 EGLBoolean EGLAPIENTRY
934 eglWaitNative(EGLint engine
)
936 _EGLContext
*ctx
= _eglGetCurrentContext();
942 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
944 disp
= ctx
->Resource
.Display
;
945 _eglLockMutex(&disp
->Mutex
);
947 /* let bad current context imply bad current surface */
948 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
949 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
950 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
952 /* a valid current context implies an initialized current display */
953 assert(disp
->Initialized
);
955 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
957 RETURN_EGL_EVAL(disp
, ret
);
961 EGLDisplay EGLAPIENTRY
962 eglGetCurrentDisplay(void)
964 _EGLContext
*ctx
= _eglGetCurrentContext();
967 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
969 RETURN_EGL_SUCCESS(NULL
, ret
);
973 EGLContext EGLAPIENTRY
974 eglGetCurrentContext(void)
976 _EGLContext
*ctx
= _eglGetCurrentContext();
979 ret
= _eglGetContextHandle(ctx
);
981 RETURN_EGL_SUCCESS(NULL
, ret
);
985 EGLSurface EGLAPIENTRY
986 eglGetCurrentSurface(EGLint readdraw
)
988 _EGLContext
*ctx
= _eglGetCurrentContext();
989 EGLint err
= EGL_SUCCESS
;
994 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
998 surf
= ctx
->DrawSurface
;
1001 surf
= ctx
->ReadSurface
;
1005 err
= EGL_BAD_PARAMETER
;
1009 ret
= _eglGetSurfaceHandle(surf
);
1011 RETURN_EGL_ERROR(NULL
, err
, ret
);
1018 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1019 EGLint e
= t
->LastError
;
1020 if (!_eglIsCurrentThreadDummy())
1021 t
->LastError
= EGL_SUCCESS
;
1026 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
1027 eglGetProcAddress(const char *procname
)
1029 static const struct {
1032 } egl_functions
[] = {
1033 /* core functions should not be queryable, but, well... */
1034 #ifdef _EGL_GET_CORE_ADDRESSES
1035 /* alphabetical order */
1036 { "eglBindAPI", (_EGLProc
) eglBindAPI
},
1037 { "eglBindTexImage", (_EGLProc
) eglBindTexImage
},
1038 { "eglChooseConfig", (_EGLProc
) eglChooseConfig
},
1039 { "eglCopyBuffers", (_EGLProc
) eglCopyBuffers
},
1040 { "eglCreateContext", (_EGLProc
) eglCreateContext
},
1041 { "eglCreatePbufferFromClientBuffer", (_EGLProc
) eglCreatePbufferFromClientBuffer
},
1042 { "eglCreatePbufferSurface", (_EGLProc
) eglCreatePbufferSurface
},
1043 { "eglCreatePixmapSurface", (_EGLProc
) eglCreatePixmapSurface
},
1044 { "eglCreateWindowSurface", (_EGLProc
) eglCreateWindowSurface
},
1045 { "eglDestroyContext", (_EGLProc
) eglDestroyContext
},
1046 { "eglDestroySurface", (_EGLProc
) eglDestroySurface
},
1047 { "eglGetConfigAttrib", (_EGLProc
) eglGetConfigAttrib
},
1048 { "eglGetConfigs", (_EGLProc
) eglGetConfigs
},
1049 { "eglGetCurrentContext", (_EGLProc
) eglGetCurrentContext
},
1050 { "eglGetCurrentDisplay", (_EGLProc
) eglGetCurrentDisplay
},
1051 { "eglGetCurrentSurface", (_EGLProc
) eglGetCurrentSurface
},
1052 { "eglGetDisplay", (_EGLProc
) eglGetDisplay
},
1053 { "eglGetError", (_EGLProc
) eglGetError
},
1054 { "eglGetProcAddress", (_EGLProc
) eglGetProcAddress
},
1055 { "eglInitialize", (_EGLProc
) eglInitialize
},
1056 { "eglMakeCurrent", (_EGLProc
) eglMakeCurrent
},
1057 { "eglQueryAPI", (_EGLProc
) eglQueryAPI
},
1058 { "eglQueryContext", (_EGLProc
) eglQueryContext
},
1059 { "eglQueryString", (_EGLProc
) eglQueryString
},
1060 { "eglQuerySurface", (_EGLProc
) eglQuerySurface
},
1061 { "eglReleaseTexImage", (_EGLProc
) eglReleaseTexImage
},
1062 { "eglReleaseThread", (_EGLProc
) eglReleaseThread
},
1063 { "eglSurfaceAttrib", (_EGLProc
) eglSurfaceAttrib
},
1064 { "eglSwapBuffers", (_EGLProc
) eglSwapBuffers
},
1065 { "eglSwapInterval", (_EGLProc
) eglSwapInterval
},
1066 { "eglTerminate", (_EGLProc
) eglTerminate
},
1067 { "eglWaitClient", (_EGLProc
) eglWaitClient
},
1068 { "eglWaitGL", (_EGLProc
) eglWaitGL
},
1069 { "eglWaitNative", (_EGLProc
) eglWaitNative
},
1070 #endif /* _EGL_GET_CORE_ADDRESSES */
1071 #ifdef EGL_MESA_screen_surface
1072 { "eglChooseModeMESA", (_EGLProc
) eglChooseModeMESA
},
1073 { "eglGetModesMESA", (_EGLProc
) eglGetModesMESA
},
1074 { "eglGetModeAttribMESA", (_EGLProc
) eglGetModeAttribMESA
},
1075 { "eglCopyContextMESA", (_EGLProc
) eglCopyContextMESA
},
1076 { "eglGetScreensMESA", (_EGLProc
) eglGetScreensMESA
},
1077 { "eglCreateScreenSurfaceMESA", (_EGLProc
) eglCreateScreenSurfaceMESA
},
1078 { "eglShowScreenSurfaceMESA", (_EGLProc
) eglShowScreenSurfaceMESA
},
1079 { "eglScreenPositionMESA", (_EGLProc
) eglScreenPositionMESA
},
1080 { "eglQueryScreenMESA", (_EGLProc
) eglQueryScreenMESA
},
1081 { "eglQueryScreenSurfaceMESA", (_EGLProc
) eglQueryScreenSurfaceMESA
},
1082 { "eglQueryScreenModeMESA", (_EGLProc
) eglQueryScreenModeMESA
},
1083 { "eglQueryModeStringMESA", (_EGLProc
) eglQueryModeStringMESA
},
1084 #endif /* EGL_MESA_screen_surface */
1085 #ifdef EGL_MESA_drm_display
1086 { "eglGetDRMDisplayMESA", (_EGLProc
) eglGetDRMDisplayMESA
},
1088 { "eglCreateImageKHR", (_EGLProc
) eglCreateImageKHR
},
1089 { "eglDestroyImageKHR", (_EGLProc
) eglDestroyImageKHR
},
1090 { "eglCreateSyncKHR", (_EGLProc
) eglCreateSyncKHR
},
1091 { "eglDestroySyncKHR", (_EGLProc
) eglDestroySyncKHR
},
1092 { "eglClientWaitSyncKHR", (_EGLProc
) eglClientWaitSyncKHR
},
1093 { "eglSignalSyncKHR", (_EGLProc
) eglSignalSyncKHR
},
1094 { "eglGetSyncAttribKHR", (_EGLProc
) eglGetSyncAttribKHR
},
1095 #ifdef EGL_NOK_swap_region
1096 { "eglSwapBuffersRegionNOK", (_EGLProc
) eglSwapBuffersRegionNOK
},
1098 #ifdef EGL_MESA_drm_image
1099 { "eglCreateDRMImageMESA", (_EGLProc
) eglCreateDRMImageMESA
},
1100 { "eglExportDRMImageMESA", (_EGLProc
) eglExportDRMImageMESA
},
1102 #ifdef EGL_WL_bind_wayland_display
1103 { "eglBindWaylandDisplayWL", (_EGLProc
) eglBindWaylandDisplayWL
},
1104 { "eglUnbindWaylandDisplayWL", (_EGLProc
) eglUnbindWaylandDisplayWL
},
1105 { "eglQueryWaylandBufferWL", (_EGLProc
) eglQueryWaylandBufferWL
},
1107 #ifdef EGL_WL_create_wayland_buffer_from_image
1108 { "eglCreateWaylandBufferFromImageWL", (_EGLProc
) eglCreateWaylandBufferFromImageWL
},
1110 { "eglPostSubBufferNV", (_EGLProc
) eglPostSubBufferNV
},
1111 #ifdef EGL_EXT_swap_buffers_with_damage
1112 { "eglSwapBuffersWithDamageEXT", (_EGLProc
) eglSwapBuffersWithDamageEXT
},
1114 { "eglGetPlatformDisplayEXT", (_EGLProc
) eglGetPlatformDisplayEXT
},
1115 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc
) eglCreatePlatformWindowSurfaceEXT
},
1116 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc
) eglCreatePlatformPixmapSurfaceEXT
},
1117 { "eglGetSyncValuesCHROMIUM", (_EGLProc
) eglGetSyncValuesCHROMIUM
},
1124 RETURN_EGL_SUCCESS(NULL
, NULL
);
1127 if (strncmp(procname
, "egl", 3) == 0) {
1128 for (i
= 0; egl_functions
[i
].name
; i
++) {
1129 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
1130 ret
= egl_functions
[i
].function
;
1136 ret
= _eglGetDriverProc(procname
);
1138 RETURN_EGL_SUCCESS(NULL
, ret
);
1142 #ifdef EGL_MESA_screen_surface
1146 * EGL_MESA_screen extension
1149 EGLBoolean EGLAPIENTRY
1150 eglChooseModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1151 const EGLint
*attrib_list
, EGLModeMESA
*modes
,
1152 EGLint modes_size
, EGLint
*num_modes
)
1154 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1155 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1159 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1160 ret
= drv
->API
.ChooseModeMESA(drv
, disp
, scrn
, attrib_list
,
1161 modes
, modes_size
, num_modes
);
1163 RETURN_EGL_EVAL(disp
, ret
);
1167 EGLBoolean EGLAPIENTRY
1168 eglGetModesMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*modes
,
1169 EGLint mode_size
, EGLint
*num_mode
)
1171 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1172 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1176 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1177 ret
= drv
->API
.GetModesMESA(drv
, disp
, scrn
, modes
, mode_size
, num_mode
);
1179 RETURN_EGL_EVAL(disp
, ret
);
1183 EGLBoolean EGLAPIENTRY
1184 eglGetModeAttribMESA(EGLDisplay dpy
, EGLModeMESA mode
,
1185 EGLint attribute
, EGLint
*value
)
1187 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1188 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1192 _EGL_CHECK_MODE(disp
, m
, EGL_FALSE
, drv
);
1193 ret
= drv
->API
.GetModeAttribMESA(drv
, disp
, m
, attribute
, value
);
1195 RETURN_EGL_EVAL(disp
, ret
);
1199 EGLBoolean EGLAPIENTRY
1200 eglCopyContextMESA(EGLDisplay dpy
, EGLContext source
, EGLContext dest
,
1203 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1204 _EGLContext
*source_context
= _eglLookupContext(source
, disp
);
1205 _EGLContext
*dest_context
= _eglLookupContext(dest
, disp
);
1209 _EGL_CHECK_CONTEXT(disp
, source_context
, EGL_FALSE
, drv
);
1211 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1213 ret
= drv
->API
.CopyContextMESA(drv
, disp
,
1214 source_context
, dest_context
, mask
);
1216 RETURN_EGL_EVAL(disp
, ret
);
1220 EGLBoolean EGLAPIENTRY
1221 eglGetScreensMESA(EGLDisplay dpy
, EGLScreenMESA
*screens
,
1222 EGLint max_screens
, EGLint
*num_screens
)
1224 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1228 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1229 ret
= drv
->API
.GetScreensMESA(drv
, disp
, screens
, max_screens
, num_screens
);
1231 RETURN_EGL_EVAL(disp
, ret
);
1235 EGLSurface EGLAPIENTRY
1236 eglCreateScreenSurfaceMESA(EGLDisplay dpy
, EGLConfig config
,
1237 const EGLint
*attrib_list
)
1239 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1240 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1245 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1247 surf
= drv
->API
.CreateScreenSurfaceMESA(drv
, disp
, conf
, attrib_list
);
1248 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1250 RETURN_EGL_EVAL(disp
, ret
);
1254 EGLBoolean EGLAPIENTRY
1255 eglShowScreenSurfaceMESA(EGLDisplay dpy
, EGLint screen
,
1256 EGLSurface surface
, EGLModeMESA mode
)
1258 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1259 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1260 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1261 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1265 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1266 if (!surf
&& surface
!= EGL_NO_SURFACE
)
1267 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1268 if (!m
&& mode
!= EGL_NO_MODE_MESA
)
1269 RETURN_EGL_ERROR(disp
, EGL_BAD_MODE_MESA
, EGL_FALSE
);
1271 ret
= drv
->API
.ShowScreenSurfaceMESA(drv
, disp
, scrn
, surf
, m
);
1273 RETURN_EGL_EVAL(disp
, ret
);
1277 EGLBoolean EGLAPIENTRY
1278 eglScreenPositionMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLint x
, EGLint y
)
1280 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1281 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1285 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1286 ret
= drv
->API
.ScreenPositionMESA(drv
, disp
, scrn
, x
, y
);
1288 RETURN_EGL_EVAL(disp
, ret
);
1292 EGLBoolean EGLAPIENTRY
1293 eglQueryScreenMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1294 EGLint attribute
, EGLint
*value
)
1296 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1297 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1301 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1302 ret
= drv
->API
.QueryScreenMESA(drv
, disp
, scrn
, attribute
, value
);
1304 RETURN_EGL_EVAL(disp
, ret
);
1308 EGLBoolean EGLAPIENTRY
1309 eglQueryScreenSurfaceMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1310 EGLSurface
*surface
)
1312 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1313 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1318 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1319 ret
= drv
->API
.QueryScreenSurfaceMESA(drv
, disp
, scrn
, &surf
);
1321 *surface
= _eglGetSurfaceHandle(surf
);
1323 RETURN_EGL_EVAL(disp
, ret
);
1327 EGLBoolean EGLAPIENTRY
1328 eglQueryScreenModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*mode
)
1330 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1331 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1336 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1337 ret
= drv
->API
.QueryScreenModeMESA(drv
, disp
, scrn
, &m
);
1341 RETURN_EGL_EVAL(disp
, ret
);
1345 const char * EGLAPIENTRY
1346 eglQueryModeStringMESA(EGLDisplay dpy
, EGLModeMESA mode
)
1348 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1349 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1353 _EGL_CHECK_MODE(disp
, m
, NULL
, drv
);
1354 ret
= drv
->API
.QueryModeStringMESA(drv
, disp
, m
);
1356 RETURN_EGL_EVAL(disp
, ret
);
1360 #endif /* EGL_MESA_screen_surface */
1363 #ifdef EGL_MESA_drm_display
1365 EGLDisplay EGLAPIENTRY
1366 eglGetDRMDisplayMESA(int fd
)
1368 _EGLDisplay
*dpy
= _eglFindDisplay(_EGL_PLATFORM_DRM
, (void *) (intptr_t) fd
);
1369 return _eglGetDisplayHandle(dpy
);
1372 #endif /* EGL_MESA_drm_display */
1379 * Specify the client API to use for subsequent calls including:
1380 * eglCreateContext()
1381 * eglGetCurrentContext()
1382 * eglGetCurrentDisplay()
1383 * eglGetCurrentSurface()
1384 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1387 * See section 3.7 "Rendering Context" in the EGL specification for details.
1389 EGLBoolean EGLAPIENTRY
1390 eglBindAPI(EGLenum api
)
1392 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1394 if (_eglIsCurrentThreadDummy())
1395 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1397 if (!_eglIsApiValid(api
))
1398 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1400 t
->CurrentAPIIndex
= _eglConvertApiToIndex(api
);
1402 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1407 * Return the last value set with eglBindAPI().
1412 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1415 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1416 ret
= _eglConvertApiFromIndex(t
->CurrentAPIIndex
);
1418 RETURN_EGL_SUCCESS(NULL
, ret
);
1422 EGLSurface EGLAPIENTRY
1423 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1424 EGLClientBuffer buffer
, EGLConfig config
,
1425 const EGLint
*attrib_list
)
1427 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1428 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1433 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1435 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1437 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1439 RETURN_EGL_EVAL(disp
, ret
);
1443 EGLBoolean EGLAPIENTRY
1444 eglReleaseThread(void)
1446 /* unbind current contexts */
1447 if (!_eglIsCurrentThreadDummy()) {
1448 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1449 EGLint api_index
= t
->CurrentAPIIndex
;
1452 for (i
= 0; i
< _EGL_API_NUM_APIS
; i
++) {
1453 _EGLContext
*ctx
= t
->CurrentContexts
[i
];
1455 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1458 t
->CurrentAPIIndex
= i
;
1460 _eglLockMutex(&disp
->Mutex
);
1462 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1463 _eglUnlockMutex(&disp
->Mutex
);
1467 t
->CurrentAPIIndex
= api_index
;
1470 _eglDestroyCurrentThread();
1472 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1476 EGLImageKHR EGLAPIENTRY
1477 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1478 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1480 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1481 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1486 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1487 if (!disp
->Extensions
.KHR_image_base
)
1488 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1489 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1490 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1491 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1492 * <ctx> must be EGL_NO_CONTEXT..."
1494 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1495 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1497 img
= drv
->API
.CreateImageKHR(drv
,
1498 disp
, context
, target
, buffer
, attr_list
);
1499 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1501 RETURN_EGL_EVAL(disp
, ret
);
1505 EGLBoolean EGLAPIENTRY
1506 eglDestroyImageKHR(EGLDisplay dpy
, EGLImageKHR image
)
1508 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1509 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1513 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1514 if (!disp
->Extensions
.KHR_image_base
)
1515 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1517 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1519 _eglUnlinkImage(img
);
1520 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1522 RETURN_EGL_EVAL(disp
, ret
);
1526 EGLSyncKHR EGLAPIENTRY
1527 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*attrib_list
)
1529 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1534 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1535 if (!disp
->Extensions
.KHR_reusable_sync
)
1536 RETURN_EGL_EVAL(disp
, EGL_NO_SYNC_KHR
);
1538 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1539 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1541 RETURN_EGL_EVAL(disp
, ret
);
1545 EGLBoolean EGLAPIENTRY
1546 eglDestroySyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
)
1548 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1549 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1553 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1554 assert(disp
->Extensions
.KHR_reusable_sync
);
1557 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1559 RETURN_EGL_EVAL(disp
, ret
);
1564 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLint flags
, EGLTimeKHR timeout
)
1566 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1567 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1571 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1572 assert(disp
->Extensions
.KHR_reusable_sync
);
1573 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1575 RETURN_EGL_EVAL(disp
, ret
);
1579 EGLBoolean EGLAPIENTRY
1580 eglSignalSyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLenum mode
)
1582 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1583 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1587 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1588 assert(disp
->Extensions
.KHR_reusable_sync
);
1589 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
1591 RETURN_EGL_EVAL(disp
, ret
);
1595 EGLBoolean EGLAPIENTRY
1596 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLint attribute
, EGLint
*value
)
1598 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1599 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1603 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1604 assert(disp
->Extensions
.KHR_reusable_sync
);
1605 ret
= drv
->API
.GetSyncAttribKHR(drv
, disp
, s
, attribute
, value
);
1607 RETURN_EGL_EVAL(disp
, ret
);
1611 #ifdef EGL_NOK_swap_region
1613 EGLBoolean EGLAPIENTRY
1614 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
1615 EGLint numRects
, const EGLint
*rects
)
1617 _EGLContext
*ctx
= _eglGetCurrentContext();
1618 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1619 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1623 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1625 if (!disp
->Extensions
.NOK_swap_region
)
1626 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1628 /* surface must be bound to current context in EGL 1.4 */
1629 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1630 surf
!= ctx
->DrawSurface
)
1631 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1633 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
1635 RETURN_EGL_EVAL(disp
, ret
);
1638 #endif /* EGL_NOK_swap_region */
1641 #ifdef EGL_MESA_drm_image
1643 EGLImageKHR EGLAPIENTRY
1644 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
1646 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1651 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1652 if (!disp
->Extensions
.MESA_drm_image
)
1653 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1655 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
1656 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1658 RETURN_EGL_EVAL(disp
, ret
);
1661 EGLBoolean EGLAPIENTRY
1662 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImageKHR image
,
1663 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
1665 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1666 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1670 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1671 assert(disp
->Extensions
.MESA_drm_image
);
1674 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1676 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
1678 RETURN_EGL_EVAL(disp
, ret
);
1683 #ifdef EGL_WL_bind_wayland_display
1686 EGLBoolean EGLAPIENTRY
1687 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1689 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1693 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1694 assert(disp
->Extensions
.WL_bind_wayland_display
);
1697 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1699 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
1701 RETURN_EGL_EVAL(disp
, ret
);
1704 EGLBoolean EGLAPIENTRY
1705 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1707 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1711 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1712 assert(disp
->Extensions
.WL_bind_wayland_display
);
1715 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1717 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
1719 RETURN_EGL_EVAL(disp
, ret
);
1722 EGLBoolean EGLAPIENTRY
1723 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
1724 EGLint attribute
, EGLint
*value
)
1726 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1730 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1731 assert(disp
->Extensions
.WL_bind_wayland_display
);
1734 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1736 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
1738 RETURN_EGL_EVAL(disp
, ret
);
1742 #ifdef EGL_WL_create_wayland_buffer_from_image
1743 struct wl_buffer
* EGLAPIENTRY
1744 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImageKHR image
)
1746 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1749 struct wl_buffer
*ret
;
1751 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
1752 assert(disp
->Extensions
.WL_create_wayland_buffer_from_image
);
1754 img
= _eglLookupImage(image
, disp
);
1757 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
1759 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
1761 RETURN_EGL_EVAL(disp
, ret
);
1765 EGLBoolean EGLAPIENTRY
1766 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
1767 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
1769 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1770 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1774 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1776 if (!disp
->Extensions
.NV_post_sub_buffer
)
1777 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1779 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
1781 RETURN_EGL_EVAL(disp
, ret
);
1784 EGLBoolean EGLAPIENTRY
1785 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
1786 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
1789 _EGLDisplay
*disp
= _eglLockDisplay(display
);
1790 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1794 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1795 if (!disp
->Extensions
.CHROMIUM_sync_control
)
1796 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1798 if (!ust
|| !msc
|| !sbc
)
1799 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1801 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
1803 RETURN_EGL_EVAL(disp
, ret
);