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