1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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
= _eglGetNativePlatform(nativeDisplay
);
300 _EGLDisplay
*dpy
= _eglFindDisplay(plat
, (void *) nativeDisplay
);
301 return _eglGetDisplayHandle(dpy
);
306 * This is typically the second EGL function that an application calls.
307 * Here we load/initialize the actual hardware driver.
309 EGLBoolean EGLAPIENTRY
310 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
312 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
315 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
317 if (!disp
->Initialized
) {
318 if (!_eglMatchDriver(disp
, EGL_FALSE
))
319 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
321 /* limit to APIs supported by core */
322 disp
->ClientAPIs
&= _EGL_API_ALL_BITS
;
325 /* Update applications version of major and minor if not NULL */
326 if ((major
!= NULL
) && (minor
!= NULL
)) {
327 *major
= disp
->VersionMajor
;
328 *minor
= disp
->VersionMinor
;
331 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
335 EGLBoolean EGLAPIENTRY
336 eglTerminate(EGLDisplay dpy
)
338 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
341 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
343 if (disp
->Initialized
) {
344 _EGLDriver
*drv
= disp
->Driver
;
346 drv
->API
.Terminate(drv
, disp
);
347 /* do not reset disp->Driver */
348 disp
->Initialized
= EGL_FALSE
;
351 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
355 const char * EGLAPIENTRY
356 eglQueryString(EGLDisplay dpy
, EGLint name
)
362 if (dpy
== EGL_NO_DISPLAY
&& name
== EGL_EXTENSIONS
) {
363 RETURN_EGL_SUCCESS(NULL
, _eglGlobal
.ClientExtensionString
);
366 disp
= _eglLockDisplay(dpy
);
367 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
368 ret
= drv
->API
.QueryString(drv
, disp
, name
);
370 RETURN_EGL_EVAL(disp
, ret
);
374 EGLBoolean EGLAPIENTRY
375 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
376 EGLint config_size
, EGLint
*num_config
)
378 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
382 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
383 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
385 RETURN_EGL_EVAL(disp
, ret
);
389 EGLBoolean EGLAPIENTRY
390 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
391 EGLint config_size
, EGLint
*num_config
)
393 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
397 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
398 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
399 config_size
, num_config
);
401 RETURN_EGL_EVAL(disp
, ret
);
405 EGLBoolean EGLAPIENTRY
406 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
407 EGLint attribute
, EGLint
*value
)
409 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
410 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
414 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
415 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
417 RETURN_EGL_EVAL(disp
, ret
);
421 EGLContext EGLAPIENTRY
422 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
423 const EGLint
*attrib_list
)
425 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
426 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
427 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
429 _EGLContext
*context
;
432 _EGL_CHECK_DISPLAY(disp
, EGL_NO_CONTEXT
, drv
);
435 /* config may be NULL if surfaceless */
436 if (!disp
->Extensions
.KHR_surfaceless_context
)
437 RETURN_EGL_ERROR(disp
, EGL_BAD_CONFIG
, EGL_NO_CONTEXT
);
440 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
441 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
443 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
444 ret
= (context
) ? _eglLinkContext(context
) : EGL_NO_CONTEXT
;
446 RETURN_EGL_EVAL(disp
, ret
);
450 EGLBoolean EGLAPIENTRY
451 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
453 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
454 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
458 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
459 _eglUnlinkContext(context
);
460 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
462 RETURN_EGL_EVAL(disp
, ret
);
466 EGLBoolean EGLAPIENTRY
467 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
470 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
471 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
472 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
473 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
478 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
481 /* display is allowed to be uninitialized under certain condition */
482 if (!disp
->Initialized
) {
483 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
484 ctx
!= EGL_NO_CONTEXT
)
485 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
488 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
490 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
491 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
492 if (!draw_surf
|| !read_surf
) {
493 /* surfaces may be NULL if surfaceless */
494 if (!disp
->Extensions
.KHR_surfaceless_context
)
495 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
497 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
498 (!read_surf
&& read
!= EGL_NO_SURFACE
))
499 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
500 if (draw_surf
|| read_surf
)
501 RETURN_EGL_ERROR(disp
, EGL_BAD_MATCH
, EGL_FALSE
);
504 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
506 RETURN_EGL_EVAL(disp
, ret
);
510 EGLBoolean EGLAPIENTRY
511 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
512 EGLint attribute
, EGLint
*value
)
514 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
515 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
519 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
520 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
522 RETURN_EGL_EVAL(disp
, ret
);
526 EGLSurface EGLAPIENTRY
527 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
528 EGLNativeWindowType window
, const EGLint
*attrib_list
)
530 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
531 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
536 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
537 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
538 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
540 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, window
, attrib_list
);
541 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
543 RETURN_EGL_EVAL(disp
, ret
);
547 EGLSurface EGLAPIENTRY
548 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
549 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
551 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
552 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
557 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
558 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
559 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
561 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, pixmap
, attrib_list
);
562 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
564 RETURN_EGL_EVAL(disp
, ret
);
568 EGLSurface EGLAPIENTRY
569 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
570 const EGLint
*attrib_list
)
572 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
573 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
578 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
580 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
581 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
583 RETURN_EGL_EVAL(disp
, ret
);
587 EGLBoolean EGLAPIENTRY
588 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
590 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
591 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
595 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
596 _eglUnlinkSurface(surf
);
597 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
599 RETURN_EGL_EVAL(disp
, ret
);
602 EGLBoolean EGLAPIENTRY
603 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
604 EGLint attribute
, EGLint
*value
)
606 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
607 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
611 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
612 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
614 RETURN_EGL_EVAL(disp
, ret
);
617 EGLBoolean EGLAPIENTRY
618 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
619 EGLint attribute
, EGLint value
)
621 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
622 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
626 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
627 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
629 RETURN_EGL_EVAL(disp
, ret
);
633 EGLBoolean EGLAPIENTRY
634 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
636 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
637 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
641 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
642 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
644 RETURN_EGL_EVAL(disp
, ret
);
648 EGLBoolean EGLAPIENTRY
649 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
651 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
652 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
656 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
657 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
659 RETURN_EGL_EVAL(disp
, ret
);
663 EGLBoolean EGLAPIENTRY
664 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
666 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
667 _EGLContext
*ctx
= _eglGetCurrentContext();
672 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
674 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
675 ctx
->Resource
.Display
!= disp
)
676 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
678 surf
= ctx
->DrawSurface
;
679 if (_eglGetSurfaceHandle(surf
) == EGL_NO_SURFACE
)
680 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
682 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
684 RETURN_EGL_EVAL(disp
, ret
);
688 EGLBoolean EGLAPIENTRY
689 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
691 _EGLContext
*ctx
= _eglGetCurrentContext();
692 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
693 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
697 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
699 /* surface must be bound to current context in EGL 1.4 */
700 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
701 surf
!= ctx
->DrawSurface
)
702 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
704 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
706 RETURN_EGL_EVAL(disp
, ret
);
710 #ifdef EGL_EXT_swap_buffers_with_damage
712 EGLBoolean EGLAPIENTRY
713 eglSwapBuffersWithDamageEXT(EGLDisplay dpy
, EGLSurface surface
,
714 EGLint
*rects
, EGLint n_rects
)
716 _EGLContext
*ctx
= _eglGetCurrentContext();
717 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
718 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
722 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
724 /* surface must be bound to current context in EGL 1.4 */
725 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
726 surf
!= ctx
->DrawSurface
)
727 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
729 if ((n_rects
> 0 && rects
== NULL
) || n_rects
< 0)
730 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
732 ret
= drv
->API
.SwapBuffersWithDamageEXT(drv
, disp
, surf
, rects
, n_rects
);
734 RETURN_EGL_EVAL(disp
, ret
);
737 #endif /* EGL_EXT_swap_buffers_with_damage */
739 EGLBoolean EGLAPIENTRY
740 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
742 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
743 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
747 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
748 if (disp
->Platform
!= _eglGetNativePlatform(disp
->PlatformDisplay
))
749 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
750 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, target
);
752 RETURN_EGL_EVAL(disp
, ret
);
756 EGLBoolean EGLAPIENTRY
759 _EGLContext
*ctx
= _eglGetCurrentContext();
765 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
767 disp
= ctx
->Resource
.Display
;
768 _eglLockMutex(&disp
->Mutex
);
770 /* let bad current context imply bad current surface */
771 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
772 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
773 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
775 /* a valid current context implies an initialized current display */
776 assert(disp
->Initialized
);
778 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
780 RETURN_EGL_EVAL(disp
, ret
);
784 EGLBoolean EGLAPIENTRY
787 _EGLThreadInfo
*t
= _eglGetCurrentThread();
788 EGLint api_index
= t
->CurrentAPIIndex
;
789 EGLint es_index
= _eglConvertApiToIndex(EGL_OPENGL_ES_API
);
792 if (api_index
!= es_index
&& _eglIsCurrentThreadDummy())
793 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
795 t
->CurrentAPIIndex
= es_index
;
796 ret
= eglWaitClient();
797 t
->CurrentAPIIndex
= api_index
;
802 EGLBoolean EGLAPIENTRY
803 eglWaitNative(EGLint engine
)
805 _EGLContext
*ctx
= _eglGetCurrentContext();
811 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
813 disp
= ctx
->Resource
.Display
;
814 _eglLockMutex(&disp
->Mutex
);
816 /* let bad current context imply bad current surface */
817 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
818 _eglGetSurfaceHandle(ctx
->DrawSurface
) == EGL_NO_SURFACE
)
819 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
821 /* a valid current context implies an initialized current display */
822 assert(disp
->Initialized
);
824 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
826 RETURN_EGL_EVAL(disp
, ret
);
830 EGLDisplay EGLAPIENTRY
831 eglGetCurrentDisplay(void)
833 _EGLContext
*ctx
= _eglGetCurrentContext();
836 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
838 RETURN_EGL_SUCCESS(NULL
, ret
);
842 EGLContext EGLAPIENTRY
843 eglGetCurrentContext(void)
845 _EGLContext
*ctx
= _eglGetCurrentContext();
848 ret
= _eglGetContextHandle(ctx
);
850 RETURN_EGL_SUCCESS(NULL
, ret
);
854 EGLSurface EGLAPIENTRY
855 eglGetCurrentSurface(EGLint readdraw
)
857 _EGLContext
*ctx
= _eglGetCurrentContext();
858 EGLint err
= EGL_SUCCESS
;
863 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
867 surf
= ctx
->DrawSurface
;
870 surf
= ctx
->ReadSurface
;
874 err
= EGL_BAD_PARAMETER
;
878 ret
= _eglGetSurfaceHandle(surf
);
880 RETURN_EGL_ERROR(NULL
, err
, ret
);
887 _EGLThreadInfo
*t
= _eglGetCurrentThread();
888 EGLint e
= t
->LastError
;
889 if (!_eglIsCurrentThreadDummy())
890 t
->LastError
= EGL_SUCCESS
;
895 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
896 eglGetProcAddress(const char *procname
)
898 static const struct {
901 } egl_functions
[] = {
902 /* core functions should not be queryable, but, well... */
903 #ifdef _EGL_GET_CORE_ADDRESSES
904 /* alphabetical order */
905 { "eglBindAPI", (_EGLProc
) eglBindAPI
},
906 { "eglBindTexImage", (_EGLProc
) eglBindTexImage
},
907 { "eglChooseConfig", (_EGLProc
) eglChooseConfig
},
908 { "eglCopyBuffers", (_EGLProc
) eglCopyBuffers
},
909 { "eglCreateContext", (_EGLProc
) eglCreateContext
},
910 { "eglCreatePbufferFromClientBuffer", (_EGLProc
) eglCreatePbufferFromClientBuffer
},
911 { "eglCreatePbufferSurface", (_EGLProc
) eglCreatePbufferSurface
},
912 { "eglCreatePixmapSurface", (_EGLProc
) eglCreatePixmapSurface
},
913 { "eglCreateWindowSurface", (_EGLProc
) eglCreateWindowSurface
},
914 { "eglDestroyContext", (_EGLProc
) eglDestroyContext
},
915 { "eglDestroySurface", (_EGLProc
) eglDestroySurface
},
916 { "eglGetConfigAttrib", (_EGLProc
) eglGetConfigAttrib
},
917 { "eglGetConfigs", (_EGLProc
) eglGetConfigs
},
918 { "eglGetCurrentContext", (_EGLProc
) eglGetCurrentContext
},
919 { "eglGetCurrentDisplay", (_EGLProc
) eglGetCurrentDisplay
},
920 { "eglGetCurrentSurface", (_EGLProc
) eglGetCurrentSurface
},
921 { "eglGetDisplay", (_EGLProc
) eglGetDisplay
},
922 { "eglGetError", (_EGLProc
) eglGetError
},
923 { "eglGetProcAddress", (_EGLProc
) eglGetProcAddress
},
924 { "eglInitialize", (_EGLProc
) eglInitialize
},
925 { "eglMakeCurrent", (_EGLProc
) eglMakeCurrent
},
926 { "eglQueryAPI", (_EGLProc
) eglQueryAPI
},
927 { "eglQueryContext", (_EGLProc
) eglQueryContext
},
928 { "eglQueryString", (_EGLProc
) eglQueryString
},
929 { "eglQuerySurface", (_EGLProc
) eglQuerySurface
},
930 { "eglReleaseTexImage", (_EGLProc
) eglReleaseTexImage
},
931 { "eglReleaseThread", (_EGLProc
) eglReleaseThread
},
932 { "eglSurfaceAttrib", (_EGLProc
) eglSurfaceAttrib
},
933 { "eglSwapBuffers", (_EGLProc
) eglSwapBuffers
},
934 { "eglSwapInterval", (_EGLProc
) eglSwapInterval
},
935 { "eglTerminate", (_EGLProc
) eglTerminate
},
936 { "eglWaitClient", (_EGLProc
) eglWaitClient
},
937 { "eglWaitGL", (_EGLProc
) eglWaitGL
},
938 { "eglWaitNative", (_EGLProc
) eglWaitNative
},
939 #endif /* _EGL_GET_CORE_ADDRESSES */
940 #ifdef EGL_MESA_screen_surface
941 { "eglChooseModeMESA", (_EGLProc
) eglChooseModeMESA
},
942 { "eglGetModesMESA", (_EGLProc
) eglGetModesMESA
},
943 { "eglGetModeAttribMESA", (_EGLProc
) eglGetModeAttribMESA
},
944 { "eglCopyContextMESA", (_EGLProc
) eglCopyContextMESA
},
945 { "eglGetScreensMESA", (_EGLProc
) eglGetScreensMESA
},
946 { "eglCreateScreenSurfaceMESA", (_EGLProc
) eglCreateScreenSurfaceMESA
},
947 { "eglShowScreenSurfaceMESA", (_EGLProc
) eglShowScreenSurfaceMESA
},
948 { "eglScreenPositionMESA", (_EGLProc
) eglScreenPositionMESA
},
949 { "eglQueryScreenMESA", (_EGLProc
) eglQueryScreenMESA
},
950 { "eglQueryScreenSurfaceMESA", (_EGLProc
) eglQueryScreenSurfaceMESA
},
951 { "eglQueryScreenModeMESA", (_EGLProc
) eglQueryScreenModeMESA
},
952 { "eglQueryModeStringMESA", (_EGLProc
) eglQueryModeStringMESA
},
953 #endif /* EGL_MESA_screen_surface */
954 #ifdef EGL_MESA_drm_display
955 { "eglGetDRMDisplayMESA", (_EGLProc
) eglGetDRMDisplayMESA
},
957 { "eglCreateImageKHR", (_EGLProc
) eglCreateImageKHR
},
958 { "eglDestroyImageKHR", (_EGLProc
) eglDestroyImageKHR
},
959 { "eglCreateSyncKHR", (_EGLProc
) eglCreateSyncKHR
},
960 { "eglDestroySyncKHR", (_EGLProc
) eglDestroySyncKHR
},
961 { "eglClientWaitSyncKHR", (_EGLProc
) eglClientWaitSyncKHR
},
962 { "eglSignalSyncKHR", (_EGLProc
) eglSignalSyncKHR
},
963 { "eglGetSyncAttribKHR", (_EGLProc
) eglGetSyncAttribKHR
},
964 #ifdef EGL_NOK_swap_region
965 { "eglSwapBuffersRegionNOK", (_EGLProc
) eglSwapBuffersRegionNOK
},
967 #ifdef EGL_MESA_drm_image
968 { "eglCreateDRMImageMESA", (_EGLProc
) eglCreateDRMImageMESA
},
969 { "eglExportDRMImageMESA", (_EGLProc
) eglExportDRMImageMESA
},
971 #ifdef EGL_WL_bind_wayland_display
972 { "eglBindWaylandDisplayWL", (_EGLProc
) eglBindWaylandDisplayWL
},
973 { "eglUnbindWaylandDisplayWL", (_EGLProc
) eglUnbindWaylandDisplayWL
},
974 { "eglQueryWaylandBufferWL", (_EGLProc
) eglQueryWaylandBufferWL
},
976 #ifdef EGL_WL_create_wayland_buffer_from_image
977 { "eglCreateWaylandBufferFromImageWL", (_EGLProc
) eglCreateWaylandBufferFromImageWL
},
979 { "eglPostSubBufferNV", (_EGLProc
) eglPostSubBufferNV
},
980 #ifdef EGL_EXT_swap_buffers_with_damage
981 { "eglSwapBuffersWithDamageEXT", (_EGLProc
) eglSwapBuffersWithDamageEXT
},
989 RETURN_EGL_SUCCESS(NULL
, NULL
);
992 if (strncmp(procname
, "egl", 3) == 0) {
993 for (i
= 0; egl_functions
[i
].name
; i
++) {
994 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
995 ret
= egl_functions
[i
].function
;
1001 ret
= _eglGetDriverProc(procname
);
1003 RETURN_EGL_SUCCESS(NULL
, ret
);
1007 #ifdef EGL_MESA_screen_surface
1011 * EGL_MESA_screen extension
1014 EGLBoolean EGLAPIENTRY
1015 eglChooseModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1016 const EGLint
*attrib_list
, EGLModeMESA
*modes
,
1017 EGLint modes_size
, EGLint
*num_modes
)
1019 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1020 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1024 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1025 ret
= drv
->API
.ChooseModeMESA(drv
, disp
, scrn
, attrib_list
,
1026 modes
, modes_size
, num_modes
);
1028 RETURN_EGL_EVAL(disp
, ret
);
1032 EGLBoolean EGLAPIENTRY
1033 eglGetModesMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*modes
,
1034 EGLint mode_size
, EGLint
*num_mode
)
1036 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1037 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1041 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1042 ret
= drv
->API
.GetModesMESA(drv
, disp
, scrn
, modes
, mode_size
, num_mode
);
1044 RETURN_EGL_EVAL(disp
, ret
);
1048 EGLBoolean EGLAPIENTRY
1049 eglGetModeAttribMESA(EGLDisplay dpy
, EGLModeMESA mode
,
1050 EGLint attribute
, EGLint
*value
)
1052 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1053 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1057 _EGL_CHECK_MODE(disp
, m
, EGL_FALSE
, drv
);
1058 ret
= drv
->API
.GetModeAttribMESA(drv
, disp
, m
, attribute
, value
);
1060 RETURN_EGL_EVAL(disp
, ret
);
1064 EGLBoolean EGLAPIENTRY
1065 eglCopyContextMESA(EGLDisplay dpy
, EGLContext source
, EGLContext dest
,
1068 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1069 _EGLContext
*source_context
= _eglLookupContext(source
, disp
);
1070 _EGLContext
*dest_context
= _eglLookupContext(dest
, disp
);
1074 _EGL_CHECK_CONTEXT(disp
, source_context
, EGL_FALSE
, drv
);
1076 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
1078 ret
= drv
->API
.CopyContextMESA(drv
, disp
,
1079 source_context
, dest_context
, mask
);
1081 RETURN_EGL_EVAL(disp
, ret
);
1085 EGLBoolean EGLAPIENTRY
1086 eglGetScreensMESA(EGLDisplay dpy
, EGLScreenMESA
*screens
,
1087 EGLint max_screens
, EGLint
*num_screens
)
1089 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1093 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1094 ret
= drv
->API
.GetScreensMESA(drv
, disp
, screens
, max_screens
, num_screens
);
1096 RETURN_EGL_EVAL(disp
, ret
);
1100 EGLSurface EGLAPIENTRY
1101 eglCreateScreenSurfaceMESA(EGLDisplay dpy
, EGLConfig config
,
1102 const EGLint
*attrib_list
)
1104 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1105 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1110 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1112 surf
= drv
->API
.CreateScreenSurfaceMESA(drv
, disp
, conf
, attrib_list
);
1113 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1115 RETURN_EGL_EVAL(disp
, ret
);
1119 EGLBoolean EGLAPIENTRY
1120 eglShowScreenSurfaceMESA(EGLDisplay dpy
, EGLint screen
,
1121 EGLSurface surface
, EGLModeMESA mode
)
1123 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1124 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1125 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1126 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1130 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1131 if (!surf
&& surface
!= EGL_NO_SURFACE
)
1132 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1133 if (!m
&& mode
!= EGL_NO_MODE_MESA
)
1134 RETURN_EGL_ERROR(disp
, EGL_BAD_MODE_MESA
, EGL_FALSE
);
1136 ret
= drv
->API
.ShowScreenSurfaceMESA(drv
, disp
, scrn
, surf
, m
);
1138 RETURN_EGL_EVAL(disp
, ret
);
1142 EGLBoolean EGLAPIENTRY
1143 eglScreenPositionMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLint x
, EGLint y
)
1145 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1146 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1150 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1151 ret
= drv
->API
.ScreenPositionMESA(drv
, disp
, scrn
, x
, y
);
1153 RETURN_EGL_EVAL(disp
, ret
);
1157 EGLBoolean EGLAPIENTRY
1158 eglQueryScreenMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1159 EGLint attribute
, EGLint
*value
)
1161 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1162 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1166 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1167 ret
= drv
->API
.QueryScreenMESA(drv
, disp
, scrn
, attribute
, value
);
1169 RETURN_EGL_EVAL(disp
, ret
);
1173 EGLBoolean EGLAPIENTRY
1174 eglQueryScreenSurfaceMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1175 EGLSurface
*surface
)
1177 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1178 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1183 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1184 ret
= drv
->API
.QueryScreenSurfaceMESA(drv
, disp
, scrn
, &surf
);
1186 *surface
= _eglGetSurfaceHandle(surf
);
1188 RETURN_EGL_EVAL(disp
, ret
);
1192 EGLBoolean EGLAPIENTRY
1193 eglQueryScreenModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*mode
)
1195 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1196 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1201 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1202 ret
= drv
->API
.QueryScreenModeMESA(drv
, disp
, scrn
, &m
);
1206 RETURN_EGL_EVAL(disp
, ret
);
1210 const char * EGLAPIENTRY
1211 eglQueryModeStringMESA(EGLDisplay dpy
, EGLModeMESA mode
)
1213 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1214 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1218 _EGL_CHECK_MODE(disp
, m
, NULL
, drv
);
1219 ret
= drv
->API
.QueryModeStringMESA(drv
, disp
, m
);
1221 RETURN_EGL_EVAL(disp
, ret
);
1225 #endif /* EGL_MESA_screen_surface */
1228 #ifdef EGL_MESA_drm_display
1230 EGLDisplay EGLAPIENTRY
1231 eglGetDRMDisplayMESA(int fd
)
1233 _EGLDisplay
*dpy
= _eglFindDisplay(_EGL_PLATFORM_DRM
, (void *) (intptr_t) fd
);
1234 return _eglGetDisplayHandle(dpy
);
1237 #endif /* EGL_MESA_drm_display */
1244 * Specify the client API to use for subsequent calls including:
1245 * eglCreateContext()
1246 * eglGetCurrentContext()
1247 * eglGetCurrentDisplay()
1248 * eglGetCurrentSurface()
1249 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1252 * See section 3.7 "Rendering Context" in the EGL specification for details.
1254 EGLBoolean EGLAPIENTRY
1255 eglBindAPI(EGLenum api
)
1257 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1259 if (_eglIsCurrentThreadDummy())
1260 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1262 if (!_eglIsApiValid(api
))
1263 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1265 t
->CurrentAPIIndex
= _eglConvertApiToIndex(api
);
1267 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1272 * Return the last value set with eglBindAPI().
1277 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1280 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1281 ret
= _eglConvertApiFromIndex(t
->CurrentAPIIndex
);
1283 RETURN_EGL_SUCCESS(NULL
, ret
);
1287 EGLSurface EGLAPIENTRY
1288 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1289 EGLClientBuffer buffer
, EGLConfig config
,
1290 const EGLint
*attrib_list
)
1292 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1293 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1298 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1300 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1302 ret
= (surf
) ? _eglLinkSurface(surf
) : EGL_NO_SURFACE
;
1304 RETURN_EGL_EVAL(disp
, ret
);
1308 EGLBoolean EGLAPIENTRY
1309 eglReleaseThread(void)
1311 /* unbind current contexts */
1312 if (!_eglIsCurrentThreadDummy()) {
1313 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1314 EGLint api_index
= t
->CurrentAPIIndex
;
1317 for (i
= 0; i
< _EGL_API_NUM_APIS
; i
++) {
1318 _EGLContext
*ctx
= t
->CurrentContexts
[i
];
1320 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1323 t
->CurrentAPIIndex
= i
;
1325 _eglLockMutex(&disp
->Mutex
);
1327 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1328 _eglUnlockMutex(&disp
->Mutex
);
1332 t
->CurrentAPIIndex
= api_index
;
1335 _eglDestroyCurrentThread();
1337 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1341 EGLImageKHR EGLAPIENTRY
1342 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1343 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1345 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1346 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1351 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1352 if (!disp
->Extensions
.KHR_image_base
)
1353 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1354 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1355 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1356 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1357 * <ctx> must be EGL_NO_CONTEXT..."
1359 if (ctx
!= EGL_NO_CONTEXT
&& target
== EGL_LINUX_DMA_BUF_EXT
)
1360 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_NO_IMAGE_KHR
);
1362 img
= drv
->API
.CreateImageKHR(drv
,
1363 disp
, context
, target
, buffer
, attr_list
);
1364 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1366 RETURN_EGL_EVAL(disp
, ret
);
1370 EGLBoolean EGLAPIENTRY
1371 eglDestroyImageKHR(EGLDisplay dpy
, EGLImageKHR image
)
1373 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1374 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1378 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1379 if (!disp
->Extensions
.KHR_image_base
)
1380 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1382 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1384 _eglUnlinkImage(img
);
1385 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1387 RETURN_EGL_EVAL(disp
, ret
);
1391 EGLSyncKHR EGLAPIENTRY
1392 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*attrib_list
)
1394 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1399 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1400 if (!disp
->Extensions
.KHR_reusable_sync
)
1401 RETURN_EGL_EVAL(disp
, EGL_NO_SYNC_KHR
);
1403 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1404 ret
= (sync
) ? _eglLinkSync(sync
) : EGL_NO_SYNC_KHR
;
1406 RETURN_EGL_EVAL(disp
, ret
);
1410 EGLBoolean EGLAPIENTRY
1411 eglDestroySyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
)
1413 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1414 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1418 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1419 assert(disp
->Extensions
.KHR_reusable_sync
);
1422 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1424 RETURN_EGL_EVAL(disp
, ret
);
1429 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLint flags
, EGLTimeKHR timeout
)
1431 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1432 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1436 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1437 assert(disp
->Extensions
.KHR_reusable_sync
);
1438 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1440 RETURN_EGL_EVAL(disp
, ret
);
1444 EGLBoolean EGLAPIENTRY
1445 eglSignalSyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLenum mode
)
1447 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1448 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1452 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1453 assert(disp
->Extensions
.KHR_reusable_sync
);
1454 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
1456 RETURN_EGL_EVAL(disp
, ret
);
1460 EGLBoolean EGLAPIENTRY
1461 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLint attribute
, EGLint
*value
)
1463 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1464 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1468 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1469 assert(disp
->Extensions
.KHR_reusable_sync
);
1470 ret
= drv
->API
.GetSyncAttribKHR(drv
, disp
, s
, attribute
, value
);
1472 RETURN_EGL_EVAL(disp
, ret
);
1476 #ifdef EGL_NOK_swap_region
1478 EGLBoolean EGLAPIENTRY
1479 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
1480 EGLint numRects
, const EGLint
*rects
)
1482 _EGLContext
*ctx
= _eglGetCurrentContext();
1483 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1484 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1488 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1490 if (!disp
->Extensions
.NOK_swap_region
)
1491 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1493 /* surface must be bound to current context in EGL 1.4 */
1494 if (_eglGetContextHandle(ctx
) == EGL_NO_CONTEXT
||
1495 surf
!= ctx
->DrawSurface
)
1496 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1498 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
1500 RETURN_EGL_EVAL(disp
, ret
);
1503 #endif /* EGL_NOK_swap_region */
1506 #ifdef EGL_MESA_drm_image
1508 EGLImageKHR EGLAPIENTRY
1509 eglCreateDRMImageMESA(EGLDisplay dpy
, const EGLint
*attr_list
)
1511 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1516 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1517 if (!disp
->Extensions
.MESA_drm_image
)
1518 RETURN_EGL_EVAL(disp
, EGL_NO_IMAGE_KHR
);
1520 img
= drv
->API
.CreateDRMImageMESA(drv
, disp
, attr_list
);
1521 ret
= (img
) ? _eglLinkImage(img
) : EGL_NO_IMAGE_KHR
;
1523 RETURN_EGL_EVAL(disp
, ret
);
1526 EGLBoolean EGLAPIENTRY
1527 eglExportDRMImageMESA(EGLDisplay dpy
, EGLImageKHR image
,
1528 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
1530 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1531 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1535 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1536 assert(disp
->Extensions
.MESA_drm_image
);
1539 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1541 ret
= drv
->API
.ExportDRMImageMESA(drv
, disp
, img
, name
, handle
, stride
);
1543 RETURN_EGL_EVAL(disp
, ret
);
1548 #ifdef EGL_WL_bind_wayland_display
1551 EGLBoolean EGLAPIENTRY
1552 eglBindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1554 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1558 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1559 assert(disp
->Extensions
.WL_bind_wayland_display
);
1562 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1564 ret
= drv
->API
.BindWaylandDisplayWL(drv
, disp
, display
);
1566 RETURN_EGL_EVAL(disp
, ret
);
1569 EGLBoolean EGLAPIENTRY
1570 eglUnbindWaylandDisplayWL(EGLDisplay dpy
, struct wl_display
*display
)
1572 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1576 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1577 assert(disp
->Extensions
.WL_bind_wayland_display
);
1580 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1582 ret
= drv
->API
.UnbindWaylandDisplayWL(drv
, disp
, display
);
1584 RETURN_EGL_EVAL(disp
, ret
);
1587 EGLBoolean EGLAPIENTRY
1588 eglQueryWaylandBufferWL(EGLDisplay dpy
, struct wl_resource
*buffer
,
1589 EGLint attribute
, EGLint
*value
)
1591 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1595 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1596 assert(disp
->Extensions
.WL_bind_wayland_display
);
1599 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1601 ret
= drv
->API
.QueryWaylandBufferWL(drv
, disp
, buffer
, attribute
, value
);
1603 RETURN_EGL_EVAL(disp
, ret
);
1607 #ifdef EGL_WL_create_wayland_buffer_from_image
1608 struct wl_buffer
* EGLAPIENTRY
1609 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy
, EGLImageKHR image
)
1611 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1614 struct wl_buffer
*ret
;
1616 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
1617 assert(disp
->Extensions
.WL_create_wayland_buffer_from_image
);
1619 img
= _eglLookupImage(image
, disp
);
1622 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, NULL
);
1624 ret
= drv
->API
.CreateWaylandBufferFromImageWL(drv
, disp
, img
);
1626 RETURN_EGL_EVAL(disp
, ret
);
1630 EGLBoolean EGLAPIENTRY
1631 eglPostSubBufferNV(EGLDisplay dpy
, EGLSurface surface
,
1632 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
1634 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1635 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1639 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1641 if (!disp
->Extensions
.NV_post_sub_buffer
)
1642 RETURN_EGL_EVAL(disp
, EGL_FALSE
);
1644 ret
= drv
->API
.PostSubBufferNV(drv
, disp
, surf
, x
, y
, width
, height
);
1646 RETURN_EGL_EVAL(disp
, ret
);