2 * Public EGL API entrypoints
4 * Generally, we use the EGLDisplay parameter as a key to lookup the
5 * appropriate device driver handle, then jump though the driver's
6 * dispatch table to handle the function.
8 * That allows us the option of supporting multiple, simultaneous,
9 * heterogeneous hardware devices in the future.
11 * The EGLDisplay, EGLConfig, EGLContext and EGLSurface types are
12 * opaque handles. Internal objects are linked to a display to
15 * For each public API entry point, the opaque handles are looked up
16 * before being dispatched to the drivers. When it fails to look up
26 * is generated and the driver function is not called. An
27 * uninitialized EGLDisplay has no driver associated with it. When
28 * such display is detected,
34 * Some of the entry points use current display, context, or surface
35 * implicitly. For such entry points, the implicit objects are also
36 * checked before calling the driver function. Other than the
37 * errors listed above,
39 * EGL_BAD_CURRENT_SURFACE
41 * may also be generated.
43 * Notes on naming conventions:
45 * eglFooBar - public EGL function
46 * EGL_FOO_BAR - public EGL token
47 * EGLDatatype - public EGL datatype
49 * _eglFooBar - private EGL function
50 * _EGLDatatype - private EGL datatype, typedef'd struct
51 * _egl_struct - private EGL struct, non-typedef'd
60 #include "eglstring.h"
61 #include "eglcontext.h"
62 #include "egldisplay.h"
63 #include "egltypedefs.h"
64 #include "eglcurrent.h"
65 #include "egldriver.h"
66 #include "eglsurface.h"
67 #include "eglconfig.h"
68 #include "eglscreen.h"
75 * Macros to help return an API entrypoint.
77 * These macros will unlock the display and record the error code.
79 #define RETURN_EGL_ERROR(disp, err, ret) \
82 _eglUnlockDisplay(disp); \
83 /* EGL error codes are non-zero */ \
85 _eglError(err, __FUNCTION__); \
89 #define RETURN_EGL_SUCCESS(disp, ret) \
90 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
92 /* record EGL_SUCCESS only when ret evaluates to true */
93 #define RETURN_EGL_EVAL(disp, ret) \
94 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
98 * A bunch of macros and checks to simplify error checking.
101 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
103 drv = _eglCheckDisplay(disp, __FUNCTION__); \
105 RETURN_EGL_ERROR(disp, 0, ret); \
108 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
110 drv = _eglCheck ## type(disp, obj, __FUNCTION__); \
112 RETURN_EGL_ERROR(disp, 0, ret); \
115 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
116 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
118 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
119 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
121 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
122 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
124 #define _EGL_CHECK_SCREEN(disp, scrn, ret, drv) \
125 _EGL_CHECK_OBJECT(disp, Screen, scrn, ret, drv)
127 #define _EGL_CHECK_MODE(disp, m, ret, drv) \
128 _EGL_CHECK_OBJECT(disp, Mode, m, ret, drv)
130 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
131 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
134 static INLINE _EGLDriver
*
135 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
138 _eglError(EGL_BAD_DISPLAY
, msg
);
141 if (!disp
->Initialized
) {
142 _eglError(EGL_NOT_INITIALIZED
, msg
);
149 static INLINE _EGLDriver
*
150 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
152 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
156 _eglError(EGL_BAD_SURFACE
, msg
);
163 static INLINE _EGLDriver
*
164 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
166 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
170 _eglError(EGL_BAD_CONTEXT
, msg
);
177 static INLINE _EGLDriver
*
178 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
180 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
184 _eglError(EGL_BAD_CONFIG
, msg
);
191 #ifdef EGL_KHR_reusable_sync
194 static INLINE _EGLDriver
*
195 _eglCheckSync(_EGLDisplay
*disp
, _EGLSync
*s
, const char *msg
)
197 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
201 _eglError(EGL_BAD_PARAMETER
, msg
);
208 #endif /* EGL_KHR_reusable_sync */
211 #ifdef EGL_MESA_screen_surface
214 static INLINE _EGLDriver
*
215 _eglCheckScreen(_EGLDisplay
*disp
, _EGLScreen
*scrn
, const char *msg
)
217 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
221 _eglError(EGL_BAD_SCREEN_MESA
, msg
);
228 static INLINE _EGLDriver
*
229 _eglCheckMode(_EGLDisplay
*disp
, _EGLMode
*m
, const char *msg
)
231 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
235 _eglError(EGL_BAD_MODE_MESA
, msg
);
242 #endif /* EGL_MESA_screen_surface */
246 * Lookup and lock a display.
248 static INLINE _EGLDisplay
*
249 _eglLockDisplay(EGLDisplay display
)
251 _EGLDisplay
*dpy
= _eglLookupDisplay(display
);
253 _eglLockMutex(&dpy
->Mutex
);
262 _eglUnlockDisplay(_EGLDisplay
*dpy
)
264 _eglUnlockMutex(&dpy
->Mutex
);
269 * This is typically the first EGL function that an application calls.
270 * It associates a private _EGLDisplay object to the native display.
272 EGLDisplay EGLAPIENTRY
273 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
275 _EGLPlatformType plat
= _eglGetNativePlatform();
276 _EGLDisplay
*dpy
= _eglFindDisplay(plat
, (void *) nativeDisplay
);
277 return _eglGetDisplayHandle(dpy
);
282 * This is typically the second EGL function that an application calls.
283 * Here we load/initialize the actual hardware driver.
285 EGLBoolean EGLAPIENTRY
286 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
288 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
291 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
293 if (!disp
->Initialized
) {
294 if (!_eglMatchDriver(disp
, EGL_FALSE
))
295 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
297 _eglsnprintf(disp
->Version
, sizeof(disp
->Version
), "%d.%d (%s)",
298 disp
->APImajor
, disp
->APIminor
, disp
->Driver
->Name
);
299 /* limit to APIs supported by core */
300 disp
->ClientAPIsMask
&= _EGL_API_ALL_BITS
;
303 /* Update applications version of major and minor if not NULL */
304 if ((major
!= NULL
) && (minor
!= NULL
)) {
305 *major
= disp
->APImajor
;
306 *minor
= disp
->APIminor
;
309 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
313 EGLBoolean EGLAPIENTRY
314 eglTerminate(EGLDisplay dpy
)
316 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
319 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
321 if (disp
->Initialized
) {
322 _EGLDriver
*drv
= disp
->Driver
;
324 drv
->API
.Terminate(drv
, disp
);
325 /* do not reset disp->Driver */
326 disp
->Initialized
= EGL_FALSE
;
329 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
333 const char * EGLAPIENTRY
334 eglQueryString(EGLDisplay dpy
, EGLint name
)
336 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
340 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
341 ret
= drv
->API
.QueryString(drv
, disp
, name
);
343 RETURN_EGL_EVAL(disp
, ret
);
347 EGLBoolean EGLAPIENTRY
348 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
349 EGLint config_size
, EGLint
*num_config
)
351 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
355 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
356 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
358 RETURN_EGL_EVAL(disp
, ret
);
362 EGLBoolean EGLAPIENTRY
363 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
364 EGLint config_size
, EGLint
*num_config
)
366 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
370 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
371 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
372 config_size
, num_config
);
374 RETURN_EGL_EVAL(disp
, ret
);
378 EGLBoolean EGLAPIENTRY
379 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
380 EGLint attribute
, EGLint
*value
)
382 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
383 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
387 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
388 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
390 RETURN_EGL_EVAL(disp
, ret
);
394 EGLContext EGLAPIENTRY
395 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
396 const EGLint
*attrib_list
)
398 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
399 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
400 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
402 _EGLContext
*context
;
406 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
408 drv
= _eglCheckDisplay(disp
, __FUNCTION__
);
410 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
411 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
413 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
414 ret
= (context
) ? _eglLinkContext(context
, disp
) : EGL_NO_CONTEXT
;
416 RETURN_EGL_EVAL(disp
, ret
);
420 EGLBoolean EGLAPIENTRY
421 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
423 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
424 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
428 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
429 _eglUnlinkContext(context
);
430 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
432 RETURN_EGL_EVAL(disp
, ret
);
436 EGLBoolean EGLAPIENTRY
437 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
440 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
441 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
442 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
443 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
448 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
451 /* display is allowed to be uninitialized under certain condition */
452 if (!disp
->Initialized
) {
453 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
454 ctx
!= EGL_NO_CONTEXT
)
455 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
458 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
460 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
461 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
462 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
463 (!read_surf
&& read
!= EGL_NO_SURFACE
))
464 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
466 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
468 RETURN_EGL_EVAL(disp
, ret
);
472 EGLBoolean EGLAPIENTRY
473 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
474 EGLint attribute
, EGLint
*value
)
476 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
477 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
481 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
482 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
484 RETURN_EGL_EVAL(disp
, ret
);
488 EGLSurface EGLAPIENTRY
489 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
490 EGLNativeWindowType window
, const EGLint
*attrib_list
)
492 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
493 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
498 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
499 if (disp
->Platform
!= _eglGetNativePlatform())
500 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
502 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, window
, attrib_list
);
503 ret
= (surf
) ? _eglLinkSurface(surf
, disp
) : EGL_NO_SURFACE
;
505 RETURN_EGL_EVAL(disp
, ret
);
509 EGLSurface EGLAPIENTRY
510 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
511 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
513 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
514 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
519 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
520 if (disp
->Platform
!= _eglGetNativePlatform())
521 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
523 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, pixmap
, attrib_list
);
524 ret
= (surf
) ? _eglLinkSurface(surf
, disp
) : EGL_NO_SURFACE
;
526 RETURN_EGL_EVAL(disp
, ret
);
530 EGLSurface EGLAPIENTRY
531 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
532 const EGLint
*attrib_list
)
534 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
535 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
540 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
542 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
543 ret
= (surf
) ? _eglLinkSurface(surf
, disp
) : EGL_NO_SURFACE
;
545 RETURN_EGL_EVAL(disp
, ret
);
549 EGLBoolean EGLAPIENTRY
550 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
552 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
553 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
557 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
558 _eglUnlinkSurface(surf
);
559 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
561 RETURN_EGL_EVAL(disp
, ret
);
564 EGLBoolean EGLAPIENTRY
565 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
566 EGLint attribute
, EGLint
*value
)
568 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
569 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
573 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
574 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
576 RETURN_EGL_EVAL(disp
, ret
);
579 EGLBoolean EGLAPIENTRY
580 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
581 EGLint attribute
, EGLint value
)
583 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
584 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
588 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
589 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
591 RETURN_EGL_EVAL(disp
, ret
);
595 EGLBoolean EGLAPIENTRY
596 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
598 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
599 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
603 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
604 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
606 RETURN_EGL_EVAL(disp
, ret
);
610 EGLBoolean EGLAPIENTRY
611 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
613 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
614 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
618 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
619 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
621 RETURN_EGL_EVAL(disp
, ret
);
625 EGLBoolean EGLAPIENTRY
626 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
628 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
629 _EGLContext
*ctx
= _eglGetCurrentContext();
634 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
636 if (!ctx
|| !_eglIsContextLinked(ctx
) || ctx
->Resource
.Display
!= disp
)
637 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
639 surf
= ctx
->DrawSurface
;
640 if (!_eglIsSurfaceLinked(surf
))
641 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
643 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
645 RETURN_EGL_EVAL(disp
, ret
);
649 EGLBoolean EGLAPIENTRY
650 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
652 _EGLContext
*ctx
= _eglGetCurrentContext();
653 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
654 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
658 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
660 /* surface must be bound to current context in EGL 1.4 */
661 if (!ctx
|| !_eglIsContextLinked(ctx
) || surf
!= ctx
->DrawSurface
)
662 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
664 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
666 RETURN_EGL_EVAL(disp
, ret
);
670 EGLBoolean EGLAPIENTRY
671 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
673 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
674 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
678 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
679 if (disp
->Platform
!= _eglGetNativePlatform())
680 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
681 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, target
);
683 RETURN_EGL_EVAL(disp
, ret
);
687 EGLBoolean EGLAPIENTRY
690 _EGLContext
*ctx
= _eglGetCurrentContext();
696 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
698 disp
= ctx
->Resource
.Display
;
699 _eglLockMutex(&disp
->Mutex
);
701 /* let bad current context imply bad current surface */
702 if (!_eglIsContextLinked(ctx
) || !_eglIsSurfaceLinked(ctx
->DrawSurface
))
703 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
705 /* a valid current context implies an initialized current display */
706 assert(disp
->Initialized
);
708 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
710 RETURN_EGL_EVAL(disp
, ret
);
714 EGLBoolean EGLAPIENTRY
717 #ifdef EGL_VERSION_1_2
718 _EGLThreadInfo
*t
= _eglGetCurrentThread();
719 EGLint api_index
= t
->CurrentAPIIndex
;
720 EGLint es_index
= _eglConvertApiToIndex(EGL_OPENGL_ES_API
);
723 if (api_index
!= es_index
&& _eglIsCurrentThreadDummy())
724 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
726 t
->CurrentAPIIndex
= es_index
;
727 ret
= eglWaitClient();
728 t
->CurrentAPIIndex
= api_index
;
731 return eglWaitClient();
736 EGLBoolean EGLAPIENTRY
737 eglWaitNative(EGLint engine
)
739 _EGLContext
*ctx
= _eglGetCurrentContext();
745 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
747 disp
= ctx
->Resource
.Display
;
748 _eglLockMutex(&disp
->Mutex
);
750 /* let bad current context imply bad current surface */
751 if (!_eglIsContextLinked(ctx
) || !_eglIsSurfaceLinked(ctx
->DrawSurface
))
752 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
754 /* a valid current context implies an initialized current display */
755 assert(disp
->Initialized
);
757 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
759 RETURN_EGL_EVAL(disp
, ret
);
763 EGLDisplay EGLAPIENTRY
764 eglGetCurrentDisplay(void)
766 _EGLContext
*ctx
= _eglGetCurrentContext();
769 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
771 RETURN_EGL_SUCCESS(NULL
, ret
);
775 EGLContext EGLAPIENTRY
776 eglGetCurrentContext(void)
778 _EGLContext
*ctx
= _eglGetCurrentContext();
781 ret
= _eglGetContextHandle(ctx
);
783 RETURN_EGL_SUCCESS(NULL
, ret
);
787 EGLSurface EGLAPIENTRY
788 eglGetCurrentSurface(EGLint readdraw
)
790 _EGLContext
*ctx
= _eglGetCurrentContext();
791 EGLint err
= EGL_SUCCESS
;
796 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
800 surf
= ctx
->DrawSurface
;
803 surf
= ctx
->ReadSurface
;
807 err
= EGL_BAD_PARAMETER
;
811 ret
= _eglGetSurfaceHandle(surf
);
813 RETURN_EGL_ERROR(NULL
, err
, ret
);
820 _EGLThreadInfo
*t
= _eglGetCurrentThread();
821 EGLint e
= t
->LastError
;
822 if (!_eglIsCurrentThreadDummy())
823 t
->LastError
= EGL_SUCCESS
;
828 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
829 eglGetProcAddress(const char *procname
)
831 static const struct {
834 } egl_functions
[] = {
835 /* extensions only */
836 #ifdef EGL_MESA_screen_surface
837 { "eglChooseModeMESA", (_EGLProc
) eglChooseModeMESA
},
838 { "eglGetModesMESA", (_EGLProc
) eglGetModesMESA
},
839 { "eglGetModeAttribMESA", (_EGLProc
) eglGetModeAttribMESA
},
840 { "eglCopyContextMESA", (_EGLProc
) eglCopyContextMESA
},
841 { "eglGetScreensMESA", (_EGLProc
) eglGetScreensMESA
},
842 { "eglCreateScreenSurfaceMESA", (_EGLProc
) eglCreateScreenSurfaceMESA
},
843 { "eglShowScreenSurfaceMESA", (_EGLProc
) eglShowScreenSurfaceMESA
},
844 { "eglScreenPositionMESA", (_EGLProc
) eglScreenPositionMESA
},
845 { "eglQueryScreenMESA", (_EGLProc
) eglQueryScreenMESA
},
846 { "eglQueryScreenSurfaceMESA", (_EGLProc
) eglQueryScreenSurfaceMESA
},
847 { "eglQueryScreenModeMESA", (_EGLProc
) eglQueryScreenModeMESA
},
848 { "eglQueryModeStringMESA", (_EGLProc
) eglQueryModeStringMESA
},
849 #endif /* EGL_MESA_screen_surface */
850 #ifdef EGL_MESA_drm_display
851 { "eglGetDRMDisplayMESA", (_EGLProc
) eglGetDRMDisplayMESA
},
853 #ifdef EGL_KHR_image_base
854 { "eglCreateImageKHR", (_EGLProc
) eglCreateImageKHR
},
855 { "eglDestroyImageKHR", (_EGLProc
) eglDestroyImageKHR
},
856 #endif /* EGL_KHR_image_base */
857 #ifdef EGL_NOK_swap_region
858 { "eglSwapBuffersRegionNOK", (_EGLProc
) eglSwapBuffersRegionNOK
},
866 RETURN_EGL_SUCCESS(NULL
, NULL
);
869 if (strncmp(procname
, "egl", 3) == 0) {
870 for (i
= 0; egl_functions
[i
].name
; i
++) {
871 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
872 ret
= egl_functions
[i
].function
;
878 ret
= _eglGetDriverProc(procname
);
880 RETURN_EGL_SUCCESS(NULL
, ret
);
884 #ifdef EGL_MESA_screen_surface
888 * EGL_MESA_screen extension
891 EGLBoolean EGLAPIENTRY
892 eglChooseModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
893 const EGLint
*attrib_list
, EGLModeMESA
*modes
,
894 EGLint modes_size
, EGLint
*num_modes
)
896 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
897 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
901 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
902 ret
= drv
->API
.ChooseModeMESA(drv
, disp
, scrn
, attrib_list
,
903 modes
, modes_size
, num_modes
);
905 RETURN_EGL_EVAL(disp
, ret
);
909 EGLBoolean EGLAPIENTRY
910 eglGetModesMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*modes
,
911 EGLint mode_size
, EGLint
*num_mode
)
913 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
914 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
918 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
919 ret
= drv
->API
.GetModesMESA(drv
, disp
, scrn
, modes
, mode_size
, num_mode
);
921 RETURN_EGL_EVAL(disp
, ret
);
925 EGLBoolean EGLAPIENTRY
926 eglGetModeAttribMESA(EGLDisplay dpy
, EGLModeMESA mode
,
927 EGLint attribute
, EGLint
*value
)
929 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
930 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
934 _EGL_CHECK_MODE(disp
, m
, EGL_FALSE
, drv
);
935 ret
= drv
->API
.GetModeAttribMESA(drv
, disp
, m
, attribute
, value
);
937 RETURN_EGL_EVAL(disp
, ret
);
941 EGLBoolean EGLAPIENTRY
942 eglCopyContextMESA(EGLDisplay dpy
, EGLContext source
, EGLContext dest
,
945 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
946 _EGLContext
*source_context
= _eglLookupContext(source
, disp
);
947 _EGLContext
*dest_context
= _eglLookupContext(dest
, disp
);
951 _EGL_CHECK_CONTEXT(disp
, source_context
, EGL_FALSE
, drv
);
953 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
955 ret
= drv
->API
.CopyContextMESA(drv
, disp
,
956 source_context
, dest_context
, mask
);
958 RETURN_EGL_EVAL(disp
, ret
);
962 EGLBoolean EGLAPIENTRY
963 eglGetScreensMESA(EGLDisplay dpy
, EGLScreenMESA
*screens
,
964 EGLint max_screens
, EGLint
*num_screens
)
966 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
970 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
971 ret
= drv
->API
.GetScreensMESA(drv
, disp
, screens
, max_screens
, num_screens
);
973 RETURN_EGL_EVAL(disp
, ret
);
977 EGLSurface EGLAPIENTRY
978 eglCreateScreenSurfaceMESA(EGLDisplay dpy
, EGLConfig config
,
979 const EGLint
*attrib_list
)
981 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
982 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
987 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
989 surf
= drv
->API
.CreateScreenSurfaceMESA(drv
, disp
, conf
, attrib_list
);
990 ret
= (surf
) ? _eglLinkSurface(surf
, disp
) : EGL_NO_SURFACE
;
992 RETURN_EGL_EVAL(disp
, ret
);
996 EGLBoolean EGLAPIENTRY
997 eglShowScreenSurfaceMESA(EGLDisplay dpy
, EGLint screen
,
998 EGLSurface surface
, EGLModeMESA mode
)
1000 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1001 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1002 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1003 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1007 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1008 if (!surf
&& surface
!= EGL_NO_SURFACE
)
1009 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1010 if (!m
&& mode
!= EGL_NO_MODE_MESA
)
1011 RETURN_EGL_ERROR(disp
, EGL_BAD_MODE_MESA
, EGL_FALSE
);
1013 ret
= drv
->API
.ShowScreenSurfaceMESA(drv
, disp
, scrn
, surf
, m
);
1015 RETURN_EGL_EVAL(disp
, ret
);
1019 EGLBoolean EGLAPIENTRY
1020 eglScreenPositionMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLint x
, EGLint y
)
1022 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1023 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1027 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1028 ret
= drv
->API
.ScreenPositionMESA(drv
, disp
, scrn
, x
, y
);
1030 RETURN_EGL_EVAL(disp
, ret
);
1034 EGLBoolean EGLAPIENTRY
1035 eglQueryScreenMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1036 EGLint attribute
, EGLint
*value
)
1038 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1039 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1043 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1044 ret
= drv
->API
.QueryScreenMESA(drv
, disp
, scrn
, attribute
, value
);
1046 RETURN_EGL_EVAL(disp
, ret
);
1050 EGLBoolean EGLAPIENTRY
1051 eglQueryScreenSurfaceMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1052 EGLSurface
*surface
)
1054 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1055 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1060 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1061 ret
= drv
->API
.QueryScreenSurfaceMESA(drv
, disp
, scrn
, &surf
);
1063 *surface
= _eglGetSurfaceHandle(surf
);
1065 RETURN_EGL_EVAL(disp
, ret
);
1069 EGLBoolean EGLAPIENTRY
1070 eglQueryScreenModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*mode
)
1072 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1073 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1078 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1079 ret
= drv
->API
.QueryScreenModeMESA(drv
, disp
, scrn
, &m
);
1083 RETURN_EGL_EVAL(disp
, ret
);
1087 const char * EGLAPIENTRY
1088 eglQueryModeStringMESA(EGLDisplay dpy
, EGLModeMESA mode
)
1090 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1091 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1095 _EGL_CHECK_MODE(disp
, m
, NULL
, drv
);
1096 ret
= drv
->API
.QueryModeStringMESA(drv
, disp
, m
);
1098 RETURN_EGL_EVAL(disp
, ret
);
1102 #endif /* EGL_MESA_screen_surface */
1105 #ifdef EGL_MESA_drm_display
1107 EGLDisplay EGLAPIENTRY
1108 eglGetDRMDisplayMESA(int fd
)
1110 _EGLDisplay
*dpy
= _eglFindDisplay(_EGL_PLATFORM_DRM
, (void *) fd
);
1111 return _eglGetDisplayHandle(dpy
);
1114 #endif /* EGL_MESA_drm_display */
1120 #ifdef EGL_VERSION_1_2
1124 * Specify the client API to use for subsequent calls including:
1125 * eglCreateContext()
1126 * eglGetCurrentContext()
1127 * eglGetCurrentDisplay()
1128 * eglGetCurrentSurface()
1129 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1132 * See section 3.7 "Rendering Context" in the EGL specification for details.
1134 EGLBoolean EGLAPIENTRY
1135 eglBindAPI(EGLenum api
)
1137 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1139 if (_eglIsCurrentThreadDummy())
1140 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1142 if (!_eglIsApiValid(api
))
1143 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1145 t
->CurrentAPIIndex
= _eglConvertApiToIndex(api
);
1147 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1152 * Return the last value set with eglBindAPI().
1157 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1160 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1161 ret
= _eglConvertApiFromIndex(t
->CurrentAPIIndex
);
1163 RETURN_EGL_SUCCESS(NULL
, ret
);
1167 EGLSurface EGLAPIENTRY
1168 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1169 EGLClientBuffer buffer
, EGLConfig config
,
1170 const EGLint
*attrib_list
)
1172 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1173 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1178 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1180 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1182 ret
= (surf
) ? _eglLinkSurface(surf
, disp
) : EGL_NO_SURFACE
;
1184 RETURN_EGL_EVAL(disp
, ret
);
1188 EGLBoolean EGLAPIENTRY
1189 eglReleaseThread(void)
1191 /* unbind current contexts */
1192 if (!_eglIsCurrentThreadDummy()) {
1193 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1194 EGLint api_index
= t
->CurrentAPIIndex
;
1197 for (i
= 0; i
< _EGL_API_NUM_APIS
; i
++) {
1198 _EGLContext
*ctx
= t
->CurrentContexts
[i
];
1200 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1203 t
->CurrentAPIIndex
= i
;
1205 _eglLockMutex(&disp
->Mutex
);
1207 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1208 _eglUnlockMutex(&disp
->Mutex
);
1212 t
->CurrentAPIIndex
= api_index
;
1215 _eglDestroyCurrentThread();
1217 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1221 #endif /* EGL_VERSION_1_2 */
1224 #ifdef EGL_KHR_image_base
1227 EGLImageKHR EGLAPIENTRY
1228 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1229 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1231 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1232 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1237 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1238 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1239 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1241 img
= drv
->API
.CreateImageKHR(drv
,
1242 disp
, context
, target
, buffer
, attr_list
);
1243 ret
= (img
) ? _eglLinkImage(img
, disp
) : EGL_NO_IMAGE_KHR
;
1245 RETURN_EGL_EVAL(disp
, ret
);
1249 EGLBoolean EGLAPIENTRY
1250 eglDestroyImageKHR(EGLDisplay dpy
, EGLImageKHR image
)
1252 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1253 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1257 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1259 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1261 _eglUnlinkImage(img
);
1262 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1264 RETURN_EGL_EVAL(disp
, ret
);
1268 #endif /* EGL_KHR_image_base */
1271 #ifdef EGL_KHR_reusable_sync
1274 EGLSyncKHR EGLAPIENTRY
1275 eglCreateSyncKHR(EGLDisplay dpy
, EGLenum type
, const EGLint
*attrib_list
)
1277 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1282 _EGL_CHECK_DISPLAY(disp
, EGL_NO_SYNC_KHR
, drv
);
1284 sync
= drv
->API
.CreateSyncKHR(drv
, disp
, type
, attrib_list
);
1285 ret
= (sync
) ? _eglLinkSync(sync
, disp
) : EGL_NO_SYNC_KHR
;
1287 RETURN_EGL_EVAL(disp
, ret
);
1291 EGLBoolean EGLAPIENTRY
1292 eglDestroySyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
)
1294 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1295 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1299 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1301 ret
= drv
->API
.DestroySyncKHR(drv
, disp
, s
);
1303 RETURN_EGL_EVAL(disp
, ret
);
1308 eglClientWaitSyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLint flags
, EGLTimeKHR timeout
)
1310 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1311 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1315 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1316 ret
= drv
->API
.ClientWaitSyncKHR(drv
, disp
, s
, flags
, timeout
);
1318 RETURN_EGL_EVAL(disp
, ret
);
1322 EGLBoolean EGLAPIENTRY
1323 eglSignalSyncKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLenum mode
)
1325 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1326 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1330 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1331 ret
= drv
->API
.SignalSyncKHR(drv
, disp
, s
, mode
);
1333 RETURN_EGL_EVAL(disp
, ret
);
1337 EGLBoolean EGLAPIENTRY
1338 eglGetSyncAttribKHR(EGLDisplay dpy
, EGLSyncKHR sync
, EGLint attribute
, EGLint
*value
)
1340 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1341 _EGLSync
*s
= _eglLookupSync(sync
, disp
);
1345 _EGL_CHECK_SYNC(disp
, s
, EGL_FALSE
, drv
);
1346 ret
= drv
->API
.GetSyncAttribKHR(drv
, disp
, s
, attribute
, value
);
1348 RETURN_EGL_EVAL(disp
, ret
);
1352 #endif /* EGL_KHR_reusable_sync */
1355 #ifdef EGL_NOK_swap_region
1357 EGLBoolean EGLAPIENTRY
1358 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
1359 EGLint numRects
, const EGLint
*rects
)
1361 _EGLContext
*ctx
= _eglGetCurrentContext();
1362 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1363 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1367 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1369 /* surface must be bound to current context in EGL 1.4 */
1370 if (!ctx
|| !_eglIsContextLinked(ctx
) || surf
!= ctx
->DrawSurface
)
1371 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1373 if (drv
->API
.SwapBuffersRegionNOK
)
1374 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
1376 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1378 RETURN_EGL_EVAL(disp
, ret
);
1381 #endif /* EGL_NOK_swap_region */