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