egl: remove ifdef $(egl_extension) compile guards
[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_vg_parent_image);
409 _EGL_CHECK_EXTENSION(KHR_wait_sync);
410
411 _EGL_CHECK_EXTENSION(MESA_configless_context);
412 _EGL_CHECK_EXTENSION(MESA_drm_display);
413 _EGL_CHECK_EXTENSION(MESA_drm_image);
414 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export);
415
416 _EGL_CHECK_EXTENSION(NOK_swap_region);
417 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap);
418
419 _EGL_CHECK_EXTENSION(NV_post_sub_buffer);
420
421 _EGL_CHECK_EXTENSION(WL_bind_wayland_display);
422 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image);
423
424 #undef _EGL_CHECK_EXTENSION
425 }
426
427 static void
428 _eglCreateAPIsString(_EGLDisplay *dpy)
429 {
430 if (dpy->ClientAPIs & EGL_OPENGL_BIT)
431 strcat(dpy->ClientAPIsString, "OpenGL ");
432
433 if (dpy->ClientAPIs & EGL_OPENGL_ES_BIT)
434 strcat(dpy->ClientAPIsString, "OpenGL_ES ");
435
436 if (dpy->ClientAPIs & EGL_OPENGL_ES2_BIT)
437 strcat(dpy->ClientAPIsString, "OpenGL_ES2 ");
438
439 if (dpy->ClientAPIs & EGL_OPENGL_ES3_BIT_KHR)
440 strcat(dpy->ClientAPIsString, "OpenGL_ES3 ");
441
442 if (dpy->ClientAPIs & EGL_OPENVG_BIT)
443 strcat(dpy->ClientAPIsString, "OpenVG ");
444
445 assert(strlen(dpy->ClientAPIsString) < sizeof(dpy->ClientAPIsString));
446 }
447
448 static void
449 _eglComputeVersion(_EGLDisplay *disp)
450 {
451 disp->Version = 14;
452
453 if (disp->Extensions.KHR_fence_sync &&
454 disp->Extensions.KHR_cl_event2 &&
455 disp->Extensions.KHR_wait_sync &&
456 disp->Extensions.KHR_image_base &&
457 disp->Extensions.KHR_gl_texture_2D_image &&
458 disp->Extensions.KHR_gl_texture_3D_image &&
459 disp->Extensions.KHR_gl_texture_cubemap_image &&
460 disp->Extensions.KHR_gl_renderbuffer_image &&
461 disp->Extensions.KHR_create_context &&
462 disp->Extensions.EXT_create_context_robustness &&
463 disp->Extensions.KHR_get_all_proc_addresses &&
464 disp->Extensions.KHR_gl_colorspace &&
465 disp->Extensions.KHR_surfaceless_context)
466 disp->Version = 15;
467 }
468
469 /**
470 * This is typically the second EGL function that an application calls.
471 * Here we load/initialize the actual hardware driver.
472 */
473 EGLBoolean EGLAPIENTRY
474 eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
475 {
476 _EGLDisplay *disp = _eglLockDisplay(dpy);
477
478 if (!disp)
479 RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE);
480
481 if (!disp->Initialized) {
482 if (!_eglMatchDriver(disp, EGL_FALSE))
483 RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE);
484
485 /* limit to APIs supported by core */
486 disp->ClientAPIs &= _EGL_API_ALL_BITS;
487
488 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
489 * classifies it as an EGL display extension, though conceptually it's an
490 * EGL client extension.
491 *
492 * From the EGL_KHR_get_all_proc_addresses spec:
493 *
494 * The EGL implementation must expose the name
495 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
496 * EGL_KHR_get_all_proc_addresses and supports
497 * EGL_EXT_client_extensions.
498 *
499 * Mesa unconditionally exposes both client extensions mentioned above,
500 * so the spec requires that each EGLDisplay unconditionally expose
501 * EGL_KHR_get_all_proc_addresses also.
502 */
503 disp->Extensions.KHR_get_all_proc_addresses = EGL_TRUE;
504
505 _eglComputeVersion(disp);
506 _eglCreateExtensionsString(disp);
507 _eglCreateAPIsString(disp);
508 snprintf(disp->VersionString, sizeof(disp->VersionString),
509 "%d.%d (%s)", disp->Version / 10, disp->Version % 10,
510 disp->Driver->Name);
511 }
512
513 /* Update applications version of major and minor if not NULL */
514 if ((major != NULL) && (minor != NULL)) {
515 *major = disp->Version / 10;
516 *minor = disp->Version % 10;
517 }
518
519 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
520 }
521
522
523 EGLBoolean EGLAPIENTRY
524 eglTerminate(EGLDisplay dpy)
525 {
526 _EGLDisplay *disp = _eglLockDisplay(dpy);
527
528 if (!disp)
529 RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE);
530
531 if (disp->Initialized) {
532 _EGLDriver *drv = disp->Driver;
533
534 drv->API.Terminate(drv, disp);
535 /* do not reset disp->Driver */
536 disp->ClientAPIsString[0] = 0;
537 disp->Initialized = EGL_FALSE;
538 }
539
540 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
541 }
542
543
544 const char * EGLAPIENTRY
545 eglQueryString(EGLDisplay dpy, EGLint name)
546 {
547 _EGLDisplay *disp;
548 _EGLDriver *drv;
549
550 if (dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS) {
551 RETURN_EGL_SUCCESS(NULL, _eglGlobal.ClientExtensionString);
552 }
553
554 disp = _eglLockDisplay(dpy);
555 _EGL_CHECK_DISPLAY(disp, NULL, drv);
556
557 switch (name) {
558 case EGL_VENDOR:
559 RETURN_EGL_SUCCESS(disp, _EGL_VENDOR_STRING);
560 case EGL_VERSION:
561 RETURN_EGL_SUCCESS(disp, disp->VersionString);
562 case EGL_EXTENSIONS:
563 RETURN_EGL_SUCCESS(disp, disp->ExtensionsString);
564 case EGL_CLIENT_APIS:
565 RETURN_EGL_SUCCESS(disp, disp->ClientAPIsString);
566 default:
567 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL);
568 }
569 }
570
571
572 EGLBoolean EGLAPIENTRY
573 eglGetConfigs(EGLDisplay dpy, EGLConfig *configs,
574 EGLint config_size, EGLint *num_config)
575 {
576 _EGLDisplay *disp = _eglLockDisplay(dpy);
577 _EGLDriver *drv;
578 EGLBoolean ret;
579
580 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
581 ret = drv->API.GetConfigs(drv, disp, configs, config_size, num_config);
582
583 RETURN_EGL_EVAL(disp, ret);
584 }
585
586
587 EGLBoolean EGLAPIENTRY
588 eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs,
589 EGLint config_size, EGLint *num_config)
590 {
591 _EGLDisplay *disp = _eglLockDisplay(dpy);
592 _EGLDriver *drv;
593 EGLBoolean ret;
594
595 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
596 ret = drv->API.ChooseConfig(drv, disp, attrib_list, configs,
597 config_size, num_config);
598
599 RETURN_EGL_EVAL(disp, ret);
600 }
601
602
603 EGLBoolean EGLAPIENTRY
604 eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
605 EGLint attribute, EGLint *value)
606 {
607 _EGLDisplay *disp = _eglLockDisplay(dpy);
608 _EGLConfig *conf = _eglLookupConfig(config, disp);
609 _EGLDriver *drv;
610 EGLBoolean ret;
611
612 _EGL_CHECK_CONFIG(disp, conf, EGL_FALSE, drv);
613 ret = drv->API.GetConfigAttrib(drv, disp, conf, attribute, value);
614
615 RETURN_EGL_EVAL(disp, ret);
616 }
617
618
619 EGLContext EGLAPIENTRY
620 eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list,
621 const EGLint *attrib_list)
622 {
623 _EGLDisplay *disp = _eglLockDisplay(dpy);
624 _EGLConfig *conf = _eglLookupConfig(config, disp);
625 _EGLContext *share = _eglLookupContext(share_list, disp);
626 _EGLDriver *drv;
627 _EGLContext *context;
628 EGLContext ret;
629
630 _EGL_CHECK_DISPLAY(disp, EGL_NO_CONTEXT, drv);
631
632 if (!config && !disp->Extensions.MESA_configless_context)
633 RETURN_EGL_ERROR(disp, EGL_BAD_CONFIG, EGL_NO_CONTEXT);
634
635 if (!share && share_list != EGL_NO_CONTEXT)
636 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_CONTEXT);
637
638 context = drv->API.CreateContext(drv, disp, conf, share, attrib_list);
639 ret = (context) ? _eglLinkContext(context) : EGL_NO_CONTEXT;
640
641 RETURN_EGL_EVAL(disp, ret);
642 }
643
644
645 EGLBoolean EGLAPIENTRY
646 eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
647 {
648 _EGLDisplay *disp = _eglLockDisplay(dpy);
649 _EGLContext *context = _eglLookupContext(ctx, disp);
650 _EGLDriver *drv;
651 EGLBoolean ret;
652
653 _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv);
654 _eglUnlinkContext(context);
655 ret = drv->API.DestroyContext(drv, disp, context);
656
657 RETURN_EGL_EVAL(disp, ret);
658 }
659
660
661 EGLBoolean EGLAPIENTRY
662 eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read,
663 EGLContext ctx)
664 {
665 _EGLDisplay *disp = _eglLockDisplay(dpy);
666 _EGLContext *context = _eglLookupContext(ctx, disp);
667 _EGLSurface *draw_surf = _eglLookupSurface(draw, disp);
668 _EGLSurface *read_surf = _eglLookupSurface(read, disp);
669 _EGLDriver *drv;
670 EGLBoolean ret;
671
672 if (!disp)
673 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE);
674 drv = disp->Driver;
675
676 /* display is allowed to be uninitialized under certain condition */
677 if (!disp->Initialized) {
678 if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE ||
679 ctx != EGL_NO_CONTEXT)
680 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE);
681 }
682 if (!drv)
683 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
684
685 if (!context && ctx != EGL_NO_CONTEXT)
686 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE);
687 if (!draw_surf || !read_surf) {
688 /* From the EGL 1.4 (20130211) spec:
689 *
690 * To release the current context without assigning a new one, set ctx
691 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
692 */
693 if (!disp->Extensions.KHR_surfaceless_context && ctx != EGL_NO_CONTEXT)
694 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
695
696 if ((!draw_surf && draw != EGL_NO_SURFACE) ||
697 (!read_surf && read != EGL_NO_SURFACE))
698 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
699 if (draw_surf || read_surf)
700 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
701 }
702
703 ret = drv->API.MakeCurrent(drv, disp, draw_surf, read_surf, context);
704
705 RETURN_EGL_EVAL(disp, ret);
706 }
707
708
709 EGLBoolean EGLAPIENTRY
710 eglQueryContext(EGLDisplay dpy, EGLContext ctx,
711 EGLint attribute, EGLint *value)
712 {
713 _EGLDisplay *disp = _eglLockDisplay(dpy);
714 _EGLContext *context = _eglLookupContext(ctx, disp);
715 _EGLDriver *drv;
716 EGLBoolean ret;
717
718 _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv);
719 ret = drv->API.QueryContext(drv, disp, context, attribute, value);
720
721 RETURN_EGL_EVAL(disp, ret);
722 }
723
724
725 static EGLSurface
726 _eglCreateWindowSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
727 void *native_window, const EGLint *attrib_list)
728 {
729 _EGLConfig *conf = _eglLookupConfig(config, disp);
730 _EGLDriver *drv;
731 _EGLSurface *surf;
732 EGLSurface ret;
733
734 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
735
736 if (native_window == NULL)
737 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
738
739 surf = drv->API.CreateWindowSurface(drv, disp, conf, native_window,
740 attrib_list);
741 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
742
743 RETURN_EGL_EVAL(disp, ret);
744 }
745
746
747 EGLSurface EGLAPIENTRY
748 eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
749 EGLNativeWindowType window, const EGLint *attrib_list)
750 {
751 _EGLDisplay *disp = _eglLockDisplay(dpy);
752 STATIC_ASSERT(sizeof(void*) == sizeof(window));
753 return _eglCreateWindowSurfaceCommon(disp, config, (void*) window,
754 attrib_list);
755 }
756
757
758 static EGLSurface EGLAPIENTRY
759 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config,
760 void *native_window,
761 const EGLint *attrib_list)
762 {
763 _EGLDisplay *disp = _eglLockDisplay(dpy);
764
765 #ifdef HAVE_X11_PLATFORM
766 if (disp->Platform == _EGL_PLATFORM_X11 && native_window != NULL) {
767 /* The `native_window` parameter for the X11 platform differs between
768 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
769 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
770 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
771 * `Window*`. Convert `Window*` to `Window` because that's what
772 * dri2_x11_create_window_surface() expects.
773 */
774 native_window = (void*) (* (Window*) native_window);
775 }
776 #endif
777
778 return _eglCreateWindowSurfaceCommon(disp, config, native_window,
779 attrib_list);
780 }
781
782
783 EGLSurface EGLAPIENTRY
784 eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config,
785 void *native_window,
786 const EGLAttrib *attrib_list)
787 {
788 EGLSurface surface;
789 EGLint *int_attribs = _eglConvertAttribsToInt(attrib_list);
790
791 if (attrib_list && !int_attribs)
792 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_NO_SURFACE);
793
794 surface = eglCreatePlatformWindowSurfaceEXT(dpy, config, native_window,
795 int_attribs);
796 free(int_attribs);
797 return surface;
798 }
799
800
801 static EGLSurface
802 _eglCreatePixmapSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
803 void *native_pixmap, const EGLint *attrib_list)
804 {
805 _EGLConfig *conf = _eglLookupConfig(config, disp);
806 _EGLDriver *drv;
807 _EGLSurface *surf;
808 EGLSurface ret;
809
810 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
811 surf = drv->API.CreatePixmapSurface(drv, disp, conf, native_pixmap,
812 attrib_list);
813 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
814
815 RETURN_EGL_EVAL(disp, ret);
816 }
817
818
819 EGLSurface EGLAPIENTRY
820 eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config,
821 EGLNativePixmapType pixmap, const EGLint *attrib_list)
822 {
823 _EGLDisplay *disp = _eglLockDisplay(dpy);
824 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap));
825 return _eglCreatePixmapSurfaceCommon(disp, config, (void*) pixmap,
826 attrib_list);
827 }
828
829 static EGLSurface EGLAPIENTRY
830 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config,
831 void *native_pixmap,
832 const EGLint *attrib_list)
833 {
834 _EGLDisplay *disp = _eglLockDisplay(dpy);
835
836 #ifdef HAVE_X11_PLATFORM
837 /* The `native_pixmap` parameter for the X11 platform differs between
838 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
839 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
840 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
841 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
842 * dri2_x11_create_pixmap_surface() expects.
843 */
844 if (disp->Platform == _EGL_PLATFORM_X11 && native_pixmap != NULL) {
845 native_pixmap = (void*) (* (Pixmap*) native_pixmap);
846 }
847 #endif
848
849 return _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap,
850 attrib_list);
851 }
852
853
854 EGLSurface EGLAPIENTRY
855 eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config,
856 void *native_pixmap,
857 const EGLAttrib *attrib_list)
858 {
859 EGLSurface surface;
860 EGLint *int_attribs = _eglConvertAttribsToInt(attrib_list);
861
862 if (attrib_list && !int_attribs)
863 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_NO_SURFACE);
864
865 surface = eglCreatePlatformPixmapSurfaceEXT(dpy, config, native_pixmap,
866 int_attribs);
867 free(int_attribs);
868 return surface;
869 }
870
871
872 EGLSurface EGLAPIENTRY
873 eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,
874 const EGLint *attrib_list)
875 {
876 _EGLDisplay *disp = _eglLockDisplay(dpy);
877 _EGLConfig *conf = _eglLookupConfig(config, disp);
878 _EGLDriver *drv;
879 _EGLSurface *surf;
880 EGLSurface ret;
881
882 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
883
884 surf = drv->API.CreatePbufferSurface(drv, disp, conf, attrib_list);
885 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
886
887 RETURN_EGL_EVAL(disp, ret);
888 }
889
890
891 EGLBoolean EGLAPIENTRY
892 eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
893 {
894 _EGLDisplay *disp = _eglLockDisplay(dpy);
895 _EGLSurface *surf = _eglLookupSurface(surface, disp);
896 _EGLDriver *drv;
897 EGLBoolean ret;
898
899 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
900 _eglUnlinkSurface(surf);
901 ret = drv->API.DestroySurface(drv, disp, surf);
902
903 RETURN_EGL_EVAL(disp, ret);
904 }
905
906 EGLBoolean EGLAPIENTRY
907 eglQuerySurface(EGLDisplay dpy, EGLSurface surface,
908 EGLint attribute, EGLint *value)
909 {
910 _EGLDisplay *disp = _eglLockDisplay(dpy);
911 _EGLSurface *surf = _eglLookupSurface(surface, disp);
912 _EGLDriver *drv;
913 EGLBoolean ret;
914
915 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
916 ret = drv->API.QuerySurface(drv, disp, surf, attribute, value);
917
918 RETURN_EGL_EVAL(disp, ret);
919 }
920
921 EGLBoolean EGLAPIENTRY
922 eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface,
923 EGLint attribute, EGLint value)
924 {
925 _EGLDisplay *disp = _eglLockDisplay(dpy);
926 _EGLSurface *surf = _eglLookupSurface(surface, disp);
927 _EGLDriver *drv;
928 EGLBoolean ret;
929
930 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
931 ret = drv->API.SurfaceAttrib(drv, disp, surf, attribute, value);
932
933 RETURN_EGL_EVAL(disp, ret);
934 }
935
936
937 EGLBoolean EGLAPIENTRY
938 eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
939 {
940 _EGLDisplay *disp = _eglLockDisplay(dpy);
941 _EGLSurface *surf = _eglLookupSurface(surface, disp);
942 _EGLDriver *drv;
943 EGLBoolean ret;
944
945 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
946 ret = drv->API.BindTexImage(drv, disp, surf, buffer);
947
948 RETURN_EGL_EVAL(disp, ret);
949 }
950
951
952 EGLBoolean EGLAPIENTRY
953 eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
954 {
955 _EGLDisplay *disp = _eglLockDisplay(dpy);
956 _EGLSurface *surf = _eglLookupSurface(surface, disp);
957 _EGLDriver *drv;
958 EGLBoolean ret;
959
960 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
961 ret = drv->API.ReleaseTexImage(drv, disp, surf, buffer);
962
963 RETURN_EGL_EVAL(disp, ret);
964 }
965
966
967 EGLBoolean EGLAPIENTRY
968 eglSwapInterval(EGLDisplay dpy, EGLint interval)
969 {
970 _EGLDisplay *disp = _eglLockDisplay(dpy);
971 _EGLContext *ctx = _eglGetCurrentContext();
972 _EGLSurface *surf;
973 _EGLDriver *drv;
974 EGLBoolean ret;
975
976 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
977
978 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
979 ctx->Resource.Display != disp)
980 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE);
981
982 surf = ctx->DrawSurface;
983 if (_eglGetSurfaceHandle(surf) == EGL_NO_SURFACE)
984 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
985
986 ret = drv->API.SwapInterval(drv, disp, surf, interval);
987
988 RETURN_EGL_EVAL(disp, ret);
989 }
990
991
992 EGLBoolean EGLAPIENTRY
993 eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
994 {
995 _EGLContext *ctx = _eglGetCurrentContext();
996 _EGLDisplay *disp = _eglLockDisplay(dpy);
997 _EGLSurface *surf = _eglLookupSurface(surface, disp);
998 _EGLDriver *drv;
999 EGLBoolean ret;
1000
1001 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1002
1003 /* surface must be bound to current context in EGL 1.4 */
1004 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1005 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1006 surf != ctx->DrawSurface)
1007 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1008 #endif
1009
1010 ret = drv->API.SwapBuffers(drv, disp, surf);
1011
1012 RETURN_EGL_EVAL(disp, ret);
1013 }
1014
1015
1016 static EGLBoolean EGLAPIENTRY
1017 eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface,
1018 EGLint *rects, EGLint n_rects)
1019 {
1020 _EGLContext *ctx = _eglGetCurrentContext();
1021 _EGLDisplay *disp = _eglLockDisplay(dpy);
1022 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1023 _EGLDriver *drv;
1024 EGLBoolean ret;
1025
1026 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1027
1028 /* surface must be bound to current context in EGL 1.4 */
1029 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1030 surf != ctx->DrawSurface)
1031 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1032
1033 if ((n_rects > 0 && rects == NULL) || n_rects < 0)
1034 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1035
1036 ret = drv->API.SwapBuffersWithDamageEXT(drv, disp, surf, rects, n_rects);
1037
1038 RETURN_EGL_EVAL(disp, ret);
1039 }
1040
1041 EGLBoolean EGLAPIENTRY
1042 eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
1043 {
1044 _EGLDisplay *disp = _eglLockDisplay(dpy);
1045 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1046 _EGLDriver *drv;
1047 EGLBoolean ret;
1048 void *native_pixmap_ptr;
1049
1050 STATIC_ASSERT(sizeof(void*) == sizeof(target));
1051 native_pixmap_ptr = (void*) target;
1052
1053 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1054 if (disp->Platform != _eglGetNativePlatform(disp->PlatformDisplay))
1055 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_FALSE);
1056 ret = drv->API.CopyBuffers(drv, disp, surf, native_pixmap_ptr);
1057
1058 RETURN_EGL_EVAL(disp, ret);
1059 }
1060
1061
1062 EGLBoolean EGLAPIENTRY
1063 eglWaitClient(void)
1064 {
1065 _EGLContext *ctx = _eglGetCurrentContext();
1066 _EGLDisplay *disp;
1067 _EGLDriver *drv;
1068 EGLBoolean ret;
1069
1070 if (!ctx)
1071 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1072
1073 disp = ctx->Resource.Display;
1074 mtx_lock(&disp->Mutex);
1075
1076 /* let bad current context imply bad current surface */
1077 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1078 _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE)
1079 RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
1080
1081 /* a valid current context implies an initialized current display */
1082 assert(disp->Initialized);
1083 drv = disp->Driver;
1084 ret = drv->API.WaitClient(drv, disp, ctx);
1085
1086 RETURN_EGL_EVAL(disp, ret);
1087 }
1088
1089
1090 EGLBoolean EGLAPIENTRY
1091 eglWaitGL(void)
1092 {
1093 _EGLThreadInfo *t = _eglGetCurrentThread();
1094 EGLint api_index = t->CurrentAPIIndex;
1095 EGLint es_index = _eglConvertApiToIndex(EGL_OPENGL_ES_API);
1096 EGLBoolean ret;
1097
1098 if (api_index != es_index && _eglIsCurrentThreadDummy())
1099 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_FALSE);
1100
1101 t->CurrentAPIIndex = es_index;
1102 ret = eglWaitClient();
1103 t->CurrentAPIIndex = api_index;
1104 return ret;
1105 }
1106
1107
1108 EGLBoolean EGLAPIENTRY
1109 eglWaitNative(EGLint engine)
1110 {
1111 _EGLContext *ctx = _eglGetCurrentContext();
1112 _EGLDisplay *disp;
1113 _EGLDriver *drv;
1114 EGLBoolean ret;
1115
1116 if (!ctx)
1117 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1118
1119 disp = ctx->Resource.Display;
1120 mtx_lock(&disp->Mutex);
1121
1122 /* let bad current context imply bad current surface */
1123 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1124 _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE)
1125 RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
1126
1127 /* a valid current context implies an initialized current display */
1128 assert(disp->Initialized);
1129 drv = disp->Driver;
1130 ret = drv->API.WaitNative(drv, disp, engine);
1131
1132 RETURN_EGL_EVAL(disp, ret);
1133 }
1134
1135
1136 EGLDisplay EGLAPIENTRY
1137 eglGetCurrentDisplay(void)
1138 {
1139 _EGLContext *ctx = _eglGetCurrentContext();
1140 EGLDisplay ret;
1141
1142 ret = (ctx) ? _eglGetDisplayHandle(ctx->Resource.Display) : EGL_NO_DISPLAY;
1143
1144 RETURN_EGL_SUCCESS(NULL, ret);
1145 }
1146
1147
1148 EGLContext EGLAPIENTRY
1149 eglGetCurrentContext(void)
1150 {
1151 _EGLContext *ctx = _eglGetCurrentContext();
1152 EGLContext ret;
1153
1154 ret = _eglGetContextHandle(ctx);
1155
1156 RETURN_EGL_SUCCESS(NULL, ret);
1157 }
1158
1159
1160 EGLSurface EGLAPIENTRY
1161 eglGetCurrentSurface(EGLint readdraw)
1162 {
1163 _EGLContext *ctx = _eglGetCurrentContext();
1164 EGLint err = EGL_SUCCESS;
1165 _EGLSurface *surf;
1166 EGLSurface ret;
1167
1168 if (!ctx)
1169 RETURN_EGL_SUCCESS(NULL, EGL_NO_SURFACE);
1170
1171 switch (readdraw) {
1172 case EGL_DRAW:
1173 surf = ctx->DrawSurface;
1174 break;
1175 case EGL_READ:
1176 surf = ctx->ReadSurface;
1177 break;
1178 default:
1179 surf = NULL;
1180 err = EGL_BAD_PARAMETER;
1181 break;
1182 }
1183
1184 ret = _eglGetSurfaceHandle(surf);
1185
1186 RETURN_EGL_ERROR(NULL, err, ret);
1187 }
1188
1189
1190 EGLint EGLAPIENTRY
1191 eglGetError(void)
1192 {
1193 _EGLThreadInfo *t = _eglGetCurrentThread();
1194 EGLint e = t->LastError;
1195 if (!_eglIsCurrentThreadDummy())
1196 t->LastError = EGL_SUCCESS;
1197 return e;
1198 }
1199
1200
1201 static EGLDisplay EGLAPIENTRY
1202 eglGetDRMDisplayMESA(int fd)
1203 {
1204 _EGLDisplay *dpy = _eglFindDisplay(_EGL_PLATFORM_DRM, (void *) (intptr_t) fd);
1205 return _eglGetDisplayHandle(dpy);
1206 }
1207
1208 /**
1209 ** EGL 1.2
1210 **/
1211
1212 /**
1213 * Specify the client API to use for subsequent calls including:
1214 * eglCreateContext()
1215 * eglGetCurrentContext()
1216 * eglGetCurrentDisplay()
1217 * eglGetCurrentSurface()
1218 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1219 * eglWaitClient()
1220 * eglWaitNative()
1221 * See section 3.7 "Rendering Context" in the EGL specification for details.
1222 */
1223 EGLBoolean EGLAPIENTRY
1224 eglBindAPI(EGLenum api)
1225 {
1226 _EGLThreadInfo *t = _eglGetCurrentThread();
1227
1228 if (_eglIsCurrentThreadDummy())
1229 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_FALSE);
1230
1231 if (!_eglIsApiValid(api))
1232 RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, EGL_FALSE);
1233
1234 t->CurrentAPIIndex = _eglConvertApiToIndex(api);
1235
1236 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1237 }
1238
1239
1240 /**
1241 * Return the last value set with eglBindAPI().
1242 */
1243 EGLenum EGLAPIENTRY
1244 eglQueryAPI(void)
1245 {
1246 _EGLThreadInfo *t = _eglGetCurrentThread();
1247 EGLenum ret;
1248
1249 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1250 ret = _eglConvertApiFromIndex(t->CurrentAPIIndex);
1251
1252 RETURN_EGL_SUCCESS(NULL, ret);
1253 }
1254
1255
1256 EGLSurface EGLAPIENTRY
1257 eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype,
1258 EGLClientBuffer buffer, EGLConfig config,
1259 const EGLint *attrib_list)
1260 {
1261 _EGLDisplay *disp = _eglLockDisplay(dpy);
1262 _EGLConfig *conf = _eglLookupConfig(config, disp);
1263 _EGLDriver *drv;
1264 _EGLSurface *surf;
1265 EGLSurface ret;
1266
1267 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
1268
1269 surf = drv->API.CreatePbufferFromClientBuffer(drv, disp, buftype, buffer,
1270 conf, attrib_list);
1271 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
1272
1273 RETURN_EGL_EVAL(disp, ret);
1274 }
1275
1276
1277 EGLBoolean EGLAPIENTRY
1278 eglReleaseThread(void)
1279 {
1280 /* unbind current contexts */
1281 if (!_eglIsCurrentThreadDummy()) {
1282 _EGLThreadInfo *t = _eglGetCurrentThread();
1283 EGLint api_index = t->CurrentAPIIndex;
1284 EGLint i;
1285
1286 for (i = 0; i < _EGL_API_NUM_APIS; i++) {
1287 _EGLContext *ctx = t->CurrentContexts[i];
1288 if (ctx) {
1289 _EGLDisplay *disp = ctx->Resource.Display;
1290 _EGLDriver *drv;
1291
1292 t->CurrentAPIIndex = i;
1293
1294 mtx_lock(&disp->Mutex);
1295 drv = disp->Driver;
1296 (void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL);
1297 mtx_unlock(&disp->Mutex);
1298 }
1299 }
1300
1301 t->CurrentAPIIndex = api_index;
1302 }
1303
1304 _eglDestroyCurrentThread();
1305
1306 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1307 }
1308
1309
1310 static EGLImage EGLAPIENTRY
1311 eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1312 EGLClientBuffer buffer, const EGLint *attr_list)
1313 {
1314 _EGLDisplay *disp = _eglLockDisplay(dpy);
1315 _EGLContext *context = _eglLookupContext(ctx, disp);
1316 _EGLDriver *drv;
1317 _EGLImage *img;
1318 EGLImage ret;
1319
1320 _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv);
1321 if (!disp->Extensions.KHR_image_base)
1322 RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR);
1323 if (!context && ctx != EGL_NO_CONTEXT)
1324 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR);
1325 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1326 * <ctx> must be EGL_NO_CONTEXT..."
1327 */
1328 if (ctx != EGL_NO_CONTEXT && target == EGL_LINUX_DMA_BUF_EXT)
1329 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
1330
1331 img = drv->API.CreateImageKHR(drv,
1332 disp, context, target, buffer, attr_list);
1333 ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR;
1334
1335 RETURN_EGL_EVAL(disp, ret);
1336 }
1337
1338
1339 EGLImage EGLAPIENTRY
1340 eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1341 EGLClientBuffer buffer, const EGLAttrib *attr_list)
1342 {
1343 EGLImage image;
1344 EGLint *int_attribs = _eglConvertAttribsToInt(attr_list);
1345
1346 if (attr_list && !int_attribs)
1347 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_NO_IMAGE);
1348
1349 image = eglCreateImageKHR(dpy, ctx, target, buffer, int_attribs);
1350 free(int_attribs);
1351 return image;
1352 }
1353
1354
1355 EGLBoolean EGLAPIENTRY
1356 eglDestroyImage(EGLDisplay dpy, EGLImage image)
1357 {
1358 _EGLDisplay *disp = _eglLockDisplay(dpy);
1359 _EGLImage *img = _eglLookupImage(image, disp);
1360 _EGLDriver *drv;
1361 EGLBoolean ret;
1362
1363 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1364 if (!disp->Extensions.KHR_image_base)
1365 RETURN_EGL_EVAL(disp, EGL_FALSE);
1366 if (!img)
1367 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1368
1369 _eglUnlinkImage(img);
1370 ret = drv->API.DestroyImageKHR(drv, disp, img);
1371
1372 RETURN_EGL_EVAL(disp, ret);
1373 }
1374
1375
1376 static EGLSync
1377 _eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list,
1378 const EGLAttrib *attrib_list64, EGLBoolean is64,
1379 EGLenum invalid_type_error)
1380 {
1381 _EGLDisplay *disp = _eglLockDisplay(dpy);
1382 _EGLContext *ctx = _eglGetCurrentContext();
1383 _EGLDriver *drv;
1384 _EGLSync *sync;
1385 EGLSync ret;
1386
1387 _EGL_CHECK_DISPLAY(disp, EGL_NO_SYNC_KHR, drv);
1388
1389 if (!disp->Extensions.KHR_cl_event2 && is64)
1390 RETURN_EGL_EVAL(disp, EGL_NO_SYNC_KHR);
1391
1392 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1393 if (!ctx || ctx->Resource.Display != dpy ||
1394 ctx->ClientAPI != EGL_OPENGL_ES_API)
1395 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
1396
1397 switch (type) {
1398 case EGL_SYNC_FENCE_KHR:
1399 if (!disp->Extensions.KHR_fence_sync)
1400 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1401 break;
1402 case EGL_SYNC_REUSABLE_KHR:
1403 if (!disp->Extensions.KHR_reusable_sync)
1404 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1405 break;
1406 case EGL_SYNC_CL_EVENT_KHR:
1407 if (!disp->Extensions.KHR_cl_event2)
1408 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1409 break;
1410 default:
1411 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1412 }
1413
1414 sync = drv->API.CreateSyncKHR(drv, disp, type, attrib_list, attrib_list64);
1415 ret = (sync) ? _eglLinkSync(sync) : EGL_NO_SYNC_KHR;
1416
1417 RETURN_EGL_EVAL(disp, ret);
1418 }
1419
1420
1421 static EGLSync EGLAPIENTRY
1422 eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list)
1423 {
1424 return _eglCreateSync(dpy, type, attrib_list, NULL, EGL_FALSE,
1425 EGL_BAD_ATTRIBUTE);
1426 }
1427
1428
1429 static EGLSync EGLAPIENTRY
1430 eglCreateSync64KHR(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
1431 {
1432 return _eglCreateSync(dpy, type, NULL, attrib_list, EGL_TRUE,
1433 EGL_BAD_ATTRIBUTE);
1434 }
1435
1436
1437 EGLSync EGLAPIENTRY
1438 eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
1439 {
1440 return _eglCreateSync(dpy, type, NULL, attrib_list, EGL_TRUE,
1441 EGL_BAD_PARAMETER);
1442 }
1443
1444
1445 EGLBoolean EGLAPIENTRY
1446 eglDestroySync(EGLDisplay dpy, EGLSync sync)
1447 {
1448 _EGLDisplay *disp = _eglLockDisplay(dpy);
1449 _EGLSync *s = _eglLookupSync(sync, disp);
1450 _EGLDriver *drv;
1451 EGLBoolean ret;
1452
1453 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1454 assert(disp->Extensions.KHR_reusable_sync ||
1455 disp->Extensions.KHR_fence_sync);
1456
1457 _eglUnlinkSync(s);
1458 ret = drv->API.DestroySyncKHR(drv, disp, s);
1459
1460 RETURN_EGL_EVAL(disp, ret);
1461 }
1462
1463
1464 EGLint EGLAPIENTRY
1465 eglClientWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout)
1466 {
1467 _EGLDisplay *disp = _eglLockDisplay(dpy);
1468 _EGLSync *s = _eglLookupSync(sync, disp);
1469 _EGLDriver *drv;
1470 EGLint ret;
1471
1472 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1473 assert(disp->Extensions.KHR_reusable_sync ||
1474 disp->Extensions.KHR_fence_sync);
1475
1476 if (s->SyncStatus == EGL_SIGNALED_KHR)
1477 RETURN_EGL_EVAL(disp, EGL_CONDITION_SATISFIED_KHR);
1478
1479 ret = drv->API.ClientWaitSyncKHR(drv, disp, s, flags, timeout);
1480
1481 RETURN_EGL_EVAL(disp, ret);
1482 }
1483
1484
1485 static EGLint EGLAPIENTRY
1486 eglWaitSyncKHR(EGLDisplay dpy, EGLSync sync, EGLint flags)
1487 {
1488 _EGLDisplay *disp = _eglLockDisplay(dpy);
1489 _EGLSync *s = _eglLookupSync(sync, disp);
1490 _EGLContext *ctx = _eglGetCurrentContext();
1491 _EGLDriver *drv;
1492 EGLint ret;
1493
1494 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1495 assert(disp->Extensions.KHR_wait_sync);
1496
1497 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1498 if (ctx == EGL_NO_CONTEXT || ctx->ClientAPI != EGL_OPENGL_ES_API)
1499 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
1500
1501 /* the API doesn't allow any flags yet */
1502 if (flags != 0)
1503 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1504
1505 ret = drv->API.WaitSyncKHR(drv, disp, s);
1506
1507 RETURN_EGL_EVAL(disp, ret);
1508 }
1509
1510
1511 EGLBoolean EGLAPIENTRY
1512 eglWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags)
1513 {
1514 /* The KHR version returns EGLint, while the core version returns
1515 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1516 * EGL_TRUE.
1517 */
1518 return eglWaitSyncKHR(dpy, sync, flags);
1519 }
1520
1521
1522 static EGLBoolean EGLAPIENTRY
1523 eglSignalSyncKHR(EGLDisplay dpy, EGLSync sync, EGLenum mode)
1524 {
1525 _EGLDisplay *disp = _eglLockDisplay(dpy);
1526 _EGLSync *s = _eglLookupSync(sync, disp);
1527 _EGLDriver *drv;
1528 EGLBoolean ret;
1529
1530 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1531 assert(disp->Extensions.KHR_reusable_sync);
1532 ret = drv->API.SignalSyncKHR(drv, disp, s, mode);
1533
1534 RETURN_EGL_EVAL(disp, ret);
1535 }
1536
1537
1538 EGLBoolean EGLAPIENTRY
1539 eglGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value)
1540 {
1541 _EGLDisplay *disp = _eglLockDisplay(dpy);
1542 _EGLSync *s = _eglLookupSync(sync, disp);
1543 _EGLDriver *drv;
1544 EGLBoolean ret;
1545
1546 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1547 assert(disp->Extensions.KHR_reusable_sync ||
1548 disp->Extensions.KHR_fence_sync);
1549 ret = drv->API.GetSyncAttrib(drv, disp, s, attribute, value);
1550
1551 RETURN_EGL_EVAL(disp, ret);
1552 }
1553
1554
1555 static EGLBoolean EGLAPIENTRY
1556 eglGetSyncAttribKHR(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLint *value)
1557 {
1558 EGLAttrib attrib = *value;
1559 EGLBoolean result = eglGetSyncAttrib(dpy, sync, attribute, &attrib);
1560
1561 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
1562 *
1563 * If any error occurs, <*value> is not modified.
1564 */
1565 if (result == EGL_FALSE)
1566 return result;
1567
1568 *value = attrib;
1569 return result;
1570 }
1571
1572
1573 static EGLBoolean EGLAPIENTRY
1574 eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface,
1575 EGLint numRects, const EGLint *rects)
1576 {
1577 _EGLContext *ctx = _eglGetCurrentContext();
1578 _EGLDisplay *disp = _eglLockDisplay(dpy);
1579 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1580 _EGLDriver *drv;
1581 EGLBoolean ret;
1582
1583 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1584
1585 if (!disp->Extensions.NOK_swap_region)
1586 RETURN_EGL_EVAL(disp, EGL_FALSE);
1587
1588 /* surface must be bound to current context in EGL 1.4 */
1589 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1590 surf != ctx->DrawSurface)
1591 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1592
1593 ret = drv->API.SwapBuffersRegionNOK(drv, disp, surf, numRects, rects);
1594
1595 RETURN_EGL_EVAL(disp, ret);
1596 }
1597
1598
1599 static EGLImage EGLAPIENTRY
1600 eglCreateDRMImageMESA(EGLDisplay dpy, const EGLint *attr_list)
1601 {
1602 _EGLDisplay *disp = _eglLockDisplay(dpy);
1603 _EGLDriver *drv;
1604 _EGLImage *img;
1605 EGLImage ret;
1606
1607 _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv);
1608 if (!disp->Extensions.MESA_drm_image)
1609 RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR);
1610
1611 img = drv->API.CreateDRMImageMESA(drv, disp, attr_list);
1612 ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR;
1613
1614 RETURN_EGL_EVAL(disp, ret);
1615 }
1616
1617 static EGLBoolean EGLAPIENTRY
1618 eglExportDRMImageMESA(EGLDisplay dpy, EGLImage image,
1619 EGLint *name, EGLint *handle, EGLint *stride)
1620 {
1621 _EGLDisplay *disp = _eglLockDisplay(dpy);
1622 _EGLImage *img = _eglLookupImage(image, disp);
1623 _EGLDriver *drv;
1624 EGLBoolean ret;
1625
1626 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1627 assert(disp->Extensions.MESA_drm_image);
1628
1629 if (!img)
1630 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1631
1632 ret = drv->API.ExportDRMImageMESA(drv, disp, img, name, handle, stride);
1633
1634 RETURN_EGL_EVAL(disp, ret);
1635 }
1636
1637
1638 struct wl_display;
1639
1640 static EGLBoolean EGLAPIENTRY
1641 eglBindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
1642 {
1643 _EGLDisplay *disp = _eglLockDisplay(dpy);
1644 _EGLDriver *drv;
1645 EGLBoolean ret;
1646
1647 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1648 assert(disp->Extensions.WL_bind_wayland_display);
1649
1650 if (!display)
1651 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1652
1653 ret = drv->API.BindWaylandDisplayWL(drv, disp, display);
1654
1655 RETURN_EGL_EVAL(disp, ret);
1656 }
1657
1658 static EGLBoolean EGLAPIENTRY
1659 eglUnbindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
1660 {
1661 _EGLDisplay *disp = _eglLockDisplay(dpy);
1662 _EGLDriver *drv;
1663 EGLBoolean ret;
1664
1665 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1666 assert(disp->Extensions.WL_bind_wayland_display);
1667
1668 if (!display)
1669 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1670
1671 ret = drv->API.UnbindWaylandDisplayWL(drv, disp, display);
1672
1673 RETURN_EGL_EVAL(disp, ret);
1674 }
1675
1676 static EGLBoolean EGLAPIENTRY
1677 eglQueryWaylandBufferWL(EGLDisplay dpy, struct wl_resource *buffer,
1678 EGLint attribute, EGLint *value)
1679 {
1680 _EGLDisplay *disp = _eglLockDisplay(dpy);
1681 _EGLDriver *drv;
1682 EGLBoolean ret;
1683
1684 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1685 assert(disp->Extensions.WL_bind_wayland_display);
1686
1687 if (!buffer)
1688 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1689
1690 ret = drv->API.QueryWaylandBufferWL(drv, disp, buffer, attribute, value);
1691
1692 RETURN_EGL_EVAL(disp, ret);
1693 }
1694
1695
1696 static struct wl_buffer * EGLAPIENTRY
1697 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy, EGLImage image)
1698 {
1699 _EGLDisplay *disp = _eglLockDisplay(dpy);
1700 _EGLImage *img;
1701 _EGLDriver *drv;
1702 struct wl_buffer *ret;
1703
1704 _EGL_CHECK_DISPLAY(disp, NULL, drv);
1705 assert(disp->Extensions.WL_create_wayland_buffer_from_image);
1706
1707 img = _eglLookupImage(image, disp);
1708
1709 if (!img)
1710 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL);
1711
1712 ret = drv->API.CreateWaylandBufferFromImageWL(drv, disp, img);
1713
1714 RETURN_EGL_EVAL(disp, ret);
1715 }
1716
1717 static EGLBoolean EGLAPIENTRY
1718 eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface,
1719 EGLint x, EGLint y, EGLint width, EGLint height)
1720 {
1721 _EGLDisplay *disp = _eglLockDisplay(dpy);
1722 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1723 _EGLDriver *drv;
1724 EGLBoolean ret;
1725
1726 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1727
1728 if (!disp->Extensions.NV_post_sub_buffer)
1729 RETURN_EGL_EVAL(disp, EGL_FALSE);
1730
1731 ret = drv->API.PostSubBufferNV(drv, disp, surf, x, y, width, height);
1732
1733 RETURN_EGL_EVAL(disp, ret);
1734 }
1735
1736 static EGLBoolean EGLAPIENTRY
1737 eglGetSyncValuesCHROMIUM(EGLDisplay display, EGLSurface surface,
1738 EGLuint64KHR *ust, EGLuint64KHR *msc,
1739 EGLuint64KHR *sbc)
1740 {
1741 _EGLDisplay *disp = _eglLockDisplay(display);
1742 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1743 _EGLDriver *drv;
1744 EGLBoolean ret;
1745
1746 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1747 if (!disp->Extensions.CHROMIUM_sync_control)
1748 RETURN_EGL_EVAL(disp, EGL_FALSE);
1749
1750 if (!ust || !msc || !sbc)
1751 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1752
1753 ret = drv->API.GetSyncValuesCHROMIUM(disp, surf, ust, msc, sbc);
1754
1755 RETURN_EGL_EVAL(disp, ret);
1756 }
1757
1758 static EGLBoolean EGLAPIENTRY
1759 eglExportDMABUFImageQueryMESA(EGLDisplay dpy, EGLImage image,
1760 EGLint *fourcc, EGLint *nplanes,
1761 EGLuint64KHR *modifiers)
1762 {
1763 _EGLDisplay *disp = _eglLockDisplay(dpy);
1764 _EGLImage *img = _eglLookupImage(image, disp);
1765 _EGLDriver *drv;
1766 EGLBoolean ret;
1767
1768 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1769 assert(disp->Extensions.MESA_image_dma_buf_export);
1770
1771 if (!img)
1772 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1773
1774 ret = drv->API.ExportDMABUFImageQueryMESA(drv, disp, img, fourcc, nplanes,
1775 modifiers);
1776
1777 RETURN_EGL_EVAL(disp, ret);
1778 }
1779
1780 static EGLBoolean EGLAPIENTRY
1781 eglExportDMABUFImageMESA(EGLDisplay dpy, EGLImage image,
1782 int *fds, EGLint *strides, EGLint *offsets)
1783 {
1784 _EGLDisplay *disp = _eglLockDisplay(dpy);
1785 _EGLImage *img = _eglLookupImage(image, disp);
1786 _EGLDriver *drv;
1787 EGLBoolean ret;
1788
1789 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1790 assert(disp->Extensions.MESA_image_dma_buf_export);
1791
1792 if (!img)
1793 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1794
1795 ret = drv->API.ExportDMABUFImageMESA(drv, disp, img, fds, strides, offsets);
1796
1797 RETURN_EGL_EVAL(disp, ret);
1798 }
1799
1800 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
1801 eglGetProcAddress(const char *procname)
1802 {
1803 static const struct {
1804 const char *name;
1805 _EGLProc function;
1806 } egl_functions[] = {
1807 /* core functions queryable in the presence of
1808 * EGL_KHR_get_all_proc_addresses or EGL 1.5
1809 */
1810 /* alphabetical order */
1811 { "eglBindAPI", (_EGLProc) eglBindAPI },
1812 { "eglBindTexImage", (_EGLProc) eglBindTexImage },
1813 { "eglChooseConfig", (_EGLProc) eglChooseConfig },
1814 { "eglCopyBuffers", (_EGLProc) eglCopyBuffers },
1815 { "eglCreateContext", (_EGLProc) eglCreateContext },
1816 { "eglCreatePbufferFromClientBuffer", (_EGLProc) eglCreatePbufferFromClientBuffer },
1817 { "eglCreatePbufferSurface", (_EGLProc) eglCreatePbufferSurface },
1818 { "eglCreatePixmapSurface", (_EGLProc) eglCreatePixmapSurface },
1819 { "eglCreateWindowSurface", (_EGLProc) eglCreateWindowSurface },
1820 { "eglDestroyContext", (_EGLProc) eglDestroyContext },
1821 { "eglDestroySurface", (_EGLProc) eglDestroySurface },
1822 { "eglGetConfigAttrib", (_EGLProc) eglGetConfigAttrib },
1823 { "eglGetConfigs", (_EGLProc) eglGetConfigs },
1824 { "eglGetCurrentContext", (_EGLProc) eglGetCurrentContext },
1825 { "eglGetCurrentDisplay", (_EGLProc) eglGetCurrentDisplay },
1826 { "eglGetCurrentSurface", (_EGLProc) eglGetCurrentSurface },
1827 { "eglGetDisplay", (_EGLProc) eglGetDisplay },
1828 { "eglGetError", (_EGLProc) eglGetError },
1829 { "eglGetProcAddress", (_EGLProc) eglGetProcAddress },
1830 { "eglInitialize", (_EGLProc) eglInitialize },
1831 { "eglMakeCurrent", (_EGLProc) eglMakeCurrent },
1832 { "eglQueryAPI", (_EGLProc) eglQueryAPI },
1833 { "eglQueryContext", (_EGLProc) eglQueryContext },
1834 { "eglQueryString", (_EGLProc) eglQueryString },
1835 { "eglQuerySurface", (_EGLProc) eglQuerySurface },
1836 { "eglReleaseTexImage", (_EGLProc) eglReleaseTexImage },
1837 { "eglReleaseThread", (_EGLProc) eglReleaseThread },
1838 { "eglSurfaceAttrib", (_EGLProc) eglSurfaceAttrib },
1839 { "eglSwapBuffers", (_EGLProc) eglSwapBuffers },
1840 { "eglSwapInterval", (_EGLProc) eglSwapInterval },
1841 { "eglTerminate", (_EGLProc) eglTerminate },
1842 { "eglWaitClient", (_EGLProc) eglWaitClient },
1843 { "eglWaitGL", (_EGLProc) eglWaitGL },
1844 { "eglWaitNative", (_EGLProc) eglWaitNative },
1845 { "eglCreateSync", (_EGLProc) eglCreateSync },
1846 { "eglDestroySync", (_EGLProc) eglDestroySync },
1847 { "eglClientWaitSync", (_EGLProc) eglClientWaitSync },
1848 { "eglGetSyncAttrib", (_EGLProc) eglGetSyncAttrib },
1849 { "eglWaitSync", (_EGLProc) eglWaitSync },
1850 { "eglCreateImage", (_EGLProc) eglCreateImage },
1851 { "eglDestroyImage", (_EGLProc) eglDestroyImage },
1852 { "eglGetPlatformDisplay", (_EGLProc) eglGetPlatformDisplay },
1853 { "eglCreatePlatformWindowSurface", (_EGLProc) eglCreatePlatformWindowSurface },
1854 { "eglCreatePlatformPixmapSurface", (_EGLProc) eglCreatePlatformPixmapSurface },
1855 { "eglGetDRMDisplayMESA", (_EGLProc) eglGetDRMDisplayMESA },
1856 { "eglCreateImageKHR", (_EGLProc) eglCreateImageKHR },
1857 { "eglDestroyImageKHR", (_EGLProc) eglDestroyImage },
1858 { "eglCreateSyncKHR", (_EGLProc) eglCreateSyncKHR },
1859 { "eglCreateSync64KHR", (_EGLProc) eglCreateSync64KHR },
1860 { "eglDestroySyncKHR", (_EGLProc) eglDestroySync },
1861 { "eglClientWaitSyncKHR", (_EGLProc) eglClientWaitSync },
1862 { "eglWaitSyncKHR", (_EGLProc) eglWaitSyncKHR },
1863 { "eglSignalSyncKHR", (_EGLProc) eglSignalSyncKHR },
1864 { "eglGetSyncAttribKHR", (_EGLProc) eglGetSyncAttribKHR },
1865 { "eglSwapBuffersRegionNOK", (_EGLProc) eglSwapBuffersRegionNOK },
1866 { "eglCreateDRMImageMESA", (_EGLProc) eglCreateDRMImageMESA },
1867 { "eglExportDRMImageMESA", (_EGLProc) eglExportDRMImageMESA },
1868 { "eglBindWaylandDisplayWL", (_EGLProc) eglBindWaylandDisplayWL },
1869 { "eglUnbindWaylandDisplayWL", (_EGLProc) eglUnbindWaylandDisplayWL },
1870 { "eglQueryWaylandBufferWL", (_EGLProc) eglQueryWaylandBufferWL },
1871 { "eglCreateWaylandBufferFromImageWL", (_EGLProc) eglCreateWaylandBufferFromImageWL },
1872 { "eglPostSubBufferNV", (_EGLProc) eglPostSubBufferNV },
1873 { "eglSwapBuffersWithDamageEXT", (_EGLProc) eglSwapBuffersWithDamageEXT },
1874 { "eglGetPlatformDisplayEXT", (_EGLProc) eglGetPlatformDisplayEXT },
1875 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc) eglCreatePlatformWindowSurfaceEXT },
1876 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc) eglCreatePlatformPixmapSurfaceEXT },
1877 { "eglGetSyncValuesCHROMIUM", (_EGLProc) eglGetSyncValuesCHROMIUM },
1878 { "eglExportDMABUFImageQueryMESA", (_EGLProc) eglExportDMABUFImageQueryMESA },
1879 { "eglExportDMABUFImageMESA", (_EGLProc) eglExportDMABUFImageMESA },
1880 { NULL, NULL }
1881 };
1882 EGLint i;
1883 _EGLProc ret;
1884
1885 if (!procname)
1886 RETURN_EGL_SUCCESS(NULL, NULL);
1887
1888 ret = NULL;
1889 if (strncmp(procname, "egl", 3) == 0) {
1890 for (i = 0; egl_functions[i].name; i++) {
1891 if (strcmp(egl_functions[i].name, procname) == 0) {
1892 ret = egl_functions[i].function;
1893 break;
1894 }
1895 }
1896 }
1897 if (!ret)
1898 ret = _eglGetDriverProc(procname);
1899
1900 RETURN_EGL_SUCCESS(NULL, ret);
1901 }