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