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
;
362 /* Update applications version of major and minor if not NULL */
363 if ((major
!= NULL
) && (minor
!= NULL
)) {
364 *major
= disp
->VersionMajor
;
365 *minor
= disp
->VersionMinor
;
368 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
372 EGLBoolean EGLAPIENTRY
373 eglTerminate(EGLDisplay dpy
)
375 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
378 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
380 if (disp
->Initialized
) {
381 _EGLDriver
*drv
= disp
->Driver
;
383 drv
->API
.Terminate(drv
, disp
);
384 /* do not reset disp->Driver */
385 disp
->Initialized
= EGL_FALSE
;
388 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
392 const char * EGLAPIENTRY
393 eglQueryString(EGLDisplay dpy
, EGLint name
)
399 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
400 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
403 disp
= _eglLockDisplay(dpy
);
404 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
405 ret
= drv
->API
.QueryString(drv
, disp
, name
);
407 RETURN_EGL_EVAL(disp
, ret
);
411 EGLBoolean EGLAPIENTRY
412 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
413 EGLint config_size
, EGLint
*num_config
)
415 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
419 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
420 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
422 RETURN_EGL_EVAL(disp
, ret
);
426 EGLBoolean EGLAPIENTRY
427 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
428 EGLint config_size
, EGLint
*num_config
)
430 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
434 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
435 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
436 config_size
, num_config
);
438 RETURN_EGL_EVAL(disp
, ret
);
442 EGLBoolean EGLAPIENTRY
443 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
444 EGLint attribute
, EGLint
*value
)
446 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
447 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
451 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
452 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
454 RETURN_EGL_EVAL(disp
, ret
);
458 EGLContext EGLAPIENTRY
459 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
460 const EGLint
*attrib_list
)
462 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
463 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
464 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
466 _EGLContext
*context
;
469 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
471 if (!config
&& !disp
->Extensions
.MESA_configless_context
)
472 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
474 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
475 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
477 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
478 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
480 RETURN_EGL_EVAL(disp
, ret
);
484 EGLBoolean EGLAPIENTRY
485 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
487 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
488 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
492 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
493 _eglUnlinkContext(context
);
494 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
496 RETURN_EGL_EVAL(disp
, ret
);
500 EGLBoolean EGLAPIENTRY
501 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
504 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
505 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
506 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
507 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
512 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
515 /* display is allowed to be uninitialized under certain condition */
516 if (!disp
->Initialized
) {
517 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
518 ctx
!= EGL_NO_CONTEXT
)
519 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
522 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
524 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
525 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
526 if (!draw_surf
|| !read_surf
) {
527 /* From the EGL 1.4 (20130211) spec:
529 * To release the current context without assigning a new one, set ctx
530 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
532 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
533 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
535 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
536 (!read_surf
&& read
!= EGL_NO_SURFACE
))
537 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
538 if (draw_surf
|| read_surf
)
539 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
542 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
544 RETURN_EGL_EVAL(disp
, ret
);
548 EGLBoolean EGLAPIENTRY
549 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
550 EGLint attribute
, EGLint
*value
)
552 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
553 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
557 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
558 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
560 RETURN_EGL_EVAL(disp
, ret
);
565 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
566 void *native_window
, const EGLint
*attrib_list
)
568 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
573 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
575 if (native_window
== NULL
)
576 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
578 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
580 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
582 RETURN_EGL_EVAL(disp
, ret
);
586 EGLSurface EGLAPIENTRY
587 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
588 EGLNativeWindowType window
, const EGLint
*attrib_list
)
590 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
591 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
592 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
597 EGLSurface EGLAPIENTRY
598 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
600 const EGLint
*attrib_list
)
602 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
604 #ifdef HAVE_X11_PLATFORM
605 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
606 /* The `native_window` parameter for the X11 platform differs between
607 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
608 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
609 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
610 * `Window*`. Convert `Window*` to `Window` because that's what
611 * dri2_x11_create_window_surface() expects.
613 native_window
= (void*) (* (Window
*) native_window
);
617 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
623 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
624 void *native_pixmap
, const EGLint
*attrib_list
)
626 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
631 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
632 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
634 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
636 RETURN_EGL_EVAL(disp
, ret
);
640 EGLSurface EGLAPIENTRY
641 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
642 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
644 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
645 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
646 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
650 EGLSurface EGLAPIENTRY
651 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
653 const EGLint
*attrib_list
)
655 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
657 #ifdef HAVE_X11_PLATFORM
658 /* The `native_pixmap` parameter for the X11 platform differs between
659 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
660 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
661 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
662 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
663 * dri2_x11_create_pixmap_surface() expects.
665 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
) {
666 native_pixmap
= (void*) (* (Pixmap
*) native_pixmap
);
670 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
675 EGLSurface EGLAPIENTRY
676 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
677 const EGLint
*attrib_list
)
679 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
680 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
685 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
687 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
688 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
690 RETURN_EGL_EVAL(disp
, ret
);
694 EGLBoolean EGLAPIENTRY
695 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
697 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
698 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
702 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
703 _eglUnlinkSurface(surf
);
704 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
706 RETURN_EGL_EVAL(disp
, ret
);
709 EGLBoolean EGLAPIENTRY
710 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
711 EGLint attribute
, EGLint
*value
)
713 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
714 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
718 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
719 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
721 RETURN_EGL_EVAL(disp
, ret
);
724 EGLBoolean EGLAPIENTRY
725 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
726 EGLint attribute
, EGLint value
)
728 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
729 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
733 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
734 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
736 RETURN_EGL_EVAL(disp
, ret
);
740 EGLBoolean EGLAPIENTRY
741 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
743 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
744 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
748 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
749 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
751 RETURN_EGL_EVAL(disp
, ret
);
755 EGLBoolean EGLAPIENTRY
756 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
758 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
759 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
763 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
764 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
766 RETURN_EGL_EVAL(disp
, ret
);
770 EGLBoolean EGLAPIENTRY
771 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
773 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
774 _EGLContext
*ctx
= _eglGetCurrentContext();
779 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
781 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
782 ctx
->Resource
.Display
!= disp
)
783 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
785 surf
= ctx
->DrawSurface
;
786 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
787 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
789 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
791 RETURN_EGL_EVAL(disp
, ret
);
795 EGLBoolean EGLAPIENTRY
796 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
798 _EGLContext
*ctx
= _eglGetCurrentContext();
799 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
800 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
804 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
806 /* surface must be bound to current context in EGL 1.4 */
807 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
808 surf
!= ctx
->DrawSurface
)
809 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
811 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
813 RETURN_EGL_EVAL(disp
, ret
);
817 #ifdef EGL_EXT_swap_buffers_with_damage
819 EGLBoolean EGLAPIENTRY
820 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
821 EGLint
*rects
, EGLint n_rects
)
823 _EGLContext
*ctx
= _eglGetCurrentContext();
824 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
825 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
829 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
831 /* surface must be bound to current context in EGL 1.4 */
832 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
833 surf
!= ctx
->DrawSurface
)
834 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
836 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
837 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
839 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
841 RETURN_EGL_EVAL(disp
, ret
);
844 #endif /* EGL_EXT_swap_buffers_with_damage */
846 EGLBoolean EGLAPIENTRY
847 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
849 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
850 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
853 void *native_pixmap_ptr
;
855 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
856 native_pixmap_ptr
= (void*) target
;
858 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
859 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
860 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
861 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
863 RETURN_EGL_EVAL(disp
, ret
);
867 EGLBoolean EGLAPIENTRY
870 _EGLContext
*ctx
= _eglGetCurrentContext();
876 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
878 disp
= ctx
->Resource
.Display
;
879 _eglLockMutex(&disp
->Mutex
);
881 /* let bad current context imply bad current surface */
882 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
883 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
884 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
886 /* a valid current context implies an initialized current display */
887 assert(disp
->Initialized
);
889 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
891 RETURN_EGL_EVAL(disp
, ret
);
895 EGLBoolean EGLAPIENTRY
898 _EGLThreadInfo
*t
= _eglGetCurrentThread();
899 EGLint api_index
= t
->CurrentAPIIndex
;
900 EGLint es_index
= _eglConvertApiToIndex(EGL_OPENGL_ES_API
);
903 if (api_index
!= es_index
&& _eglIsCurrentThreadDummy())
904 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
906 t
->CurrentAPIIndex
= es_index
;
907 ret
= eglWaitClient();
908 t
->CurrentAPIIndex
= api_index
;
913 EGLBoolean EGLAPIENTRY
914 eglWaitNative(EGLint engine
)
916 _EGLContext
*ctx
= _eglGetCurrentContext();
922 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
924 disp
= ctx
->Resource
.Display
;
925 _eglLockMutex(&disp
->Mutex
);
927 /* let bad current context imply bad current surface */
928 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
929 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
930 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
932 /* a valid current context implies an initialized current display */
933 assert(disp
->Initialized
);
935 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
937 RETURN_EGL_EVAL(disp
, ret
);
941 EGLDisplay EGLAPIENTRY
942 eglGetCurrentDisplay(void)
944 _EGLContext
*ctx
= _eglGetCurrentContext();
947 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
949 RETURN_EGL_SUCCESS(NULL
, ret
);
953 EGLContext EGLAPIENTRY
954 eglGetCurrentContext(void)
956 _EGLContext
*ctx
= _eglGetCurrentContext();
959 ret
= _eglGetContextHandle(ctx
);
961 RETURN_EGL_SUCCESS(NULL
, ret
);
965 EGLSurface EGLAPIENTRY
966 eglGetCurrentSurface(EGLint readdraw
)
968 _EGLContext
*ctx
= _eglGetCurrentContext();
969 EGLint err
= EGL_SUCCESS
;
974 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
978 surf
= ctx
->DrawSurface
;
981 surf
= ctx
->ReadSurface
;
985 err
= EGL_BAD_PARAMETER
;
989 ret
= _eglGetSurfaceHandle(surf
);
991 RETURN_EGL_ERROR(NULL
, err
, ret
);
998 _EGLThreadInfo
*t
= _eglGetCurrentThread();
999 EGLint e
= t
->LastError
;
1000 if (!_eglIsCurrentThreadDummy())
1001 t
->LastError
= EGL_SUCCESS
;
1006 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
1007 eglGetProcAddress(const char *procname
)
1009 static const struct {
1012 } egl_functions
[] = {
1013 /* core functions should not be queryable, but, well... */
1014 #ifdef _EGL_GET_CORE_ADDRESSES
1015 /* alphabetical order */
1016 { "eglBindAPI", (_EGLProc
) eglBindAPI
},
1017 { "eglBindTexImage", (_EGLProc
) eglBindTexImage
},
1018 { "eglChooseConfig", (_EGLProc
) eglChooseConfig
},
1019 { "eglCopyBuffers", (_EGLProc
) eglCopyBuffers
},
1020 { "eglCreateContext", (_EGLProc
) eglCreateContext
},
1021 { "eglCreatePbufferFromClientBuffer", (_EGLProc
) eglCreatePbufferFromClientBuffer
},
1022 { "eglCreatePbufferSurface", (_EGLProc
) eglCreatePbufferSurface
},
1023 { "eglCreatePixmapSurface", (_EGLProc
) eglCreatePixmapSurface
},
1024 { "eglCreateWindowSurface", (_EGLProc
) eglCreateWindowSurface
},
1025 { "eglDestroyContext", (_EGLProc
) eglDestroyContext
},
1026 { "eglDestroySurface", (_EGLProc
) eglDestroySurface
},
1027 { "eglGetConfigAttrib", (_EGLProc
) eglGetConfigAttrib
},
1028 { "eglGetConfigs", (_EGLProc
) eglGetConfigs
},
1029 { "eglGetCurrentContext", (_EGLProc
) eglGetCurrentContext
},
1030 { "eglGetCurrentDisplay", (_EGLProc
) eglGetCurrentDisplay
},
1031 { "eglGetCurrentSurface", (_EGLProc
) eglGetCurrentSurface
},
1032 { "eglGetDisplay", (_EGLProc
) eglGetDisplay
},
1033 { "eglGetError", (_EGLProc
) eglGetError
},
1034 { "eglGetProcAddress", (_EGLProc
) eglGetProcAddress
},
1035 { "eglInitialize", (_EGLProc
) eglInitialize
},
1036 { "eglMakeCurrent", (_EGLProc
) eglMakeCurrent
},
1037 { "eglQueryAPI", (_EGLProc
) eglQueryAPI
},
1038 { "eglQueryContext", (_EGLProc
) eglQueryContext
},
1039 { "eglQueryString", (_EGLProc
) eglQueryString
},
1040 { "eglQuerySurface", (_EGLProc
) eglQuerySurface
},
1041 { "eglReleaseTexImage", (_EGLProc
) eglReleaseTexImage
},
1042 { "eglReleaseThread", (_EGLProc
) eglReleaseThread
},
1043 { "eglSurfaceAttrib", (_EGLProc
) eglSurfaceAttrib
},
1044 { "eglSwapBuffers", (_EGLProc
) eglSwapBuffers
},
1045 { "eglSwapInterval", (_EGLProc
) eglSwapInterval
},
1046 { "eglTerminate", (_EGLProc
) eglTerminate
},
1047 { "eglWaitClient", (_EGLProc
) eglWaitClient
},
1048 { "eglWaitGL", (_EGLProc
) eglWaitGL
},
1049 { "eglWaitNative", (_EGLProc
) eglWaitNative
},
1050 #endif /* _EGL_GET_CORE_ADDRESSES */
1051 #ifdef EGL_MESA_screen_surface
1052 { "eglChooseModeMESA", (_EGLProc
) eglChooseModeMESA
},
1053 { "eglGetModesMESA", (_EGLProc
) eglGetModesMESA
},
1054 { "eglGetModeAttribMESA", (_EGLProc
) eglGetModeAttribMESA
},
1055 { "eglCopyContextMESA", (_EGLProc
) eglCopyContextMESA
},
1056 { "eglGetScreensMESA", (_EGLProc
) eglGetScreensMESA
},
1057 { "eglCreateScreenSurfaceMESA", (_EGLProc
) eglCreateScreenSurfaceMESA
},
1058 { "eglShowScreenSurfaceMESA", (_EGLProc
) eglShowScreenSurfaceMESA
},
1059 { "eglScreenPositionMESA", (_EGLProc
) eglScreenPositionMESA
},
1060 { "eglQueryScreenMESA", (_EGLProc
) eglQueryScreenMESA
},
1061 { "eglQueryScreenSurfaceMESA", (_EGLProc
) eglQueryScreenSurfaceMESA
},
1062 { "eglQueryScreenModeMESA", (_EGLProc
) eglQueryScreenModeMESA
},
1063 { "eglQueryModeStringMESA", (_EGLProc
) eglQueryModeStringMESA
},
1064 #endif /* EGL_MESA_screen_surface */
1065 #ifdef EGL_MESA_drm_display
1066 { "eglGetDRMDisplayMESA", (_EGLProc
) eglGetDRMDisplayMESA
},
1068 { "eglCreateImageKHR", (_EGLProc
) eglCreateImageKHR
},
1069 { "eglDestroyImageKHR", (_EGLProc
) eglDestroyImageKHR
},
1070 { "eglCreateSyncKHR", (_EGLProc
) eglCreateSyncKHR
},
1071 { "eglDestroySyncKHR", (_EGLProc
) eglDestroySyncKHR
},
1072 { "eglClientWaitSyncKHR", (_EGLProc
) eglClientWaitSyncKHR
},
1073 { "eglSignalSyncKHR", (_EGLProc
) eglSignalSyncKHR
},
1074 { "eglGetSyncAttribKHR", (_EGLProc
) eglGetSyncAttribKHR
},
1075 #ifdef EGL_NOK_swap_region
1076 { "eglSwapBuffersRegionNOK", (_EGLProc
) eglSwapBuffersRegionNOK
},
1078 #ifdef EGL_MESA_drm_image
1079 { "eglCreateDRMImageMESA", (_EGLProc
) eglCreateDRMImageMESA
},
1080 { "eglExportDRMImageMESA", (_EGLProc
) eglExportDRMImageMESA
},
1082 #ifdef EGL_WL_bind_wayland_display
1083 { "eglBindWaylandDisplayWL", (_EGLProc
) eglBindWaylandDisplayWL
},
1084 { "eglUnbindWaylandDisplayWL", (_EGLProc
) eglUnbindWaylandDisplayWL
},
1085 { "eglQueryWaylandBufferWL", (_EGLProc
) eglQueryWaylandBufferWL
},
1087 #ifdef EGL_WL_create_wayland_buffer_from_image
1088 { "eglCreateWaylandBufferFromImageWL", (_EGLProc
) eglCreateWaylandBufferFromImageWL
},
1090 { "eglPostSubBufferNV", (_EGLProc
) eglPostSubBufferNV
},
1091 #ifdef EGL_EXT_swap_buffers_with_damage
1092 { "eglSwapBuffersWithDamageEXT", (_EGLProc
) eglSwapBuffersWithDamageEXT
},
1094 { "eglGetPlatformDisplayEXT", (_EGLProc
) eglGetPlatformDisplayEXT
},
1095 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc
) eglCreatePlatformWindowSurfaceEXT
},
1096 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc
) eglCreatePlatformPixmapSurfaceEXT
},
1097 { "eglGetSyncValuesCHROMIUM", (_EGLProc
) eglGetSyncValuesCHROMIUM
},
1104 RETURN_EGL_SUCCESS(NULL
, NULL
);
1107 if (strncmp(procname
, "egl", 3) == 0) {
1108 for (i
= 0; egl_functions
[i
].name
; i
++) {
1109 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
1110 ret
= egl_functions
[i
].function
;
1116 ret
= _eglGetDriverProc(procname
);
1118 RETURN_EGL_SUCCESS(NULL
, ret
);
1122 #ifdef EGL_MESA_screen_surface
1126 * EGL_MESA_screen extension
1129 EGLBoolean EGLAPIENTRY
1130 eglChooseModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1131 const EGLint
*attrib_list
, EGLModeMESA
*modes
,
1132 EGLint modes_size
, EGLint
*num_modes
)
1134 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1135 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1139 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1140 ret
= drv
->API
.ChooseModeMESA(drv
, disp
, scrn
, attrib_list
,
1141 modes
, modes_size
, num_modes
);
1143 RETURN_EGL_EVAL(disp
, ret
);
1147 EGLBoolean EGLAPIENTRY
1148 eglGetModesMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*modes
,
1149 EGLint mode_size
, EGLint
*num_mode
)
1151 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1152 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1156 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1157 ret
= drv
->API
.GetModesMESA(drv
, disp
, scrn
, modes
, mode_size
, num_mode
);
1159 RETURN_EGL_EVAL(disp
, ret
);
1163 EGLBoolean EGLAPIENTRY
1164 eglGetModeAttribMESA(EGLDisplay dpy
, EGLModeMESA mode
,
1165 EGLint attribute
, EGLint
*value
)
1167 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1168 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1172 _EGL_CHECK_MODE(disp
, m
, EGL_FALSE
, drv
);
1173 ret
= drv
->API
.GetModeAttribMESA(drv
, disp
, m
, attribute
, value
);
1175 RETURN_EGL_EVAL(disp
, ret
);
1179 EGLBoolean EGLAPIENTRY
1180 eglCopyContextMESA(EGLDisplay dpy
, EGLContext source
, EGLContext dest
,
1183 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1184 _EGLContext
*source_context
= _eglLookupContext(source
, disp
);
1185 _EGLContext
*dest_context
= _eglLookupContext(dest
, disp
);
1189 _EGL_CHECK_CONTEXT(disp
, source_context
, EGL_FALSE
, drv
);
1191 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1193 ret
= drv
->API
.CopyContextMESA(drv
, disp
,
1194 source_context
, dest_context
, mask
);
1196 RETURN_EGL_EVAL(disp
, ret
);
1200 EGLBoolean EGLAPIENTRY
1201 eglGetScreensMESA(EGLDisplay dpy
, EGLScreenMESA
*screens
,
1202 EGLint max_screens
, EGLint
*num_screens
)
1204 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1208 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1209 ret
= drv
->API
.GetScreensMESA(drv
, disp
, screens
, max_screens
, num_screens
);
1211 RETURN_EGL_EVAL(disp
, ret
);
1215 EGLSurface EGLAPIENTRY
1216 eglCreateScreenSurfaceMESA(EGLDisplay dpy
, EGLConfig config
,
1217 const EGLint
*attrib_list
)
1219 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1220 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1225 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1227 surf
= drv
->API
.CreateScreenSurfaceMESA(drv
, disp
, conf
, attrib_list
);
1228 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1230 RETURN_EGL_EVAL(disp
, ret
);
1234 EGLBoolean EGLAPIENTRY
1235 eglShowScreenSurfaceMESA(EGLDisplay dpy
, EGLint screen
,
1236 EGLSurface surface
, EGLModeMESA mode
)
1238 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1239 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1240 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1241 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1245 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1246 if (!surf
&& surface
!= EGL_NO_SURFACE
)
1247 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1248 if (!m
&& mode
!= EGL_NO_MODE_MESA
)
1249 RETURN_EGL_ERROR(disp
, EGL_BAD_MODE_MESA
, EGL_FALSE
);
1251 ret
= drv
->API
.ShowScreenSurfaceMESA(drv
, disp
, scrn
, surf
, m
);
1253 RETURN_EGL_EVAL(disp
, ret
);
1257 EGLBoolean EGLAPIENTRY
1258 eglScreenPositionMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLint x
, EGLint y
)
1260 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1261 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1265 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1266 ret
= drv
->API
.ScreenPositionMESA(drv
, disp
, scrn
, x
, y
);
1268 RETURN_EGL_EVAL(disp
, ret
);
1272 EGLBoolean EGLAPIENTRY
1273 eglQueryScreenMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1274 EGLint attribute
, EGLint
*value
)
1276 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1277 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1281 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1282 ret
= drv
->API
.QueryScreenMESA(drv
, disp
, scrn
, attribute
, value
);
1284 RETURN_EGL_EVAL(disp
, ret
);
1288 EGLBoolean EGLAPIENTRY
1289 eglQueryScreenSurfaceMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1290 EGLSurface
*surface
)
1292 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1293 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1298 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1299 ret
= drv
->API
.QueryScreenSurfaceMESA(drv
, disp
, scrn
, &surf
);
1301 *surface
= _eglGetSurfaceHandle(surf
);
1303 RETURN_EGL_EVAL(disp
, ret
);
1307 EGLBoolean EGLAPIENTRY
1308 eglQueryScreenModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*mode
)
1310 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1311 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1316 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1317 ret
= drv
->API
.QueryScreenModeMESA(drv
, disp
, scrn
, &m
);
1321 RETURN_EGL_EVAL(disp
, ret
);
1325 const char * EGLAPIENTRY
1326 eglQueryModeStringMESA(EGLDisplay dpy
, EGLModeMESA mode
)
1328 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1329 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1333 _EGL_CHECK_MODE(disp
, m
, NULL
, drv
);
1334 ret
= drv
->API
.QueryModeStringMESA(drv
, disp
, m
);
1336 RETURN_EGL_EVAL(disp
, ret
);
1340 #endif /* EGL_MESA_screen_surface */
1343 #ifdef EGL_MESA_drm_display
1345 EGLDisplay EGLAPIENTRY
1346 eglGetDRMDisplayMESA(int fd
)
1348 _EGLDisplay
*dpy
= _eglFindDisplay(_EGL_PLATFORM_DRM
, (void *) (intptr_t) fd
);
1349 return _eglGetDisplayHandle(dpy
);
1352 #endif /* EGL_MESA_drm_display */
1359 * Specify the client API to use for subsequent calls including:
1360 * eglCreateContext()
1361 * eglGetCurrentContext()
1362 * eglGetCurrentDisplay()
1363 * eglGetCurrentSurface()
1364 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1367 * See section 3.7 "Rendering Context" in the EGL specification for details.
1369 EGLBoolean EGLAPIENTRY
1370 eglBindAPI(EGLenum api
)
1372 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1374 if (_eglIsCurrentThreadDummy())
1375 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1377 if (!_eglIsApiValid(api
))
1378 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1380 t
->CurrentAPIIndex
= _eglConvertApiToIndex(api
);
1382 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1387 * Return the last value set with eglBindAPI().
1392 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1395 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1396 ret
= _eglConvertApiFromIndex(t
->CurrentAPIIndex
);
1398 RETURN_EGL_SUCCESS(NULL
, ret
);
1402 EGLSurface EGLAPIENTRY
1403 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1404 EGLClientBuffer buffer
, EGLConfig config
,
1405 const EGLint
*attrib_list
)
1407 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1408 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1413 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1415 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1417 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1419 RETURN_EGL_EVAL(disp
, ret
);
1423 EGLBoolean EGLAPIENTRY
1424 eglReleaseThread(void)
1426 /* unbind current contexts */
1427 if (!_eglIsCurrentThreadDummy()) {
1428 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1429 EGLint api_index
= t
->CurrentAPIIndex
;
1432 for (i
= 0; i
< _EGL_API_NUM_APIS
; i
++) {
1433 _EGLContext
*ctx
= t
->CurrentContexts
[i
];
1435 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1438 t
->CurrentAPIIndex
= i
;
1440 _eglLockMutex(&disp
->Mutex
);
1442 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1443 _eglUnlockMutex(&disp
->Mutex
);
1447 t
->CurrentAPIIndex
= api_index
;
1450 _eglDestroyCurrentThread();
1452 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1456 EGLImageKHR EGLAPIENTRY
1457 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1458 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1460 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1461 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1466 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1467 if (!disp
->Extensions
.KHR_image_base
)
1468 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1469 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1470 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1471 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1472 * <ctx> must be EGL_NO_CONTEXT..."
1474 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1475 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1477 img
= drv
->API
.CreateImageKHR(drv
,
1478 disp
, context
, target
, buffer
, attr_list
);
1479 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1481 RETURN_EGL_EVAL(disp
, ret
);
1485 EGLBoolean EGLAPIENTRY
1486 eglDestroyImageKHR(EGLDisplay dpy
, EGLImageKHR image
)
1488 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1489 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1493 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1494 if (!disp
->Extensions
.KHR_image_base
)
1495 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1497 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1499 _eglUnlinkImage(img
);
1500 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1502 RETURN_EGL_EVAL(disp
, ret
);
1506 EGLSyncKHR EGLAPIENTRY
1507 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*attrib_list
)
1509 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1514 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1515 if (!disp
->Extensions
.KHR_reusable_sync
)
1516 RETURN_EGL_EVAL(disp
, EGL_NO_SYNC_KHR
);
1518 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1519 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1521 RETURN_EGL_EVAL(disp
, ret
);
1525 EGLBoolean EGLAPIENTRY
1526 eglDestroySyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
)
1528 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1529 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1533 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1534 assert(disp
->Extensions
.KHR_reusable_sync
);
1537 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1539 RETURN_EGL_EVAL(disp
, ret
);
1544 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLint flags
, EGLTimeKHR timeout
)
1546 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1547 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1551 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1552 assert(disp
->Extensions
.KHR_reusable_sync
);
1553 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1555 RETURN_EGL_EVAL(disp
, ret
);
1559 EGLBoolean EGLAPIENTRY
1560 eglSignalSyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLenum mode
)
1562 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1563 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1567 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1568 assert(disp
->Extensions
.KHR_reusable_sync
);
1569 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
1571 RETURN_EGL_EVAL(disp
, ret
);
1575 EGLBoolean EGLAPIENTRY
1576 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLint attribute
, EGLint
*value
)
1578 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1579 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1583 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1584 assert(disp
->Extensions
.KHR_reusable_sync
);
1585 ret
= drv
->API
.GetSyncAttribKHR(drv
, disp
, s
, attribute
, value
);
1587 RETURN_EGL_EVAL(disp
, ret
);
1591 #ifdef EGL_NOK_swap_region
1593 EGLBoolean EGLAPIENTRY
1594 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
1595 EGLint numRects
, const EGLint
*rects
)
1597 _EGLContext
*ctx
= _eglGetCurrentContext();
1598 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1599 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1603 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1605 if (!disp
->Extensions
.NOK_swap_region
)
1606 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1608 /* surface must be bound to current context in EGL 1.4 */
1609 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1610 surf
!= ctx
->DrawSurface
)
1611 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1613 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
1615 RETURN_EGL_EVAL(disp
, ret
);
1618 #endif /* EGL_NOK_swap_region */
1621 #ifdef EGL_MESA_drm_image
1623 EGLImageKHR EGLAPIENTRY
1624 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
1626 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1631 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1632 if (!disp
->Extensions
.MESA_drm_image
)
1633 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1635 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
1636 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1638 RETURN_EGL_EVAL(disp
, ret
);
1641 EGLBoolean EGLAPIENTRY
1642 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImageKHR image
,
1643 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
1645 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1646 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1650 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1651 assert(disp
->Extensions
.MESA_drm_image
);
1654 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1656 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
1658 RETURN_EGL_EVAL(disp
, ret
);
1663 #ifdef EGL_WL_bind_wayland_display
1666 EGLBoolean EGLAPIENTRY
1667 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1669 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1673 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1674 assert(disp
->Extensions
.WL_bind_wayland_display
);
1677 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1679 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
1681 RETURN_EGL_EVAL(disp
, ret
);
1684 EGLBoolean EGLAPIENTRY
1685 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1687 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1691 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1692 assert(disp
->Extensions
.WL_bind_wayland_display
);
1695 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1697 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
1699 RETURN_EGL_EVAL(disp
, ret
);
1702 EGLBoolean EGLAPIENTRY
1703 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
1704 EGLint attribute
, EGLint
*value
)
1706 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1710 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1711 assert(disp
->Extensions
.WL_bind_wayland_display
);
1714 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1716 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
1718 RETURN_EGL_EVAL(disp
, ret
);
1722 #ifdef EGL_WL_create_wayland_buffer_from_image
1723 struct wl_buffer
* EGLAPIENTRY
1724 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImageKHR image
)
1726 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1729 struct wl_buffer
*ret
;
1731 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
1732 assert(disp
->Extensions
.WL_create_wayland_buffer_from_image
);
1734 img
= _eglLookupImage(image
, disp
);
1737 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
1739 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
1741 RETURN_EGL_EVAL(disp
, ret
);
1745 EGLBoolean EGLAPIENTRY
1746 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
1747 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
1749 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1750 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1754 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1756 if (!disp
->Extensions
.NV_post_sub_buffer
)
1757 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1759 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
1761 RETURN_EGL_EVAL(disp
, ret
);
1764 EGLBoolean EGLAPIENTRY
1765 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
1766 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
1769 _EGLDisplay
*disp
= _eglLockDisplay(display
);
1770 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1774 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1775 if (!disp
->Extensions
.CHROMIUM_sync_control
)
1776 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1778 if (!ust
|| !msc
|| !sbc
)
1779 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1781 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
1783 RETURN_EGL_EVAL(disp
, ret
);