Merge remote-tracking branch 'public/master' into vulkan
[mesa.git] / src / egl / main / eglapi.c
1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
4 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5 * Copyright 2010-2011 LunarG, Inc.
6 * All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 *
28 **************************************************************************/
29
30
31 /**
32 * Public EGL API entrypoints
33 *
34 * Generally, we use the EGLDisplay parameter as a key to lookup the
35 * appropriate device driver handle, then jump though the driver's
36 * dispatch table to handle the function.
37 *
38 * That allows us the option of supporting multiple, simultaneous,
39 * heterogeneous hardware devices in the future.
40 *
41 * The EGLDisplay, EGLConfig, EGLContext and EGLSurface types are
42 * opaque handles. Internal objects are linked to a display to
43 * create the handles.
44 *
45 * For each public API entry point, the opaque handles are looked up
46 * before being dispatched to the drivers. When it fails to look up
47 * a handle, one of
48 *
49 * EGL_BAD_DISPLAY
50 * EGL_BAD_CONFIG
51 * EGL_BAD_CONTEXT
52 * EGL_BAD_SURFACE
53 * EGL_BAD_SCREEN_MESA
54 * EGL_BAD_MODE_MESA
55 *
56 * is generated and the driver function is not called. An
57 * uninitialized EGLDisplay has no driver associated with it. When
58 * such display is detected,
59 *
60 * EGL_NOT_INITIALIZED
61 *
62 * is generated.
63 *
64 * Some of the entry points use current display, context, or surface
65 * implicitly. For such entry points, the implicit objects are also
66 * checked before calling the driver function. Other than the
67 * errors listed above,
68 *
69 * EGL_BAD_CURRENT_SURFACE
70 *
71 * may also be generated.
72 *
73 * Notes on naming conventions:
74 *
75 * eglFooBar - public EGL function
76 * EGL_FOO_BAR - public EGL token
77 * EGLDatatype - public EGL datatype
78 *
79 * _eglFooBar - private EGL function
80 * _EGLDatatype - private EGL datatype, typedef'd struct
81 * _egl_struct - private EGL struct, non-typedef'd
82 *
83 */
84
85
86 #include <stdio.h>
87 #include <stdlib.h>
88 #include <string.h>
89 #include "c99_compat.h"
90 #include "c11/threads.h"
91 #include "eglcompiler.h"
92
93 #include "eglglobals.h"
94 #include "eglcontext.h"
95 #include "egldisplay.h"
96 #include "egltypedefs.h"
97 #include "eglcurrent.h"
98 #include "egldriver.h"
99 #include "eglsurface.h"
100 #include "eglconfig.h"
101 #include "eglimage.h"
102 #include "eglsync.h"
103
104
105 /**
106 * Macros to help return an API entrypoint.
107 *
108 * These macros will unlock the display and record the error code.
109 */
110 #define RETURN_EGL_ERROR(disp, err, ret) \
111 do { \
112 if (disp) \
113 _eglUnlockDisplay(disp); \
114 /* EGL error codes are non-zero */ \
115 if (err) \
116 _eglError(err, __func__); \
117 return ret; \
118 } while (0)
119
120 #define RETURN_EGL_SUCCESS(disp, ret) \
121 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
122
123 /* record EGL_SUCCESS only when ret evaluates to true */
124 #define RETURN_EGL_EVAL(disp, ret) \
125 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
126
127
128 /*
129 * A bunch of macros and checks to simplify error checking.
130 */
131
132 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
133 do { \
134 drv = _eglCheckDisplay(disp, __func__); \
135 if (!drv) \
136 RETURN_EGL_ERROR(disp, 0, ret); \
137 } while (0)
138
139 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
140 do { \
141 drv = _eglCheck ## type(disp, obj, __func__); \
142 if (!drv) \
143 RETURN_EGL_ERROR(disp, 0, ret); \
144 } while (0)
145
146 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
147 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
148
149 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
150 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
151
152 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
153 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
154
155 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
156 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
157
158
159 static inline _EGLDriver *
160 _eglCheckDisplay(_EGLDisplay *disp, const char *msg)
161 {
162 if (!disp) {
163 _eglError(EGL_BAD_DISPLAY, msg);
164 return NULL;
165 }
166 if (!disp->Initialized) {
167 _eglError(EGL_NOT_INITIALIZED, msg);
168 return NULL;
169 }
170 return disp->Driver;
171 }
172
173
174 static inline _EGLDriver *
175 _eglCheckSurface(_EGLDisplay *disp, _EGLSurface *surf, const char *msg)
176 {
177 _EGLDriver *drv = _eglCheckDisplay(disp, msg);
178 if (!drv)
179 return NULL;
180 if (!surf) {
181 _eglError(EGL_BAD_SURFACE, msg);
182 return NULL;
183 }
184 return drv;
185 }
186
187
188 static inline _EGLDriver *
189 _eglCheckContext(_EGLDisplay *disp, _EGLContext *context, const char *msg)
190 {
191 _EGLDriver *drv = _eglCheckDisplay(disp, msg);
192 if (!drv)
193 return NULL;
194 if (!context) {
195 _eglError(EGL_BAD_CONTEXT, msg);
196 return NULL;
197 }
198 return drv;
199 }
200
201
202 static inline _EGLDriver *
203 _eglCheckConfig(_EGLDisplay *disp, _EGLConfig *conf, const char *msg)
204 {
205 _EGLDriver *drv = _eglCheckDisplay(disp, msg);
206 if (!drv)
207 return NULL;
208 if (!conf) {
209 _eglError(EGL_BAD_CONFIG, msg);
210 return NULL;
211 }
212 return drv;
213 }
214
215
216 static inline _EGLDriver *
217 _eglCheckSync(_EGLDisplay *disp, _EGLSync *s, const char *msg)
218 {
219 _EGLDriver *drv = _eglCheckDisplay(disp, msg);
220 if (!drv)
221 return NULL;
222 if (!s) {
223 _eglError(EGL_BAD_PARAMETER, msg);
224 return NULL;
225 }
226 return drv;
227 }
228
229
230 /**
231 * Lookup and lock a display.
232 */
233 static inline _EGLDisplay *
234 _eglLockDisplay(EGLDisplay display)
235 {
236 _EGLDisplay *dpy = _eglLookupDisplay(display);
237 if (dpy)
238 mtx_lock(&dpy->Mutex);
239 return dpy;
240 }
241
242
243 /**
244 * Unlock a display.
245 */
246 static inline void
247 _eglUnlockDisplay(_EGLDisplay *dpy)
248 {
249 mtx_unlock(&dpy->Mutex);
250 }
251
252
253 static EGLint *
254 _eglConvertAttribsToInt(const EGLAttrib *attr_list)
255 {
256 EGLint *int_attribs = NULL;
257
258 /* Convert attributes from EGLAttrib[] to EGLint[] */
259 if (attr_list) {
260 int i, size = 0;
261
262 while (attr_list[size] != EGL_NONE)
263 size += 2;
264
265 size += 1; /* add space for EGL_NONE */
266
267 int_attribs = calloc(size, sizeof(int_attribs[0]));
268 if (!int_attribs)
269 return NULL;
270
271 for (i = 0; i < size; i++)
272 int_attribs[i] = attr_list[i];
273 }
274 return int_attribs;
275 }
276
277
278 /**
279 * This is typically the first EGL function that an application calls.
280 * It associates a private _EGLDisplay object to the native display.
281 */
282 EGLDisplay EGLAPIENTRY
283 eglGetDisplay(EGLNativeDisplayType nativeDisplay)
284 {
285 _EGLPlatformType plat;
286 _EGLDisplay *dpy;
287 void *native_display_ptr;
288
289 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay));
290 native_display_ptr = (void*) nativeDisplay;
291
292 plat = _eglGetNativePlatform(native_display_ptr);
293 dpy = _eglFindDisplay(plat, native_display_ptr);
294 return _eglGetDisplayHandle(dpy);
295 }
296
297 static EGLDisplay EGLAPIENTRY
298 eglGetPlatformDisplayEXT(EGLenum platform, void *native_display,
299 const EGLint *attrib_list)
300 {
301 _EGLDisplay *dpy;
302
303 switch (platform) {
304 #ifdef HAVE_X11_PLATFORM
305 case EGL_PLATFORM_X11_EXT:
306 dpy = _eglGetX11Display((Display*) native_display, attrib_list);
307 break;
308 #endif
309 #ifdef HAVE_DRM_PLATFORM
310 case EGL_PLATFORM_GBM_MESA:
311 dpy = _eglGetGbmDisplay((struct gbm_device*) native_display,
312 attrib_list);
313 break;
314 #endif
315 #ifdef HAVE_WAYLAND_PLATFORM
316 case EGL_PLATFORM_WAYLAND_EXT:
317 dpy = _eglGetWaylandDisplay((struct wl_display*) native_display,
318 attrib_list);
319 break;
320 #endif
321 default:
322 RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, NULL);
323 }
324
325 return _eglGetDisplayHandle(dpy);
326 }
327
328 EGLDisplay EGLAPIENTRY
329 eglGetPlatformDisplay(EGLenum platform, void *native_display,
330 const EGLAttrib *attrib_list)
331 {
332 EGLDisplay display;
333 EGLint *int_attribs = _eglConvertAttribsToInt(attrib_list);
334
335 if (attrib_list && !int_attribs)
336 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, NULL);
337
338 display = eglGetPlatformDisplayEXT(platform, native_display, int_attribs);
339 free(int_attribs);
340 return display;
341 }
342
343 /**
344 * Copy the extension into the string and update the string pointer.
345 */
346 static EGLint
347 _eglAppendExtension(char **str, const char *ext)
348 {
349 char *s = *str;
350 size_t len = strlen(ext);
351
352 if (s) {
353 memcpy(s, ext, len);
354 s[len++] = ' ';
355 s[len] = '\0';
356
357 *str += len;
358 }
359 else {
360 len++;
361 }
362
363 return (EGLint) len;
364 }
365
366 /**
367 * Examine the individual extension enable/disable flags and recompute
368 * the driver's Extensions string.
369 */
370 static void
371 _eglCreateExtensionsString(_EGLDisplay *dpy)
372 {
373 #define _EGL_CHECK_EXTENSION(ext) \
374 do { \
375 if (dpy->Extensions.ext) { \
376 _eglAppendExtension(&exts, "EGL_" #ext); \
377 assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
378 } \
379 } while (0)
380
381 char *exts = dpy->ExtensionsString;
382
383 /* Please keep these sorted alphabetically. */
384 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer);
385
386 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control);
387
388 _EGL_CHECK_EXTENSION(EXT_buffer_age);
389 _EGL_CHECK_EXTENSION(EXT_create_context_robustness);
390 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import);
391 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage);
392
393 _EGL_CHECK_EXTENSION(KHR_cl_event2);
394 _EGL_CHECK_EXTENSION(KHR_create_context);
395 _EGL_CHECK_EXTENSION(KHR_fence_sync);
396 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses);
397 _EGL_CHECK_EXTENSION(KHR_gl_colorspace);
398 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image);
399 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image);
400 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image);
401 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image);
402 if (dpy->Extensions.KHR_image_base && dpy->Extensions.KHR_image_pixmap)
403 _eglAppendExtension(&exts, "EGL_KHR_image");
404 _EGL_CHECK_EXTENSION(KHR_image_base);
405 _EGL_CHECK_EXTENSION(KHR_image_pixmap);
406 _EGL_CHECK_EXTENSION(KHR_reusable_sync);
407 _EGL_CHECK_EXTENSION(KHR_surfaceless_context);
408 _EGL_CHECK_EXTENSION(KHR_wait_sync);
409
410 _EGL_CHECK_EXTENSION(MESA_configless_context);
411 _EGL_CHECK_EXTENSION(MESA_drm_image);
412 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export);
413
414 _EGL_CHECK_EXTENSION(NOK_swap_region);
415 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap);
416
417 _EGL_CHECK_EXTENSION(NV_post_sub_buffer);
418
419 _EGL_CHECK_EXTENSION(WL_bind_wayland_display);
420 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image);
421
422 #undef _EGL_CHECK_EXTENSION
423 }
424
425 static void
426 _eglCreateAPIsString(_EGLDisplay *dpy)
427 {
428 if (dpy->ClientAPIs & EGL_OPENGL_BIT)
429 strcat(dpy->ClientAPIsString, "OpenGL ");
430
431 if (dpy->ClientAPIs & EGL_OPENGL_ES_BIT)
432 strcat(dpy->ClientAPIsString, "OpenGL_ES ");
433
434 if (dpy->ClientAPIs & EGL_OPENGL_ES2_BIT)
435 strcat(dpy->ClientAPIsString, "OpenGL_ES2 ");
436
437 if (dpy->ClientAPIs & EGL_OPENGL_ES3_BIT_KHR)
438 strcat(dpy->ClientAPIsString, "OpenGL_ES3 ");
439
440 if (dpy->ClientAPIs & EGL_OPENVG_BIT)
441 strcat(dpy->ClientAPIsString, "OpenVG ");
442
443 assert(strlen(dpy->ClientAPIsString) < sizeof(dpy->ClientAPIsString));
444 }
445
446 static void
447 _eglComputeVersion(_EGLDisplay *disp)
448 {
449 disp->Version = 14;
450
451 if (disp->Extensions.KHR_fence_sync &&
452 disp->Extensions.KHR_cl_event2 &&
453 disp->Extensions.KHR_wait_sync &&
454 disp->Extensions.KHR_image_base &&
455 disp->Extensions.KHR_gl_texture_2D_image &&
456 disp->Extensions.KHR_gl_texture_3D_image &&
457 disp->Extensions.KHR_gl_texture_cubemap_image &&
458 disp->Extensions.KHR_gl_renderbuffer_image &&
459 disp->Extensions.KHR_create_context &&
460 disp->Extensions.EXT_create_context_robustness &&
461 disp->Extensions.KHR_get_all_proc_addresses &&
462 disp->Extensions.KHR_gl_colorspace &&
463 disp->Extensions.KHR_surfaceless_context)
464 disp->Version = 15;
465 }
466
467 /**
468 * This is typically the second EGL function that an application calls.
469 * Here we load/initialize the actual hardware driver.
470 */
471 EGLBoolean EGLAPIENTRY
472 eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
473 {
474 _EGLDisplay *disp = _eglLockDisplay(dpy);
475
476 if (!disp)
477 RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE);
478
479 if (!disp->Initialized) {
480 if (!_eglMatchDriver(disp, EGL_FALSE))
481 RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE);
482
483 /* limit to APIs supported by core */
484 disp->ClientAPIs &= _EGL_API_ALL_BITS;
485
486 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
487 * classifies it as an EGL display extension, though conceptually it's an
488 * EGL client extension.
489 *
490 * From the EGL_KHR_get_all_proc_addresses spec:
491 *
492 * The EGL implementation must expose the name
493 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
494 * EGL_KHR_get_all_proc_addresses and supports
495 * EGL_EXT_client_extensions.
496 *
497 * Mesa unconditionally exposes both client extensions mentioned above,
498 * so the spec requires that each EGLDisplay unconditionally expose
499 * EGL_KHR_get_all_proc_addresses also.
500 */
501 disp->Extensions.KHR_get_all_proc_addresses = EGL_TRUE;
502
503 _eglComputeVersion(disp);
504 _eglCreateExtensionsString(disp);
505 _eglCreateAPIsString(disp);
506 snprintf(disp->VersionString, sizeof(disp->VersionString),
507 "%d.%d (%s)", disp->Version / 10, disp->Version % 10,
508 disp->Driver->Name);
509 }
510
511 /* Update applications version of major and minor if not NULL */
512 if ((major != NULL) && (minor != NULL)) {
513 *major = disp->Version / 10;
514 *minor = disp->Version % 10;
515 }
516
517 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
518 }
519
520
521 EGLBoolean EGLAPIENTRY
522 eglTerminate(EGLDisplay dpy)
523 {
524 _EGLDisplay *disp = _eglLockDisplay(dpy);
525
526 if (!disp)
527 RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE);
528
529 if (disp->Initialized) {
530 _EGLDriver *drv = disp->Driver;
531
532 drv->API.Terminate(drv, disp);
533 /* do not reset disp->Driver */
534 disp->ClientAPIsString[0] = 0;
535 disp->Initialized = EGL_FALSE;
536 }
537
538 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
539 }
540
541
542 const char * EGLAPIENTRY
543 eglQueryString(EGLDisplay dpy, EGLint name)
544 {
545 _EGLDisplay *disp;
546 _EGLDriver *drv;
547
548 if (dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS) {
549 RETURN_EGL_SUCCESS(NULL, _eglGlobal.ClientExtensionString);
550 }
551
552 disp = _eglLockDisplay(dpy);
553 _EGL_CHECK_DISPLAY(disp, NULL, drv);
554
555 switch (name) {
556 case EGL_VENDOR:
557 RETURN_EGL_SUCCESS(disp, _EGL_VENDOR_STRING);
558 case EGL_VERSION:
559 RETURN_EGL_SUCCESS(disp, disp->VersionString);
560 case EGL_EXTENSIONS:
561 RETURN_EGL_SUCCESS(disp, disp->ExtensionsString);
562 case EGL_CLIENT_APIS:
563 RETURN_EGL_SUCCESS(disp, disp->ClientAPIsString);
564 default:
565 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL);
566 }
567 }
568
569
570 EGLBoolean EGLAPIENTRY
571 eglGetConfigs(EGLDisplay dpy, EGLConfig *configs,
572 EGLint config_size, EGLint *num_config)
573 {
574 _EGLDisplay *disp = _eglLockDisplay(dpy);
575 _EGLDriver *drv;
576 EGLBoolean ret;
577
578 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
579 ret = drv->API.GetConfigs(drv, disp, configs, config_size, num_config);
580
581 RETURN_EGL_EVAL(disp, ret);
582 }
583
584
585 EGLBoolean EGLAPIENTRY
586 eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs,
587 EGLint config_size, EGLint *num_config)
588 {
589 _EGLDisplay *disp = _eglLockDisplay(dpy);
590 _EGLDriver *drv;
591 EGLBoolean ret;
592
593 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
594 ret = drv->API.ChooseConfig(drv, disp, attrib_list, configs,
595 config_size, num_config);
596
597 RETURN_EGL_EVAL(disp, ret);
598 }
599
600
601 EGLBoolean EGLAPIENTRY
602 eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
603 EGLint attribute, EGLint *value)
604 {
605 _EGLDisplay *disp = _eglLockDisplay(dpy);
606 _EGLConfig *conf = _eglLookupConfig(config, disp);
607 _EGLDriver *drv;
608 EGLBoolean ret;
609
610 _EGL_CHECK_CONFIG(disp, conf, EGL_FALSE, drv);
611 ret = drv->API.GetConfigAttrib(drv, disp, conf, attribute, value);
612
613 RETURN_EGL_EVAL(disp, ret);
614 }
615
616
617 EGLContext EGLAPIENTRY
618 eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list,
619 const EGLint *attrib_list)
620 {
621 _EGLDisplay *disp = _eglLockDisplay(dpy);
622 _EGLConfig *conf = _eglLookupConfig(config, disp);
623 _EGLContext *share = _eglLookupContext(share_list, disp);
624 _EGLDriver *drv;
625 _EGLContext *context;
626 EGLContext ret;
627
628 _EGL_CHECK_DISPLAY(disp, EGL_NO_CONTEXT, drv);
629
630 if (!config && !disp->Extensions.MESA_configless_context)
631 RETURN_EGL_ERROR(disp, EGL_BAD_CONFIG, EGL_NO_CONTEXT);
632
633 if (!share && share_list != EGL_NO_CONTEXT)
634 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_CONTEXT);
635
636 context = drv->API.CreateContext(drv, disp, conf, share, attrib_list);
637 ret = (context) ? _eglLinkContext(context) : EGL_NO_CONTEXT;
638
639 RETURN_EGL_EVAL(disp, ret);
640 }
641
642
643 EGLBoolean EGLAPIENTRY
644 eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
645 {
646 _EGLDisplay *disp = _eglLockDisplay(dpy);
647 _EGLContext *context = _eglLookupContext(ctx, disp);
648 _EGLDriver *drv;
649 EGLBoolean ret;
650
651 _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv);
652 _eglUnlinkContext(context);
653 ret = drv->API.DestroyContext(drv, disp, context);
654
655 RETURN_EGL_EVAL(disp, ret);
656 }
657
658
659 EGLBoolean EGLAPIENTRY
660 eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read,
661 EGLContext ctx)
662 {
663 _EGLDisplay *disp = _eglLockDisplay(dpy);
664 _EGLContext *context = _eglLookupContext(ctx, disp);
665 _EGLSurface *draw_surf = _eglLookupSurface(draw, disp);
666 _EGLSurface *read_surf = _eglLookupSurface(read, disp);
667 _EGLDriver *drv;
668 EGLBoolean ret;
669
670 if (!disp)
671 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE);
672 drv = disp->Driver;
673
674 /* display is allowed to be uninitialized under certain condition */
675 if (!disp->Initialized) {
676 if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE ||
677 ctx != EGL_NO_CONTEXT)
678 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE);
679 }
680 if (!drv)
681 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
682
683 if (!context && ctx != EGL_NO_CONTEXT)
684 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE);
685 if (!draw_surf || !read_surf) {
686 /* From the EGL 1.4 (20130211) spec:
687 *
688 * To release the current context without assigning a new one, set ctx
689 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
690 */
691 if (!disp->Extensions.KHR_surfaceless_context && ctx != EGL_NO_CONTEXT)
692 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
693
694 if ((!draw_surf && draw != EGL_NO_SURFACE) ||
695 (!read_surf && read != EGL_NO_SURFACE))
696 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
697 if (draw_surf || read_surf)
698 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
699 }
700
701 ret = drv->API.MakeCurrent(drv, disp, draw_surf, read_surf, context);
702
703 RETURN_EGL_EVAL(disp, ret);
704 }
705
706
707 EGLBoolean EGLAPIENTRY
708 eglQueryContext(EGLDisplay dpy, EGLContext ctx,
709 EGLint attribute, EGLint *value)
710 {
711 _EGLDisplay *disp = _eglLockDisplay(dpy);
712 _EGLContext *context = _eglLookupContext(ctx, disp);
713 _EGLDriver *drv;
714 EGLBoolean ret;
715
716 _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv);
717 ret = drv->API.QueryContext(drv, disp, context, attribute, value);
718
719 RETURN_EGL_EVAL(disp, ret);
720 }
721
722
723 static EGLSurface
724 _eglCreateWindowSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
725 void *native_window, const EGLint *attrib_list)
726 {
727 _EGLConfig *conf = _eglLookupConfig(config, disp);
728 _EGLDriver *drv;
729 _EGLSurface *surf;
730 EGLSurface ret;
731
732 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
733
734 if (native_window == NULL)
735 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
736
737 surf = drv->API.CreateWindowSurface(drv, disp, conf, native_window,
738 attrib_list);
739 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
740
741 RETURN_EGL_EVAL(disp, ret);
742 }
743
744
745 EGLSurface EGLAPIENTRY
746 eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
747 EGLNativeWindowType window, const EGLint *attrib_list)
748 {
749 _EGLDisplay *disp = _eglLockDisplay(dpy);
750 STATIC_ASSERT(sizeof(void*) == sizeof(window));
751 return _eglCreateWindowSurfaceCommon(disp, config, (void*) window,
752 attrib_list);
753 }
754
755
756 static EGLSurface EGLAPIENTRY
757 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config,
758 void *native_window,
759 const EGLint *attrib_list)
760 {
761 _EGLDisplay *disp = _eglLockDisplay(dpy);
762
763 #ifdef HAVE_X11_PLATFORM
764 if (disp->Platform == _EGL_PLATFORM_X11 && native_window != NULL) {
765 /* The `native_window` parameter for the X11 platform differs between
766 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
767 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
768 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
769 * `Window*`. Convert `Window*` to `Window` because that's what
770 * dri2_x11_create_window_surface() expects.
771 */
772 native_window = (void*) (* (Window*) native_window);
773 }
774 #endif
775
776 return _eglCreateWindowSurfaceCommon(disp, config, native_window,
777 attrib_list);
778 }
779
780
781 EGLSurface EGLAPIENTRY
782 eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config,
783 void *native_window,
784 const EGLAttrib *attrib_list)
785 {
786 EGLSurface surface;
787 EGLint *int_attribs = _eglConvertAttribsToInt(attrib_list);
788
789 if (attrib_list && !int_attribs)
790 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_NO_SURFACE);
791
792 surface = eglCreatePlatformWindowSurfaceEXT(dpy, config, native_window,
793 int_attribs);
794 free(int_attribs);
795 return surface;
796 }
797
798
799 static EGLSurface
800 _eglCreatePixmapSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
801 void *native_pixmap, const EGLint *attrib_list)
802 {
803 _EGLConfig *conf = _eglLookupConfig(config, disp);
804 _EGLDriver *drv;
805 _EGLSurface *surf;
806 EGLSurface ret;
807
808 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
809 surf = drv->API.CreatePixmapSurface(drv, disp, conf, native_pixmap,
810 attrib_list);
811 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
812
813 RETURN_EGL_EVAL(disp, ret);
814 }
815
816
817 EGLSurface EGLAPIENTRY
818 eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config,
819 EGLNativePixmapType pixmap, const EGLint *attrib_list)
820 {
821 _EGLDisplay *disp = _eglLockDisplay(dpy);
822 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap));
823 return _eglCreatePixmapSurfaceCommon(disp, config, (void*) pixmap,
824 attrib_list);
825 }
826
827 static EGLSurface EGLAPIENTRY
828 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config,
829 void *native_pixmap,
830 const EGLint *attrib_list)
831 {
832 _EGLDisplay *disp = _eglLockDisplay(dpy);
833
834 #ifdef HAVE_X11_PLATFORM
835 /* The `native_pixmap` parameter for the X11 platform differs between
836 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
837 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
838 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
839 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
840 * dri2_x11_create_pixmap_surface() expects.
841 */
842 if (disp->Platform == _EGL_PLATFORM_X11 && native_pixmap != NULL) {
843 native_pixmap = (void*) (* (Pixmap*) native_pixmap);
844 }
845 #endif
846
847 return _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap,
848 attrib_list);
849 }
850
851
852 EGLSurface EGLAPIENTRY
853 eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config,
854 void *native_pixmap,
855 const EGLAttrib *attrib_list)
856 {
857 EGLSurface surface;
858 EGLint *int_attribs = _eglConvertAttribsToInt(attrib_list);
859
860 if (attrib_list && !int_attribs)
861 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_NO_SURFACE);
862
863 surface = eglCreatePlatformPixmapSurfaceEXT(dpy, config, native_pixmap,
864 int_attribs);
865 free(int_attribs);
866 return surface;
867 }
868
869
870 EGLSurface EGLAPIENTRY
871 eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,
872 const EGLint *attrib_list)
873 {
874 _EGLDisplay *disp = _eglLockDisplay(dpy);
875 _EGLConfig *conf = _eglLookupConfig(config, disp);
876 _EGLDriver *drv;
877 _EGLSurface *surf;
878 EGLSurface ret;
879
880 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
881
882 surf = drv->API.CreatePbufferSurface(drv, disp, conf, attrib_list);
883 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
884
885 RETURN_EGL_EVAL(disp, ret);
886 }
887
888
889 EGLBoolean EGLAPIENTRY
890 eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
891 {
892 _EGLDisplay *disp = _eglLockDisplay(dpy);
893 _EGLSurface *surf = _eglLookupSurface(surface, disp);
894 _EGLDriver *drv;
895 EGLBoolean ret;
896
897 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
898 _eglUnlinkSurface(surf);
899 ret = drv->API.DestroySurface(drv, disp, surf);
900
901 RETURN_EGL_EVAL(disp, ret);
902 }
903
904 EGLBoolean EGLAPIENTRY
905 eglQuerySurface(EGLDisplay dpy, EGLSurface surface,
906 EGLint attribute, EGLint *value)
907 {
908 _EGLDisplay *disp = _eglLockDisplay(dpy);
909 _EGLSurface *surf = _eglLookupSurface(surface, disp);
910 _EGLDriver *drv;
911 EGLBoolean ret;
912
913 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
914 ret = drv->API.QuerySurface(drv, disp, surf, attribute, value);
915
916 RETURN_EGL_EVAL(disp, ret);
917 }
918
919 EGLBoolean EGLAPIENTRY
920 eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface,
921 EGLint attribute, EGLint value)
922 {
923 _EGLDisplay *disp = _eglLockDisplay(dpy);
924 _EGLSurface *surf = _eglLookupSurface(surface, disp);
925 _EGLDriver *drv;
926 EGLBoolean ret;
927
928 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
929 ret = drv->API.SurfaceAttrib(drv, disp, surf, attribute, value);
930
931 RETURN_EGL_EVAL(disp, ret);
932 }
933
934
935 EGLBoolean EGLAPIENTRY
936 eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
937 {
938 _EGLDisplay *disp = _eglLockDisplay(dpy);
939 _EGLSurface *surf = _eglLookupSurface(surface, disp);
940 _EGLDriver *drv;
941 EGLBoolean ret;
942
943 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
944 ret = drv->API.BindTexImage(drv, disp, surf, buffer);
945
946 RETURN_EGL_EVAL(disp, ret);
947 }
948
949
950 EGLBoolean EGLAPIENTRY
951 eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
952 {
953 _EGLDisplay *disp = _eglLockDisplay(dpy);
954 _EGLSurface *surf = _eglLookupSurface(surface, disp);
955 _EGLDriver *drv;
956 EGLBoolean ret;
957
958 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
959 ret = drv->API.ReleaseTexImage(drv, disp, surf, buffer);
960
961 RETURN_EGL_EVAL(disp, ret);
962 }
963
964
965 EGLBoolean EGLAPIENTRY
966 eglSwapInterval(EGLDisplay dpy, EGLint interval)
967 {
968 _EGLDisplay *disp = _eglLockDisplay(dpy);
969 _EGLContext *ctx = _eglGetCurrentContext();
970 _EGLSurface *surf;
971 _EGLDriver *drv;
972 EGLBoolean ret;
973
974 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
975
976 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
977 ctx->Resource.Display != disp)
978 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE);
979
980 surf = ctx->DrawSurface;
981 if (_eglGetSurfaceHandle(surf) == EGL_NO_SURFACE)
982 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
983
984 ret = drv->API.SwapInterval(drv, disp, surf, interval);
985
986 RETURN_EGL_EVAL(disp, ret);
987 }
988
989
990 EGLBoolean EGLAPIENTRY
991 eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
992 {
993 _EGLContext *ctx = _eglGetCurrentContext();
994 _EGLDisplay *disp = _eglLockDisplay(dpy);
995 _EGLSurface *surf = _eglLookupSurface(surface, disp);
996 _EGLDriver *drv;
997 EGLBoolean ret;
998
999 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1000
1001 /* surface must be bound to current context in EGL 1.4 */
1002 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1003 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1004 surf != ctx->DrawSurface)
1005 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1006 #endif
1007
1008 ret = drv->API.SwapBuffers(drv, disp, surf);
1009
1010 RETURN_EGL_EVAL(disp, ret);
1011 }
1012
1013
1014 static EGLBoolean EGLAPIENTRY
1015 eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface,
1016 EGLint *rects, EGLint n_rects)
1017 {
1018 _EGLContext *ctx = _eglGetCurrentContext();
1019 _EGLDisplay *disp = _eglLockDisplay(dpy);
1020 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1021 _EGLDriver *drv;
1022 EGLBoolean ret;
1023
1024 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1025
1026 /* surface must be bound to current context in EGL 1.4 */
1027 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1028 surf != ctx->DrawSurface)
1029 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1030
1031 if ((n_rects > 0 && rects == NULL) || n_rects < 0)
1032 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1033
1034 ret = drv->API.SwapBuffersWithDamageEXT(drv, disp, surf, rects, n_rects);
1035
1036 RETURN_EGL_EVAL(disp, ret);
1037 }
1038
1039 EGLBoolean EGLAPIENTRY
1040 eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
1041 {
1042 _EGLDisplay *disp = _eglLockDisplay(dpy);
1043 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1044 _EGLDriver *drv;
1045 EGLBoolean ret;
1046 void *native_pixmap_ptr;
1047
1048 STATIC_ASSERT(sizeof(void*) == sizeof(target));
1049 native_pixmap_ptr = (void*) target;
1050
1051 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1052 if (disp->Platform != _eglGetNativePlatform(disp->PlatformDisplay))
1053 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_FALSE);
1054 ret = drv->API.CopyBuffers(drv, disp, surf, native_pixmap_ptr);
1055
1056 RETURN_EGL_EVAL(disp, ret);
1057 }
1058
1059
1060 EGLBoolean EGLAPIENTRY
1061 eglWaitClient(void)
1062 {
1063 _EGLContext *ctx = _eglGetCurrentContext();
1064 _EGLDisplay *disp;
1065 _EGLDriver *drv;
1066 EGLBoolean ret;
1067
1068 if (!ctx)
1069 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1070
1071 disp = ctx->Resource.Display;
1072 mtx_lock(&disp->Mutex);
1073
1074 /* let bad current context imply bad current surface */
1075 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1076 _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE)
1077 RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
1078
1079 /* a valid current context implies an initialized current display */
1080 assert(disp->Initialized);
1081 drv = disp->Driver;
1082 ret = drv->API.WaitClient(drv, disp, ctx);
1083
1084 RETURN_EGL_EVAL(disp, ret);
1085 }
1086
1087
1088 EGLBoolean EGLAPIENTRY
1089 eglWaitGL(void)
1090 {
1091 _EGLThreadInfo *t = _eglGetCurrentThread();
1092 EGLint api_index = t->CurrentAPIIndex;
1093 EGLint es_index = _eglConvertApiToIndex(EGL_OPENGL_ES_API);
1094 EGLBoolean ret;
1095
1096 if (api_index != es_index && _eglIsCurrentThreadDummy())
1097 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_FALSE);
1098
1099 t->CurrentAPIIndex = es_index;
1100 ret = eglWaitClient();
1101 t->CurrentAPIIndex = api_index;
1102 return ret;
1103 }
1104
1105
1106 EGLBoolean EGLAPIENTRY
1107 eglWaitNative(EGLint engine)
1108 {
1109 _EGLContext *ctx = _eglGetCurrentContext();
1110 _EGLDisplay *disp;
1111 _EGLDriver *drv;
1112 EGLBoolean ret;
1113
1114 if (!ctx)
1115 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1116
1117 disp = ctx->Resource.Display;
1118 mtx_lock(&disp->Mutex);
1119
1120 /* let bad current context imply bad current surface */
1121 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1122 _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE)
1123 RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
1124
1125 /* a valid current context implies an initialized current display */
1126 assert(disp->Initialized);
1127 drv = disp->Driver;
1128 ret = drv->API.WaitNative(drv, disp, engine);
1129
1130 RETURN_EGL_EVAL(disp, ret);
1131 }
1132
1133
1134 EGLDisplay EGLAPIENTRY
1135 eglGetCurrentDisplay(void)
1136 {
1137 _EGLContext *ctx = _eglGetCurrentContext();
1138 EGLDisplay ret;
1139
1140 ret = (ctx) ? _eglGetDisplayHandle(ctx->Resource.Display) : EGL_NO_DISPLAY;
1141
1142 RETURN_EGL_SUCCESS(NULL, ret);
1143 }
1144
1145
1146 EGLContext EGLAPIENTRY
1147 eglGetCurrentContext(void)
1148 {
1149 _EGLContext *ctx = _eglGetCurrentContext();
1150 EGLContext ret;
1151
1152 ret = _eglGetContextHandle(ctx);
1153
1154 RETURN_EGL_SUCCESS(NULL, ret);
1155 }
1156
1157
1158 EGLSurface EGLAPIENTRY
1159 eglGetCurrentSurface(EGLint readdraw)
1160 {
1161 _EGLContext *ctx = _eglGetCurrentContext();
1162 EGLint err = EGL_SUCCESS;
1163 _EGLSurface *surf;
1164 EGLSurface ret;
1165
1166 if (!ctx)
1167 RETURN_EGL_SUCCESS(NULL, EGL_NO_SURFACE);
1168
1169 switch (readdraw) {
1170 case EGL_DRAW:
1171 surf = ctx->DrawSurface;
1172 break;
1173 case EGL_READ:
1174 surf = ctx->ReadSurface;
1175 break;
1176 default:
1177 surf = NULL;
1178 err = EGL_BAD_PARAMETER;
1179 break;
1180 }
1181
1182 ret = _eglGetSurfaceHandle(surf);
1183
1184 RETURN_EGL_ERROR(NULL, err, ret);
1185 }
1186
1187
1188 EGLint EGLAPIENTRY
1189 eglGetError(void)
1190 {
1191 _EGLThreadInfo *t = _eglGetCurrentThread();
1192 EGLint e = t->LastError;
1193 if (!_eglIsCurrentThreadDummy())
1194 t->LastError = EGL_SUCCESS;
1195 return e;
1196 }
1197
1198
1199 /**
1200 ** EGL 1.2
1201 **/
1202
1203 /**
1204 * Specify the client API to use for subsequent calls including:
1205 * eglCreateContext()
1206 * eglGetCurrentContext()
1207 * eglGetCurrentDisplay()
1208 * eglGetCurrentSurface()
1209 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1210 * eglWaitClient()
1211 * eglWaitNative()
1212 * See section 3.7 "Rendering Context" in the EGL specification for details.
1213 */
1214 EGLBoolean EGLAPIENTRY
1215 eglBindAPI(EGLenum api)
1216 {
1217 _EGLThreadInfo *t = _eglGetCurrentThread();
1218
1219 if (_eglIsCurrentThreadDummy())
1220 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_FALSE);
1221
1222 if (!_eglIsApiValid(api))
1223 RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, EGL_FALSE);
1224
1225 t->CurrentAPIIndex = _eglConvertApiToIndex(api);
1226
1227 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1228 }
1229
1230
1231 /**
1232 * Return the last value set with eglBindAPI().
1233 */
1234 EGLenum EGLAPIENTRY
1235 eglQueryAPI(void)
1236 {
1237 _EGLThreadInfo *t = _eglGetCurrentThread();
1238 EGLenum ret;
1239
1240 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1241 ret = _eglConvertApiFromIndex(t->CurrentAPIIndex);
1242
1243 RETURN_EGL_SUCCESS(NULL, ret);
1244 }
1245
1246
1247 EGLSurface EGLAPIENTRY
1248 eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype,
1249 EGLClientBuffer buffer, EGLConfig config,
1250 const EGLint *attrib_list)
1251 {
1252 _EGLDisplay *disp = _eglLockDisplay(dpy);
1253 _EGLConfig *conf = _eglLookupConfig(config, disp);
1254 _EGLDriver *drv;
1255 _EGLSurface *surf;
1256 EGLSurface ret;
1257
1258 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
1259
1260 surf = drv->API.CreatePbufferFromClientBuffer(drv, disp, buftype, buffer,
1261 conf, attrib_list);
1262 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
1263
1264 RETURN_EGL_EVAL(disp, ret);
1265 }
1266
1267
1268 EGLBoolean EGLAPIENTRY
1269 eglReleaseThread(void)
1270 {
1271 /* unbind current contexts */
1272 if (!_eglIsCurrentThreadDummy()) {
1273 _EGLThreadInfo *t = _eglGetCurrentThread();
1274 EGLint api_index = t->CurrentAPIIndex;
1275 EGLint i;
1276
1277 for (i = 0; i < _EGL_API_NUM_APIS; i++) {
1278 _EGLContext *ctx = t->CurrentContexts[i];
1279 if (ctx) {
1280 _EGLDisplay *disp = ctx->Resource.Display;
1281 _EGLDriver *drv;
1282
1283 t->CurrentAPIIndex = i;
1284
1285 mtx_lock(&disp->Mutex);
1286 drv = disp->Driver;
1287 (void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL);
1288 mtx_unlock(&disp->Mutex);
1289 }
1290 }
1291
1292 t->CurrentAPIIndex = api_index;
1293 }
1294
1295 _eglDestroyCurrentThread();
1296
1297 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1298 }
1299
1300
1301 static EGLImage EGLAPIENTRY
1302 eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1303 EGLClientBuffer buffer, const EGLint *attr_list)
1304 {
1305 _EGLDisplay *disp = _eglLockDisplay(dpy);
1306 _EGLContext *context = _eglLookupContext(ctx, disp);
1307 _EGLDriver *drv;
1308 _EGLImage *img;
1309 EGLImage ret;
1310
1311 _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv);
1312 if (!disp->Extensions.KHR_image_base)
1313 RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR);
1314 if (!context && ctx != EGL_NO_CONTEXT)
1315 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR);
1316 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1317 * <ctx> must be EGL_NO_CONTEXT..."
1318 */
1319 if (ctx != EGL_NO_CONTEXT && target == EGL_LINUX_DMA_BUF_EXT)
1320 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
1321
1322 img = drv->API.CreateImageKHR(drv,
1323 disp, context, target, buffer, attr_list);
1324 ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR;
1325
1326 RETURN_EGL_EVAL(disp, ret);
1327 }
1328
1329
1330 EGLImage EGLAPIENTRY
1331 eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1332 EGLClientBuffer buffer, const EGLAttrib *attr_list)
1333 {
1334 EGLImage image;
1335 EGLint *int_attribs = _eglConvertAttribsToInt(attr_list);
1336
1337 if (attr_list && !int_attribs)
1338 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_NO_IMAGE);
1339
1340 image = eglCreateImageKHR(dpy, ctx, target, buffer, int_attribs);
1341 free(int_attribs);
1342 return image;
1343 }
1344
1345
1346 EGLBoolean EGLAPIENTRY
1347 eglDestroyImage(EGLDisplay dpy, EGLImage image)
1348 {
1349 _EGLDisplay *disp = _eglLockDisplay(dpy);
1350 _EGLImage *img = _eglLookupImage(image, disp);
1351 _EGLDriver *drv;
1352 EGLBoolean ret;
1353
1354 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1355 if (!disp->Extensions.KHR_image_base)
1356 RETURN_EGL_EVAL(disp, EGL_FALSE);
1357 if (!img)
1358 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1359
1360 _eglUnlinkImage(img);
1361 ret = drv->API.DestroyImageKHR(drv, disp, img);
1362
1363 RETURN_EGL_EVAL(disp, ret);
1364 }
1365
1366
1367 static EGLSync
1368 _eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list,
1369 const EGLAttrib *attrib_list64, EGLBoolean is64,
1370 EGLenum invalid_type_error)
1371 {
1372 _EGLDisplay *disp = _eglLockDisplay(dpy);
1373 _EGLContext *ctx = _eglGetCurrentContext();
1374 _EGLDriver *drv;
1375 _EGLSync *sync;
1376 EGLSync ret;
1377
1378 _EGL_CHECK_DISPLAY(disp, EGL_NO_SYNC_KHR, drv);
1379
1380 if (!disp->Extensions.KHR_cl_event2 && is64)
1381 RETURN_EGL_EVAL(disp, EGL_NO_SYNC_KHR);
1382
1383 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1384 if (!ctx || ctx->Resource.Display != dpy ||
1385 ctx->ClientAPI != EGL_OPENGL_ES_API)
1386 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
1387
1388 switch (type) {
1389 case EGL_SYNC_FENCE_KHR:
1390 if (!disp->Extensions.KHR_fence_sync)
1391 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1392 break;
1393 case EGL_SYNC_REUSABLE_KHR:
1394 if (!disp->Extensions.KHR_reusable_sync)
1395 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1396 break;
1397 case EGL_SYNC_CL_EVENT_KHR:
1398 if (!disp->Extensions.KHR_cl_event2)
1399 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1400 break;
1401 default:
1402 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1403 }
1404
1405 sync = drv->API.CreateSyncKHR(drv, disp, type, attrib_list, attrib_list64);
1406 ret = (sync) ? _eglLinkSync(sync) : EGL_NO_SYNC_KHR;
1407
1408 RETURN_EGL_EVAL(disp, ret);
1409 }
1410
1411
1412 static EGLSync EGLAPIENTRY
1413 eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list)
1414 {
1415 return _eglCreateSync(dpy, type, attrib_list, NULL, EGL_FALSE,
1416 EGL_BAD_ATTRIBUTE);
1417 }
1418
1419
1420 static EGLSync EGLAPIENTRY
1421 eglCreateSync64KHR(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
1422 {
1423 return _eglCreateSync(dpy, type, NULL, attrib_list, EGL_TRUE,
1424 EGL_BAD_ATTRIBUTE);
1425 }
1426
1427
1428 EGLSync EGLAPIENTRY
1429 eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
1430 {
1431 return _eglCreateSync(dpy, type, NULL, attrib_list, EGL_TRUE,
1432 EGL_BAD_PARAMETER);
1433 }
1434
1435
1436 EGLBoolean EGLAPIENTRY
1437 eglDestroySync(EGLDisplay dpy, EGLSync sync)
1438 {
1439 _EGLDisplay *disp = _eglLockDisplay(dpy);
1440 _EGLSync *s = _eglLookupSync(sync, disp);
1441 _EGLDriver *drv;
1442 EGLBoolean ret;
1443
1444 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1445 assert(disp->Extensions.KHR_reusable_sync ||
1446 disp->Extensions.KHR_fence_sync);
1447
1448 _eglUnlinkSync(s);
1449 ret = drv->API.DestroySyncKHR(drv, disp, s);
1450
1451 RETURN_EGL_EVAL(disp, ret);
1452 }
1453
1454
1455 EGLint EGLAPIENTRY
1456 eglClientWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout)
1457 {
1458 _EGLDisplay *disp = _eglLockDisplay(dpy);
1459 _EGLSync *s = _eglLookupSync(sync, disp);
1460 _EGLDriver *drv;
1461 EGLint ret;
1462
1463 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1464 assert(disp->Extensions.KHR_reusable_sync ||
1465 disp->Extensions.KHR_fence_sync);
1466
1467 if (s->SyncStatus == EGL_SIGNALED_KHR)
1468 RETURN_EGL_EVAL(disp, EGL_CONDITION_SATISFIED_KHR);
1469
1470 ret = drv->API.ClientWaitSyncKHR(drv, disp, s, flags, timeout);
1471
1472 RETURN_EGL_EVAL(disp, ret);
1473 }
1474
1475
1476 static EGLint EGLAPIENTRY
1477 eglWaitSyncKHR(EGLDisplay dpy, EGLSync sync, EGLint flags)
1478 {
1479 _EGLDisplay *disp = _eglLockDisplay(dpy);
1480 _EGLSync *s = _eglLookupSync(sync, disp);
1481 _EGLContext *ctx = _eglGetCurrentContext();
1482 _EGLDriver *drv;
1483 EGLint ret;
1484
1485 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1486 assert(disp->Extensions.KHR_wait_sync);
1487
1488 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1489 if (ctx == EGL_NO_CONTEXT || ctx->ClientAPI != EGL_OPENGL_ES_API)
1490 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
1491
1492 /* the API doesn't allow any flags yet */
1493 if (flags != 0)
1494 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1495
1496 ret = drv->API.WaitSyncKHR(drv, disp, s);
1497
1498 RETURN_EGL_EVAL(disp, ret);
1499 }
1500
1501
1502 EGLBoolean EGLAPIENTRY
1503 eglWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags)
1504 {
1505 /* The KHR version returns EGLint, while the core version returns
1506 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1507 * EGL_TRUE.
1508 */
1509 return eglWaitSyncKHR(dpy, sync, flags);
1510 }
1511
1512
1513 static EGLBoolean EGLAPIENTRY
1514 eglSignalSyncKHR(EGLDisplay dpy, EGLSync sync, EGLenum mode)
1515 {
1516 _EGLDisplay *disp = _eglLockDisplay(dpy);
1517 _EGLSync *s = _eglLookupSync(sync, disp);
1518 _EGLDriver *drv;
1519 EGLBoolean ret;
1520
1521 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1522 assert(disp->Extensions.KHR_reusable_sync);
1523 ret = drv->API.SignalSyncKHR(drv, disp, s, mode);
1524
1525 RETURN_EGL_EVAL(disp, ret);
1526 }
1527
1528
1529 EGLBoolean EGLAPIENTRY
1530 eglGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value)
1531 {
1532 _EGLDisplay *disp = _eglLockDisplay(dpy);
1533 _EGLSync *s = _eglLookupSync(sync, disp);
1534 _EGLDriver *drv;
1535 EGLBoolean ret;
1536
1537 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1538 assert(disp->Extensions.KHR_reusable_sync ||
1539 disp->Extensions.KHR_fence_sync);
1540 ret = drv->API.GetSyncAttrib(drv, disp, s, attribute, value);
1541
1542 RETURN_EGL_EVAL(disp, ret);
1543 }
1544
1545
1546 static EGLBoolean EGLAPIENTRY
1547 eglGetSyncAttribKHR(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLint *value)
1548 {
1549 EGLAttrib attrib;
1550 EGLBoolean result;
1551
1552 if (!value)
1553 RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, EGL_FALSE);
1554
1555 attrib = *value;
1556 result = eglGetSyncAttrib(dpy, sync, attribute, &attrib);
1557
1558 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
1559 *
1560 * If any error occurs, <*value> is not modified.
1561 */
1562 if (result == EGL_FALSE)
1563 return result;
1564
1565 *value = attrib;
1566 return result;
1567 }
1568
1569
1570 static EGLBoolean EGLAPIENTRY
1571 eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface,
1572 EGLint numRects, const EGLint *rects)
1573 {
1574 _EGLContext *ctx = _eglGetCurrentContext();
1575 _EGLDisplay *disp = _eglLockDisplay(dpy);
1576 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1577 _EGLDriver *drv;
1578 EGLBoolean ret;
1579
1580 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1581
1582 if (!disp->Extensions.NOK_swap_region)
1583 RETURN_EGL_EVAL(disp, EGL_FALSE);
1584
1585 /* surface must be bound to current context in EGL 1.4 */
1586 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1587 surf != ctx->DrawSurface)
1588 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1589
1590 ret = drv->API.SwapBuffersRegionNOK(drv, disp, surf, numRects, rects);
1591
1592 RETURN_EGL_EVAL(disp, ret);
1593 }
1594
1595
1596 static EGLImage EGLAPIENTRY
1597 eglCreateDRMImageMESA(EGLDisplay dpy, const EGLint *attr_list)
1598 {
1599 _EGLDisplay *disp = _eglLockDisplay(dpy);
1600 _EGLDriver *drv;
1601 _EGLImage *img;
1602 EGLImage ret;
1603
1604 _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv);
1605 if (!disp->Extensions.MESA_drm_image)
1606 RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR);
1607
1608 img = drv->API.CreateDRMImageMESA(drv, disp, attr_list);
1609 ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR;
1610
1611 RETURN_EGL_EVAL(disp, ret);
1612 }
1613
1614 static EGLBoolean EGLAPIENTRY
1615 eglExportDRMImageMESA(EGLDisplay dpy, EGLImage image,
1616 EGLint *name, EGLint *handle, EGLint *stride)
1617 {
1618 _EGLDisplay *disp = _eglLockDisplay(dpy);
1619 _EGLImage *img = _eglLookupImage(image, disp);
1620 _EGLDriver *drv;
1621 EGLBoolean ret;
1622
1623 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1624 assert(disp->Extensions.MESA_drm_image);
1625
1626 if (!img)
1627 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1628
1629 ret = drv->API.ExportDRMImageMESA(drv, disp, img, name, handle, stride);
1630
1631 RETURN_EGL_EVAL(disp, ret);
1632 }
1633
1634
1635 struct wl_display;
1636
1637 static EGLBoolean EGLAPIENTRY
1638 eglBindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
1639 {
1640 _EGLDisplay *disp = _eglLockDisplay(dpy);
1641 _EGLDriver *drv;
1642 EGLBoolean ret;
1643
1644 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1645 assert(disp->Extensions.WL_bind_wayland_display);
1646
1647 if (!display)
1648 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1649
1650 ret = drv->API.BindWaylandDisplayWL(drv, disp, display);
1651
1652 RETURN_EGL_EVAL(disp, ret);
1653 }
1654
1655 static EGLBoolean EGLAPIENTRY
1656 eglUnbindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
1657 {
1658 _EGLDisplay *disp = _eglLockDisplay(dpy);
1659 _EGLDriver *drv;
1660 EGLBoolean ret;
1661
1662 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1663 assert(disp->Extensions.WL_bind_wayland_display);
1664
1665 if (!display)
1666 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1667
1668 ret = drv->API.UnbindWaylandDisplayWL(drv, disp, display);
1669
1670 RETURN_EGL_EVAL(disp, ret);
1671 }
1672
1673 static EGLBoolean EGLAPIENTRY
1674 eglQueryWaylandBufferWL(EGLDisplay dpy, struct wl_resource *buffer,
1675 EGLint attribute, EGLint *value)
1676 {
1677 _EGLDisplay *disp = _eglLockDisplay(dpy);
1678 _EGLDriver *drv;
1679 EGLBoolean ret;
1680
1681 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1682 assert(disp->Extensions.WL_bind_wayland_display);
1683
1684 if (!buffer)
1685 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1686
1687 ret = drv->API.QueryWaylandBufferWL(drv, disp, buffer, attribute, value);
1688
1689 RETURN_EGL_EVAL(disp, ret);
1690 }
1691
1692
1693 static struct wl_buffer * EGLAPIENTRY
1694 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy, EGLImage image)
1695 {
1696 _EGLDisplay *disp = _eglLockDisplay(dpy);
1697 _EGLImage *img;
1698 _EGLDriver *drv;
1699 struct wl_buffer *ret;
1700
1701 _EGL_CHECK_DISPLAY(disp, NULL, drv);
1702 assert(disp->Extensions.WL_create_wayland_buffer_from_image);
1703
1704 img = _eglLookupImage(image, disp);
1705
1706 if (!img)
1707 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL);
1708
1709 ret = drv->API.CreateWaylandBufferFromImageWL(drv, disp, img);
1710
1711 RETURN_EGL_EVAL(disp, ret);
1712 }
1713
1714 static EGLBoolean EGLAPIENTRY
1715 eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface,
1716 EGLint x, EGLint y, EGLint width, EGLint height)
1717 {
1718 _EGLDisplay *disp = _eglLockDisplay(dpy);
1719 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1720 _EGLDriver *drv;
1721 EGLBoolean ret;
1722
1723 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1724
1725 if (!disp->Extensions.NV_post_sub_buffer)
1726 RETURN_EGL_EVAL(disp, EGL_FALSE);
1727
1728 ret = drv->API.PostSubBufferNV(drv, disp, surf, x, y, width, height);
1729
1730 RETURN_EGL_EVAL(disp, ret);
1731 }
1732
1733 static EGLBoolean EGLAPIENTRY
1734 eglGetSyncValuesCHROMIUM(EGLDisplay display, EGLSurface surface,
1735 EGLuint64KHR *ust, EGLuint64KHR *msc,
1736 EGLuint64KHR *sbc)
1737 {
1738 _EGLDisplay *disp = _eglLockDisplay(display);
1739 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1740 _EGLDriver *drv;
1741 EGLBoolean ret;
1742
1743 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1744 if (!disp->Extensions.CHROMIUM_sync_control)
1745 RETURN_EGL_EVAL(disp, EGL_FALSE);
1746
1747 if (!ust || !msc || !sbc)
1748 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1749
1750 ret = drv->API.GetSyncValuesCHROMIUM(disp, surf, ust, msc, sbc);
1751
1752 RETURN_EGL_EVAL(disp, ret);
1753 }
1754
1755 static EGLBoolean EGLAPIENTRY
1756 eglExportDMABUFImageQueryMESA(EGLDisplay dpy, EGLImage image,
1757 EGLint *fourcc, EGLint *nplanes,
1758 EGLuint64KHR *modifiers)
1759 {
1760 _EGLDisplay *disp = _eglLockDisplay(dpy);
1761 _EGLImage *img = _eglLookupImage(image, disp);
1762 _EGLDriver *drv;
1763 EGLBoolean ret;
1764
1765 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1766 assert(disp->Extensions.MESA_image_dma_buf_export);
1767
1768 if (!img)
1769 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1770
1771 ret = drv->API.ExportDMABUFImageQueryMESA(drv, disp, img, fourcc, nplanes,
1772 modifiers);
1773
1774 RETURN_EGL_EVAL(disp, ret);
1775 }
1776
1777 static EGLBoolean EGLAPIENTRY
1778 eglExportDMABUFImageMESA(EGLDisplay dpy, EGLImage image,
1779 int *fds, EGLint *strides, EGLint *offsets)
1780 {
1781 _EGLDisplay *disp = _eglLockDisplay(dpy);
1782 _EGLImage *img = _eglLookupImage(image, disp);
1783 _EGLDriver *drv;
1784 EGLBoolean ret;
1785
1786 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1787 assert(disp->Extensions.MESA_image_dma_buf_export);
1788
1789 if (!img)
1790 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1791
1792 ret = drv->API.ExportDMABUFImageMESA(drv, disp, img, fds, strides, offsets);
1793
1794 RETURN_EGL_EVAL(disp, ret);
1795 }
1796
1797 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
1798 eglGetProcAddress(const char *procname)
1799 {
1800 static const struct {
1801 const char *name;
1802 _EGLProc function;
1803 } egl_functions[] = {
1804 /* core functions queryable in the presence of
1805 * EGL_KHR_get_all_proc_addresses or EGL 1.5
1806 */
1807 /* alphabetical order */
1808 { "eglBindAPI", (_EGLProc) eglBindAPI },
1809 { "eglBindTexImage", (_EGLProc) eglBindTexImage },
1810 { "eglChooseConfig", (_EGLProc) eglChooseConfig },
1811 { "eglCopyBuffers", (_EGLProc) eglCopyBuffers },
1812 { "eglCreateContext", (_EGLProc) eglCreateContext },
1813 { "eglCreatePbufferFromClientBuffer", (_EGLProc) eglCreatePbufferFromClientBuffer },
1814 { "eglCreatePbufferSurface", (_EGLProc) eglCreatePbufferSurface },
1815 { "eglCreatePixmapSurface", (_EGLProc) eglCreatePixmapSurface },
1816 { "eglCreateWindowSurface", (_EGLProc) eglCreateWindowSurface },
1817 { "eglDestroyContext", (_EGLProc) eglDestroyContext },
1818 { "eglDestroySurface", (_EGLProc) eglDestroySurface },
1819 { "eglGetConfigAttrib", (_EGLProc) eglGetConfigAttrib },
1820 { "eglGetConfigs", (_EGLProc) eglGetConfigs },
1821 { "eglGetCurrentContext", (_EGLProc) eglGetCurrentContext },
1822 { "eglGetCurrentDisplay", (_EGLProc) eglGetCurrentDisplay },
1823 { "eglGetCurrentSurface", (_EGLProc) eglGetCurrentSurface },
1824 { "eglGetDisplay", (_EGLProc) eglGetDisplay },
1825 { "eglGetError", (_EGLProc) eglGetError },
1826 { "eglGetProcAddress", (_EGLProc) eglGetProcAddress },
1827 { "eglInitialize", (_EGLProc) eglInitialize },
1828 { "eglMakeCurrent", (_EGLProc) eglMakeCurrent },
1829 { "eglQueryAPI", (_EGLProc) eglQueryAPI },
1830 { "eglQueryContext", (_EGLProc) eglQueryContext },
1831 { "eglQueryString", (_EGLProc) eglQueryString },
1832 { "eglQuerySurface", (_EGLProc) eglQuerySurface },
1833 { "eglReleaseTexImage", (_EGLProc) eglReleaseTexImage },
1834 { "eglReleaseThread", (_EGLProc) eglReleaseThread },
1835 { "eglSurfaceAttrib", (_EGLProc) eglSurfaceAttrib },
1836 { "eglSwapBuffers", (_EGLProc) eglSwapBuffers },
1837 { "eglSwapInterval", (_EGLProc) eglSwapInterval },
1838 { "eglTerminate", (_EGLProc) eglTerminate },
1839 { "eglWaitClient", (_EGLProc) eglWaitClient },
1840 { "eglWaitGL", (_EGLProc) eglWaitGL },
1841 { "eglWaitNative", (_EGLProc) eglWaitNative },
1842 { "eglCreateSync", (_EGLProc) eglCreateSync },
1843 { "eglDestroySync", (_EGLProc) eglDestroySync },
1844 { "eglClientWaitSync", (_EGLProc) eglClientWaitSync },
1845 { "eglGetSyncAttrib", (_EGLProc) eglGetSyncAttrib },
1846 { "eglWaitSync", (_EGLProc) eglWaitSync },
1847 { "eglCreateImage", (_EGLProc) eglCreateImage },
1848 { "eglDestroyImage", (_EGLProc) eglDestroyImage },
1849 { "eglGetPlatformDisplay", (_EGLProc) eglGetPlatformDisplay },
1850 { "eglCreatePlatformWindowSurface", (_EGLProc) eglCreatePlatformWindowSurface },
1851 { "eglCreatePlatformPixmapSurface", (_EGLProc) eglCreatePlatformPixmapSurface },
1852 { "eglCreateImageKHR", (_EGLProc) eglCreateImageKHR },
1853 { "eglDestroyImageKHR", (_EGLProc) eglDestroyImage },
1854 { "eglCreateSyncKHR", (_EGLProc) eglCreateSyncKHR },
1855 { "eglCreateSync64KHR", (_EGLProc) eglCreateSync64KHR },
1856 { "eglDestroySyncKHR", (_EGLProc) eglDestroySync },
1857 { "eglClientWaitSyncKHR", (_EGLProc) eglClientWaitSync },
1858 { "eglWaitSyncKHR", (_EGLProc) eglWaitSyncKHR },
1859 { "eglSignalSyncKHR", (_EGLProc) eglSignalSyncKHR },
1860 { "eglGetSyncAttribKHR", (_EGLProc) eglGetSyncAttribKHR },
1861 { "eglSwapBuffersRegionNOK", (_EGLProc) eglSwapBuffersRegionNOK },
1862 { "eglCreateDRMImageMESA", (_EGLProc) eglCreateDRMImageMESA },
1863 { "eglExportDRMImageMESA", (_EGLProc) eglExportDRMImageMESA },
1864 { "eglBindWaylandDisplayWL", (_EGLProc) eglBindWaylandDisplayWL },
1865 { "eglUnbindWaylandDisplayWL", (_EGLProc) eglUnbindWaylandDisplayWL },
1866 { "eglQueryWaylandBufferWL", (_EGLProc) eglQueryWaylandBufferWL },
1867 { "eglCreateWaylandBufferFromImageWL", (_EGLProc) eglCreateWaylandBufferFromImageWL },
1868 { "eglPostSubBufferNV", (_EGLProc) eglPostSubBufferNV },
1869 { "eglSwapBuffersWithDamageEXT", (_EGLProc) eglSwapBuffersWithDamageEXT },
1870 { "eglGetPlatformDisplayEXT", (_EGLProc) eglGetPlatformDisplayEXT },
1871 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc) eglCreatePlatformWindowSurfaceEXT },
1872 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc) eglCreatePlatformPixmapSurfaceEXT },
1873 { "eglGetSyncValuesCHROMIUM", (_EGLProc) eglGetSyncValuesCHROMIUM },
1874 { "eglExportDMABUFImageQueryMESA", (_EGLProc) eglExportDMABUFImageQueryMESA },
1875 { "eglExportDMABUFImageMESA", (_EGLProc) eglExportDMABUFImageMESA },
1876 { NULL, NULL }
1877 };
1878 EGLint i;
1879 _EGLProc ret;
1880
1881 if (!procname)
1882 RETURN_EGL_SUCCESS(NULL, NULL);
1883
1884 ret = NULL;
1885 if (strncmp(procname, "egl", 3) == 0) {
1886 for (i = 0; egl_functions[i].name; i++) {
1887 if (strcmp(egl_functions[i].name, procname) == 0) {
1888 ret = egl_functions[i].function;
1889 break;
1890 }
1891 }
1892 }
1893 if (!ret)
1894 ret = _eglGetDriverProc(procname);
1895
1896 RETURN_EGL_SUCCESS(NULL, ret);
1897 }