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