egl: add check that eglCreateContext gets a valid config
[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 static EGLBoolean
254 _eglSetFuncName(const char *funcName, _EGLDisplay *disp, EGLenum objectType, _EGLResource *object)
255 {
256 _EGLThreadInfo *thr = _eglGetCurrentThread();
257 if (!_eglIsCurrentThreadDummy()) {
258 thr->CurrentFuncName = funcName;
259 thr->CurrentObjectLabel = NULL;
260
261 if (objectType == EGL_OBJECT_THREAD_KHR)
262 thr->CurrentObjectLabel = thr->Label;
263 else if (objectType == EGL_OBJECT_DISPLAY_KHR && disp)
264 thr->CurrentObjectLabel = disp->Label;
265 else if (object)
266 thr->CurrentObjectLabel = object->Label;
267
268 return EGL_TRUE;
269 }
270
271 _eglDebugReportFull(EGL_BAD_ALLOC, funcName, funcName,
272 EGL_DEBUG_MSG_CRITICAL_KHR, NULL, NULL);
273 return EGL_FALSE;
274 }
275
276 #define _EGL_FUNC_START(disp, objectType, object, ret) \
277 do { \
278 if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \
279 if (disp) \
280 _eglUnlockDisplay(disp); \
281 return ret; \
282 } \
283 } while(0)
284
285 /**
286 * Convert an attribute list from EGLint[] to EGLAttrib[].
287 *
288 * Return an EGL error code. The output parameter out_attrib_list is modified
289 * only on success.
290 */
291 EGLint
292 _eglConvertIntsToAttribs(const EGLint *int_list, EGLAttrib **out_attrib_list)
293 {
294 size_t len = 0;
295 EGLAttrib *attrib_list;
296
297 if (int_list) {
298 while (int_list[2*len] != EGL_NONE)
299 ++len;
300 }
301
302 if (len == 0) {
303 *out_attrib_list = NULL;
304 return EGL_SUCCESS;
305 }
306
307 if (2*len + 1 > SIZE_MAX / sizeof(EGLAttrib))
308 return EGL_BAD_ALLOC;
309
310 attrib_list = malloc((2*len + 1) * sizeof(EGLAttrib));
311 if (!attrib_list)
312 return EGL_BAD_ALLOC;
313
314 for (size_t i = 0; i < len; ++i) {
315 attrib_list[2*i + 0] = int_list[2*i + 0];
316 attrib_list[2*i + 1] = int_list[2*i + 1];
317 }
318
319 attrib_list[2*len] = EGL_NONE;
320
321 *out_attrib_list = attrib_list;
322 return EGL_SUCCESS;
323 }
324
325
326 static EGLint *
327 _eglConvertAttribsToInt(const EGLAttrib *attr_list)
328 {
329 EGLint *int_attribs = NULL;
330
331 /* Convert attributes from EGLAttrib[] to EGLint[] */
332 if (attr_list) {
333 int i, size = 0;
334
335 while (attr_list[size] != EGL_NONE)
336 size += 2;
337
338 size += 1; /* add space for EGL_NONE */
339
340 int_attribs = calloc(size, sizeof(int_attribs[0]));
341 if (!int_attribs)
342 return NULL;
343
344 for (i = 0; i < size; i++)
345 int_attribs[i] = attr_list[i];
346 }
347 return int_attribs;
348 }
349
350
351 /**
352 * This is typically the first EGL function that an application calls.
353 * It associates a private _EGLDisplay object to the native display.
354 */
355 EGLDisplay EGLAPIENTRY
356 eglGetDisplay(EGLNativeDisplayType nativeDisplay)
357 {
358 _EGLPlatformType plat;
359 _EGLDisplay *dpy;
360 void *native_display_ptr;
361
362 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY);
363
364 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay));
365 native_display_ptr = (void*) nativeDisplay;
366
367 plat = _eglGetNativePlatform(native_display_ptr);
368 dpy = _eglFindDisplay(plat, native_display_ptr);
369 return _eglGetDisplayHandle(dpy);
370 }
371
372 static EGLDisplay
373 _eglGetPlatformDisplayCommon(EGLenum platform, void *native_display,
374 const EGLint *attrib_list)
375 {
376 _EGLDisplay *dpy;
377
378 switch (platform) {
379 #ifdef HAVE_X11_PLATFORM
380 case EGL_PLATFORM_X11_EXT:
381 dpy = _eglGetX11Display((Display*) native_display, attrib_list);
382 break;
383 #endif
384 #ifdef HAVE_DRM_PLATFORM
385 case EGL_PLATFORM_GBM_MESA:
386 dpy = _eglGetGbmDisplay((struct gbm_device*) native_display,
387 attrib_list);
388 break;
389 #endif
390 #ifdef HAVE_WAYLAND_PLATFORM
391 case EGL_PLATFORM_WAYLAND_EXT:
392 dpy = _eglGetWaylandDisplay((struct wl_display*) native_display,
393 attrib_list);
394 break;
395 #endif
396 #ifdef HAVE_SURFACELESS_PLATFORM
397 case EGL_PLATFORM_SURFACELESS_MESA:
398 dpy = _eglGetSurfacelessDisplay(native_display, attrib_list);
399 break;
400 #endif
401 default:
402 RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, NULL);
403 }
404
405 return _eglGetDisplayHandle(dpy);
406 }
407
408 static EGLDisplay EGLAPIENTRY
409 eglGetPlatformDisplayEXT(EGLenum platform, void *native_display,
410 const EGLint *attrib_list)
411 {
412 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY);
413 return _eglGetPlatformDisplayCommon(platform, native_display, attrib_list);
414 }
415
416 EGLDisplay EGLAPIENTRY
417 eglGetPlatformDisplay(EGLenum platform, void *native_display,
418 const EGLAttrib *attrib_list)
419 {
420 EGLDisplay display;
421 EGLint *int_attribs;
422
423 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY);
424
425 int_attribs = _eglConvertAttribsToInt(attrib_list);
426 if (attrib_list && !int_attribs)
427 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, NULL);
428
429 display = _eglGetPlatformDisplayCommon(platform, native_display, int_attribs);
430 free(int_attribs);
431 return display;
432 }
433
434 /**
435 * Copy the extension into the string and update the string pointer.
436 */
437 static EGLint
438 _eglAppendExtension(char **str, const char *ext)
439 {
440 char *s = *str;
441 size_t len = strlen(ext);
442
443 if (s) {
444 memcpy(s, ext, len);
445 s[len++] = ' ';
446 s[len] = '\0';
447
448 *str += len;
449 }
450 else {
451 len++;
452 }
453
454 return (EGLint) len;
455 }
456
457 /**
458 * Examine the individual extension enable/disable flags and recompute
459 * the driver's Extensions string.
460 */
461 static void
462 _eglCreateExtensionsString(_EGLDisplay *dpy)
463 {
464 #define _EGL_CHECK_EXTENSION(ext) \
465 do { \
466 if (dpy->Extensions.ext) { \
467 _eglAppendExtension(&exts, "EGL_" #ext); \
468 assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
469 } \
470 } while (0)
471
472 char *exts = dpy->ExtensionsString;
473
474 /* Please keep these sorted alphabetically. */
475 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target);
476 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer);
477 _EGL_CHECK_EXTENSION(ANDROID_recordable);
478
479 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control);
480
481 _EGL_CHECK_EXTENSION(EXT_buffer_age);
482 _EGL_CHECK_EXTENSION(EXT_create_context_robustness);
483 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import);
484 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage);
485
486 _EGL_CHECK_EXTENSION(KHR_cl_event2);
487 _EGL_CHECK_EXTENSION(KHR_create_context);
488 _EGL_CHECK_EXTENSION(KHR_fence_sync);
489 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses);
490 _EGL_CHECK_EXTENSION(KHR_gl_colorspace);
491 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image);
492 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image);
493 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image);
494 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image);
495 if (dpy->Extensions.KHR_image_base && dpy->Extensions.KHR_image_pixmap)
496 _eglAppendExtension(&exts, "EGL_KHR_image");
497 _EGL_CHECK_EXTENSION(KHR_image_base);
498 _EGL_CHECK_EXTENSION(KHR_image_pixmap);
499 _EGL_CHECK_EXTENSION(KHR_no_config_context);
500 _EGL_CHECK_EXTENSION(KHR_reusable_sync);
501 _EGL_CHECK_EXTENSION(KHR_surfaceless_context);
502 if (dpy->Extensions.EXT_swap_buffers_with_damage)
503 _eglAppendExtension(&exts, "EGL_KHR_swap_buffers_with_damage");
504 _EGL_CHECK_EXTENSION(KHR_wait_sync);
505
506 if (dpy->Extensions.KHR_no_config_context)
507 _eglAppendExtension(&exts, "EGL_MESA_configless_context");
508 _EGL_CHECK_EXTENSION(MESA_drm_image);
509 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export);
510
511 _EGL_CHECK_EXTENSION(NOK_swap_region);
512 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap);
513
514 _EGL_CHECK_EXTENSION(NV_post_sub_buffer);
515
516 _EGL_CHECK_EXTENSION(WL_bind_wayland_display);
517 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image);
518
519 #undef _EGL_CHECK_EXTENSION
520 }
521
522 static void
523 _eglCreateAPIsString(_EGLDisplay *dpy)
524 {
525 if (dpy->ClientAPIs & EGL_OPENGL_BIT)
526 strcat(dpy->ClientAPIsString, "OpenGL ");
527
528 if (dpy->ClientAPIs & EGL_OPENGL_ES_BIT ||
529 dpy->ClientAPIs & EGL_OPENGL_ES2_BIT ||
530 dpy->ClientAPIs & EGL_OPENGL_ES3_BIT_KHR) {
531 strcat(dpy->ClientAPIsString, "OpenGL_ES ");
532 }
533
534 if (dpy->ClientAPIs & EGL_OPENVG_BIT)
535 strcat(dpy->ClientAPIsString, "OpenVG ");
536
537 assert(strlen(dpy->ClientAPIsString) < sizeof(dpy->ClientAPIsString));
538 }
539
540 static void
541 _eglComputeVersion(_EGLDisplay *disp)
542 {
543 disp->Version = 14;
544
545 if (disp->Extensions.KHR_fence_sync &&
546 disp->Extensions.KHR_cl_event2 &&
547 disp->Extensions.KHR_wait_sync &&
548 disp->Extensions.KHR_image_base &&
549 disp->Extensions.KHR_gl_texture_2D_image &&
550 disp->Extensions.KHR_gl_texture_3D_image &&
551 disp->Extensions.KHR_gl_texture_cubemap_image &&
552 disp->Extensions.KHR_gl_renderbuffer_image &&
553 disp->Extensions.KHR_create_context &&
554 disp->Extensions.EXT_create_context_robustness &&
555 disp->Extensions.KHR_get_all_proc_addresses &&
556 disp->Extensions.KHR_gl_colorspace &&
557 disp->Extensions.KHR_surfaceless_context)
558 disp->Version = 15;
559 }
560
561 /**
562 * This is typically the second EGL function that an application calls.
563 * Here we load/initialize the actual hardware driver.
564 */
565 EGLBoolean EGLAPIENTRY
566 eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
567 {
568 _EGLDisplay *disp = _eglLockDisplay(dpy);
569
570 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
571
572 if (!disp)
573 RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE);
574
575 if (!disp->Initialized) {
576 if (!_eglMatchDriver(disp, EGL_FALSE))
577 RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE);
578
579 /* limit to APIs supported by core */
580 disp->ClientAPIs &= _EGL_API_ALL_BITS;
581
582 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
583 * classifies it as an EGL display extension, though conceptually it's an
584 * EGL client extension.
585 *
586 * From the EGL_KHR_get_all_proc_addresses spec:
587 *
588 * The EGL implementation must expose the name
589 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
590 * EGL_KHR_get_all_proc_addresses and supports
591 * EGL_EXT_client_extensions.
592 *
593 * Mesa unconditionally exposes both client extensions mentioned above,
594 * so the spec requires that each EGLDisplay unconditionally expose
595 * EGL_KHR_get_all_proc_addresses also.
596 */
597 disp->Extensions.KHR_get_all_proc_addresses = EGL_TRUE;
598
599 _eglComputeVersion(disp);
600 _eglCreateExtensionsString(disp);
601 _eglCreateAPIsString(disp);
602 snprintf(disp->VersionString, sizeof(disp->VersionString),
603 "%d.%d (%s)", disp->Version / 10, disp->Version % 10,
604 disp->Driver->Name);
605 }
606
607 /* Update applications version of major and minor if not NULL */
608 if ((major != NULL) && (minor != NULL)) {
609 *major = disp->Version / 10;
610 *minor = disp->Version % 10;
611 }
612
613 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
614 }
615
616
617 EGLBoolean EGLAPIENTRY
618 eglTerminate(EGLDisplay dpy)
619 {
620 _EGLDisplay *disp = _eglLockDisplay(dpy);
621
622 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
623
624 if (!disp)
625 RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE);
626
627 if (disp->Initialized) {
628 _EGLDriver *drv = disp->Driver;
629
630 drv->API.Terminate(drv, disp);
631 /* do not reset disp->Driver */
632 disp->ClientAPIsString[0] = 0;
633 disp->Initialized = EGL_FALSE;
634 }
635
636 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
637 }
638
639
640 const char * EGLAPIENTRY
641 eglQueryString(EGLDisplay dpy, EGLint name)
642 {
643 _EGLDisplay *disp;
644 _EGLDriver *drv;
645
646 if (dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS) {
647 RETURN_EGL_SUCCESS(NULL, _eglGlobal.ClientExtensionString);
648 }
649
650 disp = _eglLockDisplay(dpy);
651 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, NULL);
652 _EGL_CHECK_DISPLAY(disp, NULL, drv);
653
654 switch (name) {
655 case EGL_VENDOR:
656 RETURN_EGL_SUCCESS(disp, _EGL_VENDOR_STRING);
657 case EGL_VERSION:
658 RETURN_EGL_SUCCESS(disp, disp->VersionString);
659 case EGL_EXTENSIONS:
660 RETURN_EGL_SUCCESS(disp, disp->ExtensionsString);
661 case EGL_CLIENT_APIS:
662 RETURN_EGL_SUCCESS(disp, disp->ClientAPIsString);
663 default:
664 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL);
665 }
666 }
667
668
669 EGLBoolean EGLAPIENTRY
670 eglGetConfigs(EGLDisplay dpy, EGLConfig *configs,
671 EGLint config_size, EGLint *num_config)
672 {
673 _EGLDisplay *disp = _eglLockDisplay(dpy);
674 _EGLDriver *drv;
675 EGLBoolean ret;
676
677 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
678
679 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
680 ret = drv->API.GetConfigs(drv, disp, configs, config_size, num_config);
681
682 RETURN_EGL_EVAL(disp, ret);
683 }
684
685
686 EGLBoolean EGLAPIENTRY
687 eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs,
688 EGLint config_size, EGLint *num_config)
689 {
690 _EGLDisplay *disp = _eglLockDisplay(dpy);
691 _EGLDriver *drv;
692 EGLBoolean ret;
693
694 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
695
696 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
697 ret = drv->API.ChooseConfig(drv, disp, attrib_list, configs,
698 config_size, num_config);
699
700 RETURN_EGL_EVAL(disp, ret);
701 }
702
703
704 EGLBoolean EGLAPIENTRY
705 eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
706 EGLint attribute, EGLint *value)
707 {
708 _EGLDisplay *disp = _eglLockDisplay(dpy);
709 _EGLConfig *conf = _eglLookupConfig(config, disp);
710 _EGLDriver *drv;
711 EGLBoolean ret;
712
713 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
714
715 _EGL_CHECK_CONFIG(disp, conf, EGL_FALSE, drv);
716 ret = drv->API.GetConfigAttrib(drv, disp, conf, attribute, value);
717
718 RETURN_EGL_EVAL(disp, ret);
719 }
720
721
722 EGLContext EGLAPIENTRY
723 eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list,
724 const EGLint *attrib_list)
725 {
726 _EGLDisplay *disp = _eglLockDisplay(dpy);
727 _EGLConfig *conf = _eglLookupConfig(config, disp);
728 _EGLContext *share = _eglLookupContext(share_list, disp);
729 _EGLDriver *drv;
730 _EGLContext *context;
731 EGLContext ret;
732
733 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_CONTEXT);
734
735 _EGL_CHECK_DISPLAY(disp, EGL_NO_CONTEXT, drv);
736
737 if (config != EGL_NO_CONFIG_KHR)
738 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_CONTEXT, drv);
739 else if (!disp->Extensions.KHR_no_config_context)
740 RETURN_EGL_ERROR(disp, EGL_BAD_CONFIG, EGL_NO_CONTEXT);
741
742 if (!share && share_list != EGL_NO_CONTEXT)
743 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_CONTEXT);
744
745 context = drv->API.CreateContext(drv, disp, conf, share, attrib_list);
746 ret = (context) ? _eglLinkContext(context) : EGL_NO_CONTEXT;
747
748 RETURN_EGL_EVAL(disp, ret);
749 }
750
751
752 EGLBoolean EGLAPIENTRY
753 eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
754 {
755 _EGLDisplay *disp = _eglLockDisplay(dpy);
756 _EGLContext *context = _eglLookupContext(ctx, disp);
757 _EGLDriver *drv;
758 EGLBoolean ret;
759
760 _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE);
761
762 _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv);
763 _eglUnlinkContext(context);
764 ret = drv->API.DestroyContext(drv, disp, context);
765
766 RETURN_EGL_EVAL(disp, ret);
767 }
768
769
770 EGLBoolean EGLAPIENTRY
771 eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read,
772 EGLContext ctx)
773 {
774 _EGLDisplay *disp = _eglLockDisplay(dpy);
775 _EGLContext *context = _eglLookupContext(ctx, disp);
776 _EGLSurface *draw_surf = _eglLookupSurface(draw, disp);
777 _EGLSurface *read_surf = _eglLookupSurface(read, disp);
778 _EGLDriver *drv;
779 EGLBoolean ret;
780
781 _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE);
782
783 if (!disp)
784 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE);
785 drv = disp->Driver;
786
787 /* display is allowed to be uninitialized under certain condition */
788 if (!disp->Initialized) {
789 if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE ||
790 ctx != EGL_NO_CONTEXT)
791 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE);
792 }
793 if (!drv)
794 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
795
796 if (!context && ctx != EGL_NO_CONTEXT)
797 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE);
798 if (!draw_surf || !read_surf) {
799 /* From the EGL 1.4 (20130211) spec:
800 *
801 * To release the current context without assigning a new one, set ctx
802 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
803 */
804 if (!disp->Extensions.KHR_surfaceless_context && ctx != EGL_NO_CONTEXT)
805 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
806
807 if ((!draw_surf && draw != EGL_NO_SURFACE) ||
808 (!read_surf && read != EGL_NO_SURFACE))
809 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
810 if (draw_surf || read_surf)
811 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
812 }
813
814 ret = drv->API.MakeCurrent(drv, disp, draw_surf, read_surf, context);
815
816 RETURN_EGL_EVAL(disp, ret);
817 }
818
819
820 EGLBoolean EGLAPIENTRY
821 eglQueryContext(EGLDisplay dpy, EGLContext ctx,
822 EGLint attribute, EGLint *value)
823 {
824 _EGLDisplay *disp = _eglLockDisplay(dpy);
825 _EGLContext *context = _eglLookupContext(ctx, disp);
826 _EGLDriver *drv;
827 EGLBoolean ret;
828
829 _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE);
830
831 _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv);
832 ret = drv->API.QueryContext(drv, disp, context, attribute, value);
833
834 RETURN_EGL_EVAL(disp, ret);
835 }
836
837
838 static EGLSurface
839 _eglCreateWindowSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
840 void *native_window, const EGLint *attrib_list)
841 {
842 _EGLConfig *conf = _eglLookupConfig(config, disp);
843 _EGLDriver *drv;
844 _EGLSurface *surf;
845 EGLSurface ret;
846
847
848 if (native_window == NULL)
849 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
850
851 #ifdef HAVE_SURFACELESS_PLATFORM
852 if (disp->Platform == _EGL_PLATFORM_SURFACELESS) {
853 /* From the EGL_MESA_platform_surfaceless spec (v1):
854 *
855 * eglCreatePlatformWindowSurface fails when called with a <display>
856 * that belongs to the surfaceless platform. It returns
857 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
858 * justification for this unconditional failure is that the
859 * surfaceless platform has no native windows, and therefore the
860 * <native_window> parameter is always invalid.
861 *
862 * This check must occur before checking the EGLConfig, which emits
863 * EGL_BAD_CONFIG.
864 */
865 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
866 }
867 #endif
868
869 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
870
871 surf = drv->API.CreateWindowSurface(drv, disp, conf, native_window,
872 attrib_list);
873 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
874
875 RETURN_EGL_EVAL(disp, ret);
876 }
877
878
879 EGLSurface EGLAPIENTRY
880 eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
881 EGLNativeWindowType window, const EGLint *attrib_list)
882 {
883 _EGLDisplay *disp = _eglLockDisplay(dpy);
884
885 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
886 STATIC_ASSERT(sizeof(void*) == sizeof(window));
887 return _eglCreateWindowSurfaceCommon(disp, config, (void*) window,
888 attrib_list);
889 }
890
891 static void *
892 fixupNativeWindow(_EGLDisplay *disp, void *native_window)
893 {
894 #ifdef HAVE_X11_PLATFORM
895 if (disp->Platform == _EGL_PLATFORM_X11 && native_window != NULL) {
896 /* The `native_window` parameter for the X11 platform differs between
897 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
898 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
899 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
900 * `Window*`. Convert `Window*` to `Window` because that's what
901 * dri2_x11_create_window_surface() expects.
902 */
903 return (void *)(* (Window*) native_window);
904 }
905 #endif
906 return native_window;
907 }
908
909 static EGLSurface EGLAPIENTRY
910 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config,
911 void *native_window,
912 const EGLint *attrib_list)
913 {
914 _EGLDisplay *disp = _eglLockDisplay(dpy);
915
916 native_window = fixupNativeWindow(disp, native_window);
917
918 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
919 return _eglCreateWindowSurfaceCommon(disp, config, native_window,
920 attrib_list);
921 }
922
923
924 EGLSurface EGLAPIENTRY
925 eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config,
926 void *native_window,
927 const EGLAttrib *attrib_list)
928 {
929 _EGLDisplay *disp = _eglLockDisplay(dpy);
930 EGLSurface surface;
931 EGLint *int_attribs;
932
933 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
934
935 int_attribs = _eglConvertAttribsToInt(attrib_list);
936 if (attrib_list && !int_attribs)
937 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE);
938
939 native_window = fixupNativeWindow(disp, native_window);
940 surface = _eglCreateWindowSurfaceCommon(disp, config, native_window,
941 int_attribs);
942 free(int_attribs);
943 return surface;
944 }
945
946 static void *
947 fixupNativePixmap(_EGLDisplay *disp, void *native_pixmap)
948 {
949 #ifdef HAVE_X11_PLATFORM
950 /* The `native_pixmap` parameter for the X11 platform differs between
951 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
952 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
953 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
954 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
955 * dri2_x11_create_pixmap_surface() expects.
956 */
957 if (disp->Platform == _EGL_PLATFORM_X11 && native_pixmap != NULL)
958 return (void *)(* (Pixmap*) native_pixmap);
959 #endif
960 return native_pixmap;
961 }
962
963 static EGLSurface
964 _eglCreatePixmapSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
965 void *native_pixmap, const EGLint *attrib_list)
966 {
967 _EGLConfig *conf = _eglLookupConfig(config, disp);
968 _EGLDriver *drv;
969 _EGLSurface *surf;
970 EGLSurface ret;
971
972 #if HAVE_SURFACELESS_PLATFORM
973 if (disp->Platform == _EGL_PLATFORM_SURFACELESS) {
974 /* From the EGL_MESA_platform_surfaceless spec (v1):
975 *
976 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
977 * also fails when called with a <display> that belongs to the
978 * surfaceless platform. It returns EGL_NO_SURFACE and generates
979 * EGL_BAD_NATIVE_PIXMAP.
980 *
981 * This check must occur before checking the EGLConfig, which emits
982 * EGL_BAD_CONFIG.
983 */
984 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE);
985 }
986 #endif
987
988 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
989 surf = drv->API.CreatePixmapSurface(drv, disp, conf, native_pixmap,
990 attrib_list);
991 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
992
993 RETURN_EGL_EVAL(disp, ret);
994 }
995
996
997 EGLSurface EGLAPIENTRY
998 eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config,
999 EGLNativePixmapType pixmap, const EGLint *attrib_list)
1000 {
1001 _EGLDisplay *disp = _eglLockDisplay(dpy);
1002
1003 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1004 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap));
1005 return _eglCreatePixmapSurfaceCommon(disp, config, (void*) pixmap,
1006 attrib_list);
1007 }
1008
1009 static EGLSurface EGLAPIENTRY
1010 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config,
1011 void *native_pixmap,
1012 const EGLint *attrib_list)
1013 {
1014 _EGLDisplay *disp = _eglLockDisplay(dpy);
1015
1016 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1017 native_pixmap = fixupNativePixmap(disp, native_pixmap);
1018 return _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap,
1019 attrib_list);
1020 }
1021
1022
1023 EGLSurface EGLAPIENTRY
1024 eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config,
1025 void *native_pixmap,
1026 const EGLAttrib *attrib_list)
1027 {
1028 _EGLDisplay *disp = _eglLockDisplay(dpy);
1029 EGLSurface surface;
1030 EGLint *int_attribs;
1031
1032 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1033
1034 int_attribs = _eglConvertAttribsToInt(attrib_list);
1035 if (attrib_list && !int_attribs)
1036 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE);
1037
1038 native_pixmap = fixupNativePixmap(disp, native_pixmap);
1039 surface = _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap,
1040 int_attribs);
1041 free(int_attribs);
1042 return surface;
1043 }
1044
1045
1046 EGLSurface EGLAPIENTRY
1047 eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,
1048 const EGLint *attrib_list)
1049 {
1050 _EGLDisplay *disp = _eglLockDisplay(dpy);
1051 _EGLConfig *conf = _eglLookupConfig(config, disp);
1052 _EGLDriver *drv;
1053 _EGLSurface *surf;
1054 EGLSurface ret;
1055
1056 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1057 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
1058
1059 surf = drv->API.CreatePbufferSurface(drv, disp, conf, attrib_list);
1060 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
1061
1062 RETURN_EGL_EVAL(disp, ret);
1063 }
1064
1065
1066 EGLBoolean EGLAPIENTRY
1067 eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
1068 {
1069 _EGLDisplay *disp = _eglLockDisplay(dpy);
1070 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1071 _EGLDriver *drv;
1072 EGLBoolean ret;
1073
1074 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1075 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1076 _eglUnlinkSurface(surf);
1077 ret = drv->API.DestroySurface(drv, disp, surf);
1078
1079 RETURN_EGL_EVAL(disp, ret);
1080 }
1081
1082 EGLBoolean EGLAPIENTRY
1083 eglQuerySurface(EGLDisplay dpy, EGLSurface surface,
1084 EGLint attribute, EGLint *value)
1085 {
1086 _EGLDisplay *disp = _eglLockDisplay(dpy);
1087 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1088 _EGLDriver *drv;
1089 EGLBoolean ret;
1090
1091 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1092 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1093 ret = drv->API.QuerySurface(drv, disp, surf, attribute, value);
1094
1095 RETURN_EGL_EVAL(disp, ret);
1096 }
1097
1098 EGLBoolean EGLAPIENTRY
1099 eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface,
1100 EGLint attribute, EGLint value)
1101 {
1102 _EGLDisplay *disp = _eglLockDisplay(dpy);
1103 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1104 _EGLDriver *drv;
1105 EGLBoolean ret;
1106
1107 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1108 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1109 ret = drv->API.SurfaceAttrib(drv, disp, surf, attribute, value);
1110
1111 RETURN_EGL_EVAL(disp, ret);
1112 }
1113
1114
1115 EGLBoolean EGLAPIENTRY
1116 eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1117 {
1118 _EGLDisplay *disp = _eglLockDisplay(dpy);
1119 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1120 _EGLDriver *drv;
1121 EGLBoolean ret;
1122
1123 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1124 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1125 ret = drv->API.BindTexImage(drv, disp, surf, buffer);
1126
1127 RETURN_EGL_EVAL(disp, ret);
1128 }
1129
1130
1131 EGLBoolean EGLAPIENTRY
1132 eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1133 {
1134 _EGLDisplay *disp = _eglLockDisplay(dpy);
1135 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1136 _EGLDriver *drv;
1137 EGLBoolean ret;
1138
1139 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1140 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1141 ret = drv->API.ReleaseTexImage(drv, disp, surf, buffer);
1142
1143 RETURN_EGL_EVAL(disp, ret);
1144 }
1145
1146
1147 EGLBoolean EGLAPIENTRY
1148 eglSwapInterval(EGLDisplay dpy, EGLint interval)
1149 {
1150 _EGLDisplay *disp = _eglLockDisplay(dpy);
1151 _EGLContext *ctx = _eglGetCurrentContext();
1152 _EGLSurface *surf = ctx ? ctx->DrawSurface : NULL;
1153 _EGLDriver *drv;
1154 EGLBoolean ret;
1155
1156 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1157 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1158
1159 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1160 ctx->Resource.Display != disp)
1161 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE);
1162
1163 if (_eglGetSurfaceHandle(surf) == EGL_NO_SURFACE)
1164 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1165
1166 ret = drv->API.SwapInterval(drv, disp, surf, interval);
1167
1168 RETURN_EGL_EVAL(disp, ret);
1169 }
1170
1171
1172 EGLBoolean EGLAPIENTRY
1173 eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
1174 {
1175 _EGLContext *ctx = _eglGetCurrentContext();
1176 _EGLDisplay *disp = _eglLockDisplay(dpy);
1177 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1178 _EGLDriver *drv;
1179 EGLBoolean ret;
1180
1181 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1182 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1183
1184 /* surface must be bound to current context in EGL 1.4 */
1185 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1186 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1187 surf != ctx->DrawSurface)
1188 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1189 #endif
1190
1191 ret = drv->API.SwapBuffers(drv, disp, surf);
1192
1193 RETURN_EGL_EVAL(disp, ret);
1194 }
1195
1196
1197 static EGLBoolean
1198 eglSwapBuffersWithDamageCommon(_EGLDisplay *disp, _EGLSurface *surf,
1199 EGLint *rects, EGLint n_rects)
1200 {
1201 _EGLContext *ctx = _eglGetCurrentContext();
1202 _EGLDriver *drv;
1203 EGLBoolean ret;
1204
1205 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1206
1207 /* surface must be bound to current context in EGL 1.4 */
1208 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1209 surf != ctx->DrawSurface)
1210 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1211
1212 if ((n_rects > 0 && rects == NULL) || n_rects < 0)
1213 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1214
1215 ret = drv->API.SwapBuffersWithDamageEXT(drv, disp, surf, rects, n_rects);
1216
1217 RETURN_EGL_EVAL(disp, ret);
1218 }
1219
1220 static EGLBoolean EGLAPIENTRY
1221 eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface,
1222 EGLint *rects, EGLint n_rects)
1223 {
1224 _EGLDisplay *disp = _eglLockDisplay(dpy);
1225 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1226 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1227 return eglSwapBuffersWithDamageCommon(disp, surf, rects, n_rects);
1228 }
1229
1230 static EGLBoolean EGLAPIENTRY
1231 eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface,
1232 EGLint *rects, EGLint n_rects)
1233 {
1234 _EGLDisplay *disp = _eglLockDisplay(dpy);
1235 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1236 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1237 return eglSwapBuffersWithDamageCommon(disp, surf, rects, n_rects);
1238 }
1239
1240 EGLBoolean EGLAPIENTRY
1241 eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
1242 {
1243 _EGLDisplay *disp = _eglLockDisplay(dpy);
1244 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1245 _EGLDriver *drv;
1246 EGLBoolean ret;
1247 void *native_pixmap_ptr;
1248
1249 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1250 STATIC_ASSERT(sizeof(void*) == sizeof(target));
1251 native_pixmap_ptr = (void*) target;
1252
1253 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1254 if (disp->Platform != _eglGetNativePlatform(disp->PlatformDisplay))
1255 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_FALSE);
1256 ret = drv->API.CopyBuffers(drv, disp, surf, native_pixmap_ptr);
1257
1258 RETURN_EGL_EVAL(disp, ret);
1259 }
1260
1261
1262 static EGLBoolean
1263 _eglWaitClientCommon(void)
1264 {
1265 _EGLContext *ctx = _eglGetCurrentContext();
1266 _EGLDisplay *disp;
1267 _EGLDriver *drv;
1268 EGLBoolean ret;
1269
1270 if (!ctx)
1271 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1272
1273 disp = ctx->Resource.Display;
1274 mtx_lock(&disp->Mutex);
1275
1276 /* let bad current context imply bad current surface */
1277 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1278 _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE)
1279 RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
1280
1281 /* a valid current context implies an initialized current display */
1282 assert(disp->Initialized);
1283 drv = disp->Driver;
1284 ret = drv->API.WaitClient(drv, disp, ctx);
1285
1286 RETURN_EGL_EVAL(disp, ret);
1287 }
1288
1289 EGLBoolean EGLAPIENTRY
1290 eglWaitClient(void)
1291 {
1292 _EGL_FUNC_START(NULL, EGL_OBJECT_CONTEXT_KHR, _eglGetCurrentContext(), EGL_FALSE);
1293 return _eglWaitClientCommon();
1294 }
1295
1296 EGLBoolean EGLAPIENTRY
1297 eglWaitGL(void)
1298 {
1299 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1300 _EGL_FUNC_START(NULL, EGL_OBJECT_CONTEXT_KHR, _eglGetCurrentContext(), EGL_FALSE);
1301 return _eglWaitClientCommon();
1302 }
1303
1304
1305 EGLBoolean EGLAPIENTRY
1306 eglWaitNative(EGLint engine)
1307 {
1308 _EGLContext *ctx = _eglGetCurrentContext();
1309 _EGLDisplay *disp;
1310 _EGLDriver *drv;
1311 EGLBoolean ret;
1312
1313 if (!ctx)
1314 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1315
1316 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE);
1317
1318 disp = ctx->Resource.Display;
1319 mtx_lock(&disp->Mutex);
1320
1321 /* let bad current context imply bad current surface */
1322 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1323 _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE)
1324 RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
1325
1326 /* a valid current context implies an initialized current display */
1327 assert(disp->Initialized);
1328 drv = disp->Driver;
1329 ret = drv->API.WaitNative(drv, disp, engine);
1330
1331 RETURN_EGL_EVAL(disp, ret);
1332 }
1333
1334
1335 EGLDisplay EGLAPIENTRY
1336 eglGetCurrentDisplay(void)
1337 {
1338 _EGLContext *ctx = _eglGetCurrentContext();
1339 EGLDisplay ret;
1340
1341 ret = (ctx) ? _eglGetDisplayHandle(ctx->Resource.Display) : EGL_NO_DISPLAY;
1342
1343 RETURN_EGL_SUCCESS(NULL, ret);
1344 }
1345
1346
1347 EGLContext EGLAPIENTRY
1348 eglGetCurrentContext(void)
1349 {
1350 _EGLContext *ctx = _eglGetCurrentContext();
1351 EGLContext ret;
1352
1353 ret = _eglGetContextHandle(ctx);
1354
1355 RETURN_EGL_SUCCESS(NULL, ret);
1356 }
1357
1358
1359 EGLSurface EGLAPIENTRY
1360 eglGetCurrentSurface(EGLint readdraw)
1361 {
1362 _EGLContext *ctx = _eglGetCurrentContext();
1363 EGLint err = EGL_SUCCESS;
1364 _EGLSurface *surf;
1365 EGLSurface ret;
1366
1367 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_NO_SURFACE);
1368
1369 if (!ctx)
1370 RETURN_EGL_SUCCESS(NULL, EGL_NO_SURFACE);
1371
1372 switch (readdraw) {
1373 case EGL_DRAW:
1374 surf = ctx->DrawSurface;
1375 break;
1376 case EGL_READ:
1377 surf = ctx->ReadSurface;
1378 break;
1379 default:
1380 surf = NULL;
1381 err = EGL_BAD_PARAMETER;
1382 break;
1383 }
1384
1385 ret = _eglGetSurfaceHandle(surf);
1386
1387 RETURN_EGL_ERROR(NULL, err, ret);
1388 }
1389
1390
1391 EGLint EGLAPIENTRY
1392 eglGetError(void)
1393 {
1394 _EGLThreadInfo *t = _eglGetCurrentThread();
1395 EGLint e = t->LastError;
1396 if (!_eglIsCurrentThreadDummy())
1397 t->LastError = EGL_SUCCESS;
1398 return e;
1399 }
1400
1401
1402 /**
1403 ** EGL 1.2
1404 **/
1405
1406 /**
1407 * Specify the client API to use for subsequent calls including:
1408 * eglCreateContext()
1409 * eglGetCurrentContext()
1410 * eglGetCurrentDisplay()
1411 * eglGetCurrentSurface()
1412 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1413 * eglWaitClient()
1414 * eglWaitNative()
1415 * See section 3.7 "Rendering Context" in the EGL specification for details.
1416 */
1417 EGLBoolean EGLAPIENTRY
1418 eglBindAPI(EGLenum api)
1419 {
1420 _EGLThreadInfo *t;
1421
1422 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE);
1423
1424 t = _eglGetCurrentThread();
1425 if (_eglIsCurrentThreadDummy())
1426 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_FALSE);
1427
1428 if (!_eglIsApiValid(api))
1429 RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, EGL_FALSE);
1430
1431 t->CurrentAPI = api;
1432
1433 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1434 }
1435
1436
1437 /**
1438 * Return the last value set with eglBindAPI().
1439 */
1440 EGLenum EGLAPIENTRY
1441 eglQueryAPI(void)
1442 {
1443 _EGLThreadInfo *t = _eglGetCurrentThread();
1444 EGLenum ret;
1445
1446 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1447 ret = t->CurrentAPI;
1448
1449 RETURN_EGL_SUCCESS(NULL, ret);
1450 }
1451
1452
1453 EGLSurface EGLAPIENTRY
1454 eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype,
1455 EGLClientBuffer buffer, EGLConfig config,
1456 const EGLint *attrib_list)
1457 {
1458 _EGLDisplay *disp = _eglLockDisplay(dpy);
1459 _EGLConfig *conf = _eglLookupConfig(config, disp);
1460 _EGLDriver *drv;
1461 _EGLSurface *surf;
1462 EGLSurface ret;
1463
1464 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1465
1466 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
1467
1468 surf = drv->API.CreatePbufferFromClientBuffer(drv, disp, buftype, buffer,
1469 conf, attrib_list);
1470 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
1471
1472 RETURN_EGL_EVAL(disp, ret);
1473 }
1474
1475
1476 EGLBoolean EGLAPIENTRY
1477 eglReleaseThread(void)
1478 {
1479 /* unbind current contexts */
1480 if (!_eglIsCurrentThreadDummy()) {
1481 _EGLThreadInfo *t = _eglGetCurrentThread();
1482 _EGLContext *ctx = t->CurrentContext;
1483
1484 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE);
1485
1486 if (ctx) {
1487 _EGLDisplay *disp = ctx->Resource.Display;
1488 _EGLDriver *drv;
1489
1490 mtx_lock(&disp->Mutex);
1491 drv = disp->Driver;
1492 (void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL);
1493 mtx_unlock(&disp->Mutex);
1494 }
1495 }
1496
1497 _eglDestroyCurrentThread();
1498
1499 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1500 }
1501
1502
1503 static EGLImage
1504 _eglCreateImageCommon(_EGLDisplay *disp, EGLContext ctx, EGLenum target,
1505 EGLClientBuffer buffer, const EGLint *attr_list)
1506 {
1507 _EGLContext *context = _eglLookupContext(ctx, disp);
1508 _EGLDriver *drv;
1509 _EGLImage *img;
1510 EGLImage ret;
1511
1512 _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv);
1513 if (!disp->Extensions.KHR_image_base)
1514 RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR);
1515 if (!context && ctx != EGL_NO_CONTEXT)
1516 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR);
1517 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1518 * <ctx> must be EGL_NO_CONTEXT..."
1519 */
1520 if (ctx != EGL_NO_CONTEXT && target == EGL_LINUX_DMA_BUF_EXT)
1521 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
1522
1523 img = drv->API.CreateImageKHR(drv,
1524 disp, context, target, buffer, attr_list);
1525 ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR;
1526
1527 RETURN_EGL_EVAL(disp, ret);
1528 }
1529
1530 static EGLImage EGLAPIENTRY
1531 eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1532 EGLClientBuffer buffer, const EGLint *attr_list)
1533 {
1534 _EGLDisplay *disp = _eglLockDisplay(dpy);
1535 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_IMAGE_KHR);
1536 return _eglCreateImageCommon(disp, ctx, target, buffer, attr_list);
1537 }
1538
1539
1540 EGLImage EGLAPIENTRY
1541 eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1542 EGLClientBuffer buffer, const EGLAttrib *attr_list)
1543 {
1544 _EGLDisplay *disp = _eglLockDisplay(dpy);
1545 EGLImage image;
1546 EGLint *int_attribs;
1547
1548 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_IMAGE_KHR);
1549
1550 int_attribs = _eglConvertAttribsToInt(attr_list);
1551 if (attr_list && !int_attribs)
1552 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_IMAGE);
1553
1554 image = _eglCreateImageCommon(disp, ctx, target, buffer, int_attribs);
1555 free(int_attribs);
1556 return image;
1557 }
1558
1559
1560 EGLBoolean EGLAPIENTRY
1561 eglDestroyImage(EGLDisplay dpy, EGLImage image)
1562 {
1563 _EGLDisplay *disp = _eglLockDisplay(dpy);
1564 _EGLImage *img = _eglLookupImage(image, disp);
1565 _EGLDriver *drv;
1566 EGLBoolean ret;
1567
1568 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
1569
1570 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1571 if (!disp->Extensions.KHR_image_base)
1572 RETURN_EGL_EVAL(disp, EGL_FALSE);
1573 if (!img)
1574 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1575
1576 _eglUnlinkImage(img);
1577 ret = drv->API.DestroyImageKHR(drv, disp, img);
1578
1579 RETURN_EGL_EVAL(disp, ret);
1580 }
1581
1582
1583 static EGLSync
1584 _eglCreateSync(_EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_list,
1585 EGLBoolean orig_is_EGLAttrib,
1586 EGLenum invalid_type_error)
1587 {
1588 _EGLContext *ctx = _eglGetCurrentContext();
1589 _EGLDriver *drv;
1590 _EGLSync *sync;
1591 EGLSync ret;
1592
1593 _EGL_CHECK_DISPLAY(disp, EGL_NO_SYNC_KHR, drv);
1594
1595 if (!disp->Extensions.KHR_cl_event2 && orig_is_EGLAttrib) {
1596 /* There exist two EGLAttrib variants of eglCreateSync*:
1597 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1598 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1599 * support as a proxy for EGL 1.5 support, even though that's not
1600 * entirely correct (though _eglComputeVersion does the same).
1601 *
1602 * The EGL spec provides no guidance on how to handle unsupported
1603 * functions. EGL_BAD_MATCH seems reasonable.
1604 */
1605 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
1606 }
1607
1608 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1609 if (!ctx || ctx->Resource.Display != disp ||
1610 ctx->ClientAPI != EGL_OPENGL_ES_API)
1611 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
1612
1613 switch (type) {
1614 case EGL_SYNC_FENCE_KHR:
1615 if (!disp->Extensions.KHR_fence_sync)
1616 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1617 break;
1618 case EGL_SYNC_REUSABLE_KHR:
1619 if (!disp->Extensions.KHR_reusable_sync)
1620 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1621 break;
1622 case EGL_SYNC_CL_EVENT_KHR:
1623 if (!disp->Extensions.KHR_cl_event2)
1624 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1625 break;
1626 default:
1627 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1628 }
1629
1630 sync = drv->API.CreateSyncKHR(drv, disp, type, attrib_list);
1631 ret = (sync) ? _eglLinkSync(sync) : EGL_NO_SYNC_KHR;
1632
1633 RETURN_EGL_EVAL(disp, ret);
1634 }
1635
1636
1637 static EGLSync EGLAPIENTRY
1638 eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *int_list)
1639 {
1640 _EGLDisplay *disp = _eglLockDisplay(dpy);
1641 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1642
1643 EGLSync sync;
1644 EGLAttrib *attrib_list;
1645 EGLint err;
1646
1647 if (sizeof(int_list[0]) == sizeof(attrib_list[0])) {
1648 attrib_list = (EGLAttrib *) int_list;
1649 } else {
1650 err = _eglConvertIntsToAttribs(int_list, &attrib_list);
1651 if (err != EGL_SUCCESS)
1652 RETURN_EGL_ERROR(disp, err, EGL_NO_SYNC);
1653 }
1654
1655 sync = _eglCreateSync(disp, type, attrib_list, EGL_FALSE,
1656 EGL_BAD_ATTRIBUTE);
1657
1658 if (sizeof(int_list[0]) != sizeof(attrib_list[0]))
1659 free(attrib_list);
1660
1661 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1662 return sync;
1663 }
1664
1665
1666 static EGLSync EGLAPIENTRY
1667 eglCreateSync64KHR(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
1668 {
1669 _EGLDisplay *disp = _eglLockDisplay(dpy);
1670 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1671 return _eglCreateSync(disp, type, attrib_list, EGL_TRUE,
1672 EGL_BAD_ATTRIBUTE);
1673 }
1674
1675
1676 EGLSync EGLAPIENTRY
1677 eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
1678 {
1679 _EGLDisplay *disp = _eglLockDisplay(dpy);
1680 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1681 return _eglCreateSync(disp, type, attrib_list, EGL_TRUE,
1682 EGL_BAD_PARAMETER);
1683 }
1684
1685
1686 EGLBoolean EGLAPIENTRY
1687 eglDestroySync(EGLDisplay dpy, EGLSync sync)
1688 {
1689 _EGLDisplay *disp = _eglLockDisplay(dpy);
1690 _EGLSync *s = _eglLookupSync(sync, disp);
1691 _EGLDriver *drv;
1692 EGLBoolean ret;
1693
1694 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1695
1696 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1697 assert(disp->Extensions.KHR_reusable_sync ||
1698 disp->Extensions.KHR_fence_sync);
1699
1700 _eglUnlinkSync(s);
1701 ret = drv->API.DestroySyncKHR(drv, disp, s);
1702
1703 RETURN_EGL_EVAL(disp, ret);
1704 }
1705
1706
1707 EGLint EGLAPIENTRY
1708 eglClientWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout)
1709 {
1710 _EGLDisplay *disp = _eglLockDisplay(dpy);
1711 _EGLSync *s = _eglLookupSync(sync, disp);
1712 _EGLDriver *drv;
1713 EGLint ret;
1714
1715 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1716
1717 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1718 assert(disp->Extensions.KHR_reusable_sync ||
1719 disp->Extensions.KHR_fence_sync);
1720
1721 if (s->SyncStatus == EGL_SIGNALED_KHR)
1722 RETURN_EGL_EVAL(disp, EGL_CONDITION_SATISFIED_KHR);
1723
1724 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1725 * unlocked here to allow other threads also to be able to
1726 * go into waiting state.
1727 */
1728
1729 if (s->Type == EGL_SYNC_REUSABLE_KHR)
1730 _eglUnlockDisplay(dpy);
1731
1732 ret = drv->API.ClientWaitSyncKHR(drv, disp, s, flags, timeout);
1733
1734 /*
1735 * 'disp' is already unlocked for reusable sync type,
1736 * so passing 'NULL' to bypass unlocking display.
1737 */
1738 if (s->Type == EGL_SYNC_REUSABLE_KHR)
1739 RETURN_EGL_EVAL(NULL, ret);
1740 else
1741 RETURN_EGL_EVAL(disp, ret);
1742 }
1743
1744
1745 static EGLint
1746 _eglWaitSyncCommon(_EGLDisplay *disp, _EGLSync *s, EGLint flags)
1747 {
1748 _EGLContext *ctx = _eglGetCurrentContext();
1749 _EGLDriver *drv;
1750 EGLint ret;
1751
1752 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1753 assert(disp->Extensions.KHR_wait_sync);
1754
1755 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1756 if (ctx == EGL_NO_CONTEXT || ctx->ClientAPI != EGL_OPENGL_ES_API)
1757 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
1758
1759 /* the API doesn't allow any flags yet */
1760 if (flags != 0)
1761 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1762
1763 ret = drv->API.WaitSyncKHR(drv, disp, s);
1764
1765 RETURN_EGL_EVAL(disp, ret);
1766 }
1767
1768 static EGLint EGLAPIENTRY
1769 eglWaitSyncKHR(EGLDisplay dpy, EGLSync sync, EGLint flags)
1770 {
1771 _EGLDisplay *disp = _eglLockDisplay(dpy);
1772 _EGLSync *s = _eglLookupSync(sync, disp);
1773 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1774 return _eglWaitSyncCommon(disp, s, flags);
1775 }
1776
1777
1778 EGLBoolean EGLAPIENTRY
1779 eglWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags)
1780 {
1781 /* The KHR version returns EGLint, while the core version returns
1782 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1783 * EGL_TRUE.
1784 */
1785 _EGLDisplay *disp = _eglLockDisplay(dpy);
1786 _EGLSync *s = _eglLookupSync(sync, disp);
1787 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1788 return _eglWaitSyncCommon(disp, s, flags);
1789 }
1790
1791
1792 static EGLBoolean EGLAPIENTRY
1793 eglSignalSyncKHR(EGLDisplay dpy, EGLSync sync, EGLenum mode)
1794 {
1795 _EGLDisplay *disp = _eglLockDisplay(dpy);
1796 _EGLSync *s = _eglLookupSync(sync, disp);
1797 _EGLDriver *drv;
1798 EGLBoolean ret;
1799
1800 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1801
1802 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1803 assert(disp->Extensions.KHR_reusable_sync);
1804 ret = drv->API.SignalSyncKHR(drv, disp, s, mode);
1805
1806 RETURN_EGL_EVAL(disp, ret);
1807 }
1808
1809
1810 static EGLBoolean
1811 _eglGetSyncAttribCommon(_EGLDisplay *disp, _EGLSync *s, EGLint attribute, EGLAttrib *value)
1812 {
1813 _EGLDriver *drv;
1814 EGLBoolean ret;
1815
1816 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1817 assert(disp->Extensions.KHR_reusable_sync ||
1818 disp->Extensions.KHR_fence_sync);
1819 ret = drv->API.GetSyncAttrib(drv, disp, s, attribute, value);
1820
1821 RETURN_EGL_EVAL(disp, ret);
1822 }
1823
1824 EGLBoolean EGLAPIENTRY
1825 eglGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value)
1826 {
1827 _EGLDisplay *disp = _eglLockDisplay(dpy);
1828 _EGLSync *s = _eglLookupSync(sync, disp);
1829 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1830 return _eglGetSyncAttribCommon(disp, s, attribute, value);
1831 }
1832
1833
1834 static EGLBoolean EGLAPIENTRY
1835 eglGetSyncAttribKHR(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLint *value)
1836 {
1837 _EGLDisplay *disp = _eglLockDisplay(dpy);
1838 _EGLSync *s = _eglLookupSync(sync, disp);
1839 EGLAttrib attrib;
1840 EGLBoolean result;
1841
1842 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1843
1844 if (!value)
1845 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1846
1847 attrib = *value;
1848 result = _eglGetSyncAttribCommon(disp, s, attribute, &attrib);
1849
1850 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
1851 *
1852 * If any error occurs, <*value> is not modified.
1853 */
1854 if (result == EGL_FALSE)
1855 return result;
1856
1857 *value = attrib;
1858 return result;
1859 }
1860
1861
1862 static EGLBoolean EGLAPIENTRY
1863 eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface,
1864 EGLint numRects, const EGLint *rects)
1865 {
1866 _EGLContext *ctx = _eglGetCurrentContext();
1867 _EGLDisplay *disp = _eglLockDisplay(dpy);
1868 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1869 _EGLDriver *drv;
1870 EGLBoolean ret;
1871
1872 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1873
1874 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1875
1876 if (!disp->Extensions.NOK_swap_region)
1877 RETURN_EGL_EVAL(disp, EGL_FALSE);
1878
1879 /* surface must be bound to current context in EGL 1.4 */
1880 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1881 surf != ctx->DrawSurface)
1882 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1883
1884 ret = drv->API.SwapBuffersRegionNOK(drv, disp, surf, numRects, rects);
1885
1886 RETURN_EGL_EVAL(disp, ret);
1887 }
1888
1889
1890 static EGLImage EGLAPIENTRY
1891 eglCreateDRMImageMESA(EGLDisplay dpy, const EGLint *attr_list)
1892 {
1893 _EGLDisplay *disp = _eglLockDisplay(dpy);
1894 _EGLDriver *drv;
1895 _EGLImage *img;
1896 EGLImage ret;
1897
1898 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1899
1900 _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv);
1901 if (!disp->Extensions.MESA_drm_image)
1902 RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR);
1903
1904 img = drv->API.CreateDRMImageMESA(drv, disp, attr_list);
1905 ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR;
1906
1907 RETURN_EGL_EVAL(disp, ret);
1908 }
1909
1910 static EGLBoolean EGLAPIENTRY
1911 eglExportDRMImageMESA(EGLDisplay dpy, EGLImage image,
1912 EGLint *name, EGLint *handle, EGLint *stride)
1913 {
1914 _EGLDisplay *disp = _eglLockDisplay(dpy);
1915 _EGLImage *img = _eglLookupImage(image, disp);
1916 _EGLDriver *drv;
1917 EGLBoolean ret;
1918
1919 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
1920
1921 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1922 assert(disp->Extensions.MESA_drm_image);
1923
1924 if (!img)
1925 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1926
1927 ret = drv->API.ExportDRMImageMESA(drv, disp, img, name, handle, stride);
1928
1929 RETURN_EGL_EVAL(disp, ret);
1930 }
1931
1932
1933 struct wl_display;
1934
1935 static EGLBoolean EGLAPIENTRY
1936 eglBindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
1937 {
1938 _EGLDisplay *disp = _eglLockDisplay(dpy);
1939 _EGLDriver *drv;
1940 EGLBoolean ret;
1941
1942 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1943
1944 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1945 assert(disp->Extensions.WL_bind_wayland_display);
1946
1947 if (!display)
1948 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1949
1950 ret = drv->API.BindWaylandDisplayWL(drv, disp, display);
1951
1952 RETURN_EGL_EVAL(disp, ret);
1953 }
1954
1955 static EGLBoolean EGLAPIENTRY
1956 eglUnbindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
1957 {
1958 _EGLDisplay *disp = _eglLockDisplay(dpy);
1959 _EGLDriver *drv;
1960 EGLBoolean ret;
1961
1962 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1963
1964 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1965 assert(disp->Extensions.WL_bind_wayland_display);
1966
1967 if (!display)
1968 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1969
1970 ret = drv->API.UnbindWaylandDisplayWL(drv, disp, display);
1971
1972 RETURN_EGL_EVAL(disp, ret);
1973 }
1974
1975 static EGLBoolean EGLAPIENTRY
1976 eglQueryWaylandBufferWL(EGLDisplay dpy, struct wl_resource *buffer,
1977 EGLint attribute, EGLint *value)
1978 {
1979 _EGLDisplay *disp = _eglLockDisplay(dpy);
1980 _EGLDriver *drv;
1981 EGLBoolean ret;
1982
1983 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1984
1985 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1986 assert(disp->Extensions.WL_bind_wayland_display);
1987
1988 if (!buffer)
1989 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1990
1991 ret = drv->API.QueryWaylandBufferWL(drv, disp, buffer, attribute, value);
1992
1993 RETURN_EGL_EVAL(disp, ret);
1994 }
1995
1996
1997 static struct wl_buffer * EGLAPIENTRY
1998 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy, EGLImage image)
1999 {
2000 _EGLDisplay *disp = _eglLockDisplay(dpy);
2001 _EGLImage *img;
2002 _EGLDriver *drv;
2003 struct wl_buffer *ret;
2004
2005 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
2006
2007 _EGL_CHECK_DISPLAY(disp, NULL, drv);
2008 assert(disp->Extensions.WL_create_wayland_buffer_from_image);
2009
2010 img = _eglLookupImage(image, disp);
2011
2012 if (!img)
2013 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL);
2014
2015 ret = drv->API.CreateWaylandBufferFromImageWL(drv, disp, img);
2016
2017 RETURN_EGL_EVAL(disp, ret);
2018 }
2019
2020 static EGLBoolean EGLAPIENTRY
2021 eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface,
2022 EGLint x, EGLint y, EGLint width, EGLint height)
2023 {
2024 _EGLDisplay *disp = _eglLockDisplay(dpy);
2025 _EGLSurface *surf = _eglLookupSurface(surface, disp);
2026 _EGLDriver *drv;
2027 EGLBoolean ret;
2028
2029 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
2030
2031 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
2032
2033 if (!disp->Extensions.NV_post_sub_buffer)
2034 RETURN_EGL_EVAL(disp, EGL_FALSE);
2035
2036 ret = drv->API.PostSubBufferNV(drv, disp, surf, x, y, width, height);
2037
2038 RETURN_EGL_EVAL(disp, ret);
2039 }
2040
2041 static EGLBoolean EGLAPIENTRY
2042 eglGetSyncValuesCHROMIUM(EGLDisplay display, EGLSurface surface,
2043 EGLuint64KHR *ust, EGLuint64KHR *msc,
2044 EGLuint64KHR *sbc)
2045 {
2046 _EGLDisplay *disp = _eglLockDisplay(display);
2047 _EGLSurface *surf = _eglLookupSurface(surface, disp);
2048 _EGLDriver *drv;
2049 EGLBoolean ret;
2050
2051 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
2052
2053 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
2054 if (!disp->Extensions.CHROMIUM_sync_control)
2055 RETURN_EGL_EVAL(disp, EGL_FALSE);
2056
2057 if (!ust || !msc || !sbc)
2058 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2059
2060 ret = drv->API.GetSyncValuesCHROMIUM(disp, surf, ust, msc, sbc);
2061
2062 RETURN_EGL_EVAL(disp, ret);
2063 }
2064
2065 static EGLBoolean EGLAPIENTRY
2066 eglExportDMABUFImageQueryMESA(EGLDisplay dpy, EGLImage image,
2067 EGLint *fourcc, EGLint *nplanes,
2068 EGLuint64KHR *modifiers)
2069 {
2070 _EGLDisplay *disp = _eglLockDisplay(dpy);
2071 _EGLImage *img = _eglLookupImage(image, disp);
2072 _EGLDriver *drv;
2073 EGLBoolean ret;
2074
2075 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
2076
2077 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2078 assert(disp->Extensions.MESA_image_dma_buf_export);
2079
2080 if (!img)
2081 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2082
2083 ret = drv->API.ExportDMABUFImageQueryMESA(drv, disp, img, fourcc, nplanes,
2084 modifiers);
2085
2086 RETURN_EGL_EVAL(disp, ret);
2087 }
2088
2089 static EGLBoolean EGLAPIENTRY
2090 eglExportDMABUFImageMESA(EGLDisplay dpy, EGLImage image,
2091 int *fds, EGLint *strides, EGLint *offsets)
2092 {
2093 _EGLDisplay *disp = _eglLockDisplay(dpy);
2094 _EGLImage *img = _eglLookupImage(image, disp);
2095 _EGLDriver *drv;
2096 EGLBoolean ret;
2097
2098 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
2099
2100 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2101 assert(disp->Extensions.MESA_image_dma_buf_export);
2102
2103 if (!img)
2104 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2105
2106 ret = drv->API.ExportDMABUFImageMESA(drv, disp, img, fds, strides, offsets);
2107
2108 RETURN_EGL_EVAL(disp, ret);
2109 }
2110
2111 static EGLint EGLAPIENTRY
2112 eglLabelObjectKHR(EGLDisplay dpy, EGLenum objectType, EGLObjectKHR object,
2113 EGLLabelKHR label)
2114 {
2115 _EGLDisplay *disp = NULL;
2116 _EGLResourceType type;
2117
2118 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC);
2119
2120 if (objectType == EGL_OBJECT_THREAD_KHR) {
2121 _EGLThreadInfo *t = _eglGetCurrentThread();
2122
2123 if (!_eglIsCurrentThreadDummy()) {
2124 t->Label = label;
2125 return EGL_SUCCESS;
2126 }
2127
2128 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_BAD_ALLOC);
2129 }
2130
2131 disp = _eglLockDisplay(dpy);
2132 if (disp == NULL)
2133 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_BAD_DISPLAY);
2134
2135 if (objectType == EGL_OBJECT_DISPLAY_KHR) {
2136 if (dpy != (EGLDisplay) object)
2137 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER);
2138
2139 disp->Label = label;
2140 RETURN_EGL_EVAL(disp, EGL_SUCCESS);
2141 }
2142
2143 switch (objectType) {
2144 case EGL_OBJECT_CONTEXT_KHR:
2145 type = _EGL_RESOURCE_CONTEXT;
2146 break;
2147 case EGL_OBJECT_SURFACE_KHR:
2148 type = _EGL_RESOURCE_SURFACE;
2149 break;
2150 case EGL_OBJECT_IMAGE_KHR:
2151 type = _EGL_RESOURCE_IMAGE;
2152 break;
2153 case EGL_OBJECT_SYNC_KHR:
2154 type = _EGL_RESOURCE_SYNC;
2155 break;
2156 case EGL_OBJECT_STREAM_KHR:
2157 default:
2158 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER);
2159 }
2160
2161 if (_eglCheckResource(object, type, disp)) {
2162 _EGLResource *res = (_EGLResource *) object;
2163
2164 res->Label = label;
2165 RETURN_EGL_EVAL(disp, EGL_SUCCESS);
2166 }
2167
2168 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER);
2169 }
2170
2171 static EGLBoolean
2172 validDebugMessageLevel(EGLAttrib level)
2173 {
2174 return (level >= EGL_DEBUG_MSG_CRITICAL_KHR &&
2175 level <= EGL_DEBUG_MSG_INFO_KHR);
2176 }
2177
2178 static EGLint EGLAPIENTRY
2179 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback,
2180 const EGLAttrib *attrib_list)
2181 {
2182 unsigned int newEnabled;
2183
2184 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC);
2185
2186 mtx_lock(_eglGlobal.Mutex);
2187
2188 newEnabled = _eglGlobal.debugTypesEnabled;
2189 if (attrib_list != NULL) {
2190 int i;
2191
2192 for (i = 0; attrib_list[i] != EGL_NONE; i += 2) {
2193 if (validDebugMessageLevel(attrib_list[i])) {
2194 if (attrib_list[i + 1])
2195 newEnabled |= DebugBitFromType(attrib_list[i]);
2196 else
2197 newEnabled &= ~DebugBitFromType(attrib_list[i]);
2198 continue;
2199 }
2200
2201 // On error, set the last error code, call the current
2202 // debug callback, and return the error code.
2203 mtx_unlock(_eglGlobal.Mutex);
2204 _eglReportError(EGL_BAD_ATTRIBUTE, NULL,
2205 "Invalid attribute 0x%04lx", (unsigned long) attrib_list[i]);
2206 return EGL_BAD_ATTRIBUTE;
2207 }
2208 }
2209
2210 if (callback != NULL) {
2211 _eglGlobal.debugCallback = callback;
2212 _eglGlobal.debugTypesEnabled = newEnabled;
2213 } else {
2214 _eglGlobal.debugCallback = NULL;
2215 _eglGlobal.debugTypesEnabled = _EGL_DEBUG_BIT_CRITICAL | _EGL_DEBUG_BIT_ERROR;
2216 }
2217
2218 mtx_unlock(_eglGlobal.Mutex);
2219 return EGL_SUCCESS;
2220 }
2221
2222 static EGLBoolean EGLAPIENTRY
2223 eglQueryDebugKHR(EGLint attribute, EGLAttrib *value)
2224 {
2225 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC);
2226
2227 mtx_lock(_eglGlobal.Mutex);
2228
2229 do {
2230 if (validDebugMessageLevel(attribute)) {
2231 if (_eglGlobal.debugTypesEnabled & DebugBitFromType(attribute))
2232 *value = EGL_TRUE;
2233 else
2234 *value = EGL_FALSE;
2235 break;
2236 }
2237
2238 if (attribute == EGL_DEBUG_CALLBACK_KHR) {
2239 *value = (EGLAttrib) _eglGlobal.debugCallback;
2240 break;
2241 }
2242
2243 mtx_unlock(_eglGlobal.Mutex);
2244 _eglReportError(EGL_BAD_ATTRIBUTE, NULL,
2245 "Invalid attribute 0x%04lx", (unsigned long) attribute);
2246 return EGL_FALSE;
2247 } while (0);
2248
2249 mtx_unlock(_eglGlobal.Mutex);
2250 return EGL_TRUE;
2251 }
2252
2253 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2254 eglGetProcAddress(const char *procname)
2255 {
2256 static const struct {
2257 const char *name;
2258 _EGLProc function;
2259 } egl_functions[] = {
2260 /* core functions queryable in the presence of
2261 * EGL_KHR_get_all_proc_addresses or EGL 1.5
2262 */
2263 /* alphabetical order */
2264 { "eglBindAPI", (_EGLProc) eglBindAPI },
2265 { "eglBindTexImage", (_EGLProc) eglBindTexImage },
2266 { "eglChooseConfig", (_EGLProc) eglChooseConfig },
2267 { "eglCopyBuffers", (_EGLProc) eglCopyBuffers },
2268 { "eglCreateContext", (_EGLProc) eglCreateContext },
2269 { "eglCreatePbufferFromClientBuffer", (_EGLProc) eglCreatePbufferFromClientBuffer },
2270 { "eglCreatePbufferSurface", (_EGLProc) eglCreatePbufferSurface },
2271 { "eglCreatePixmapSurface", (_EGLProc) eglCreatePixmapSurface },
2272 { "eglCreateWindowSurface", (_EGLProc) eglCreateWindowSurface },
2273 { "eglDestroyContext", (_EGLProc) eglDestroyContext },
2274 { "eglDestroySurface", (_EGLProc) eglDestroySurface },
2275 { "eglGetConfigAttrib", (_EGLProc) eglGetConfigAttrib },
2276 { "eglGetConfigs", (_EGLProc) eglGetConfigs },
2277 { "eglGetCurrentContext", (_EGLProc) eglGetCurrentContext },
2278 { "eglGetCurrentDisplay", (_EGLProc) eglGetCurrentDisplay },
2279 { "eglGetCurrentSurface", (_EGLProc) eglGetCurrentSurface },
2280 { "eglGetDisplay", (_EGLProc) eglGetDisplay },
2281 { "eglGetError", (_EGLProc) eglGetError },
2282 { "eglGetProcAddress", (_EGLProc) eglGetProcAddress },
2283 { "eglInitialize", (_EGLProc) eglInitialize },
2284 { "eglMakeCurrent", (_EGLProc) eglMakeCurrent },
2285 { "eglQueryAPI", (_EGLProc) eglQueryAPI },
2286 { "eglQueryContext", (_EGLProc) eglQueryContext },
2287 { "eglQueryString", (_EGLProc) eglQueryString },
2288 { "eglQuerySurface", (_EGLProc) eglQuerySurface },
2289 { "eglReleaseTexImage", (_EGLProc) eglReleaseTexImage },
2290 { "eglReleaseThread", (_EGLProc) eglReleaseThread },
2291 { "eglSurfaceAttrib", (_EGLProc) eglSurfaceAttrib },
2292 { "eglSwapBuffers", (_EGLProc) eglSwapBuffers },
2293 { "eglSwapInterval", (_EGLProc) eglSwapInterval },
2294 { "eglTerminate", (_EGLProc) eglTerminate },
2295 { "eglWaitClient", (_EGLProc) eglWaitClient },
2296 { "eglWaitGL", (_EGLProc) eglWaitGL },
2297 { "eglWaitNative", (_EGLProc) eglWaitNative },
2298 { "eglCreateSync", (_EGLProc) eglCreateSync },
2299 { "eglDestroySync", (_EGLProc) eglDestroySync },
2300 { "eglClientWaitSync", (_EGLProc) eglClientWaitSync },
2301 { "eglGetSyncAttrib", (_EGLProc) eglGetSyncAttrib },
2302 { "eglWaitSync", (_EGLProc) eglWaitSync },
2303 { "eglCreateImage", (_EGLProc) eglCreateImage },
2304 { "eglDestroyImage", (_EGLProc) eglDestroyImage },
2305 { "eglGetPlatformDisplay", (_EGLProc) eglGetPlatformDisplay },
2306 { "eglCreatePlatformWindowSurface", (_EGLProc) eglCreatePlatformWindowSurface },
2307 { "eglCreatePlatformPixmapSurface", (_EGLProc) eglCreatePlatformPixmapSurface },
2308 { "eglCreateImageKHR", (_EGLProc) eglCreateImageKHR },
2309 { "eglDestroyImageKHR", (_EGLProc) eglDestroyImage },
2310 { "eglCreateSyncKHR", (_EGLProc) eglCreateSyncKHR },
2311 { "eglCreateSync64KHR", (_EGLProc) eglCreateSync64KHR },
2312 { "eglDestroySyncKHR", (_EGLProc) eglDestroySync },
2313 { "eglClientWaitSyncKHR", (_EGLProc) eglClientWaitSync },
2314 { "eglWaitSyncKHR", (_EGLProc) eglWaitSyncKHR },
2315 { "eglSignalSyncKHR", (_EGLProc) eglSignalSyncKHR },
2316 { "eglGetSyncAttribKHR", (_EGLProc) eglGetSyncAttribKHR },
2317 { "eglSwapBuffersRegionNOK", (_EGLProc) eglSwapBuffersRegionNOK },
2318 { "eglCreateDRMImageMESA", (_EGLProc) eglCreateDRMImageMESA },
2319 { "eglExportDRMImageMESA", (_EGLProc) eglExportDRMImageMESA },
2320 { "eglBindWaylandDisplayWL", (_EGLProc) eglBindWaylandDisplayWL },
2321 { "eglUnbindWaylandDisplayWL", (_EGLProc) eglUnbindWaylandDisplayWL },
2322 { "eglQueryWaylandBufferWL", (_EGLProc) eglQueryWaylandBufferWL },
2323 { "eglCreateWaylandBufferFromImageWL", (_EGLProc) eglCreateWaylandBufferFromImageWL },
2324 { "eglPostSubBufferNV", (_EGLProc) eglPostSubBufferNV },
2325 { "eglSwapBuffersWithDamageEXT", (_EGLProc) eglSwapBuffersWithDamageEXT },
2326 { "eglSwapBuffersWithDamageKHR", (_EGLProc) eglSwapBuffersWithDamageKHR },
2327 { "eglGetPlatformDisplayEXT", (_EGLProc) eglGetPlatformDisplayEXT },
2328 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc) eglCreatePlatformWindowSurfaceEXT },
2329 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc) eglCreatePlatformPixmapSurfaceEXT },
2330 { "eglGetSyncValuesCHROMIUM", (_EGLProc) eglGetSyncValuesCHROMIUM },
2331 { "eglExportDMABUFImageQueryMESA", (_EGLProc) eglExportDMABUFImageQueryMESA },
2332 { "eglExportDMABUFImageMESA", (_EGLProc) eglExportDMABUFImageMESA },
2333 { "eglLabelObjectKHR", (_EGLProc) eglLabelObjectKHR },
2334 { "eglDebugMessageControlKHR", (_EGLProc) eglDebugMessageControlKHR },
2335 { "eglQueryDebugKHR", (_EGLProc) eglQueryDebugKHR },
2336 { NULL, NULL }
2337 };
2338 EGLint i;
2339 _EGLProc ret;
2340
2341 if (!procname)
2342 RETURN_EGL_SUCCESS(NULL, NULL);
2343
2344 _EGL_FUNC_START(NULL, EGL_NONE, NULL, NULL);
2345
2346 ret = NULL;
2347 if (strncmp(procname, "egl", 3) == 0) {
2348 for (i = 0; egl_functions[i].name; i++) {
2349 if (strcmp(egl_functions[i].name, procname) == 0) {
2350 ret = egl_functions[i].function;
2351 break;
2352 }
2353 }
2354 }
2355 if (!ret)
2356 ret = _eglGetDriverProc(procname);
2357
2358 RETURN_EGL_SUCCESS(NULL, ret);
2359 }
2360
2361 static int
2362 _eglLockDisplayInterop(EGLDisplay dpy, EGLContext context,
2363 _EGLDisplay **disp, _EGLDriver **drv,
2364 _EGLContext **ctx)
2365 {
2366
2367 *disp = _eglLockDisplay(dpy);
2368 if (!*disp || !(*disp)->Initialized || !(*disp)->Driver) {
2369 if (*disp)
2370 _eglUnlockDisplay(*disp);
2371 return MESA_GLINTEROP_INVALID_DISPLAY;
2372 }
2373
2374 *drv = (*disp)->Driver;
2375
2376 *ctx = _eglLookupContext(context, *disp);
2377 if (!*ctx ||
2378 ((*ctx)->ClientAPI != EGL_OPENGL_API &&
2379 (*ctx)->ClientAPI != EGL_OPENGL_ES_API)) {
2380 _eglUnlockDisplay(*disp);
2381 return MESA_GLINTEROP_INVALID_CONTEXT;
2382 }
2383
2384 return MESA_GLINTEROP_SUCCESS;
2385 }
2386
2387 int
2388 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy, EGLContext context,
2389 struct mesa_glinterop_device_info *out)
2390 {
2391 _EGLDisplay *disp;
2392 _EGLDriver *drv;
2393 _EGLContext *ctx;
2394 int ret;
2395
2396 ret = _eglLockDisplayInterop(dpy, context, &disp, &drv, &ctx);
2397 if (ret != MESA_GLINTEROP_SUCCESS)
2398 return ret;
2399
2400 if (drv->API.GLInteropQueryDeviceInfo)
2401 ret = drv->API.GLInteropQueryDeviceInfo(disp, ctx, out);
2402 else
2403 ret = MESA_GLINTEROP_UNSUPPORTED;
2404
2405 _eglUnlockDisplay(disp);
2406 return ret;
2407 }
2408
2409 int
2410 MesaGLInteropEGLExportObject(EGLDisplay dpy, EGLContext context,
2411 struct mesa_glinterop_export_in *in,
2412 struct mesa_glinterop_export_out *out)
2413 {
2414 _EGLDisplay *disp;
2415 _EGLDriver *drv;
2416 _EGLContext *ctx;
2417 int ret;
2418
2419 ret = _eglLockDisplayInterop(dpy, context, &disp, &drv, &ctx);
2420 if (ret != MESA_GLINTEROP_SUCCESS)
2421 return ret;
2422
2423 if (drv->API.GLInteropExportObject)
2424 ret = drv->API.GLInteropExportObject(disp, ctx, in, out);
2425 else
2426 ret = MESA_GLINTEROP_UNSUPPORTED;
2427
2428 _eglUnlockDisplay(disp);
2429 return ret;
2430 }