egl: move eglQuerySurface() fallback to eglapi.c
[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 #ifdef USE_LIBGLVND
87 #define EGLAPI
88 #undef PUBLIC
89 #define PUBLIC
90 #endif
91
92 #include <stdio.h>
93 #include <stdlib.h>
94 #include <string.h>
95 #include "c99_compat.h"
96 #include "c11/threads.h"
97 #include "util/macros.h"
98
99 #include "eglapi.h"
100 #include "egldefines.h"
101 #include "eglglobals.h"
102 #include "eglcontext.h"
103 #include "egldisplay.h"
104 #include "egltypedefs.h"
105 #include "eglcurrent.h"
106 #include "egldevice.h"
107 #include "egldriver.h"
108 #include "eglsurface.h"
109 #include "eglconfig.h"
110 #include "eglimage.h"
111 #include "eglsync.h"
112
113 #include "GL/mesa_glinterop.h"
114
115 /**
116 * Macros to help return an API entrypoint.
117 *
118 * These macros will unlock the display and record the error code.
119 */
120 #define RETURN_EGL_ERROR(disp, err, ret) \
121 do { \
122 if (disp) \
123 _eglUnlockDisplay(disp); \
124 /* EGL error codes are non-zero */ \
125 if (err) \
126 _eglError(err, __func__); \
127 return ret; \
128 } while (0)
129
130 #define RETURN_EGL_SUCCESS(disp, ret) \
131 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
132
133 /* record EGL_SUCCESS only when ret evaluates to true */
134 #define RETURN_EGL_EVAL(disp, ret) \
135 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
136
137
138 /*
139 * A bunch of macros and checks to simplify error checking.
140 */
141
142 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
143 do { \
144 drv = _eglCheckDisplay(disp, __func__); \
145 if (!drv) \
146 RETURN_EGL_ERROR(disp, 0, ret); \
147 } while (0)
148
149 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
150 do { \
151 drv = _eglCheck ## type(disp, obj, __func__); \
152 if (!drv) \
153 RETURN_EGL_ERROR(disp, 0, ret); \
154 } while (0)
155
156 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
157 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
158
159 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
160 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
161
162 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
163 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
164
165 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
166 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
167
168
169 struct _egl_entrypoint {
170 const char *name;
171 _EGLProc function;
172 };
173
174
175 static inline _EGLDriver *
176 _eglCheckDisplay(_EGLDisplay *disp, const char *msg)
177 {
178 if (!disp) {
179 _eglError(EGL_BAD_DISPLAY, msg);
180 return NULL;
181 }
182 if (!disp->Initialized) {
183 _eglError(EGL_NOT_INITIALIZED, msg);
184 return NULL;
185 }
186 return disp->Driver;
187 }
188
189
190 static inline _EGLDriver *
191 _eglCheckSurface(_EGLDisplay *disp, _EGLSurface *surf, const char *msg)
192 {
193 _EGLDriver *drv = _eglCheckDisplay(disp, msg);
194 if (!drv)
195 return NULL;
196 if (!surf) {
197 _eglError(EGL_BAD_SURFACE, msg);
198 return NULL;
199 }
200 return drv;
201 }
202
203
204 static inline _EGLDriver *
205 _eglCheckContext(_EGLDisplay *disp, _EGLContext *context, const char *msg)
206 {
207 _EGLDriver *drv = _eglCheckDisplay(disp, msg);
208 if (!drv)
209 return NULL;
210 if (!context) {
211 _eglError(EGL_BAD_CONTEXT, msg);
212 return NULL;
213 }
214 return drv;
215 }
216
217
218 static inline _EGLDriver *
219 _eglCheckConfig(_EGLDisplay *disp, _EGLConfig *conf, const char *msg)
220 {
221 _EGLDriver *drv = _eglCheckDisplay(disp, msg);
222 if (!drv)
223 return NULL;
224 if (!conf) {
225 _eglError(EGL_BAD_CONFIG, msg);
226 return NULL;
227 }
228 return drv;
229 }
230
231
232 static inline _EGLDriver *
233 _eglCheckSync(_EGLDisplay *disp, _EGLSync *s, const char *msg)
234 {
235 _EGLDriver *drv = _eglCheckDisplay(disp, msg);
236 if (!drv)
237 return NULL;
238 if (!s) {
239 _eglError(EGL_BAD_PARAMETER, msg);
240 return NULL;
241 }
242 return drv;
243 }
244
245
246 /**
247 * Lookup and lock a display.
248 */
249 static inline _EGLDisplay *
250 _eglLockDisplay(EGLDisplay dpy)
251 {
252 _EGLDisplay *disp = _eglLookupDisplay(dpy);
253 if (disp)
254 mtx_lock(&disp->Mutex);
255 return disp;
256 }
257
258
259 /**
260 * Unlock a display.
261 */
262 static inline void
263 _eglUnlockDisplay(_EGLDisplay *disp)
264 {
265 mtx_unlock(&disp->Mutex);
266 }
267
268 static EGLBoolean
269 _eglSetFuncName(const char *funcName, _EGLDisplay *disp, EGLenum objectType, _EGLResource *object)
270 {
271 _EGLThreadInfo *thr = _eglGetCurrentThread();
272 if (!_eglIsCurrentThreadDummy()) {
273 thr->CurrentFuncName = funcName;
274 thr->CurrentObjectLabel = NULL;
275
276 if (objectType == EGL_OBJECT_THREAD_KHR)
277 thr->CurrentObjectLabel = thr->Label;
278 else if (objectType == EGL_OBJECT_DISPLAY_KHR && disp)
279 thr->CurrentObjectLabel = disp->Label;
280 else if (object)
281 thr->CurrentObjectLabel = object->Label;
282
283 return EGL_TRUE;
284 }
285
286 _eglDebugReport(EGL_BAD_ALLOC, funcName, EGL_DEBUG_MSG_CRITICAL_KHR, NULL);
287 return EGL_FALSE;
288 }
289
290 #define _EGL_FUNC_START(disp, objectType, object, ret) \
291 do { \
292 if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \
293 if (disp) \
294 _eglUnlockDisplay(disp); \
295 return ret; \
296 } \
297 } while(0)
298
299 /**
300 * Convert an attribute list from EGLint[] to EGLAttrib[].
301 *
302 * Return an EGL error code. The output parameter out_attrib_list is modified
303 * only on success.
304 */
305 static EGLint
306 _eglConvertIntsToAttribs(const EGLint *int_list, EGLAttrib **out_attrib_list)
307 {
308 size_t len = 0;
309 EGLAttrib *attrib_list;
310
311 if (int_list) {
312 while (int_list[2*len] != EGL_NONE)
313 ++len;
314 }
315
316 if (len == 0) {
317 *out_attrib_list = NULL;
318 return EGL_SUCCESS;
319 }
320
321 if (2*len + 1 > SIZE_MAX / sizeof(EGLAttrib))
322 return EGL_BAD_ALLOC;
323
324 attrib_list = malloc((2*len + 1) * sizeof(EGLAttrib));
325 if (!attrib_list)
326 return EGL_BAD_ALLOC;
327
328 for (size_t i = 0; i < len; ++i) {
329 attrib_list[2*i + 0] = int_list[2*i + 0];
330 attrib_list[2*i + 1] = int_list[2*i + 1];
331 }
332
333 attrib_list[2*len] = EGL_NONE;
334
335 *out_attrib_list = attrib_list;
336 return EGL_SUCCESS;
337 }
338
339
340 static EGLint *
341 _eglConvertAttribsToInt(const EGLAttrib *attr_list)
342 {
343 size_t size = _eglNumAttribs(attr_list);
344 EGLint *int_attribs = NULL;
345
346 /* Convert attributes from EGLAttrib[] to EGLint[] */
347 if (size) {
348 int_attribs = calloc(size, sizeof(int_attribs[0]));
349 if (!int_attribs)
350 return NULL;
351
352 for (size_t i = 0; i < size; i++)
353 int_attribs[i] = attr_list[i];
354 }
355 return int_attribs;
356 }
357
358
359 /**
360 * This is typically the first EGL function that an application calls.
361 * It associates a private _EGLDisplay object to the native display.
362 */
363 EGLDisplay EGLAPIENTRY
364 eglGetDisplay(EGLNativeDisplayType nativeDisplay)
365 {
366 _EGLPlatformType plat;
367 _EGLDisplay *disp;
368 void *native_display_ptr;
369
370 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY);
371
372 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay));
373 native_display_ptr = (void*) nativeDisplay;
374
375 plat = _eglGetNativePlatform(native_display_ptr);
376 disp = _eglFindDisplay(plat, native_display_ptr, NULL);
377 return _eglGetDisplayHandle(disp);
378 }
379
380 static EGLDisplay
381 _eglGetPlatformDisplayCommon(EGLenum platform, void *native_display,
382 const EGLAttrib *attrib_list)
383 {
384 _EGLDisplay *disp;
385
386 switch (platform) {
387 #ifdef HAVE_X11_PLATFORM
388 case EGL_PLATFORM_X11_EXT:
389 disp = _eglGetX11Display((Display*) native_display, attrib_list);
390 break;
391 #endif
392 #ifdef HAVE_DRM_PLATFORM
393 case EGL_PLATFORM_GBM_MESA:
394 disp = _eglGetGbmDisplay((struct gbm_device*) native_display,
395 attrib_list);
396 break;
397 #endif
398 #ifdef HAVE_WAYLAND_PLATFORM
399 case EGL_PLATFORM_WAYLAND_EXT:
400 disp = _eglGetWaylandDisplay((struct wl_display*) native_display,
401 attrib_list);
402 break;
403 #endif
404 #ifdef HAVE_SURFACELESS_PLATFORM
405 case EGL_PLATFORM_SURFACELESS_MESA:
406 disp = _eglGetSurfacelessDisplay(native_display, attrib_list);
407 break;
408 #endif
409 case EGL_PLATFORM_DEVICE_EXT:
410 disp = _eglGetDeviceDisplay(native_display, attrib_list);
411 break;
412 default:
413 RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, NULL);
414 }
415
416 return _eglGetDisplayHandle(disp);
417 }
418
419 static EGLDisplay EGLAPIENTRY
420 eglGetPlatformDisplayEXT(EGLenum platform, void *native_display,
421 const EGLint *int_attribs)
422 {
423 EGLAttrib *attrib_list;
424 EGLDisplay disp;
425
426 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY);
427
428 if (_eglConvertIntsToAttribs(int_attribs, &attrib_list) != EGL_SUCCESS)
429 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, NULL);
430
431 disp = _eglGetPlatformDisplayCommon(platform, native_display, attrib_list);
432 free(attrib_list);
433 return disp;
434 }
435
436 EGLDisplay EGLAPIENTRY
437 eglGetPlatformDisplay(EGLenum platform, void *native_display,
438 const EGLAttrib *attrib_list)
439 {
440 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY);
441 return _eglGetPlatformDisplayCommon(platform, native_display, attrib_list);
442 }
443
444 /**
445 * Copy the extension into the string and update the string pointer.
446 */
447 static EGLint
448 _eglAppendExtension(char **str, const char *ext)
449 {
450 char *s = *str;
451 size_t len = strlen(ext);
452
453 if (s) {
454 memcpy(s, ext, len);
455 s[len++] = ' ';
456 s[len] = '\0';
457
458 *str += len;
459 }
460 else {
461 len++;
462 }
463
464 return (EGLint) len;
465 }
466
467 /**
468 * Examine the individual extension enable/disable flags and recompute
469 * the driver's Extensions string.
470 */
471 static void
472 _eglCreateExtensionsString(_EGLDisplay *disp)
473 {
474 #define _EGL_CHECK_EXTENSION(ext) \
475 do { \
476 if (disp->Extensions.ext) { \
477 _eglAppendExtension(&exts, "EGL_" #ext); \
478 assert(exts <= disp->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
479 } \
480 } while (0)
481
482 char *exts = disp->ExtensionsString;
483
484 /* Please keep these sorted alphabetically. */
485 _EGL_CHECK_EXTENSION(ANDROID_blob_cache);
486 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target);
487 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer);
488 _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync);
489 _EGL_CHECK_EXTENSION(ANDROID_recordable);
490
491 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control);
492
493 _EGL_CHECK_EXTENSION(EXT_buffer_age);
494 _EGL_CHECK_EXTENSION(EXT_create_context_robustness);
495 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import);
496 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers);
497 _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata);
498 _EGL_CHECK_EXTENSION(EXT_surface_SMPTE2086_metadata);
499 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage);
500
501 _EGL_CHECK_EXTENSION(IMG_context_priority);
502
503 _EGL_CHECK_EXTENSION(KHR_cl_event2);
504 _EGL_CHECK_EXTENSION(KHR_config_attribs);
505 _EGL_CHECK_EXTENSION(KHR_context_flush_control);
506 _EGL_CHECK_EXTENSION(KHR_create_context);
507 _EGL_CHECK_EXTENSION(KHR_create_context_no_error);
508 _EGL_CHECK_EXTENSION(KHR_fence_sync);
509 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses);
510 _EGL_CHECK_EXTENSION(KHR_gl_colorspace);
511 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image);
512 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image);
513 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image);
514 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image);
515 if (disp->Extensions.KHR_image_base && disp->Extensions.KHR_image_pixmap)
516 disp->Extensions.KHR_image = EGL_TRUE;
517 _EGL_CHECK_EXTENSION(KHR_image);
518 _EGL_CHECK_EXTENSION(KHR_image_base);
519 _EGL_CHECK_EXTENSION(KHR_image_pixmap);
520 _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer);
521 _EGL_CHECK_EXTENSION(KHR_no_config_context);
522 _EGL_CHECK_EXTENSION(KHR_partial_update);
523 _EGL_CHECK_EXTENSION(KHR_reusable_sync);
524 _EGL_CHECK_EXTENSION(KHR_surfaceless_context);
525 if (disp->Extensions.EXT_swap_buffers_with_damage)
526 _eglAppendExtension(&exts, "EGL_KHR_swap_buffers_with_damage");
527 _EGL_CHECK_EXTENSION(EXT_pixel_format_float);
528 _EGL_CHECK_EXTENSION(KHR_wait_sync);
529
530 if (disp->Extensions.KHR_no_config_context)
531 _eglAppendExtension(&exts, "EGL_MESA_configless_context");
532 _EGL_CHECK_EXTENSION(MESA_drm_image);
533 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export);
534 _EGL_CHECK_EXTENSION(MESA_query_driver);
535
536 _EGL_CHECK_EXTENSION(NOK_swap_region);
537 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap);
538
539 _EGL_CHECK_EXTENSION(NV_post_sub_buffer);
540
541 _EGL_CHECK_EXTENSION(WL_bind_wayland_display);
542 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image);
543
544 #undef _EGL_CHECK_EXTENSION
545 }
546
547 static void
548 _eglCreateAPIsString(_EGLDisplay *disp)
549 {
550 #define addstr(str) \
551 { \
552 const size_t old_len = strlen(disp->ClientAPIsString); \
553 const size_t add_len = sizeof(str); \
554 const size_t max_len = sizeof(disp->ClientAPIsString) - 1; \
555 if (old_len + add_len <= max_len) \
556 strcat(disp->ClientAPIsString, str " "); \
557 else \
558 assert(!"disp->ClientAPIsString is not large enough"); \
559 }
560
561 if (disp->ClientAPIs & EGL_OPENGL_BIT)
562 addstr("OpenGL");
563
564 if (disp->ClientAPIs & EGL_OPENGL_ES_BIT ||
565 disp->ClientAPIs & EGL_OPENGL_ES2_BIT ||
566 disp->ClientAPIs & EGL_OPENGL_ES3_BIT_KHR) {
567 addstr("OpenGL_ES");
568 }
569
570 if (disp->ClientAPIs & EGL_OPENVG_BIT)
571 addstr("OpenVG");
572
573 #undef addstr
574 }
575
576 static void
577 _eglComputeVersion(_EGLDisplay *disp)
578 {
579 disp->Version = 14;
580
581 if (disp->Extensions.KHR_fence_sync &&
582 disp->Extensions.KHR_cl_event2 &&
583 disp->Extensions.KHR_wait_sync &&
584 disp->Extensions.KHR_image_base &&
585 disp->Extensions.KHR_gl_texture_2D_image &&
586 disp->Extensions.KHR_gl_texture_3D_image &&
587 disp->Extensions.KHR_gl_texture_cubemap_image &&
588 disp->Extensions.KHR_gl_renderbuffer_image &&
589 disp->Extensions.KHR_create_context &&
590 disp->Extensions.EXT_create_context_robustness &&
591 disp->Extensions.KHR_get_all_proc_addresses &&
592 disp->Extensions.KHR_gl_colorspace &&
593 disp->Extensions.KHR_surfaceless_context)
594 disp->Version = 15;
595 }
596
597 /**
598 * This is typically the second EGL function that an application calls.
599 * Here we load/initialize the actual hardware driver.
600 */
601 EGLBoolean EGLAPIENTRY
602 eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
603 {
604 _EGLDisplay *disp = _eglLockDisplay(dpy);
605
606 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
607
608 if (!disp)
609 RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE);
610
611 if (!disp->Initialized) {
612 if (!_eglMatchDriver(disp))
613 RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE);
614
615 /* limit to APIs supported by core */
616 disp->ClientAPIs &= _EGL_API_ALL_BITS;
617
618 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
619 * classifies it as an EGL display extension, though conceptually it's an
620 * EGL client extension.
621 *
622 * From the EGL_KHR_get_all_proc_addresses spec:
623 *
624 * The EGL implementation must expose the name
625 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
626 * EGL_KHR_get_all_proc_addresses and supports
627 * EGL_EXT_client_extensions.
628 *
629 * Mesa unconditionally exposes both client extensions mentioned above,
630 * so the spec requires that each EGLDisplay unconditionally expose
631 * EGL_KHR_get_all_proc_addresses also.
632 */
633 disp->Extensions.KHR_get_all_proc_addresses = EGL_TRUE;
634
635 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
636 * programs. It is driver agnostic and handled in the main EGL code.
637 */
638 disp->Extensions.KHR_config_attribs = EGL_TRUE;
639
640 _eglComputeVersion(disp);
641 _eglCreateExtensionsString(disp);
642 _eglCreateAPIsString(disp);
643 snprintf(disp->VersionString, sizeof(disp->VersionString),
644 "%d.%d", disp->Version / 10, disp->Version % 10);
645 }
646
647 /* Update applications version of major and minor if not NULL */
648 if ((major != NULL) && (minor != NULL)) {
649 *major = disp->Version / 10;
650 *minor = disp->Version % 10;
651 }
652
653 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
654 }
655
656
657 EGLBoolean EGLAPIENTRY
658 eglTerminate(EGLDisplay dpy)
659 {
660 _EGLDisplay *disp = _eglLockDisplay(dpy);
661
662 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
663
664 if (!disp)
665 RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE);
666
667 if (disp->Initialized) {
668 _EGLDriver *drv = disp->Driver;
669
670 drv->API.Terminate(drv, disp);
671 /* do not reset disp->Driver */
672 disp->ClientAPIsString[0] = 0;
673 disp->Initialized = EGL_FALSE;
674 }
675
676 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
677 }
678
679
680 const char * EGLAPIENTRY
681 eglQueryString(EGLDisplay dpy, EGLint name)
682 {
683 _EGLDisplay *disp;
684 _EGLDriver *drv;
685
686 if (dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS) {
687 const char *ret = _eglGetClientExtensionString();
688 if (ret != NULL)
689 RETURN_EGL_SUCCESS(NULL, ret);
690 else
691 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, NULL);
692 }
693
694 disp = _eglLockDisplay(dpy);
695 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, NULL);
696 _EGL_CHECK_DISPLAY(disp, NULL, drv);
697
698 switch (name) {
699 case EGL_VENDOR:
700 RETURN_EGL_SUCCESS(disp, _EGL_VENDOR_STRING);
701 case EGL_VERSION:
702 RETURN_EGL_SUCCESS(disp, disp->VersionString);
703 case EGL_EXTENSIONS:
704 RETURN_EGL_SUCCESS(disp, disp->ExtensionsString);
705 case EGL_CLIENT_APIS:
706 RETURN_EGL_SUCCESS(disp, disp->ClientAPIsString);
707 default:
708 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL);
709 }
710 }
711
712
713 EGLBoolean EGLAPIENTRY
714 eglGetConfigs(EGLDisplay dpy, EGLConfig *configs,
715 EGLint config_size, EGLint *num_config)
716 {
717 _EGLDisplay *disp = _eglLockDisplay(dpy);
718 _EGLDriver *drv;
719 EGLBoolean ret;
720
721 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
722
723 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
724
725 if (!num_config)
726 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
727
728 if (drv->API.GetConfigs)
729 ret = drv->API.GetConfigs(drv, disp, configs, config_size, num_config);
730 else
731 ret = _eglGetConfigs(drv, disp, configs, config_size, num_config);
732
733 RETURN_EGL_EVAL(disp, ret);
734 }
735
736
737 EGLBoolean EGLAPIENTRY
738 eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs,
739 EGLint config_size, EGLint *num_config)
740 {
741 _EGLDisplay *disp = _eglLockDisplay(dpy);
742 _EGLDriver *drv;
743 EGLBoolean ret;
744
745 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
746
747 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
748
749 if (!num_config)
750 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
751
752 if (drv->API.ChooseConfig)
753 ret = drv->API.ChooseConfig(drv, disp, attrib_list, configs,
754 config_size, num_config);
755 else
756 ret = _eglChooseConfig(drv, disp, attrib_list, configs,
757 config_size, num_config);
758
759 RETURN_EGL_EVAL(disp, ret);
760 }
761
762
763 EGLBoolean EGLAPIENTRY
764 eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
765 EGLint attribute, EGLint *value)
766 {
767 _EGLDisplay *disp = _eglLockDisplay(dpy);
768 _EGLConfig *conf = _eglLookupConfig(config, disp);
769 _EGLDriver *drv;
770 EGLBoolean ret;
771
772 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
773
774 _EGL_CHECK_CONFIG(disp, conf, EGL_FALSE, drv);
775
776 if (drv->API.GetConfigAttrib)
777 ret = drv->API.GetConfigAttrib(drv, disp, conf, attribute, value);
778 else
779 ret = _eglGetConfigAttrib(drv, disp, conf, attribute, value);
780
781 RETURN_EGL_EVAL(disp, ret);
782 }
783
784
785 EGLContext EGLAPIENTRY
786 eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list,
787 const EGLint *attrib_list)
788 {
789 _EGLDisplay *disp = _eglLockDisplay(dpy);
790 _EGLConfig *conf = _eglLookupConfig(config, disp);
791 _EGLContext *share = _eglLookupContext(share_list, disp);
792 _EGLDriver *drv;
793 _EGLContext *context;
794 EGLContext ret;
795
796 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_CONTEXT);
797
798 _EGL_CHECK_DISPLAY(disp, EGL_NO_CONTEXT, drv);
799
800 if (config != EGL_NO_CONFIG_KHR)
801 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_CONTEXT, drv);
802 else if (!disp->Extensions.KHR_no_config_context)
803 RETURN_EGL_ERROR(disp, EGL_BAD_CONFIG, EGL_NO_CONTEXT);
804
805 if (!share && share_list != EGL_NO_CONTEXT)
806 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_CONTEXT);
807
808 context = drv->API.CreateContext(drv, disp, conf, share, attrib_list);
809 ret = (context) ? _eglLinkContext(context) : EGL_NO_CONTEXT;
810
811 RETURN_EGL_EVAL(disp, ret);
812 }
813
814
815 EGLBoolean EGLAPIENTRY
816 eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
817 {
818 _EGLDisplay *disp = _eglLockDisplay(dpy);
819 _EGLContext *context = _eglLookupContext(ctx, disp);
820 _EGLDriver *drv;
821 EGLBoolean ret;
822
823 _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE);
824
825 _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv);
826 _eglUnlinkContext(context);
827 ret = drv->API.DestroyContext(drv, disp, context);
828
829 RETURN_EGL_EVAL(disp, ret);
830 }
831
832
833 EGLBoolean EGLAPIENTRY
834 eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read,
835 EGLContext ctx)
836 {
837 _EGLDisplay *disp = _eglLockDisplay(dpy);
838 _EGLContext *context = _eglLookupContext(ctx, disp);
839 _EGLSurface *draw_surf = _eglLookupSurface(draw, disp);
840 _EGLSurface *read_surf = _eglLookupSurface(read, disp);
841 _EGLDriver *drv;
842 EGLBoolean ret;
843
844 _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE);
845
846 if (!disp)
847 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE);
848 drv = disp->Driver;
849
850 /* display is allowed to be uninitialized under certain condition */
851 if (!disp->Initialized) {
852 if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE ||
853 ctx != EGL_NO_CONTEXT)
854 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE);
855 }
856 if (!drv)
857 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
858
859 if (!context && ctx != EGL_NO_CONTEXT)
860 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE);
861 if (!draw_surf || !read_surf) {
862 /* From the EGL 1.4 (20130211) spec:
863 *
864 * To release the current context without assigning a new one, set ctx
865 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
866 */
867 if (!disp->Extensions.KHR_surfaceless_context && ctx != EGL_NO_CONTEXT)
868 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
869
870 if ((!draw_surf && draw != EGL_NO_SURFACE) ||
871 (!read_surf && read != EGL_NO_SURFACE))
872 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
873 if (draw_surf || read_surf)
874 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
875 }
876
877 /* If a native window underlying either draw or read is no longer valid,
878 * an EGL_BAD_NATIVE_WINDOW error is generated.
879 */
880 if (draw_surf && draw_surf->Lost)
881 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_FALSE);
882 if (read_surf && read_surf->Lost)
883 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_FALSE);
884
885 ret = drv->API.MakeCurrent(drv, disp, draw_surf, read_surf, context);
886
887 RETURN_EGL_EVAL(disp, ret);
888 }
889
890
891 EGLBoolean EGLAPIENTRY
892 eglQueryContext(EGLDisplay dpy, EGLContext ctx,
893 EGLint attribute, EGLint *value)
894 {
895 _EGLDisplay *disp = _eglLockDisplay(dpy);
896 _EGLContext *context = _eglLookupContext(ctx, disp);
897 _EGLDriver *drv;
898 EGLBoolean ret;
899
900 _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE);
901
902 _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv);
903
904 if (drv->API.QueryContext)
905 ret = drv->API.QueryContext(drv, disp, context, attribute, value);
906 else
907 ret = _eglQueryContext(drv, disp, context, attribute, value);
908
909 RETURN_EGL_EVAL(disp, ret);
910 }
911
912
913 /* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says
914 * that if native_surface was already used to create a window or pixmap, we
915 * can't create a new one. This is what this function checks for.
916 */
917 static bool
918 _eglNativeSurfaceAlreadyUsed(_EGLDisplay *disp, void *native_surface)
919 {
920 _EGLResource *list;
921
922 list = disp->ResourceLists[_EGL_RESOURCE_SURFACE];
923 while (list) {
924 _EGLSurface *surf = (_EGLSurface *) list;
925
926 list = list->Next;
927
928 if (surf->Type == EGL_PBUFFER_BIT)
929 continue;
930
931 if (surf->NativeSurface == native_surface)
932 return true;
933 }
934
935 return false;
936 }
937
938
939 static EGLSurface
940 _eglCreateWindowSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
941 void *native_window, const EGLint *attrib_list)
942 {
943 _EGLConfig *conf = _eglLookupConfig(config, disp);
944 _EGLDriver *drv;
945 _EGLSurface *surf;
946 EGLSurface ret;
947
948
949 if (native_window == NULL)
950 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
951
952 if (disp && (disp->Platform == _EGL_PLATFORM_SURFACELESS ||
953 disp->Platform == _EGL_PLATFORM_DEVICE)) {
954 /* From the EGL_MESA_platform_surfaceless spec (v1):
955 *
956 * eglCreatePlatformWindowSurface fails when called with a <display>
957 * that belongs to the surfaceless platform. It returns
958 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
959 * justification for this unconditional failure is that the
960 * surfaceless platform has no native windows, and therefore the
961 * <native_window> parameter is always invalid.
962 *
963 * This check must occur before checking the EGLConfig, which emits
964 * EGL_BAD_CONFIG.
965 */
966 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
967 }
968
969 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
970
971 if ((conf->SurfaceType & EGL_WINDOW_BIT) == 0)
972 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE);
973
974 if (_eglNativeSurfaceAlreadyUsed(disp, native_window))
975 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE);
976
977 surf = drv->API.CreateWindowSurface(drv, disp, conf, native_window,
978 attrib_list);
979 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
980
981 RETURN_EGL_EVAL(disp, ret);
982 }
983
984
985 EGLSurface EGLAPIENTRY
986 eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
987 EGLNativeWindowType window, const EGLint *attrib_list)
988 {
989 _EGLDisplay *disp = _eglLockDisplay(dpy);
990
991 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
992 STATIC_ASSERT(sizeof(void*) == sizeof(window));
993 return _eglCreateWindowSurfaceCommon(disp, config, (void*) window,
994 attrib_list);
995 }
996
997 static void *
998 _fixupNativeWindow(_EGLDisplay *disp, void *native_window)
999 {
1000 #ifdef HAVE_X11_PLATFORM
1001 if (disp && disp->Platform == _EGL_PLATFORM_X11 && native_window != NULL) {
1002 /* The `native_window` parameter for the X11 platform differs between
1003 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1004 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
1005 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
1006 * `Window*`. Convert `Window*` to `Window` because that's what
1007 * dri2_x11_create_window_surface() expects.
1008 */
1009 return (void *)(* (Window*) native_window);
1010 }
1011 #endif
1012 return native_window;
1013 }
1014
1015 static EGLSurface EGLAPIENTRY
1016 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config,
1017 void *native_window,
1018 const EGLint *attrib_list)
1019 {
1020 _EGLDisplay *disp = _eglLockDisplay(dpy);
1021
1022 native_window = _fixupNativeWindow(disp, native_window);
1023
1024 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1025 return _eglCreateWindowSurfaceCommon(disp, config, native_window,
1026 attrib_list);
1027 }
1028
1029
1030 EGLSurface EGLAPIENTRY
1031 eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config,
1032 void *native_window,
1033 const EGLAttrib *attrib_list)
1034 {
1035 _EGLDisplay *disp = _eglLockDisplay(dpy);
1036 EGLSurface surface;
1037 EGLint *int_attribs;
1038
1039 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1040
1041 int_attribs = _eglConvertAttribsToInt(attrib_list);
1042 if (attrib_list && !int_attribs)
1043 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE);
1044
1045 native_window = _fixupNativeWindow(disp, native_window);
1046 surface = _eglCreateWindowSurfaceCommon(disp, config, native_window,
1047 int_attribs);
1048 free(int_attribs);
1049 return surface;
1050 }
1051
1052 static void *
1053 _fixupNativePixmap(_EGLDisplay *disp, void *native_pixmap)
1054 {
1055 #ifdef HAVE_X11_PLATFORM
1056 /* The `native_pixmap` parameter for the X11 platform differs between
1057 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1058 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1059 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1060 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1061 * dri2_x11_create_pixmap_surface() expects.
1062 */
1063 if (disp && disp->Platform == _EGL_PLATFORM_X11 && native_pixmap != NULL)
1064 return (void *)(* (Pixmap*) native_pixmap);
1065 #endif
1066 return native_pixmap;
1067 }
1068
1069 static EGLSurface
1070 _eglCreatePixmapSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
1071 void *native_pixmap, const EGLint *attrib_list)
1072 {
1073 _EGLConfig *conf = _eglLookupConfig(config, disp);
1074 _EGLDriver *drv;
1075 _EGLSurface *surf;
1076 EGLSurface ret;
1077
1078 if (disp && (disp->Platform == _EGL_PLATFORM_SURFACELESS ||
1079 disp->Platform == _EGL_PLATFORM_DEVICE)) {
1080 /* From the EGL_MESA_platform_surfaceless spec (v1):
1081 *
1082 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1083 * also fails when called with a <display> that belongs to the
1084 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1085 * EGL_BAD_NATIVE_PIXMAP.
1086 *
1087 * This check must occur before checking the EGLConfig, which emits
1088 * EGL_BAD_CONFIG.
1089 */
1090 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE);
1091 }
1092
1093 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
1094
1095 if ((conf->SurfaceType & EGL_PIXMAP_BIT) == 0)
1096 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE);
1097
1098 if (native_pixmap == NULL)
1099 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE);
1100
1101 if (_eglNativeSurfaceAlreadyUsed(disp, native_pixmap))
1102 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE);
1103
1104 surf = drv->API.CreatePixmapSurface(drv, disp, conf, native_pixmap,
1105 attrib_list);
1106 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
1107
1108 RETURN_EGL_EVAL(disp, ret);
1109 }
1110
1111
1112 EGLSurface EGLAPIENTRY
1113 eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config,
1114 EGLNativePixmapType pixmap, const EGLint *attrib_list)
1115 {
1116 _EGLDisplay *disp = _eglLockDisplay(dpy);
1117
1118 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1119 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap));
1120 return _eglCreatePixmapSurfaceCommon(disp, config, (void*) pixmap,
1121 attrib_list);
1122 }
1123
1124 static EGLSurface EGLAPIENTRY
1125 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config,
1126 void *native_pixmap,
1127 const EGLint *attrib_list)
1128 {
1129 _EGLDisplay *disp = _eglLockDisplay(dpy);
1130
1131 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1132 native_pixmap = _fixupNativePixmap(disp, native_pixmap);
1133 return _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap,
1134 attrib_list);
1135 }
1136
1137
1138 EGLSurface EGLAPIENTRY
1139 eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config,
1140 void *native_pixmap,
1141 const EGLAttrib *attrib_list)
1142 {
1143 _EGLDisplay *disp = _eglLockDisplay(dpy);
1144 EGLSurface surface;
1145 EGLint *int_attribs;
1146
1147 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1148
1149 int_attribs = _eglConvertAttribsToInt(attrib_list);
1150 if (attrib_list && !int_attribs)
1151 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE);
1152
1153 native_pixmap = _fixupNativePixmap(disp, native_pixmap);
1154 surface = _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap,
1155 int_attribs);
1156 free(int_attribs);
1157 return surface;
1158 }
1159
1160
1161 EGLSurface EGLAPIENTRY
1162 eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,
1163 const EGLint *attrib_list)
1164 {
1165 _EGLDisplay *disp = _eglLockDisplay(dpy);
1166 _EGLConfig *conf = _eglLookupConfig(config, disp);
1167 _EGLDriver *drv;
1168 _EGLSurface *surf;
1169 EGLSurface ret;
1170
1171 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1172 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
1173
1174 if ((conf->SurfaceType & EGL_PBUFFER_BIT) == 0)
1175 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE);
1176
1177 surf = drv->API.CreatePbufferSurface(drv, disp, conf, attrib_list);
1178 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
1179
1180 RETURN_EGL_EVAL(disp, ret);
1181 }
1182
1183
1184 EGLBoolean EGLAPIENTRY
1185 eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
1186 {
1187 _EGLDisplay *disp = _eglLockDisplay(dpy);
1188 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1189 _EGLDriver *drv;
1190 EGLBoolean ret;
1191
1192 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1193 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1194 _eglUnlinkSurface(surf);
1195 ret = drv->API.DestroySurface(drv, disp, surf);
1196
1197 RETURN_EGL_EVAL(disp, ret);
1198 }
1199
1200 EGLBoolean EGLAPIENTRY
1201 eglQuerySurface(EGLDisplay dpy, EGLSurface surface,
1202 EGLint attribute, EGLint *value)
1203 {
1204 _EGLDisplay *disp = _eglLockDisplay(dpy);
1205 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1206 _EGLDriver *drv;
1207 EGLBoolean ret;
1208
1209 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1210 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1211
1212 if (drv->API.QuerySurface)
1213 ret = drv->API.QuerySurface(drv, disp, surf, attribute, value);
1214 else
1215 ret = _eglQuerySurface(drv, disp, surf, attribute, value);
1216
1217 RETURN_EGL_EVAL(disp, ret);
1218 }
1219
1220 EGLBoolean EGLAPIENTRY
1221 eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface,
1222 EGLint attribute, EGLint value)
1223 {
1224 _EGLDisplay *disp = _eglLockDisplay(dpy);
1225 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1226 _EGLDriver *drv;
1227 EGLBoolean ret;
1228
1229 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1230 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1231 ret = drv->API.SurfaceAttrib(drv, disp, surf, attribute, value);
1232
1233 RETURN_EGL_EVAL(disp, ret);
1234 }
1235
1236
1237 EGLBoolean EGLAPIENTRY
1238 eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1239 {
1240 _EGLDisplay *disp = _eglLockDisplay(dpy);
1241 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1242 _EGLDriver *drv;
1243 EGLBoolean ret;
1244
1245 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1246 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1247 ret = drv->API.BindTexImage(drv, disp, surf, buffer);
1248
1249 RETURN_EGL_EVAL(disp, ret);
1250 }
1251
1252
1253 EGLBoolean EGLAPIENTRY
1254 eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1255 {
1256 _EGLDisplay *disp = _eglLockDisplay(dpy);
1257 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1258 _EGLDriver *drv;
1259 EGLBoolean ret;
1260
1261 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1262 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1263 ret = drv->API.ReleaseTexImage(drv, disp, surf, buffer);
1264
1265 RETURN_EGL_EVAL(disp, ret);
1266 }
1267
1268
1269 EGLBoolean EGLAPIENTRY
1270 eglSwapInterval(EGLDisplay dpy, EGLint interval)
1271 {
1272 _EGLDisplay *disp = _eglLockDisplay(dpy);
1273 _EGLContext *ctx = _eglGetCurrentContext();
1274 _EGLSurface *surf = ctx ? ctx->DrawSurface : NULL;
1275 _EGLDriver *drv;
1276 EGLBoolean ret;
1277
1278 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1279 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1280
1281 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1282 ctx->Resource.Display != disp)
1283 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE);
1284
1285 if (_eglGetSurfaceHandle(surf) == EGL_NO_SURFACE)
1286 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1287
1288 if (surf->Type != EGL_WINDOW_BIT)
1289 RETURN_EGL_EVAL(disp, EGL_TRUE);
1290
1291 interval = CLAMP(interval,
1292 surf->Config->MinSwapInterval,
1293 surf->Config->MaxSwapInterval);
1294
1295 if (surf->SwapInterval != interval)
1296 ret = drv->API.SwapInterval(drv, disp, surf, interval);
1297 else
1298 ret = EGL_TRUE;
1299
1300 if (ret)
1301 surf->SwapInterval = interval;
1302
1303 RETURN_EGL_EVAL(disp, ret);
1304 }
1305
1306
1307 EGLBoolean EGLAPIENTRY
1308 eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
1309 {
1310 _EGLContext *ctx = _eglGetCurrentContext();
1311 _EGLDisplay *disp = _eglLockDisplay(dpy);
1312 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1313 _EGLDriver *drv;
1314 EGLBoolean ret;
1315
1316 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1317 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1318
1319 /* surface must be bound to current context in EGL 1.4 */
1320 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1321 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1322 surf != ctx->DrawSurface)
1323 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1324 #endif
1325
1326 if (surf->Type != EGL_WINDOW_BIT)
1327 RETURN_EGL_EVAL(disp, EGL_TRUE);
1328
1329 /* From the EGL 1.5 spec:
1330 *
1331 * If eglSwapBuffers is called and the native window associated with
1332 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1333 * generated.
1334 */
1335 if (surf->Lost)
1336 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_FALSE);
1337
1338 ret = drv->API.SwapBuffers(drv, disp, surf);
1339
1340 /* EGL_KHR_partial_update
1341 * Frame boundary successfully reached,
1342 * reset damage region and reset BufferAgeRead
1343 */
1344 if (ret) {
1345 surf->SetDamageRegionCalled = EGL_FALSE;
1346 surf->BufferAgeRead = EGL_FALSE;
1347 }
1348
1349 RETURN_EGL_EVAL(disp, ret);
1350 }
1351
1352
1353 static EGLBoolean
1354 _eglSwapBuffersWithDamageCommon(_EGLDisplay *disp, _EGLSurface *surf,
1355 EGLint *rects, EGLint n_rects)
1356 {
1357 _EGLContext *ctx = _eglGetCurrentContext();
1358 _EGLDriver *drv;
1359 EGLBoolean ret;
1360
1361 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1362
1363 /* surface must be bound to current context in EGL 1.4 */
1364 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1365 surf != ctx->DrawSurface)
1366 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1367
1368 if (surf->Type != EGL_WINDOW_BIT)
1369 RETURN_EGL_EVAL(disp, EGL_TRUE);
1370
1371 if ((n_rects > 0 && rects == NULL) || n_rects < 0)
1372 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1373
1374 ret = drv->API.SwapBuffersWithDamageEXT(drv, disp, surf, rects, n_rects);
1375
1376 /* EGL_KHR_partial_update
1377 * Frame boundary successfully reached,
1378 * reset damage region and reset BufferAgeRead
1379 */
1380 if (ret) {
1381 surf->SetDamageRegionCalled = EGL_FALSE;
1382 surf->BufferAgeRead = EGL_FALSE;
1383 }
1384
1385 RETURN_EGL_EVAL(disp, ret);
1386 }
1387
1388 static EGLBoolean EGLAPIENTRY
1389 eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface,
1390 EGLint *rects, EGLint n_rects)
1391 {
1392 _EGLDisplay *disp = _eglLockDisplay(dpy);
1393 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1394 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1395 return _eglSwapBuffersWithDamageCommon(disp, surf, rects, n_rects);
1396 }
1397
1398 static EGLBoolean EGLAPIENTRY
1399 eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface,
1400 EGLint *rects, EGLint n_rects)
1401 {
1402 _EGLDisplay *disp = _eglLockDisplay(dpy);
1403 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1404 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1405 return _eglSwapBuffersWithDamageCommon(disp, surf, rects, n_rects);
1406 }
1407
1408 /**
1409 * Clamp the rectangles so that they lie within the surface.
1410 */
1411
1412 static void
1413 _eglSetDamageRegionKHRClampRects(_EGLDisplay* disp, _EGLSurface* surf,
1414 EGLint *rects, EGLint n_rects)
1415 {
1416 EGLint i;
1417 EGLint surf_height = surf->Height;
1418 EGLint surf_width = surf->Width;
1419
1420 for (i = 0; i < (4 * n_rects); i += 4) {
1421 EGLint x1, y1, x2, y2;
1422 x1 = rects[i];
1423 y1 = rects[i + 1];
1424 x2 = rects[i + 2] + x1;
1425 y2 = rects[i + 3] + y1;
1426
1427 rects[i] = CLAMP(x1, 0, surf_width);
1428 rects[i + 1] = CLAMP(y1, 0, surf_height);
1429 rects[i + 2] = CLAMP(x2, 0, surf_width) - rects[i];
1430 rects[i + 3] = CLAMP(y2, 0, surf_height) - rects[i + 1];
1431 }
1432 }
1433
1434 static EGLBoolean EGLAPIENTRY
1435 eglSetDamageRegionKHR(EGLDisplay dpy, EGLSurface surface,
1436 EGLint *rects, EGLint n_rects)
1437 {
1438 _EGLDisplay *disp = _eglLockDisplay(dpy);
1439 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1440 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1441 _EGLContext *ctx = _eglGetCurrentContext();
1442 _EGLDriver *drv;
1443 EGLBoolean ret;
1444 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1445
1446 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1447 surf->Type != EGL_WINDOW_BIT ||
1448 ctx->DrawSurface != surf ||
1449 surf->SwapBehavior != EGL_BUFFER_DESTROYED)
1450 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
1451
1452 /* If the damage region is already set or
1453 * buffer age is not queried between
1454 * frame boundaries, throw bad access error
1455 */
1456
1457 if (surf->SetDamageRegionCalled || !surf->BufferAgeRead)
1458 RETURN_EGL_ERROR(disp, EGL_BAD_ACCESS, EGL_FALSE);
1459
1460 _eglSetDamageRegionKHRClampRects(disp, surf, rects, n_rects);
1461 ret = drv->API.SetDamageRegion(drv, disp, surf, rects, n_rects);
1462
1463 if (ret)
1464 surf->SetDamageRegionCalled = EGL_TRUE;
1465
1466 RETURN_EGL_EVAL(disp, ret);
1467 }
1468
1469 EGLBoolean EGLAPIENTRY
1470 eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
1471 {
1472 _EGLDisplay *disp = _eglLockDisplay(dpy);
1473 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1474 _EGLDriver *drv;
1475 EGLBoolean ret;
1476 void *native_pixmap_ptr;
1477
1478 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1479 STATIC_ASSERT(sizeof(void*) == sizeof(target));
1480 native_pixmap_ptr = (void*) target;
1481
1482 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1483 ret = drv->API.CopyBuffers(drv, disp, surf, native_pixmap_ptr);
1484
1485 RETURN_EGL_EVAL(disp, ret);
1486 }
1487
1488
1489 static EGLBoolean
1490 _eglWaitClientCommon(void)
1491 {
1492 _EGLContext *ctx = _eglGetCurrentContext();
1493 _EGLDisplay *disp;
1494 _EGLDriver *drv;
1495 EGLBoolean ret;
1496
1497 if (!ctx)
1498 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1499
1500 disp = ctx->Resource.Display;
1501 mtx_lock(&disp->Mutex);
1502
1503 /* let bad current context imply bad current surface */
1504 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1505 _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE)
1506 RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
1507
1508 /* a valid current context implies an initialized current display */
1509 assert(disp->Initialized);
1510 drv = disp->Driver;
1511 ret = drv->API.WaitClient(drv, disp, ctx);
1512
1513 RETURN_EGL_EVAL(disp, ret);
1514 }
1515
1516 EGLBoolean EGLAPIENTRY
1517 eglWaitClient(void)
1518 {
1519 _EGL_FUNC_START(NULL, EGL_OBJECT_CONTEXT_KHR, _eglGetCurrentContext(), EGL_FALSE);
1520 return _eglWaitClientCommon();
1521 }
1522
1523 EGLBoolean EGLAPIENTRY
1524 eglWaitGL(void)
1525 {
1526 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1527 _EGL_FUNC_START(NULL, EGL_OBJECT_CONTEXT_KHR, _eglGetCurrentContext(), EGL_FALSE);
1528 return _eglWaitClientCommon();
1529 }
1530
1531
1532 EGLBoolean EGLAPIENTRY
1533 eglWaitNative(EGLint engine)
1534 {
1535 _EGLContext *ctx = _eglGetCurrentContext();
1536 _EGLDisplay *disp;
1537 _EGLDriver *drv;
1538 EGLBoolean ret;
1539
1540 if (!ctx)
1541 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1542
1543 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE);
1544
1545 disp = ctx->Resource.Display;
1546 mtx_lock(&disp->Mutex);
1547
1548 /* let bad current context imply bad current surface */
1549 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1550 _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE)
1551 RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
1552
1553 /* a valid current context implies an initialized current display */
1554 assert(disp->Initialized);
1555 drv = disp->Driver;
1556 ret = drv->API.WaitNative(drv, disp, engine);
1557
1558 RETURN_EGL_EVAL(disp, ret);
1559 }
1560
1561
1562 EGLDisplay EGLAPIENTRY
1563 eglGetCurrentDisplay(void)
1564 {
1565 _EGLContext *ctx = _eglGetCurrentContext();
1566 EGLDisplay ret;
1567
1568 ret = (ctx) ? _eglGetDisplayHandle(ctx->Resource.Display) : EGL_NO_DISPLAY;
1569
1570 RETURN_EGL_SUCCESS(NULL, ret);
1571 }
1572
1573
1574 EGLContext EGLAPIENTRY
1575 eglGetCurrentContext(void)
1576 {
1577 _EGLContext *ctx = _eglGetCurrentContext();
1578 EGLContext ret;
1579
1580 ret = _eglGetContextHandle(ctx);
1581
1582 RETURN_EGL_SUCCESS(NULL, ret);
1583 }
1584
1585
1586 EGLSurface EGLAPIENTRY
1587 eglGetCurrentSurface(EGLint readdraw)
1588 {
1589 _EGLContext *ctx = _eglGetCurrentContext();
1590 EGLint err = EGL_SUCCESS;
1591 _EGLSurface *surf;
1592 EGLSurface ret;
1593
1594 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_NO_SURFACE);
1595
1596 if (!ctx)
1597 RETURN_EGL_SUCCESS(NULL, EGL_NO_SURFACE);
1598
1599 switch (readdraw) {
1600 case EGL_DRAW:
1601 surf = ctx->DrawSurface;
1602 break;
1603 case EGL_READ:
1604 surf = ctx->ReadSurface;
1605 break;
1606 default:
1607 surf = NULL;
1608 err = EGL_BAD_PARAMETER;
1609 break;
1610 }
1611
1612 ret = _eglGetSurfaceHandle(surf);
1613
1614 RETURN_EGL_ERROR(NULL, err, ret);
1615 }
1616
1617
1618 EGLint EGLAPIENTRY
1619 eglGetError(void)
1620 {
1621 _EGLThreadInfo *t = _eglGetCurrentThread();
1622 EGLint e = t->LastError;
1623 if (!_eglIsCurrentThreadDummy())
1624 t->LastError = EGL_SUCCESS;
1625 return e;
1626 }
1627
1628
1629 /**
1630 ** EGL 1.2
1631 **/
1632
1633 /**
1634 * Specify the client API to use for subsequent calls including:
1635 * eglCreateContext()
1636 * eglGetCurrentContext()
1637 * eglGetCurrentDisplay()
1638 * eglGetCurrentSurface()
1639 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1640 * eglWaitClient()
1641 * eglWaitNative()
1642 * See section 3.7 "Rendering Context" in the EGL specification for details.
1643 */
1644 EGLBoolean EGLAPIENTRY
1645 eglBindAPI(EGLenum api)
1646 {
1647 _EGLThreadInfo *t;
1648
1649 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE);
1650
1651 t = _eglGetCurrentThread();
1652 if (_eglIsCurrentThreadDummy())
1653 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_FALSE);
1654
1655 if (!_eglIsApiValid(api))
1656 RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, EGL_FALSE);
1657
1658 t->CurrentAPI = api;
1659
1660 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1661 }
1662
1663
1664 /**
1665 * Return the last value set with eglBindAPI().
1666 */
1667 EGLenum EGLAPIENTRY
1668 eglQueryAPI(void)
1669 {
1670 _EGLThreadInfo *t = _eglGetCurrentThread();
1671 EGLenum ret;
1672
1673 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1674 ret = t->CurrentAPI;
1675
1676 RETURN_EGL_SUCCESS(NULL, ret);
1677 }
1678
1679
1680 EGLSurface EGLAPIENTRY
1681 eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype,
1682 EGLClientBuffer buffer, EGLConfig config,
1683 const EGLint *attrib_list)
1684 {
1685 _EGLDisplay *disp = _eglLockDisplay(dpy);
1686 _EGLConfig *conf = _eglLookupConfig(config, disp);
1687 _EGLDriver *drv;
1688 _EGLSurface *surf;
1689 EGLSurface ret;
1690
1691 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1692
1693 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
1694
1695 surf = drv->API.CreatePbufferFromClientBuffer(drv, disp, buftype, buffer,
1696 conf, attrib_list);
1697 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
1698
1699 RETURN_EGL_EVAL(disp, ret);
1700 }
1701
1702
1703 EGLBoolean EGLAPIENTRY
1704 eglReleaseThread(void)
1705 {
1706 /* unbind current contexts */
1707 if (!_eglIsCurrentThreadDummy()) {
1708 _EGLThreadInfo *t = _eglGetCurrentThread();
1709 _EGLContext *ctx = t->CurrentContext;
1710
1711 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE);
1712
1713 if (ctx) {
1714 _EGLDisplay *disp = ctx->Resource.Display;
1715 _EGLDriver *drv;
1716
1717 mtx_lock(&disp->Mutex);
1718 drv = disp->Driver;
1719 (void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL);
1720 mtx_unlock(&disp->Mutex);
1721 }
1722 }
1723
1724 _eglDestroyCurrentThread();
1725
1726 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1727 }
1728
1729
1730 static EGLImage
1731 _eglCreateImageCommon(_EGLDisplay *disp, EGLContext ctx, EGLenum target,
1732 EGLClientBuffer buffer, const EGLint *attr_list)
1733 {
1734 _EGLContext *context = _eglLookupContext(ctx, disp);
1735 _EGLDriver *drv;
1736 _EGLImage *img;
1737 EGLImage ret;
1738
1739 _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv);
1740 if (!disp->Extensions.KHR_image_base)
1741 RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR);
1742 if (!context && ctx != EGL_NO_CONTEXT)
1743 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR);
1744 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1745 * <ctx> must be EGL_NO_CONTEXT..."
1746 */
1747 if (ctx != EGL_NO_CONTEXT && target == EGL_LINUX_DMA_BUF_EXT)
1748 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
1749
1750 img = drv->API.CreateImageKHR(drv, disp, context, target,
1751 buffer, attr_list);
1752 ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR;
1753
1754 RETURN_EGL_EVAL(disp, ret);
1755 }
1756
1757 static EGLImage EGLAPIENTRY
1758 eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1759 EGLClientBuffer buffer, const EGLint *attr_list)
1760 {
1761 _EGLDisplay *disp = _eglLockDisplay(dpy);
1762 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_IMAGE_KHR);
1763 return _eglCreateImageCommon(disp, ctx, target, buffer, attr_list);
1764 }
1765
1766
1767 EGLImage EGLAPIENTRY
1768 eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1769 EGLClientBuffer buffer, const EGLAttrib *attr_list)
1770 {
1771 _EGLDisplay *disp = _eglLockDisplay(dpy);
1772 EGLImage image;
1773 EGLint *int_attribs;
1774
1775 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_IMAGE_KHR);
1776
1777 int_attribs = _eglConvertAttribsToInt(attr_list);
1778 if (attr_list && !int_attribs)
1779 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_IMAGE);
1780
1781 image = _eglCreateImageCommon(disp, ctx, target, buffer, int_attribs);
1782 free(int_attribs);
1783 return image;
1784 }
1785
1786
1787 static EGLBoolean
1788 _eglDestroyImageCommon(_EGLDisplay *disp, _EGLImage *img)
1789 {
1790 _EGLDriver *drv;
1791 EGLBoolean ret;
1792
1793 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1794 if (!disp->Extensions.KHR_image_base)
1795 RETURN_EGL_EVAL(disp, EGL_FALSE);
1796 if (!img)
1797 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1798
1799 _eglUnlinkImage(img);
1800 ret = drv->API.DestroyImageKHR(drv, disp, img);
1801
1802 RETURN_EGL_EVAL(disp, ret);
1803 }
1804
1805 EGLBoolean EGLAPIENTRY
1806 eglDestroyImage(EGLDisplay dpy, EGLImage image)
1807 {
1808 _EGLDisplay *disp = _eglLockDisplay(dpy);
1809 _EGLImage *img = _eglLookupImage(image, disp);
1810 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
1811 return _eglDestroyImageCommon(disp, img);
1812 }
1813
1814 static EGLBoolean EGLAPIENTRY
1815 eglDestroyImageKHR(EGLDisplay dpy, EGLImage image)
1816 {
1817 _EGLDisplay *disp = _eglLockDisplay(dpy);
1818 _EGLImage *img = _eglLookupImage(image, disp);
1819 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
1820 return _eglDestroyImageCommon(disp, img);
1821 }
1822
1823
1824 static EGLSync
1825 _eglCreateSync(_EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_list,
1826 EGLBoolean orig_is_EGLAttrib,
1827 EGLenum invalid_type_error)
1828 {
1829 _EGLContext *ctx = _eglGetCurrentContext();
1830 _EGLDriver *drv;
1831 _EGLSync *sync;
1832 EGLSync ret;
1833
1834 _EGL_CHECK_DISPLAY(disp, EGL_NO_SYNC_KHR, drv);
1835
1836 if (!disp->Extensions.KHR_cl_event2 && orig_is_EGLAttrib) {
1837 /* There exist two EGLAttrib variants of eglCreateSync*:
1838 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1839 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1840 * support as a proxy for EGL 1.5 support, even though that's not
1841 * entirely correct (though _eglComputeVersion does the same).
1842 *
1843 * The EGL spec provides no guidance on how to handle unsupported
1844 * functions. EGL_BAD_MATCH seems reasonable.
1845 */
1846 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
1847 }
1848
1849 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1850 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1851 * error is generated.
1852 */
1853 if (!ctx &&
1854 (type == EGL_SYNC_FENCE_KHR || type == EGL_SYNC_NATIVE_FENCE_ANDROID))
1855 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
1856
1857 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1858 if (ctx && (ctx->Resource.Display != disp ||
1859 ctx->ClientAPI != EGL_OPENGL_ES_API))
1860 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
1861
1862 switch (type) {
1863 case EGL_SYNC_FENCE_KHR:
1864 if (!disp->Extensions.KHR_fence_sync)
1865 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1866 break;
1867 case EGL_SYNC_REUSABLE_KHR:
1868 if (!disp->Extensions.KHR_reusable_sync)
1869 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1870 break;
1871 case EGL_SYNC_CL_EVENT_KHR:
1872 if (!disp->Extensions.KHR_cl_event2)
1873 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1874 break;
1875 case EGL_SYNC_NATIVE_FENCE_ANDROID:
1876 if (!disp->Extensions.ANDROID_native_fence_sync)
1877 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1878 break;
1879 default:
1880 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1881 }
1882
1883 sync = drv->API.CreateSyncKHR(drv, disp, type, attrib_list);
1884 ret = (sync) ? _eglLinkSync(sync) : EGL_NO_SYNC_KHR;
1885
1886 RETURN_EGL_EVAL(disp, ret);
1887 }
1888
1889
1890 static EGLSync EGLAPIENTRY
1891 eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *int_list)
1892 {
1893 _EGLDisplay *disp = _eglLockDisplay(dpy);
1894 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1895
1896 EGLSync sync;
1897 EGLAttrib *attrib_list;
1898 EGLint err;
1899
1900 if (sizeof(int_list[0]) == sizeof(attrib_list[0])) {
1901 attrib_list = (EGLAttrib *) int_list;
1902 } else {
1903 err = _eglConvertIntsToAttribs(int_list, &attrib_list);
1904 if (err != EGL_SUCCESS)
1905 RETURN_EGL_ERROR(disp, err, EGL_NO_SYNC);
1906 }
1907
1908 sync = _eglCreateSync(disp, type, attrib_list, EGL_FALSE,
1909 EGL_BAD_ATTRIBUTE);
1910
1911 if (sizeof(int_list[0]) != sizeof(attrib_list[0]))
1912 free(attrib_list);
1913
1914 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1915 return sync;
1916 }
1917
1918
1919 static EGLSync EGLAPIENTRY
1920 eglCreateSync64KHR(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
1921 {
1922 _EGLDisplay *disp = _eglLockDisplay(dpy);
1923 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1924 return _eglCreateSync(disp, type, attrib_list, EGL_TRUE,
1925 EGL_BAD_ATTRIBUTE);
1926 }
1927
1928
1929 EGLSync EGLAPIENTRY
1930 eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
1931 {
1932 _EGLDisplay *disp = _eglLockDisplay(dpy);
1933 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1934 return _eglCreateSync(disp, type, attrib_list, EGL_TRUE,
1935 EGL_BAD_PARAMETER);
1936 }
1937
1938
1939 static EGLBoolean
1940 _eglDestroySync(_EGLDisplay *disp, _EGLSync *s)
1941 {
1942 _EGLDriver *drv;
1943 EGLBoolean ret;
1944
1945 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1946 assert(disp->Extensions.KHR_reusable_sync ||
1947 disp->Extensions.KHR_fence_sync ||
1948 disp->Extensions.ANDROID_native_fence_sync);
1949
1950 _eglUnlinkSync(s);
1951 ret = drv->API.DestroySyncKHR(drv, disp, s);
1952
1953 RETURN_EGL_EVAL(disp, ret);
1954 }
1955
1956 EGLBoolean EGLAPIENTRY
1957 eglDestroySync(EGLDisplay dpy, EGLSync sync)
1958 {
1959 _EGLDisplay *disp = _eglLockDisplay(dpy);
1960 _EGLSync *s = _eglLookupSync(sync, disp);
1961 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1962 return _eglDestroySync(disp, s);
1963 }
1964
1965 static EGLBoolean EGLAPIENTRY
1966 eglDestroySyncKHR(EGLDisplay dpy, EGLSync sync)
1967 {
1968 _EGLDisplay *disp = _eglLockDisplay(dpy);
1969 _EGLSync *s = _eglLookupSync(sync, disp);
1970 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1971 return _eglDestroySync(disp, s);
1972 }
1973
1974
1975 static EGLint
1976 _eglClientWaitSyncCommon(_EGLDisplay *disp, EGLDisplay dpy,
1977 _EGLSync *s, EGLint flags, EGLTime timeout)
1978 {
1979 _EGLDriver *drv;
1980 EGLint ret;
1981
1982 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1983 assert(disp->Extensions.KHR_reusable_sync ||
1984 disp->Extensions.KHR_fence_sync ||
1985 disp->Extensions.ANDROID_native_fence_sync);
1986
1987 if (s->SyncStatus == EGL_SIGNALED_KHR)
1988 RETURN_EGL_EVAL(disp, EGL_CONDITION_SATISFIED_KHR);
1989
1990 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1991 * unlocked here to allow other threads also to be able to
1992 * go into waiting state.
1993 */
1994
1995 if (s->Type == EGL_SYNC_REUSABLE_KHR)
1996 _eglUnlockDisplay(dpy);
1997
1998 ret = drv->API.ClientWaitSyncKHR(drv, disp, s, flags, timeout);
1999
2000 /*
2001 * 'disp' is already unlocked for reusable sync type,
2002 * so passing 'NULL' to bypass unlocking display.
2003 */
2004 if (s->Type == EGL_SYNC_REUSABLE_KHR)
2005 RETURN_EGL_EVAL(NULL, ret);
2006 else
2007 RETURN_EGL_EVAL(disp, ret);
2008 }
2009
2010 EGLint EGLAPIENTRY
2011 eglClientWaitSync(EGLDisplay dpy, EGLSync sync,
2012 EGLint flags, EGLTime timeout)
2013 {
2014 _EGLDisplay *disp = _eglLockDisplay(dpy);
2015 _EGLSync *s = _eglLookupSync(sync, disp);
2016 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2017 return _eglClientWaitSyncCommon(disp, dpy, s, flags, timeout);
2018 }
2019
2020 static EGLint EGLAPIENTRY
2021 eglClientWaitSyncKHR(EGLDisplay dpy, EGLSync sync,
2022 EGLint flags, EGLTime timeout)
2023 {
2024 _EGLDisplay *disp = _eglLockDisplay(dpy);
2025 _EGLSync *s = _eglLookupSync(sync, disp);
2026 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2027 return _eglClientWaitSyncCommon(disp, dpy, s, flags, timeout);
2028 }
2029
2030
2031 static EGLint
2032 _eglWaitSyncCommon(_EGLDisplay *disp, _EGLSync *s, EGLint flags)
2033 {
2034 _EGLContext *ctx = _eglGetCurrentContext();
2035 _EGLDriver *drv;
2036 EGLint ret;
2037
2038 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
2039 assert(disp->Extensions.KHR_wait_sync);
2040
2041 /* return an error if the client API doesn't support GL_OES_EGL_sync */
2042 if (ctx == EGL_NO_CONTEXT || ctx->ClientAPI != EGL_OPENGL_ES_API)
2043 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
2044
2045 /* the API doesn't allow any flags yet */
2046 if (flags != 0)
2047 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2048
2049 ret = drv->API.WaitSyncKHR(drv, disp, s);
2050
2051 RETURN_EGL_EVAL(disp, ret);
2052 }
2053
2054 static EGLint EGLAPIENTRY
2055 eglWaitSyncKHR(EGLDisplay dpy, EGLSync sync, EGLint flags)
2056 {
2057 _EGLDisplay *disp = _eglLockDisplay(dpy);
2058 _EGLSync *s = _eglLookupSync(sync, disp);
2059 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2060 return _eglWaitSyncCommon(disp, s, flags);
2061 }
2062
2063
2064 EGLBoolean EGLAPIENTRY
2065 eglWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags)
2066 {
2067 /* The KHR version returns EGLint, while the core version returns
2068 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2069 * EGL_TRUE.
2070 */
2071 _EGLDisplay *disp = _eglLockDisplay(dpy);
2072 _EGLSync *s = _eglLookupSync(sync, disp);
2073 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2074 return _eglWaitSyncCommon(disp, s, flags);
2075 }
2076
2077
2078 static EGLBoolean EGLAPIENTRY
2079 eglSignalSyncKHR(EGLDisplay dpy, EGLSync sync, EGLenum mode)
2080 {
2081 _EGLDisplay *disp = _eglLockDisplay(dpy);
2082 _EGLSync *s = _eglLookupSync(sync, disp);
2083 _EGLDriver *drv;
2084 EGLBoolean ret;
2085
2086 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2087
2088 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
2089 assert(disp->Extensions.KHR_reusable_sync);
2090 ret = drv->API.SignalSyncKHR(drv, disp, s, mode);
2091
2092 RETURN_EGL_EVAL(disp, ret);
2093 }
2094
2095
2096 static EGLBoolean
2097 _eglGetSyncAttribCommon(_EGLDisplay *disp, _EGLSync *s, EGLint attribute, EGLAttrib *value)
2098 {
2099 _EGLDriver *drv;
2100 EGLBoolean ret;
2101
2102 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
2103 assert(disp->Extensions.KHR_reusable_sync ||
2104 disp->Extensions.KHR_fence_sync ||
2105 disp->Extensions.ANDROID_native_fence_sync);
2106 ret = drv->API.GetSyncAttrib(drv, disp, s, attribute, value);
2107
2108 RETURN_EGL_EVAL(disp, ret);
2109 }
2110
2111 EGLBoolean EGLAPIENTRY
2112 eglGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value)
2113 {
2114 _EGLDisplay *disp = _eglLockDisplay(dpy);
2115 _EGLSync *s = _eglLookupSync(sync, disp);
2116 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2117 return _eglGetSyncAttribCommon(disp, s, attribute, value);
2118 }
2119
2120
2121 static EGLBoolean EGLAPIENTRY
2122 eglGetSyncAttribKHR(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLint *value)
2123 {
2124 _EGLDisplay *disp = _eglLockDisplay(dpy);
2125 _EGLSync *s = _eglLookupSync(sync, disp);
2126 EGLAttrib attrib;
2127 EGLBoolean result;
2128
2129 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2130
2131 if (!value)
2132 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2133
2134 attrib = *value;
2135 result = _eglGetSyncAttribCommon(disp, s, attribute, &attrib);
2136
2137 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2138 *
2139 * If any error occurs, <*value> is not modified.
2140 */
2141 if (result == EGL_FALSE)
2142 return result;
2143
2144 *value = attrib;
2145 return result;
2146 }
2147
2148 static EGLint EGLAPIENTRY
2149 eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSync sync)
2150 {
2151 _EGLDisplay *disp = _eglLockDisplay(dpy);
2152 _EGLSync *s = _eglLookupSync(sync, disp);
2153 _EGLDriver *drv;
2154 EGLBoolean ret;
2155
2156 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2157
2158 /* the spec doesn't seem to specify what happens if the fence
2159 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2160 * sensible:
2161 */
2162 if (!(s && (s->Type == EGL_SYNC_NATIVE_FENCE_ANDROID)))
2163 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_NO_NATIVE_FENCE_FD_ANDROID);
2164
2165 _EGL_CHECK_SYNC(disp, s, EGL_NO_NATIVE_FENCE_FD_ANDROID, drv);
2166 assert(disp->Extensions.ANDROID_native_fence_sync);
2167 ret = drv->API.DupNativeFenceFDANDROID(drv, disp, s);
2168
2169 RETURN_EGL_EVAL(disp, ret);
2170 }
2171
2172 static EGLBoolean EGLAPIENTRY
2173 eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface,
2174 EGLint numRects, const EGLint *rects)
2175 {
2176 _EGLContext *ctx = _eglGetCurrentContext();
2177 _EGLDisplay *disp = _eglLockDisplay(dpy);
2178 _EGLSurface *surf = _eglLookupSurface(surface, disp);
2179 _EGLDriver *drv;
2180 EGLBoolean ret;
2181
2182 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
2183
2184 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
2185
2186 if (!disp->Extensions.NOK_swap_region)
2187 RETURN_EGL_EVAL(disp, EGL_FALSE);
2188
2189 /* surface must be bound to current context in EGL 1.4 */
2190 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
2191 surf != ctx->DrawSurface)
2192 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
2193
2194 ret = drv->API.SwapBuffersRegionNOK(drv, disp, surf, numRects, rects);
2195
2196 RETURN_EGL_EVAL(disp, ret);
2197 }
2198
2199
2200 static EGLImage EGLAPIENTRY
2201 eglCreateDRMImageMESA(EGLDisplay dpy, const EGLint *attr_list)
2202 {
2203 _EGLDisplay *disp = _eglLockDisplay(dpy);
2204 _EGLDriver *drv;
2205 _EGLImage *img;
2206 EGLImage ret;
2207
2208 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
2209
2210 _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv);
2211 if (!disp->Extensions.MESA_drm_image)
2212 RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR);
2213
2214 img = drv->API.CreateDRMImageMESA(drv, disp, attr_list);
2215 ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR;
2216
2217 RETURN_EGL_EVAL(disp, ret);
2218 }
2219
2220 static EGLBoolean EGLAPIENTRY
2221 eglExportDRMImageMESA(EGLDisplay dpy, EGLImage image,
2222 EGLint *name, EGLint *handle, EGLint *stride)
2223 {
2224 _EGLDisplay *disp = _eglLockDisplay(dpy);
2225 _EGLImage *img = _eglLookupImage(image, disp);
2226 _EGLDriver *drv;
2227 EGLBoolean ret;
2228
2229 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
2230
2231 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2232 assert(disp->Extensions.MESA_drm_image);
2233
2234 if (!img)
2235 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2236
2237 ret = drv->API.ExportDRMImageMESA(drv, disp, img, name, handle, stride);
2238
2239 RETURN_EGL_EVAL(disp, ret);
2240 }
2241
2242
2243 struct wl_display;
2244
2245 static EGLBoolean EGLAPIENTRY
2246 eglBindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
2247 {
2248 _EGLDisplay *disp = _eglLockDisplay(dpy);
2249 _EGLDriver *drv;
2250 EGLBoolean ret;
2251
2252 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
2253
2254 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2255 assert(disp->Extensions.WL_bind_wayland_display);
2256
2257 if (!display)
2258 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2259
2260 ret = drv->API.BindWaylandDisplayWL(drv, disp, display);
2261
2262 RETURN_EGL_EVAL(disp, ret);
2263 }
2264
2265 static EGLBoolean EGLAPIENTRY
2266 eglUnbindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
2267 {
2268 _EGLDisplay *disp = _eglLockDisplay(dpy);
2269 _EGLDriver *drv;
2270 EGLBoolean ret;
2271
2272 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
2273
2274 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2275 assert(disp->Extensions.WL_bind_wayland_display);
2276
2277 if (!display)
2278 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2279
2280 ret = drv->API.UnbindWaylandDisplayWL(drv, disp, display);
2281
2282 RETURN_EGL_EVAL(disp, ret);
2283 }
2284
2285 static EGLBoolean EGLAPIENTRY
2286 eglQueryWaylandBufferWL(EGLDisplay dpy, struct wl_resource *buffer,
2287 EGLint attribute, EGLint *value)
2288 {
2289 _EGLDisplay *disp = _eglLockDisplay(dpy);
2290 _EGLDriver *drv;
2291 EGLBoolean ret;
2292
2293 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
2294
2295 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2296 assert(disp->Extensions.WL_bind_wayland_display);
2297
2298 if (!buffer)
2299 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2300
2301 ret = drv->API.QueryWaylandBufferWL(drv, disp, buffer, attribute, value);
2302
2303 RETURN_EGL_EVAL(disp, ret);
2304 }
2305
2306
2307 static struct wl_buffer * EGLAPIENTRY
2308 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy, EGLImage image)
2309 {
2310 _EGLDisplay *disp = _eglLockDisplay(dpy);
2311 _EGLImage *img;
2312 _EGLDriver *drv;
2313 struct wl_buffer *ret;
2314
2315 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
2316
2317 _EGL_CHECK_DISPLAY(disp, NULL, drv);
2318 if (!disp->Extensions.WL_create_wayland_buffer_from_image)
2319 RETURN_EGL_EVAL(disp, NULL);
2320
2321 img = _eglLookupImage(image, disp);
2322
2323 if (!img)
2324 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL);
2325
2326 ret = drv->API.CreateWaylandBufferFromImageWL(drv, disp, img);
2327
2328 RETURN_EGL_EVAL(disp, ret);
2329 }
2330
2331 static EGLBoolean EGLAPIENTRY
2332 eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface,
2333 EGLint x, EGLint y, EGLint width, EGLint height)
2334 {
2335 _EGLDisplay *disp = _eglLockDisplay(dpy);
2336 _EGLSurface *surf = _eglLookupSurface(surface, disp);
2337 _EGLDriver *drv;
2338 EGLBoolean ret;
2339
2340 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
2341
2342 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
2343
2344 if (!disp->Extensions.NV_post_sub_buffer)
2345 RETURN_EGL_EVAL(disp, EGL_FALSE);
2346
2347 ret = drv->API.PostSubBufferNV(drv, disp, surf, x, y, width, height);
2348
2349 RETURN_EGL_EVAL(disp, ret);
2350 }
2351
2352 static EGLBoolean EGLAPIENTRY
2353 eglGetSyncValuesCHROMIUM(EGLDisplay dpy, EGLSurface surface,
2354 EGLuint64KHR *ust, EGLuint64KHR *msc,
2355 EGLuint64KHR *sbc)
2356 {
2357 _EGLDisplay *disp = _eglLockDisplay(dpy);
2358 _EGLSurface *surf = _eglLookupSurface(surface, disp);
2359 _EGLDriver *drv;
2360 EGLBoolean ret;
2361
2362 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
2363
2364 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
2365 if (!disp->Extensions.CHROMIUM_sync_control)
2366 RETURN_EGL_EVAL(disp, EGL_FALSE);
2367
2368 if (!ust || !msc || !sbc)
2369 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2370
2371 ret = drv->API.GetSyncValuesCHROMIUM(disp, surf, ust, msc, sbc);
2372
2373 RETURN_EGL_EVAL(disp, ret);
2374 }
2375
2376 static EGLBoolean EGLAPIENTRY
2377 eglExportDMABUFImageQueryMESA(EGLDisplay dpy, EGLImage image,
2378 EGLint *fourcc, EGLint *nplanes,
2379 EGLuint64KHR *modifiers)
2380 {
2381 _EGLDisplay *disp = _eglLockDisplay(dpy);
2382 _EGLImage *img = _eglLookupImage(image, disp);
2383 _EGLDriver *drv;
2384 EGLBoolean ret;
2385
2386 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
2387
2388 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2389 assert(disp->Extensions.MESA_image_dma_buf_export);
2390
2391 if (!img)
2392 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2393
2394 ret = drv->API.ExportDMABUFImageQueryMESA(drv, disp, img, fourcc, nplanes,
2395 modifiers);
2396
2397 RETURN_EGL_EVAL(disp, ret);
2398 }
2399
2400 static EGLBoolean EGLAPIENTRY
2401 eglExportDMABUFImageMESA(EGLDisplay dpy, EGLImage image,
2402 int *fds, EGLint *strides, EGLint *offsets)
2403 {
2404 _EGLDisplay *disp = _eglLockDisplay(dpy);
2405 _EGLImage *img = _eglLookupImage(image, disp);
2406 _EGLDriver *drv;
2407 EGLBoolean ret;
2408
2409 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
2410
2411 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2412 assert(disp->Extensions.MESA_image_dma_buf_export);
2413
2414 if (!img)
2415 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2416
2417 ret = drv->API.ExportDMABUFImageMESA(drv, disp, img, fds, strides, offsets);
2418
2419 RETURN_EGL_EVAL(disp, ret);
2420 }
2421
2422 static EGLint EGLAPIENTRY
2423 eglLabelObjectKHR(EGLDisplay dpy, EGLenum objectType, EGLObjectKHR object,
2424 EGLLabelKHR label)
2425 {
2426 _EGLDisplay *disp = NULL;
2427 _EGLResourceType type;
2428
2429 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC);
2430
2431 if (objectType == EGL_OBJECT_THREAD_KHR) {
2432 _EGLThreadInfo *t = _eglGetCurrentThread();
2433
2434 if (!_eglIsCurrentThreadDummy()) {
2435 t->Label = label;
2436 return EGL_SUCCESS;
2437 }
2438
2439 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_BAD_ALLOC);
2440 }
2441
2442 disp = _eglLockDisplay(dpy);
2443 if (disp == NULL)
2444 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_BAD_DISPLAY);
2445
2446 if (objectType == EGL_OBJECT_DISPLAY_KHR) {
2447 if (dpy != (EGLDisplay) object)
2448 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER);
2449
2450 disp->Label = label;
2451 RETURN_EGL_EVAL(disp, EGL_SUCCESS);
2452 }
2453
2454 switch (objectType) {
2455 case EGL_OBJECT_CONTEXT_KHR:
2456 type = _EGL_RESOURCE_CONTEXT;
2457 break;
2458 case EGL_OBJECT_SURFACE_KHR:
2459 type = _EGL_RESOURCE_SURFACE;
2460 break;
2461 case EGL_OBJECT_IMAGE_KHR:
2462 type = _EGL_RESOURCE_IMAGE;
2463 break;
2464 case EGL_OBJECT_SYNC_KHR:
2465 type = _EGL_RESOURCE_SYNC;
2466 break;
2467 case EGL_OBJECT_STREAM_KHR:
2468 default:
2469 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER);
2470 }
2471
2472 if (_eglCheckResource(object, type, disp)) {
2473 _EGLResource *res = (_EGLResource *) object;
2474
2475 res->Label = label;
2476 RETURN_EGL_EVAL(disp, EGL_SUCCESS);
2477 }
2478
2479 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER);
2480 }
2481
2482 static EGLint EGLAPIENTRY
2483 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback,
2484 const EGLAttrib *attrib_list)
2485 {
2486 unsigned int newEnabled;
2487
2488 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC);
2489
2490 mtx_lock(_eglGlobal.Mutex);
2491
2492 newEnabled = _eglGlobal.debugTypesEnabled;
2493 if (attrib_list != NULL) {
2494 int i;
2495
2496 for (i = 0; attrib_list[i] != EGL_NONE; i += 2) {
2497 switch (attrib_list[i]) {
2498 case EGL_DEBUG_MSG_CRITICAL_KHR:
2499 case EGL_DEBUG_MSG_ERROR_KHR:
2500 case EGL_DEBUG_MSG_WARN_KHR:
2501 case EGL_DEBUG_MSG_INFO_KHR:
2502 if (attrib_list[i + 1])
2503 newEnabled |= DebugBitFromType(attrib_list[i]);
2504 else
2505 newEnabled &= ~DebugBitFromType(attrib_list[i]);
2506 break;
2507 default:
2508 // On error, set the last error code, call the current
2509 // debug callback, and return the error code.
2510 mtx_unlock(_eglGlobal.Mutex);
2511 _eglReportError(EGL_BAD_ATTRIBUTE, NULL,
2512 "Invalid attribute 0x%04lx", (unsigned long) attrib_list[i]);
2513 return EGL_BAD_ATTRIBUTE;
2514 }
2515 }
2516 }
2517
2518 if (callback != NULL) {
2519 _eglGlobal.debugCallback = callback;
2520 _eglGlobal.debugTypesEnabled = newEnabled;
2521 } else {
2522 _eglGlobal.debugCallback = NULL;
2523 _eglGlobal.debugTypesEnabled = _EGL_DEBUG_BIT_CRITICAL | _EGL_DEBUG_BIT_ERROR;
2524 }
2525
2526 mtx_unlock(_eglGlobal.Mutex);
2527 return EGL_SUCCESS;
2528 }
2529
2530 static EGLBoolean EGLAPIENTRY
2531 eglQueryDebugKHR(EGLint attribute, EGLAttrib *value)
2532 {
2533 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC);
2534
2535 mtx_lock(_eglGlobal.Mutex);
2536
2537 switch (attribute) {
2538 case EGL_DEBUG_MSG_CRITICAL_KHR:
2539 case EGL_DEBUG_MSG_ERROR_KHR:
2540 case EGL_DEBUG_MSG_WARN_KHR:
2541 case EGL_DEBUG_MSG_INFO_KHR:
2542 if (_eglGlobal.debugTypesEnabled & DebugBitFromType(attribute))
2543 *value = EGL_TRUE;
2544 else
2545 *value = EGL_FALSE;
2546 break;
2547 case EGL_DEBUG_CALLBACK_KHR:
2548 *value = (EGLAttrib) _eglGlobal.debugCallback;
2549 break;
2550 default:
2551 mtx_unlock(_eglGlobal.Mutex);
2552 _eglReportError(EGL_BAD_ATTRIBUTE, NULL,
2553 "Invalid attribute 0x%04lx", (unsigned long) attribute);
2554 return EGL_FALSE;
2555 }
2556
2557 mtx_unlock(_eglGlobal.Mutex);
2558 return EGL_TRUE;
2559 }
2560
2561 static int
2562 _eglFunctionCompare(const void *key, const void *elem)
2563 {
2564 const char *procname = key;
2565 const struct _egl_entrypoint *entrypoint = elem;
2566 return strcmp(procname, entrypoint->name);
2567 }
2568
2569 static EGLBoolean EGLAPIENTRY
2570 eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint max_formats,
2571 EGLint *formats, EGLint *num_formats)
2572 {
2573 _EGLDisplay *disp = _eglLockDisplay(dpy);
2574 _EGLDriver *drv;
2575 EGLBoolean ret;
2576
2577 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
2578
2579 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2580
2581 ret = drv->API.QueryDmaBufFormatsEXT(drv, disp, max_formats, formats,
2582 num_formats);
2583
2584 RETURN_EGL_EVAL(disp, ret);
2585 }
2586
2587 static EGLBoolean EGLAPIENTRY
2588 eglQueryDmaBufModifiersEXT(EGLDisplay dpy, EGLint format, EGLint max_modifiers,
2589 EGLuint64KHR *modifiers, EGLBoolean *external_only,
2590 EGLint *num_modifiers)
2591 {
2592 _EGLDisplay *disp = _eglLockDisplay(dpy);
2593 _EGLDriver *drv;
2594 EGLBoolean ret;
2595
2596 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
2597
2598 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2599
2600 ret = drv->API.QueryDmaBufModifiersEXT(drv, disp, format, max_modifiers,
2601 modifiers, external_only,
2602 num_modifiers);
2603
2604 RETURN_EGL_EVAL(disp, ret);
2605 }
2606
2607 static void EGLAPIENTRY
2608 eglSetBlobCacheFuncsANDROID(EGLDisplay *dpy, EGLSetBlobFuncANDROID set,
2609 EGLGetBlobFuncANDROID get)
2610 {
2611 /* This function does not return anything so we cannot
2612 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2613 */
2614 _EGLDisplay *disp = _eglLockDisplay(dpy);
2615 if (!_eglSetFuncName(__func__, disp, EGL_OBJECT_DISPLAY_KHR, NULL)) {
2616 if (disp)
2617 _eglUnlockDisplay(disp);
2618 return;
2619 }
2620
2621 _EGLDriver *drv = _eglCheckDisplay(disp, __func__);
2622 if (!drv) {
2623 if (disp)
2624 _eglUnlockDisplay(disp);
2625 return;
2626 }
2627
2628 if (!set || !get) {
2629 _eglError(EGL_BAD_PARAMETER,
2630 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2631 _eglUnlockDisplay(disp);
2632 return;
2633 }
2634
2635 if (disp->BlobCacheSet) {
2636 _eglError(EGL_BAD_PARAMETER,
2637 "eglSetBlobCacheFuncsANDROID: functions already set");
2638 _eglUnlockDisplay(disp);
2639 return;
2640 }
2641
2642 disp->BlobCacheSet = set;
2643 disp->BlobCacheGet = get;
2644
2645 drv->API.SetBlobCacheFuncsANDROID(drv, disp, set, get);
2646
2647 _eglUnlockDisplay(disp);
2648 }
2649
2650 static EGLBoolean EGLAPIENTRY
2651 eglQueryDeviceAttribEXT(EGLDeviceEXT device,
2652 EGLint attribute,
2653 EGLAttrib *value)
2654 {
2655 _EGLDevice *dev = _eglLookupDevice(device);
2656 EGLBoolean ret;
2657
2658 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
2659 if (!dev)
2660 RETURN_EGL_ERROR(NULL, EGL_BAD_DEVICE_EXT, EGL_FALSE);
2661
2662 ret = _eglQueryDeviceAttribEXT(dev, attribute, value);
2663 RETURN_EGL_EVAL(NULL, ret);
2664 }
2665
2666 static const char * EGLAPIENTRY
2667 eglQueryDeviceStringEXT(EGLDeviceEXT device,
2668 EGLint name)
2669 {
2670 _EGLDevice *dev = _eglLookupDevice(device);
2671
2672 _EGL_FUNC_START(NULL, EGL_NONE, NULL, NULL);
2673 if (!dev)
2674 RETURN_EGL_ERROR(NULL, EGL_BAD_DEVICE_EXT, NULL);
2675
2676 RETURN_EGL_EVAL(NULL, _eglQueryDeviceStringEXT(dev, name));
2677 }
2678
2679 static EGLBoolean EGLAPIENTRY
2680 eglQueryDevicesEXT(EGLint max_devices,
2681 EGLDeviceEXT *devices,
2682 EGLint *num_devices)
2683 {
2684 EGLBoolean ret;
2685
2686 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
2687 ret = _eglQueryDevicesEXT(max_devices, (_EGLDevice **) devices,
2688 num_devices);
2689 RETURN_EGL_EVAL(NULL, ret);
2690 }
2691
2692 static EGLBoolean EGLAPIENTRY
2693 eglQueryDisplayAttribEXT(EGLDisplay dpy,
2694 EGLint attribute,
2695 EGLAttrib *value)
2696 {
2697 _EGLDisplay *disp = _eglLockDisplay(dpy);
2698 _EGLDriver *drv;
2699
2700 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
2701 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2702
2703 switch (attribute) {
2704 case EGL_DEVICE_EXT:
2705 *value = (EGLAttrib) disp->Device;
2706 break;
2707 default:
2708 RETURN_EGL_ERROR(disp, EGL_BAD_ATTRIBUTE, EGL_FALSE);
2709 }
2710 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
2711 }
2712
2713 static char * EGLAPIENTRY
2714 eglGetDisplayDriverConfig(EGLDisplay dpy)
2715 {
2716 _EGLDisplay *disp = _eglLockDisplay(dpy);
2717 _EGLDriver *drv;
2718 char *ret;
2719
2720 _EGL_FUNC_START(disp, EGL_NONE, NULL, NULL);
2721 _EGL_CHECK_DISPLAY(disp, NULL, drv);
2722
2723 assert(disp->Extensions.MESA_query_driver);
2724
2725 ret = drv->API.QueryDriverConfig(disp);
2726 RETURN_EGL_EVAL(disp, ret);
2727 }
2728
2729 static const char * EGLAPIENTRY
2730 eglGetDisplayDriverName(EGLDisplay dpy)
2731 {
2732 _EGLDisplay *disp = _eglLockDisplay(dpy);
2733 _EGLDriver *drv;
2734 const char *ret;
2735
2736 _EGL_FUNC_START(disp, EGL_NONE, NULL, NULL);
2737 _EGL_CHECK_DISPLAY(disp, NULL, drv);
2738
2739 assert(disp->Extensions.MESA_query_driver);
2740
2741 ret = drv->API.QueryDriverName(disp);
2742 RETURN_EGL_EVAL(disp, ret);
2743 }
2744
2745 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2746 eglGetProcAddress(const char *procname)
2747 {
2748 static const struct _egl_entrypoint egl_functions[] = {
2749 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2750 #include "eglentrypoint.h"
2751 #undef EGL_ENTRYPOINT
2752 };
2753 _EGLProc ret = NULL;
2754
2755 if (!procname)
2756 RETURN_EGL_SUCCESS(NULL, NULL);
2757
2758 _EGL_FUNC_START(NULL, EGL_NONE, NULL, NULL);
2759
2760 if (strncmp(procname, "egl", 3) == 0) {
2761 const struct _egl_entrypoint *entrypoint =
2762 bsearch(procname,
2763 egl_functions, ARRAY_SIZE(egl_functions),
2764 sizeof(egl_functions[0]),
2765 _eglFunctionCompare);
2766 if (entrypoint)
2767 ret = entrypoint->function;
2768 }
2769
2770 if (!ret)
2771 ret = _eglGetDriverProc(procname);
2772
2773 RETURN_EGL_SUCCESS(NULL, ret);
2774 }
2775
2776 static int
2777 _eglLockDisplayInterop(EGLDisplay dpy, EGLContext context,
2778 _EGLDisplay **disp, _EGLDriver **drv,
2779 _EGLContext **ctx)
2780 {
2781
2782 *disp = _eglLockDisplay(dpy);
2783 if (!*disp || !(*disp)->Initialized || !(*disp)->Driver) {
2784 if (*disp)
2785 _eglUnlockDisplay(*disp);
2786 return MESA_GLINTEROP_INVALID_DISPLAY;
2787 }
2788
2789 *drv = (*disp)->Driver;
2790
2791 *ctx = _eglLookupContext(context, *disp);
2792 if (!*ctx ||
2793 ((*ctx)->ClientAPI != EGL_OPENGL_API &&
2794 (*ctx)->ClientAPI != EGL_OPENGL_ES_API)) {
2795 _eglUnlockDisplay(*disp);
2796 return MESA_GLINTEROP_INVALID_CONTEXT;
2797 }
2798
2799 return MESA_GLINTEROP_SUCCESS;
2800 }
2801
2802 PUBLIC int
2803 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy, EGLContext context,
2804 struct mesa_glinterop_device_info *out)
2805 {
2806 _EGLDisplay *disp;
2807 _EGLDriver *drv;
2808 _EGLContext *ctx;
2809 int ret;
2810
2811 ret = _eglLockDisplayInterop(dpy, context, &disp, &drv, &ctx);
2812 if (ret != MESA_GLINTEROP_SUCCESS)
2813 return ret;
2814
2815 if (drv->API.GLInteropQueryDeviceInfo)
2816 ret = drv->API.GLInteropQueryDeviceInfo(disp, ctx, out);
2817 else
2818 ret = MESA_GLINTEROP_UNSUPPORTED;
2819
2820 _eglUnlockDisplay(disp);
2821 return ret;
2822 }
2823
2824 PUBLIC int
2825 MesaGLInteropEGLExportObject(EGLDisplay dpy, EGLContext context,
2826 struct mesa_glinterop_export_in *in,
2827 struct mesa_glinterop_export_out *out)
2828 {
2829 _EGLDisplay *disp;
2830 _EGLDriver *drv;
2831 _EGLContext *ctx;
2832 int ret;
2833
2834 ret = _eglLockDisplayInterop(dpy, context, &disp, &drv, &ctx);
2835 if (ret != MESA_GLINTEROP_SUCCESS)
2836 return ret;
2837
2838 if (drv->API.GLInteropExportObject)
2839 ret = drv->API.GLInteropExportObject(disp, ctx, in, out);
2840 else
2841 ret = MESA_GLINTEROP_UNSUPPORTED;
2842
2843 _eglUnlockDisplay(disp);
2844 return ret;
2845 }