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