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
90 #include "eglglobals.h"
91 #include "eglcontext.h"
92 #include "egldisplay.h"
93 #include "egltypedefs.h"
94 #include "eglcurrent.h"
95 #include "egldriver.h"
96 #include "eglsurface.h"
97 #include "eglconfig.h"
98 #include "eglscreen.h"
100 #include "eglimage.h"
105 * Macros to help return an API entrypoint.
107 * These macros will unlock the display and record the error code.
109 #define RETURN_EGL_ERROR(disp, err, ret) \
112 _eglUnlockDisplay(disp); \
113 /* EGL error codes are non-zero */ \
115 _eglError(err, __FUNCTION__); \
119 #define RETURN_EGL_SUCCESS(disp, ret) \
120 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
122 /* record EGL_SUCCESS only when ret evaluates to true */
123 #define RETURN_EGL_EVAL(disp, ret) \
124 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
128 * A bunch of macros and checks to simplify error checking.
131 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
133 drv = _eglCheckDisplay(disp, __FUNCTION__); \
135 RETURN_EGL_ERROR(disp, 0, ret); \
138 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
140 drv = _eglCheck ## type(disp, obj, __FUNCTION__); \
142 RETURN_EGL_ERROR(disp, 0, ret); \
145 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
146 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
148 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
149 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
151 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
152 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
154 #define _EGL_CHECK_SCREEN(disp, scrn, ret, drv) \
155 _EGL_CHECK_OBJECT(disp, Screen, scrn, ret, drv)
157 #define _EGL_CHECK_MODE(disp, m, ret, drv) \
158 _EGL_CHECK_OBJECT(disp, Mode, m, ret, drv)
160 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
161 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
164 static INLINE _EGLDriver
*
165 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
168 _eglError(EGL_BAD_DISPLAY
, msg
);
171 if (!disp
->Initialized
) {
172 _eglError(EGL_NOT_INITIALIZED
, msg
);
179 static INLINE _EGLDriver
*
180 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
182 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
186 _eglError(EGL_BAD_SURFACE
, msg
);
193 static INLINE _EGLDriver
*
194 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
196 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
200 _eglError(EGL_BAD_CONTEXT
, msg
);
207 static INLINE _EGLDriver
*
208 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
210 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
214 _eglError(EGL_BAD_CONFIG
, msg
);
221 static INLINE _EGLDriver
*
222 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
224 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
228 _eglError(EGL_BAD_PARAMETER
, msg
);
235 #ifdef EGL_MESA_screen_surface
238 static INLINE _EGLDriver
*
239 _eglCheckScreen(_EGLDisplay
*disp
, _EGLScreen
*scrn
, const char *msg
)
241 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
245 _eglError(EGL_BAD_SCREEN_MESA
, msg
);
252 static INLINE _EGLDriver
*
253 _eglCheckMode(_EGLDisplay
*disp
, _EGLMode
*m
, const char *msg
)
255 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
259 _eglError(EGL_BAD_MODE_MESA
, msg
);
266 #endif /* EGL_MESA_screen_surface */
270 * Lookup and lock a display.
272 static INLINE _EGLDisplay
*
273 _eglLockDisplay(EGLDisplay display
)
275 _EGLDisplay
*dpy
= _eglLookupDisplay(display
);
277 _eglLockMutex(&dpy
->Mutex
);
286 _eglUnlockDisplay(_EGLDisplay
*dpy
)
288 _eglUnlockMutex(&dpy
->Mutex
);
293 * This is typically the first EGL function that an application calls.
294 * It associates a private _EGLDisplay object to the native display.
296 EGLDisplay EGLAPIENTRY
297 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
299 _EGLPlatformType plat
;
301 void *native_display_ptr
;
303 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
304 native_display_ptr
= (void*) nativeDisplay
;
306 plat
= _eglGetNativePlatform(native_display_ptr
);
307 dpy
= _eglFindDisplay(plat
, native_display_ptr
);
308 return _eglGetDisplayHandle(dpy
);
311 EGLDisplay EGLAPIENTRY
312 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
313 const EGLint
*attrib_list
)
318 #ifdef HAVE_X11_PLATFORM
319 case EGL_PLATFORM_X11_EXT
:
320 dpy
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
323 #ifdef HAVE_DRM_PLATFORM
324 case EGL_PLATFORM_GBM_MESA
:
325 dpy
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
329 #ifdef HAVE_WAYLAND_PLATFORM
330 case EGL_PLATFORM_WAYLAND_EXT
:
331 dpy
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
336 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
339 return _eglGetDisplayHandle(dpy
);
343 * This is typically the second EGL function that an application calls.
344 * Here we load/initialize the actual hardware driver.
346 EGLBoolean EGLAPIENTRY
347 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
349 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
352 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
354 if (!disp
->Initialized
) {
355 if (!_eglMatchDriver(disp
, EGL_FALSE
))
356 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
358 /* limit to APIs supported by core */
359 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
361 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
362 * classifies it as an EGL display extension, though conceptually it's an
363 * EGL client extension.
365 * From the EGL_KHR_get_all_proc_addresses spec:
367 * The EGL implementation must expose the name
368 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
369 * EGL_KHR_get_all_proc_addresses and supports
370 * EGL_EXT_client_extensions.
372 * Mesa unconditionally exposes both client extensions mentioned above,
373 * so the spec requires that each EGLDisplay unconditionally expose
374 * EGL_KHR_get_all_proc_addresses also.
376 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
379 /* Update applications version of major and minor if not NULL */
380 if ((major
!= NULL
) && (minor
!= NULL
)) {
381 *major
= disp
->VersionMajor
;
382 *minor
= disp
->VersionMinor
;
385 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
389 EGLBoolean EGLAPIENTRY
390 eglTerminate(EGLDisplay dpy
)
392 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
395 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
397 if (disp
->Initialized
) {
398 _EGLDriver
*drv
= disp
->Driver
;
400 drv
->API
.Terminate(drv
, disp
);
401 /* do not reset disp->Driver */
402 disp
->Initialized
= EGL_FALSE
;
405 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
409 const char * EGLAPIENTRY
410 eglQueryString(EGLDisplay dpy
, EGLint name
)
416 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
417 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
420 disp
= _eglLockDisplay(dpy
);
421 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
422 ret
= drv
->API
.QueryString(drv
, disp
, name
);
424 RETURN_EGL_EVAL(disp
, ret
);
428 EGLBoolean EGLAPIENTRY
429 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
430 EGLint config_size
, EGLint
*num_config
)
432 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
436 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
437 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
439 RETURN_EGL_EVAL(disp
, ret
);
443 EGLBoolean EGLAPIENTRY
444 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
445 EGLint config_size
, EGLint
*num_config
)
447 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
451 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
452 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
453 config_size
, num_config
);
455 RETURN_EGL_EVAL(disp
, ret
);
459 EGLBoolean EGLAPIENTRY
460 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
461 EGLint attribute
, EGLint
*value
)
463 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
464 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
468 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
469 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
471 RETURN_EGL_EVAL(disp
, ret
);
475 EGLContext EGLAPIENTRY
476 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
477 const EGLint
*attrib_list
)
479 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
480 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
481 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
483 _EGLContext
*context
;
486 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
488 if (!config
&& !disp
->Extensions
.MESA_configless_context
)
489 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
491 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
492 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
494 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
495 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
497 RETURN_EGL_EVAL(disp
, ret
);
501 EGLBoolean EGLAPIENTRY
502 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
504 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
505 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
509 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
510 _eglUnlinkContext(context
);
511 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
513 RETURN_EGL_EVAL(disp
, ret
);
517 EGLBoolean EGLAPIENTRY
518 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
521 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
522 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
523 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
524 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
529 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
532 /* display is allowed to be uninitialized under certain condition */
533 if (!disp
->Initialized
) {
534 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
535 ctx
!= EGL_NO_CONTEXT
)
536 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
539 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
541 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
542 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
543 if (!draw_surf
|| !read_surf
) {
544 /* From the EGL 1.4 (20130211) spec:
546 * To release the current context without assigning a new one, set ctx
547 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
549 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
550 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
552 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
553 (!read_surf
&& read
!= EGL_NO_SURFACE
))
554 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
555 if (draw_surf
|| read_surf
)
556 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
559 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
561 RETURN_EGL_EVAL(disp
, ret
);
565 EGLBoolean EGLAPIENTRY
566 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
567 EGLint attribute
, EGLint
*value
)
569 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
570 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
574 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
575 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
577 RETURN_EGL_EVAL(disp
, ret
);
582 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
583 void *native_window
, const EGLint
*attrib_list
)
585 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
590 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
592 if (native_window
== NULL
)
593 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
595 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
597 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
599 RETURN_EGL_EVAL(disp
, ret
);
603 EGLSurface EGLAPIENTRY
604 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
605 EGLNativeWindowType window
, const EGLint
*attrib_list
)
607 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
608 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
609 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
614 EGLSurface EGLAPIENTRY
615 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
617 const EGLint
*attrib_list
)
619 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
621 #ifdef HAVE_X11_PLATFORM
622 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
623 /* The `native_window` parameter for the X11 platform differs between
624 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
625 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
626 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
627 * `Window*`. Convert `Window*` to `Window` because that's what
628 * dri2_x11_create_window_surface() expects.
630 native_window
= (void*) (* (Window
*) native_window
);
634 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
640 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
641 void *native_pixmap
, const EGLint
*attrib_list
)
643 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
648 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
649 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
651 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
653 RETURN_EGL_EVAL(disp
, ret
);
657 EGLSurface EGLAPIENTRY
658 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
659 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
661 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
662 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
663 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
667 EGLSurface EGLAPIENTRY
668 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
670 const EGLint
*attrib_list
)
672 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
674 #ifdef HAVE_X11_PLATFORM
675 /* The `native_pixmap` parameter for the X11 platform differs between
676 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
677 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
678 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
679 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
680 * dri2_x11_create_pixmap_surface() expects.
682 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
) {
683 native_pixmap
= (void*) (* (Pixmap
*) native_pixmap
);
687 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
692 EGLSurface EGLAPIENTRY
693 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
694 const EGLint
*attrib_list
)
696 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
697 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
702 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
704 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
705 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
707 RETURN_EGL_EVAL(disp
, ret
);
711 EGLBoolean EGLAPIENTRY
712 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
714 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
715 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
719 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
720 _eglUnlinkSurface(surf
);
721 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
723 RETURN_EGL_EVAL(disp
, ret
);
726 EGLBoolean EGLAPIENTRY
727 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
728 EGLint attribute
, EGLint
*value
)
730 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
731 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
735 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
736 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
738 RETURN_EGL_EVAL(disp
, ret
);
741 EGLBoolean EGLAPIENTRY
742 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
743 EGLint attribute
, EGLint value
)
745 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
746 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
750 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
751 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
753 RETURN_EGL_EVAL(disp
, ret
);
757 EGLBoolean EGLAPIENTRY
758 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
760 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
761 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
765 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
766 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
768 RETURN_EGL_EVAL(disp
, ret
);
772 EGLBoolean EGLAPIENTRY
773 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
775 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
776 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
780 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
781 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
783 RETURN_EGL_EVAL(disp
, ret
);
787 EGLBoolean EGLAPIENTRY
788 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
790 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
791 _EGLContext
*ctx
= _eglGetCurrentContext();
796 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
798 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
799 ctx
->Resource
.Display
!= disp
)
800 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
802 surf
= ctx
->DrawSurface
;
803 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
804 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
806 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
808 RETURN_EGL_EVAL(disp
, ret
);
812 EGLBoolean EGLAPIENTRY
813 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
815 _EGLContext
*ctx
= _eglGetCurrentContext();
816 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
817 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
821 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
823 /* surface must be bound to current context in EGL 1.4 */
824 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
825 surf
!= ctx
->DrawSurface
)
826 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
828 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
830 RETURN_EGL_EVAL(disp
, ret
);
834 #ifdef EGL_EXT_swap_buffers_with_damage
836 EGLBoolean EGLAPIENTRY
837 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
838 EGLint
*rects
, EGLint n_rects
)
840 _EGLContext
*ctx
= _eglGetCurrentContext();
841 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
842 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
846 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
848 /* surface must be bound to current context in EGL 1.4 */
849 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
850 surf
!= ctx
->DrawSurface
)
851 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
853 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
854 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
856 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
858 RETURN_EGL_EVAL(disp
, ret
);
861 #endif /* EGL_EXT_swap_buffers_with_damage */
863 EGLBoolean EGLAPIENTRY
864 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
866 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
867 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
870 void *native_pixmap_ptr
;
872 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
873 native_pixmap_ptr
= (void*) target
;
875 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
876 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
877 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
878 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
880 RETURN_EGL_EVAL(disp
, ret
);
884 EGLBoolean EGLAPIENTRY
887 _EGLContext
*ctx
= _eglGetCurrentContext();
893 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
895 disp
= ctx
->Resource
.Display
;
896 _eglLockMutex(&disp
->Mutex
);
898 /* let bad current context imply bad current surface */
899 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
900 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
901 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
903 /* a valid current context implies an initialized current display */
904 assert(disp
->Initialized
);
906 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
908 RETURN_EGL_EVAL(disp
, ret
);
912 EGLBoolean EGLAPIENTRY
915 _EGLThreadInfo
*t
= _eglGetCurrentThread();
916 EGLint api_index
= t
->CurrentAPIIndex
;
917 EGLint es_index
= _eglConvertApiToIndex(EGL_OPENGL_ES_API
);
920 if (api_index
!= es_index
&& _eglIsCurrentThreadDummy())
921 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
923 t
->CurrentAPIIndex
= es_index
;
924 ret
= eglWaitClient();
925 t
->CurrentAPIIndex
= api_index
;
930 EGLBoolean EGLAPIENTRY
931 eglWaitNative(EGLint engine
)
933 _EGLContext
*ctx
= _eglGetCurrentContext();
939 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
941 disp
= ctx
->Resource
.Display
;
942 _eglLockMutex(&disp
->Mutex
);
944 /* let bad current context imply bad current surface */
945 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
946 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
947 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
949 /* a valid current context implies an initialized current display */
950 assert(disp
->Initialized
);
952 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
954 RETURN_EGL_EVAL(disp
, ret
);
958 EGLDisplay EGLAPIENTRY
959 eglGetCurrentDisplay(void)
961 _EGLContext
*ctx
= _eglGetCurrentContext();
964 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
966 RETURN_EGL_SUCCESS(NULL
, ret
);
970 EGLContext EGLAPIENTRY
971 eglGetCurrentContext(void)
973 _EGLContext
*ctx
= _eglGetCurrentContext();
976 ret
= _eglGetContextHandle(ctx
);
978 RETURN_EGL_SUCCESS(NULL
, ret
);
982 EGLSurface EGLAPIENTRY
983 eglGetCurrentSurface(EGLint readdraw
)
985 _EGLContext
*ctx
= _eglGetCurrentContext();
986 EGLint err
= EGL_SUCCESS
;
991 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
995 surf
= ctx
->DrawSurface
;
998 surf
= ctx
->ReadSurface
;
1002 err
= EGL_BAD_PARAMETER
;
1006 ret
= _eglGetSurfaceHandle(surf
);
1008 RETURN_EGL_ERROR(NULL
, err
, ret
);
1015 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1016 EGLint e
= t
->LastError
;
1017 if (!_eglIsCurrentThreadDummy())
1018 t
->LastError
= EGL_SUCCESS
;
1023 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
1024 eglGetProcAddress(const char *procname
)
1026 static const struct {
1029 } egl_functions
[] = {
1030 /* core functions should not be queryable, but, well... */
1031 #ifdef _EGL_GET_CORE_ADDRESSES
1032 /* alphabetical order */
1033 { "eglBindAPI", (_EGLProc
) eglBindAPI
},
1034 { "eglBindTexImage", (_EGLProc
) eglBindTexImage
},
1035 { "eglChooseConfig", (_EGLProc
) eglChooseConfig
},
1036 { "eglCopyBuffers", (_EGLProc
) eglCopyBuffers
},
1037 { "eglCreateContext", (_EGLProc
) eglCreateContext
},
1038 { "eglCreatePbufferFromClientBuffer", (_EGLProc
) eglCreatePbufferFromClientBuffer
},
1039 { "eglCreatePbufferSurface", (_EGLProc
) eglCreatePbufferSurface
},
1040 { "eglCreatePixmapSurface", (_EGLProc
) eglCreatePixmapSurface
},
1041 { "eglCreateWindowSurface", (_EGLProc
) eglCreateWindowSurface
},
1042 { "eglDestroyContext", (_EGLProc
) eglDestroyContext
},
1043 { "eglDestroySurface", (_EGLProc
) eglDestroySurface
},
1044 { "eglGetConfigAttrib", (_EGLProc
) eglGetConfigAttrib
},
1045 { "eglGetConfigs", (_EGLProc
) eglGetConfigs
},
1046 { "eglGetCurrentContext", (_EGLProc
) eglGetCurrentContext
},
1047 { "eglGetCurrentDisplay", (_EGLProc
) eglGetCurrentDisplay
},
1048 { "eglGetCurrentSurface", (_EGLProc
) eglGetCurrentSurface
},
1049 { "eglGetDisplay", (_EGLProc
) eglGetDisplay
},
1050 { "eglGetError", (_EGLProc
) eglGetError
},
1051 { "eglGetProcAddress", (_EGLProc
) eglGetProcAddress
},
1052 { "eglInitialize", (_EGLProc
) eglInitialize
},
1053 { "eglMakeCurrent", (_EGLProc
) eglMakeCurrent
},
1054 { "eglQueryAPI", (_EGLProc
) eglQueryAPI
},
1055 { "eglQueryContext", (_EGLProc
) eglQueryContext
},
1056 { "eglQueryString", (_EGLProc
) eglQueryString
},
1057 { "eglQuerySurface", (_EGLProc
) eglQuerySurface
},
1058 { "eglReleaseTexImage", (_EGLProc
) eglReleaseTexImage
},
1059 { "eglReleaseThread", (_EGLProc
) eglReleaseThread
},
1060 { "eglSurfaceAttrib", (_EGLProc
) eglSurfaceAttrib
},
1061 { "eglSwapBuffers", (_EGLProc
) eglSwapBuffers
},
1062 { "eglSwapInterval", (_EGLProc
) eglSwapInterval
},
1063 { "eglTerminate", (_EGLProc
) eglTerminate
},
1064 { "eglWaitClient", (_EGLProc
) eglWaitClient
},
1065 { "eglWaitGL", (_EGLProc
) eglWaitGL
},
1066 { "eglWaitNative", (_EGLProc
) eglWaitNative
},
1067 #endif /* _EGL_GET_CORE_ADDRESSES */
1068 #ifdef EGL_MESA_screen_surface
1069 { "eglChooseModeMESA", (_EGLProc
) eglChooseModeMESA
},
1070 { "eglGetModesMESA", (_EGLProc
) eglGetModesMESA
},
1071 { "eglGetModeAttribMESA", (_EGLProc
) eglGetModeAttribMESA
},
1072 { "eglCopyContextMESA", (_EGLProc
) eglCopyContextMESA
},
1073 { "eglGetScreensMESA", (_EGLProc
) eglGetScreensMESA
},
1074 { "eglCreateScreenSurfaceMESA", (_EGLProc
) eglCreateScreenSurfaceMESA
},
1075 { "eglShowScreenSurfaceMESA", (_EGLProc
) eglShowScreenSurfaceMESA
},
1076 { "eglScreenPositionMESA", (_EGLProc
) eglScreenPositionMESA
},
1077 { "eglQueryScreenMESA", (_EGLProc
) eglQueryScreenMESA
},
1078 { "eglQueryScreenSurfaceMESA", (_EGLProc
) eglQueryScreenSurfaceMESA
},
1079 { "eglQueryScreenModeMESA", (_EGLProc
) eglQueryScreenModeMESA
},
1080 { "eglQueryModeStringMESA", (_EGLProc
) eglQueryModeStringMESA
},
1081 #endif /* EGL_MESA_screen_surface */
1082 #ifdef EGL_MESA_drm_display
1083 { "eglGetDRMDisplayMESA", (_EGLProc
) eglGetDRMDisplayMESA
},
1085 { "eglCreateImageKHR", (_EGLProc
) eglCreateImageKHR
},
1086 { "eglDestroyImageKHR", (_EGLProc
) eglDestroyImageKHR
},
1087 { "eglCreateSyncKHR", (_EGLProc
) eglCreateSyncKHR
},
1088 { "eglDestroySyncKHR", (_EGLProc
) eglDestroySyncKHR
},
1089 { "eglClientWaitSyncKHR", (_EGLProc
) eglClientWaitSyncKHR
},
1090 { "eglSignalSyncKHR", (_EGLProc
) eglSignalSyncKHR
},
1091 { "eglGetSyncAttribKHR", (_EGLProc
) eglGetSyncAttribKHR
},
1092 #ifdef EGL_NOK_swap_region
1093 { "eglSwapBuffersRegionNOK", (_EGLProc
) eglSwapBuffersRegionNOK
},
1095 #ifdef EGL_MESA_drm_image
1096 { "eglCreateDRMImageMESA", (_EGLProc
) eglCreateDRMImageMESA
},
1097 { "eglExportDRMImageMESA", (_EGLProc
) eglExportDRMImageMESA
},
1099 #ifdef EGL_WL_bind_wayland_display
1100 { "eglBindWaylandDisplayWL", (_EGLProc
) eglBindWaylandDisplayWL
},
1101 { "eglUnbindWaylandDisplayWL", (_EGLProc
) eglUnbindWaylandDisplayWL
},
1102 { "eglQueryWaylandBufferWL", (_EGLProc
) eglQueryWaylandBufferWL
},
1104 #ifdef EGL_WL_create_wayland_buffer_from_image
1105 { "eglCreateWaylandBufferFromImageWL", (_EGLProc
) eglCreateWaylandBufferFromImageWL
},
1107 { "eglPostSubBufferNV", (_EGLProc
) eglPostSubBufferNV
},
1108 #ifdef EGL_EXT_swap_buffers_with_damage
1109 { "eglSwapBuffersWithDamageEXT", (_EGLProc
) eglSwapBuffersWithDamageEXT
},
1111 { "eglGetPlatformDisplayEXT", (_EGLProc
) eglGetPlatformDisplayEXT
},
1112 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc
) eglCreatePlatformWindowSurfaceEXT
},
1113 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc
) eglCreatePlatformPixmapSurfaceEXT
},
1114 { "eglGetSyncValuesCHROMIUM", (_EGLProc
) eglGetSyncValuesCHROMIUM
},
1121 RETURN_EGL_SUCCESS(NULL
, NULL
);
1124 if (strncmp(procname
, "egl", 3) == 0) {
1125 for (i
= 0; egl_functions
[i
].name
; i
++) {
1126 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
1127 ret
= egl_functions
[i
].function
;
1133 ret
= _eglGetDriverProc(procname
);
1135 RETURN_EGL_SUCCESS(NULL
, ret
);
1139 #ifdef EGL_MESA_screen_surface
1143 * EGL_MESA_screen extension
1146 EGLBoolean EGLAPIENTRY
1147 eglChooseModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1148 const EGLint
*attrib_list
, EGLModeMESA
*modes
,
1149 EGLint modes_size
, EGLint
*num_modes
)
1151 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1152 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1156 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1157 ret
= drv
->API
.ChooseModeMESA(drv
, disp
, scrn
, attrib_list
,
1158 modes
, modes_size
, num_modes
);
1160 RETURN_EGL_EVAL(disp
, ret
);
1164 EGLBoolean EGLAPIENTRY
1165 eglGetModesMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*modes
,
1166 EGLint mode_size
, EGLint
*num_mode
)
1168 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1169 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1173 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1174 ret
= drv
->API
.GetModesMESA(drv
, disp
, scrn
, modes
, mode_size
, num_mode
);
1176 RETURN_EGL_EVAL(disp
, ret
);
1180 EGLBoolean EGLAPIENTRY
1181 eglGetModeAttribMESA(EGLDisplay dpy
, EGLModeMESA mode
,
1182 EGLint attribute
, EGLint
*value
)
1184 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1185 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1189 _EGL_CHECK_MODE(disp
, m
, EGL_FALSE
, drv
);
1190 ret
= drv
->API
.GetModeAttribMESA(drv
, disp
, m
, attribute
, value
);
1192 RETURN_EGL_EVAL(disp
, ret
);
1196 EGLBoolean EGLAPIENTRY
1197 eglCopyContextMESA(EGLDisplay dpy
, EGLContext source
, EGLContext dest
,
1200 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1201 _EGLContext
*source_context
= _eglLookupContext(source
, disp
);
1202 _EGLContext
*dest_context
= _eglLookupContext(dest
, disp
);
1206 _EGL_CHECK_CONTEXT(disp
, source_context
, EGL_FALSE
, drv
);
1208 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1210 ret
= drv
->API
.CopyContextMESA(drv
, disp
,
1211 source_context
, dest_context
, mask
);
1213 RETURN_EGL_EVAL(disp
, ret
);
1217 EGLBoolean EGLAPIENTRY
1218 eglGetScreensMESA(EGLDisplay dpy
, EGLScreenMESA
*screens
,
1219 EGLint max_screens
, EGLint
*num_screens
)
1221 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1225 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1226 ret
= drv
->API
.GetScreensMESA(drv
, disp
, screens
, max_screens
, num_screens
);
1228 RETURN_EGL_EVAL(disp
, ret
);
1232 EGLSurface EGLAPIENTRY
1233 eglCreateScreenSurfaceMESA(EGLDisplay dpy
, EGLConfig config
,
1234 const EGLint
*attrib_list
)
1236 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1237 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1242 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1244 surf
= drv
->API
.CreateScreenSurfaceMESA(drv
, disp
, conf
, attrib_list
);
1245 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1247 RETURN_EGL_EVAL(disp
, ret
);
1251 EGLBoolean EGLAPIENTRY
1252 eglShowScreenSurfaceMESA(EGLDisplay dpy
, EGLint screen
,
1253 EGLSurface surface
, EGLModeMESA mode
)
1255 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1256 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1257 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1258 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1262 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1263 if (!surf
&& surface
!= EGL_NO_SURFACE
)
1264 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1265 if (!m
&& mode
!= EGL_NO_MODE_MESA
)
1266 RETURN_EGL_ERROR(disp
, EGL_BAD_MODE_MESA
, EGL_FALSE
);
1268 ret
= drv
->API
.ShowScreenSurfaceMESA(drv
, disp
, scrn
, surf
, m
);
1270 RETURN_EGL_EVAL(disp
, ret
);
1274 EGLBoolean EGLAPIENTRY
1275 eglScreenPositionMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLint x
, EGLint y
)
1277 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1278 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1282 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1283 ret
= drv
->API
.ScreenPositionMESA(drv
, disp
, scrn
, x
, y
);
1285 RETURN_EGL_EVAL(disp
, ret
);
1289 EGLBoolean EGLAPIENTRY
1290 eglQueryScreenMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1291 EGLint attribute
, EGLint
*value
)
1293 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1294 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1298 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1299 ret
= drv
->API
.QueryScreenMESA(drv
, disp
, scrn
, attribute
, value
);
1301 RETURN_EGL_EVAL(disp
, ret
);
1305 EGLBoolean EGLAPIENTRY
1306 eglQueryScreenSurfaceMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1307 EGLSurface
*surface
)
1309 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1310 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1315 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1316 ret
= drv
->API
.QueryScreenSurfaceMESA(drv
, disp
, scrn
, &surf
);
1318 *surface
= _eglGetSurfaceHandle(surf
);
1320 RETURN_EGL_EVAL(disp
, ret
);
1324 EGLBoolean EGLAPIENTRY
1325 eglQueryScreenModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*mode
)
1327 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1328 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1333 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1334 ret
= drv
->API
.QueryScreenModeMESA(drv
, disp
, scrn
, &m
);
1338 RETURN_EGL_EVAL(disp
, ret
);
1342 const char * EGLAPIENTRY
1343 eglQueryModeStringMESA(EGLDisplay dpy
, EGLModeMESA mode
)
1345 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1346 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1350 _EGL_CHECK_MODE(disp
, m
, NULL
, drv
);
1351 ret
= drv
->API
.QueryModeStringMESA(drv
, disp
, m
);
1353 RETURN_EGL_EVAL(disp
, ret
);
1357 #endif /* EGL_MESA_screen_surface */
1360 #ifdef EGL_MESA_drm_display
1362 EGLDisplay EGLAPIENTRY
1363 eglGetDRMDisplayMESA(int fd
)
1365 _EGLDisplay
*dpy
= _eglFindDisplay(_EGL_PLATFORM_DRM
, (void *) (intptr_t) fd
);
1366 return _eglGetDisplayHandle(dpy
);
1369 #endif /* EGL_MESA_drm_display */
1376 * Specify the client API to use for subsequent calls including:
1377 * eglCreateContext()
1378 * eglGetCurrentContext()
1379 * eglGetCurrentDisplay()
1380 * eglGetCurrentSurface()
1381 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1384 * See section 3.7 "Rendering Context" in the EGL specification for details.
1386 EGLBoolean EGLAPIENTRY
1387 eglBindAPI(EGLenum api
)
1389 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1391 if (_eglIsCurrentThreadDummy())
1392 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1394 if (!_eglIsApiValid(api
))
1395 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1397 t
->CurrentAPIIndex
= _eglConvertApiToIndex(api
);
1399 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1404 * Return the last value set with eglBindAPI().
1409 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1412 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1413 ret
= _eglConvertApiFromIndex(t
->CurrentAPIIndex
);
1415 RETURN_EGL_SUCCESS(NULL
, ret
);
1419 EGLSurface EGLAPIENTRY
1420 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1421 EGLClientBuffer buffer
, EGLConfig config
,
1422 const EGLint
*attrib_list
)
1424 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1425 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1430 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1432 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1434 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1436 RETURN_EGL_EVAL(disp
, ret
);
1440 EGLBoolean EGLAPIENTRY
1441 eglReleaseThread(void)
1443 /* unbind current contexts */
1444 if (!_eglIsCurrentThreadDummy()) {
1445 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1446 EGLint api_index
= t
->CurrentAPIIndex
;
1449 for (i
= 0; i
< _EGL_API_NUM_APIS
; i
++) {
1450 _EGLContext
*ctx
= t
->CurrentContexts
[i
];
1452 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1455 t
->CurrentAPIIndex
= i
;
1457 _eglLockMutex(&disp
->Mutex
);
1459 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1460 _eglUnlockMutex(&disp
->Mutex
);
1464 t
->CurrentAPIIndex
= api_index
;
1467 _eglDestroyCurrentThread();
1469 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1473 EGLImageKHR EGLAPIENTRY
1474 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1475 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1477 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1478 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1483 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1484 if (!disp
->Extensions
.KHR_image_base
)
1485 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1486 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1487 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1488 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1489 * <ctx> must be EGL_NO_CONTEXT..."
1491 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1492 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1494 img
= drv
->API
.CreateImageKHR(drv
,
1495 disp
, context
, target
, buffer
, attr_list
);
1496 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1498 RETURN_EGL_EVAL(disp
, ret
);
1502 EGLBoolean EGLAPIENTRY
1503 eglDestroyImageKHR(EGLDisplay dpy
, EGLImageKHR image
)
1505 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1506 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1510 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1511 if (!disp
->Extensions
.KHR_image_base
)
1512 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1514 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1516 _eglUnlinkImage(img
);
1517 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1519 RETURN_EGL_EVAL(disp
, ret
);
1523 EGLSyncKHR EGLAPIENTRY
1524 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*attrib_list
)
1526 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1531 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1532 if (!disp
->Extensions
.KHR_reusable_sync
)
1533 RETURN_EGL_EVAL(disp
, EGL_NO_SYNC_KHR
);
1535 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1536 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1538 RETURN_EGL_EVAL(disp
, ret
);
1542 EGLBoolean EGLAPIENTRY
1543 eglDestroySyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
)
1545 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1546 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1550 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1551 assert(disp
->Extensions
.KHR_reusable_sync
);
1554 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1556 RETURN_EGL_EVAL(disp
, ret
);
1561 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLint flags
, EGLTimeKHR timeout
)
1563 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1564 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1568 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1569 assert(disp
->Extensions
.KHR_reusable_sync
);
1570 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1572 RETURN_EGL_EVAL(disp
, ret
);
1576 EGLBoolean EGLAPIENTRY
1577 eglSignalSyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLenum mode
)
1579 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1580 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1584 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1585 assert(disp
->Extensions
.KHR_reusable_sync
);
1586 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
1588 RETURN_EGL_EVAL(disp
, ret
);
1592 EGLBoolean EGLAPIENTRY
1593 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLint attribute
, EGLint
*value
)
1595 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1596 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1600 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1601 assert(disp
->Extensions
.KHR_reusable_sync
);
1602 ret
= drv
->API
.GetSyncAttribKHR(drv
, disp
, s
, attribute
, value
);
1604 RETURN_EGL_EVAL(disp
, ret
);
1608 #ifdef EGL_NOK_swap_region
1610 EGLBoolean EGLAPIENTRY
1611 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
1612 EGLint numRects
, const EGLint
*rects
)
1614 _EGLContext
*ctx
= _eglGetCurrentContext();
1615 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1616 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1620 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1622 if (!disp
->Extensions
.NOK_swap_region
)
1623 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1625 /* surface must be bound to current context in EGL 1.4 */
1626 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1627 surf
!= ctx
->DrawSurface
)
1628 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1630 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
1632 RETURN_EGL_EVAL(disp
, ret
);
1635 #endif /* EGL_NOK_swap_region */
1638 #ifdef EGL_MESA_drm_image
1640 EGLImageKHR EGLAPIENTRY
1641 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
1643 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1648 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1649 if (!disp
->Extensions
.MESA_drm_image
)
1650 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1652 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
1653 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1655 RETURN_EGL_EVAL(disp
, ret
);
1658 EGLBoolean EGLAPIENTRY
1659 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImageKHR image
,
1660 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
1662 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1663 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1667 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1668 assert(disp
->Extensions
.MESA_drm_image
);
1671 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1673 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
1675 RETURN_EGL_EVAL(disp
, ret
);
1680 #ifdef EGL_WL_bind_wayland_display
1683 EGLBoolean EGLAPIENTRY
1684 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1686 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1690 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1691 assert(disp
->Extensions
.WL_bind_wayland_display
);
1694 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1696 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
1698 RETURN_EGL_EVAL(disp
, ret
);
1701 EGLBoolean EGLAPIENTRY
1702 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1704 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1708 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1709 assert(disp
->Extensions
.WL_bind_wayland_display
);
1712 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1714 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
1716 RETURN_EGL_EVAL(disp
, ret
);
1719 EGLBoolean EGLAPIENTRY
1720 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
1721 EGLint attribute
, EGLint
*value
)
1723 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1727 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1728 assert(disp
->Extensions
.WL_bind_wayland_display
);
1731 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1733 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
1735 RETURN_EGL_EVAL(disp
, ret
);
1739 #ifdef EGL_WL_create_wayland_buffer_from_image
1740 struct wl_buffer
* EGLAPIENTRY
1741 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImageKHR image
)
1743 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1746 struct wl_buffer
*ret
;
1748 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
1749 assert(disp
->Extensions
.WL_create_wayland_buffer_from_image
);
1751 img
= _eglLookupImage(image
, disp
);
1754 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
1756 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
1758 RETURN_EGL_EVAL(disp
, ret
);
1762 EGLBoolean EGLAPIENTRY
1763 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
1764 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
1766 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1767 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1771 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1773 if (!disp
->Extensions
.NV_post_sub_buffer
)
1774 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1776 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
1778 RETURN_EGL_EVAL(disp
, ret
);
1781 EGLBoolean EGLAPIENTRY
1782 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
1783 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
1786 _EGLDisplay
*disp
= _eglLockDisplay(display
);
1787 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1791 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1792 if (!disp
->Extensions
.CHROMIUM_sync_control
)
1793 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1795 if (!ust
|| !msc
|| !sbc
)
1796 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1798 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
1800 RETURN_EGL_EVAL(disp
, ret
);