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