0be901c125e7b2524aa27021aecd4d0b9dd13636
[mesa.git] / src / egl / main / eglapi.c
1 /**
2 * Public EGL API entrypoints
3 *
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.
7 *
8 * That allows us the option of supporting multiple, simultaneous,
9 * heterogeneous hardware devices in the future.
10 *
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.
17 *
18 *
19 * Notes on naming conventions:
20 *
21 * eglFooBar - public EGL function
22 * EGL_FOO_BAR - public EGL token
23 * EGLDatatype - public EGL datatype
24 *
25 * _eglFooBar - private EGL function
26 * _EGLDatatype - private EGL datatype, typedef'd struct
27 * _egl_struct - private EGL struct, non-typedef'd
28 *
29 */
30
31
32
33 #include <stdio.h>
34 #include <string.h>
35 /**#include "glapi.h"**/
36 #include "eglcontext.h"
37 #include "egldisplay.h"
38 #include "egltypedefs.h"
39 #include "eglglobals.h"
40 #include "egldriver.h"
41 #include "eglsurface.h"
42
43
44
45 /**
46 * NOTE: displayName is treated as a string in _eglChooseDriver()!!!
47 * This will probably change!
48 * See _eglChooseDriver() for details!
49 */
50 EGLDisplay APIENTRY
51 eglGetDisplay(NativeDisplayType displayName)
52 {
53 _EGLDisplay *dpy;
54 _eglInitGlobals();
55 dpy = _eglNewDisplay(displayName);
56 if (dpy)
57 return dpy->Handle;
58 else
59 return EGL_NO_DISPLAY;
60 }
61
62
63 EGLBoolean APIENTRY
64 eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
65 {
66 if (dpy) {
67 _EGLDriver *drv = _eglChooseDriver(dpy);
68 if (drv)
69 return drv->Initialize(drv, dpy, major, minor);
70 }
71 return EGL_FALSE;
72 }
73
74
75 EGLBoolean APIENTRY
76 eglTerminate(EGLDisplay dpy)
77 {
78 _EGLDriver *drv = _eglLookupDriver(dpy);
79 if (drv)
80 return _eglCloseDriver(drv, dpy);
81 else
82 return EGL_FALSE;
83 }
84
85
86 const char * APIENTRY
87 eglQueryString(EGLDisplay dpy, EGLint name)
88 {
89 _EGLDriver *drv = _eglLookupDriver(dpy);
90 if (drv)
91 return drv->QueryString(drv, dpy, name);
92 else
93 return NULL;
94 }
95
96
97 EGLBoolean APIENTRY
98 eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)
99 {
100 _EGLDriver *drv = _eglLookupDriver(dpy);
101 /* XXX check drv for null in remaining functions */
102 return drv->GetConfigs(drv, dpy, configs, config_size, num_config);
103 }
104
105
106 EGLBoolean APIENTRY
107 eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
108 {
109 _EGLDriver *drv = _eglLookupDriver(dpy);
110 return drv->ChooseConfig(drv, dpy, attrib_list, configs, config_size, num_config);
111 }
112
113
114 EGLBoolean APIENTRY
115 eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
116 {
117 _EGLDriver *drv = _eglLookupDriver(dpy);
118 return drv->GetConfigAttrib(drv, dpy, config, attribute, value);
119 }
120
121
122 EGLContext APIENTRY
123 eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list)
124 {
125 _EGLDriver *drv = _eglLookupDriver(dpy);
126 return drv->CreateContext(drv, dpy, config, share_list, attrib_list);
127 }
128
129
130 EGLBoolean APIENTRY
131 eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
132 {
133 _EGLDriver *drv = _eglLookupDriver(dpy);
134 return drv->DestroyContext(drv, dpy, ctx);
135 }
136
137
138 EGLBoolean APIENTRY
139 eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
140 {
141 _EGLDriver *drv = _eglLookupDriver(dpy);
142 return drv->MakeCurrent(drv, dpy, draw, read, ctx);
143 }
144
145
146 EGLBoolean APIENTRY
147 eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value)
148 {
149 _EGLDriver *drv = _eglLookupDriver(dpy);
150 return drv->QueryContext(drv, dpy, ctx, attribute, value);
151 }
152
153
154 EGLSurface APIENTRY
155 eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list)
156 {
157 _EGLDriver *drv = _eglLookupDriver(dpy);
158 return drv->CreateWindowSurface(drv, dpy, config, window, attrib_list);
159 }
160
161
162 EGLSurface APIENTRY
163 eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, NativePixmapType pixmap, const EGLint *attrib_list)
164 {
165 _EGLDriver *drv = _eglLookupDriver(dpy);
166 return drv->CreatePixmapSurface(drv, dpy, config, pixmap, attrib_list);
167 }
168
169
170 EGLSurface APIENTRY
171 eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
172 {
173 _EGLDriver *drv = _eglLookupDriver(dpy);
174 return drv->CreatePbufferSurface(drv, dpy, config, attrib_list);
175 }
176
177
178 EGLBoolean APIENTRY
179 eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
180 {
181 _EGLDriver *drv = _eglLookupDriver(dpy);
182 return drv->DestroySurface(drv, dpy, surface);
183 }
184
185
186 EGLBoolean APIENTRY
187 eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value)
188 {
189 _EGLDriver *drv = _eglLookupDriver(dpy);
190 return drv->QuerySurface(drv, dpy, surface, attribute, value);
191 }
192
193
194 EGLBoolean APIENTRY
195 eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
196 {
197 _EGLDriver *drv = _eglLookupDriver(dpy);
198 return drv->SurfaceAttrib(drv, dpy, surface, attribute, value);
199 }
200
201
202 EGLBoolean APIENTRY
203 eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
204 {
205 _EGLDriver *drv = _eglLookupDriver(dpy);
206 return drv->BindTexImage(drv, dpy, surface, buffer);
207 }
208
209
210 EGLBoolean APIENTRY
211 eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
212 {
213 _EGLDriver *drv = _eglLookupDriver(dpy);
214 return drv->ReleaseTexImage(drv, dpy, surface, buffer);
215 }
216
217
218 EGLBoolean APIENTRY
219 eglSwapInterval(EGLDisplay dpy, EGLint interval)
220 {
221 _EGLDriver *drv = _eglLookupDriver(dpy);
222 return drv->SwapInterval(drv, dpy, interval);
223 }
224
225
226 EGLBoolean APIENTRY
227 eglSwapBuffers(EGLDisplay dpy, EGLSurface draw)
228 {
229 _EGLDriver *drv = _eglLookupDriver(dpy);
230 return drv->SwapBuffers(drv, dpy, draw);
231 }
232
233
234 EGLBoolean APIENTRY
235 eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, NativePixmapType target)
236 {
237 _EGLDriver *drv = _eglLookupDriver(dpy);
238 return drv->CopyBuffers(drv, dpy, surface, target);
239 }
240
241
242 EGLBoolean APIENTRY
243 eglWaitGL(void)
244 {
245 EGLDisplay dpy = eglGetCurrentDisplay();
246 if (dpy != EGL_NO_DISPLAY) {
247 _EGLDriver *drv = _eglLookupDriver(dpy);
248 return drv->WaitGL(drv, dpy);
249 }
250 else
251 return EGL_FALSE;
252 }
253
254
255 EGLBoolean APIENTRY
256 eglWaitNative(EGLint engine)
257 {
258 EGLDisplay dpy = eglGetCurrentDisplay();
259 if (dpy != EGL_NO_DISPLAY) {
260 _EGLDriver *drv = _eglLookupDriver(dpy);
261 return drv->WaitNative(drv, dpy, engine);
262 }
263 else
264 return EGL_FALSE;
265 }
266
267
268 EGLDisplay APIENTRY
269 eglGetCurrentDisplay(void)
270 {
271 _EGLDisplay *dpy = _eglGetCurrentDisplay();
272 if (dpy)
273 return dpy->Handle;
274 else
275 return EGL_NO_DISPLAY;
276 }
277
278
279 EGLContext APIENTRY
280 eglGetCurrentContext(void)
281 {
282 _EGLContext *ctx = _eglGetCurrentContext();
283 if (ctx)
284 return ctx->Handle;
285 else
286 return EGL_NO_CONTEXT;
287 }
288
289
290 EGLSurface APIENTRY
291 eglGetCurrentSurface(EGLint readdraw)
292 {
293 _EGLSurface *s = _eglGetCurrentSurface(readdraw);
294 if (s)
295 return s->Handle;
296 else
297 return EGL_NO_SURFACE;
298 }
299
300
301 EGLint APIENTRY
302 eglGetError(void)
303 {
304 EGLint e = _eglGlobal.LastError;
305 _eglGlobal.LastError = EGL_SUCCESS;
306 return e;
307 }
308
309
310 void (* APIENTRY eglGetProcAddress(const char *procname))()
311 {
312 typedef void (*genericFunc)();
313 struct name_function {
314 const char *name;
315 _EGLProc function;
316 };
317 static struct name_function egl_functions[] = {
318 /* alphabetical order */
319 { "eglBindTexImage", (_EGLProc) eglBindTexImage },
320 { "eglChooseConfig", (_EGLProc) eglChooseConfig },
321 { "eglCopyBuffers", (_EGLProc) eglCopyBuffers },
322 { "eglCreateContext", (_EGLProc) eglCreateContext },
323 { "eglCreatePbufferSurface", (_EGLProc) eglCreatePbufferSurface },
324 { "eglCreatePixmapSurface", (_EGLProc) eglCreatePixmapSurface },
325 { "eglCreateWindowSurface", (_EGLProc) eglCreateWindowSurface },
326 { "eglDestroyContext", (_EGLProc) eglDestroyContext },
327 { "eglDestroySurface", (_EGLProc) eglDestroySurface },
328 { "eglGetConfigAttrib", (_EGLProc) eglGetConfigAttrib },
329 { "eglGetConfigs", (_EGLProc) eglGetConfigs },
330 { "eglGetCurrentContext", (_EGLProc) eglGetCurrentContext },
331 { "eglGetCurrentDisplay", (_EGLProc) eglGetCurrentDisplay },
332 { "eglGetCurrentSurface", (_EGLProc) eglGetCurrentSurface },
333 { "eglGetDisplay", (_EGLProc) eglGetDisplay },
334 { "eglGetError", (_EGLProc) eglGetError },
335 { "eglGetProcAddress", (_EGLProc) eglGetProcAddress },
336 { "eglInitialize", (_EGLProc) eglInitialize },
337 { "eglMakeCurrent", (_EGLProc) eglMakeCurrent },
338 { "eglQueryContext", (_EGLProc) eglQueryContext },
339 { "eglQueryString", (_EGLProc) eglQueryString },
340 { "eglQuerySurface", (_EGLProc) eglQuerySurface },
341 { "eglReleaseTexImage", (_EGLProc) eglReleaseTexImage },
342 { "eglSurfaceAttrib", (_EGLProc) eglSurfaceAttrib },
343 { "eglSwapBuffers", (_EGLProc) eglSwapBuffers },
344 { "eglSwapInterval", (_EGLProc) eglSwapInterval },
345 { "eglTerminate", (_EGLProc) eglTerminate },
346 { "eglWaitGL", (_EGLProc) eglWaitGL },
347 { "eglWaitNative", (_EGLProc) eglWaitNative },
348 /* Extensions */
349 { "eglChooseModeMESA", (_EGLProc) eglChooseModeMESA },
350 { "eglGetModesMESA", (_EGLProc) eglGetModesMESA },
351 { "eglGetModeAttribMESA", (_EGLProc) eglGetModeAttribMESA },
352 { "eglGetScreensMESA", (_EGLProc) eglGetScreensMESA },
353 { "eglCreateScreenSurfaceMESA", (_EGLProc) eglCreateScreenSurfaceMESA },
354 { "eglShowSurfaceMESA", (_EGLProc) eglShowSurfaceMESA },
355 { "eglScreenPositionMESA", (_EGLProc) eglScreenPositionMESA },
356 { "eglQueryDisplayMESA", (_EGLProc) eglQueryDisplayMESA },
357 { "eglQueryScreenMESA", (_EGLProc) eglQueryScreenMESA },
358 { "eglQueryScreenSurfaceMESA", (_EGLProc) eglQueryScreenSurfaceMESA },
359 { "eglQueryScreenModeMESA", (_EGLProc) eglQueryScreenModeMESA },
360 { "eglQueryModeStringMESA", (_EGLProc) eglQueryModeStringMESA },
361 { NULL, NULL }
362 };
363 EGLint i;
364 for (i = 0; egl_functions[i].name; i++) {
365 if (strcmp(egl_functions[i].name, procname) == 0) {
366 return (genericFunc) egl_functions[i].function;
367 }
368 }
369 #if 0
370 /* XXX enable this code someday */
371 return (genericFunc) _glapi_get_proc_address(procname);
372 #else
373 return NULL;
374 #endif
375 }
376
377
378 /*
379 * EGL_MESA_screen extension
380 */
381
382 EGLBoolean APIENTRY
383 eglChooseModeMESA(EGLDisplay dpy, EGLScreenMESA screen,
384 const EGLint *attrib_list, EGLModeMESA *modes,
385 EGLint modes_size, EGLint *num_modes)
386 {
387 _EGLDriver *drv = _eglLookupDriver(dpy);
388 if (drv)
389 return drv->ChooseModeMESA(drv, dpy, screen, attrib_list, modes, modes_size, num_modes);
390 else
391 return EGL_FALSE;
392 }
393
394
395 EGLBoolean APIENTRY
396 eglGetModesMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *modes, EGLint mode_size, EGLint *num_mode)
397 {
398 _EGLDriver *drv = _eglLookupDriver(dpy);
399 if (drv)
400 return drv->GetModesMESA(drv, dpy, screen, modes, mode_size, num_mode);
401 else
402 return EGL_FALSE;
403 }
404
405
406 EGLBoolean APIENTRY
407 eglGetModeAttribMESA(EGLDisplay dpy, EGLModeMESA mode, EGLint attribute, EGLint *value)
408 {
409 _EGLDriver *drv = _eglLookupDriver(dpy);
410 if (drv)
411 return drv->GetModeAttribMESA(drv, dpy, mode, attribute, value);
412 else
413 return EGL_FALSE;
414 }
415
416
417 EGLBoolean
418 eglGetScreensMESA(EGLDisplay dpy, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens)
419 {
420 _EGLDriver *drv = _eglLookupDriver(dpy);
421 if (drv)
422 return drv->GetScreensMESA(drv, dpy, screens, max_screens, num_screens);
423 else
424 return EGL_FALSE;
425 }
426
427
428 EGLSurface
429 eglCreateScreenSurfaceMESA(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
430 {
431 _EGLDriver *drv = _eglLookupDriver(dpy);
432 return drv->CreateScreenSurfaceMESA(drv, dpy, config, attrib_list);
433 }
434
435
436 EGLBoolean
437 eglShowSurfaceMESA(EGLDisplay dpy, EGLint screen, EGLSurface surface, EGLModeMESA mode)
438 {
439 _EGLDriver *drv = _eglLookupDriver(dpy);
440 return drv->ShowSurfaceMESA(drv, dpy, screen, surface, mode);
441 }
442
443
444 EGLBoolean
445 eglScreenPositionMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLint x, EGLint y)
446 {
447 _EGLDriver *drv = _eglLookupDriver(dpy);
448 return drv->ScreenPositionMESA(drv, dpy, screen, x, y);
449 }
450
451
452 EGLBoolean
453 eglQueryDisplayMESA(EGLDisplay dpy, EGLint attrib, EGLint *value)
454 {
455 _EGLDriver *drv = _eglLookupDriver(dpy);
456 return drv->QueryDisplayMESA(drv, dpy, attrib, value);
457 }
458
459
460 EGLBoolean
461 eglQueryScreenMESA( EGLDisplay dpy, EGLScreenMESA screen, EGLint attribute, EGLint *value)
462 {
463 _EGLDriver *drv = _eglLookupDriver(dpy);
464 return drv->QueryScreenMESA(drv, dpy, screen, attribute, value);
465 }
466
467
468 EGLBoolean
469 eglQueryScreenSurfaceMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLSurface *surface)
470 {
471 _EGLDriver *drv = _eglLookupDriver(dpy);
472 return drv->QueryScreenSurfaceMESA(drv, dpy, screen, surface);
473 }
474
475
476 EGLBoolean
477 eglQueryScreenModeMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *mode)
478 {
479 _EGLDriver *drv = _eglLookupDriver(dpy);
480 return drv->QueryScreenModeMESA(drv, dpy, screen, mode);
481 }
482
483
484 const char *
485 eglQueryModeStringMESA(EGLDisplay dpy, EGLModeMESA mode)
486 {
487 _EGLDriver *drv = _eglLookupDriver(dpy);
488 return drv->QueryModeStringMESA(drv, dpy, mode);
489 }
490
491
492
493
494