egl: Rename MESA_configless_context bit to KHR_no_config_context
[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_no_config_context);
410 _EGL_CHECK_EXTENSION(KHR_reusable_sync);
411 _EGL_CHECK_EXTENSION(KHR_surfaceless_context);
412 _EGL_CHECK_EXTENSION(KHR_wait_sync);
413
414 if (dpy->Extensions.KHR_no_config_context)
415 _eglAppendExtension(&exts, "EGL_MESA_configless_context");
416 _EGL_CHECK_EXTENSION(MESA_drm_image);
417 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export);
418
419 _EGL_CHECK_EXTENSION(NOK_swap_region);
420 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap);
421
422 _EGL_CHECK_EXTENSION(NV_post_sub_buffer);
423
424 _EGL_CHECK_EXTENSION(WL_bind_wayland_display);
425 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image);
426
427 #undef _EGL_CHECK_EXTENSION
428 }
429
430 static void
431 _eglCreateAPIsString(_EGLDisplay *dpy)
432 {
433 if (dpy->ClientAPIs & EGL_OPENGL_BIT)
434 strcat(dpy->ClientAPIsString, "OpenGL ");
435
436 if (dpy->ClientAPIs & EGL_OPENGL_ES_BIT ||
437 dpy->ClientAPIs & EGL_OPENGL_ES2_BIT ||
438 dpy->ClientAPIs & EGL_OPENGL_ES3_BIT_KHR) {
439 strcat(dpy->ClientAPIsString, "OpenGL_ES ");
440 }
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.KHR_no_config_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 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1094 return eglWaitClient();
1095 }
1096
1097
1098 EGLBoolean EGLAPIENTRY
1099 eglWaitNative(EGLint engine)
1100 {
1101 _EGLContext *ctx = _eglGetCurrentContext();
1102 _EGLDisplay *disp;
1103 _EGLDriver *drv;
1104 EGLBoolean ret;
1105
1106 if (!ctx)
1107 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1108
1109 disp = ctx->Resource.Display;
1110 mtx_lock(&disp->Mutex);
1111
1112 /* let bad current context imply bad current surface */
1113 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1114 _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE)
1115 RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
1116
1117 /* a valid current context implies an initialized current display */
1118 assert(disp->Initialized);
1119 drv = disp->Driver;
1120 ret = drv->API.WaitNative(drv, disp, engine);
1121
1122 RETURN_EGL_EVAL(disp, ret);
1123 }
1124
1125
1126 EGLDisplay EGLAPIENTRY
1127 eglGetCurrentDisplay(void)
1128 {
1129 _EGLContext *ctx = _eglGetCurrentContext();
1130 EGLDisplay ret;
1131
1132 ret = (ctx) ? _eglGetDisplayHandle(ctx->Resource.Display) : EGL_NO_DISPLAY;
1133
1134 RETURN_EGL_SUCCESS(NULL, ret);
1135 }
1136
1137
1138 EGLContext EGLAPIENTRY
1139 eglGetCurrentContext(void)
1140 {
1141 _EGLContext *ctx = _eglGetCurrentContext();
1142 EGLContext ret;
1143
1144 ret = _eglGetContextHandle(ctx);
1145
1146 RETURN_EGL_SUCCESS(NULL, ret);
1147 }
1148
1149
1150 EGLSurface EGLAPIENTRY
1151 eglGetCurrentSurface(EGLint readdraw)
1152 {
1153 _EGLContext *ctx = _eglGetCurrentContext();
1154 EGLint err = EGL_SUCCESS;
1155 _EGLSurface *surf;
1156 EGLSurface ret;
1157
1158 if (!ctx)
1159 RETURN_EGL_SUCCESS(NULL, EGL_NO_SURFACE);
1160
1161 switch (readdraw) {
1162 case EGL_DRAW:
1163 surf = ctx->DrawSurface;
1164 break;
1165 case EGL_READ:
1166 surf = ctx->ReadSurface;
1167 break;
1168 default:
1169 surf = NULL;
1170 err = EGL_BAD_PARAMETER;
1171 break;
1172 }
1173
1174 ret = _eglGetSurfaceHandle(surf);
1175
1176 RETURN_EGL_ERROR(NULL, err, ret);
1177 }
1178
1179
1180 EGLint EGLAPIENTRY
1181 eglGetError(void)
1182 {
1183 _EGLThreadInfo *t = _eglGetCurrentThread();
1184 EGLint e = t->LastError;
1185 if (!_eglIsCurrentThreadDummy())
1186 t->LastError = EGL_SUCCESS;
1187 return e;
1188 }
1189
1190
1191 /**
1192 ** EGL 1.2
1193 **/
1194
1195 /**
1196 * Specify the client API to use for subsequent calls including:
1197 * eglCreateContext()
1198 * eglGetCurrentContext()
1199 * eglGetCurrentDisplay()
1200 * eglGetCurrentSurface()
1201 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1202 * eglWaitClient()
1203 * eglWaitNative()
1204 * See section 3.7 "Rendering Context" in the EGL specification for details.
1205 */
1206 EGLBoolean EGLAPIENTRY
1207 eglBindAPI(EGLenum api)
1208 {
1209 _EGLThreadInfo *t = _eglGetCurrentThread();
1210
1211 if (_eglIsCurrentThreadDummy())
1212 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_FALSE);
1213
1214 if (!_eglIsApiValid(api))
1215 RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, EGL_FALSE);
1216
1217 t->CurrentAPI = api;
1218
1219 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1220 }
1221
1222
1223 /**
1224 * Return the last value set with eglBindAPI().
1225 */
1226 EGLenum EGLAPIENTRY
1227 eglQueryAPI(void)
1228 {
1229 _EGLThreadInfo *t = _eglGetCurrentThread();
1230 EGLenum ret;
1231
1232 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1233 ret = t->CurrentAPI;
1234
1235 RETURN_EGL_SUCCESS(NULL, ret);
1236 }
1237
1238
1239 EGLSurface EGLAPIENTRY
1240 eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype,
1241 EGLClientBuffer buffer, EGLConfig config,
1242 const EGLint *attrib_list)
1243 {
1244 _EGLDisplay *disp = _eglLockDisplay(dpy);
1245 _EGLConfig *conf = _eglLookupConfig(config, disp);
1246 _EGLDriver *drv;
1247 _EGLSurface *surf;
1248 EGLSurface ret;
1249
1250 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
1251
1252 surf = drv->API.CreatePbufferFromClientBuffer(drv, disp, buftype, buffer,
1253 conf, attrib_list);
1254 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
1255
1256 RETURN_EGL_EVAL(disp, ret);
1257 }
1258
1259
1260 EGLBoolean EGLAPIENTRY
1261 eglReleaseThread(void)
1262 {
1263 /* unbind current contexts */
1264 if (!_eglIsCurrentThreadDummy()) {
1265 _EGLThreadInfo *t = _eglGetCurrentThread();
1266
1267 _EGLContext *ctx = t->CurrentContext;
1268 if (ctx) {
1269 _EGLDisplay *disp = ctx->Resource.Display;
1270 _EGLDriver *drv;
1271
1272 mtx_lock(&disp->Mutex);
1273 drv = disp->Driver;
1274 (void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL);
1275 mtx_unlock(&disp->Mutex);
1276 }
1277 }
1278
1279 _eglDestroyCurrentThread();
1280
1281 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1282 }
1283
1284
1285 static EGLImage EGLAPIENTRY
1286 eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1287 EGLClientBuffer buffer, const EGLint *attr_list)
1288 {
1289 _EGLDisplay *disp = _eglLockDisplay(dpy);
1290 _EGLContext *context = _eglLookupContext(ctx, disp);
1291 _EGLDriver *drv;
1292 _EGLImage *img;
1293 EGLImage ret;
1294
1295 _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv);
1296 if (!disp->Extensions.KHR_image_base)
1297 RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR);
1298 if (!context && ctx != EGL_NO_CONTEXT)
1299 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR);
1300 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1301 * <ctx> must be EGL_NO_CONTEXT..."
1302 */
1303 if (ctx != EGL_NO_CONTEXT && target == EGL_LINUX_DMA_BUF_EXT)
1304 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
1305
1306 img = drv->API.CreateImageKHR(drv,
1307 disp, context, target, buffer, attr_list);
1308 ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR;
1309
1310 RETURN_EGL_EVAL(disp, ret);
1311 }
1312
1313
1314 EGLImage EGLAPIENTRY
1315 eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1316 EGLClientBuffer buffer, const EGLAttrib *attr_list)
1317 {
1318 EGLImage image;
1319 EGLint *int_attribs = _eglConvertAttribsToInt(attr_list);
1320
1321 if (attr_list && !int_attribs)
1322 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_NO_IMAGE);
1323
1324 image = eglCreateImageKHR(dpy, ctx, target, buffer, int_attribs);
1325 free(int_attribs);
1326 return image;
1327 }
1328
1329
1330 EGLBoolean EGLAPIENTRY
1331 eglDestroyImage(EGLDisplay dpy, EGLImage image)
1332 {
1333 _EGLDisplay *disp = _eglLockDisplay(dpy);
1334 _EGLImage *img = _eglLookupImage(image, disp);
1335 _EGLDriver *drv;
1336 EGLBoolean ret;
1337
1338 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1339 if (!disp->Extensions.KHR_image_base)
1340 RETURN_EGL_EVAL(disp, EGL_FALSE);
1341 if (!img)
1342 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1343
1344 _eglUnlinkImage(img);
1345 ret = drv->API.DestroyImageKHR(drv, disp, img);
1346
1347 RETURN_EGL_EVAL(disp, ret);
1348 }
1349
1350
1351 static EGLSync
1352 _eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list,
1353 const EGLAttrib *attrib_list64, EGLBoolean is64,
1354 EGLenum invalid_type_error)
1355 {
1356 _EGLDisplay *disp = _eglLockDisplay(dpy);
1357 _EGLContext *ctx = _eglGetCurrentContext();
1358 _EGLDriver *drv;
1359 _EGLSync *sync;
1360 EGLSync ret;
1361
1362 _EGL_CHECK_DISPLAY(disp, EGL_NO_SYNC_KHR, drv);
1363
1364 if (!disp->Extensions.KHR_cl_event2 && is64)
1365 RETURN_EGL_EVAL(disp, EGL_NO_SYNC_KHR);
1366
1367 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1368 if (!ctx || ctx->Resource.Display != dpy ||
1369 ctx->ClientAPI != EGL_OPENGL_ES_API)
1370 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
1371
1372 switch (type) {
1373 case EGL_SYNC_FENCE_KHR:
1374 if (!disp->Extensions.KHR_fence_sync)
1375 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1376 break;
1377 case EGL_SYNC_REUSABLE_KHR:
1378 if (!disp->Extensions.KHR_reusable_sync)
1379 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1380 break;
1381 case EGL_SYNC_CL_EVENT_KHR:
1382 if (!disp->Extensions.KHR_cl_event2)
1383 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1384 break;
1385 default:
1386 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1387 }
1388
1389 sync = drv->API.CreateSyncKHR(drv, disp, type, attrib_list, attrib_list64);
1390 ret = (sync) ? _eglLinkSync(sync) : EGL_NO_SYNC_KHR;
1391
1392 RETURN_EGL_EVAL(disp, ret);
1393 }
1394
1395
1396 static EGLSync EGLAPIENTRY
1397 eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list)
1398 {
1399 return _eglCreateSync(dpy, type, attrib_list, NULL, EGL_FALSE,
1400 EGL_BAD_ATTRIBUTE);
1401 }
1402
1403
1404 static EGLSync EGLAPIENTRY
1405 eglCreateSync64KHR(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
1406 {
1407 return _eglCreateSync(dpy, type, NULL, attrib_list, EGL_TRUE,
1408 EGL_BAD_ATTRIBUTE);
1409 }
1410
1411
1412 EGLSync EGLAPIENTRY
1413 eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
1414 {
1415 return _eglCreateSync(dpy, type, NULL, attrib_list, EGL_TRUE,
1416 EGL_BAD_PARAMETER);
1417 }
1418
1419
1420 EGLBoolean EGLAPIENTRY
1421 eglDestroySync(EGLDisplay dpy, EGLSync sync)
1422 {
1423 _EGLDisplay *disp = _eglLockDisplay(dpy);
1424 _EGLSync *s = _eglLookupSync(sync, disp);
1425 _EGLDriver *drv;
1426 EGLBoolean ret;
1427
1428 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1429 assert(disp->Extensions.KHR_reusable_sync ||
1430 disp->Extensions.KHR_fence_sync);
1431
1432 _eglUnlinkSync(s);
1433 ret = drv->API.DestroySyncKHR(drv, disp, s);
1434
1435 RETURN_EGL_EVAL(disp, ret);
1436 }
1437
1438
1439 EGLint EGLAPIENTRY
1440 eglClientWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout)
1441 {
1442 _EGLDisplay *disp = _eglLockDisplay(dpy);
1443 _EGLSync *s = _eglLookupSync(sync, disp);
1444 _EGLDriver *drv;
1445 EGLint ret;
1446
1447 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1448 assert(disp->Extensions.KHR_reusable_sync ||
1449 disp->Extensions.KHR_fence_sync);
1450
1451 if (s->SyncStatus == EGL_SIGNALED_KHR)
1452 RETURN_EGL_EVAL(disp, EGL_CONDITION_SATISFIED_KHR);
1453
1454 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1455 * unlocked here to allow other threads also to be able to
1456 * go into waiting state.
1457 */
1458
1459 if (s->Type == EGL_SYNC_REUSABLE_KHR)
1460 _eglUnlockDisplay(dpy);
1461
1462 ret = drv->API.ClientWaitSyncKHR(drv, disp, s, flags, timeout);
1463
1464 /*
1465 * 'disp' is already unlocked for reusable sync type,
1466 * so passing 'NULL' to bypass unlocking display.
1467 */
1468 if (s->Type == EGL_SYNC_REUSABLE_KHR)
1469 RETURN_EGL_EVAL(NULL, ret);
1470 else
1471 RETURN_EGL_EVAL(disp, ret);
1472 }
1473
1474
1475 static EGLint EGLAPIENTRY
1476 eglWaitSyncKHR(EGLDisplay dpy, EGLSync sync, EGLint flags)
1477 {
1478 _EGLDisplay *disp = _eglLockDisplay(dpy);
1479 _EGLSync *s = _eglLookupSync(sync, disp);
1480 _EGLContext *ctx = _eglGetCurrentContext();
1481 _EGLDriver *drv;
1482 EGLint ret;
1483
1484 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1485 assert(disp->Extensions.KHR_wait_sync);
1486
1487 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1488 if (ctx == EGL_NO_CONTEXT || ctx->ClientAPI != EGL_OPENGL_ES_API)
1489 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
1490
1491 /* the API doesn't allow any flags yet */
1492 if (flags != 0)
1493 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1494
1495 ret = drv->API.WaitSyncKHR(drv, disp, s);
1496
1497 RETURN_EGL_EVAL(disp, ret);
1498 }
1499
1500
1501 EGLBoolean EGLAPIENTRY
1502 eglWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags)
1503 {
1504 /* The KHR version returns EGLint, while the core version returns
1505 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1506 * EGL_TRUE.
1507 */
1508 return eglWaitSyncKHR(dpy, sync, flags);
1509 }
1510
1511
1512 static EGLBoolean EGLAPIENTRY
1513 eglSignalSyncKHR(EGLDisplay dpy, EGLSync sync, EGLenum mode)
1514 {
1515 _EGLDisplay *disp = _eglLockDisplay(dpy);
1516 _EGLSync *s = _eglLookupSync(sync, disp);
1517 _EGLDriver *drv;
1518 EGLBoolean ret;
1519
1520 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1521 assert(disp->Extensions.KHR_reusable_sync);
1522 ret = drv->API.SignalSyncKHR(drv, disp, s, mode);
1523
1524 RETURN_EGL_EVAL(disp, ret);
1525 }
1526
1527
1528 EGLBoolean EGLAPIENTRY
1529 eglGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value)
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 disp->Extensions.KHR_fence_sync);
1539 ret = drv->API.GetSyncAttrib(drv, disp, s, attribute, value);
1540
1541 RETURN_EGL_EVAL(disp, ret);
1542 }
1543
1544
1545 static EGLBoolean EGLAPIENTRY
1546 eglGetSyncAttribKHR(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLint *value)
1547 {
1548 EGLAttrib attrib;
1549 EGLBoolean result;
1550
1551 if (!value)
1552 RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, EGL_FALSE);
1553
1554 attrib = *value;
1555 result = eglGetSyncAttrib(dpy, sync, attribute, &attrib);
1556
1557 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
1558 *
1559 * If any error occurs, <*value> is not modified.
1560 */
1561 if (result == EGL_FALSE)
1562 return result;
1563
1564 *value = attrib;
1565 return result;
1566 }
1567
1568
1569 static EGLBoolean EGLAPIENTRY
1570 eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface,
1571 EGLint numRects, const EGLint *rects)
1572 {
1573 _EGLContext *ctx = _eglGetCurrentContext();
1574 _EGLDisplay *disp = _eglLockDisplay(dpy);
1575 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1576 _EGLDriver *drv;
1577 EGLBoolean ret;
1578
1579 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1580
1581 if (!disp->Extensions.NOK_swap_region)
1582 RETURN_EGL_EVAL(disp, EGL_FALSE);
1583
1584 /* surface must be bound to current context in EGL 1.4 */
1585 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1586 surf != ctx->DrawSurface)
1587 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1588
1589 ret = drv->API.SwapBuffersRegionNOK(drv, disp, surf, numRects, rects);
1590
1591 RETURN_EGL_EVAL(disp, ret);
1592 }
1593
1594
1595 static EGLImage EGLAPIENTRY
1596 eglCreateDRMImageMESA(EGLDisplay dpy, const EGLint *attr_list)
1597 {
1598 _EGLDisplay *disp = _eglLockDisplay(dpy);
1599 _EGLDriver *drv;
1600 _EGLImage *img;
1601 EGLImage ret;
1602
1603 _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv);
1604 if (!disp->Extensions.MESA_drm_image)
1605 RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR);
1606
1607 img = drv->API.CreateDRMImageMESA(drv, disp, attr_list);
1608 ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR;
1609
1610 RETURN_EGL_EVAL(disp, ret);
1611 }
1612
1613 static EGLBoolean EGLAPIENTRY
1614 eglExportDRMImageMESA(EGLDisplay dpy, EGLImage image,
1615 EGLint *name, EGLint *handle, EGLint *stride)
1616 {
1617 _EGLDisplay *disp = _eglLockDisplay(dpy);
1618 _EGLImage *img = _eglLookupImage(image, disp);
1619 _EGLDriver *drv;
1620 EGLBoolean ret;
1621
1622 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1623 assert(disp->Extensions.MESA_drm_image);
1624
1625 if (!img)
1626 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1627
1628 ret = drv->API.ExportDRMImageMESA(drv, disp, img, name, handle, stride);
1629
1630 RETURN_EGL_EVAL(disp, ret);
1631 }
1632
1633
1634 struct wl_display;
1635
1636 static EGLBoolean EGLAPIENTRY
1637 eglBindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
1638 {
1639 _EGLDisplay *disp = _eglLockDisplay(dpy);
1640 _EGLDriver *drv;
1641 EGLBoolean ret;
1642
1643 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1644 assert(disp->Extensions.WL_bind_wayland_display);
1645
1646 if (!display)
1647 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1648
1649 ret = drv->API.BindWaylandDisplayWL(drv, disp, display);
1650
1651 RETURN_EGL_EVAL(disp, ret);
1652 }
1653
1654 static EGLBoolean EGLAPIENTRY
1655 eglUnbindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
1656 {
1657 _EGLDisplay *disp = _eglLockDisplay(dpy);
1658 _EGLDriver *drv;
1659 EGLBoolean ret;
1660
1661 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1662 assert(disp->Extensions.WL_bind_wayland_display);
1663
1664 if (!display)
1665 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1666
1667 ret = drv->API.UnbindWaylandDisplayWL(drv, disp, display);
1668
1669 RETURN_EGL_EVAL(disp, ret);
1670 }
1671
1672 static EGLBoolean EGLAPIENTRY
1673 eglQueryWaylandBufferWL(EGLDisplay dpy, struct wl_resource *buffer,
1674 EGLint attribute, EGLint *value)
1675 {
1676 _EGLDisplay *disp = _eglLockDisplay(dpy);
1677 _EGLDriver *drv;
1678 EGLBoolean ret;
1679
1680 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1681 assert(disp->Extensions.WL_bind_wayland_display);
1682
1683 if (!buffer)
1684 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1685
1686 ret = drv->API.QueryWaylandBufferWL(drv, disp, buffer, attribute, value);
1687
1688 RETURN_EGL_EVAL(disp, ret);
1689 }
1690
1691
1692 static struct wl_buffer * EGLAPIENTRY
1693 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy, EGLImage image)
1694 {
1695 _EGLDisplay *disp = _eglLockDisplay(dpy);
1696 _EGLImage *img;
1697 _EGLDriver *drv;
1698 struct wl_buffer *ret;
1699
1700 _EGL_CHECK_DISPLAY(disp, NULL, drv);
1701 assert(disp->Extensions.WL_create_wayland_buffer_from_image);
1702
1703 img = _eglLookupImage(image, disp);
1704
1705 if (!img)
1706 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL);
1707
1708 ret = drv->API.CreateWaylandBufferFromImageWL(drv, disp, img);
1709
1710 RETURN_EGL_EVAL(disp, ret);
1711 }
1712
1713 static EGLBoolean EGLAPIENTRY
1714 eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface,
1715 EGLint x, EGLint y, EGLint width, EGLint height)
1716 {
1717 _EGLDisplay *disp = _eglLockDisplay(dpy);
1718 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1719 _EGLDriver *drv;
1720 EGLBoolean ret;
1721
1722 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1723
1724 if (!disp->Extensions.NV_post_sub_buffer)
1725 RETURN_EGL_EVAL(disp, EGL_FALSE);
1726
1727 ret = drv->API.PostSubBufferNV(drv, disp, surf, x, y, width, height);
1728
1729 RETURN_EGL_EVAL(disp, ret);
1730 }
1731
1732 static EGLBoolean EGLAPIENTRY
1733 eglGetSyncValuesCHROMIUM(EGLDisplay display, EGLSurface surface,
1734 EGLuint64KHR *ust, EGLuint64KHR *msc,
1735 EGLuint64KHR *sbc)
1736 {
1737 _EGLDisplay *disp = _eglLockDisplay(display);
1738 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1739 _EGLDriver *drv;
1740 EGLBoolean ret;
1741
1742 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1743 if (!disp->Extensions.CHROMIUM_sync_control)
1744 RETURN_EGL_EVAL(disp, EGL_FALSE);
1745
1746 if (!ust || !msc || !sbc)
1747 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1748
1749 ret = drv->API.GetSyncValuesCHROMIUM(disp, surf, ust, msc, sbc);
1750
1751 RETURN_EGL_EVAL(disp, ret);
1752 }
1753
1754 static EGLBoolean EGLAPIENTRY
1755 eglExportDMABUFImageQueryMESA(EGLDisplay dpy, EGLImage image,
1756 EGLint *fourcc, EGLint *nplanes,
1757 EGLuint64KHR *modifiers)
1758 {
1759 _EGLDisplay *disp = _eglLockDisplay(dpy);
1760 _EGLImage *img = _eglLookupImage(image, disp);
1761 _EGLDriver *drv;
1762 EGLBoolean ret;
1763
1764 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1765 assert(disp->Extensions.MESA_image_dma_buf_export);
1766
1767 if (!img)
1768 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1769
1770 ret = drv->API.ExportDMABUFImageQueryMESA(drv, disp, img, fourcc, nplanes,
1771 modifiers);
1772
1773 RETURN_EGL_EVAL(disp, ret);
1774 }
1775
1776 static EGLBoolean EGLAPIENTRY
1777 eglExportDMABUFImageMESA(EGLDisplay dpy, EGLImage image,
1778 int *fds, EGLint *strides, EGLint *offsets)
1779 {
1780 _EGLDisplay *disp = _eglLockDisplay(dpy);
1781 _EGLImage *img = _eglLookupImage(image, disp);
1782 _EGLDriver *drv;
1783 EGLBoolean ret;
1784
1785 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1786 assert(disp->Extensions.MESA_image_dma_buf_export);
1787
1788 if (!img)
1789 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1790
1791 ret = drv->API.ExportDMABUFImageMESA(drv, disp, img, fds, strides, offsets);
1792
1793 RETURN_EGL_EVAL(disp, ret);
1794 }
1795
1796 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
1797 eglGetProcAddress(const char *procname)
1798 {
1799 static const struct {
1800 const char *name;
1801 _EGLProc function;
1802 } egl_functions[] = {
1803 /* core functions queryable in the presence of
1804 * EGL_KHR_get_all_proc_addresses or EGL 1.5
1805 */
1806 /* alphabetical order */
1807 { "eglBindAPI", (_EGLProc) eglBindAPI },
1808 { "eglBindTexImage", (_EGLProc) eglBindTexImage },
1809 { "eglChooseConfig", (_EGLProc) eglChooseConfig },
1810 { "eglCopyBuffers", (_EGLProc) eglCopyBuffers },
1811 { "eglCreateContext", (_EGLProc) eglCreateContext },
1812 { "eglCreatePbufferFromClientBuffer", (_EGLProc) eglCreatePbufferFromClientBuffer },
1813 { "eglCreatePbufferSurface", (_EGLProc) eglCreatePbufferSurface },
1814 { "eglCreatePixmapSurface", (_EGLProc) eglCreatePixmapSurface },
1815 { "eglCreateWindowSurface", (_EGLProc) eglCreateWindowSurface },
1816 { "eglDestroyContext", (_EGLProc) eglDestroyContext },
1817 { "eglDestroySurface", (_EGLProc) eglDestroySurface },
1818 { "eglGetConfigAttrib", (_EGLProc) eglGetConfigAttrib },
1819 { "eglGetConfigs", (_EGLProc) eglGetConfigs },
1820 { "eglGetCurrentContext", (_EGLProc) eglGetCurrentContext },
1821 { "eglGetCurrentDisplay", (_EGLProc) eglGetCurrentDisplay },
1822 { "eglGetCurrentSurface", (_EGLProc) eglGetCurrentSurface },
1823 { "eglGetDisplay", (_EGLProc) eglGetDisplay },
1824 { "eglGetError", (_EGLProc) eglGetError },
1825 { "eglGetProcAddress", (_EGLProc) eglGetProcAddress },
1826 { "eglInitialize", (_EGLProc) eglInitialize },
1827 { "eglMakeCurrent", (_EGLProc) eglMakeCurrent },
1828 { "eglQueryAPI", (_EGLProc) eglQueryAPI },
1829 { "eglQueryContext", (_EGLProc) eglQueryContext },
1830 { "eglQueryString", (_EGLProc) eglQueryString },
1831 { "eglQuerySurface", (_EGLProc) eglQuerySurface },
1832 { "eglReleaseTexImage", (_EGLProc) eglReleaseTexImage },
1833 { "eglReleaseThread", (_EGLProc) eglReleaseThread },
1834 { "eglSurfaceAttrib", (_EGLProc) eglSurfaceAttrib },
1835 { "eglSwapBuffers", (_EGLProc) eglSwapBuffers },
1836 { "eglSwapInterval", (_EGLProc) eglSwapInterval },
1837 { "eglTerminate", (_EGLProc) eglTerminate },
1838 { "eglWaitClient", (_EGLProc) eglWaitClient },
1839 { "eglWaitGL", (_EGLProc) eglWaitGL },
1840 { "eglWaitNative", (_EGLProc) eglWaitNative },
1841 { "eglCreateSync", (_EGLProc) eglCreateSync },
1842 { "eglDestroySync", (_EGLProc) eglDestroySync },
1843 { "eglClientWaitSync", (_EGLProc) eglClientWaitSync },
1844 { "eglGetSyncAttrib", (_EGLProc) eglGetSyncAttrib },
1845 { "eglWaitSync", (_EGLProc) eglWaitSync },
1846 { "eglCreateImage", (_EGLProc) eglCreateImage },
1847 { "eglDestroyImage", (_EGLProc) eglDestroyImage },
1848 { "eglGetPlatformDisplay", (_EGLProc) eglGetPlatformDisplay },
1849 { "eglCreatePlatformWindowSurface", (_EGLProc) eglCreatePlatformWindowSurface },
1850 { "eglCreatePlatformPixmapSurface", (_EGLProc) eglCreatePlatformPixmapSurface },
1851 { "eglCreateImageKHR", (_EGLProc) eglCreateImageKHR },
1852 { "eglDestroyImageKHR", (_EGLProc) eglDestroyImage },
1853 { "eglCreateSyncKHR", (_EGLProc) eglCreateSyncKHR },
1854 { "eglCreateSync64KHR", (_EGLProc) eglCreateSync64KHR },
1855 { "eglDestroySyncKHR", (_EGLProc) eglDestroySync },
1856 { "eglClientWaitSyncKHR", (_EGLProc) eglClientWaitSync },
1857 { "eglWaitSyncKHR", (_EGLProc) eglWaitSyncKHR },
1858 { "eglSignalSyncKHR", (_EGLProc) eglSignalSyncKHR },
1859 { "eglGetSyncAttribKHR", (_EGLProc) eglGetSyncAttribKHR },
1860 { "eglSwapBuffersRegionNOK", (_EGLProc) eglSwapBuffersRegionNOK },
1861 { "eglCreateDRMImageMESA", (_EGLProc) eglCreateDRMImageMESA },
1862 { "eglExportDRMImageMESA", (_EGLProc) eglExportDRMImageMESA },
1863 { "eglBindWaylandDisplayWL", (_EGLProc) eglBindWaylandDisplayWL },
1864 { "eglUnbindWaylandDisplayWL", (_EGLProc) eglUnbindWaylandDisplayWL },
1865 { "eglQueryWaylandBufferWL", (_EGLProc) eglQueryWaylandBufferWL },
1866 { "eglCreateWaylandBufferFromImageWL", (_EGLProc) eglCreateWaylandBufferFromImageWL },
1867 { "eglPostSubBufferNV", (_EGLProc) eglPostSubBufferNV },
1868 { "eglSwapBuffersWithDamageEXT", (_EGLProc) eglSwapBuffersWithDamageEXT },
1869 { "eglGetPlatformDisplayEXT", (_EGLProc) eglGetPlatformDisplayEXT },
1870 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc) eglCreatePlatformWindowSurfaceEXT },
1871 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc) eglCreatePlatformPixmapSurfaceEXT },
1872 { "eglGetSyncValuesCHROMIUM", (_EGLProc) eglGetSyncValuesCHROMIUM },
1873 { "eglExportDMABUFImageQueryMESA", (_EGLProc) eglExportDMABUFImageQueryMESA },
1874 { "eglExportDMABUFImageMESA", (_EGLProc) eglExportDMABUFImageMESA },
1875 { NULL, NULL }
1876 };
1877 EGLint i;
1878 _EGLProc ret;
1879
1880 if (!procname)
1881 RETURN_EGL_SUCCESS(NULL, NULL);
1882
1883 ret = NULL;
1884 if (strncmp(procname, "egl", 3) == 0) {
1885 for (i = 0; egl_functions[i].name; i++) {
1886 if (strcmp(egl_functions[i].name, procname) == 0) {
1887 ret = egl_functions[i].function;
1888 break;
1889 }
1890 }
1891 }
1892 if (!ret)
1893 ret = _eglGetDriverProc(procname);
1894
1895 RETURN_EGL_SUCCESS(NULL, ret);
1896 }
1897
1898 static int
1899 _eglLockDisplayInterop(EGLDisplay dpy, EGLContext context,
1900 _EGLDisplay **disp, _EGLDriver **drv,
1901 _EGLContext **ctx)
1902 {
1903
1904 *disp = _eglLockDisplay(dpy);
1905 if (!*disp || !(*disp)->Initialized || !(*disp)->Driver) {
1906 if (*disp)
1907 _eglUnlockDisplay(*disp);
1908 return MESA_GLINTEROP_INVALID_DISPLAY;
1909 }
1910
1911 *drv = (*disp)->Driver;
1912
1913 *ctx = _eglLookupContext(context, *disp);
1914 if (!*ctx ||
1915 ((*ctx)->ClientAPI != EGL_OPENGL_API &&
1916 (*ctx)->ClientAPI != EGL_OPENGL_ES_API)) {
1917 _eglUnlockDisplay(*disp);
1918 return MESA_GLINTEROP_INVALID_CONTEXT;
1919 }
1920
1921 return MESA_GLINTEROP_SUCCESS;
1922 }
1923
1924 int
1925 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy, EGLContext context,
1926 struct mesa_glinterop_device_info *out)
1927 {
1928 _EGLDisplay *disp;
1929 _EGLDriver *drv;
1930 _EGLContext *ctx;
1931 int ret;
1932
1933 ret = _eglLockDisplayInterop(dpy, context, &disp, &drv, &ctx);
1934 if (ret != MESA_GLINTEROP_SUCCESS)
1935 return ret;
1936
1937 if (drv->API.GLInteropQueryDeviceInfo)
1938 ret = drv->API.GLInteropQueryDeviceInfo(disp, ctx, out);
1939 else
1940 ret = MESA_GLINTEROP_UNSUPPORTED;
1941
1942 _eglUnlockDisplay(disp);
1943 return ret;
1944 }
1945
1946 int
1947 MesaGLInteropEGLExportObject(EGLDisplay dpy, EGLContext context,
1948 struct mesa_glinterop_export_in *in,
1949 struct mesa_glinterop_export_out *out)
1950 {
1951 _EGLDisplay *disp;
1952 _EGLDriver *drv;
1953 _EGLContext *ctx;
1954 int ret;
1955
1956 ret = _eglLockDisplayInterop(dpy, context, &disp, &drv, &ctx);
1957 if (ret != MESA_GLINTEROP_SUCCESS)
1958 return ret;
1959
1960 if (drv->API.GLInteropExportObject)
1961 ret = drv->API.GLInteropExportObject(disp, ctx, in, out);
1962 else
1963 ret = MESA_GLINTEROP_UNSUPPORTED;
1964
1965 _eglUnlockDisplay(disp);
1966 return ret;
1967 }