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 implemented with 32-bit unsigned integers.
13 * It's up to the driver function or fallback function to look up the
14 * handle and get an object.
15 * By using opaque handles, we leave open the possibility of having
16 * indirect rendering in the future, like GLX.
19 * Notes on naming conventions:
21 * eglFooBar - public EGL function
22 * EGL_FOO_BAR - public EGL token
23 * EGLDatatype - public EGL datatype
25 * _eglFooBar - private EGL function
26 * _EGLDatatype - private EGL datatype, typedef'd struct
27 * _egl_struct - private EGL struct, non-typedef'd
36 #include "eglcontext.h"
37 #include "egldisplay.h"
38 #include "egltypedefs.h"
39 #include "eglglobals.h"
40 #include "egldriver.h"
41 #include "eglsurface.h"
46 * This is typically the first EGL function that an application calls.
47 * We initialize our global vars and create a private _EGLDisplay object.
49 EGLDisplay EGLAPIENTRY
50 eglGetDisplay(NativeDisplayType nativeDisplay
)
54 dpy
= _eglFindDisplay(nativeDisplay
);
56 dpy
= _eglNewDisplay(nativeDisplay
);
60 return _eglGetDisplayHandle(dpy
);
65 * This is typically the second EGL function that an application calls.
66 * Here we load/initialize the actual hardware driver.
68 EGLBoolean EGLAPIENTRY
69 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
71 EGLint major_int
, minor_int
;
75 _EGLDisplay
*dpyPriv
= _eglLookupDisplay(dpy
);
79 dpyPriv
->Driver
= _eglOpenDriver(dpyPriv
,
82 if (!dpyPriv
->Driver
) {
85 /* Initialize the particular driver now */
86 retVal
= dpyPriv
->Driver
->API
.Initialize(dpyPriv
->Driver
, dpy
,
87 &major_int
, &minor_int
);
89 dpyPriv
->Driver
->APImajor
= major_int
;
90 dpyPriv
->Driver
->APIminor
= minor_int
;
91 snprintf(dpyPriv
->Driver
->Version
, sizeof(dpyPriv
->Driver
->Version
),
92 "%d.%d (%s)", major_int
, minor_int
, dpyPriv
->Driver
->Name
);
94 /* Update applications version of major and minor if not NULL */
95 if((major
!= NULL
) && (minor
!= NULL
))
107 EGLBoolean EGLAPIENTRY
108 eglTerminate(EGLDisplay dpy
)
110 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
112 return _eglCloseDriver(drv
, dpy
);
118 const char * EGLAPIENTRY
119 eglQueryString(EGLDisplay dpy
, EGLint name
)
121 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
123 return drv
->API
.QueryString(drv
, dpy
, name
);
129 EGLBoolean EGLAPIENTRY
130 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
, EGLint config_size
, EGLint
*num_config
)
132 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
133 /* XXX check drv for null in remaining functions */
134 return drv
->API
.GetConfigs(drv
, dpy
, configs
, config_size
, num_config
);
138 EGLBoolean EGLAPIENTRY
139 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
, EGLint config_size
, EGLint
*num_config
)
141 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
142 return drv
->API
.ChooseConfig(drv
, dpy
, attrib_list
, configs
, config_size
, num_config
);
146 EGLBoolean EGLAPIENTRY
147 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
, EGLint attribute
, EGLint
*value
)
149 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
150 return drv
->API
.GetConfigAttrib(drv
, dpy
, config
, attribute
, value
);
154 EGLContext EGLAPIENTRY
155 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
, const EGLint
*attrib_list
)
157 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
158 return drv
->API
.CreateContext(drv
, dpy
, config
, share_list
, attrib_list
);
162 EGLBoolean EGLAPIENTRY
163 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
165 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
166 return drv
->API
.DestroyContext(drv
, dpy
, ctx
);
170 EGLBoolean EGLAPIENTRY
171 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
, EGLContext ctx
)
173 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
174 return drv
->API
.MakeCurrent(drv
, dpy
, draw
, read
, ctx
);
178 EGLBoolean EGLAPIENTRY
179 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
, EGLint attribute
, EGLint
*value
)
181 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
182 return drv
->API
.QueryContext(drv
, dpy
, ctx
, attribute
, value
);
186 EGLSurface EGLAPIENTRY
187 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
, NativeWindowType window
, const EGLint
*attrib_list
)
189 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
190 return drv
->API
.CreateWindowSurface(drv
, dpy
, config
, window
, attrib_list
);
194 EGLSurface EGLAPIENTRY
195 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
, NativePixmapType pixmap
, const EGLint
*attrib_list
)
197 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
198 return drv
->API
.CreatePixmapSurface(drv
, dpy
, config
, pixmap
, attrib_list
);
202 EGLSurface EGLAPIENTRY
203 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
, const EGLint
*attrib_list
)
205 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
206 return drv
->API
.CreatePbufferSurface(drv
, dpy
, config
, attrib_list
);
210 EGLBoolean EGLAPIENTRY
211 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
213 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
214 return drv
->API
.DestroySurface(drv
, dpy
, surface
);
218 EGLBoolean EGLAPIENTRY
219 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
, EGLint attribute
, EGLint
*value
)
221 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
222 return drv
->API
.QuerySurface(drv
, dpy
, surface
, attribute
, value
);
226 EGLBoolean EGLAPIENTRY
227 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
, EGLint attribute
, EGLint value
)
229 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
230 return drv
->API
.SurfaceAttrib(drv
, dpy
, surface
, attribute
, value
);
234 EGLBoolean EGLAPIENTRY
235 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
237 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
238 return drv
->API
.BindTexImage(drv
, dpy
, surface
, buffer
);
242 EGLBoolean EGLAPIENTRY
243 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
245 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
246 return drv
->API
.ReleaseTexImage(drv
, dpy
, surface
, buffer
);
250 EGLBoolean EGLAPIENTRY
251 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
253 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
254 return drv
->API
.SwapInterval(drv
, dpy
, interval
);
258 EGLBoolean EGLAPIENTRY
259 eglSwapBuffers(EGLDisplay dpy
, EGLSurface draw
)
261 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
262 return drv
->API
.SwapBuffers(drv
, dpy
, draw
);
266 EGLBoolean EGLAPIENTRY
267 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, NativePixmapType target
)
269 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
270 return drv
->API
.CopyBuffers(drv
, dpy
, surface
, target
);
274 EGLBoolean EGLAPIENTRY
277 EGLDisplay dpy
= eglGetCurrentDisplay();
278 if (dpy
!= EGL_NO_DISPLAY
) {
279 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
280 return drv
->API
.WaitGL(drv
, dpy
);
287 EGLBoolean EGLAPIENTRY
288 eglWaitNative(EGLint engine
)
290 EGLDisplay dpy
= eglGetCurrentDisplay();
291 if (dpy
!= EGL_NO_DISPLAY
) {
292 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
293 return drv
->API
.WaitNative(drv
, dpy
, engine
);
300 EGLDisplay EGLAPIENTRY
301 eglGetCurrentDisplay(void)
303 _EGLDisplay
*dpy
= _eglGetCurrentDisplay();
304 return _eglGetDisplayHandle(dpy
);
308 EGLContext EGLAPIENTRY
309 eglGetCurrentContext(void)
311 _EGLContext
*ctx
= _eglGetCurrentContext();
312 return _eglGetContextHandle(ctx
);
316 EGLSurface EGLAPIENTRY
317 eglGetCurrentSurface(EGLint readdraw
)
319 _EGLSurface
*s
= _eglGetCurrentSurface(readdraw
);
320 return _eglGetSurfaceHandle(s
);
327 _EGLThreadInfo
*t
= _eglGetCurrentThread();
328 EGLint e
= t
->LastError
;
329 if (!_eglIsCurrentThreadDummy())
330 t
->LastError
= EGL_SUCCESS
;
335 void (* EGLAPIENTRY
eglGetProcAddress(const char *procname
))()
337 typedef void (*genericFunc
)();
338 struct name_function
{
342 static struct name_function egl_functions
[] = {
343 /* alphabetical order */
344 { "eglBindTexImage", (_EGLProc
) eglBindTexImage
},
345 { "eglChooseConfig", (_EGLProc
) eglChooseConfig
},
346 { "eglCopyBuffers", (_EGLProc
) eglCopyBuffers
},
347 { "eglCreateContext", (_EGLProc
) eglCreateContext
},
348 { "eglCreatePbufferSurface", (_EGLProc
) eglCreatePbufferSurface
},
349 { "eglCreatePixmapSurface", (_EGLProc
) eglCreatePixmapSurface
},
350 { "eglCreateWindowSurface", (_EGLProc
) eglCreateWindowSurface
},
351 { "eglDestroyContext", (_EGLProc
) eglDestroyContext
},
352 { "eglDestroySurface", (_EGLProc
) eglDestroySurface
},
353 { "eglGetConfigAttrib", (_EGLProc
) eglGetConfigAttrib
},
354 { "eglGetConfigs", (_EGLProc
) eglGetConfigs
},
355 { "eglGetCurrentContext", (_EGLProc
) eglGetCurrentContext
},
356 { "eglGetCurrentDisplay", (_EGLProc
) eglGetCurrentDisplay
},
357 { "eglGetCurrentSurface", (_EGLProc
) eglGetCurrentSurface
},
358 { "eglGetDisplay", (_EGLProc
) eglGetDisplay
},
359 { "eglGetError", (_EGLProc
) eglGetError
},
360 { "eglGetProcAddress", (_EGLProc
) eglGetProcAddress
},
361 { "eglInitialize", (_EGLProc
) eglInitialize
},
362 { "eglMakeCurrent", (_EGLProc
) eglMakeCurrent
},
363 { "eglQueryContext", (_EGLProc
) eglQueryContext
},
364 { "eglQueryString", (_EGLProc
) eglQueryString
},
365 { "eglQuerySurface", (_EGLProc
) eglQuerySurface
},
366 { "eglReleaseTexImage", (_EGLProc
) eglReleaseTexImage
},
367 { "eglSurfaceAttrib", (_EGLProc
) eglSurfaceAttrib
},
368 { "eglSwapBuffers", (_EGLProc
) eglSwapBuffers
},
369 { "eglSwapInterval", (_EGLProc
) eglSwapInterval
},
370 { "eglTerminate", (_EGLProc
) eglTerminate
},
371 { "eglWaitGL", (_EGLProc
) eglWaitGL
},
372 { "eglWaitNative", (_EGLProc
) eglWaitNative
},
374 #ifdef EGL_MESA_screen_surface
375 { "eglChooseModeMESA", (_EGLProc
) eglChooseModeMESA
},
376 { "eglGetModesMESA", (_EGLProc
) eglGetModesMESA
},
377 { "eglGetModeAttribMESA", (_EGLProc
) eglGetModeAttribMESA
},
378 { "eglCopyContextMESA", (_EGLProc
) eglCopyContextMESA
},
379 { "eglGetScreensMESA", (_EGLProc
) eglGetScreensMESA
},
380 { "eglCreateScreenSurfaceMESA", (_EGLProc
) eglCreateScreenSurfaceMESA
},
381 { "eglShowScreenSurfaceMESA", (_EGLProc
) eglShowScreenSurfaceMESA
},
382 { "eglScreenPositionMESA", (_EGLProc
) eglScreenPositionMESA
},
383 { "eglQueryScreenMESA", (_EGLProc
) eglQueryScreenMESA
},
384 { "eglQueryScreenSurfaceMESA", (_EGLProc
) eglQueryScreenSurfaceMESA
},
385 { "eglQueryScreenModeMESA", (_EGLProc
) eglQueryScreenModeMESA
},
386 { "eglQueryModeStringMESA", (_EGLProc
) eglQueryModeStringMESA
},
387 #endif /* EGL_MESA_screen_surface */
388 #ifdef EGL_VERSION_1_2
389 { "eglBindAPI", (_EGLProc
) eglBindAPI
},
390 { "eglCreatePbufferFromClientBuffer", (_EGLProc
) eglCreatePbufferFromClientBuffer
},
391 { "eglQueryAPI", (_EGLProc
) eglQueryAPI
},
392 { "eglReleaseThread", (_EGLProc
) eglReleaseThread
},
393 { "eglWaitClient", (_EGLProc
) eglWaitClient
},
394 #endif /* EGL_VERSION_1_2 */
398 for (i
= 0; egl_functions
[i
].name
; i
++) {
399 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
400 return (genericFunc
) egl_functions
[i
].function
;
404 /* now loop over drivers to query their procs */
405 for (i
= 0; i
< _eglGlobal
.NumDrivers
; i
++) {
406 _EGLProc p
= _eglGlobal
.Drivers
[i
]->API
.GetProcAddress(procname
);
416 * EGL_MESA_screen extension
419 EGLBoolean EGLAPIENTRY
420 eglChooseModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
421 const EGLint
*attrib_list
, EGLModeMESA
*modes
,
422 EGLint modes_size
, EGLint
*num_modes
)
424 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
426 return drv
->API
.ChooseModeMESA(drv
, dpy
, screen
, attrib_list
, modes
, modes_size
, num_modes
);
432 EGLBoolean EGLAPIENTRY
433 eglGetModesMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*modes
, EGLint mode_size
, EGLint
*num_mode
)
435 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
437 return drv
->API
.GetModesMESA(drv
, dpy
, screen
, modes
, mode_size
, num_mode
);
443 EGLBoolean EGLAPIENTRY
444 eglGetModeAttribMESA(EGLDisplay dpy
, EGLModeMESA mode
, EGLint attribute
, EGLint
*value
)
446 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
448 return drv
->API
.GetModeAttribMESA(drv
, dpy
, mode
, attribute
, value
);
454 EGLBoolean EGLAPIENTRY
455 eglCopyContextMESA(EGLDisplay dpy
, EGLContext source
, EGLContext dest
, EGLint mask
)
457 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
459 return drv
->API
.CopyContextMESA(drv
, dpy
, source
, dest
, mask
);
466 eglGetScreensMESA(EGLDisplay dpy
, EGLScreenMESA
*screens
, EGLint max_screens
, EGLint
*num_screens
)
468 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
470 return drv
->API
.GetScreensMESA(drv
, dpy
, screens
, max_screens
, num_screens
);
477 eglCreateScreenSurfaceMESA(EGLDisplay dpy
, EGLConfig config
, const EGLint
*attrib_list
)
479 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
480 return drv
->API
.CreateScreenSurfaceMESA(drv
, dpy
, config
, attrib_list
);
485 eglShowScreenSurfaceMESA(EGLDisplay dpy
, EGLint screen
, EGLSurface surface
, EGLModeMESA mode
)
487 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
488 return drv
->API
.ShowScreenSurfaceMESA(drv
, dpy
, screen
, surface
, mode
);
493 eglScreenPositionMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLint x
, EGLint y
)
495 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
496 return drv
->API
.ScreenPositionMESA(drv
, dpy
, screen
, x
, y
);
501 eglQueryScreenMESA( EGLDisplay dpy
, EGLScreenMESA screen
, EGLint attribute
, EGLint
*value
)
503 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
504 return drv
->API
.QueryScreenMESA(drv
, dpy
, screen
, attribute
, value
);
509 eglQueryScreenSurfaceMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLSurface
*surface
)
511 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
512 return drv
->API
.QueryScreenSurfaceMESA(drv
, dpy
, screen
, surface
);
517 eglQueryScreenModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*mode
)
519 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
520 return drv
->API
.QueryScreenModeMESA(drv
, dpy
, screen
, mode
);
525 eglQueryModeStringMESA(EGLDisplay dpy
, EGLModeMESA mode
)
527 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
528 return drv
->API
.QueryModeStringMESA(drv
, dpy
, mode
);
536 #ifdef EGL_VERSION_1_2
540 * Specify the client API to use for subsequent calls including:
542 * eglGetCurrentContext()
543 * eglGetCurrentDisplay()
544 * eglGetCurrentSurface()
545 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
548 * See section 3.7 "Rendering Context" in the EGL specification for details.
551 eglBindAPI(EGLenum api
)
553 _EGLThreadInfo
*t
= _eglGetCurrentThread();
555 if (_eglIsCurrentThreadDummy())
556 return _eglError(EGL_BAD_ALLOC
, "eglBindAPI");
558 if (!_eglIsApiValid(api
))
559 return _eglError(EGL_BAD_PARAMETER
, "eglBindAPI");
562 #ifdef EGL_VERSION_1_4
564 if (_eglGlobal
.ClientAPIsMask
& EGL_OPENGL_BIT
) {
565 t
->CurrentAPIIndex
= _eglConvertApiToIndex(api
);
568 _eglError(EGL_BAD_PARAMETER
, "eglBindAPI");
571 case EGL_OPENGL_ES_API
:
572 if (_eglGlobal
.ClientAPIsMask
& (EGL_OPENGL_ES_BIT
| EGL_OPENGL_ES2_BIT
)) {
573 t
->CurrentAPIIndex
= _eglConvertApiToIndex(api
);
576 _eglError(EGL_BAD_PARAMETER
, "eglBindAPI");
579 if (_eglGlobal
.ClientAPIsMask
& EGL_OPENVG_BIT
) {
580 t
->CurrentAPIIndex
= _eglConvertApiToIndex(api
);
583 _eglError(EGL_BAD_PARAMETER
, "eglBindAPI");
593 * Return the last value set with eglBindAPI().
598 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
599 _EGLThreadInfo
*t
= _eglGetCurrentThread();
600 return _eglConvertApiFromIndex(t
->CurrentAPIIndex
);
605 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
606 EGLClientBuffer buffer
, EGLConfig config
,
607 const EGLint
*attrib_list
)
609 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
610 return drv
->API
.CreatePbufferFromClientBuffer(drv
, dpy
, buftype
, buffer
,
611 config
, attrib_list
);
616 eglReleaseThread(void)
620 if (_eglIsCurrentThreadDummy())
623 dpy
= eglGetCurrentDisplay();
625 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
627 (void) drv
->API
.MakeCurrent(drv
, dpy
, EGL_NO_SURFACE
,
628 EGL_NO_SURFACE
, EGL_NO_CONTEXT
);
630 _eglDestroyCurrentThread();
638 EGLDisplay dpy
= eglGetCurrentDisplay();
639 if (dpy
!= EGL_NO_DISPLAY
) {
640 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
641 return drv
->API
.WaitClient(drv
, dpy
);
647 #endif /* EGL_VERSION_1_2 */