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
);
574 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
576 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
578 RETURN_EGL_EVAL(disp
, ret
);
582 EGLSurface EGLAPIENTRY
583 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
584 EGLNativeWindowType window
, const EGLint
*attrib_list
)
586 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
587 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
588 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
593 EGLSurface EGLAPIENTRY
594 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
596 const EGLint
*attrib_list
)
598 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
600 #ifdef HAVE_X11_PLATFORM
601 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
602 /* The `native_window` parameter for the X11 platform differs between
603 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
604 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
605 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
606 * `Window*`. Convert `Window*` to `Window` because that's what
607 * dri2_x11_create_window_surface() expects.
609 native_window
= (void*) (* (Window
*) native_window
);
613 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
619 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
620 void *native_pixmap
, const EGLint
*attrib_list
)
622 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
627 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
628 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
630 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
632 RETURN_EGL_EVAL(disp
, ret
);
636 EGLSurface EGLAPIENTRY
637 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
638 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
640 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
641 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
642 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
646 EGLSurface EGLAPIENTRY
647 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
649 const EGLint
*attrib_list
)
651 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
653 #ifdef HAVE_X11_PLATFORM
654 /* The `native_pixmap` parameter for the X11 platform differs between
655 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
656 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
657 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
658 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
659 * dri2_x11_create_pixmap_surface() expects.
661 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
) {
662 native_pixmap
= (void*) (* (Pixmap
*) native_pixmap
);
666 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
671 EGLSurface EGLAPIENTRY
672 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
673 const EGLint
*attrib_list
)
675 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
676 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
681 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
683 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
684 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
686 RETURN_EGL_EVAL(disp
, ret
);
690 EGLBoolean EGLAPIENTRY
691 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
693 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
694 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
698 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
699 _eglUnlinkSurface(surf
);
700 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
702 RETURN_EGL_EVAL(disp
, ret
);
705 EGLBoolean EGLAPIENTRY
706 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
707 EGLint attribute
, EGLint
*value
)
709 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
710 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
714 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
715 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
717 RETURN_EGL_EVAL(disp
, ret
);
720 EGLBoolean EGLAPIENTRY
721 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
722 EGLint attribute
, EGLint value
)
724 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
725 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
729 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
730 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
732 RETURN_EGL_EVAL(disp
, ret
);
736 EGLBoolean EGLAPIENTRY
737 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
739 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
740 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
744 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
745 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
747 RETURN_EGL_EVAL(disp
, ret
);
751 EGLBoolean EGLAPIENTRY
752 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
754 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
755 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
759 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
760 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
762 RETURN_EGL_EVAL(disp
, ret
);
766 EGLBoolean EGLAPIENTRY
767 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
769 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
770 _EGLContext
*ctx
= _eglGetCurrentContext();
775 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
777 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
778 ctx
->Resource
.Display
!= disp
)
779 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
781 surf
= ctx
->DrawSurface
;
782 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
783 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
785 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
787 RETURN_EGL_EVAL(disp
, ret
);
791 EGLBoolean EGLAPIENTRY
792 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
794 _EGLContext
*ctx
= _eglGetCurrentContext();
795 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
796 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
800 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
802 /* surface must be bound to current context in EGL 1.4 */
803 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
804 surf
!= ctx
->DrawSurface
)
805 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
807 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
809 RETURN_EGL_EVAL(disp
, ret
);
813 #ifdef EGL_EXT_swap_buffers_with_damage
815 EGLBoolean EGLAPIENTRY
816 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
817 EGLint
*rects
, EGLint n_rects
)
819 _EGLContext
*ctx
= _eglGetCurrentContext();
820 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
821 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
825 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
827 /* surface must be bound to current context in EGL 1.4 */
828 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
829 surf
!= ctx
->DrawSurface
)
830 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
832 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
833 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
835 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
837 RETURN_EGL_EVAL(disp
, ret
);
840 #endif /* EGL_EXT_swap_buffers_with_damage */
842 EGLBoolean EGLAPIENTRY
843 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
845 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
846 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
849 void *native_pixmap_ptr
;
851 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
852 native_pixmap_ptr
= (void*) target
;
854 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
855 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
856 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
857 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
859 RETURN_EGL_EVAL(disp
, ret
);
863 EGLBoolean EGLAPIENTRY
866 _EGLContext
*ctx
= _eglGetCurrentContext();
872 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
874 disp
= ctx
->Resource
.Display
;
875 _eglLockMutex(&disp
->Mutex
);
877 /* let bad current context imply bad current surface */
878 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
879 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
880 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
882 /* a valid current context implies an initialized current display */
883 assert(disp
->Initialized
);
885 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
887 RETURN_EGL_EVAL(disp
, ret
);
891 EGLBoolean EGLAPIENTRY
894 _EGLThreadInfo
*t
= _eglGetCurrentThread();
895 EGLint api_index
= t
->CurrentAPIIndex
;
896 EGLint es_index
= _eglConvertApiToIndex(EGL_OPENGL_ES_API
);
899 if (api_index
!= es_index
&& _eglIsCurrentThreadDummy())
900 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
902 t
->CurrentAPIIndex
= es_index
;
903 ret
= eglWaitClient();
904 t
->CurrentAPIIndex
= api_index
;
909 EGLBoolean EGLAPIENTRY
910 eglWaitNative(EGLint engine
)
912 _EGLContext
*ctx
= _eglGetCurrentContext();
918 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
920 disp
= ctx
->Resource
.Display
;
921 _eglLockMutex(&disp
->Mutex
);
923 /* let bad current context imply bad current surface */
924 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
925 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
926 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
928 /* a valid current context implies an initialized current display */
929 assert(disp
->Initialized
);
931 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
933 RETURN_EGL_EVAL(disp
, ret
);
937 EGLDisplay EGLAPIENTRY
938 eglGetCurrentDisplay(void)
940 _EGLContext
*ctx
= _eglGetCurrentContext();
943 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
945 RETURN_EGL_SUCCESS(NULL
, ret
);
949 EGLContext EGLAPIENTRY
950 eglGetCurrentContext(void)
952 _EGLContext
*ctx
= _eglGetCurrentContext();
955 ret
= _eglGetContextHandle(ctx
);
957 RETURN_EGL_SUCCESS(NULL
, ret
);
961 EGLSurface EGLAPIENTRY
962 eglGetCurrentSurface(EGLint readdraw
)
964 _EGLContext
*ctx
= _eglGetCurrentContext();
965 EGLint err
= EGL_SUCCESS
;
970 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
974 surf
= ctx
->DrawSurface
;
977 surf
= ctx
->ReadSurface
;
981 err
= EGL_BAD_PARAMETER
;
985 ret
= _eglGetSurfaceHandle(surf
);
987 RETURN_EGL_ERROR(NULL
, err
, ret
);
994 _EGLThreadInfo
*t
= _eglGetCurrentThread();
995 EGLint e
= t
->LastError
;
996 if (!_eglIsCurrentThreadDummy())
997 t
->LastError
= EGL_SUCCESS
;
1002 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
1003 eglGetProcAddress(const char *procname
)
1005 static const struct {
1008 } egl_functions
[] = {
1009 /* core functions should not be queryable, but, well... */
1010 #ifdef _EGL_GET_CORE_ADDRESSES
1011 /* alphabetical order */
1012 { "eglBindAPI", (_EGLProc
) eglBindAPI
},
1013 { "eglBindTexImage", (_EGLProc
) eglBindTexImage
},
1014 { "eglChooseConfig", (_EGLProc
) eglChooseConfig
},
1015 { "eglCopyBuffers", (_EGLProc
) eglCopyBuffers
},
1016 { "eglCreateContext", (_EGLProc
) eglCreateContext
},
1017 { "eglCreatePbufferFromClientBuffer", (_EGLProc
) eglCreatePbufferFromClientBuffer
},
1018 { "eglCreatePbufferSurface", (_EGLProc
) eglCreatePbufferSurface
},
1019 { "eglCreatePixmapSurface", (_EGLProc
) eglCreatePixmapSurface
},
1020 { "eglCreateWindowSurface", (_EGLProc
) eglCreateWindowSurface
},
1021 { "eglDestroyContext", (_EGLProc
) eglDestroyContext
},
1022 { "eglDestroySurface", (_EGLProc
) eglDestroySurface
},
1023 { "eglGetConfigAttrib", (_EGLProc
) eglGetConfigAttrib
},
1024 { "eglGetConfigs", (_EGLProc
) eglGetConfigs
},
1025 { "eglGetCurrentContext", (_EGLProc
) eglGetCurrentContext
},
1026 { "eglGetCurrentDisplay", (_EGLProc
) eglGetCurrentDisplay
},
1027 { "eglGetCurrentSurface", (_EGLProc
) eglGetCurrentSurface
},
1028 { "eglGetDisplay", (_EGLProc
) eglGetDisplay
},
1029 { "eglGetError", (_EGLProc
) eglGetError
},
1030 { "eglGetProcAddress", (_EGLProc
) eglGetProcAddress
},
1031 { "eglInitialize", (_EGLProc
) eglInitialize
},
1032 { "eglMakeCurrent", (_EGLProc
) eglMakeCurrent
},
1033 { "eglQueryAPI", (_EGLProc
) eglQueryAPI
},
1034 { "eglQueryContext", (_EGLProc
) eglQueryContext
},
1035 { "eglQueryString", (_EGLProc
) eglQueryString
},
1036 { "eglQuerySurface", (_EGLProc
) eglQuerySurface
},
1037 { "eglReleaseTexImage", (_EGLProc
) eglReleaseTexImage
},
1038 { "eglReleaseThread", (_EGLProc
) eglReleaseThread
},
1039 { "eglSurfaceAttrib", (_EGLProc
) eglSurfaceAttrib
},
1040 { "eglSwapBuffers", (_EGLProc
) eglSwapBuffers
},
1041 { "eglSwapInterval", (_EGLProc
) eglSwapInterval
},
1042 { "eglTerminate", (_EGLProc
) eglTerminate
},
1043 { "eglWaitClient", (_EGLProc
) eglWaitClient
},
1044 { "eglWaitGL", (_EGLProc
) eglWaitGL
},
1045 { "eglWaitNative", (_EGLProc
) eglWaitNative
},
1046 #endif /* _EGL_GET_CORE_ADDRESSES */
1047 #ifdef EGL_MESA_screen_surface
1048 { "eglChooseModeMESA", (_EGLProc
) eglChooseModeMESA
},
1049 { "eglGetModesMESA", (_EGLProc
) eglGetModesMESA
},
1050 { "eglGetModeAttribMESA", (_EGLProc
) eglGetModeAttribMESA
},
1051 { "eglCopyContextMESA", (_EGLProc
) eglCopyContextMESA
},
1052 { "eglGetScreensMESA", (_EGLProc
) eglGetScreensMESA
},
1053 { "eglCreateScreenSurfaceMESA", (_EGLProc
) eglCreateScreenSurfaceMESA
},
1054 { "eglShowScreenSurfaceMESA", (_EGLProc
) eglShowScreenSurfaceMESA
},
1055 { "eglScreenPositionMESA", (_EGLProc
) eglScreenPositionMESA
},
1056 { "eglQueryScreenMESA", (_EGLProc
) eglQueryScreenMESA
},
1057 { "eglQueryScreenSurfaceMESA", (_EGLProc
) eglQueryScreenSurfaceMESA
},
1058 { "eglQueryScreenModeMESA", (_EGLProc
) eglQueryScreenModeMESA
},
1059 { "eglQueryModeStringMESA", (_EGLProc
) eglQueryModeStringMESA
},
1060 #endif /* EGL_MESA_screen_surface */
1061 #ifdef EGL_MESA_drm_display
1062 { "eglGetDRMDisplayMESA", (_EGLProc
) eglGetDRMDisplayMESA
},
1064 { "eglCreateImageKHR", (_EGLProc
) eglCreateImageKHR
},
1065 { "eglDestroyImageKHR", (_EGLProc
) eglDestroyImageKHR
},
1066 { "eglCreateSyncKHR", (_EGLProc
) eglCreateSyncKHR
},
1067 { "eglDestroySyncKHR", (_EGLProc
) eglDestroySyncKHR
},
1068 { "eglClientWaitSyncKHR", (_EGLProc
) eglClientWaitSyncKHR
},
1069 { "eglSignalSyncKHR", (_EGLProc
) eglSignalSyncKHR
},
1070 { "eglGetSyncAttribKHR", (_EGLProc
) eglGetSyncAttribKHR
},
1071 #ifdef EGL_NOK_swap_region
1072 { "eglSwapBuffersRegionNOK", (_EGLProc
) eglSwapBuffersRegionNOK
},
1074 #ifdef EGL_MESA_drm_image
1075 { "eglCreateDRMImageMESA", (_EGLProc
) eglCreateDRMImageMESA
},
1076 { "eglExportDRMImageMESA", (_EGLProc
) eglExportDRMImageMESA
},
1078 #ifdef EGL_WL_bind_wayland_display
1079 { "eglBindWaylandDisplayWL", (_EGLProc
) eglBindWaylandDisplayWL
},
1080 { "eglUnbindWaylandDisplayWL", (_EGLProc
) eglUnbindWaylandDisplayWL
},
1081 { "eglQueryWaylandBufferWL", (_EGLProc
) eglQueryWaylandBufferWL
},
1083 #ifdef EGL_WL_create_wayland_buffer_from_image
1084 { "eglCreateWaylandBufferFromImageWL", (_EGLProc
) eglCreateWaylandBufferFromImageWL
},
1086 { "eglPostSubBufferNV", (_EGLProc
) eglPostSubBufferNV
},
1087 #ifdef EGL_EXT_swap_buffers_with_damage
1088 { "eglSwapBuffersWithDamageEXT", (_EGLProc
) eglSwapBuffersWithDamageEXT
},
1090 { "eglGetPlatformDisplayEXT", (_EGLProc
) eglGetPlatformDisplayEXT
},
1091 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc
) eglCreatePlatformWindowSurfaceEXT
},
1092 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc
) eglCreatePlatformPixmapSurfaceEXT
},
1093 { "eglGetSyncValuesCHROMIUM", (_EGLProc
) eglGetSyncValuesCHROMIUM
},
1100 RETURN_EGL_SUCCESS(NULL
, NULL
);
1103 if (strncmp(procname
, "egl", 3) == 0) {
1104 for (i
= 0; egl_functions
[i
].name
; i
++) {
1105 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
1106 ret
= egl_functions
[i
].function
;
1112 ret
= _eglGetDriverProc(procname
);
1114 RETURN_EGL_SUCCESS(NULL
, ret
);
1118 #ifdef EGL_MESA_screen_surface
1122 * EGL_MESA_screen extension
1125 EGLBoolean EGLAPIENTRY
1126 eglChooseModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1127 const EGLint
*attrib_list
, EGLModeMESA
*modes
,
1128 EGLint modes_size
, EGLint
*num_modes
)
1130 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1131 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1135 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1136 ret
= drv
->API
.ChooseModeMESA(drv
, disp
, scrn
, attrib_list
,
1137 modes
, modes_size
, num_modes
);
1139 RETURN_EGL_EVAL(disp
, ret
);
1143 EGLBoolean EGLAPIENTRY
1144 eglGetModesMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*modes
,
1145 EGLint mode_size
, EGLint
*num_mode
)
1147 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1148 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1152 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1153 ret
= drv
->API
.GetModesMESA(drv
, disp
, scrn
, modes
, mode_size
, num_mode
);
1155 RETURN_EGL_EVAL(disp
, ret
);
1159 EGLBoolean EGLAPIENTRY
1160 eglGetModeAttribMESA(EGLDisplay dpy
, EGLModeMESA mode
,
1161 EGLint attribute
, EGLint
*value
)
1163 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1164 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1168 _EGL_CHECK_MODE(disp
, m
, EGL_FALSE
, drv
);
1169 ret
= drv
->API
.GetModeAttribMESA(drv
, disp
, m
, attribute
, value
);
1171 RETURN_EGL_EVAL(disp
, ret
);
1175 EGLBoolean EGLAPIENTRY
1176 eglCopyContextMESA(EGLDisplay dpy
, EGLContext source
, EGLContext dest
,
1179 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1180 _EGLContext
*source_context
= _eglLookupContext(source
, disp
);
1181 _EGLContext
*dest_context
= _eglLookupContext(dest
, disp
);
1185 _EGL_CHECK_CONTEXT(disp
, source_context
, EGL_FALSE
, drv
);
1187 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1189 ret
= drv
->API
.CopyContextMESA(drv
, disp
,
1190 source_context
, dest_context
, mask
);
1192 RETURN_EGL_EVAL(disp
, ret
);
1196 EGLBoolean EGLAPIENTRY
1197 eglGetScreensMESA(EGLDisplay dpy
, EGLScreenMESA
*screens
,
1198 EGLint max_screens
, EGLint
*num_screens
)
1200 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1204 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1205 ret
= drv
->API
.GetScreensMESA(drv
, disp
, screens
, max_screens
, num_screens
);
1207 RETURN_EGL_EVAL(disp
, ret
);
1211 EGLSurface EGLAPIENTRY
1212 eglCreateScreenSurfaceMESA(EGLDisplay dpy
, EGLConfig config
,
1213 const EGLint
*attrib_list
)
1215 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1216 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1221 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1223 surf
= drv
->API
.CreateScreenSurfaceMESA(drv
, disp
, conf
, attrib_list
);
1224 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1226 RETURN_EGL_EVAL(disp
, ret
);
1230 EGLBoolean EGLAPIENTRY
1231 eglShowScreenSurfaceMESA(EGLDisplay dpy
, EGLint screen
,
1232 EGLSurface surface
, EGLModeMESA mode
)
1234 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1235 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1236 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1237 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1241 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1242 if (!surf
&& surface
!= EGL_NO_SURFACE
)
1243 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1244 if (!m
&& mode
!= EGL_NO_MODE_MESA
)
1245 RETURN_EGL_ERROR(disp
, EGL_BAD_MODE_MESA
, EGL_FALSE
);
1247 ret
= drv
->API
.ShowScreenSurfaceMESA(drv
, disp
, scrn
, surf
, m
);
1249 RETURN_EGL_EVAL(disp
, ret
);
1253 EGLBoolean EGLAPIENTRY
1254 eglScreenPositionMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLint x
, EGLint y
)
1256 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1257 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1261 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1262 ret
= drv
->API
.ScreenPositionMESA(drv
, disp
, scrn
, x
, y
);
1264 RETURN_EGL_EVAL(disp
, ret
);
1268 EGLBoolean EGLAPIENTRY
1269 eglQueryScreenMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1270 EGLint attribute
, EGLint
*value
)
1272 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1273 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1277 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1278 ret
= drv
->API
.QueryScreenMESA(drv
, disp
, scrn
, attribute
, value
);
1280 RETURN_EGL_EVAL(disp
, ret
);
1284 EGLBoolean EGLAPIENTRY
1285 eglQueryScreenSurfaceMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1286 EGLSurface
*surface
)
1288 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1289 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1294 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1295 ret
= drv
->API
.QueryScreenSurfaceMESA(drv
, disp
, scrn
, &surf
);
1297 *surface
= _eglGetSurfaceHandle(surf
);
1299 RETURN_EGL_EVAL(disp
, ret
);
1303 EGLBoolean EGLAPIENTRY
1304 eglQueryScreenModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*mode
)
1306 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1307 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1312 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1313 ret
= drv
->API
.QueryScreenModeMESA(drv
, disp
, scrn
, &m
);
1317 RETURN_EGL_EVAL(disp
, ret
);
1321 const char * EGLAPIENTRY
1322 eglQueryModeStringMESA(EGLDisplay dpy
, EGLModeMESA mode
)
1324 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1325 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1329 _EGL_CHECK_MODE(disp
, m
, NULL
, drv
);
1330 ret
= drv
->API
.QueryModeStringMESA(drv
, disp
, m
);
1332 RETURN_EGL_EVAL(disp
, ret
);
1336 #endif /* EGL_MESA_screen_surface */
1339 #ifdef EGL_MESA_drm_display
1341 EGLDisplay EGLAPIENTRY
1342 eglGetDRMDisplayMESA(int fd
)
1344 _EGLDisplay
*dpy
= _eglFindDisplay(_EGL_PLATFORM_DRM
, (void *) (intptr_t) fd
);
1345 return _eglGetDisplayHandle(dpy
);
1348 #endif /* EGL_MESA_drm_display */
1355 * Specify the client API to use for subsequent calls including:
1356 * eglCreateContext()
1357 * eglGetCurrentContext()
1358 * eglGetCurrentDisplay()
1359 * eglGetCurrentSurface()
1360 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1363 * See section 3.7 "Rendering Context" in the EGL specification for details.
1365 EGLBoolean EGLAPIENTRY
1366 eglBindAPI(EGLenum api
)
1368 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1370 if (_eglIsCurrentThreadDummy())
1371 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1373 if (!_eglIsApiValid(api
))
1374 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1376 t
->CurrentAPIIndex
= _eglConvertApiToIndex(api
);
1378 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1383 * Return the last value set with eglBindAPI().
1388 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1391 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1392 ret
= _eglConvertApiFromIndex(t
->CurrentAPIIndex
);
1394 RETURN_EGL_SUCCESS(NULL
, ret
);
1398 EGLSurface EGLAPIENTRY
1399 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1400 EGLClientBuffer buffer
, EGLConfig config
,
1401 const EGLint
*attrib_list
)
1403 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1404 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1409 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1411 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1413 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1415 RETURN_EGL_EVAL(disp
, ret
);
1419 EGLBoolean EGLAPIENTRY
1420 eglReleaseThread(void)
1422 /* unbind current contexts */
1423 if (!_eglIsCurrentThreadDummy()) {
1424 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1425 EGLint api_index
= t
->CurrentAPIIndex
;
1428 for (i
= 0; i
< _EGL_API_NUM_APIS
; i
++) {
1429 _EGLContext
*ctx
= t
->CurrentContexts
[i
];
1431 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1434 t
->CurrentAPIIndex
= i
;
1436 _eglLockMutex(&disp
->Mutex
);
1438 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1439 _eglUnlockMutex(&disp
->Mutex
);
1443 t
->CurrentAPIIndex
= api_index
;
1446 _eglDestroyCurrentThread();
1448 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1452 EGLImageKHR EGLAPIENTRY
1453 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1454 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1456 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1457 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1462 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1463 if (!disp
->Extensions
.KHR_image_base
)
1464 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1465 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1466 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1467 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1468 * <ctx> must be EGL_NO_CONTEXT..."
1470 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1471 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1473 img
= drv
->API
.CreateImageKHR(drv
,
1474 disp
, context
, target
, buffer
, attr_list
);
1475 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1477 RETURN_EGL_EVAL(disp
, ret
);
1481 EGLBoolean EGLAPIENTRY
1482 eglDestroyImageKHR(EGLDisplay dpy
, EGLImageKHR image
)
1484 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1485 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1489 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1490 if (!disp
->Extensions
.KHR_image_base
)
1491 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1493 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1495 _eglUnlinkImage(img
);
1496 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1498 RETURN_EGL_EVAL(disp
, ret
);
1502 EGLSyncKHR EGLAPIENTRY
1503 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*attrib_list
)
1505 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1510 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1511 if (!disp
->Extensions
.KHR_reusable_sync
)
1512 RETURN_EGL_EVAL(disp
, EGL_NO_SYNC_KHR
);
1514 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1515 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1517 RETURN_EGL_EVAL(disp
, ret
);
1521 EGLBoolean EGLAPIENTRY
1522 eglDestroySyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
)
1524 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1525 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1529 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1530 assert(disp
->Extensions
.KHR_reusable_sync
);
1533 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1535 RETURN_EGL_EVAL(disp
, ret
);
1540 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLint flags
, EGLTimeKHR timeout
)
1542 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1543 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1547 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1548 assert(disp
->Extensions
.KHR_reusable_sync
);
1549 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1551 RETURN_EGL_EVAL(disp
, ret
);
1555 EGLBoolean EGLAPIENTRY
1556 eglSignalSyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLenum mode
)
1558 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1559 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1563 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1564 assert(disp
->Extensions
.KHR_reusable_sync
);
1565 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
1567 RETURN_EGL_EVAL(disp
, ret
);
1571 EGLBoolean EGLAPIENTRY
1572 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLint attribute
, EGLint
*value
)
1574 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1575 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1579 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1580 assert(disp
->Extensions
.KHR_reusable_sync
);
1581 ret
= drv
->API
.GetSyncAttribKHR(drv
, disp
, s
, attribute
, value
);
1583 RETURN_EGL_EVAL(disp
, ret
);
1587 #ifdef EGL_NOK_swap_region
1589 EGLBoolean EGLAPIENTRY
1590 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
1591 EGLint numRects
, const EGLint
*rects
)
1593 _EGLContext
*ctx
= _eglGetCurrentContext();
1594 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1595 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1599 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1601 if (!disp
->Extensions
.NOK_swap_region
)
1602 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1604 /* surface must be bound to current context in EGL 1.4 */
1605 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1606 surf
!= ctx
->DrawSurface
)
1607 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1609 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
1611 RETURN_EGL_EVAL(disp
, ret
);
1614 #endif /* EGL_NOK_swap_region */
1617 #ifdef EGL_MESA_drm_image
1619 EGLImageKHR EGLAPIENTRY
1620 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
1622 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1627 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1628 if (!disp
->Extensions
.MESA_drm_image
)
1629 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1631 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
1632 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1634 RETURN_EGL_EVAL(disp
, ret
);
1637 EGLBoolean EGLAPIENTRY
1638 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImageKHR image
,
1639 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
1641 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1642 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1646 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1647 assert(disp
->Extensions
.MESA_drm_image
);
1650 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1652 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
1654 RETURN_EGL_EVAL(disp
, ret
);
1659 #ifdef EGL_WL_bind_wayland_display
1662 EGLBoolean EGLAPIENTRY
1663 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1665 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1669 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1670 assert(disp
->Extensions
.WL_bind_wayland_display
);
1673 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1675 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
1677 RETURN_EGL_EVAL(disp
, ret
);
1680 EGLBoolean EGLAPIENTRY
1681 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1683 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1687 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1688 assert(disp
->Extensions
.WL_bind_wayland_display
);
1691 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1693 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
1695 RETURN_EGL_EVAL(disp
, ret
);
1698 EGLBoolean EGLAPIENTRY
1699 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
1700 EGLint attribute
, EGLint
*value
)
1702 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1706 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1707 assert(disp
->Extensions
.WL_bind_wayland_display
);
1710 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1712 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
1714 RETURN_EGL_EVAL(disp
, ret
);
1718 #ifdef EGL_WL_create_wayland_buffer_from_image
1719 struct wl_buffer
* EGLAPIENTRY
1720 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImageKHR image
)
1722 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1725 struct wl_buffer
*ret
;
1727 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
1728 assert(disp
->Extensions
.WL_create_wayland_buffer_from_image
);
1730 img
= _eglLookupImage(image
, disp
);
1733 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
1735 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
1737 RETURN_EGL_EVAL(disp
, ret
);
1741 EGLBoolean EGLAPIENTRY
1742 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
1743 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
1745 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1746 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1750 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1752 if (!disp
->Extensions
.NV_post_sub_buffer
)
1753 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1755 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
1757 RETURN_EGL_EVAL(disp
, ret
);
1760 EGLBoolean EGLAPIENTRY
1761 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
1762 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
1765 _EGLDisplay
*disp
= _eglLockDisplay(display
);
1766 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1770 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1771 if (!disp
->Extensions
.CHROMIUM_sync_control
)
1772 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1774 if (!ust
|| !msc
|| !sbc
)
1775 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1777 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
1779 RETURN_EGL_EVAL(disp
, ret
);