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