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
= _eglNewDisplay(nativeDisplay
);
55 return _eglGetDisplayHandle(dpy
);
60 * This is typically the second EGL function that an application calls.
61 * Here we load/initialize the actual hardware driver.
63 EGLBoolean EGLAPIENTRY
64 eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
)
66 EGLint major_int
, minor_int
;
70 _EGLDisplay
*dpyPriv
= _eglLookupDisplay(dpy
);
74 dpyPriv
->Driver
= _eglOpenDriver(dpyPriv
,
77 if (!dpyPriv
->Driver
) {
80 /* Initialize the particular driver now */
81 retVal
= dpyPriv
->Driver
->API
.Initialize(dpyPriv
->Driver
, dpy
,
82 &major_int
, &minor_int
);
84 dpyPriv
->Driver
->APImajor
= major_int
;
85 dpyPriv
->Driver
->APIminor
= minor_int
;
86 snprintf(dpyPriv
->Driver
->Version
, sizeof(dpyPriv
->Driver
->Version
),
87 "%d.%d (%s)", major_int
, minor_int
, dpyPriv
->Driver
->Name
);
89 /* Update applications version of major and minor if not NULL */
90 if((major
!= NULL
) && (minor
!= NULL
))
102 EGLBoolean EGLAPIENTRY
103 eglTerminate(EGLDisplay dpy
)
105 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
107 return _eglCloseDriver(drv
, dpy
);
113 const char * EGLAPIENTRY
114 eglQueryString(EGLDisplay dpy
, EGLint name
)
116 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
118 return drv
->API
.QueryString(drv
, dpy
, name
);
124 EGLBoolean EGLAPIENTRY
125 eglGetConfigs(EGLDisplay dpy
, EGLConfig
*configs
, EGLint config_size
, EGLint
*num_config
)
127 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
128 /* XXX check drv for null in remaining functions */
129 return drv
->API
.GetConfigs(drv
, dpy
, configs
, config_size
, num_config
);
133 EGLBoolean EGLAPIENTRY
134 eglChooseConfig(EGLDisplay dpy
, const EGLint
*attrib_list
, EGLConfig
*configs
, EGLint config_size
, EGLint
*num_config
)
136 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
137 return drv
->API
.ChooseConfig(drv
, dpy
, attrib_list
, configs
, config_size
, num_config
);
141 EGLBoolean EGLAPIENTRY
142 eglGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
, EGLint attribute
, EGLint
*value
)
144 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
145 return drv
->API
.GetConfigAttrib(drv
, dpy
, config
, attribute
, value
);
149 EGLContext EGLAPIENTRY
150 eglCreateContext(EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
, const EGLint
*attrib_list
)
152 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
153 return drv
->API
.CreateContext(drv
, dpy
, config
, share_list
, attrib_list
);
157 EGLBoolean EGLAPIENTRY
158 eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
)
160 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
161 return drv
->API
.DestroyContext(drv
, dpy
, ctx
);
165 EGLBoolean EGLAPIENTRY
166 eglMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
, EGLContext ctx
)
168 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
169 return drv
->API
.MakeCurrent(drv
, dpy
, draw
, read
, ctx
);
173 EGLBoolean EGLAPIENTRY
174 eglQueryContext(EGLDisplay dpy
, EGLContext ctx
, EGLint attribute
, EGLint
*value
)
176 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
177 return drv
->API
.QueryContext(drv
, dpy
, ctx
, attribute
, value
);
181 EGLSurface EGLAPIENTRY
182 eglCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
, NativeWindowType window
, const EGLint
*attrib_list
)
184 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
185 return drv
->API
.CreateWindowSurface(drv
, dpy
, config
, window
, attrib_list
);
189 EGLSurface EGLAPIENTRY
190 eglCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
, NativePixmapType pixmap
, const EGLint
*attrib_list
)
192 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
193 return drv
->API
.CreatePixmapSurface(drv
, dpy
, config
, pixmap
, attrib_list
);
197 EGLSurface EGLAPIENTRY
198 eglCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
, const EGLint
*attrib_list
)
200 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
201 return drv
->API
.CreatePbufferSurface(drv
, dpy
, config
, attrib_list
);
205 EGLBoolean EGLAPIENTRY
206 eglDestroySurface(EGLDisplay dpy
, EGLSurface surface
)
208 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
209 return drv
->API
.DestroySurface(drv
, dpy
, surface
);
213 EGLBoolean EGLAPIENTRY
214 eglQuerySurface(EGLDisplay dpy
, EGLSurface surface
, EGLint attribute
, EGLint
*value
)
216 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
217 return drv
->API
.QuerySurface(drv
, dpy
, surface
, attribute
, value
);
221 EGLBoolean EGLAPIENTRY
222 eglSurfaceAttrib(EGLDisplay dpy
, EGLSurface surface
, EGLint attribute
, EGLint value
)
224 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
225 return drv
->API
.SurfaceAttrib(drv
, dpy
, surface
, attribute
, value
);
229 EGLBoolean EGLAPIENTRY
230 eglBindTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
232 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
233 return drv
->API
.BindTexImage(drv
, dpy
, surface
, buffer
);
237 EGLBoolean EGLAPIENTRY
238 eglReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
240 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
241 return drv
->API
.ReleaseTexImage(drv
, dpy
, surface
, buffer
);
245 EGLBoolean EGLAPIENTRY
246 eglSwapInterval(EGLDisplay dpy
, EGLint interval
)
248 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
249 return drv
->API
.SwapInterval(drv
, dpy
, interval
);
253 EGLBoolean EGLAPIENTRY
254 eglSwapBuffers(EGLDisplay dpy
, EGLSurface draw
)
256 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
257 return drv
->API
.SwapBuffers(drv
, dpy
, draw
);
261 EGLBoolean EGLAPIENTRY
262 eglCopyBuffers(EGLDisplay dpy
, EGLSurface surface
, NativePixmapType target
)
264 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
265 return drv
->API
.CopyBuffers(drv
, dpy
, surface
, target
);
269 EGLBoolean EGLAPIENTRY
272 EGLDisplay dpy
= eglGetCurrentDisplay();
273 if (dpy
!= EGL_NO_DISPLAY
) {
274 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
275 return drv
->API
.WaitGL(drv
, dpy
);
282 EGLBoolean EGLAPIENTRY
283 eglWaitNative(EGLint engine
)
285 EGLDisplay dpy
= eglGetCurrentDisplay();
286 if (dpy
!= EGL_NO_DISPLAY
) {
287 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
288 return drv
->API
.WaitNative(drv
, dpy
, engine
);
295 EGLDisplay EGLAPIENTRY
296 eglGetCurrentDisplay(void)
298 _EGLDisplay
*dpy
= _eglGetCurrentDisplay();
299 return _eglGetDisplayHandle(dpy
);
303 EGLContext EGLAPIENTRY
304 eglGetCurrentContext(void)
306 _EGLContext
*ctx
= _eglGetCurrentContext();
307 return _eglGetContextHandle(ctx
);
311 EGLSurface EGLAPIENTRY
312 eglGetCurrentSurface(EGLint readdraw
)
314 _EGLSurface
*s
= _eglGetCurrentSurface(readdraw
);
315 return _eglGetSurfaceHandle(s
);
322 _EGLThreadInfo
*t
= _eglGetCurrentThread();
323 EGLint e
= t
->LastError
;
324 t
->LastError
= EGL_SUCCESS
;
329 void (* EGLAPIENTRY
eglGetProcAddress(const char *procname
))()
331 typedef void (*genericFunc
)();
332 struct name_function
{
336 static struct name_function egl_functions
[] = {
337 /* alphabetical order */
338 { "eglBindTexImage", (_EGLProc
) eglBindTexImage
},
339 { "eglChooseConfig", (_EGLProc
) eglChooseConfig
},
340 { "eglCopyBuffers", (_EGLProc
) eglCopyBuffers
},
341 { "eglCreateContext", (_EGLProc
) eglCreateContext
},
342 { "eglCreatePbufferSurface", (_EGLProc
) eglCreatePbufferSurface
},
343 { "eglCreatePixmapSurface", (_EGLProc
) eglCreatePixmapSurface
},
344 { "eglCreateWindowSurface", (_EGLProc
) eglCreateWindowSurface
},
345 { "eglDestroyContext", (_EGLProc
) eglDestroyContext
},
346 { "eglDestroySurface", (_EGLProc
) eglDestroySurface
},
347 { "eglGetConfigAttrib", (_EGLProc
) eglGetConfigAttrib
},
348 { "eglGetConfigs", (_EGLProc
) eglGetConfigs
},
349 { "eglGetCurrentContext", (_EGLProc
) eglGetCurrentContext
},
350 { "eglGetCurrentDisplay", (_EGLProc
) eglGetCurrentDisplay
},
351 { "eglGetCurrentSurface", (_EGLProc
) eglGetCurrentSurface
},
352 { "eglGetDisplay", (_EGLProc
) eglGetDisplay
},
353 { "eglGetError", (_EGLProc
) eglGetError
},
354 { "eglGetProcAddress", (_EGLProc
) eglGetProcAddress
},
355 { "eglInitialize", (_EGLProc
) eglInitialize
},
356 { "eglMakeCurrent", (_EGLProc
) eglMakeCurrent
},
357 { "eglQueryContext", (_EGLProc
) eglQueryContext
},
358 { "eglQueryString", (_EGLProc
) eglQueryString
},
359 { "eglQuerySurface", (_EGLProc
) eglQuerySurface
},
360 { "eglReleaseTexImage", (_EGLProc
) eglReleaseTexImage
},
361 { "eglSurfaceAttrib", (_EGLProc
) eglSurfaceAttrib
},
362 { "eglSwapBuffers", (_EGLProc
) eglSwapBuffers
},
363 { "eglSwapInterval", (_EGLProc
) eglSwapInterval
},
364 { "eglTerminate", (_EGLProc
) eglTerminate
},
365 { "eglWaitGL", (_EGLProc
) eglWaitGL
},
366 { "eglWaitNative", (_EGLProc
) eglWaitNative
},
368 #ifdef EGL_MESA_screen_surface
369 { "eglChooseModeMESA", (_EGLProc
) eglChooseModeMESA
},
370 { "eglGetModesMESA", (_EGLProc
) eglGetModesMESA
},
371 { "eglGetModeAttribMESA", (_EGLProc
) eglGetModeAttribMESA
},
372 { "eglCopyContextMESA", (_EGLProc
) eglCopyContextMESA
},
373 { "eglGetScreensMESA", (_EGLProc
) eglGetScreensMESA
},
374 { "eglCreateScreenSurfaceMESA", (_EGLProc
) eglCreateScreenSurfaceMESA
},
375 { "eglShowScreenSurfaceMESA", (_EGLProc
) eglShowScreenSurfaceMESA
},
376 { "eglScreenPositionMESA", (_EGLProc
) eglScreenPositionMESA
},
377 { "eglQueryScreenMESA", (_EGLProc
) eglQueryScreenMESA
},
378 { "eglQueryScreenSurfaceMESA", (_EGLProc
) eglQueryScreenSurfaceMESA
},
379 { "eglQueryScreenModeMESA", (_EGLProc
) eglQueryScreenModeMESA
},
380 { "eglQueryModeStringMESA", (_EGLProc
) eglQueryModeStringMESA
},
381 #endif /* EGL_MESA_screen_surface */
382 #ifdef EGL_VERSION_1_2
383 { "eglBindAPI", (_EGLProc
) eglBindAPI
},
384 { "eglCreatePbufferFromClientBuffer", (_EGLProc
) eglCreatePbufferFromClientBuffer
},
385 { "eglQueryAPI", (_EGLProc
) eglQueryAPI
},
386 { "eglReleaseThread", (_EGLProc
) eglReleaseThread
},
387 { "eglWaitClient", (_EGLProc
) eglWaitClient
},
388 #endif /* EGL_VERSION_1_2 */
392 for (i
= 0; egl_functions
[i
].name
; i
++) {
393 if (strcmp(egl_functions
[i
].name
, procname
) == 0) {
394 return (genericFunc
) egl_functions
[i
].function
;
398 /* now loop over drivers to query their procs */
399 for (i
= 0; i
< _eglGlobal
.NumDrivers
; i
++) {
400 _EGLProc p
= _eglGlobal
.Drivers
[i
]->API
.GetProcAddress(procname
);
410 * EGL_MESA_screen extension
413 EGLBoolean EGLAPIENTRY
414 eglChooseModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
,
415 const EGLint
*attrib_list
, EGLModeMESA
*modes
,
416 EGLint modes_size
, EGLint
*num_modes
)
418 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
420 return drv
->API
.ChooseModeMESA(drv
, dpy
, screen
, attrib_list
, modes
, modes_size
, num_modes
);
426 EGLBoolean EGLAPIENTRY
427 eglGetModesMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*modes
, EGLint mode_size
, EGLint
*num_mode
)
429 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
431 return drv
->API
.GetModesMESA(drv
, dpy
, screen
, modes
, mode_size
, num_mode
);
437 EGLBoolean EGLAPIENTRY
438 eglGetModeAttribMESA(EGLDisplay dpy
, EGLModeMESA mode
, EGLint attribute
, EGLint
*value
)
440 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
442 return drv
->API
.GetModeAttribMESA(drv
, dpy
, mode
, attribute
, value
);
448 EGLBoolean EGLAPIENTRY
449 eglCopyContextMESA(EGLDisplay dpy
, EGLContext source
, EGLContext dest
, EGLint mask
)
451 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
453 return drv
->API
.CopyContextMESA(drv
, dpy
, source
, dest
, mask
);
460 eglGetScreensMESA(EGLDisplay dpy
, EGLScreenMESA
*screens
, EGLint max_screens
, EGLint
*num_screens
)
462 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
464 return drv
->API
.GetScreensMESA(drv
, dpy
, screens
, max_screens
, num_screens
);
471 eglCreateScreenSurfaceMESA(EGLDisplay dpy
, EGLConfig config
, const EGLint
*attrib_list
)
473 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
474 return drv
->API
.CreateScreenSurfaceMESA(drv
, dpy
, config
, attrib_list
);
479 eglShowScreenSurfaceMESA(EGLDisplay dpy
, EGLint screen
, EGLSurface surface
, EGLModeMESA mode
)
481 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
482 return drv
->API
.ShowScreenSurfaceMESA(drv
, dpy
, screen
, surface
, mode
);
487 eglScreenPositionMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLint x
, EGLint y
)
489 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
490 return drv
->API
.ScreenPositionMESA(drv
, dpy
, screen
, x
, y
);
495 eglQueryScreenMESA( EGLDisplay dpy
, EGLScreenMESA screen
, EGLint attribute
, EGLint
*value
)
497 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
498 return drv
->API
.QueryScreenMESA(drv
, dpy
, screen
, attribute
, value
);
503 eglQueryScreenSurfaceMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLSurface
*surface
)
505 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
506 return drv
->API
.QueryScreenSurfaceMESA(drv
, dpy
, screen
, surface
);
511 eglQueryScreenModeMESA(EGLDisplay dpy
, EGLScreenMESA screen
, EGLModeMESA
*mode
)
513 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
514 return drv
->API
.QueryScreenModeMESA(drv
, dpy
, screen
, mode
);
519 eglQueryModeStringMESA(EGLDisplay dpy
, EGLModeMESA mode
)
521 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
522 return drv
->API
.QueryModeStringMESA(drv
, dpy
, mode
);
530 #ifdef EGL_VERSION_1_2
534 * Specify the client API to use for subsequent calls including:
536 * eglGetCurrentContext()
537 * eglGetCurrentDisplay()
538 * eglGetCurrentSurface()
539 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
542 * See section 3.7 "Rendering Context" in the EGL specification for details.
545 eglBindAPI(EGLenum api
)
547 _EGLThreadInfo
*t
= _eglGetCurrentThread();
550 #ifdef EGL_VERSION_1_4
552 if (_eglGlobal
.ClientAPIsMask
& EGL_OPENGL_BIT
) {
556 _eglError(EGL_BAD_PARAMETER
, "eglBindAPI");
559 case EGL_OPENGL_ES_API
:
560 if (_eglGlobal
.ClientAPIsMask
& (EGL_OPENGL_ES_BIT
| EGL_OPENGL_ES2_BIT
)) {
564 _eglError(EGL_BAD_PARAMETER
, "eglBindAPI");
567 if (_eglGlobal
.ClientAPIsMask
& EGL_OPENVG_BIT
) {
571 _eglError(EGL_BAD_PARAMETER
, "eglBindAPI");
581 * Return the last value set with eglBindAPI().
586 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
587 _EGLThreadInfo
*t
= _eglGetCurrentThread();
588 return t
->CurrentAPI
;
593 eglCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
594 EGLClientBuffer buffer
, EGLConfig config
,
595 const EGLint
*attrib_list
)
597 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
598 return drv
->API
.CreatePbufferFromClientBuffer(drv
, dpy
, buftype
, buffer
,
599 config
, attrib_list
);
604 eglReleaseThread(void)
606 _EGLThreadInfo
*t
= _eglGetCurrentThread();
607 EGLDisplay dpy
= eglGetCurrentDisplay();
609 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
611 (void) drv
->API
.MakeCurrent(drv
, dpy
, EGL_NO_SURFACE
,
612 EGL_NO_SURFACE
, EGL_NO_CONTEXT
);
614 _eglDeleteThreadData(t
);
622 EGLDisplay dpy
= eglGetCurrentDisplay();
623 if (dpy
!= EGL_NO_DISPLAY
) {
624 _EGLDriver
*drv
= _eglLookupDriver(dpy
);
625 return drv
->API
.WaitClient(drv
, dpy
);
631 #endif /* EGL_VERSION_1_2 */