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
59 #include "eglcontext.h"
60 #include "egldisplay.h"
61 #include "egltypedefs.h"
62 #include "eglglobals.h"
63 #include "eglcurrent.h"
64 #include "egldriver.h"
65 #include "eglsurface.h"
66 #include "eglconfig.h"
67 #include "eglscreen.h"
73 * Macros to help return an API entrypoint.
75 #define _EGL_ERROR(disp, err, ret) \
77 /* EGL error codes are non-zero */ \
79 _eglError(err, __FUNCTION__); \
85 * A bunch of macros and checks to simplify error checking.
87 #define _EGL_CHECK_DISPLAY(disp, ret) \
89 _EGLDriver *__drv = _eglCheckDisplay(disp, __FUNCTION__); \
91 return _EGL_ERROR(disp, 0, ret); \
96 #define _EGL_CHECK_OBJECT(disp, type, obj, ret) \
98 _EGLDriver *__drv = _eglCheck ## type(disp, obj, __FUNCTION__); \
100 return _EGL_ERROR(disp, 0, ret); \
103 #define _EGL_CHECK_SURFACE(disp, surf, ret) \
104 _EGL_CHECK_OBJECT(disp, Surface, surf, ret)
105 #define _EGL_CHECK_CONTEXT(disp, context, ret) \
106 _EGL_CHECK_OBJECT(disp, Context, context, ret)
107 #define _EGL_CHECK_CONFIG(disp, conf, ret) \
108 _EGL_CHECK_OBJECT(disp, Config, conf, ret)
109 #define _EGL_CHECK_SCREEN(disp, scrn, ret) \
110 _EGL_CHECK_OBJECT(disp, Screen, scrn, ret)
111 #define _EGL_CHECK_MODE(disp, m, ret) \
112 _EGL_CHECK_OBJECT(disp, Mode, m, ret)
115 static INLINE _EGLDriver
*
116 _eglCheckDisplay(_EGLDisplay
*disp
, const char *msg
)
119 _eglError(EGL_BAD_DISPLAY
, msg
);
122 if (!disp
->Initialized
) {
123 _eglError(EGL_NOT_INITIALIZED
, msg
);
130 static INLINE _EGLDriver
*
131 _eglCheckSurface(_EGLDisplay
*disp
, _EGLSurface
*surf
, const char *msg
)
133 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
137 _eglError(EGL_BAD_SURFACE
, msg
);
144 static INLINE _EGLDriver
*
145 _eglCheckContext(_EGLDisplay
*disp
, _EGLContext
*context
, const char *msg
)
147 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
151 _eglError(EGL_BAD_CONTEXT
, msg
);
158 static INLINE _EGLDriver
*
159 _eglCheckConfig(_EGLDisplay
*disp
, _EGLConfig
*conf
, const char *msg
)
161 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
165 _eglError(EGL_BAD_CONFIG
, msg
);
172 #ifdef EGL_MESA_screen_surface
175 static INLINE _EGLDriver
*
176 _eglCheckScreen(_EGLDisplay
*disp
, _EGLScreen
*scrn
, const char *msg
)
178 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
182 _eglError(EGL_BAD_SCREEN_MESA
, msg
);
189 static INLINE _EGLDriver
*
190 _eglCheckMode(_EGLDisplay
*disp
, _EGLMode
*m
, const char *msg
)
192 _EGLDriver
*drv
= _eglCheckDisplay(disp
, msg
);
196 _eglError(EGL_BAD_MODE_MESA
, msg
);
203 #endif /* EGL_MESA_screen_surface */
207 * This is typically the first EGL function that an application calls.
208 * We initialize our global vars and create a private _EGLDisplay object.
210 EGLDisplay EGLAPIENTRY
211 eglGetDisplay(EGLNativeDisplayType nativeDisplay
)
214 dpy
= _eglFindDisplay(nativeDisplay
);
216 dpy
= _eglNewDisplay(nativeDisplay
);
218 _eglLinkDisplay(dpy
);
220 return _eglGetDisplayHandle(dpy
);
225 * This is typically the second EGL function that an application calls.
226 * Here we load/initialize the actual hardware driver.
228 EGLBoolean EGLAPIENTRY
229 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
231 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
232 EGLint major_int
, minor_int
;
235 return _eglError(EGL_BAD_DISPLAY
, __FUNCTION__
);
237 if (!disp
->Initialized
) {
238 _EGLDriver
*drv
= disp
->Driver
;
241 _eglPreloadDrivers();
242 drv
= _eglMatchDriver(disp
);
244 return _eglError(EGL_NOT_INITIALIZED
, __FUNCTION__
);
247 /* Initialize the particular display now */
248 if (!drv
->API
.Initialize(drv
, disp
, &major_int
, &minor_int
))
249 return _eglError(EGL_NOT_INITIALIZED
, __FUNCTION__
);
251 disp
->APImajor
= major_int
;
252 disp
->APIminor
= minor_int
;
253 snprintf(disp
->Version
, sizeof(disp
->Version
),
254 "%d.%d (%s)", major_int
, minor_int
, drv
->Name
);
256 /* limit to APIs supported by core */
257 disp
->ClientAPIsMask
&= _EGL_API_ALL_BITS
;
260 disp
->Initialized
= EGL_TRUE
;
262 major_int
= disp
->APImajor
;
263 minor_int
= disp
->APIminor
;
266 /* Update applications version of major and minor if not NULL */
267 if ((major
!= NULL
) && (minor
!= NULL
)) {
276 EGLBoolean EGLAPIENTRY
277 eglTerminate(EGLDisplay dpy
)
279 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
282 return _eglError(EGL_BAD_DISPLAY
, __FUNCTION__
);
284 if (disp
->Initialized
) {
285 _EGLDriver
*drv
= disp
->Driver
;
287 drv
->API
.Terminate(drv
, disp
);
288 /* do not reset disp->Driver */
289 disp
->Initialized
= EGL_FALSE
;
296 const char * EGLAPIENTRY
297 eglQueryString(EGLDisplay dpy
, EGLint name
)
299 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
302 drv
= _EGL_CHECK_DISPLAY(disp
, NULL
);
303 return drv
->API
.QueryString(drv
, disp
, name
);
307 EGLBoolean EGLAPIENTRY
308 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
,
309 EGLint config_size
, EGLint
*num_config
)
311 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
314 drv
= _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
315 return drv
->API
.GetConfigs(drv
, disp
, configs
, config_size
, num_config
);
319 EGLBoolean EGLAPIENTRY
320 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
,
321 EGLint config_size
, EGLint
*num_config
)
323 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
326 drv
= _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
327 return drv
->API
.ChooseConfig(drv
, disp
, attrib_list
, configs
,
328 config_size
, num_config
);
332 EGLBoolean EGLAPIENTRY
333 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
334 EGLint attribute
, EGLint
*value
)
336 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
337 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
340 drv
= _EGL_CHECK_CONFIG(disp
, conf
, EGL_FALSE
);
341 return drv
->API
.GetConfigAttrib(drv
, disp
, conf
, attribute
, value
);
345 EGLContext EGLAPIENTRY
346 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
,
347 const EGLint
*attrib_list
)
349 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
350 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
351 _EGLContext
*share
= _eglLookupContext(share_list
, disp
);
353 _EGLContext
*context
;
355 drv
= _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_CONTEXT
);
356 if (!share
&& share_list
!= EGL_NO_CONTEXT
) {
357 _eglError(EGL_BAD_CONTEXT
, __FUNCTION__
);
358 return EGL_NO_CONTEXT
;
361 context
= drv
->API
.CreateContext(drv
, disp
, conf
, share
, attrib_list
);
363 return _eglLinkContext(context
, disp
);
365 return EGL_NO_CONTEXT
;
369 EGLBoolean EGLAPIENTRY
370 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
372 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
373 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
376 drv
= _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
);
377 _eglUnlinkContext(context
);
378 return drv
->API
.DestroyContext(drv
, disp
, context
);
382 EGLBoolean EGLAPIENTRY
383 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
386 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
387 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
388 _EGLSurface
*draw_surf
= _eglLookupSurface(draw
, disp
);
389 _EGLSurface
*read_surf
= _eglLookupSurface(read
, disp
);
393 return _eglError(EGL_BAD_DISPLAY
, __FUNCTION__
);
396 /* display is allowed to be uninitialized under certain condition */
397 if (!disp
->Initialized
) {
398 if (draw
!= EGL_NO_SURFACE
|| read
!= EGL_NO_SURFACE
||
399 ctx
!= EGL_NO_CONTEXT
)
400 return _eglError(EGL_BAD_DISPLAY
, __FUNCTION__
);
405 if (!context
&& ctx
!= EGL_NO_CONTEXT
)
406 return _eglError(EGL_BAD_CONTEXT
, __FUNCTION__
);
407 if ((!draw_surf
&& draw
!= EGL_NO_SURFACE
) ||
408 (!read_surf
&& read
!= EGL_NO_SURFACE
))
409 return _eglError(EGL_BAD_SURFACE
, __FUNCTION__
);
411 return drv
->API
.MakeCurrent(drv
, disp
, draw_surf
, read_surf
, context
);
415 EGLBoolean EGLAPIENTRY
416 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
,
417 EGLint attribute
, EGLint
*value
)
419 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
420 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
423 drv
= _EGL_CHECK_CONTEXT(disp
, context
, EGL_FALSE
);
424 return drv
->API
.QueryContext(drv
, disp
, context
, attribute
, value
);
428 EGLSurface EGLAPIENTRY
429 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
430 EGLNativeWindowType window
, const EGLint
*attrib_list
)
432 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
433 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
437 drv
= _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
);
439 surf
= drv
->API
.CreateWindowSurface(drv
, disp
, conf
, window
, attrib_list
);
441 return _eglLinkSurface(surf
, disp
);
443 return EGL_NO_SURFACE
;
447 EGLSurface EGLAPIENTRY
448 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
449 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
451 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
452 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
456 drv
= _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
);
458 surf
= drv
->API
.CreatePixmapSurface(drv
, disp
, conf
, pixmap
, attrib_list
);
460 return _eglLinkSurface(surf
, disp
);
462 return EGL_NO_SURFACE
;
466 EGLSurface EGLAPIENTRY
467 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
468 const EGLint
*attrib_list
)
470 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
471 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
475 drv
= _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
);
477 surf
= drv
->API
.CreatePbufferSurface(drv
, disp
, conf
, attrib_list
);
479 return _eglLinkSurface(surf
, disp
);
481 return EGL_NO_SURFACE
;
485 EGLBoolean EGLAPIENTRY
486 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
488 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
489 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
492 drv
= _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
493 _eglUnlinkSurface(surf
);
494 return drv
->API
.DestroySurface(drv
, disp
, surf
);
497 EGLBoolean EGLAPIENTRY
498 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
,
499 EGLint attribute
, EGLint
*value
)
501 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
502 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
505 drv
= _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
506 return drv
->API
.QuerySurface(drv
, disp
, surf
, attribute
, value
);
509 EGLBoolean EGLAPIENTRY
510 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
,
511 EGLint attribute
, EGLint value
)
513 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
514 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
517 drv
= _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
518 return drv
->API
.SurfaceAttrib(drv
, disp
, surf
, attribute
, value
);
522 EGLBoolean EGLAPIENTRY
523 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
525 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
526 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
529 drv
= _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
530 return drv
->API
.BindTexImage(drv
, disp
, surf
, buffer
);
534 EGLBoolean EGLAPIENTRY
535 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
537 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
538 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
541 drv
= _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
542 return drv
->API
.ReleaseTexImage(drv
, disp
, surf
, buffer
);
546 EGLBoolean EGLAPIENTRY
547 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
549 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
550 _EGLContext
*ctx
= _eglGetCurrentContext();
554 drv
= _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
556 if (!ctx
|| !_eglIsContextLinked(ctx
) || ctx
->Resource
.Display
!= disp
)
557 return _eglError(EGL_BAD_CONTEXT
, __FUNCTION__
);
559 surf
= ctx
->DrawSurface
;
560 if (!_eglIsSurfaceLinked(surf
))
561 return _eglError(EGL_BAD_SURFACE
, __FUNCTION__
);
563 return drv
->API
.SwapInterval(drv
, disp
, surf
, interval
);
567 EGLBoolean EGLAPIENTRY
568 eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
)
570 _EGLContext
*ctx
= _eglGetCurrentContext();
571 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
572 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
575 drv
= _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
577 /* surface must be bound to current context in EGL 1.4 */
578 if (!ctx
|| !_eglIsContextLinked(ctx
) || surf
!= ctx
->DrawSurface
)
579 return _eglError(EGL_BAD_SURFACE
, __FUNCTION__
);
581 return drv
->API
.SwapBuffers(drv
, disp
, surf
);
585 EGLBoolean EGLAPIENTRY
586 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, EGLNativePixmapType target
)
588 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
589 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
592 drv
= _EGL_CHECK_SURFACE(disp
, surf
, EGL_FALSE
);
593 return drv
->API
.CopyBuffers(drv
, disp
, surf
, target
);
597 EGLBoolean EGLAPIENTRY
600 _EGLContext
*ctx
= _eglGetCurrentContext();
606 /* let bad current context imply bad current surface */
607 if (!_eglIsContextLinked(ctx
) || !_eglIsSurfaceLinked(ctx
->DrawSurface
))
608 return _eglError(EGL_BAD_CURRENT_SURFACE
, __FUNCTION__
);
610 /* a valid current context implies an initialized current display */
611 disp
= ctx
->Resource
.Display
;
612 assert(disp
->Initialized
);
615 return drv
->API
.WaitClient(drv
, disp
, ctx
);
619 EGLBoolean EGLAPIENTRY
622 #ifdef EGL_VERSION_1_2
623 _EGLThreadInfo
*t
= _eglGetCurrentThread();
624 EGLint api_index
= t
->CurrentAPIIndex
;
625 EGLint es_index
= _eglConvertApiToIndex(EGL_OPENGL_ES_API
);
628 if (api_index
!= es_index
&& _eglIsCurrentThreadDummy())
629 return _eglError(EGL_BAD_ALLOC
, "eglWaitGL");
631 t
->CurrentAPIIndex
= es_index
;
632 ret
= eglWaitClient();
633 t
->CurrentAPIIndex
= api_index
;
636 return eglWaitClient();
641 EGLBoolean EGLAPIENTRY
642 eglWaitNative(EGLint engine
)
644 _EGLContext
*ctx
= _eglGetCurrentContext();
650 /* let bad current context imply bad current surface */
651 if (!_eglIsContextLinked(ctx
) || !_eglIsSurfaceLinked(ctx
->DrawSurface
))
652 return _eglError(EGL_BAD_CURRENT_SURFACE
, __FUNCTION__
);
654 /* a valid current context implies an initialized current display */
655 disp
= ctx
->Resource
.Display
;
656 assert(disp
->Initialized
);
659 return drv
->API
.WaitNative(drv
, disp
, engine
);
663 EGLDisplay EGLAPIENTRY
664 eglGetCurrentDisplay(void)
666 _EGLContext
*ctx
= _eglGetCurrentContext();
667 return (ctx
) ? _eglGetDisplayHandle(ctx
->Resource
.Display
) : EGL_NO_DISPLAY
;
671 EGLContext EGLAPIENTRY
672 eglGetCurrentContext(void)
674 _EGLContext
*ctx
= _eglGetCurrentContext();
675 return _eglGetContextHandle(ctx
);
679 EGLSurface EGLAPIENTRY
680 eglGetCurrentSurface(EGLint readdraw
)
682 _EGLContext
*ctx
= _eglGetCurrentContext();
686 return EGL_NO_SURFACE
;
690 surf
= ctx
->DrawSurface
;
693 surf
= ctx
->ReadSurface
;
696 _eglError(EGL_BAD_PARAMETER
, __FUNCTION__
);
701 return _eglGetSurfaceHandle(surf
);
708 _EGLThreadInfo
*t
= _eglGetCurrentThread();
709 EGLint e
= t
->LastError
;
710 if (!_eglIsCurrentThreadDummy())
711 t
->LastError
= EGL_SUCCESS
;
716 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
717 eglGetProcAddress(const char *procname
)
719 static const struct {
722 } egl_functions
[] = {
723 /* extensions only */
724 #ifdef EGL_MESA_screen_surface
725 { "eglChooseModeMESA", (_EGLProc
) eglChooseModeMESA
},
726 { "eglGetModesMESA", (_EGLProc
) eglGetModesMESA
},
727 { "eglGetModeAttribMESA", (_EGLProc
) eglGetModeAttribMESA
},
728 { "eglCopyContextMESA", (_EGLProc
) eglCopyContextMESA
},
729 { "eglGetScreensMESA", (_EGLProc
) eglGetScreensMESA
},
730 { "eglCreateScreenSurfaceMESA", (_EGLProc
) eglCreateScreenSurfaceMESA
},
731 { "eglShowScreenSurfaceMESA", (_EGLProc
) eglShowScreenSurfaceMESA
},
732 { "eglScreenPositionMESA", (_EGLProc
) eglScreenPositionMESA
},
733 { "eglQueryScreenMESA", (_EGLProc
) eglQueryScreenMESA
},
734 { "eglQueryScreenSurfaceMESA", (_EGLProc
) eglQueryScreenSurfaceMESA
},
735 { "eglQueryScreenModeMESA", (_EGLProc
) eglQueryScreenModeMESA
},
736 { "eglQueryModeStringMESA", (_EGLProc
) eglQueryModeStringMESA
},
737 #endif /* EGL_MESA_screen_surface */
738 #ifdef EGL_KHR_image_base
739 { "eglCreateImageKHR", (_EGLProc
) eglCreateImageKHR
},
740 { "eglDestroyImageKHR", (_EGLProc
) eglDestroyImageKHR
},
741 #endif /* EGL_KHR_image_base */
748 if (strncmp(procname
, "egl", 3) == 0) {
749 for (i
= 0; egl_functions
[i
].name
; i
++) {
750 if (strcmp(egl_functions
[i
].name
, procname
) == 0)
751 return egl_functions
[i
].function
;
755 _eglPreloadDrivers();
757 /* now loop over drivers to query their procs */
758 for (i
= 0; i
< _eglGlobal
.NumDrivers
; i
++) {
759 _EGLDriver
*drv
= _eglGlobal
.Drivers
[i
];
760 _EGLProc p
= drv
->API
.GetProcAddress(drv
, procname
);
769 #ifdef EGL_MESA_screen_surface
773 * EGL_MESA_screen extension
776 EGLBoolean EGLAPIENTRY
777 eglChooseModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
778 const EGLint
*attrib_list
, EGLModeMESA
*modes
,
779 EGLint modes_size
, EGLint
*num_modes
)
781 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
782 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
785 drv
= _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
);
786 return drv
->API
.ChooseModeMESA(drv
, disp
, scrn
, attrib_list
,
787 modes
, modes_size
, num_modes
);
791 EGLBoolean EGLAPIENTRY
792 eglGetModesMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*modes
,
793 EGLint mode_size
, EGLint
*num_mode
)
795 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
796 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
799 drv
= _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
);
800 return drv
->API
.GetModesMESA(drv
, disp
, scrn
, modes
, mode_size
, num_mode
);
804 EGLBoolean EGLAPIENTRY
805 eglGetModeAttribMESA(EGLDisplay dpy
, EGLModeMESA mode
,
806 EGLint attribute
, EGLint
*value
)
808 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
809 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
812 drv
= _EGL_CHECK_MODE(disp
, m
, EGL_FALSE
);
813 return drv
->API
.GetModeAttribMESA(drv
, disp
, m
, attribute
, value
);
817 EGLBoolean EGLAPIENTRY
818 eglCopyContextMESA(EGLDisplay dpy
, EGLContext source
, EGLContext dest
,
821 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
822 _EGLContext
*source_context
= _eglLookupContext(source
, disp
);
823 _EGLContext
*dest_context
= _eglLookupContext(dest
, disp
);
826 drv
= _EGL_CHECK_CONTEXT(disp
, source_context
, EGL_FALSE
);
828 _eglError(EGL_BAD_CONTEXT
, __FUNCTION__
);
832 return drv
->API
.CopyContextMESA(drv
, disp
, source_context
, dest_context
,
838 eglGetScreensMESA(EGLDisplay dpy
, EGLScreenMESA
*screens
,
839 EGLint max_screens
, EGLint
*num_screens
)
841 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
844 drv
= _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
845 return drv
->API
.GetScreensMESA(drv
, disp
, screens
,
846 max_screens
, num_screens
);
851 eglCreateScreenSurfaceMESA(EGLDisplay dpy
, EGLConfig config
,
852 const EGLint
*attrib_list
)
854 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
855 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
859 drv
= _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
);
861 surf
= drv
->API
.CreateScreenSurfaceMESA(drv
, disp
, conf
, attrib_list
);
863 return _eglLinkSurface(surf
, disp
);
865 return EGL_NO_SURFACE
;
870 eglShowScreenSurfaceMESA(EGLDisplay dpy
, EGLint screen
,
871 EGLSurface surface
, EGLModeMESA mode
)
873 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
874 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
875 _EGLSurface
*surf
= _eglLookupSurface(surface
, disp
);
876 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
879 drv
= _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
);
880 if (!surf
&& surface
!= EGL_NO_SURFACE
)
881 return _eglError(EGL_BAD_SURFACE
, __FUNCTION__
);
882 if (!m
&& mode
!= EGL_NO_MODE_MESA
)
883 return _eglError(EGL_BAD_MODE_MESA
, __FUNCTION__
);
885 return drv
->API
.ShowScreenSurfaceMESA(drv
, disp
, scrn
, surf
, m
);
890 eglScreenPositionMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLint x
, EGLint y
)
892 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
893 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
896 drv
= _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
);
897 return drv
->API
.ScreenPositionMESA(drv
, disp
, scrn
, x
, y
);
902 eglQueryScreenMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
903 EGLint attribute
, EGLint
*value
)
905 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
906 _EGLScreen
*scrn
= _eglLookupScreen(screen
, disp
);
909 drv
= _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
);
910 return drv
->API
.QueryScreenMESA(drv
, disp
, scrn
, attribute
, value
);
915 eglQueryScreenSurfaceMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
918 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
919 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
923 drv
= _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
);
925 if (drv
->API
.QueryScreenSurfaceMESA(drv
, disp
, scrn
, &surf
) != EGL_TRUE
)
928 *surface
= _eglGetSurfaceHandle(surf
);
929 return (surf
!= NULL
);
934 eglQueryScreenModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*mode
)
936 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
937 _EGLScreen
*scrn
= _eglLookupScreen((EGLScreenMESA
) screen
, disp
);
941 drv
= _EGL_CHECK_SCREEN(disp
, scrn
, EGL_FALSE
);
943 if (drv
->API
.QueryScreenModeMESA(drv
, disp
, scrn
, &m
) != EGL_TRUE
)
953 eglQueryModeStringMESA(EGLDisplay dpy
, EGLModeMESA mode
)
955 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
956 _EGLMode
*m
= _eglLookupMode(mode
, disp
);
959 drv
= _EGL_CHECK_MODE(disp
, m
, NULL
);
960 return drv
->API
.QueryModeStringMESA(drv
, disp
, m
);
964 #endif /* EGL_MESA_screen_surface */
971 #ifdef EGL_VERSION_1_2
975 * Specify the client API to use for subsequent calls including:
977 * eglGetCurrentContext()
978 * eglGetCurrentDisplay()
979 * eglGetCurrentSurface()
980 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
983 * See section 3.7 "Rendering Context" in the EGL specification for details.
986 eglBindAPI(EGLenum api
)
988 _EGLThreadInfo
*t
= _eglGetCurrentThread();
990 if (_eglIsCurrentThreadDummy())
991 return _eglError(EGL_BAD_ALLOC
, "eglBindAPI");
993 if (!_eglIsApiValid(api
))
994 return _eglError(EGL_BAD_PARAMETER
, "eglBindAPI");
996 t
->CurrentAPIIndex
= _eglConvertApiToIndex(api
);
1002 * Return the last value set with eglBindAPI().
1007 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1008 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1009 return _eglConvertApiFromIndex(t
->CurrentAPIIndex
);
1014 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
1015 EGLClientBuffer buffer
, EGLConfig config
,
1016 const EGLint
*attrib_list
)
1018 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
1019 _EGLConfig
*conf
= _eglLookupConfig(config
, disp
);
1023 drv
= _EGL_CHECK_CONFIG(disp
, conf
, EGL_NO_SURFACE
);
1025 surf
= drv
->API
.CreatePbufferFromClientBuffer(drv
, disp
, buftype
, buffer
,
1028 return _eglLinkSurface(surf
, disp
);
1030 return EGL_NO_SURFACE
;
1035 eglReleaseThread(void)
1037 /* unbind current contexts */
1038 if (!_eglIsCurrentThreadDummy()) {
1039 _EGLThreadInfo
*t
= _eglGetCurrentThread();
1040 EGLint api_index
= t
->CurrentAPIIndex
;
1043 for (i
= 0; i
< _EGL_API_NUM_APIS
; i
++) {
1044 _EGLContext
*ctx
= t
->CurrentContexts
[i
];
1046 _EGLDisplay
*disp
= ctx
->Resource
.Display
;
1047 _EGLDriver
*drv
= disp
->Driver
;
1048 t
->CurrentAPIIndex
= i
;
1049 (void) drv
->API
.MakeCurrent(drv
, disp
, NULL
, NULL
, NULL
);
1053 t
->CurrentAPIIndex
= api_index
;
1056 _eglDestroyCurrentThread();
1061 #endif /* EGL_VERSION_1_2 */
1064 #ifdef EGL_KHR_image_base
1068 eglCreateImageKHR(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
1069 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1071 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
1072 _EGLContext
*context
= _eglLookupContext(ctx
, disp
);
1076 drv
= _EGL_CHECK_DISPLAY(disp
, EGL_NO_IMAGE_KHR
);
1077 if (!context
&& ctx
!= EGL_NO_CONTEXT
) {
1078 _eglError(EGL_BAD_CONTEXT
, __FUNCTION__
);
1079 return EGL_NO_IMAGE_KHR
;
1082 img
= drv
->API
.CreateImageKHR(drv
,
1083 disp
, context
, target
, buffer
, attr_list
);
1085 return _eglLinkImage(img
, disp
);
1087 return EGL_NO_IMAGE_KHR
;
1091 EGLBoolean
eglDestroyImageKHR(EGLDisplay dpy
, EGLImageKHR image
)
1093 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
1094 _EGLImage
*img
= _eglLookupImage(image
, disp
);
1097 drv
= _EGL_CHECK_DISPLAY(disp
, EGL_FALSE
);
1099 return _eglError(EGL_BAD_PARAMETER
, __FUNCTION__
);
1101 _eglUnlinkImage(img
);
1102 return drv
->API
.DestroyImageKHR(drv
, disp
, img
);
1106 #endif /* EGL_KHR_image_base */