egl: add eglSwapBuffersWithDamageKHR
[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 #include <stdio.h>
87 #include <stdlib.h>
88 #include <string.h>
89 #include "c99_compat.h"
90 #include "c11/threads.h"
91 #include "GL/mesa_glinterop.h"
92 #include "eglcompiler.h"
93
94 #include "eglglobals.h"
95 #include "eglcontext.h"
96 #include "egldisplay.h"
97 #include "egltypedefs.h"
98 #include "eglcurrent.h"
99 #include "egldriver.h"
100 #include "eglsurface.h"
101 #include "eglconfig.h"
102 #include "eglimage.h"
103 #include "eglsync.h"
104
105
106 /**
107 * Macros to help return an API entrypoint.
108 *
109 * These macros will unlock the display and record the error code.
110 */
111 #define RETURN_EGL_ERROR(disp, err, ret) \
112 do { \
113 if (disp) \
114 _eglUnlockDisplay(disp); \
115 /* EGL error codes are non-zero */ \
116 if (err) \
117 _eglError(err, __func__); \
118 return ret; \
119 } while (0)
120
121 #define RETURN_EGL_SUCCESS(disp, ret) \
122 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
123
124 /* record EGL_SUCCESS only when ret evaluates to true */
125 #define RETURN_EGL_EVAL(disp, ret) \
126 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
127
128
129 /*
130 * A bunch of macros and checks to simplify error checking.
131 */
132
133 #define _EGL_CHECK_DISPLAY(disp, ret, drv) \
134 do { \
135 drv = _eglCheckDisplay(disp, __func__); \
136 if (!drv) \
137 RETURN_EGL_ERROR(disp, 0, ret); \
138 } while (0)
139
140 #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
141 do { \
142 drv = _eglCheck ## type(disp, obj, __func__); \
143 if (!drv) \
144 RETURN_EGL_ERROR(disp, 0, ret); \
145 } while (0)
146
147 #define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
148 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
149
150 #define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
151 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
152
153 #define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
154 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
155
156 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
157 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
158
159
160 static inline _EGLDriver *
161 _eglCheckDisplay(_EGLDisplay *disp, const char *msg)
162 {
163 if (!disp) {
164 _eglError(EGL_BAD_DISPLAY, msg);
165 return NULL;
166 }
167 if (!disp->Initialized) {
168 _eglError(EGL_NOT_INITIALIZED, msg);
169 return NULL;
170 }
171 return disp->Driver;
172 }
173
174
175 static inline _EGLDriver *
176 _eglCheckSurface(_EGLDisplay *disp, _EGLSurface *surf, const char *msg)
177 {
178 _EGLDriver *drv = _eglCheckDisplay(disp, msg);
179 if (!drv)
180 return NULL;
181 if (!surf) {
182 _eglError(EGL_BAD_SURFACE, msg);
183 return NULL;
184 }
185 return drv;
186 }
187
188
189 static inline _EGLDriver *
190 _eglCheckContext(_EGLDisplay *disp, _EGLContext *context, const char *msg)
191 {
192 _EGLDriver *drv = _eglCheckDisplay(disp, msg);
193 if (!drv)
194 return NULL;
195 if (!context) {
196 _eglError(EGL_BAD_CONTEXT, msg);
197 return NULL;
198 }
199 return drv;
200 }
201
202
203 static inline _EGLDriver *
204 _eglCheckConfig(_EGLDisplay *disp, _EGLConfig *conf, const char *msg)
205 {
206 _EGLDriver *drv = _eglCheckDisplay(disp, msg);
207 if (!drv)
208 return NULL;
209 if (!conf) {
210 _eglError(EGL_BAD_CONFIG, msg);
211 return NULL;
212 }
213 return drv;
214 }
215
216
217 static inline _EGLDriver *
218 _eglCheckSync(_EGLDisplay *disp, _EGLSync *s, const char *msg)
219 {
220 _EGLDriver *drv = _eglCheckDisplay(disp, msg);
221 if (!drv)
222 return NULL;
223 if (!s) {
224 _eglError(EGL_BAD_PARAMETER, msg);
225 return NULL;
226 }
227 return drv;
228 }
229
230
231 /**
232 * Lookup and lock a display.
233 */
234 static inline _EGLDisplay *
235 _eglLockDisplay(EGLDisplay display)
236 {
237 _EGLDisplay *dpy = _eglLookupDisplay(display);
238 if (dpy)
239 mtx_lock(&dpy->Mutex);
240 return dpy;
241 }
242
243
244 /**
245 * Unlock a display.
246 */
247 static inline void
248 _eglUnlockDisplay(_EGLDisplay *dpy)
249 {
250 mtx_unlock(&dpy->Mutex);
251 }
252
253 static EGLBoolean
254 _eglSetFuncName(const char *funcName, _EGLDisplay *disp, EGLenum objectType, _EGLResource *object)
255 {
256 _EGLThreadInfo *thr = _eglGetCurrentThread();
257 if (!_eglIsCurrentThreadDummy()) {
258 thr->CurrentFuncName = funcName;
259 thr->CurrentObjectLabel = NULL;
260
261 if (objectType == EGL_OBJECT_THREAD_KHR)
262 thr->CurrentObjectLabel = thr->Label;
263 else if (objectType == EGL_OBJECT_DISPLAY_KHR && disp)
264 thr->CurrentObjectLabel = disp->Label;
265 else if (object)
266 thr->CurrentObjectLabel = object->Label;
267
268 return EGL_TRUE;
269 }
270
271 _eglDebugReportFull(EGL_BAD_ALLOC, funcName, funcName,
272 EGL_DEBUG_MSG_CRITICAL_KHR, NULL, NULL);
273 return EGL_FALSE;
274 }
275
276 #define _EGL_FUNC_START(disp, objectType, object, ret) \
277 do { \
278 if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \
279 if (disp) \
280 _eglUnlockDisplay(disp); \
281 return ret; \
282 } \
283 } while(0)
284
285 /**
286 * Convert an attribute list from EGLint[] to EGLAttrib[].
287 *
288 * Return an EGL error code. The output parameter out_attrib_list is modified
289 * only on success.
290 */
291 EGLint
292 _eglConvertIntsToAttribs(const EGLint *int_list, EGLAttrib **out_attrib_list)
293 {
294 size_t len = 0;
295 EGLAttrib *attrib_list;
296
297 if (int_list) {
298 while (int_list[2*len] != EGL_NONE)
299 ++len;
300 }
301
302 if (len == 0) {
303 *out_attrib_list = NULL;
304 return EGL_SUCCESS;
305 }
306
307 if (2*len + 1 > SIZE_MAX / sizeof(EGLAttrib))
308 return EGL_BAD_ALLOC;
309
310 attrib_list = malloc((2*len + 1) * sizeof(EGLAttrib));
311 if (!attrib_list)
312 return EGL_BAD_ALLOC;
313
314 for (size_t i = 0; i < len; ++i) {
315 attrib_list[2*i + 0] = int_list[2*i + 0];
316 attrib_list[2*i + 1] = int_list[2*i + 1];
317 }
318
319 attrib_list[2*len] = EGL_NONE;
320
321 *out_attrib_list = attrib_list;
322 return EGL_SUCCESS;
323 }
324
325
326 static EGLint *
327 _eglConvertAttribsToInt(const EGLAttrib *attr_list)
328 {
329 EGLint *int_attribs = NULL;
330
331 /* Convert attributes from EGLAttrib[] to EGLint[] */
332 if (attr_list) {
333 int i, size = 0;
334
335 while (attr_list[size] != EGL_NONE)
336 size += 2;
337
338 size += 1; /* add space for EGL_NONE */
339
340 int_attribs = calloc(size, sizeof(int_attribs[0]));
341 if (!int_attribs)
342 return NULL;
343
344 for (i = 0; i < size; i++)
345 int_attribs[i] = attr_list[i];
346 }
347 return int_attribs;
348 }
349
350
351 /**
352 * This is typically the first EGL function that an application calls.
353 * It associates a private _EGLDisplay object to the native display.
354 */
355 EGLDisplay EGLAPIENTRY
356 eglGetDisplay(EGLNativeDisplayType nativeDisplay)
357 {
358 _EGLPlatformType plat;
359 _EGLDisplay *dpy;
360 void *native_display_ptr;
361
362 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY);
363
364 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay));
365 native_display_ptr = (void*) nativeDisplay;
366
367 plat = _eglGetNativePlatform(native_display_ptr);
368 dpy = _eglFindDisplay(plat, native_display_ptr);
369 return _eglGetDisplayHandle(dpy);
370 }
371
372 static EGLDisplay
373 _eglGetPlatformDisplayCommon(EGLenum platform, void *native_display,
374 const EGLint *attrib_list)
375 {
376 _EGLDisplay *dpy;
377
378 switch (platform) {
379 #ifdef HAVE_X11_PLATFORM
380 case EGL_PLATFORM_X11_EXT:
381 dpy = _eglGetX11Display((Display*) native_display, attrib_list);
382 break;
383 #endif
384 #ifdef HAVE_DRM_PLATFORM
385 case EGL_PLATFORM_GBM_MESA:
386 dpy = _eglGetGbmDisplay((struct gbm_device*) native_display,
387 attrib_list);
388 break;
389 #endif
390 #ifdef HAVE_WAYLAND_PLATFORM
391 case EGL_PLATFORM_WAYLAND_EXT:
392 dpy = _eglGetWaylandDisplay((struct wl_display*) native_display,
393 attrib_list);
394 break;
395 #endif
396 default:
397 RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, NULL);
398 }
399
400 return _eglGetDisplayHandle(dpy);
401 }
402
403 static EGLDisplay EGLAPIENTRY
404 eglGetPlatformDisplayEXT(EGLenum platform, void *native_display,
405 const EGLint *attrib_list)
406 {
407 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY);
408 return _eglGetPlatformDisplayCommon(platform, native_display, attrib_list);
409 }
410
411 EGLDisplay EGLAPIENTRY
412 eglGetPlatformDisplay(EGLenum platform, void *native_display,
413 const EGLAttrib *attrib_list)
414 {
415 EGLDisplay display;
416 EGLint *int_attribs;
417
418 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY);
419
420 int_attribs = _eglConvertAttribsToInt(attrib_list);
421 if (attrib_list && !int_attribs)
422 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, NULL);
423
424 display = _eglGetPlatformDisplayCommon(platform, native_display, int_attribs);
425 free(int_attribs);
426 return display;
427 }
428
429 /**
430 * Copy the extension into the string and update the string pointer.
431 */
432 static EGLint
433 _eglAppendExtension(char **str, const char *ext)
434 {
435 char *s = *str;
436 size_t len = strlen(ext);
437
438 if (s) {
439 memcpy(s, ext, len);
440 s[len++] = ' ';
441 s[len] = '\0';
442
443 *str += len;
444 }
445 else {
446 len++;
447 }
448
449 return (EGLint) len;
450 }
451
452 /**
453 * Examine the individual extension enable/disable flags and recompute
454 * the driver's Extensions string.
455 */
456 static void
457 _eglCreateExtensionsString(_EGLDisplay *dpy)
458 {
459 #define _EGL_CHECK_EXTENSION(ext) \
460 do { \
461 if (dpy->Extensions.ext) { \
462 _eglAppendExtension(&exts, "EGL_" #ext); \
463 assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
464 } \
465 } while (0)
466
467 char *exts = dpy->ExtensionsString;
468
469 /* Please keep these sorted alphabetically. */
470 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target);
471 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer);
472 _EGL_CHECK_EXTENSION(ANDROID_recordable);
473
474 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control);
475
476 _EGL_CHECK_EXTENSION(EXT_buffer_age);
477 _EGL_CHECK_EXTENSION(EXT_create_context_robustness);
478 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import);
479 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage);
480
481 _EGL_CHECK_EXTENSION(KHR_cl_event2);
482 _EGL_CHECK_EXTENSION(KHR_create_context);
483 _EGL_CHECK_EXTENSION(KHR_fence_sync);
484 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses);
485 _EGL_CHECK_EXTENSION(KHR_gl_colorspace);
486 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image);
487 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image);
488 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image);
489 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image);
490 if (dpy->Extensions.KHR_image_base && dpy->Extensions.KHR_image_pixmap)
491 _eglAppendExtension(&exts, "EGL_KHR_image");
492 _EGL_CHECK_EXTENSION(KHR_image_base);
493 _EGL_CHECK_EXTENSION(KHR_image_pixmap);
494 _EGL_CHECK_EXTENSION(KHR_no_config_context);
495 _EGL_CHECK_EXTENSION(KHR_reusable_sync);
496 _EGL_CHECK_EXTENSION(KHR_surfaceless_context);
497 if (dpy->Extensions.EXT_swap_buffers_with_damage)
498 _eglAppendExtension(&exts, "EGL_KHR_swap_buffers_with_damage");
499 _EGL_CHECK_EXTENSION(KHR_wait_sync);
500
501 if (dpy->Extensions.KHR_no_config_context)
502 _eglAppendExtension(&exts, "EGL_MESA_configless_context");
503 _EGL_CHECK_EXTENSION(MESA_drm_image);
504 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export);
505
506 _EGL_CHECK_EXTENSION(NOK_swap_region);
507 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap);
508
509 _EGL_CHECK_EXTENSION(NV_post_sub_buffer);
510
511 _EGL_CHECK_EXTENSION(WL_bind_wayland_display);
512 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image);
513
514 #undef _EGL_CHECK_EXTENSION
515 }
516
517 static void
518 _eglCreateAPIsString(_EGLDisplay *dpy)
519 {
520 if (dpy->ClientAPIs & EGL_OPENGL_BIT)
521 strcat(dpy->ClientAPIsString, "OpenGL ");
522
523 if (dpy->ClientAPIs & EGL_OPENGL_ES_BIT ||
524 dpy->ClientAPIs & EGL_OPENGL_ES2_BIT ||
525 dpy->ClientAPIs & EGL_OPENGL_ES3_BIT_KHR) {
526 strcat(dpy->ClientAPIsString, "OpenGL_ES ");
527 }
528
529 if (dpy->ClientAPIs & EGL_OPENVG_BIT)
530 strcat(dpy->ClientAPIsString, "OpenVG ");
531
532 assert(strlen(dpy->ClientAPIsString) < sizeof(dpy->ClientAPIsString));
533 }
534
535 static void
536 _eglComputeVersion(_EGLDisplay *disp)
537 {
538 disp->Version = 14;
539
540 if (disp->Extensions.KHR_fence_sync &&
541 disp->Extensions.KHR_cl_event2 &&
542 disp->Extensions.KHR_wait_sync &&
543 disp->Extensions.KHR_image_base &&
544 disp->Extensions.KHR_gl_texture_2D_image &&
545 disp->Extensions.KHR_gl_texture_3D_image &&
546 disp->Extensions.KHR_gl_texture_cubemap_image &&
547 disp->Extensions.KHR_gl_renderbuffer_image &&
548 disp->Extensions.KHR_create_context &&
549 disp->Extensions.EXT_create_context_robustness &&
550 disp->Extensions.KHR_get_all_proc_addresses &&
551 disp->Extensions.KHR_gl_colorspace &&
552 disp->Extensions.KHR_surfaceless_context)
553 disp->Version = 15;
554 }
555
556 /**
557 * This is typically the second EGL function that an application calls.
558 * Here we load/initialize the actual hardware driver.
559 */
560 EGLBoolean EGLAPIENTRY
561 eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
562 {
563 _EGLDisplay *disp = _eglLockDisplay(dpy);
564
565 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
566
567 if (!disp)
568 RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE);
569
570 if (!disp->Initialized) {
571 if (!_eglMatchDriver(disp, EGL_FALSE))
572 RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE);
573
574 /* limit to APIs supported by core */
575 disp->ClientAPIs &= _EGL_API_ALL_BITS;
576
577 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
578 * classifies it as an EGL display extension, though conceptually it's an
579 * EGL client extension.
580 *
581 * From the EGL_KHR_get_all_proc_addresses spec:
582 *
583 * The EGL implementation must expose the name
584 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
585 * EGL_KHR_get_all_proc_addresses and supports
586 * EGL_EXT_client_extensions.
587 *
588 * Mesa unconditionally exposes both client extensions mentioned above,
589 * so the spec requires that each EGLDisplay unconditionally expose
590 * EGL_KHR_get_all_proc_addresses also.
591 */
592 disp->Extensions.KHR_get_all_proc_addresses = EGL_TRUE;
593
594 _eglComputeVersion(disp);
595 _eglCreateExtensionsString(disp);
596 _eglCreateAPIsString(disp);
597 snprintf(disp->VersionString, sizeof(disp->VersionString),
598 "%d.%d (%s)", disp->Version / 10, disp->Version % 10,
599 disp->Driver->Name);
600 }
601
602 /* Update applications version of major and minor if not NULL */
603 if ((major != NULL) && (minor != NULL)) {
604 *major = disp->Version / 10;
605 *minor = disp->Version % 10;
606 }
607
608 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
609 }
610
611
612 EGLBoolean EGLAPIENTRY
613 eglTerminate(EGLDisplay dpy)
614 {
615 _EGLDisplay *disp = _eglLockDisplay(dpy);
616
617 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
618
619 if (!disp)
620 RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE);
621
622 if (disp->Initialized) {
623 _EGLDriver *drv = disp->Driver;
624
625 drv->API.Terminate(drv, disp);
626 /* do not reset disp->Driver */
627 disp->ClientAPIsString[0] = 0;
628 disp->Initialized = EGL_FALSE;
629 }
630
631 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
632 }
633
634
635 const char * EGLAPIENTRY
636 eglQueryString(EGLDisplay dpy, EGLint name)
637 {
638 _EGLDisplay *disp;
639 _EGLDriver *drv;
640
641 if (dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS) {
642 RETURN_EGL_SUCCESS(NULL, _eglGlobal.ClientExtensionString);
643 }
644
645 disp = _eglLockDisplay(dpy);
646 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, NULL);
647 _EGL_CHECK_DISPLAY(disp, NULL, drv);
648
649 switch (name) {
650 case EGL_VENDOR:
651 RETURN_EGL_SUCCESS(disp, _EGL_VENDOR_STRING);
652 case EGL_VERSION:
653 RETURN_EGL_SUCCESS(disp, disp->VersionString);
654 case EGL_EXTENSIONS:
655 RETURN_EGL_SUCCESS(disp, disp->ExtensionsString);
656 case EGL_CLIENT_APIS:
657 RETURN_EGL_SUCCESS(disp, disp->ClientAPIsString);
658 default:
659 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL);
660 }
661 }
662
663
664 EGLBoolean EGLAPIENTRY
665 eglGetConfigs(EGLDisplay dpy, EGLConfig *configs,
666 EGLint config_size, EGLint *num_config)
667 {
668 _EGLDisplay *disp = _eglLockDisplay(dpy);
669 _EGLDriver *drv;
670 EGLBoolean ret;
671
672 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
673
674 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
675 ret = drv->API.GetConfigs(drv, disp, configs, config_size, num_config);
676
677 RETURN_EGL_EVAL(disp, ret);
678 }
679
680
681 EGLBoolean EGLAPIENTRY
682 eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs,
683 EGLint config_size, EGLint *num_config)
684 {
685 _EGLDisplay *disp = _eglLockDisplay(dpy);
686 _EGLDriver *drv;
687 EGLBoolean ret;
688
689 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
690
691 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
692 ret = drv->API.ChooseConfig(drv, disp, attrib_list, configs,
693 config_size, num_config);
694
695 RETURN_EGL_EVAL(disp, ret);
696 }
697
698
699 EGLBoolean EGLAPIENTRY
700 eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
701 EGLint attribute, EGLint *value)
702 {
703 _EGLDisplay *disp = _eglLockDisplay(dpy);
704 _EGLConfig *conf = _eglLookupConfig(config, disp);
705 _EGLDriver *drv;
706 EGLBoolean ret;
707
708 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
709
710 _EGL_CHECK_CONFIG(disp, conf, EGL_FALSE, drv);
711 ret = drv->API.GetConfigAttrib(drv, disp, conf, attribute, value);
712
713 RETURN_EGL_EVAL(disp, ret);
714 }
715
716
717 EGLContext EGLAPIENTRY
718 eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list,
719 const EGLint *attrib_list)
720 {
721 _EGLDisplay *disp = _eglLockDisplay(dpy);
722 _EGLConfig *conf = _eglLookupConfig(config, disp);
723 _EGLContext *share = _eglLookupContext(share_list, disp);
724 _EGLDriver *drv;
725 _EGLContext *context;
726 EGLContext ret;
727
728 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_CONTEXT);
729
730 _EGL_CHECK_DISPLAY(disp, EGL_NO_CONTEXT, drv);
731
732 if (!config && !disp->Extensions.KHR_no_config_context)
733 RETURN_EGL_ERROR(disp, EGL_BAD_CONFIG, EGL_NO_CONTEXT);
734
735 if (!share && share_list != EGL_NO_CONTEXT)
736 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_CONTEXT);
737
738 context = drv->API.CreateContext(drv, disp, conf, share, attrib_list);
739 ret = (context) ? _eglLinkContext(context) : EGL_NO_CONTEXT;
740
741 RETURN_EGL_EVAL(disp, ret);
742 }
743
744
745 EGLBoolean EGLAPIENTRY
746 eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
747 {
748 _EGLDisplay *disp = _eglLockDisplay(dpy);
749 _EGLContext *context = _eglLookupContext(ctx, disp);
750 _EGLDriver *drv;
751 EGLBoolean ret;
752
753 _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE);
754
755 _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv);
756 _eglUnlinkContext(context);
757 ret = drv->API.DestroyContext(drv, disp, context);
758
759 RETURN_EGL_EVAL(disp, ret);
760 }
761
762
763 EGLBoolean EGLAPIENTRY
764 eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read,
765 EGLContext ctx)
766 {
767 _EGLDisplay *disp = _eglLockDisplay(dpy);
768 _EGLContext *context = _eglLookupContext(ctx, disp);
769 _EGLSurface *draw_surf = _eglLookupSurface(draw, disp);
770 _EGLSurface *read_surf = _eglLookupSurface(read, disp);
771 _EGLDriver *drv;
772 EGLBoolean ret;
773
774 _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE);
775
776 if (!disp)
777 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE);
778 drv = disp->Driver;
779
780 /* display is allowed to be uninitialized under certain condition */
781 if (!disp->Initialized) {
782 if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE ||
783 ctx != EGL_NO_CONTEXT)
784 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE);
785 }
786 if (!drv)
787 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
788
789 if (!context && ctx != EGL_NO_CONTEXT)
790 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE);
791 if (!draw_surf || !read_surf) {
792 /* From the EGL 1.4 (20130211) spec:
793 *
794 * To release the current context without assigning a new one, set ctx
795 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
796 */
797 if (!disp->Extensions.KHR_surfaceless_context && ctx != EGL_NO_CONTEXT)
798 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
799
800 if ((!draw_surf && draw != EGL_NO_SURFACE) ||
801 (!read_surf && read != EGL_NO_SURFACE))
802 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
803 if (draw_surf || read_surf)
804 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
805 }
806
807 ret = drv->API.MakeCurrent(drv, disp, draw_surf, read_surf, context);
808
809 RETURN_EGL_EVAL(disp, ret);
810 }
811
812
813 EGLBoolean EGLAPIENTRY
814 eglQueryContext(EGLDisplay dpy, EGLContext ctx,
815 EGLint attribute, EGLint *value)
816 {
817 _EGLDisplay *disp = _eglLockDisplay(dpy);
818 _EGLContext *context = _eglLookupContext(ctx, disp);
819 _EGLDriver *drv;
820 EGLBoolean ret;
821
822 _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE);
823
824 _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv);
825 ret = drv->API.QueryContext(drv, disp, context, attribute, value);
826
827 RETURN_EGL_EVAL(disp, ret);
828 }
829
830
831 static EGLSurface
832 _eglCreateWindowSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
833 void *native_window, const EGLint *attrib_list)
834 {
835 _EGLConfig *conf = _eglLookupConfig(config, disp);
836 _EGLDriver *drv;
837 _EGLSurface *surf;
838 EGLSurface ret;
839
840 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
841
842 if (native_window == NULL)
843 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
844
845 surf = drv->API.CreateWindowSurface(drv, disp, conf, native_window,
846 attrib_list);
847 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
848
849 RETURN_EGL_EVAL(disp, ret);
850 }
851
852
853 EGLSurface EGLAPIENTRY
854 eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
855 EGLNativeWindowType window, const EGLint *attrib_list)
856 {
857 _EGLDisplay *disp = _eglLockDisplay(dpy);
858
859 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
860 STATIC_ASSERT(sizeof(void*) == sizeof(window));
861 return _eglCreateWindowSurfaceCommon(disp, config, (void*) window,
862 attrib_list);
863 }
864
865 static void *
866 fixupNativeWindow(_EGLDisplay *disp, void *native_window)
867 {
868 #ifdef HAVE_X11_PLATFORM
869 if (disp->Platform == _EGL_PLATFORM_X11 && native_window != NULL) {
870 /* The `native_window` parameter for the X11 platform differs between
871 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
872 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
873 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
874 * `Window*`. Convert `Window*` to `Window` because that's what
875 * dri2_x11_create_window_surface() expects.
876 */
877 return (void *)(* (Window*) native_window);
878 }
879 #endif
880 return native_window;
881 }
882
883 static EGLSurface EGLAPIENTRY
884 eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config,
885 void *native_window,
886 const EGLint *attrib_list)
887 {
888 _EGLDisplay *disp = _eglLockDisplay(dpy);
889
890 native_window = fixupNativeWindow(disp, native_window);
891
892 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
893 return _eglCreateWindowSurfaceCommon(disp, config, native_window,
894 attrib_list);
895 }
896
897
898 EGLSurface EGLAPIENTRY
899 eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config,
900 void *native_window,
901 const EGLAttrib *attrib_list)
902 {
903 _EGLDisplay *disp = _eglLockDisplay(dpy);
904 EGLSurface surface;
905 EGLint *int_attribs;
906
907 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
908
909 int_attribs = _eglConvertAttribsToInt(attrib_list);
910 if (attrib_list && !int_attribs)
911 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE);
912
913 native_window = fixupNativeWindow(disp, native_window);
914 surface = _eglCreateWindowSurfaceCommon(disp, config, native_window,
915 int_attribs);
916 free(int_attribs);
917 return surface;
918 }
919
920 static void *
921 fixupNativePixmap(_EGLDisplay *disp, void *native_pixmap)
922 {
923 #ifdef HAVE_X11_PLATFORM
924 /* The `native_pixmap` parameter for the X11 platform differs between
925 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
926 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
927 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
928 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
929 * dri2_x11_create_pixmap_surface() expects.
930 */
931 if (disp->Platform == _EGL_PLATFORM_X11 && native_pixmap != NULL)
932 return (void *)(* (Pixmap*) native_pixmap);
933 #endif
934 return native_pixmap;
935 }
936
937 static EGLSurface
938 _eglCreatePixmapSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
939 void *native_pixmap, const EGLint *attrib_list)
940 {
941 _EGLConfig *conf = _eglLookupConfig(config, disp);
942 _EGLDriver *drv;
943 _EGLSurface *surf;
944 EGLSurface ret;
945
946 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
947 surf = drv->API.CreatePixmapSurface(drv, disp, conf, native_pixmap,
948 attrib_list);
949 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
950
951 RETURN_EGL_EVAL(disp, ret);
952 }
953
954
955 EGLSurface EGLAPIENTRY
956 eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config,
957 EGLNativePixmapType pixmap, const EGLint *attrib_list)
958 {
959 _EGLDisplay *disp = _eglLockDisplay(dpy);
960
961 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
962 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap));
963 return _eglCreatePixmapSurfaceCommon(disp, config, (void*) pixmap,
964 attrib_list);
965 }
966
967 static EGLSurface EGLAPIENTRY
968 eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config,
969 void *native_pixmap,
970 const EGLint *attrib_list)
971 {
972 _EGLDisplay *disp = _eglLockDisplay(dpy);
973
974 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
975 native_pixmap = fixupNativePixmap(disp, native_pixmap);
976 return _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap,
977 attrib_list);
978 }
979
980
981 EGLSurface EGLAPIENTRY
982 eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config,
983 void *native_pixmap,
984 const EGLAttrib *attrib_list)
985 {
986 _EGLDisplay *disp = _eglLockDisplay(dpy);
987 EGLSurface surface;
988 EGLint *int_attribs;
989
990 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
991
992 int_attribs = _eglConvertAttribsToInt(attrib_list);
993 if (attrib_list && !int_attribs)
994 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE);
995
996 native_pixmap = fixupNativePixmap(disp, native_pixmap);
997 surface = _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap,
998 int_attribs);
999 free(int_attribs);
1000 return surface;
1001 }
1002
1003
1004 EGLSurface EGLAPIENTRY
1005 eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,
1006 const EGLint *attrib_list)
1007 {
1008 _EGLDisplay *disp = _eglLockDisplay(dpy);
1009 _EGLConfig *conf = _eglLookupConfig(config, disp);
1010 _EGLDriver *drv;
1011 _EGLSurface *surf;
1012 EGLSurface ret;
1013
1014 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1015 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
1016
1017 surf = drv->API.CreatePbufferSurface(drv, disp, conf, attrib_list);
1018 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
1019
1020 RETURN_EGL_EVAL(disp, ret);
1021 }
1022
1023
1024 EGLBoolean EGLAPIENTRY
1025 eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
1026 {
1027 _EGLDisplay *disp = _eglLockDisplay(dpy);
1028 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1029 _EGLDriver *drv;
1030 EGLBoolean ret;
1031
1032 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1033 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1034 _eglUnlinkSurface(surf);
1035 ret = drv->API.DestroySurface(drv, disp, surf);
1036
1037 RETURN_EGL_EVAL(disp, ret);
1038 }
1039
1040 EGLBoolean EGLAPIENTRY
1041 eglQuerySurface(EGLDisplay dpy, EGLSurface surface,
1042 EGLint attribute, EGLint *value)
1043 {
1044 _EGLDisplay *disp = _eglLockDisplay(dpy);
1045 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1046 _EGLDriver *drv;
1047 EGLBoolean ret;
1048
1049 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1050 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1051 ret = drv->API.QuerySurface(drv, disp, surf, attribute, value);
1052
1053 RETURN_EGL_EVAL(disp, ret);
1054 }
1055
1056 EGLBoolean EGLAPIENTRY
1057 eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface,
1058 EGLint attribute, EGLint value)
1059 {
1060 _EGLDisplay *disp = _eglLockDisplay(dpy);
1061 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1062 _EGLDriver *drv;
1063 EGLBoolean ret;
1064
1065 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1066 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1067 ret = drv->API.SurfaceAttrib(drv, disp, surf, attribute, value);
1068
1069 RETURN_EGL_EVAL(disp, ret);
1070 }
1071
1072
1073 EGLBoolean EGLAPIENTRY
1074 eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1075 {
1076 _EGLDisplay *disp = _eglLockDisplay(dpy);
1077 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1078 _EGLDriver *drv;
1079 EGLBoolean ret;
1080
1081 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1082 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1083 ret = drv->API.BindTexImage(drv, disp, surf, buffer);
1084
1085 RETURN_EGL_EVAL(disp, ret);
1086 }
1087
1088
1089 EGLBoolean EGLAPIENTRY
1090 eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1091 {
1092 _EGLDisplay *disp = _eglLockDisplay(dpy);
1093 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1094 _EGLDriver *drv;
1095 EGLBoolean ret;
1096
1097 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1098 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1099 ret = drv->API.ReleaseTexImage(drv, disp, surf, buffer);
1100
1101 RETURN_EGL_EVAL(disp, ret);
1102 }
1103
1104
1105 EGLBoolean EGLAPIENTRY
1106 eglSwapInterval(EGLDisplay dpy, EGLint interval)
1107 {
1108 _EGLDisplay *disp = _eglLockDisplay(dpy);
1109 _EGLContext *ctx = _eglGetCurrentContext();
1110 _EGLSurface *surf = ctx ? ctx->DrawSurface : NULL;
1111 _EGLDriver *drv;
1112 EGLBoolean ret;
1113
1114 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1115 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1116
1117 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1118 ctx->Resource.Display != disp)
1119 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE);
1120
1121 if (_eglGetSurfaceHandle(surf) == EGL_NO_SURFACE)
1122 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1123
1124 ret = drv->API.SwapInterval(drv, disp, surf, interval);
1125
1126 RETURN_EGL_EVAL(disp, ret);
1127 }
1128
1129
1130 EGLBoolean EGLAPIENTRY
1131 eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
1132 {
1133 _EGLContext *ctx = _eglGetCurrentContext();
1134 _EGLDisplay *disp = _eglLockDisplay(dpy);
1135 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1136 _EGLDriver *drv;
1137 EGLBoolean ret;
1138
1139 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1140 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1141
1142 /* surface must be bound to current context in EGL 1.4 */
1143 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
1144 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1145 surf != ctx->DrawSurface)
1146 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1147 #endif
1148
1149 ret = drv->API.SwapBuffers(drv, disp, surf);
1150
1151 RETURN_EGL_EVAL(disp, ret);
1152 }
1153
1154
1155 static EGLBoolean
1156 eglSwapBuffersWithDamageCommon(_EGLDisplay *disp, _EGLSurface *surf,
1157 EGLint *rects, EGLint n_rects)
1158 {
1159 _EGLContext *ctx = _eglGetCurrentContext();
1160 _EGLDriver *drv;
1161 EGLBoolean ret;
1162
1163 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1164
1165 /* surface must be bound to current context in EGL 1.4 */
1166 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1167 surf != ctx->DrawSurface)
1168 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1169
1170 if ((n_rects > 0 && rects == NULL) || n_rects < 0)
1171 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1172
1173 ret = drv->API.SwapBuffersWithDamageEXT(drv, disp, surf, rects, n_rects);
1174
1175 RETURN_EGL_EVAL(disp, ret);
1176 }
1177
1178 static EGLBoolean EGLAPIENTRY
1179 eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface,
1180 EGLint *rects, EGLint n_rects)
1181 {
1182 _EGLDisplay *disp = _eglLockDisplay(dpy);
1183 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1184 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1185 return eglSwapBuffersWithDamageCommon(disp, surf, rects, n_rects);
1186 }
1187
1188 static EGLBoolean EGLAPIENTRY
1189 eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface,
1190 EGLint *rects, EGLint n_rects)
1191 {
1192 _EGLDisplay *disp = _eglLockDisplay(dpy);
1193 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1194 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1195 return eglSwapBuffersWithDamageCommon(disp, surf, rects, n_rects);
1196 }
1197
1198 EGLBoolean EGLAPIENTRY
1199 eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
1200 {
1201 _EGLDisplay *disp = _eglLockDisplay(dpy);
1202 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1203 _EGLDriver *drv;
1204 EGLBoolean ret;
1205 void *native_pixmap_ptr;
1206
1207 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1208 STATIC_ASSERT(sizeof(void*) == sizeof(target));
1209 native_pixmap_ptr = (void*) target;
1210
1211 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1212 if (disp->Platform != _eglGetNativePlatform(disp->PlatformDisplay))
1213 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_FALSE);
1214 ret = drv->API.CopyBuffers(drv, disp, surf, native_pixmap_ptr);
1215
1216 RETURN_EGL_EVAL(disp, ret);
1217 }
1218
1219
1220 static EGLBoolean
1221 _eglWaitClientCommon(void)
1222 {
1223 _EGLContext *ctx = _eglGetCurrentContext();
1224 _EGLDisplay *disp;
1225 _EGLDriver *drv;
1226 EGLBoolean ret;
1227
1228 if (!ctx)
1229 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1230
1231 disp = ctx->Resource.Display;
1232 mtx_lock(&disp->Mutex);
1233
1234 /* let bad current context imply bad current surface */
1235 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1236 _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE)
1237 RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
1238
1239 /* a valid current context implies an initialized current display */
1240 assert(disp->Initialized);
1241 drv = disp->Driver;
1242 ret = drv->API.WaitClient(drv, disp, ctx);
1243
1244 RETURN_EGL_EVAL(disp, ret);
1245 }
1246
1247 EGLBoolean EGLAPIENTRY
1248 eglWaitClient(void)
1249 {
1250 _EGL_FUNC_START(NULL, EGL_OBJECT_CONTEXT_KHR, _eglGetCurrentContext(), EGL_FALSE);
1251 return _eglWaitClientCommon();
1252 }
1253
1254 EGLBoolean EGLAPIENTRY
1255 eglWaitGL(void)
1256 {
1257 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
1258 _EGL_FUNC_START(NULL, EGL_OBJECT_CONTEXT_KHR, _eglGetCurrentContext(), EGL_FALSE);
1259 return _eglWaitClientCommon();
1260 }
1261
1262
1263 EGLBoolean EGLAPIENTRY
1264 eglWaitNative(EGLint engine)
1265 {
1266 _EGLContext *ctx = _eglGetCurrentContext();
1267 _EGLDisplay *disp;
1268 _EGLDriver *drv;
1269 EGLBoolean ret;
1270
1271 if (!ctx)
1272 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1273
1274 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE);
1275
1276 disp = ctx->Resource.Display;
1277 mtx_lock(&disp->Mutex);
1278
1279 /* let bad current context imply bad current surface */
1280 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1281 _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE)
1282 RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
1283
1284 /* a valid current context implies an initialized current display */
1285 assert(disp->Initialized);
1286 drv = disp->Driver;
1287 ret = drv->API.WaitNative(drv, disp, engine);
1288
1289 RETURN_EGL_EVAL(disp, ret);
1290 }
1291
1292
1293 EGLDisplay EGLAPIENTRY
1294 eglGetCurrentDisplay(void)
1295 {
1296 _EGLContext *ctx = _eglGetCurrentContext();
1297 EGLDisplay ret;
1298
1299 ret = (ctx) ? _eglGetDisplayHandle(ctx->Resource.Display) : EGL_NO_DISPLAY;
1300
1301 RETURN_EGL_SUCCESS(NULL, ret);
1302 }
1303
1304
1305 EGLContext EGLAPIENTRY
1306 eglGetCurrentContext(void)
1307 {
1308 _EGLContext *ctx = _eglGetCurrentContext();
1309 EGLContext ret;
1310
1311 ret = _eglGetContextHandle(ctx);
1312
1313 RETURN_EGL_SUCCESS(NULL, ret);
1314 }
1315
1316
1317 EGLSurface EGLAPIENTRY
1318 eglGetCurrentSurface(EGLint readdraw)
1319 {
1320 _EGLContext *ctx = _eglGetCurrentContext();
1321 EGLint err = EGL_SUCCESS;
1322 _EGLSurface *surf;
1323 EGLSurface ret;
1324
1325 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_NO_SURFACE);
1326
1327 if (!ctx)
1328 RETURN_EGL_SUCCESS(NULL, EGL_NO_SURFACE);
1329
1330 switch (readdraw) {
1331 case EGL_DRAW:
1332 surf = ctx->DrawSurface;
1333 break;
1334 case EGL_READ:
1335 surf = ctx->ReadSurface;
1336 break;
1337 default:
1338 surf = NULL;
1339 err = EGL_BAD_PARAMETER;
1340 break;
1341 }
1342
1343 ret = _eglGetSurfaceHandle(surf);
1344
1345 RETURN_EGL_ERROR(NULL, err, ret);
1346 }
1347
1348
1349 EGLint EGLAPIENTRY
1350 eglGetError(void)
1351 {
1352 _EGLThreadInfo *t = _eglGetCurrentThread();
1353 EGLint e = t->LastError;
1354 if (!_eglIsCurrentThreadDummy())
1355 t->LastError = EGL_SUCCESS;
1356 return e;
1357 }
1358
1359
1360 /**
1361 ** EGL 1.2
1362 **/
1363
1364 /**
1365 * Specify the client API to use for subsequent calls including:
1366 * eglCreateContext()
1367 * eglGetCurrentContext()
1368 * eglGetCurrentDisplay()
1369 * eglGetCurrentSurface()
1370 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1371 * eglWaitClient()
1372 * eglWaitNative()
1373 * See section 3.7 "Rendering Context" in the EGL specification for details.
1374 */
1375 EGLBoolean EGLAPIENTRY
1376 eglBindAPI(EGLenum api)
1377 {
1378 _EGLThreadInfo *t;
1379
1380 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE);
1381
1382 t = _eglGetCurrentThread();
1383 if (_eglIsCurrentThreadDummy())
1384 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_FALSE);
1385
1386 if (!_eglIsApiValid(api))
1387 RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, EGL_FALSE);
1388
1389 t->CurrentAPI = api;
1390
1391 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1392 }
1393
1394
1395 /**
1396 * Return the last value set with eglBindAPI().
1397 */
1398 EGLenum EGLAPIENTRY
1399 eglQueryAPI(void)
1400 {
1401 _EGLThreadInfo *t = _eglGetCurrentThread();
1402 EGLenum ret;
1403
1404 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
1405 ret = t->CurrentAPI;
1406
1407 RETURN_EGL_SUCCESS(NULL, ret);
1408 }
1409
1410
1411 EGLSurface EGLAPIENTRY
1412 eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype,
1413 EGLClientBuffer buffer, EGLConfig config,
1414 const EGLint *attrib_list)
1415 {
1416 _EGLDisplay *disp = _eglLockDisplay(dpy);
1417 _EGLConfig *conf = _eglLookupConfig(config, disp);
1418 _EGLDriver *drv;
1419 _EGLSurface *surf;
1420 EGLSurface ret;
1421
1422 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1423
1424 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
1425
1426 surf = drv->API.CreatePbufferFromClientBuffer(drv, disp, buftype, buffer,
1427 conf, attrib_list);
1428 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
1429
1430 RETURN_EGL_EVAL(disp, ret);
1431 }
1432
1433
1434 EGLBoolean EGLAPIENTRY
1435 eglReleaseThread(void)
1436 {
1437 /* unbind current contexts */
1438 if (!_eglIsCurrentThreadDummy()) {
1439 _EGLThreadInfo *t = _eglGetCurrentThread();
1440 _EGLContext *ctx = t->CurrentContext;
1441
1442 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE);
1443
1444 if (ctx) {
1445 _EGLDisplay *disp = ctx->Resource.Display;
1446 _EGLDriver *drv;
1447
1448 mtx_lock(&disp->Mutex);
1449 drv = disp->Driver;
1450 (void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL);
1451 mtx_unlock(&disp->Mutex);
1452 }
1453 }
1454
1455 _eglDestroyCurrentThread();
1456
1457 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
1458 }
1459
1460
1461 static EGLImage
1462 _eglCreateImageCommon(_EGLDisplay *disp, EGLContext ctx, EGLenum target,
1463 EGLClientBuffer buffer, const EGLint *attr_list)
1464 {
1465 _EGLContext *context = _eglLookupContext(ctx, disp);
1466 _EGLDriver *drv;
1467 _EGLImage *img;
1468 EGLImage ret;
1469
1470 _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv);
1471 if (!disp->Extensions.KHR_image_base)
1472 RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR);
1473 if (!context && ctx != EGL_NO_CONTEXT)
1474 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR);
1475 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1476 * <ctx> must be EGL_NO_CONTEXT..."
1477 */
1478 if (ctx != EGL_NO_CONTEXT && target == EGL_LINUX_DMA_BUF_EXT)
1479 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
1480
1481 img = drv->API.CreateImageKHR(drv,
1482 disp, context, target, buffer, attr_list);
1483 ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR;
1484
1485 RETURN_EGL_EVAL(disp, ret);
1486 }
1487
1488 static EGLImage EGLAPIENTRY
1489 eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1490 EGLClientBuffer buffer, const EGLint *attr_list)
1491 {
1492 _EGLDisplay *disp = _eglLockDisplay(dpy);
1493 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_IMAGE_KHR);
1494 return _eglCreateImageCommon(disp, ctx, target, buffer, attr_list);
1495 }
1496
1497
1498 EGLImage EGLAPIENTRY
1499 eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1500 EGLClientBuffer buffer, const EGLAttrib *attr_list)
1501 {
1502 _EGLDisplay *disp = _eglLockDisplay(dpy);
1503 EGLImage image;
1504 EGLint *int_attribs;
1505
1506 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_IMAGE_KHR);
1507
1508 int_attribs = _eglConvertAttribsToInt(attr_list);
1509 if (attr_list && !int_attribs)
1510 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_IMAGE);
1511
1512 image = _eglCreateImageCommon(disp, ctx, target, buffer, int_attribs);
1513 free(int_attribs);
1514 return image;
1515 }
1516
1517
1518 EGLBoolean EGLAPIENTRY
1519 eglDestroyImage(EGLDisplay dpy, EGLImage image)
1520 {
1521 _EGLDisplay *disp = _eglLockDisplay(dpy);
1522 _EGLImage *img = _eglLookupImage(image, disp);
1523 _EGLDriver *drv;
1524 EGLBoolean ret;
1525
1526 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
1527
1528 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1529 if (!disp->Extensions.KHR_image_base)
1530 RETURN_EGL_EVAL(disp, EGL_FALSE);
1531 if (!img)
1532 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1533
1534 _eglUnlinkImage(img);
1535 ret = drv->API.DestroyImageKHR(drv, disp, img);
1536
1537 RETURN_EGL_EVAL(disp, ret);
1538 }
1539
1540
1541 static EGLSync
1542 _eglCreateSync(_EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_list,
1543 EGLBoolean orig_is_EGLAttrib,
1544 EGLenum invalid_type_error)
1545 {
1546 _EGLContext *ctx = _eglGetCurrentContext();
1547 _EGLDriver *drv;
1548 _EGLSync *sync;
1549 EGLSync ret;
1550
1551 _EGL_CHECK_DISPLAY(disp, EGL_NO_SYNC_KHR, drv);
1552
1553 if (!disp->Extensions.KHR_cl_event2 && orig_is_EGLAttrib) {
1554 /* There exist two EGLAttrib variants of eglCreateSync*:
1555 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1556 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1557 * support as a proxy for EGL 1.5 support, even though that's not
1558 * entirely correct (though _eglComputeVersion does the same).
1559 *
1560 * The EGL spec provides no guidance on how to handle unsupported
1561 * functions. EGL_BAD_MATCH seems reasonable.
1562 */
1563 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
1564 }
1565
1566 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1567 if (!ctx || ctx->Resource.Display != disp ||
1568 ctx->ClientAPI != EGL_OPENGL_ES_API)
1569 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
1570
1571 switch (type) {
1572 case EGL_SYNC_FENCE_KHR:
1573 if (!disp->Extensions.KHR_fence_sync)
1574 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1575 break;
1576 case EGL_SYNC_REUSABLE_KHR:
1577 if (!disp->Extensions.KHR_reusable_sync)
1578 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1579 break;
1580 case EGL_SYNC_CL_EVENT_KHR:
1581 if (!disp->Extensions.KHR_cl_event2)
1582 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1583 break;
1584 default:
1585 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1586 }
1587
1588 sync = drv->API.CreateSyncKHR(drv, disp, type, attrib_list);
1589 ret = (sync) ? _eglLinkSync(sync) : EGL_NO_SYNC_KHR;
1590
1591 RETURN_EGL_EVAL(disp, ret);
1592 }
1593
1594
1595 static EGLSync EGLAPIENTRY
1596 eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *int_list)
1597 {
1598 _EGLDisplay *disp = _eglLockDisplay(dpy);
1599 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1600
1601 EGLSync sync;
1602 EGLAttrib *attrib_list;
1603 EGLint err;
1604
1605 if (sizeof(int_list[0]) == sizeof(attrib_list[0])) {
1606 attrib_list = (EGLAttrib *) int_list;
1607 } else {
1608 err = _eglConvertIntsToAttribs(int_list, &attrib_list);
1609 if (err != EGL_SUCCESS)
1610 RETURN_EGL_ERROR(disp, err, EGL_NO_SYNC);
1611 }
1612
1613 sync = _eglCreateSync(disp, type, attrib_list, EGL_FALSE,
1614 EGL_BAD_ATTRIBUTE);
1615
1616 if (sizeof(int_list[0]) != sizeof(attrib_list[0]))
1617 free(attrib_list);
1618
1619 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1620 return sync;
1621 }
1622
1623
1624 static EGLSync EGLAPIENTRY
1625 eglCreateSync64KHR(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
1626 {
1627 _EGLDisplay *disp = _eglLockDisplay(dpy);
1628 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1629 return _eglCreateSync(disp, type, attrib_list, EGL_TRUE,
1630 EGL_BAD_ATTRIBUTE);
1631 }
1632
1633
1634 EGLSync EGLAPIENTRY
1635 eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
1636 {
1637 _EGLDisplay *disp = _eglLockDisplay(dpy);
1638 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1639 return _eglCreateSync(disp, type, attrib_list, EGL_TRUE,
1640 EGL_BAD_PARAMETER);
1641 }
1642
1643
1644 EGLBoolean EGLAPIENTRY
1645 eglDestroySync(EGLDisplay dpy, EGLSync sync)
1646 {
1647 _EGLDisplay *disp = _eglLockDisplay(dpy);
1648 _EGLSync *s = _eglLookupSync(sync, disp);
1649 _EGLDriver *drv;
1650 EGLBoolean ret;
1651
1652 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1653
1654 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1655 assert(disp->Extensions.KHR_reusable_sync ||
1656 disp->Extensions.KHR_fence_sync);
1657
1658 _eglUnlinkSync(s);
1659 ret = drv->API.DestroySyncKHR(drv, disp, s);
1660
1661 RETURN_EGL_EVAL(disp, ret);
1662 }
1663
1664
1665 EGLint EGLAPIENTRY
1666 eglClientWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout)
1667 {
1668 _EGLDisplay *disp = _eglLockDisplay(dpy);
1669 _EGLSync *s = _eglLookupSync(sync, disp);
1670 _EGLDriver *drv;
1671 EGLint ret;
1672
1673 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1674
1675 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1676 assert(disp->Extensions.KHR_reusable_sync ||
1677 disp->Extensions.KHR_fence_sync);
1678
1679 if (s->SyncStatus == EGL_SIGNALED_KHR)
1680 RETURN_EGL_EVAL(disp, EGL_CONDITION_SATISFIED_KHR);
1681
1682 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1683 * unlocked here to allow other threads also to be able to
1684 * go into waiting state.
1685 */
1686
1687 if (s->Type == EGL_SYNC_REUSABLE_KHR)
1688 _eglUnlockDisplay(dpy);
1689
1690 ret = drv->API.ClientWaitSyncKHR(drv, disp, s, flags, timeout);
1691
1692 /*
1693 * 'disp' is already unlocked for reusable sync type,
1694 * so passing 'NULL' to bypass unlocking display.
1695 */
1696 if (s->Type == EGL_SYNC_REUSABLE_KHR)
1697 RETURN_EGL_EVAL(NULL, ret);
1698 else
1699 RETURN_EGL_EVAL(disp, ret);
1700 }
1701
1702
1703 static EGLint
1704 _eglWaitSyncCommon(_EGLDisplay *disp, _EGLSync *s, EGLint flags)
1705 {
1706 _EGLContext *ctx = _eglGetCurrentContext();
1707 _EGLDriver *drv;
1708 EGLint ret;
1709
1710 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1711 assert(disp->Extensions.KHR_wait_sync);
1712
1713 /* return an error if the client API doesn't support GL_OES_EGL_sync */
1714 if (ctx == EGL_NO_CONTEXT || ctx->ClientAPI != EGL_OPENGL_ES_API)
1715 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
1716
1717 /* the API doesn't allow any flags yet */
1718 if (flags != 0)
1719 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1720
1721 ret = drv->API.WaitSyncKHR(drv, disp, s);
1722
1723 RETURN_EGL_EVAL(disp, ret);
1724 }
1725
1726 static EGLint EGLAPIENTRY
1727 eglWaitSyncKHR(EGLDisplay dpy, EGLSync sync, EGLint flags)
1728 {
1729 _EGLDisplay *disp = _eglLockDisplay(dpy);
1730 _EGLSync *s = _eglLookupSync(sync, disp);
1731 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1732 return _eglWaitSyncCommon(disp, s, flags);
1733 }
1734
1735
1736 EGLBoolean EGLAPIENTRY
1737 eglWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags)
1738 {
1739 /* The KHR version returns EGLint, while the core version returns
1740 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
1741 * EGL_TRUE.
1742 */
1743 _EGLDisplay *disp = _eglLockDisplay(dpy);
1744 _EGLSync *s = _eglLookupSync(sync, disp);
1745 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1746 return _eglWaitSyncCommon(disp, s, flags);
1747 }
1748
1749
1750 static EGLBoolean EGLAPIENTRY
1751 eglSignalSyncKHR(EGLDisplay dpy, EGLSync sync, EGLenum mode)
1752 {
1753 _EGLDisplay *disp = _eglLockDisplay(dpy);
1754 _EGLSync *s = _eglLookupSync(sync, disp);
1755 _EGLDriver *drv;
1756 EGLBoolean ret;
1757
1758 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1759
1760 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1761 assert(disp->Extensions.KHR_reusable_sync);
1762 ret = drv->API.SignalSyncKHR(drv, disp, s, mode);
1763
1764 RETURN_EGL_EVAL(disp, ret);
1765 }
1766
1767
1768 static EGLBoolean
1769 _eglGetSyncAttribCommon(_EGLDisplay *disp, _EGLSync *s, EGLint attribute, EGLAttrib *value)
1770 {
1771 _EGLDriver *drv;
1772 EGLBoolean ret;
1773
1774 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
1775 assert(disp->Extensions.KHR_reusable_sync ||
1776 disp->Extensions.KHR_fence_sync);
1777 ret = drv->API.GetSyncAttrib(drv, disp, s, attribute, value);
1778
1779 RETURN_EGL_EVAL(disp, ret);
1780 }
1781
1782 EGLBoolean EGLAPIENTRY
1783 eglGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value)
1784 {
1785 _EGLDisplay *disp = _eglLockDisplay(dpy);
1786 _EGLSync *s = _eglLookupSync(sync, disp);
1787 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1788 return _eglGetSyncAttribCommon(disp, s, attribute, value);
1789 }
1790
1791
1792 static EGLBoolean EGLAPIENTRY
1793 eglGetSyncAttribKHR(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLint *value)
1794 {
1795 _EGLDisplay *disp = _eglLockDisplay(dpy);
1796 _EGLSync *s = _eglLookupSync(sync, disp);
1797 EGLAttrib attrib;
1798 EGLBoolean result;
1799
1800 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1801
1802 if (!value)
1803 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1804
1805 attrib = *value;
1806 result = _eglGetSyncAttribCommon(disp, s, attribute, &attrib);
1807
1808 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
1809 *
1810 * If any error occurs, <*value> is not modified.
1811 */
1812 if (result == EGL_FALSE)
1813 return result;
1814
1815 *value = attrib;
1816 return result;
1817 }
1818
1819
1820 static EGLBoolean EGLAPIENTRY
1821 eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface,
1822 EGLint numRects, const EGLint *rects)
1823 {
1824 _EGLContext *ctx = _eglGetCurrentContext();
1825 _EGLDisplay *disp = _eglLockDisplay(dpy);
1826 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1827 _EGLDriver *drv;
1828 EGLBoolean ret;
1829
1830 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1831
1832 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1833
1834 if (!disp->Extensions.NOK_swap_region)
1835 RETURN_EGL_EVAL(disp, EGL_FALSE);
1836
1837 /* surface must be bound to current context in EGL 1.4 */
1838 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1839 surf != ctx->DrawSurface)
1840 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1841
1842 ret = drv->API.SwapBuffersRegionNOK(drv, disp, surf, numRects, rects);
1843
1844 RETURN_EGL_EVAL(disp, ret);
1845 }
1846
1847
1848 static EGLImage EGLAPIENTRY
1849 eglCreateDRMImageMESA(EGLDisplay dpy, const EGLint *attr_list)
1850 {
1851 _EGLDisplay *disp = _eglLockDisplay(dpy);
1852 _EGLDriver *drv;
1853 _EGLImage *img;
1854 EGLImage ret;
1855
1856 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1857
1858 _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv);
1859 if (!disp->Extensions.MESA_drm_image)
1860 RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR);
1861
1862 img = drv->API.CreateDRMImageMESA(drv, disp, attr_list);
1863 ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR;
1864
1865 RETURN_EGL_EVAL(disp, ret);
1866 }
1867
1868 static EGLBoolean EGLAPIENTRY
1869 eglExportDRMImageMESA(EGLDisplay dpy, EGLImage image,
1870 EGLint *name, EGLint *handle, EGLint *stride)
1871 {
1872 _EGLDisplay *disp = _eglLockDisplay(dpy);
1873 _EGLImage *img = _eglLookupImage(image, disp);
1874 _EGLDriver *drv;
1875 EGLBoolean ret;
1876
1877 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
1878
1879 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1880 assert(disp->Extensions.MESA_drm_image);
1881
1882 if (!img)
1883 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1884
1885 ret = drv->API.ExportDRMImageMESA(drv, disp, img, name, handle, stride);
1886
1887 RETURN_EGL_EVAL(disp, ret);
1888 }
1889
1890
1891 struct wl_display;
1892
1893 static EGLBoolean EGLAPIENTRY
1894 eglBindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
1895 {
1896 _EGLDisplay *disp = _eglLockDisplay(dpy);
1897 _EGLDriver *drv;
1898 EGLBoolean ret;
1899
1900 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1901
1902 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1903 assert(disp->Extensions.WL_bind_wayland_display);
1904
1905 if (!display)
1906 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1907
1908 ret = drv->API.BindWaylandDisplayWL(drv, disp, display);
1909
1910 RETURN_EGL_EVAL(disp, ret);
1911 }
1912
1913 static EGLBoolean EGLAPIENTRY
1914 eglUnbindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
1915 {
1916 _EGLDisplay *disp = _eglLockDisplay(dpy);
1917 _EGLDriver *drv;
1918 EGLBoolean ret;
1919
1920 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1921
1922 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1923 assert(disp->Extensions.WL_bind_wayland_display);
1924
1925 if (!display)
1926 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1927
1928 ret = drv->API.UnbindWaylandDisplayWL(drv, disp, display);
1929
1930 RETURN_EGL_EVAL(disp, ret);
1931 }
1932
1933 static EGLBoolean EGLAPIENTRY
1934 eglQueryWaylandBufferWL(EGLDisplay dpy, struct wl_resource *buffer,
1935 EGLint attribute, EGLint *value)
1936 {
1937 _EGLDisplay *disp = _eglLockDisplay(dpy);
1938 _EGLDriver *drv;
1939 EGLBoolean ret;
1940
1941 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1942
1943 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
1944 assert(disp->Extensions.WL_bind_wayland_display);
1945
1946 if (!buffer)
1947 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1948
1949 ret = drv->API.QueryWaylandBufferWL(drv, disp, buffer, attribute, value);
1950
1951 RETURN_EGL_EVAL(disp, ret);
1952 }
1953
1954
1955 static struct wl_buffer * EGLAPIENTRY
1956 eglCreateWaylandBufferFromImageWL(EGLDisplay dpy, EGLImage image)
1957 {
1958 _EGLDisplay *disp = _eglLockDisplay(dpy);
1959 _EGLImage *img;
1960 _EGLDriver *drv;
1961 struct wl_buffer *ret;
1962
1963 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
1964
1965 _EGL_CHECK_DISPLAY(disp, NULL, drv);
1966 assert(disp->Extensions.WL_create_wayland_buffer_from_image);
1967
1968 img = _eglLookupImage(image, disp);
1969
1970 if (!img)
1971 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL);
1972
1973 ret = drv->API.CreateWaylandBufferFromImageWL(drv, disp, img);
1974
1975 RETURN_EGL_EVAL(disp, ret);
1976 }
1977
1978 static EGLBoolean EGLAPIENTRY
1979 eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface,
1980 EGLint x, EGLint y, EGLint width, EGLint height)
1981 {
1982 _EGLDisplay *disp = _eglLockDisplay(dpy);
1983 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1984 _EGLDriver *drv;
1985 EGLBoolean ret;
1986
1987 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1988
1989 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1990
1991 if (!disp->Extensions.NV_post_sub_buffer)
1992 RETURN_EGL_EVAL(disp, EGL_FALSE);
1993
1994 ret = drv->API.PostSubBufferNV(drv, disp, surf, x, y, width, height);
1995
1996 RETURN_EGL_EVAL(disp, ret);
1997 }
1998
1999 static EGLBoolean EGLAPIENTRY
2000 eglGetSyncValuesCHROMIUM(EGLDisplay display, EGLSurface surface,
2001 EGLuint64KHR *ust, EGLuint64KHR *msc,
2002 EGLuint64KHR *sbc)
2003 {
2004 _EGLDisplay *disp = _eglLockDisplay(display);
2005 _EGLSurface *surf = _eglLookupSurface(surface, disp);
2006 _EGLDriver *drv;
2007 EGLBoolean ret;
2008
2009 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
2010
2011 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
2012 if (!disp->Extensions.CHROMIUM_sync_control)
2013 RETURN_EGL_EVAL(disp, EGL_FALSE);
2014
2015 if (!ust || !msc || !sbc)
2016 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2017
2018 ret = drv->API.GetSyncValuesCHROMIUM(disp, surf, ust, msc, sbc);
2019
2020 RETURN_EGL_EVAL(disp, ret);
2021 }
2022
2023 static EGLBoolean EGLAPIENTRY
2024 eglExportDMABUFImageQueryMESA(EGLDisplay dpy, EGLImage image,
2025 EGLint *fourcc, EGLint *nplanes,
2026 EGLuint64KHR *modifiers)
2027 {
2028 _EGLDisplay *disp = _eglLockDisplay(dpy);
2029 _EGLImage *img = _eglLookupImage(image, disp);
2030 _EGLDriver *drv;
2031 EGLBoolean ret;
2032
2033 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
2034
2035 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2036 assert(disp->Extensions.MESA_image_dma_buf_export);
2037
2038 if (!img)
2039 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2040
2041 ret = drv->API.ExportDMABUFImageQueryMESA(drv, disp, img, fourcc, nplanes,
2042 modifiers);
2043
2044 RETURN_EGL_EVAL(disp, ret);
2045 }
2046
2047 static EGLBoolean EGLAPIENTRY
2048 eglExportDMABUFImageMESA(EGLDisplay dpy, EGLImage image,
2049 int *fds, EGLint *strides, EGLint *offsets)
2050 {
2051 _EGLDisplay *disp = _eglLockDisplay(dpy);
2052 _EGLImage *img = _eglLookupImage(image, disp);
2053 _EGLDriver *drv;
2054 EGLBoolean ret;
2055
2056 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
2057
2058 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2059 assert(disp->Extensions.MESA_image_dma_buf_export);
2060
2061 if (!img)
2062 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2063
2064 ret = drv->API.ExportDMABUFImageMESA(drv, disp, img, fds, strides, offsets);
2065
2066 RETURN_EGL_EVAL(disp, ret);
2067 }
2068
2069 static EGLint EGLAPIENTRY
2070 eglLabelObjectKHR(EGLDisplay dpy, EGLenum objectType, EGLObjectKHR object,
2071 EGLLabelKHR label)
2072 {
2073 _EGLDisplay *disp = NULL;
2074 _EGLResourceType type;
2075
2076 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC);
2077
2078 if (objectType == EGL_OBJECT_THREAD_KHR) {
2079 _EGLThreadInfo *t = _eglGetCurrentThread();
2080
2081 if (!_eglIsCurrentThreadDummy()) {
2082 t->Label = label;
2083 return EGL_SUCCESS;
2084 }
2085
2086 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_BAD_ALLOC);
2087 }
2088
2089 disp = _eglLockDisplay(dpy);
2090 if (disp == NULL)
2091 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_BAD_DISPLAY);
2092
2093 if (objectType == EGL_OBJECT_DISPLAY_KHR) {
2094 if (dpy != (EGLDisplay) object)
2095 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER);
2096
2097 disp->Label = label;
2098 RETURN_EGL_EVAL(disp, EGL_SUCCESS);
2099 }
2100
2101 switch (objectType) {
2102 case EGL_OBJECT_CONTEXT_KHR:
2103 type = _EGL_RESOURCE_CONTEXT;
2104 break;
2105 case EGL_OBJECT_SURFACE_KHR:
2106 type = _EGL_RESOURCE_SURFACE;
2107 break;
2108 case EGL_OBJECT_IMAGE_KHR:
2109 type = _EGL_RESOURCE_IMAGE;
2110 break;
2111 case EGL_OBJECT_SYNC_KHR:
2112 type = _EGL_RESOURCE_SYNC;
2113 break;
2114 case EGL_OBJECT_STREAM_KHR:
2115 default:
2116 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER);
2117 }
2118
2119 if (_eglCheckResource(object, type, disp)) {
2120 _EGLResource *res = (_EGLResource *) object;
2121
2122 res->Label = label;
2123 RETURN_EGL_EVAL(disp, EGL_SUCCESS);
2124 }
2125
2126 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER);
2127 }
2128
2129 static EGLBoolean
2130 validDebugMessageLevel(EGLAttrib level)
2131 {
2132 return (level >= EGL_DEBUG_MSG_CRITICAL_KHR &&
2133 level <= EGL_DEBUG_MSG_INFO_KHR);
2134 }
2135
2136 static EGLint EGLAPIENTRY
2137 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback,
2138 const EGLAttrib *attrib_list)
2139 {
2140 unsigned int newEnabled;
2141
2142 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC);
2143
2144 mtx_lock(_eglGlobal.Mutex);
2145
2146 newEnabled = _eglGlobal.debugTypesEnabled;
2147 if (attrib_list != NULL) {
2148 int i;
2149
2150 for (i = 0; attrib_list[i] != EGL_NONE; i += 2) {
2151 if (validDebugMessageLevel(attrib_list[i])) {
2152 if (attrib_list[i + 1])
2153 newEnabled |= DebugBitFromType(attrib_list[i]);
2154 else
2155 newEnabled &= ~DebugBitFromType(attrib_list[i]);
2156 continue;
2157 }
2158
2159 // On error, set the last error code, call the current
2160 // debug callback, and return the error code.
2161 mtx_unlock(_eglGlobal.Mutex);
2162 _eglReportError(EGL_BAD_ATTRIBUTE, NULL,
2163 "Invalid attribute 0x%04lx", (unsigned long) attrib_list[i]);
2164 return EGL_BAD_ATTRIBUTE;
2165 }
2166 }
2167
2168 if (callback != NULL) {
2169 _eglGlobal.debugCallback = callback;
2170 _eglGlobal.debugTypesEnabled = newEnabled;
2171 } else {
2172 _eglGlobal.debugCallback = NULL;
2173 _eglGlobal.debugTypesEnabled = _EGL_DEBUG_BIT_CRITICAL | _EGL_DEBUG_BIT_ERROR;
2174 }
2175
2176 mtx_unlock(_eglGlobal.Mutex);
2177 return EGL_SUCCESS;
2178 }
2179
2180 static EGLBoolean EGLAPIENTRY
2181 eglQueryDebugKHR(EGLint attribute, EGLAttrib *value)
2182 {
2183 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC);
2184
2185 mtx_lock(_eglGlobal.Mutex);
2186
2187 do {
2188 if (validDebugMessageLevel(attribute)) {
2189 if (_eglGlobal.debugTypesEnabled & DebugBitFromType(attribute))
2190 *value = EGL_TRUE;
2191 else
2192 *value = EGL_FALSE;
2193 break;
2194 }
2195
2196 if (attribute == EGL_DEBUG_CALLBACK_KHR) {
2197 *value = (EGLAttrib) _eglGlobal.debugCallback;
2198 break;
2199 }
2200
2201 mtx_unlock(_eglGlobal.Mutex);
2202 _eglReportError(EGL_BAD_ATTRIBUTE, NULL,
2203 "Invalid attribute 0x%04lx", (unsigned long) attribute);
2204 return EGL_FALSE;
2205 } while (0);
2206
2207 mtx_unlock(_eglGlobal.Mutex);
2208 return EGL_TRUE;
2209 }
2210
2211 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
2212 eglGetProcAddress(const char *procname)
2213 {
2214 static const struct {
2215 const char *name;
2216 _EGLProc function;
2217 } egl_functions[] = {
2218 /* core functions queryable in the presence of
2219 * EGL_KHR_get_all_proc_addresses or EGL 1.5
2220 */
2221 /* alphabetical order */
2222 { "eglBindAPI", (_EGLProc) eglBindAPI },
2223 { "eglBindTexImage", (_EGLProc) eglBindTexImage },
2224 { "eglChooseConfig", (_EGLProc) eglChooseConfig },
2225 { "eglCopyBuffers", (_EGLProc) eglCopyBuffers },
2226 { "eglCreateContext", (_EGLProc) eglCreateContext },
2227 { "eglCreatePbufferFromClientBuffer", (_EGLProc) eglCreatePbufferFromClientBuffer },
2228 { "eglCreatePbufferSurface", (_EGLProc) eglCreatePbufferSurface },
2229 { "eglCreatePixmapSurface", (_EGLProc) eglCreatePixmapSurface },
2230 { "eglCreateWindowSurface", (_EGLProc) eglCreateWindowSurface },
2231 { "eglDestroyContext", (_EGLProc) eglDestroyContext },
2232 { "eglDestroySurface", (_EGLProc) eglDestroySurface },
2233 { "eglGetConfigAttrib", (_EGLProc) eglGetConfigAttrib },
2234 { "eglGetConfigs", (_EGLProc) eglGetConfigs },
2235 { "eglGetCurrentContext", (_EGLProc) eglGetCurrentContext },
2236 { "eglGetCurrentDisplay", (_EGLProc) eglGetCurrentDisplay },
2237 { "eglGetCurrentSurface", (_EGLProc) eglGetCurrentSurface },
2238 { "eglGetDisplay", (_EGLProc) eglGetDisplay },
2239 { "eglGetError", (_EGLProc) eglGetError },
2240 { "eglGetProcAddress", (_EGLProc) eglGetProcAddress },
2241 { "eglInitialize", (_EGLProc) eglInitialize },
2242 { "eglMakeCurrent", (_EGLProc) eglMakeCurrent },
2243 { "eglQueryAPI", (_EGLProc) eglQueryAPI },
2244 { "eglQueryContext", (_EGLProc) eglQueryContext },
2245 { "eglQueryString", (_EGLProc) eglQueryString },
2246 { "eglQuerySurface", (_EGLProc) eglQuerySurface },
2247 { "eglReleaseTexImage", (_EGLProc) eglReleaseTexImage },
2248 { "eglReleaseThread", (_EGLProc) eglReleaseThread },
2249 { "eglSurfaceAttrib", (_EGLProc) eglSurfaceAttrib },
2250 { "eglSwapBuffers", (_EGLProc) eglSwapBuffers },
2251 { "eglSwapInterval", (_EGLProc) eglSwapInterval },
2252 { "eglTerminate", (_EGLProc) eglTerminate },
2253 { "eglWaitClient", (_EGLProc) eglWaitClient },
2254 { "eglWaitGL", (_EGLProc) eglWaitGL },
2255 { "eglWaitNative", (_EGLProc) eglWaitNative },
2256 { "eglCreateSync", (_EGLProc) eglCreateSync },
2257 { "eglDestroySync", (_EGLProc) eglDestroySync },
2258 { "eglClientWaitSync", (_EGLProc) eglClientWaitSync },
2259 { "eglGetSyncAttrib", (_EGLProc) eglGetSyncAttrib },
2260 { "eglWaitSync", (_EGLProc) eglWaitSync },
2261 { "eglCreateImage", (_EGLProc) eglCreateImage },
2262 { "eglDestroyImage", (_EGLProc) eglDestroyImage },
2263 { "eglGetPlatformDisplay", (_EGLProc) eglGetPlatformDisplay },
2264 { "eglCreatePlatformWindowSurface", (_EGLProc) eglCreatePlatformWindowSurface },
2265 { "eglCreatePlatformPixmapSurface", (_EGLProc) eglCreatePlatformPixmapSurface },
2266 { "eglCreateImageKHR", (_EGLProc) eglCreateImageKHR },
2267 { "eglDestroyImageKHR", (_EGLProc) eglDestroyImage },
2268 { "eglCreateSyncKHR", (_EGLProc) eglCreateSyncKHR },
2269 { "eglCreateSync64KHR", (_EGLProc) eglCreateSync64KHR },
2270 { "eglDestroySyncKHR", (_EGLProc) eglDestroySync },
2271 { "eglClientWaitSyncKHR", (_EGLProc) eglClientWaitSync },
2272 { "eglWaitSyncKHR", (_EGLProc) eglWaitSyncKHR },
2273 { "eglSignalSyncKHR", (_EGLProc) eglSignalSyncKHR },
2274 { "eglGetSyncAttribKHR", (_EGLProc) eglGetSyncAttribKHR },
2275 { "eglSwapBuffersRegionNOK", (_EGLProc) eglSwapBuffersRegionNOK },
2276 { "eglCreateDRMImageMESA", (_EGLProc) eglCreateDRMImageMESA },
2277 { "eglExportDRMImageMESA", (_EGLProc) eglExportDRMImageMESA },
2278 { "eglBindWaylandDisplayWL", (_EGLProc) eglBindWaylandDisplayWL },
2279 { "eglUnbindWaylandDisplayWL", (_EGLProc) eglUnbindWaylandDisplayWL },
2280 { "eglQueryWaylandBufferWL", (_EGLProc) eglQueryWaylandBufferWL },
2281 { "eglCreateWaylandBufferFromImageWL", (_EGLProc) eglCreateWaylandBufferFromImageWL },
2282 { "eglPostSubBufferNV", (_EGLProc) eglPostSubBufferNV },
2283 { "eglSwapBuffersWithDamageEXT", (_EGLProc) eglSwapBuffersWithDamageEXT },
2284 { "eglSwapBuffersWithDamageKHR", (_EGLProc) eglSwapBuffersWithDamageKHR },
2285 { "eglGetPlatformDisplayEXT", (_EGLProc) eglGetPlatformDisplayEXT },
2286 { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc) eglCreatePlatformWindowSurfaceEXT },
2287 { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc) eglCreatePlatformPixmapSurfaceEXT },
2288 { "eglGetSyncValuesCHROMIUM", (_EGLProc) eglGetSyncValuesCHROMIUM },
2289 { "eglExportDMABUFImageQueryMESA", (_EGLProc) eglExportDMABUFImageQueryMESA },
2290 { "eglExportDMABUFImageMESA", (_EGLProc) eglExportDMABUFImageMESA },
2291 { "eglLabelObjectKHR", (_EGLProc) eglLabelObjectKHR },
2292 { "eglDebugMessageControlKHR", (_EGLProc) eglDebugMessageControlKHR },
2293 { "eglQueryDebugKHR", (_EGLProc) eglQueryDebugKHR },
2294 { NULL, NULL }
2295 };
2296 EGLint i;
2297 _EGLProc ret;
2298
2299 if (!procname)
2300 RETURN_EGL_SUCCESS(NULL, NULL);
2301
2302 _EGL_FUNC_START(NULL, EGL_NONE, NULL, NULL);
2303
2304 ret = NULL;
2305 if (strncmp(procname, "egl", 3) == 0) {
2306 for (i = 0; egl_functions[i].name; i++) {
2307 if (strcmp(egl_functions[i].name, procname) == 0) {
2308 ret = egl_functions[i].function;
2309 break;
2310 }
2311 }
2312 }
2313 if (!ret)
2314 ret = _eglGetDriverProc(procname);
2315
2316 RETURN_EGL_SUCCESS(NULL, ret);
2317 }
2318
2319 static int
2320 _eglLockDisplayInterop(EGLDisplay dpy, EGLContext context,
2321 _EGLDisplay **disp, _EGLDriver **drv,
2322 _EGLContext **ctx)
2323 {
2324
2325 *disp = _eglLockDisplay(dpy);
2326 if (!*disp || !(*disp)->Initialized || !(*disp)->Driver) {
2327 if (*disp)
2328 _eglUnlockDisplay(*disp);
2329 return MESA_GLINTEROP_INVALID_DISPLAY;
2330 }
2331
2332 *drv = (*disp)->Driver;
2333
2334 *ctx = _eglLookupContext(context, *disp);
2335 if (!*ctx ||
2336 ((*ctx)->ClientAPI != EGL_OPENGL_API &&
2337 (*ctx)->ClientAPI != EGL_OPENGL_ES_API)) {
2338 _eglUnlockDisplay(*disp);
2339 return MESA_GLINTEROP_INVALID_CONTEXT;
2340 }
2341
2342 return MESA_GLINTEROP_SUCCESS;
2343 }
2344
2345 int
2346 MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy, EGLContext context,
2347 struct mesa_glinterop_device_info *out)
2348 {
2349 _EGLDisplay *disp;
2350 _EGLDriver *drv;
2351 _EGLContext *ctx;
2352 int ret;
2353
2354 ret = _eglLockDisplayInterop(dpy, context, &disp, &drv, &ctx);
2355 if (ret != MESA_GLINTEROP_SUCCESS)
2356 return ret;
2357
2358 if (drv->API.GLInteropQueryDeviceInfo)
2359 ret = drv->API.GLInteropQueryDeviceInfo(disp, ctx, out);
2360 else
2361 ret = MESA_GLINTEROP_UNSUPPORTED;
2362
2363 _eglUnlockDisplay(disp);
2364 return ret;
2365 }
2366
2367 int
2368 MesaGLInteropEGLExportObject(EGLDisplay dpy, EGLContext context,
2369 struct mesa_glinterop_export_in *in,
2370 struct mesa_glinterop_export_out *out)
2371 {
2372 _EGLDisplay *disp;
2373 _EGLDriver *drv;
2374 _EGLContext *ctx;
2375 int ret;
2376
2377 ret = _eglLockDisplayInterop(dpy, context, &disp, &drv, &ctx);
2378 if (ret != MESA_GLINTEROP_SUCCESS)
2379 return ret;
2380
2381 if (drv->API.GLInteropExportObject)
2382 ret = drv->API.GLInteropExportObject(disp, ctx, in, out);
2383 else
2384 ret = MESA_GLINTEROP_UNSUPPORTED;
2385
2386 _eglUnlockDisplay(disp);
2387 return ret;
2388 }