egl: drop unused _EGLDriver from {Create,Destroy}Context()
[mesa.git] / src / egl / main / eglapi.c
1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
4 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5 * Copyright 2010-2011 LunarG, Inc.
6 * All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 *
28 **************************************************************************/
29
30
31 /**
32 * Public EGL API entrypoints
33 *
34 * Generally, we use the EGLDisplay parameter as a key to lookup the
35 * appropriate device driver handle, then jump though the driver's
36 * dispatch table to handle the function.
37 *
38 * That allows us the option of supporting multiple, simultaneous,
39 * heterogeneous hardware devices in the future.
40 *
41 * The EGLDisplay, EGLConfig, EGLContext and EGLSurface types are
42 * opaque handles. Internal objects are linked to a display to
43 * create the handles.
44 *
45 * For each public API entry point, the opaque handles are looked up
46 * before being dispatched to the drivers. When it fails to look up
47 * a handle, one of
48 *
49 * EGL_BAD_DISPLAY
50 * EGL_BAD_CONFIG
51 * EGL_BAD_CONTEXT
52 * EGL_BAD_SURFACE
53 * EGL_BAD_SCREEN_MESA
54 * EGL_BAD_MODE_MESA
55 *
56 * is generated and the driver function is not called. An
57 * uninitialized EGLDisplay has no driver associated with it. When
58 * such display is detected,
59 *
60 * EGL_NOT_INITIALIZED
61 *
62 * is generated.
63 *
64 * Some of the entry points use current display, context, or surface
65 * implicitly. For such entry points, the implicit objects are also
66 * checked before calling the driver function. Other than the
67 * errors listed above,
68 *
69 * EGL_BAD_CURRENT_SURFACE
70 *
71 * may also be generated.
72 *
73 * Notes on naming conventions:
74 *
75 * eglFooBar - public EGL function
76 * EGL_FOO_BAR - public EGL token
77 * EGLDatatype - public EGL datatype
78 *
79 * _eglFooBar - private EGL function
80 * _EGLDatatype - private EGL datatype, typedef'd struct
81 * _egl_struct - private EGL struct, non-typedef'd
82 *
83 */
84
85
86 #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 disp->Driver->Terminate(disp);
676 /* do not reset disp->Driver */
677 disp->ClientAPIsString[0] = 0;
678 disp->Initialized = EGL_FALSE;
679
680 /* Reset blob cache funcs on terminate. */
681 disp->BlobCacheSet = NULL;
682 disp->BlobCacheGet = NULL;
683 }
684
685 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
686 }
687
688
689 const char * EGLAPIENTRY
690 eglQueryString(EGLDisplay dpy, EGLint name)
691 {
692 _EGLDisplay *disp;
693 const _EGLDriver *drv;
694
695 #if !USE_LIBGLVND
696 if (dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS) {
697 RETURN_EGL_SUCCESS(NULL, _eglGlobal.ClientExtensionString);
698 }
699 #endif
700
701 disp = _eglLockDisplay(dpy);
702 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, NULL);
703 _EGL_CHECK_DISPLAY(disp, NULL, drv);
704
705 switch (name) {
706 case EGL_VENDOR:
707 RETURN_EGL_SUCCESS(disp, _EGL_VENDOR_STRING);
708 case EGL_VERSION:
709 RETURN_EGL_SUCCESS(disp, disp->VersionString);
710 case EGL_EXTENSIONS:
711 RETURN_EGL_SUCCESS(disp, disp->ExtensionsString);
712 case EGL_CLIENT_APIS:
713 RETURN_EGL_SUCCESS(disp, disp->ClientAPIsString);
714 default:
715 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL);
716 }
717 }
718
719
720 EGLBoolean EGLAPIENTRY
721 eglGetConfigs(EGLDisplay dpy, EGLConfig *configs,
722 EGLint config_size, EGLint *num_config)
723 {
724 _EGLDisplay *disp = _eglLockDisplay(dpy);
725 const _EGLDriver *drv;
726 EGLBoolean ret;
727
728 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
729
730 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
731
732 if (!num_config)
733 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
734
735 ret = _eglGetConfigs(drv, disp, configs, config_size, num_config);
736
737 RETURN_EGL_EVAL(disp, ret);
738 }
739
740
741 EGLBoolean EGLAPIENTRY
742 eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs,
743 EGLint config_size, EGLint *num_config)
744 {
745 _EGLDisplay *disp = _eglLockDisplay(dpy);
746 const _EGLDriver *drv;
747 EGLBoolean ret;
748
749 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
750
751 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
752
753 if (!num_config)
754 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
755
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 const _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 ret = _eglGetConfigAttrib(drv, disp, conf, attribute, value);
777
778 RETURN_EGL_EVAL(disp, ret);
779 }
780
781
782 EGLContext EGLAPIENTRY
783 eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list,
784 const EGLint *attrib_list)
785 {
786 _EGLDisplay *disp = _eglLockDisplay(dpy);
787 _EGLConfig *conf = _eglLookupConfig(config, disp);
788 _EGLContext *share = _eglLookupContext(share_list, disp);
789 const _EGLDriver *drv;
790 _EGLContext *context;
791 EGLContext ret;
792
793 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_CONTEXT);
794
795 _EGL_CHECK_DISPLAY(disp, EGL_NO_CONTEXT, drv);
796
797 if (config != EGL_NO_CONFIG_KHR)
798 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_CONTEXT, drv);
799 else if (!disp->Extensions.KHR_no_config_context)
800 RETURN_EGL_ERROR(disp, EGL_BAD_CONFIG, EGL_NO_CONTEXT);
801
802 if (!share && share_list != EGL_NO_CONTEXT)
803 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_CONTEXT);
804
805 context = drv->CreateContext(disp, conf, share, attrib_list);
806 ret = (context) ? _eglLinkContext(context) : EGL_NO_CONTEXT;
807
808 RETURN_EGL_EVAL(disp, ret);
809 }
810
811
812 EGLBoolean EGLAPIENTRY
813 eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
814 {
815 _EGLDisplay *disp = _eglLockDisplay(dpy);
816 _EGLContext *context = _eglLookupContext(ctx, disp);
817 const _EGLDriver *drv;
818 EGLBoolean ret;
819
820 _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE);
821
822 _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv);
823 _eglUnlinkContext(context);
824 ret = drv->DestroyContext(disp, context);
825
826 RETURN_EGL_EVAL(disp, ret);
827 }
828
829
830 EGLBoolean EGLAPIENTRY
831 eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read,
832 EGLContext ctx)
833 {
834 _EGLDisplay *disp = _eglLockDisplay(dpy);
835 _EGLContext *context = _eglLookupContext(ctx, disp);
836 _EGLSurface *draw_surf = _eglLookupSurface(draw, disp);
837 _EGLSurface *read_surf = _eglLookupSurface(read, disp);
838 const _EGLDriver *drv;
839 EGLBoolean ret;
840
841 _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE);
842
843 if (!disp)
844 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE);
845 drv = disp->Driver;
846
847 /* display is allowed to be uninitialized under certain condition */
848 if (!disp->Initialized) {
849 if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE ||
850 ctx != EGL_NO_CONTEXT)
851 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE);
852 }
853 if (!drv)
854 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
855
856 if (!context && ctx != EGL_NO_CONTEXT)
857 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE);
858 if (!draw_surf || !read_surf) {
859 /* From the EGL 1.4 (20130211) spec:
860 *
861 * To release the current context without assigning a new one, set ctx
862 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
863 */
864 if (!disp->Extensions.KHR_surfaceless_context && ctx != EGL_NO_CONTEXT)
865 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
866
867 if ((!draw_surf && draw != EGL_NO_SURFACE) ||
868 (!read_surf && read != EGL_NO_SURFACE))
869 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
870 if (draw_surf || read_surf)
871 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
872 }
873
874 /* If a native window underlying either draw or read is no longer valid,
875 * an EGL_BAD_NATIVE_WINDOW error is generated.
876 */
877 if (draw_surf && draw_surf->Lost)
878 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_FALSE);
879 if (read_surf && read_surf->Lost)
880 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_FALSE);
881
882 ret = drv->MakeCurrent(drv, disp, draw_surf, read_surf, context);
883
884 RETURN_EGL_EVAL(disp, ret);
885 }
886
887
888 EGLBoolean EGLAPIENTRY
889 eglQueryContext(EGLDisplay dpy, EGLContext ctx,
890 EGLint attribute, EGLint *value)
891 {
892 _EGLDisplay *disp = _eglLockDisplay(dpy);
893 _EGLContext *context = _eglLookupContext(ctx, disp);
894 const _EGLDriver *drv;
895 EGLBoolean ret;
896
897 _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE);
898
899 _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv);
900
901 ret = _eglQueryContext(drv, disp, context, attribute, value);
902
903 RETURN_EGL_EVAL(disp, ret);
904 }
905
906
907 /* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says
908 * that if native_surface was already used to create a window or pixmap, we
909 * can't create a new one. This is what this function checks for.
910 */
911 static bool
912 _eglNativeSurfaceAlreadyUsed(_EGLDisplay *disp, void *native_surface)
913 {
914 _EGLResource *list;
915
916 list = disp->ResourceLists[_EGL_RESOURCE_SURFACE];
917 while (list) {
918 _EGLSurface *surf = (_EGLSurface *) list;
919
920 list = list->Next;
921
922 if (surf->Type == EGL_PBUFFER_BIT)
923 continue;
924
925 if (surf->NativeSurface == native_surface)
926 return true;
927 }
928
929 return false;
930 }
931
932
933 static EGLSurface
934 _eglCreateWindowSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
935 void *native_window, const EGLint *attrib_list)
936 {
937 _EGLConfig *conf = _eglLookupConfig(config, disp);
938 const _EGLDriver *drv;
939 _EGLSurface *surf;
940 EGLSurface ret;
941
942
943 if (native_window == NULL)
944 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
945
946 if (disp && (disp->Platform == _EGL_PLATFORM_SURFACELESS ||
947 disp->Platform == _EGL_PLATFORM_DEVICE)) {
948 /* From the EGL_MESA_platform_surfaceless spec (v1):
949 *
950 * eglCreatePlatformWindowSurface fails when called with a <display>
951 * that belongs to the surfaceless platform. It returns
952 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
953 * justification for this unconditional failure is that the
954 * surfaceless platform has no native windows, and therefore the
955 * <native_window> parameter is always invalid.
956 *
957 * This check must occur before checking the EGLConfig, which emits
958 * EGL_BAD_CONFIG.
959 */
960 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
961 }
962
963 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
964
965 if ((conf->SurfaceType & EGL_WINDOW_BIT) == 0)
966 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE);
967
968 if (_eglNativeSurfaceAlreadyUsed(disp, native_window))
969 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE);
970
971 surf = drv->CreateWindowSurface(drv, disp, conf, native_window,
972 attrib_list);
973 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
974
975 RETURN_EGL_EVAL(disp, ret);
976 }
977
978
979 EGLSurface EGLAPIENTRY
980 eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
981 EGLNativeWindowType window, const EGLint *attrib_list)
982 {
983 _EGLDisplay *disp = _eglLockDisplay(dpy);
984
985 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
986 STATIC_ASSERT(sizeof(void*) == sizeof(window));
987 return _eglCreateWindowSurfaceCommon(disp, config, (void*) window,
988 attrib_list);
989 }
990
991 static void *
992 _fixupNativeWindow(_EGLDisplay *disp, void *native_window)
993 {
994 #ifdef HAVE_X11_PLATFORM
995 if (disp && disp->Platform == _EGL_PLATFORM_X11 && native_window != NULL) {
996 /* The `native_window` parameter for the X11 platform differs between
997 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
998 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
999 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
1000 * `Window*`. Convert `Window*` to `Window` because that's what
1001 * dri2_x11_create_window_surface() expects.
1002 */
1003 return (void *)(* (Window*) native_window);
1004 }
1005 #endif
1006 return native_window;
1007 }
1008
1009 static EGLSurface EGLAPIENTRY
1010 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config,
1011 void *native_window,
1012 const EGLint *attrib_list)
1013 {
1014 _EGLDisplay *disp = _eglLockDisplay(dpy);
1015
1016 native_window = _fixupNativeWindow(disp, native_window);
1017
1018 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1019 return _eglCreateWindowSurfaceCommon(disp, config, native_window,
1020 attrib_list);
1021 }
1022
1023
1024 EGLSurface EGLAPIENTRY
1025 eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config,
1026 void *native_window,
1027 const EGLAttrib *attrib_list)
1028 {
1029 _EGLDisplay *disp = _eglLockDisplay(dpy);
1030 EGLSurface surface;
1031 EGLint *int_attribs;
1032
1033 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1034
1035 int_attribs = _eglConvertAttribsToInt(attrib_list);
1036 if (attrib_list && !int_attribs)
1037 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE);
1038
1039 native_window = _fixupNativeWindow(disp, native_window);
1040 surface = _eglCreateWindowSurfaceCommon(disp, config, native_window,
1041 int_attribs);
1042 free(int_attribs);
1043 return surface;
1044 }
1045
1046 static void *
1047 _fixupNativePixmap(_EGLDisplay *disp, void *native_pixmap)
1048 {
1049 #ifdef HAVE_X11_PLATFORM
1050 /* The `native_pixmap` parameter for the X11 platform differs between
1051 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1052 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1053 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1054 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1055 * dri2_x11_create_pixmap_surface() expects.
1056 */
1057 if (disp && disp->Platform == _EGL_PLATFORM_X11 && native_pixmap != NULL)
1058 return (void *)(* (Pixmap*) native_pixmap);
1059 #endif
1060 return native_pixmap;
1061 }
1062
1063 static EGLSurface
1064 _eglCreatePixmapSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
1065 void *native_pixmap, const EGLint *attrib_list)
1066 {
1067 _EGLConfig *conf = _eglLookupConfig(config, disp);
1068 const _EGLDriver *drv;
1069 _EGLSurface *surf;
1070 EGLSurface ret;
1071
1072 if (disp && (disp->Platform == _EGL_PLATFORM_SURFACELESS ||
1073 disp->Platform == _EGL_PLATFORM_DEVICE)) {
1074 /* From the EGL_MESA_platform_surfaceless spec (v1):
1075 *
1076 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1077 * also fails when called with a <display> that belongs to the
1078 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1079 * EGL_BAD_NATIVE_PIXMAP.
1080 *
1081 * This check must occur before checking the EGLConfig, which emits
1082 * EGL_BAD_CONFIG.
1083 */
1084 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE);
1085 }
1086
1087 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
1088
1089 if ((conf->SurfaceType & EGL_PIXMAP_BIT) == 0)
1090 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE);
1091
1092 if (native_pixmap == NULL)
1093 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE);
1094
1095 if (_eglNativeSurfaceAlreadyUsed(disp, native_pixmap))
1096 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE);
1097
1098 surf = drv->CreatePixmapSurface(drv, disp, conf, native_pixmap,
1099 attrib_list);
1100 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
1101
1102 RETURN_EGL_EVAL(disp, ret);
1103 }
1104
1105
1106 EGLSurface EGLAPIENTRY
1107 eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config,
1108 EGLNativePixmapType pixmap, const EGLint *attrib_list)
1109 {
1110 _EGLDisplay *disp = _eglLockDisplay(dpy);
1111
1112 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1113 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap));
1114 return _eglCreatePixmapSurfaceCommon(disp, config, (void*) pixmap,
1115 attrib_list);
1116 }
1117
1118 static EGLSurface EGLAPIENTRY
1119 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config,
1120 void *native_pixmap,
1121 const EGLint *attrib_list)
1122 {
1123 _EGLDisplay *disp = _eglLockDisplay(dpy);
1124
1125 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1126 native_pixmap = _fixupNativePixmap(disp, native_pixmap);
1127 return _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap,
1128 attrib_list);
1129 }
1130
1131
1132 EGLSurface EGLAPIENTRY
1133 eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config,
1134 void *native_pixmap,
1135 const EGLAttrib *attrib_list)
1136 {
1137 _EGLDisplay *disp = _eglLockDisplay(dpy);
1138 EGLSurface surface;
1139 EGLint *int_attribs;
1140
1141 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1142
1143 int_attribs = _eglConvertAttribsToInt(attrib_list);
1144 if (attrib_list && !int_attribs)
1145 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE);
1146
1147 native_pixmap = _fixupNativePixmap(disp, native_pixmap);
1148 surface = _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap,
1149 int_attribs);
1150 free(int_attribs);
1151 return surface;
1152 }
1153
1154
1155 EGLSurface EGLAPIENTRY
1156 eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,
1157 const EGLint *attrib_list)
1158 {
1159 _EGLDisplay *disp = _eglLockDisplay(dpy);
1160 _EGLConfig *conf = _eglLookupConfig(config, disp);
1161 const _EGLDriver *drv;
1162 _EGLSurface *surf;
1163 EGLSurface ret;
1164
1165 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1166 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
1167
1168 if ((conf->SurfaceType & EGL_PBUFFER_BIT) == 0)
1169 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE);
1170
1171 surf = drv->CreatePbufferSurface(drv, disp, conf, attrib_list);
1172 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
1173
1174 RETURN_EGL_EVAL(disp, ret);
1175 }
1176
1177
1178 EGLBoolean EGLAPIENTRY
1179 eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
1180 {
1181 _EGLDisplay *disp = _eglLockDisplay(dpy);
1182 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1183 const _EGLDriver *drv;
1184 EGLBoolean ret;
1185
1186 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1187 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1188 _eglUnlinkSurface(surf);
1189 ret = drv->DestroySurface(drv, disp, surf);
1190
1191 RETURN_EGL_EVAL(disp, ret);
1192 }
1193
1194 EGLBoolean EGLAPIENTRY
1195 eglQuerySurface(EGLDisplay dpy, EGLSurface surface,
1196 EGLint attribute, EGLint *value)
1197 {
1198 _EGLDisplay *disp = _eglLockDisplay(dpy);
1199 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1200 const _EGLDriver *drv;
1201 EGLBoolean ret;
1202
1203 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1204 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1205
1206 if (drv->QuerySurface)
1207 ret = drv->QuerySurface(drv, disp, surf, attribute, value);
1208 else
1209 ret = _eglQuerySurface(drv, disp, surf, attribute, value);
1210
1211 RETURN_EGL_EVAL(disp, ret);
1212 }
1213
1214 EGLBoolean EGLAPIENTRY
1215 eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface,
1216 EGLint attribute, EGLint value)
1217 {
1218 _EGLDisplay *disp = _eglLockDisplay(dpy);
1219 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1220 const _EGLDriver *drv;
1221 EGLBoolean ret;
1222
1223 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1224 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1225
1226 ret = _eglSurfaceAttrib(drv, disp, surf, attribute, value);
1227
1228 RETURN_EGL_EVAL(disp, ret);
1229 }
1230
1231
1232 EGLBoolean EGLAPIENTRY
1233 eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1234 {
1235 _EGLDisplay *disp = _eglLockDisplay(dpy);
1236 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1237 const _EGLDriver *drv;
1238 EGLBoolean ret;
1239
1240 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1241 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1242 ret = drv->BindTexImage(drv, disp, surf, buffer);
1243
1244 RETURN_EGL_EVAL(disp, ret);
1245 }
1246
1247
1248 EGLBoolean EGLAPIENTRY
1249 eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1250 {
1251 _EGLDisplay *disp = _eglLockDisplay(dpy);
1252 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1253 const _EGLDriver *drv;
1254 EGLBoolean ret;
1255
1256 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1257 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1258 ret = drv->ReleaseTexImage(drv, disp, surf, buffer);
1259
1260 RETURN_EGL_EVAL(disp, ret);
1261 }
1262
1263
1264 EGLBoolean EGLAPIENTRY
1265 eglSwapInterval(EGLDisplay dpy, EGLint interval)
1266 {
1267 _EGLDisplay *disp = _eglLockDisplay(dpy);
1268 _EGLContext *ctx = _eglGetCurrentContext();
1269 _EGLSurface *surf = ctx ? ctx->DrawSurface : NULL;
1270 const _EGLDriver *drv;
1271 EGLBoolean ret;
1272
1273 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1274 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1275
1276 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1277 ctx->Resource.Display != disp)
1278 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE);
1279
1280 if (_eglGetSurfaceHandle(surf) == EGL_NO_SURFACE)
1281 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1282
1283 if (surf->Type != EGL_WINDOW_BIT)
1284 RETURN_EGL_EVAL(disp, EGL_TRUE);
1285
1286 interval = CLAMP(interval,
1287 surf->Config->MinSwapInterval,
1288 surf->Config->MaxSwapInterval);
1289
1290 if (surf->SwapInterval != interval) {
1291 if (drv->SwapInterval)
1292 ret = drv->SwapInterval(drv, disp, surf, interval);
1293 else
1294 ret = _eglSwapInterval(drv, disp, surf, interval);
1295 }
1296 else {
1297 ret = EGL_TRUE;
1298 }
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 const _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->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 const EGLint *rects, EGLint n_rects)
1356 {
1357 _EGLContext *ctx = _eglGetCurrentContext();
1358 const _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->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 const 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 const 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 const _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->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 const _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->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 const _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->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 const _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->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 const _EGLDriver *drv;
1688
1689 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1690
1691 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
1692
1693 /* OpenVG is not supported */
1694 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE);
1695 }
1696
1697
1698 EGLBoolean EGLAPIENTRY
1699 eglReleaseThread(void)
1700 {
1701 /* unbind current contexts */
1702 if (!_eglIsCurrentThreadDummy()) {
1703 _EGLThreadInfo *t = _eglGetCurrentThread();
1704 _EGLContext *ctx = t->CurrentContext;
1705
1706 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE);
1707
1708 if (ctx) {
1709 _EGLDisplay *disp = ctx->Resource.Display;
1710 const _EGLDriver *drv;
1711
1712 mtx_lock(&disp->Mutex);
1713 drv = disp->Driver;
1714 (void) drv->MakeCurrent(drv, disp, NULL, NULL, NULL);
1715 mtx_unlock(&disp->Mutex);
1716 }
1717 }
1718
1719 _eglDestroyCurrentThread();
1720
1721 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1722 }
1723
1724
1725 static EGLImage
1726 _eglCreateImageCommon(_EGLDisplay *disp, EGLContext ctx, EGLenum target,
1727 EGLClientBuffer buffer, const EGLint *attr_list)
1728 {
1729 _EGLContext *context = _eglLookupContext(ctx, disp);
1730 const _EGLDriver *drv;
1731 _EGLImage *img;
1732 EGLImage ret;
1733
1734 _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv);
1735 if (!disp->Extensions.KHR_image_base)
1736 RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR);
1737 if (!context && ctx != EGL_NO_CONTEXT)
1738 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR);
1739 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1740 * <ctx> must be EGL_NO_CONTEXT..."
1741 */
1742 if (ctx != EGL_NO_CONTEXT && target == EGL_LINUX_DMA_BUF_EXT)
1743 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
1744
1745 img = drv->CreateImageKHR(drv, disp, context, target,
1746 buffer, attr_list);
1747 ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR;
1748
1749 RETURN_EGL_EVAL(disp, ret);
1750 }
1751
1752 static EGLImage EGLAPIENTRY
1753 eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1754 EGLClientBuffer buffer, const EGLint *attr_list)
1755 {
1756 _EGLDisplay *disp = _eglLockDisplay(dpy);
1757 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_IMAGE_KHR);
1758 return _eglCreateImageCommon(disp, ctx, target, buffer, attr_list);
1759 }
1760
1761
1762 EGLImage EGLAPIENTRY
1763 eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1764 EGLClientBuffer buffer, const EGLAttrib *attr_list)
1765 {
1766 _EGLDisplay *disp = _eglLockDisplay(dpy);
1767 EGLImage image;
1768 EGLint *int_attribs;
1769
1770 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_IMAGE_KHR);
1771
1772 int_attribs = _eglConvertAttribsToInt(attr_list);
1773 if (attr_list && !int_attribs)
1774 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_IMAGE);
1775
1776 image = _eglCreateImageCommon(disp, ctx, target, buffer, int_attribs);
1777 free(int_attribs);
1778 return image;
1779 }
1780
1781
1782 static EGLBoolean
1783 _eglDestroyImageCommon(_EGLDisplay *disp, _EGLImage *img)
1784 {
1785 const _EGLDriver *drv;
1786 EGLBoolean ret;
1787
1788 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1789 if (!disp->Extensions.KHR_image_base)
1790 RETURN_EGL_EVAL(disp, EGL_FALSE);
1791 if (!img)
1792 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1793
1794 _eglUnlinkImage(img);
1795 ret = drv->DestroyImageKHR(drv, disp, img);
1796
1797 RETURN_EGL_EVAL(disp, ret);
1798 }
1799
1800 EGLBoolean EGLAPIENTRY
1801 eglDestroyImage(EGLDisplay dpy, EGLImage image)
1802 {
1803 _EGLDisplay *disp = _eglLockDisplay(dpy);
1804 _EGLImage *img = _eglLookupImage(image, disp);
1805 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
1806 return _eglDestroyImageCommon(disp, img);
1807 }
1808
1809 static EGLBoolean EGLAPIENTRY
1810 eglDestroyImageKHR(EGLDisplay dpy, EGLImage image)
1811 {
1812 _EGLDisplay *disp = _eglLockDisplay(dpy);
1813 _EGLImage *img = _eglLookupImage(image, disp);
1814 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
1815 return _eglDestroyImageCommon(disp, img);
1816 }
1817
1818
1819 static EGLSync
1820 _eglCreateSync(_EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_list,
1821 EGLBoolean orig_is_EGLAttrib,
1822 EGLenum invalid_type_error)
1823 {
1824 _EGLContext *ctx = _eglGetCurrentContext();
1825 const _EGLDriver *drv;
1826 _EGLSync *sync;
1827 EGLSync ret;
1828
1829 _EGL_CHECK_DISPLAY(disp, EGL_NO_SYNC_KHR, drv);
1830
1831 if (!disp->Extensions.KHR_cl_event2 && orig_is_EGLAttrib) {
1832 /* There exist two EGLAttrib variants of eglCreateSync*:
1833 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1834 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1835 * support as a proxy for EGL 1.5 support, even though that's not
1836 * entirely correct (though _eglComputeVersion does the same).
1837 *
1838 * The EGL spec provides no guidance on how to handle unsupported
1839 * functions. EGL_BAD_MATCH seems reasonable.
1840 */
1841 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
1842 }
1843
1844 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1845 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1846 * error is generated.
1847 */
1848 if (!ctx &&
1849 (type == EGL_SYNC_FENCE_KHR || type == EGL_SYNC_NATIVE_FENCE_ANDROID))
1850 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
1851
1852 /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */
1853 if (ctx && (ctx->Resource.Display != disp ||
1854 (ctx->ClientAPI != EGL_OPENGL_ES_API &&
1855 ctx->ClientAPI != EGL_OPENGL_API)))
1856 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
1857
1858 switch (type) {
1859 case EGL_SYNC_FENCE_KHR:
1860 if (!disp->Extensions.KHR_fence_sync)
1861 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1862 break;
1863 case EGL_SYNC_REUSABLE_KHR:
1864 if (!disp->Extensions.KHR_reusable_sync)
1865 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1866 break;
1867 case EGL_SYNC_CL_EVENT_KHR:
1868 if (!disp->Extensions.KHR_cl_event2)
1869 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1870 break;
1871 case EGL_SYNC_NATIVE_FENCE_ANDROID:
1872 if (!disp->Extensions.ANDROID_native_fence_sync)
1873 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1874 break;
1875 default:
1876 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1877 }
1878
1879 sync = drv->CreateSyncKHR(drv, disp, type, attrib_list);
1880 ret = (sync) ? _eglLinkSync(sync) : EGL_NO_SYNC_KHR;
1881
1882 RETURN_EGL_EVAL(disp, ret);
1883 }
1884
1885
1886 static EGLSync EGLAPIENTRY
1887 eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *int_list)
1888 {
1889 _EGLDisplay *disp = _eglLockDisplay(dpy);
1890 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1891
1892 EGLSync sync;
1893 EGLAttrib *attrib_list;
1894 EGLint err;
1895
1896 if (sizeof(int_list[0]) == sizeof(attrib_list[0])) {
1897 attrib_list = (EGLAttrib *) int_list;
1898 } else {
1899 err = _eglConvertIntsToAttribs(int_list, &attrib_list);
1900 if (err != EGL_SUCCESS)
1901 RETURN_EGL_ERROR(disp, err, EGL_NO_SYNC);
1902 }
1903
1904 sync = _eglCreateSync(disp, type, attrib_list, EGL_FALSE,
1905 EGL_BAD_ATTRIBUTE);
1906
1907 if (sizeof(int_list[0]) != sizeof(attrib_list[0]))
1908 free(attrib_list);
1909
1910 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1911 return sync;
1912 }
1913
1914
1915 static EGLSync EGLAPIENTRY
1916 eglCreateSync64KHR(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
1917 {
1918 _EGLDisplay *disp = _eglLockDisplay(dpy);
1919 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1920 return _eglCreateSync(disp, type, attrib_list, EGL_TRUE,
1921 EGL_BAD_ATTRIBUTE);
1922 }
1923
1924
1925 EGLSync EGLAPIENTRY
1926 eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
1927 {
1928 _EGLDisplay *disp = _eglLockDisplay(dpy);
1929 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1930 return _eglCreateSync(disp, type, attrib_list, EGL_TRUE,
1931 EGL_BAD_PARAMETER);
1932 }
1933
1934
1935 static EGLBoolean
1936 _eglDestroySync(_EGLDisplay *disp, _EGLSync *s)
1937 {
1938 const _EGLDriver *drv;
1939 EGLBoolean ret;
1940
1941 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1942 assert(disp->Extensions.KHR_reusable_sync ||
1943 disp->Extensions.KHR_fence_sync ||
1944 disp->Extensions.ANDROID_native_fence_sync);
1945
1946 _eglUnlinkSync(s);
1947 ret = drv->DestroySyncKHR(drv, disp, s);
1948
1949 RETURN_EGL_EVAL(disp, ret);
1950 }
1951
1952 EGLBoolean EGLAPIENTRY
1953 eglDestroySync(EGLDisplay dpy, EGLSync sync)
1954 {
1955 _EGLDisplay *disp = _eglLockDisplay(dpy);
1956 _EGLSync *s = _eglLookupSync(sync, disp);
1957 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1958 return _eglDestroySync(disp, s);
1959 }
1960
1961 static EGLBoolean EGLAPIENTRY
1962 eglDestroySyncKHR(EGLDisplay dpy, EGLSync sync)
1963 {
1964 _EGLDisplay *disp = _eglLockDisplay(dpy);
1965 _EGLSync *s = _eglLookupSync(sync, disp);
1966 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1967 return _eglDestroySync(disp, s);
1968 }
1969
1970
1971 static EGLint
1972 _eglClientWaitSyncCommon(_EGLDisplay *disp, EGLDisplay dpy,
1973 _EGLSync *s, EGLint flags, EGLTime timeout)
1974 {
1975 const _EGLDriver *drv;
1976 EGLint ret;
1977
1978 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1979 assert(disp->Extensions.KHR_reusable_sync ||
1980 disp->Extensions.KHR_fence_sync ||
1981 disp->Extensions.ANDROID_native_fence_sync);
1982
1983 if (s->SyncStatus == EGL_SIGNALED_KHR)
1984 RETURN_EGL_EVAL(disp, EGL_CONDITION_SATISFIED_KHR);
1985
1986 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1987 * unlocked here to allow other threads also to be able to
1988 * go into waiting state.
1989 */
1990
1991 if (s->Type == EGL_SYNC_REUSABLE_KHR)
1992 _eglUnlockDisplay(dpy);
1993
1994 ret = drv->ClientWaitSyncKHR(drv, disp, s, flags, timeout);
1995
1996 /*
1997 * 'disp' is already unlocked for reusable sync type,
1998 * so passing 'NULL' to bypass unlocking display.
1999 */
2000 if (s->Type == EGL_SYNC_REUSABLE_KHR)
2001 RETURN_EGL_EVAL(NULL, ret);
2002 else
2003 RETURN_EGL_EVAL(disp, ret);
2004 }
2005
2006 EGLint EGLAPIENTRY
2007 eglClientWaitSync(EGLDisplay dpy, EGLSync sync,
2008 EGLint flags, EGLTime timeout)
2009 {
2010 _EGLDisplay *disp = _eglLockDisplay(dpy);
2011 _EGLSync *s = _eglLookupSync(sync, disp);
2012 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2013 return _eglClientWaitSyncCommon(disp, dpy, s, flags, timeout);
2014 }
2015
2016 static EGLint EGLAPIENTRY
2017 eglClientWaitSyncKHR(EGLDisplay dpy, EGLSync sync,
2018 EGLint flags, EGLTime timeout)
2019 {
2020 _EGLDisplay *disp = _eglLockDisplay(dpy);
2021 _EGLSync *s = _eglLookupSync(sync, disp);
2022 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2023 return _eglClientWaitSyncCommon(disp, dpy, s, flags, timeout);
2024 }
2025
2026
2027 static EGLint
2028 _eglWaitSyncCommon(_EGLDisplay *disp, _EGLSync *s, EGLint flags)
2029 {
2030 _EGLContext *ctx = _eglGetCurrentContext();
2031 const _EGLDriver *drv;
2032 EGLint ret;
2033
2034 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
2035 assert(disp->Extensions.KHR_wait_sync);
2036
2037 /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */
2038 if (ctx == EGL_NO_CONTEXT ||
2039 (ctx->ClientAPI != EGL_OPENGL_ES_API &&
2040 ctx->ClientAPI != EGL_OPENGL_API))
2041 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
2042
2043 /* the API doesn't allow any flags yet */
2044 if (flags != 0)
2045 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2046
2047 ret = drv->WaitSyncKHR(drv, disp, s);
2048
2049 RETURN_EGL_EVAL(disp, ret);
2050 }
2051
2052 static EGLint EGLAPIENTRY
2053 eglWaitSyncKHR(EGLDisplay dpy, EGLSync sync, EGLint flags)
2054 {
2055 _EGLDisplay *disp = _eglLockDisplay(dpy);
2056 _EGLSync *s = _eglLookupSync(sync, disp);
2057 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2058 return _eglWaitSyncCommon(disp, s, flags);
2059 }
2060
2061
2062 EGLBoolean EGLAPIENTRY
2063 eglWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags)
2064 {
2065 /* The KHR version returns EGLint, while the core version returns
2066 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2067 * EGL_TRUE.
2068 */
2069 _EGLDisplay *disp = _eglLockDisplay(dpy);
2070 _EGLSync *s = _eglLookupSync(sync, disp);
2071 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2072 return _eglWaitSyncCommon(disp, s, flags);
2073 }
2074
2075
2076 static EGLBoolean EGLAPIENTRY
2077 eglSignalSyncKHR(EGLDisplay dpy, EGLSync sync, EGLenum mode)
2078 {
2079 _EGLDisplay *disp = _eglLockDisplay(dpy);
2080 _EGLSync *s = _eglLookupSync(sync, disp);
2081 const _EGLDriver *drv;
2082 EGLBoolean ret;
2083
2084 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2085
2086 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
2087 assert(disp->Extensions.KHR_reusable_sync);
2088 ret = drv->SignalSyncKHR(drv, disp, s, mode);
2089
2090 RETURN_EGL_EVAL(disp, ret);
2091 }
2092
2093
2094 static EGLBoolean
2095 _eglGetSyncAttribCommon(_EGLDisplay *disp, _EGLSync *s, EGLint attribute, EGLAttrib *value)
2096 {
2097 const _EGLDriver *drv;
2098 EGLBoolean ret;
2099
2100 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
2101 assert(disp->Extensions.KHR_reusable_sync ||
2102 disp->Extensions.KHR_fence_sync ||
2103 disp->Extensions.ANDROID_native_fence_sync);
2104
2105 ret = _eglGetSyncAttrib(drv, disp, s, attribute, value);
2106
2107 RETURN_EGL_EVAL(disp, ret);
2108 }
2109
2110 EGLBoolean EGLAPIENTRY
2111 eglGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value)
2112 {
2113 _EGLDisplay *disp = _eglLockDisplay(dpy);
2114 _EGLSync *s = _eglLookupSync(sync, disp);
2115 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2116
2117 if (!value)
2118 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2119
2120 return _eglGetSyncAttribCommon(disp, s, attribute, value);
2121 }
2122
2123
2124 static EGLBoolean EGLAPIENTRY
2125 eglGetSyncAttribKHR(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLint *value)
2126 {
2127 _EGLDisplay *disp = _eglLockDisplay(dpy);
2128 _EGLSync *s = _eglLookupSync(sync, disp);
2129 EGLAttrib attrib;
2130 EGLBoolean result;
2131
2132 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2133
2134 if (!value)
2135 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2136
2137 attrib = *value;
2138 result = _eglGetSyncAttribCommon(disp, s, attribute, &attrib);
2139
2140 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2141 *
2142 * If any error occurs, <*value> is not modified.
2143 */
2144 if (result == EGL_FALSE)
2145 return result;
2146
2147 *value = attrib;
2148 return result;
2149 }
2150
2151 static EGLint EGLAPIENTRY
2152 eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSync sync)
2153 {
2154 _EGLDisplay *disp = _eglLockDisplay(dpy);
2155 _EGLSync *s = _eglLookupSync(sync, disp);
2156 const _EGLDriver *drv;
2157 EGLBoolean ret;
2158
2159 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2160
2161 /* the spec doesn't seem to specify what happens if the fence
2162 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2163 * sensible:
2164 */
2165 if (!(s && (s->Type == EGL_SYNC_NATIVE_FENCE_ANDROID)))
2166 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_NO_NATIVE_FENCE_FD_ANDROID);
2167
2168 _EGL_CHECK_SYNC(disp, s, EGL_NO_NATIVE_FENCE_FD_ANDROID, drv);
2169 assert(disp->Extensions.ANDROID_native_fence_sync);
2170 ret = drv->DupNativeFenceFDANDROID(drv, disp, s);
2171
2172 RETURN_EGL_EVAL(disp, ret);
2173 }
2174
2175 static EGLBoolean EGLAPIENTRY
2176 eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface,
2177 EGLint numRects, const EGLint *rects)
2178 {
2179 _EGLContext *ctx = _eglGetCurrentContext();
2180 _EGLDisplay *disp = _eglLockDisplay(dpy);
2181 _EGLSurface *surf = _eglLookupSurface(surface, disp);
2182 const _EGLDriver *drv;
2183 EGLBoolean ret;
2184
2185 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
2186
2187 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
2188
2189 if (!disp->Extensions.NOK_swap_region)
2190 RETURN_EGL_EVAL(disp, EGL_FALSE);
2191
2192 /* surface must be bound to current context in EGL 1.4 */
2193 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
2194 surf != ctx->DrawSurface)
2195 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
2196
2197 ret = drv->SwapBuffersRegionNOK(drv, disp, surf, numRects, rects);
2198
2199 RETURN_EGL_EVAL(disp, ret);
2200 }
2201
2202
2203 static EGLImage EGLAPIENTRY
2204 eglCreateDRMImageMESA(EGLDisplay dpy, const EGLint *attr_list)
2205 {
2206 _EGLDisplay *disp = _eglLockDisplay(dpy);
2207 const _EGLDriver *drv;
2208 _EGLImage *img;
2209 EGLImage ret;
2210
2211 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
2212
2213 _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv);
2214 if (!disp->Extensions.MESA_drm_image)
2215 RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR);
2216
2217 img = drv->CreateDRMImageMESA(drv, disp, attr_list);
2218 ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR;
2219
2220 RETURN_EGL_EVAL(disp, ret);
2221 }
2222
2223 static EGLBoolean EGLAPIENTRY
2224 eglExportDRMImageMESA(EGLDisplay dpy, EGLImage image,
2225 EGLint *name, EGLint *handle, EGLint *stride)
2226 {
2227 _EGLDisplay *disp = _eglLockDisplay(dpy);
2228 _EGLImage *img = _eglLookupImage(image, disp);
2229 const _EGLDriver *drv;
2230 EGLBoolean ret;
2231
2232 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
2233
2234 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2235 assert(disp->Extensions.MESA_drm_image);
2236
2237 if (!img)
2238 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2239
2240 ret = drv->ExportDRMImageMESA(drv, disp, img, name, handle, stride);
2241
2242 RETURN_EGL_EVAL(disp, ret);
2243 }
2244
2245
2246 struct wl_display;
2247
2248 static EGLBoolean EGLAPIENTRY
2249 eglBindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
2250 {
2251 _EGLDisplay *disp = _eglLockDisplay(dpy);
2252 const _EGLDriver *drv;
2253 EGLBoolean ret;
2254
2255 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
2256
2257 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2258 assert(disp->Extensions.WL_bind_wayland_display);
2259
2260 if (!display)
2261 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2262
2263 ret = drv->BindWaylandDisplayWL(drv, disp, display);
2264
2265 RETURN_EGL_EVAL(disp, ret);
2266 }
2267
2268 static EGLBoolean EGLAPIENTRY
2269 eglUnbindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
2270 {
2271 _EGLDisplay *disp = _eglLockDisplay(dpy);
2272 const _EGLDriver *drv;
2273 EGLBoolean ret;
2274
2275 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
2276
2277 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2278 assert(disp->Extensions.WL_bind_wayland_display);
2279
2280 if (!display)
2281 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2282
2283 ret = drv->UnbindWaylandDisplayWL(drv, disp, display);
2284
2285 RETURN_EGL_EVAL(disp, ret);
2286 }
2287
2288 static EGLBoolean EGLAPIENTRY
2289 eglQueryWaylandBufferWL(EGLDisplay dpy, struct wl_resource *buffer,
2290 EGLint attribute, EGLint *value)
2291 {
2292 _EGLDisplay *disp = _eglLockDisplay(dpy);
2293 const _EGLDriver *drv;
2294 EGLBoolean ret;
2295
2296 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
2297
2298 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2299 assert(disp->Extensions.WL_bind_wayland_display);
2300
2301 if (!buffer)
2302 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2303
2304 ret = drv->QueryWaylandBufferWL(drv, disp, buffer, attribute, value);
2305
2306 RETURN_EGL_EVAL(disp, ret);
2307 }
2308
2309
2310 static struct wl_buffer * EGLAPIENTRY
2311 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy, EGLImage image)
2312 {
2313 _EGLDisplay *disp = _eglLockDisplay(dpy);
2314 _EGLImage *img;
2315 const _EGLDriver *drv;
2316 struct wl_buffer *ret;
2317
2318 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
2319
2320 _EGL_CHECK_DISPLAY(disp, NULL, drv);
2321 if (!disp->Extensions.WL_create_wayland_buffer_from_image)
2322 RETURN_EGL_EVAL(disp, NULL);
2323
2324 img = _eglLookupImage(image, disp);
2325
2326 if (!img)
2327 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL);
2328
2329 ret = drv->CreateWaylandBufferFromImageWL(drv, disp, img);
2330
2331 RETURN_EGL_EVAL(disp, ret);
2332 }
2333
2334 static EGLBoolean EGLAPIENTRY
2335 eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface,
2336 EGLint x, EGLint y, EGLint width, EGLint height)
2337 {
2338 _EGLDisplay *disp = _eglLockDisplay(dpy);
2339 _EGLSurface *surf = _eglLookupSurface(surface, disp);
2340 const _EGLDriver *drv;
2341 EGLBoolean ret;
2342
2343 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
2344
2345 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
2346
2347 if (!disp->Extensions.NV_post_sub_buffer)
2348 RETURN_EGL_EVAL(disp, EGL_FALSE);
2349
2350 ret = drv->PostSubBufferNV(drv, disp, surf, x, y, width, height);
2351
2352 RETURN_EGL_EVAL(disp, ret);
2353 }
2354
2355 static EGLBoolean EGLAPIENTRY
2356 eglGetSyncValuesCHROMIUM(EGLDisplay dpy, EGLSurface surface,
2357 EGLuint64KHR *ust, EGLuint64KHR *msc,
2358 EGLuint64KHR *sbc)
2359 {
2360 _EGLDisplay *disp = _eglLockDisplay(dpy);
2361 _EGLSurface *surf = _eglLookupSurface(surface, disp);
2362 const _EGLDriver *drv;
2363 EGLBoolean ret;
2364
2365 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
2366
2367 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
2368 if (!disp->Extensions.CHROMIUM_sync_control)
2369 RETURN_EGL_EVAL(disp, EGL_FALSE);
2370
2371 if (!ust || !msc || !sbc)
2372 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2373
2374 ret = drv->GetSyncValuesCHROMIUM(disp, surf, ust, msc, sbc);
2375
2376 RETURN_EGL_EVAL(disp, ret);
2377 }
2378
2379 static EGLBoolean EGLAPIENTRY
2380 eglExportDMABUFImageQueryMESA(EGLDisplay dpy, EGLImage image,
2381 EGLint *fourcc, EGLint *nplanes,
2382 EGLuint64KHR *modifiers)
2383 {
2384 _EGLDisplay *disp = _eglLockDisplay(dpy);
2385 _EGLImage *img = _eglLookupImage(image, disp);
2386 const _EGLDriver *drv;
2387 EGLBoolean ret;
2388
2389 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
2390
2391 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2392 assert(disp->Extensions.MESA_image_dma_buf_export);
2393
2394 if (!img)
2395 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2396
2397 ret = drv->ExportDMABUFImageQueryMESA(drv, disp, img, fourcc, nplanes,
2398 modifiers);
2399
2400 RETURN_EGL_EVAL(disp, ret);
2401 }
2402
2403 static EGLBoolean EGLAPIENTRY
2404 eglExportDMABUFImageMESA(EGLDisplay dpy, EGLImage image,
2405 int *fds, EGLint *strides, EGLint *offsets)
2406 {
2407 _EGLDisplay *disp = _eglLockDisplay(dpy);
2408 _EGLImage *img = _eglLookupImage(image, disp);
2409 const _EGLDriver *drv;
2410 EGLBoolean ret;
2411
2412 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
2413
2414 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2415 assert(disp->Extensions.MESA_image_dma_buf_export);
2416
2417 if (!img)
2418 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2419
2420 ret = drv->ExportDMABUFImageMESA(drv, disp, img, fds, strides, offsets);
2421
2422 RETURN_EGL_EVAL(disp, ret);
2423 }
2424
2425 static EGLint EGLAPIENTRY
2426 eglLabelObjectKHR(EGLDisplay dpy, EGLenum objectType, EGLObjectKHR object,
2427 EGLLabelKHR label)
2428 {
2429 _EGLDisplay *disp = NULL;
2430 _EGLResourceType type;
2431
2432 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC);
2433
2434 if (objectType == EGL_OBJECT_THREAD_KHR) {
2435 _EGLThreadInfo *t = _eglGetCurrentThread();
2436
2437 if (!_eglIsCurrentThreadDummy()) {
2438 t->Label = label;
2439 return EGL_SUCCESS;
2440 }
2441
2442 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_BAD_ALLOC);
2443 }
2444
2445 disp = _eglLockDisplay(dpy);
2446 if (disp == NULL)
2447 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_BAD_DISPLAY);
2448
2449 if (objectType == EGL_OBJECT_DISPLAY_KHR) {
2450 if (dpy != (EGLDisplay) object)
2451 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER);
2452
2453 disp->Label = label;
2454 RETURN_EGL_EVAL(disp, EGL_SUCCESS);
2455 }
2456
2457 switch (objectType) {
2458 case EGL_OBJECT_CONTEXT_KHR:
2459 type = _EGL_RESOURCE_CONTEXT;
2460 break;
2461 case EGL_OBJECT_SURFACE_KHR:
2462 type = _EGL_RESOURCE_SURFACE;
2463 break;
2464 case EGL_OBJECT_IMAGE_KHR:
2465 type = _EGL_RESOURCE_IMAGE;
2466 break;
2467 case EGL_OBJECT_SYNC_KHR:
2468 type = _EGL_RESOURCE_SYNC;
2469 break;
2470 case EGL_OBJECT_STREAM_KHR:
2471 default:
2472 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER);
2473 }
2474
2475 if (_eglCheckResource(object, type, disp)) {
2476 _EGLResource *res = (_EGLResource *) object;
2477
2478 res->Label = label;
2479 RETURN_EGL_EVAL(disp, EGL_SUCCESS);
2480 }
2481
2482 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER);
2483 }
2484
2485 static EGLint EGLAPIENTRY
2486 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback,
2487 const EGLAttrib *attrib_list)
2488 {
2489 unsigned int newEnabled;
2490
2491 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC);
2492
2493 mtx_lock(_eglGlobal.Mutex);
2494
2495 newEnabled = _eglGlobal.debugTypesEnabled;
2496 if (attrib_list != NULL) {
2497 int i;
2498
2499 for (i = 0; attrib_list[i] != EGL_NONE; i += 2) {
2500 switch (attrib_list[i]) {
2501 case EGL_DEBUG_MSG_CRITICAL_KHR:
2502 case EGL_DEBUG_MSG_ERROR_KHR:
2503 case EGL_DEBUG_MSG_WARN_KHR:
2504 case EGL_DEBUG_MSG_INFO_KHR:
2505 if (attrib_list[i + 1])
2506 newEnabled |= DebugBitFromType(attrib_list[i]);
2507 else
2508 newEnabled &= ~DebugBitFromType(attrib_list[i]);
2509 break;
2510 default:
2511 // On error, set the last error code, call the current
2512 // debug callback, and return the error code.
2513 mtx_unlock(_eglGlobal.Mutex);
2514 _eglReportError(EGL_BAD_ATTRIBUTE, NULL,
2515 "Invalid attribute 0x%04lx", (unsigned long) attrib_list[i]);
2516 return EGL_BAD_ATTRIBUTE;
2517 }
2518 }
2519 }
2520
2521 if (callback != NULL) {
2522 _eglGlobal.debugCallback = callback;
2523 _eglGlobal.debugTypesEnabled = newEnabled;
2524 } else {
2525 _eglGlobal.debugCallback = NULL;
2526 _eglGlobal.debugTypesEnabled = _EGL_DEBUG_BIT_CRITICAL | _EGL_DEBUG_BIT_ERROR;
2527 }
2528
2529 mtx_unlock(_eglGlobal.Mutex);
2530 return EGL_SUCCESS;
2531 }
2532
2533 static EGLBoolean EGLAPIENTRY
2534 eglQueryDebugKHR(EGLint attribute, EGLAttrib *value)
2535 {
2536 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC);
2537
2538 mtx_lock(_eglGlobal.Mutex);
2539
2540 switch (attribute) {
2541 case EGL_DEBUG_MSG_CRITICAL_KHR:
2542 case EGL_DEBUG_MSG_ERROR_KHR:
2543 case EGL_DEBUG_MSG_WARN_KHR:
2544 case EGL_DEBUG_MSG_INFO_KHR:
2545 if (_eglGlobal.debugTypesEnabled & DebugBitFromType(attribute))
2546 *value = EGL_TRUE;
2547 else
2548 *value = EGL_FALSE;
2549 break;
2550 case EGL_DEBUG_CALLBACK_KHR:
2551 *value = (EGLAttrib) _eglGlobal.debugCallback;
2552 break;
2553 default:
2554 mtx_unlock(_eglGlobal.Mutex);
2555 _eglReportError(EGL_BAD_ATTRIBUTE, NULL,
2556 "Invalid attribute 0x%04lx", (unsigned long) attribute);
2557 return EGL_FALSE;
2558 }
2559
2560 mtx_unlock(_eglGlobal.Mutex);
2561 return EGL_TRUE;
2562 }
2563
2564 static int
2565 _eglFunctionCompare(const void *key, const void *elem)
2566 {
2567 const char *procname = key;
2568 const struct _egl_entrypoint *entrypoint = elem;
2569 return strcmp(procname, entrypoint->name);
2570 }
2571
2572 static EGLBoolean EGLAPIENTRY
2573 eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint max_formats,
2574 EGLint *formats, EGLint *num_formats)
2575 {
2576 _EGLDisplay *disp = _eglLockDisplay(dpy);
2577 const _EGLDriver *drv;
2578 EGLBoolean ret;
2579
2580 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
2581
2582 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2583
2584 ret = drv->QueryDmaBufFormatsEXT(drv, disp, max_formats, formats,
2585 num_formats);
2586
2587 RETURN_EGL_EVAL(disp, ret);
2588 }
2589
2590 static EGLBoolean EGLAPIENTRY
2591 eglQueryDmaBufModifiersEXT(EGLDisplay dpy, EGLint format, EGLint max_modifiers,
2592 EGLuint64KHR *modifiers, EGLBoolean *external_only,
2593 EGLint *num_modifiers)
2594 {
2595 _EGLDisplay *disp = _eglLockDisplay(dpy);
2596 const _EGLDriver *drv;
2597 EGLBoolean ret;
2598
2599 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
2600
2601 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2602
2603 ret = drv->QueryDmaBufModifiersEXT(drv, disp, format, max_modifiers,
2604 modifiers, external_only,
2605 num_modifiers);
2606
2607 RETURN_EGL_EVAL(disp, ret);
2608 }
2609
2610 static void EGLAPIENTRY
2611 eglSetBlobCacheFuncsANDROID(EGLDisplay *dpy, EGLSetBlobFuncANDROID set,
2612 EGLGetBlobFuncANDROID get)
2613 {
2614 /* This function does not return anything so we cannot
2615 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2616 */
2617 _EGLDisplay *disp = _eglLockDisplay(dpy);
2618 if (!_eglSetFuncName(__func__, disp, EGL_OBJECT_DISPLAY_KHR, NULL)) {
2619 if (disp)
2620 _eglUnlockDisplay(disp);
2621 return;
2622 }
2623
2624 const _EGLDriver *drv = _eglCheckDisplay(disp, __func__);
2625 if (!drv) {
2626 if (disp)
2627 _eglUnlockDisplay(disp);
2628 return;
2629 }
2630
2631 if (!set || !get) {
2632 _eglError(EGL_BAD_PARAMETER,
2633 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2634 _eglUnlockDisplay(disp);
2635 return;
2636 }
2637
2638 if (disp->BlobCacheSet) {
2639 _eglError(EGL_BAD_PARAMETER,
2640 "eglSetBlobCacheFuncsANDROID: functions already set");
2641 _eglUnlockDisplay(disp);
2642 return;
2643 }
2644
2645 disp->BlobCacheSet = set;
2646 disp->BlobCacheGet = get;
2647
2648 drv->SetBlobCacheFuncsANDROID(drv, disp, set, get);
2649
2650 _eglUnlockDisplay(disp);
2651 }
2652
2653 static EGLBoolean EGLAPIENTRY
2654 eglQueryDeviceAttribEXT(EGLDeviceEXT device,
2655 EGLint attribute,
2656 EGLAttrib *value)
2657 {
2658 _EGLDevice *dev = _eglLookupDevice(device);
2659 EGLBoolean ret;
2660
2661 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
2662 if (!dev)
2663 RETURN_EGL_ERROR(NULL, EGL_BAD_DEVICE_EXT, EGL_FALSE);
2664
2665 ret = _eglQueryDeviceAttribEXT(dev, attribute, value);
2666 RETURN_EGL_EVAL(NULL, ret);
2667 }
2668
2669 static const char * EGLAPIENTRY
2670 eglQueryDeviceStringEXT(EGLDeviceEXT device,
2671 EGLint name)
2672 {
2673 _EGLDevice *dev = _eglLookupDevice(device);
2674
2675 _EGL_FUNC_START(NULL, EGL_NONE, NULL, NULL);
2676 if (!dev)
2677 RETURN_EGL_ERROR(NULL, EGL_BAD_DEVICE_EXT, NULL);
2678
2679 RETURN_EGL_EVAL(NULL, _eglQueryDeviceStringEXT(dev, name));
2680 }
2681
2682 static EGLBoolean EGLAPIENTRY
2683 eglQueryDevicesEXT(EGLint max_devices,
2684 EGLDeviceEXT *devices,
2685 EGLint *num_devices)
2686 {
2687 EGLBoolean ret;
2688
2689 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
2690 ret = _eglQueryDevicesEXT(max_devices, (_EGLDevice **) devices,
2691 num_devices);
2692 RETURN_EGL_EVAL(NULL, ret);
2693 }
2694
2695 static EGLBoolean EGLAPIENTRY
2696 eglQueryDisplayAttribEXT(EGLDisplay dpy,
2697 EGLint attribute,
2698 EGLAttrib *value)
2699 {
2700 _EGLDisplay *disp = _eglLockDisplay(dpy);
2701 const _EGLDriver *drv;
2702
2703 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
2704 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2705
2706 switch (attribute) {
2707 case EGL_DEVICE_EXT:
2708 *value = (EGLAttrib) disp->Device;
2709 break;
2710 default:
2711 RETURN_EGL_ERROR(disp, EGL_BAD_ATTRIBUTE, EGL_FALSE);
2712 }
2713 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
2714 }
2715
2716 static char * EGLAPIENTRY
2717 eglGetDisplayDriverConfig(EGLDisplay dpy)
2718 {
2719 _EGLDisplay *disp = _eglLockDisplay(dpy);
2720 const _EGLDriver *drv;
2721 char *ret;
2722
2723 _EGL_FUNC_START(disp, EGL_NONE, NULL, NULL);
2724 _EGL_CHECK_DISPLAY(disp, NULL, drv);
2725
2726 assert(disp->Extensions.MESA_query_driver);
2727
2728 ret = drv->QueryDriverConfig(disp);
2729 RETURN_EGL_EVAL(disp, ret);
2730 }
2731
2732 static const char * EGLAPIENTRY
2733 eglGetDisplayDriverName(EGLDisplay dpy)
2734 {
2735 _EGLDisplay *disp = _eglLockDisplay(dpy);
2736 const _EGLDriver *drv;
2737 const char *ret;
2738
2739 _EGL_FUNC_START(disp, EGL_NONE, NULL, NULL);
2740 _EGL_CHECK_DISPLAY(disp, NULL, drv);
2741
2742 assert(disp->Extensions.MESA_query_driver);
2743
2744 ret = drv->QueryDriverName(disp);
2745 RETURN_EGL_EVAL(disp, ret);
2746 }
2747
2748 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2749 eglGetProcAddress(const char *procname)
2750 {
2751 static const struct _egl_entrypoint egl_functions[] = {
2752 #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
2753 #include "eglentrypoint.h"
2754 #undef EGL_ENTRYPOINT
2755 };
2756 _EGLProc ret = NULL;
2757
2758 if (!procname)
2759 RETURN_EGL_SUCCESS(NULL, NULL);
2760
2761 _EGL_FUNC_START(NULL, EGL_NONE, NULL, NULL);
2762
2763 if (strncmp(procname, "egl", 3) == 0) {
2764 const struct _egl_entrypoint *entrypoint =
2765 bsearch(procname,
2766 egl_functions, ARRAY_SIZE(egl_functions),
2767 sizeof(egl_functions[0]),
2768 _eglFunctionCompare);
2769 if (entrypoint)
2770 ret = entrypoint->function;
2771 }
2772
2773 if (!ret)
2774 ret = _eglGetDriverProc(procname);
2775
2776 RETURN_EGL_SUCCESS(NULL, ret);
2777 }
2778
2779 static int
2780 _eglLockDisplayInterop(EGLDisplay dpy, EGLContext context,
2781 _EGLDisplay **disp, const _EGLDriver **drv,
2782 _EGLContext **ctx)
2783 {
2784
2785 *disp = _eglLockDisplay(dpy);
2786 if (!*disp || !(*disp)->Initialized || !(*disp)->Driver) {
2787 if (*disp)
2788 _eglUnlockDisplay(*disp);
2789 return MESA_GLINTEROP_INVALID_DISPLAY;
2790 }
2791
2792 *drv = (*disp)->Driver;
2793
2794 *ctx = _eglLookupContext(context, *disp);
2795 if (!*ctx ||
2796 ((*ctx)->ClientAPI != EGL_OPENGL_API &&
2797 (*ctx)->ClientAPI != EGL_OPENGL_ES_API)) {
2798 _eglUnlockDisplay(*disp);
2799 return MESA_GLINTEROP_INVALID_CONTEXT;
2800 }
2801
2802 return MESA_GLINTEROP_SUCCESS;
2803 }
2804
2805 PUBLIC int
2806 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy, EGLContext context,
2807 struct mesa_glinterop_device_info *out)
2808 {
2809 _EGLDisplay *disp;
2810 const _EGLDriver *drv;
2811 _EGLContext *ctx;
2812 int ret;
2813
2814 ret = _eglLockDisplayInterop(dpy, context, &disp, &drv, &ctx);
2815 if (ret != MESA_GLINTEROP_SUCCESS)
2816 return ret;
2817
2818 if (drv->GLInteropQueryDeviceInfo)
2819 ret = drv->GLInteropQueryDeviceInfo(disp, ctx, out);
2820 else
2821 ret = MESA_GLINTEROP_UNSUPPORTED;
2822
2823 _eglUnlockDisplay(disp);
2824 return ret;
2825 }
2826
2827 PUBLIC int
2828 MesaGLInteropEGLExportObject(EGLDisplay dpy, EGLContext context,
2829 struct mesa_glinterop_export_in *in,
2830 struct mesa_glinterop_export_out *out)
2831 {
2832 _EGLDisplay *disp;
2833 const _EGLDriver *drv;
2834 _EGLContext *ctx;
2835 int ret;
2836
2837 ret = _eglLockDisplayInterop(dpy, context, &disp, &drv, &ctx);
2838 if (ret != MESA_GLINTEROP_SUCCESS)
2839 return ret;
2840
2841 if (drv->GLInteropExportObject)
2842 ret = drv->GLInteropExportObject(disp, ctx, in, out);
2843 else
2844 ret = MESA_GLINTEROP_UNSUPPORTED;
2845
2846 _eglUnlockDisplay(disp);
2847 return ret;
2848 }