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"
74 * Macros to help return an API entrypoint.
76 * These macros will unlock the display and record the error code.
78 #define RETURN_EGL_ERROR(disp, err, ret) \
81 _eglUnlockDisplay(disp); \
82 /* EGL error codes are non-zero */ \
84 _eglError(err, __FUNCTION__); \
88 #define RETURN_EGL_SUCCESS(disp, ret) \
89 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
91 /* record EGL_SUCCESS only when ret evaluates to true */
92 #define RETURN_EGL_EVAL(disp, ret) \
93 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
97 * A bunch of macros and checks to simplify error checking.
100 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
102 drv = _eglCheckDisplay(disp, __FUNCTION__); \
104 RETURN_EGL_ERROR(disp, 0, ret); \
107 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
109 drv = _eglCheck ## type(disp, obj, __FUNCTION__); \
111 RETURN_EGL_ERROR(disp, 0, ret); \
114 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
115 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
117 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
118 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
120 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
121 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
123 #define _EGL_CHECK_SCREEN(disp, scrn, ret, drv) \
124 _EGL_CHECK_OBJECT(disp, Screen, scrn, ret, drv)
126 #define _EGL_CHECK_MODE(disp, m, ret, drv) \
127 _EGL_CHECK_OBJECT(disp, Mode, m, ret, drv)
131 static INLINE _EGLDriver
*
132 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
135 _eglError(EGL_BAD_DISPLAY
, msg
);
138 if (!disp
->Initialized
) {
139 _eglError(EGL_NOT_INITIALIZED
, msg
);
146 static INLINE _EGLDriver
*
147 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
149 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
153 _eglError(EGL_BAD_SURFACE
, msg
);
160 static INLINE _EGLDriver
*
161 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
163 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
167 _eglError(EGL_BAD_CONTEXT
, msg
);
174 static INLINE _EGLDriver
*
175 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
177 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
181 _eglError(EGL_BAD_CONFIG
, msg
);
188 #ifdef EGL_MESA_screen_surface
191 static INLINE _EGLDriver
*
192 _eglCheckScreen(_EGLDisplay
*disp
, _EGLScreen
*scrn
, const char *msg
)
194 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
198 _eglError(EGL_BAD_SCREEN_MESA
, msg
);
205 static INLINE _EGLDriver
*
206 _eglCheckMode(_EGLDisplay
*disp
, _EGLMode
*m
, const char *msg
)
208 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
212 _eglError(EGL_BAD_MODE_MESA
, msg
);
219 #endif /* EGL_MESA_screen_surface */
223 * Lookup and lock a display.
225 static INLINE _EGLDisplay
*
226 _eglLockDisplay(EGLDisplay display
)
228 _EGLDisplay
*dpy
= _eglLookupDisplay(display
);
230 _eglLockMutex(&dpy
->Mutex
);
239 _eglUnlockDisplay(_EGLDisplay
*dpy
)
241 _eglUnlockMutex(&dpy
->Mutex
);
246 * This is typically the first EGL function that an application calls.
247 * It associates a private _EGLDisplay object to the native display.
249 EGLDisplay EGLAPIENTRY
250 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
252 _EGLPlatformType plat
= _eglGetNativePlatform();
253 _EGLDisplay
*dpy
= _eglFindDisplay(plat
, (void *) nativeDisplay
);
254 return _eglGetDisplayHandle(dpy
);
259 * This is typically the second EGL function that an application calls.
260 * Here we load/initialize the actual hardware driver.
262 EGLBoolean EGLAPIENTRY
263 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
265 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
268 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
270 if (!disp
->Initialized
) {
271 if (!_eglMatchDriver(disp
, EGL_FALSE
))
272 RETURN_EGL_ERROR(disp
, EGL_NOT_INITIALIZED
, EGL_FALSE
);
274 _eglsnprintf(disp
->Version
, sizeof(disp
->Version
), "%d.%d (%s)",
275 disp
->APImajor
, disp
->APIminor
, disp
->Driver
->Name
);
276 /* limit to APIs supported by core */
277 disp
->ClientAPIsMask
&= _EGL_API_ALL_BITS
;
280 /* Update applications version of major and minor if not NULL */
281 if ((major
!= NULL
) && (minor
!= NULL
)) {
282 *major
= disp
->APImajor
;
283 *minor
= disp
->APIminor
;
286 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
290 EGLBoolean EGLAPIENTRY
291 eglTerminate(EGLDisplay dpy
)
293 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
296 RETURN_EGL_ERROR(NULL
, EGL_BAD_DISPLAY
, EGL_FALSE
);
298 if (disp
->Initialized
) {
299 _EGLDriver
*drv
= disp
->Driver
;
301 drv
->API
.Terminate(drv
, disp
);
302 /* do not reset disp->Driver */
303 disp
->Initialized
= EGL_FALSE
;
306 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
310 const char * EGLAPIENTRY
311 eglQueryString(EGLDisplay dpy
, EGLint name
)
313 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
317 _EGL_CHECK_DISPLAY(disp
, NULL
, drv
);
318 ret
= drv
->API
.QueryString(drv
, disp
, name
);
320 RETURN_EGL_EVAL(disp
, ret
);
324 EGLBoolean EGLAPIENTRY
325 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
326 EGLint config_size
, EGLint
*num_config
)
328 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
332 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
333 ret
= drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
335 RETURN_EGL_EVAL(disp
, ret
);
339 EGLBoolean EGLAPIENTRY
340 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
341 EGLint config_size
, EGLint
*num_config
)
343 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
347 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
348 ret
= drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
349 config_size
, num_config
);
351 RETURN_EGL_EVAL(disp
, ret
);
355 EGLBoolean EGLAPIENTRY
356 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
357 EGLint attribute
, EGLint
*value
)
359 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
360 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
364 _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
, drv
);
365 ret
= drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
367 RETURN_EGL_EVAL(disp
, ret
);
371 EGLContext EGLAPIENTRY
372 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
373 const EGLint
*attrib_list
)
375 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
376 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
377 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
379 _EGLContext
*context
;
382 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
, drv
);
383 if (!share
&& share_list
!= EGL_NO_CONTEXT
)
384 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_CONTEXT
);
386 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
387 ret
= (context
) ? _eglLinkContext(context
, disp
) : EGL_NO_CONTEXT
;
389 RETURN_EGL_EVAL(disp
, ret
);
393 EGLBoolean EGLAPIENTRY
394 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
396 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
397 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
401 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
402 _eglUnlinkContext(context
);
403 ret
= drv
->API
.DestroyContext(drv
, disp
, context
);
405 RETURN_EGL_EVAL(disp
, ret
);
409 EGLBoolean EGLAPIENTRY
410 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
413 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
414 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
415 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
416 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
421 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
424 /* display is allowed to be uninitialized under certain condition */
425 if (!disp
->Initialized
) {
426 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
427 ctx
!= EGL_NO_CONTEXT
)
428 RETURN_EGL_ERROR(disp
, EGL_BAD_DISPLAY
, EGL_FALSE
);
431 RETURN_EGL_SUCCESS(disp
, EGL_TRUE
);
433 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
434 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
435 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
436 (!read_surf
&& read
!= EGL_NO_SURFACE
))
437 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
439 ret
= drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
441 RETURN_EGL_EVAL(disp
, ret
);
445 EGLBoolean EGLAPIENTRY
446 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
447 EGLint attribute
, EGLint
*value
)
449 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
450 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
454 _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
, drv
);
455 ret
= drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
457 RETURN_EGL_EVAL(disp
, ret
);
461 EGLSurface EGLAPIENTRY
462 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
463 EGLNativeWindowType window
, const EGLint
*attrib_list
)
465 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
466 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
471 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
472 if (disp
->Platform
!= _eglGetNativePlatform())
473 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
475 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, window
, attrib_list
);
476 ret
= (surf
) ? _eglLinkSurface(surf
, disp
) : EGL_NO_SURFACE
;
478 RETURN_EGL_EVAL(disp
, ret
);
482 EGLSurface EGLAPIENTRY
483 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
484 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
486 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
487 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
492 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
493 if (disp
->Platform
!= _eglGetNativePlatform())
494 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_NO_SURFACE
);
496 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, pixmap
, attrib_list
);
497 ret
= (surf
) ? _eglLinkSurface(surf
, disp
) : EGL_NO_SURFACE
;
499 RETURN_EGL_EVAL(disp
, ret
);
503 EGLSurface EGLAPIENTRY
504 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
505 const EGLint
*attrib_list
)
507 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
508 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
513 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
515 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
516 ret
= (surf
) ? _eglLinkSurface(surf
, disp
) : EGL_NO_SURFACE
;
518 RETURN_EGL_EVAL(disp
, ret
);
522 EGLBoolean EGLAPIENTRY
523 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
525 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
526 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
530 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
531 _eglUnlinkSurface(surf
);
532 ret
= drv
->API
.DestroySurface(drv
, disp
, surf
);
534 RETURN_EGL_EVAL(disp
, ret
);
537 EGLBoolean EGLAPIENTRY
538 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
539 EGLint attribute
, EGLint
*value
)
541 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
542 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
546 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
547 ret
= drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
549 RETURN_EGL_EVAL(disp
, ret
);
552 EGLBoolean EGLAPIENTRY
553 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
554 EGLint attribute
, EGLint value
)
556 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
557 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
561 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
562 ret
= drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
564 RETURN_EGL_EVAL(disp
, ret
);
568 EGLBoolean EGLAPIENTRY
569 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
571 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
572 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
576 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
577 ret
= drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
579 RETURN_EGL_EVAL(disp
, ret
);
583 EGLBoolean EGLAPIENTRY
584 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
586 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
587 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
591 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
592 ret
= drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
594 RETURN_EGL_EVAL(disp
, ret
);
598 EGLBoolean EGLAPIENTRY
599 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
601 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
602 _EGLContext
*ctx
= _eglGetCurrentContext();
607 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
609 if (!ctx
|| !_eglIsContextLinked(ctx
) || ctx
->Resource
.Display
!= disp
)
610 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
612 surf
= ctx
->DrawSurface
;
613 if (!_eglIsSurfaceLinked(surf
))
614 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
616 ret
= drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
618 RETURN_EGL_EVAL(disp
, ret
);
622 EGLBoolean EGLAPIENTRY
623 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
625 _EGLContext
*ctx
= _eglGetCurrentContext();
626 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
627 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
631 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
633 /* surface must be bound to current context in EGL 1.4 */
634 if (!ctx
|| !_eglIsContextLinked(ctx
) || surf
!= ctx
->DrawSurface
)
635 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
637 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
639 RETURN_EGL_EVAL(disp
, ret
);
643 EGLBoolean EGLAPIENTRY
644 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
646 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
647 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
651 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
652 if (disp
->Platform
!= _eglGetNativePlatform())
653 RETURN_EGL_ERROR(disp
, EGL_BAD_NATIVE_PIXMAP
, EGL_FALSE
);
654 ret
= drv
->API
.CopyBuffers(drv
, disp
, surf
, target
);
656 RETURN_EGL_EVAL(disp
, ret
);
660 EGLBoolean EGLAPIENTRY
663 _EGLContext
*ctx
= _eglGetCurrentContext();
669 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
671 disp
= ctx
->Resource
.Display
;
672 _eglLockMutex(&disp
->Mutex
);
674 /* let bad current context imply bad current surface */
675 if (!_eglIsContextLinked(ctx
) || !_eglIsSurfaceLinked(ctx
->DrawSurface
))
676 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
678 /* a valid current context implies an initialized current display */
679 assert(disp
->Initialized
);
681 ret
= drv
->API
.WaitClient(drv
, disp
, ctx
);
683 RETURN_EGL_EVAL(disp
, ret
);
687 EGLBoolean EGLAPIENTRY
690 #ifdef EGL_VERSION_1_2
691 _EGLThreadInfo
*t
= _eglGetCurrentThread();
692 EGLint api_index
= t
->CurrentAPIIndex
;
693 EGLint es_index
= _eglConvertApiToIndex(EGL_OPENGL_ES_API
);
696 if (api_index
!= es_index
&& _eglIsCurrentThreadDummy())
697 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
699 t
->CurrentAPIIndex
= es_index
;
700 ret
= eglWaitClient();
701 t
->CurrentAPIIndex
= api_index
;
704 return eglWaitClient();
709 EGLBoolean EGLAPIENTRY
710 eglWaitNative(EGLint engine
)
712 _EGLContext
*ctx
= _eglGetCurrentContext();
718 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
720 disp
= ctx
->Resource
.Display
;
721 _eglLockMutex(&disp
->Mutex
);
723 /* let bad current context imply bad current surface */
724 if (!_eglIsContextLinked(ctx
) || !_eglIsSurfaceLinked(ctx
->DrawSurface
))
725 RETURN_EGL_ERROR(disp
, EGL_BAD_CURRENT_SURFACE
, EGL_FALSE
);
727 /* a valid current context implies an initialized current display */
728 assert(disp
->Initialized
);
730 ret
= drv
->API
.WaitNative(drv
, disp
, engine
);
732 RETURN_EGL_EVAL(disp
, ret
);
736 EGLDisplay EGLAPIENTRY
737 eglGetCurrentDisplay(void)
739 _EGLContext
*ctx
= _eglGetCurrentContext();
742 ret
= (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
744 RETURN_EGL_SUCCESS(NULL
, ret
);
748 EGLContext EGLAPIENTRY
749 eglGetCurrentContext(void)
751 _EGLContext
*ctx
= _eglGetCurrentContext();
754 ret
= _eglGetContextHandle(ctx
);
756 RETURN_EGL_SUCCESS(NULL
, ret
);
760 EGLSurface EGLAPIENTRY
761 eglGetCurrentSurface(EGLint readdraw
)
763 _EGLContext
*ctx
= _eglGetCurrentContext();
764 EGLint err
= EGL_SUCCESS
;
769 RETURN_EGL_SUCCESS(NULL
, EGL_NO_SURFACE
);
773 surf
= ctx
->DrawSurface
;
776 surf
= ctx
->ReadSurface
;
780 err
= EGL_BAD_PARAMETER
;
784 ret
= _eglGetSurfaceHandle(surf
);
786 RETURN_EGL_ERROR(NULL
, err
, ret
);
793 _EGLThreadInfo
*t
= _eglGetCurrentThread();
794 EGLint e
= t
->LastError
;
795 if (!_eglIsCurrentThreadDummy())
796 t
->LastError
= EGL_SUCCESS
;
801 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
802 eglGetProcAddress(const char *procname
)
804 static const struct {
807 } egl_functions
[] = {
808 /* extensions only */
809 #ifdef EGL_MESA_screen_surface
810 { "eglChooseModeMESA", (_EGLProc
) eglChooseModeMESA
},
811 { "eglGetModesMESA", (_EGLProc
) eglGetModesMESA
},
812 { "eglGetModeAttribMESA", (_EGLProc
) eglGetModeAttribMESA
},
813 { "eglCopyContextMESA", (_EGLProc
) eglCopyContextMESA
},
814 { "eglGetScreensMESA", (_EGLProc
) eglGetScreensMESA
},
815 { "eglCreateScreenSurfaceMESA", (_EGLProc
) eglCreateScreenSurfaceMESA
},
816 { "eglShowScreenSurfaceMESA", (_EGLProc
) eglShowScreenSurfaceMESA
},
817 { "eglScreenPositionMESA", (_EGLProc
) eglScreenPositionMESA
},
818 { "eglQueryScreenMESA", (_EGLProc
) eglQueryScreenMESA
},
819 { "eglQueryScreenSurfaceMESA", (_EGLProc
) eglQueryScreenSurfaceMESA
},
820 { "eglQueryScreenModeMESA", (_EGLProc
) eglQueryScreenModeMESA
},
821 { "eglQueryModeStringMESA", (_EGLProc
) eglQueryModeStringMESA
},
822 #endif /* EGL_MESA_screen_surface */
823 #ifdef EGL_MESA_drm_display
824 { "eglGetDRMDisplayMESA", (_EGLProc
) eglGetDRMDisplayMESA
},
826 #ifdef EGL_KHR_image_base
827 { "eglCreateImageKHR", (_EGLProc
) eglCreateImageKHR
},
828 { "eglDestroyImageKHR", (_EGLProc
) eglDestroyImageKHR
},
829 #endif /* EGL_KHR_image_base */
830 #ifdef EGL_NOK_swap_region
831 { "eglSwapBuffersRegionNOK", (_EGLProc
) eglSwapBuffersRegionNOK
},
839 RETURN_EGL_SUCCESS(NULL
, NULL
);
842 if (strncmp(procname
, "egl", 3) == 0) {
843 for (i
= 0; egl_functions
[i
].name
; i
++) {
844 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
845 ret
= egl_functions
[i
].function
;
851 ret
= _eglGetDriverProc(procname
);
853 RETURN_EGL_SUCCESS(NULL
, ret
);
857 #ifdef EGL_MESA_screen_surface
861 * EGL_MESA_screen extension
864 EGLBoolean EGLAPIENTRY
865 eglChooseModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
866 const EGLint
*attrib_list
, EGLModeMESA
*modes
,
867 EGLint modes_size
, EGLint
*num_modes
)
869 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
870 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
874 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
875 ret
= drv
->API
.ChooseModeMESA(drv
, disp
, scrn
, attrib_list
,
876 modes
, modes_size
, num_modes
);
878 RETURN_EGL_EVAL(disp
, ret
);
882 EGLBoolean EGLAPIENTRY
883 eglGetModesMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*modes
,
884 EGLint mode_size
, EGLint
*num_mode
)
886 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
887 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
891 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
892 ret
= drv
->API
.GetModesMESA(drv
, disp
, scrn
, modes
, mode_size
, num_mode
);
894 RETURN_EGL_EVAL(disp
, ret
);
898 EGLBoolean EGLAPIENTRY
899 eglGetModeAttribMESA(EGLDisplay dpy
, EGLModeMESA mode
,
900 EGLint attribute
, EGLint
*value
)
902 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
903 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
907 _EGL_CHECK_MODE(disp
, m
, EGL_FALSE
, drv
);
908 ret
= drv
->API
.GetModeAttribMESA(drv
, disp
, m
, attribute
, value
);
910 RETURN_EGL_EVAL(disp
, ret
);
914 EGLBoolean EGLAPIENTRY
915 eglCopyContextMESA(EGLDisplay dpy
, EGLContext source
, EGLContext dest
,
918 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
919 _EGLContext
*source_context
= _eglLookupContext(source
, disp
);
920 _EGLContext
*dest_context
= _eglLookupContext(dest
, disp
);
924 _EGL_CHECK_CONTEXT(disp
, source_context
, EGL_FALSE
, drv
);
926 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_FALSE
);
928 ret
= drv
->API
.CopyContextMESA(drv
, disp
,
929 source_context
, dest_context
, mask
);
931 RETURN_EGL_EVAL(disp
, ret
);
935 EGLBoolean EGLAPIENTRY
936 eglGetScreensMESA(EGLDisplay dpy
, EGLScreenMESA
*screens
,
937 EGLint max_screens
, EGLint
*num_screens
)
939 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
943 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
944 ret
= drv
->API
.GetScreensMESA(drv
, disp
, screens
, max_screens
, num_screens
);
946 RETURN_EGL_EVAL(disp
, ret
);
950 EGLSurface EGLAPIENTRY
951 eglCreateScreenSurfaceMESA(EGLDisplay dpy
, EGLConfig config
,
952 const EGLint
*attrib_list
)
954 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
955 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
960 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
962 surf
= drv
->API
.CreateScreenSurfaceMESA(drv
, disp
, conf
, attrib_list
);
963 ret
= (surf
) ? _eglLinkSurface(surf
, disp
) : EGL_NO_SURFACE
;
965 RETURN_EGL_EVAL(disp
, ret
);
969 EGLBoolean EGLAPIENTRY
970 eglShowScreenSurfaceMESA(EGLDisplay dpy
, EGLint screen
,
971 EGLSurface surface
, EGLModeMESA mode
)
973 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
974 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
975 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
976 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
980 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
981 if (!surf
&& surface
!= EGL_NO_SURFACE
)
982 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
983 if (!m
&& mode
!= EGL_NO_MODE_MESA
)
984 RETURN_EGL_ERROR(disp
, EGL_BAD_MODE_MESA
, EGL_FALSE
);
986 ret
= drv
->API
.ShowScreenSurfaceMESA(drv
, disp
, scrn
, surf
, m
);
988 RETURN_EGL_EVAL(disp
, ret
);
992 EGLBoolean EGLAPIENTRY
993 eglScreenPositionMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLint x
, EGLint y
)
995 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
996 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1000 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1001 ret
= drv
->API
.ScreenPositionMESA(drv
, disp
, scrn
, x
, y
);
1003 RETURN_EGL_EVAL(disp
, ret
);
1007 EGLBoolean EGLAPIENTRY
1008 eglQueryScreenMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1009 EGLint attribute
, EGLint
*value
)
1011 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1012 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
1016 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1017 ret
= drv
->API
.QueryScreenMESA(drv
, disp
, scrn
, attribute
, value
);
1019 RETURN_EGL_EVAL(disp
, ret
);
1023 EGLBoolean EGLAPIENTRY
1024 eglQueryScreenSurfaceMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
1025 EGLSurface
*surface
)
1027 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1028 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1033 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1034 ret
= drv
->API
.QueryScreenSurfaceMESA(drv
, disp
, scrn
, &surf
);
1036 *surface
= _eglGetSurfaceHandle(surf
);
1038 RETURN_EGL_EVAL(disp
, ret
);
1042 EGLBoolean EGLAPIENTRY
1043 eglQueryScreenModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*mode
)
1045 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1046 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
1051 _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
, drv
);
1052 ret
= drv
->API
.QueryScreenModeMESA(drv
, disp
, scrn
, &m
);
1056 RETURN_EGL_EVAL(disp
, ret
);
1060 const char * EGLAPIENTRY
1061 eglQueryModeStringMESA(EGLDisplay dpy
, EGLModeMESA mode
)
1063 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1064 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
1068 _EGL_CHECK_MODE(disp
, m
, NULL
, drv
);
1069 ret
= drv
->API
.QueryModeStringMESA(drv
, disp
, m
);
1071 RETURN_EGL_EVAL(disp
, ret
);
1075 #endif /* EGL_MESA_screen_surface */
1078 #ifdef EGL_MESA_drm_display
1080 EGLDisplay EGLAPIENTRY
1081 eglGetDRMDisplayMESA(int fd
)
1083 _EGLDisplay
*dpy
= _eglFindDisplay(_EGL_PLATFORM_DRM
, (void *) fd
);
1084 return _eglGetDisplayHandle(dpy
);
1087 #endif /* EGL_MESA_drm_display */
1093 #ifdef EGL_VERSION_1_2
1097 * Specify the client API to use for subsequent calls including:
1098 * eglCreateContext()
1099 * eglGetCurrentContext()
1100 * eglGetCurrentDisplay()
1101 * eglGetCurrentSurface()
1102 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1105 * See section 3.7 "Rendering Context" in the EGL specification for details.
1107 EGLBoolean EGLAPIENTRY
1108 eglBindAPI(EGLenum api
)
1110 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1112 if (_eglIsCurrentThreadDummy())
1113 RETURN_EGL_ERROR(NULL
, EGL_BAD_ALLOC
, EGL_FALSE
);
1115 if (!_eglIsApiValid(api
))
1116 RETURN_EGL_ERROR(NULL
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1118 t
->CurrentAPIIndex
= _eglConvertApiToIndex(api
);
1120 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1125 * Return the last value set with eglBindAPI().
1130 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1133 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1134 ret
= _eglConvertApiFromIndex(t
->CurrentAPIIndex
);
1136 RETURN_EGL_SUCCESS(NULL
, ret
);
1140 EGLSurface EGLAPIENTRY
1141 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1142 EGLClientBuffer buffer
, EGLConfig config
,
1143 const EGLint
*attrib_list
)
1145 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1146 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1151 _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
, drv
);
1153 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1155 ret
= (surf
) ? _eglLinkSurface(surf
, disp
) : EGL_NO_SURFACE
;
1157 RETURN_EGL_EVAL(disp
, ret
);
1161 EGLBoolean EGLAPIENTRY
1162 eglReleaseThread(void)
1164 /* unbind current contexts */
1165 if (!_eglIsCurrentThreadDummy()) {
1166 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1167 EGLint api_index
= t
->CurrentAPIIndex
;
1170 for (i
= 0; i
< _EGL_API_NUM_APIS
; i
++) {
1171 _EGLContext
*ctx
= t
->CurrentContexts
[i
];
1173 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1176 t
->CurrentAPIIndex
= i
;
1178 _eglLockMutex(&disp
->Mutex
);
1180 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1181 _eglUnlockMutex(&disp
->Mutex
);
1185 t
->CurrentAPIIndex
= api_index
;
1188 _eglDestroyCurrentThread();
1190 RETURN_EGL_SUCCESS(NULL
, EGL_TRUE
);
1194 #endif /* EGL_VERSION_1_2 */
1197 #ifdef EGL_KHR_image_base
1200 EGLImageKHR EGLAPIENTRY
1201 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1202 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1204 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1205 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1210 _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
, drv
);
1211 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
1212 RETURN_EGL_ERROR(disp
, EGL_BAD_CONTEXT
, EGL_NO_IMAGE_KHR
);
1214 img
= drv
->API
.CreateImageKHR(drv
,
1215 disp
, context
, target
, buffer
, attr_list
);
1216 ret
= (img
) ? _eglLinkImage(img
, disp
) : EGL_NO_IMAGE_KHR
;
1218 RETURN_EGL_EVAL(disp
, ret
);
1222 EGLBoolean EGLAPIENTRY
1223 eglDestroyImageKHR(EGLDisplay dpy
, EGLImageKHR image
)
1225 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1226 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1230 _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
, drv
);
1232 RETURN_EGL_ERROR(disp
, EGL_BAD_PARAMETER
, EGL_FALSE
);
1234 _eglUnlinkImage(img
);
1235 ret
= drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1237 RETURN_EGL_EVAL(disp
, ret
);
1241 #endif /* EGL_KHR_image_base */
1244 #ifdef EGL_NOK_swap_region
1246 EGLBoolean EGLAPIENTRY
1247 eglSwapBuffersRegionNOK(EGLDisplay dpy
, EGLSurface surface
,
1248 EGLint numRects
, const EGLint
*rects
)
1250 _EGLContext
*ctx
= _eglGetCurrentContext();
1251 _EGLDisplay
*disp
= _eglLockDisplay(dpy
);
1252 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
1256 _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
, drv
);
1258 /* surface must be bound to current context in EGL 1.4 */
1259 if (!ctx
|| !_eglIsContextLinked(ctx
) || surf
!= ctx
->DrawSurface
)
1260 RETURN_EGL_ERROR(disp
, EGL_BAD_SURFACE
, EGL_FALSE
);
1262 if (drv
->API
.SwapBuffersRegionNOK
)
1263 ret
= drv
->API
.SwapBuffersRegionNOK(drv
, disp
, surf
, numRects
, rects
);
1265 ret
= drv
->API
.SwapBuffers(drv
, disp
, surf
);
1267 RETURN_EGL_EVAL(disp
, ret
);
1270 #endif /* EGL_NOK_swap_region */