1 /**************************************************************************
3 * Copyright 2008 VMware, Inc.
4 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5 * Copyright 2010-2011 LunarG, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
32 * Public EGL API entrypoints
34 * Generally, we use the EGLDisplay parameter as a key to lookup the
35 * appropriate device driver handle, then jump though the driver's
36 * dispatch table to handle the function.
38 * That allows us the option of supporting multiple, simultaneous,
39 * heterogeneous hardware devices in the future.
41 * The EGLDisplay, EGLConfig, EGLContext and EGLSurface types are
42 * opaque handles. Internal objects are linked to a display to
45 * For each public API entry point, the opaque handles are looked up
46 * before being dispatched to the drivers. When it fails to look up
56 * is generated and the driver function is not called. An
57 * uninitialized EGLDisplay has no driver associated with it. When
58 * such display is detected,
64 * Some of the entry points use current display, context, or surface
65 * implicitly. For such entry points, the implicit objects are also
66 * checked before calling the driver function. Other than the
67 * errors listed above,
69 * EGL_BAD_CURRENT_SURFACE
71 * may also be generated.
73 * Notes on naming conventions:
75 * eglFooBar - public EGL function
76 * EGL_FOO_BAR - public EGL token
77 * EGLDatatype - public EGL datatype
79 * _eglFooBar - private EGL function
80 * _EGLDatatype - private EGL datatype, typedef'd struct
81 * _egl_struct - private EGL struct, non-typedef'd
89 #include "c99_compat.h"
90 #include "c11/threads.h"
91 #include "eglcompiler.h"
93 #include "eglglobals.h"
94 #include "eglcontext.h"
95 #include "egldisplay.h"
96 #include "egltypedefs.h"
97 #include "eglcurrent.h"
98 #include "egldriver.h"
99 #include "eglsurface.h"
100 #include "eglconfig.h"
101 #include "eglscreen.h"
103 #include "eglimage.h"
108 * Macros to help return an API entrypoint.
110 * These macros will unlock the display and record the error code.
112 #define RETURN_EGL_ERROR(disp, err, ret) \
115 _eglUnlockDisplay(disp); \
116 /* EGL error codes are non-zero */ \
118 _eglError(err, __func__); \
122 #define RETURN_EGL_SUCCESS(disp, ret) \
123 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
125 /* record EGL_SUCCESS only when ret evaluates to true */
126 #define RETURN_EGL_EVAL(disp, ret) \
127 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
131 * A bunch of macros and checks to simplify error checking.
134 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
136 drv = _eglCheckDisplay(disp, __func__); \
138 RETURN_EGL_ERROR(disp, 0, ret); \
141 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
143 drv = _eglCheck ## type(disp, obj, __func__); \
145 RETURN_EGL_ERROR(disp, 0, ret); \
148 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
149 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
151 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
152 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
154 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
155 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
157 #define _EGL_CHECK_SCREEN(disp, scrn, ret, drv) \
158 _EGL_CHECK_OBJECT(disp, Screen, scrn, ret, drv)
160 #define _EGL_CHECK_MODE(disp, m, ret, drv) \
161 _EGL_CHECK_OBJECT(disp, Mode, m, ret, drv)
163 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
164 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
167 static inline _EGLDriver
*
168 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
171 _eglError(EGL_BAD_DISPLAY
, msg
);
174 if (!disp
->Initialized
) {
175 _eglError(EGL_NOT_INITIALIZED
, msg
);
182 static inline _EGLDriver
*
183 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
185 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
189 _eglError(EGL_BAD_SURFACE
, msg
);
196 static inline _EGLDriver
*
197 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
199 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
203 _eglError(EGL_BAD_CONTEXT
, msg
);
210 static inline _EGLDriver
*
211 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
213 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
217 _eglError(EGL_BAD_CONFIG
, msg
);
224 static inline _EGLDriver
*
225 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
227 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
231 _eglError(EGL_BAD_PARAMETER
, msg
);
238 #ifdef EGL_MESA_screen_surface
241 static inline _EGLDriver
*
242 _eglCheckScreen(_EGLDisplay
*disp
, _EGLScreen
*scrn
, const char *msg
)
244 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
248 _eglError(EGL_BAD_SCREEN_MESA
, msg
);
255 static inline _EGLDriver
*
256 _eglCheckMode(_EGLDisplay
*disp
, _EGLMode
*m
, const char *msg
)
258 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
262 _eglError(EGL_BAD_MODE_MESA
, msg
);
269 #endif /* EGL_MESA_screen_surface */
273 * Lookup and lock a display.
275 static inline _EGLDisplay
*
276 _eglLockDisplay(EGLDisplay display
)
278 _EGLDisplay
*dpy
= _eglLookupDisplay(display
);
280 mtx_lock(&dpy
->Mutex
);
289 _eglUnlockDisplay(_EGLDisplay
*dpy
)
291 mtx_unlock(&dpy
->Mutex
);
296 * This is typically the first EGL function that an application calls.
297 * It associates a private _EGLDisplay object to the native display.
299 EGLDisplay EGLAPIENTRY
300 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
302 _EGLPlatformType plat
;
304 void *native_display_ptr
;
306 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay
));
307 native_display_ptr
= (void*) nativeDisplay
;
309 plat
= _eglGetNativePlatform(native_display_ptr
);
310 dpy
= _eglFindDisplay(plat
, native_display_ptr
);
311 return _eglGetDisplayHandle(dpy
);
314 EGLDisplay EGLAPIENTRY
315 eglGetPlatformDisplayEXT(EGLenum platform
, void *native_display
,
316 const EGLint
*attrib_list
)
321 #ifdef HAVE_X11_PLATFORM
322 case EGL_PLATFORM_X11_EXT
:
323 dpy
= _eglGetX11Display((Display
*) native_display
, attrib_list
);
326 #ifdef HAVE_DRM_PLATFORM
327 case EGL_PLATFORM_GBM_MESA
:
328 dpy
= _eglGetGbmDisplay((struct gbm_device
*) native_display
,
332 #ifdef HAVE_WAYLAND_PLATFORM
333 case EGL_PLATFORM_WAYLAND_EXT
:
334 dpy
= _eglGetWaylandDisplay((struct wl_display
*) native_display
,
339 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, NULL
);
342 return _eglGetDisplayHandle(dpy
);
346 * This is typically the second EGL function that an application calls.
347 * Here we load/initialize the actual hardware driver.
349 EGLBoolean EGLAPIENTRY
350 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
352 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
355 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
357 if (!disp
->Initialized
) {
358 if (!_eglMatchDriver(disp
, EGL_FALSE
))
359 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
361 /* limit to APIs supported by core */
362 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
364 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
365 * classifies it as an EGL display extension, though conceptually it's an
366 * EGL client extension.
368 * From the EGL_KHR_get_all_proc_addresses spec:
370 * The EGL implementation must expose the name
371 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
372 * EGL_KHR_get_all_proc_addresses and supports
373 * EGL_EXT_client_extensions.
375 * Mesa unconditionally exposes both client extensions mentioned above,
376 * so the spec requires that each EGLDisplay unconditionally expose
377 * EGL_KHR_get_all_proc_addresses also.
379 disp
->Extensions
.KHR_get_all_proc_addresses
= EGL_TRUE
;
382 /* Update applications version of major and minor if not NULL */
383 if ((major
!= NULL
) && (minor
!= NULL
)) {
384 *major
= disp
->VersionMajor
;
385 *minor
= disp
->VersionMinor
;
388 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
392 EGLBoolean EGLAPIENTRY
393 eglTerminate(EGLDisplay dpy
)
395 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
398 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
400 if (disp
->Initialized
) {
401 _EGLDriver
*drv
= disp
->Driver
;
403 drv
->API
.Terminate(drv
, disp
);
404 /* do not reset disp->Driver */
405 disp
->Initialized
= EGL_FALSE
;
408 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
412 const char * EGLAPIENTRY
413 eglQueryString(EGLDisplay dpy
, EGLint name
)
419 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
420 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
423 disp
= _eglLockDisplay(dpy
);
424 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
425 ret
= drv
->API
.QueryString(drv
, disp
, name
);
427 RETURN_EGL_EVAL(disp
, ret
);
431 EGLBoolean EGLAPIENTRY
432 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
433 EGLint config_size
, EGLint
*num_config
)
435 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
439 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
440 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
442 RETURN_EGL_EVAL(disp
, ret
);
446 EGLBoolean EGLAPIENTRY
447 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
448 EGLint config_size
, EGLint
*num_config
)
450 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
454 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
455 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
456 config_size
, num_config
);
458 RETURN_EGL_EVAL(disp
, ret
);
462 EGLBoolean EGLAPIENTRY
463 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
464 EGLint attribute
, EGLint
*value
)
466 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
467 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
471 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
472 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
474 RETURN_EGL_EVAL(disp
, ret
);
478 EGLContext EGLAPIENTRY
479 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
480 const EGLint
*attrib_list
)
482 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
483 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
484 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
486 _EGLContext
*context
;
489 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
491 if (!config
&& !disp
->Extensions
.MESA_configless_context
)
492 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
494 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
495 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
497 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
498 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
500 RETURN_EGL_EVAL(disp
, ret
);
504 EGLBoolean EGLAPIENTRY
505 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
507 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
508 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
512 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
513 _eglUnlinkContext(context
);
514 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
516 RETURN_EGL_EVAL(disp
, ret
);
520 EGLBoolean EGLAPIENTRY
521 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
524 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
525 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
526 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
527 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
532 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
535 /* display is allowed to be uninitialized under certain condition */
536 if (!disp
->Initialized
) {
537 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
538 ctx
!= EGL_NO_CONTEXT
)
539 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
542 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
544 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
545 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
546 if (!draw_surf
|| !read_surf
) {
547 /* From the EGL 1.4 (20130211) spec:
549 * To release the current context without assigning a new one, set ctx
550 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
552 if (!disp
->Extensions
.KHR_surfaceless_context
&& ctx
!= EGL_NO_CONTEXT
)
553 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
555 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
556 (!read_surf
&& read
!= EGL_NO_SURFACE
))
557 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
558 if (draw_surf
|| read_surf
)
559 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
562 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
564 RETURN_EGL_EVAL(disp
, ret
);
568 EGLBoolean EGLAPIENTRY
569 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
570 EGLint attribute
, EGLint
*value
)
572 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
573 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
577 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
578 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
580 RETURN_EGL_EVAL(disp
, ret
);
585 _eglCreateWindowSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
586 void *native_window
, const EGLint
*attrib_list
)
588 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
593 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
595 if (native_window
== NULL
)
596 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
598 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, native_window
,
600 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
602 RETURN_EGL_EVAL(disp
, ret
);
606 EGLSurface EGLAPIENTRY
607 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
608 EGLNativeWindowType window
, const EGLint
*attrib_list
)
610 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
611 STATIC_ASSERT(sizeof(void*) == sizeof(window
));
612 return _eglCreateWindowSurfaceCommon(disp
, config
, (void*) window
,
617 EGLSurface EGLAPIENTRY
618 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
620 const EGLint
*attrib_list
)
622 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
624 #ifdef HAVE_X11_PLATFORM
625 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_window
!= NULL
) {
626 /* The `native_window` parameter for the X11 platform differs between
627 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
628 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
629 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
630 * `Window*`. Convert `Window*` to `Window` because that's what
631 * dri2_x11_create_window_surface() expects.
633 native_window
= (void*) (* (Window
*) native_window
);
637 return _eglCreateWindowSurfaceCommon(disp
, config
, native_window
,
643 _eglCreatePixmapSurfaceCommon(_EGLDisplay
*disp
, EGLConfig config
,
644 void *native_pixmap
, const EGLint
*attrib_list
)
646 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
651 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
652 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, native_pixmap
,
654 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
656 RETURN_EGL_EVAL(disp
, ret
);
660 EGLSurface EGLAPIENTRY
661 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
662 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
664 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
665 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap
));
666 return _eglCreatePixmapSurfaceCommon(disp
, config
, (void*) pixmap
,
670 EGLSurface EGLAPIENTRY
671 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy
, EGLConfig config
,
673 const EGLint
*attrib_list
)
675 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
677 #ifdef HAVE_X11_PLATFORM
678 /* The `native_pixmap` parameter for the X11 platform differs between
679 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
680 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
681 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
682 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
683 * dri2_x11_create_pixmap_surface() expects.
685 if (disp
->Platform
== _EGL_PLATFORM_X11
&& native_pixmap
!= NULL
) {
686 native_pixmap
= (void*) (* (Pixmap
*) native_pixmap
);
690 return _eglCreatePixmapSurfaceCommon(disp
, config
, native_pixmap
,
695 EGLSurface EGLAPIENTRY
696 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
697 const EGLint
*attrib_list
)
699 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
700 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
705 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
707 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
708 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
710 RETURN_EGL_EVAL(disp
, ret
);
714 EGLBoolean EGLAPIENTRY
715 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
717 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
718 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
722 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
723 _eglUnlinkSurface(surf
);
724 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
726 RETURN_EGL_EVAL(disp
, ret
);
729 EGLBoolean EGLAPIENTRY
730 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
731 EGLint attribute
, EGLint
*value
)
733 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
734 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
738 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
739 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
741 RETURN_EGL_EVAL(disp
, ret
);
744 EGLBoolean EGLAPIENTRY
745 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
746 EGLint attribute
, EGLint value
)
748 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
749 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
753 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
754 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
756 RETURN_EGL_EVAL(disp
, ret
);
760 EGLBoolean EGLAPIENTRY
761 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
763 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
764 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
768 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
769 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
771 RETURN_EGL_EVAL(disp
, ret
);
775 EGLBoolean EGLAPIENTRY
776 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
778 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
779 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
783 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
784 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
786 RETURN_EGL_EVAL(disp
, ret
);
790 EGLBoolean EGLAPIENTRY
791 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
793 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
794 _EGLContext
*ctx
= _eglGetCurrentContext();
799 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
801 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
802 ctx
->Resource
.Display
!= disp
)
803 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
805 surf
= ctx
->DrawSurface
;
806 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
807 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
809 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
811 RETURN_EGL_EVAL(disp
, ret
);
815 EGLBoolean EGLAPIENTRY
816 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
818 _EGLContext
*ctx
= _eglGetCurrentContext();
819 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
820 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
824 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
826 /* surface must be bound to current context in EGL 1.4 */
827 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
828 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
829 surf
!= ctx
->DrawSurface
)
830 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
833 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
835 RETURN_EGL_EVAL(disp
, ret
);
839 #ifdef EGL_EXT_swap_buffers_with_damage
841 EGLBoolean EGLAPIENTRY
842 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
843 EGLint
*rects
, EGLint n_rects
)
845 _EGLContext
*ctx
= _eglGetCurrentContext();
846 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
847 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
851 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
853 /* surface must be bound to current context in EGL 1.4 */
854 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
855 surf
!= ctx
->DrawSurface
)
856 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
858 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
859 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
861 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
863 RETURN_EGL_EVAL(disp
, ret
);
866 #endif /* EGL_EXT_swap_buffers_with_damage */
868 EGLBoolean EGLAPIENTRY
869 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
871 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
872 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
875 void *native_pixmap_ptr
;
877 STATIC_ASSERT(sizeof(void*) == sizeof(target
));
878 native_pixmap_ptr
= (void*) target
;
880 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
881 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
882 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
883 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, native_pixmap_ptr
);
885 RETURN_EGL_EVAL(disp
, ret
);
889 EGLBoolean EGLAPIENTRY
892 _EGLContext
*ctx
= _eglGetCurrentContext();
898 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
900 disp
= ctx
->Resource
.Display
;
901 mtx_lock(&disp
->Mutex
);
903 /* let bad current context imply bad current surface */
904 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
905 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
906 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
908 /* a valid current context implies an initialized current display */
909 assert(disp
->Initialized
);
911 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
913 RETURN_EGL_EVAL(disp
, ret
);
917 EGLBoolean EGLAPIENTRY
920 _EGLThreadInfo
*t
= _eglGetCurrentThread();
921 EGLint api_index
= t
->CurrentAPIIndex
;
922 EGLint es_index
= _eglConvertApiToIndex(EGL_OPENGL_ES_API
);
925 if (api_index
!= es_index
&& _eglIsCurrentThreadDummy())
926 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
928 t
->CurrentAPIIndex
= es_index
;
929 ret
= eglWaitClient();
930 t
->CurrentAPIIndex
= api_index
;
935 EGLBoolean EGLAPIENTRY
936 eglWaitNative(EGLint engine
)
938 _EGLContext
*ctx
= _eglGetCurrentContext();
944 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
946 disp
= ctx
->Resource
.Display
;
947 mtx_lock(&disp
->Mutex
);
949 /* let bad current context imply bad current surface */
950 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
951 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
952 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
954 /* a valid current context implies an initialized current display */
955 assert(disp
->Initialized
);
957 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
959 RETURN_EGL_EVAL(disp
, ret
);
963 EGLDisplay EGLAPIENTRY
964 eglGetCurrentDisplay(void)
966 _EGLContext
*ctx
= _eglGetCurrentContext();
969 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
971 RETURN_EGL_SUCCESS(NULL
, ret
);
975 EGLContext EGLAPIENTRY
976 eglGetCurrentContext(void)
978 _EGLContext
*ctx
= _eglGetCurrentContext();
981 ret
= _eglGetContextHandle(ctx
);
983 RETURN_EGL_SUCCESS(NULL
, ret
);
987 EGLSurface EGLAPIENTRY
988 eglGetCurrentSurface(EGLint readdraw
)
990 _EGLContext
*ctx
= _eglGetCurrentContext();
991 EGLint err
= EGL_SUCCESS
;
996 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
1000 surf
= ctx
->DrawSurface
;
1003 surf
= ctx
->ReadSurface
;
1007 err
= EGL_BAD_PARAMETER
;
1011 ret
= _eglGetSurfaceHandle(surf
);
1013 RETURN_EGL_ERROR(NULL
, err
, ret
);
1020 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1021 EGLint e
= t
->LastError
;
1022 if (!_eglIsCurrentThreadDummy())
1023 t
->LastError
= EGL_SUCCESS
;
1028 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
1029 eglGetProcAddress(const char *procname
)
1031 static const struct {
1034 } egl_functions
[] = {
1035 /* core functions should not be queryable, but, well... */
1036 #ifdef _EGL_GET_CORE_ADDRESSES
1037 /* alphabetical order */
1038 { "eglBindAPI", (_EGLProc
) eglBindAPI
},
1039 { "eglBindTexImage", (_EGLProc
) eglBindTexImage
},
1040 { "eglChooseConfig", (_EGLProc
) eglChooseConfig
},
1041 { "eglCopyBuffers", (_EGLProc
) eglCopyBuffers
},
1042 { "eglCreateContext", (_EGLProc
) eglCreateContext
},
1043 { "eglCreatePbufferFromClientBuffer", (_EGLProc
) eglCreatePbufferFromClientBuffer
},
1044 { "eglCreatePbufferSurface", (_EGLProc
) eglCreatePbufferSurface
},
1045 { "eglCreatePixmapSurface", (_EGLProc
) eglCreatePixmapSurface
},
1046 { "eglCreateWindowSurface", (_EGLProc
) eglCreateWindowSurface
},
1047 { "eglDestroyContext", (_EGLProc
) eglDestroyContext
},
1048 { "eglDestroySurface", (_EGLProc
) eglDestroySurface
},
1049 { "eglGetConfigAttrib", (_EGLProc
) eglGetConfigAttrib
},
1050 { "eglGetConfigs", (_EGLProc
) eglGetConfigs
},
1051 { "eglGetCurrentContext", (_EGLProc
) eglGetCurrentContext
},
1052 { "eglGetCurrentDisplay", (_EGLProc
) eglGetCurrentDisplay
},
1053 { "eglGetCurrentSurface", (_EGLProc
) eglGetCurrentSurface
},
1054 { "eglGetDisplay", (_EGLProc
) eglGetDisplay
},
1055 { "eglGetError", (_EGLProc
) eglGetError
},
1056 { "eglGetProcAddress", (_EGLProc
) eglGetProcAddress
},
1057 { "eglInitialize", (_EGLProc
) eglInitialize
},
1058 { "eglMakeCurrent", (_EGLProc
) eglMakeCurrent
},
1059 { "eglQueryAPI", (_EGLProc
) eglQueryAPI
},
1060 { "eglQueryContext", (_EGLProc
) eglQueryContext
},
1061 { "eglQueryString", (_EGLProc
) eglQueryString
},
1062 { "eglQuerySurface", (_EGLProc
) eglQuerySurface
},
1063 { "eglReleaseTexImage", (_EGLProc
) eglReleaseTexImage
},
1064 { "eglReleaseThread", (_EGLProc
) eglReleaseThread
},
1065 { "eglSurfaceAttrib", (_EGLProc
) eglSurfaceAttrib
},
1066 { "eglSwapBuffers", (_EGLProc
) eglSwapBuffers
},
1067 { "eglSwapInterval", (_EGLProc
) eglSwapInterval
},
1068 { "eglTerminate", (_EGLProc
) eglTerminate
},
1069 { "eglWaitClient", (_EGLProc
) eglWaitClient
},
1070 { "eglWaitGL", (_EGLProc
) eglWaitGL
},
1071 { "eglWaitNative", (_EGLProc
) eglWaitNative
},
1072 #endif /* _EGL_GET_CORE_ADDRESSES */
1073 #ifdef EGL_MESA_screen_surface
1074 { "eglChooseModeMESA", (_EGLProc
) eglChooseModeMESA
},
1075 { "eglGetModesMESA", (_EGLProc
) eglGetModesMESA
},
1076 { "eglGetModeAttribMESA", (_EGLProc
) eglGetModeAttribMESA
},
1077 { "eglCopyContextMESA", (_EGLProc
) eglCopyContextMESA
},
1078 { "eglGetScreensMESA", (_EGLProc
) eglGetScreensMESA
},
1079 { "eglCreateScreenSurfaceMESA", (_EGLProc
) eglCreateScreenSurfaceMESA
},
1080 { "eglShowScreenSurfaceMESA", (_EGLProc
) eglShowScreenSurfaceMESA
},
1081 { "eglScreenPositionMESA", (_EGLProc
) eglScreenPositionMESA
},
1082 { "eglQueryScreenMESA", (_EGLProc
) eglQueryScreenMESA
},
1083 { "eglQueryScreenSurfaceMESA", (_EGLProc
) eglQueryScreenSurfaceMESA
},
1084 { "eglQueryScreenModeMESA", (_EGLProc
) eglQueryScreenModeMESA
},
1085 { "eglQueryModeStringMESA", (_EGLProc
) eglQueryModeStringMESA
},
1086 #endif /* EGL_MESA_screen_surface */
1087 #ifdef EGL_MESA_drm_display
1088 { "eglGetDRMDisplayMESA", (_EGLProc
) eglGetDRMDisplayMESA
},
1090 { "eglCreateImageKHR", (_EGLProc
) eglCreateImageKHR
},
1091 { "eglDestroyImageKHR", (_EGLProc
) eglDestroyImageKHR
},
1092 { "eglCreateSyncKHR", (_EGLProc
) eglCreateSyncKHR
},
1093 { "eglDestroySyncKHR", (_EGLProc
) eglDestroySyncKHR
},
1094 { "eglClientWaitSyncKHR", (_EGLProc
) eglClientWaitSyncKHR
},
1095 { "eglSignalSyncKHR", (_EGLProc
) eglSignalSyncKHR
},
1096 { "eglGetSyncAttribKHR", (_EGLProc
) eglGetSyncAttribKHR
},
1097 #ifdef EGL_NOK_swap_region
1098 { "eglSwapBuffersRegionNOK", (_EGLProc
) eglSwapBuffersRegionNOK
},
1100 #ifdef EGL_MESA_drm_image
1101 { "eglCreateDRMImageMESA", (_EGLProc
) eglCreateDRMImageMESA
},
1102 { "eglExportDRMImageMESA", (_EGLProc
) eglExportDRMImageMESA
},
1104 #ifdef EGL_WL_bind_wayland_display
1105 { "eglBindWaylandDisplayWL", (_EGLProc
) eglBindWaylandDisplayWL
},
1106 { "eglUnbindWaylandDisplayWL", (_EGLProc
) eglUnbindWaylandDisplayWL
},
1107 { "eglQueryWaylandBufferWL", (_EGLProc
) eglQueryWaylandBufferWL
},
1109 #ifdef EGL_WL_create_wayland_buffer_from_image
1110 { "eglCreateWaylandBufferFromImageWL", (_EGLProc
) eglCreateWaylandBufferFromImageWL
},
1112 { "eglPostSubBufferNV", (_EGLProc
) eglPostSubBufferNV
},
1113 #ifdef EGL_EXT_swap_buffers_with_damage
1114 { "eglSwapBuffersWithDamageEXT", (_EGLProc
) eglSwapBuffersWithDamageEXT
},
1116 { "eglGetPlatformDisplayEXT", (_EGLProc
) eglGetPlatformDisplayEXT
},
1117 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc
) eglCreatePlatformWindowSurfaceEXT
},
1118 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc
) eglCreatePlatformPixmapSurfaceEXT
},
1119 { "eglGetSyncValuesCHROMIUM", (_EGLProc
) eglGetSyncValuesCHROMIUM
},
1126 RETURN_EGL_SUCCESS(NULL
, NULL
);
1129 if (strncmp(procname
, "egl", 3) == 0) {
1130 for (i
= 0; egl_functions
[i
].name
; i
++) {
1131 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
1132 ret
= egl_functions
[i
].function
;
1138 ret
= _eglGetDriverProc(procname
);
1140 RETURN_EGL_SUCCESS(NULL
, ret
);
1144 #ifdef EGL_MESA_screen_surface
1148 * EGL_MESA_screen extension
1151 EGLBoolean EGLAPIENTRY
1152 eglChooseModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1153 const EGLint
*attrib_list
, EGLModeMESA
*modes
,
1154 EGLint modes_size
, EGLint
*num_modes
)
1156 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1157 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1161 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1162 ret
= drv
->API
.ChooseModeMESA(drv
, disp
, scrn
, attrib_list
,
1163 modes
, modes_size
, num_modes
);
1165 RETURN_EGL_EVAL(disp
, ret
);
1169 EGLBoolean EGLAPIENTRY
1170 eglGetModesMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*modes
,
1171 EGLint mode_size
, EGLint
*num_mode
)
1173 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1174 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1178 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1179 ret
= drv
->API
.GetModesMESA(drv
, disp
, scrn
, modes
, mode_size
, num_mode
);
1181 RETURN_EGL_EVAL(disp
, ret
);
1185 EGLBoolean EGLAPIENTRY
1186 eglGetModeAttribMESA(EGLDisplay dpy
, EGLModeMESA mode
,
1187 EGLint attribute
, EGLint
*value
)
1189 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1190 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1194 _EGL_CHECK_MODE(disp
, m
, EGL_FALSE
, drv
);
1195 ret
= drv
->API
.GetModeAttribMESA(drv
, disp
, m
, attribute
, value
);
1197 RETURN_EGL_EVAL(disp
, ret
);
1201 EGLBoolean EGLAPIENTRY
1202 eglCopyContextMESA(EGLDisplay dpy
, EGLContext source
, EGLContext dest
,
1205 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1206 _EGLContext
*source_context
= _eglLookupContext(source
, disp
);
1207 _EGLContext
*dest_context
= _eglLookupContext(dest
, disp
);
1211 _EGL_CHECK_CONTEXT(disp
, source_context
, EGL_FALSE
, drv
);
1213 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1215 ret
= drv
->API
.CopyContextMESA(drv
, disp
,
1216 source_context
, dest_context
, mask
);
1218 RETURN_EGL_EVAL(disp
, ret
);
1222 EGLBoolean EGLAPIENTRY
1223 eglGetScreensMESA(EGLDisplay dpy
, EGLScreenMESA
*screens
,
1224 EGLint max_screens
, EGLint
*num_screens
)
1226 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1230 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1231 ret
= drv
->API
.GetScreensMESA(drv
, disp
, screens
, max_screens
, num_screens
);
1233 RETURN_EGL_EVAL(disp
, ret
);
1237 EGLSurface EGLAPIENTRY
1238 eglCreateScreenSurfaceMESA(EGLDisplay dpy
, EGLConfig config
,
1239 const EGLint
*attrib_list
)
1241 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1242 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1247 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1249 surf
= drv
->API
.CreateScreenSurfaceMESA(drv
, disp
, conf
, attrib_list
);
1250 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1252 RETURN_EGL_EVAL(disp
, ret
);
1256 EGLBoolean EGLAPIENTRY
1257 eglShowScreenSurfaceMESA(EGLDisplay dpy
, EGLint screen
,
1258 EGLSurface surface
, EGLModeMESA mode
)
1260 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1261 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1262 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1263 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1267 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1268 if (!surf
&& surface
!= EGL_NO_SURFACE
)
1269 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1270 if (!m
&& mode
!= EGL_NO_MODE_MESA
)
1271 RETURN_EGL_ERROR(disp
, EGL_BAD_MODE_MESA
, EGL_FALSE
);
1273 ret
= drv
->API
.ShowScreenSurfaceMESA(drv
, disp
, scrn
, surf
, m
);
1275 RETURN_EGL_EVAL(disp
, ret
);
1279 EGLBoolean EGLAPIENTRY
1280 eglScreenPositionMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLint x
, EGLint y
)
1282 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1283 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1287 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1288 ret
= drv
->API
.ScreenPositionMESA(drv
, disp
, scrn
, x
, y
);
1290 RETURN_EGL_EVAL(disp
, ret
);
1294 EGLBoolean EGLAPIENTRY
1295 eglQueryScreenMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1296 EGLint attribute
, EGLint
*value
)
1298 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1299 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1303 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1304 ret
= drv
->API
.QueryScreenMESA(drv
, disp
, scrn
, attribute
, value
);
1306 RETURN_EGL_EVAL(disp
, ret
);
1310 EGLBoolean EGLAPIENTRY
1311 eglQueryScreenSurfaceMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1312 EGLSurface
*surface
)
1314 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1315 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1320 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1321 ret
= drv
->API
.QueryScreenSurfaceMESA(drv
, disp
, scrn
, &surf
);
1323 *surface
= _eglGetSurfaceHandle(surf
);
1325 RETURN_EGL_EVAL(disp
, ret
);
1329 EGLBoolean EGLAPIENTRY
1330 eglQueryScreenModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*mode
)
1332 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1333 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1338 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1339 ret
= drv
->API
.QueryScreenModeMESA(drv
, disp
, scrn
, &m
);
1343 RETURN_EGL_EVAL(disp
, ret
);
1347 const char * EGLAPIENTRY
1348 eglQueryModeStringMESA(EGLDisplay dpy
, EGLModeMESA mode
)
1350 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1351 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1355 _EGL_CHECK_MODE(disp
, m
, NULL
, drv
);
1356 ret
= drv
->API
.QueryModeStringMESA(drv
, disp
, m
);
1358 RETURN_EGL_EVAL(disp
, ret
);
1362 #endif /* EGL_MESA_screen_surface */
1365 #ifdef EGL_MESA_drm_display
1367 EGLDisplay EGLAPIENTRY
1368 eglGetDRMDisplayMESA(int fd
)
1370 _EGLDisplay
*dpy
= _eglFindDisplay(_EGL_PLATFORM_DRM
, (void *) (intptr_t) fd
);
1371 return _eglGetDisplayHandle(dpy
);
1374 #endif /* EGL_MESA_drm_display */
1381 * Specify the client API to use for subsequent calls including:
1382 * eglCreateContext()
1383 * eglGetCurrentContext()
1384 * eglGetCurrentDisplay()
1385 * eglGetCurrentSurface()
1386 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1389 * See section 3.7 "Rendering Context" in the EGL specification for details.
1391 EGLBoolean EGLAPIENTRY
1392 eglBindAPI(EGLenum api
)
1394 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1396 if (_eglIsCurrentThreadDummy())
1397 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1399 if (!_eglIsApiValid(api
))
1400 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1402 t
->CurrentAPIIndex
= _eglConvertApiToIndex(api
);
1404 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1409 * Return the last value set with eglBindAPI().
1414 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1417 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1418 ret
= _eglConvertApiFromIndex(t
->CurrentAPIIndex
);
1420 RETURN_EGL_SUCCESS(NULL
, ret
);
1424 EGLSurface EGLAPIENTRY
1425 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1426 EGLClientBuffer buffer
, EGLConfig config
,
1427 const EGLint
*attrib_list
)
1429 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1430 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1435 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1437 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1439 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1441 RETURN_EGL_EVAL(disp
, ret
);
1445 EGLBoolean EGLAPIENTRY
1446 eglReleaseThread(void)
1448 /* unbind current contexts */
1449 if (!_eglIsCurrentThreadDummy()) {
1450 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1451 EGLint api_index
= t
->CurrentAPIIndex
;
1454 for (i
= 0; i
< _EGL_API_NUM_APIS
; i
++) {
1455 _EGLContext
*ctx
= t
->CurrentContexts
[i
];
1457 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1460 t
->CurrentAPIIndex
= i
;
1462 mtx_lock(&disp
->Mutex
);
1464 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1465 mtx_unlock(&disp
->Mutex
);
1469 t
->CurrentAPIIndex
= api_index
;
1472 _eglDestroyCurrentThread();
1474 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1478 EGLImageKHR EGLAPIENTRY
1479 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1480 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1482 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1483 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1488 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1489 if (!disp
->Extensions
.KHR_image_base
)
1490 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1491 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1492 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1493 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1494 * <ctx> must be EGL_NO_CONTEXT..."
1496 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1497 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1499 img
= drv
->API
.CreateImageKHR(drv
,
1500 disp
, context
, target
, buffer
, attr_list
);
1501 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1503 RETURN_EGL_EVAL(disp
, ret
);
1507 EGLBoolean EGLAPIENTRY
1508 eglDestroyImageKHR(EGLDisplay dpy
, EGLImageKHR image
)
1510 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1511 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1515 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1516 if (!disp
->Extensions
.KHR_image_base
)
1517 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1519 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1521 _eglUnlinkImage(img
);
1522 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1524 RETURN_EGL_EVAL(disp
, ret
);
1528 EGLSyncKHR EGLAPIENTRY
1529 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*attrib_list
)
1531 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1536 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1537 if (!disp
->Extensions
.KHR_reusable_sync
)
1538 RETURN_EGL_EVAL(disp
, EGL_NO_SYNC_KHR
);
1540 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1541 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1543 RETURN_EGL_EVAL(disp
, ret
);
1547 EGLBoolean EGLAPIENTRY
1548 eglDestroySyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
)
1550 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1551 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1555 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1556 assert(disp
->Extensions
.KHR_reusable_sync
);
1559 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1561 RETURN_EGL_EVAL(disp
, ret
);
1566 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLint flags
, EGLTimeKHR timeout
)
1568 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1569 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1573 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1574 assert(disp
->Extensions
.KHR_reusable_sync
);
1575 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1577 RETURN_EGL_EVAL(disp
, ret
);
1581 EGLBoolean EGLAPIENTRY
1582 eglSignalSyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLenum mode
)
1584 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1585 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1589 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1590 assert(disp
->Extensions
.KHR_reusable_sync
);
1591 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
1593 RETURN_EGL_EVAL(disp
, ret
);
1597 EGLBoolean EGLAPIENTRY
1598 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLint attribute
, EGLint
*value
)
1600 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1601 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1605 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1606 assert(disp
->Extensions
.KHR_reusable_sync
);
1607 ret
= drv
->API
.GetSyncAttribKHR(drv
, disp
, s
, attribute
, value
);
1609 RETURN_EGL_EVAL(disp
, ret
);
1613 #ifdef EGL_NOK_swap_region
1615 EGLBoolean EGLAPIENTRY
1616 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
1617 EGLint numRects
, const EGLint
*rects
)
1619 _EGLContext
*ctx
= _eglGetCurrentContext();
1620 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1621 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1625 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1627 if (!disp
->Extensions
.NOK_swap_region
)
1628 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1630 /* surface must be bound to current context in EGL 1.4 */
1631 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1632 surf
!= ctx
->DrawSurface
)
1633 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1635 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
1637 RETURN_EGL_EVAL(disp
, ret
);
1640 #endif /* EGL_NOK_swap_region */
1643 #ifdef EGL_MESA_drm_image
1645 EGLImageKHR EGLAPIENTRY
1646 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
1648 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1653 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1654 if (!disp
->Extensions
.MESA_drm_image
)
1655 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1657 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
1658 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1660 RETURN_EGL_EVAL(disp
, ret
);
1663 EGLBoolean EGLAPIENTRY
1664 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImageKHR image
,
1665 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
1667 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1668 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1672 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1673 assert(disp
->Extensions
.MESA_drm_image
);
1676 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1678 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
1680 RETURN_EGL_EVAL(disp
, ret
);
1685 #ifdef EGL_WL_bind_wayland_display
1688 EGLBoolean EGLAPIENTRY
1689 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1691 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1695 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1696 assert(disp
->Extensions
.WL_bind_wayland_display
);
1699 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1701 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
1703 RETURN_EGL_EVAL(disp
, ret
);
1706 EGLBoolean EGLAPIENTRY
1707 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1709 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1713 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1714 assert(disp
->Extensions
.WL_bind_wayland_display
);
1717 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1719 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
1721 RETURN_EGL_EVAL(disp
, ret
);
1724 EGLBoolean EGLAPIENTRY
1725 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
1726 EGLint attribute
, EGLint
*value
)
1728 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1732 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1733 assert(disp
->Extensions
.WL_bind_wayland_display
);
1736 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1738 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
1740 RETURN_EGL_EVAL(disp
, ret
);
1744 #ifdef EGL_WL_create_wayland_buffer_from_image
1745 struct wl_buffer
* EGLAPIENTRY
1746 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImageKHR image
)
1748 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1751 struct wl_buffer
*ret
;
1753 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
1754 assert(disp
->Extensions
.WL_create_wayland_buffer_from_image
);
1756 img
= _eglLookupImage(image
, disp
);
1759 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
1761 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
1763 RETURN_EGL_EVAL(disp
, ret
);
1767 EGLBoolean EGLAPIENTRY
1768 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
1769 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
1771 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1772 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1776 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1778 if (!disp
->Extensions
.NV_post_sub_buffer
)
1779 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1781 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
1783 RETURN_EGL_EVAL(disp
, ret
);
1786 EGLBoolean EGLAPIENTRY
1787 eglGetSyncValuesCHROMIUM(EGLDisplay display
, EGLSurface surface
,
1788 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
1791 _EGLDisplay
*disp
= _eglLockDisplay(display
);
1792 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1796 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1797 if (!disp
->Extensions
.CHROMIUM_sync_control
)
1798 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1800 if (!ust
|| !msc
|| !sbc
)
1801 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1803 ret
= drv
->API
.GetSyncValuesCHROMIUM(disp
, surf
, ust
, msc
, sbc
);
1805 RETURN_EGL_EVAL(disp
, ret
);