X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fegl%2Fmain%2Feglapi.c;h=51557be0864a43f3f4621fc04e130e614caa4c0c;hb=e64b91e34aa04a137a322ae9444c1c603383c6d4;hp=88cdf06121f3cc200c576914a9a076bc0b5d3fa0;hpb=6a5545d3ba60a19a3bce8f62141e0991a595eeaf;p=mesa.git diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index 88cdf06121f..51557be0864 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -83,25 +83,34 @@ */ +#ifdef USE_LIBGLVND +#define EGLAPI +#undef PUBLIC +#define PUBLIC +#endif + #include #include #include #include "c99_compat.h" #include "c11/threads.h" -#include "GL/mesa_glinterop.h" -#include "eglcompiler.h" +#include "util/macros.h" +#include "eglapi.h" +#include "egldefines.h" #include "eglglobals.h" #include "eglcontext.h" #include "egldisplay.h" #include "egltypedefs.h" #include "eglcurrent.h" +#include "egldevice.h" #include "egldriver.h" #include "eglsurface.h" #include "eglconfig.h" #include "eglimage.h" #include "eglsync.h" +#include "GL/mesa_glinterop.h" /** * Macros to help return an API entrypoint. @@ -157,6 +166,12 @@ _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv) +struct _egl_entrypoint { + const char *name; + _EGLProc function; +}; + + static inline _EGLDriver * _eglCheckDisplay(_EGLDisplay *disp, const char *msg) { @@ -232,12 +247,12 @@ _eglCheckSync(_EGLDisplay *disp, _EGLSync *s, const char *msg) * Lookup and lock a display. */ static inline _EGLDisplay * -_eglLockDisplay(EGLDisplay display) +_eglLockDisplay(EGLDisplay dpy) { - _EGLDisplay *dpy = _eglLookupDisplay(display); - if (dpy) - mtx_lock(&dpy->Mutex); - return dpy; + _EGLDisplay *disp = _eglLookupDisplay(dpy); + if (disp) + mtx_lock(&disp->Mutex); + return disp; } @@ -245,9 +260,9 @@ _eglLockDisplay(EGLDisplay display) * Unlock a display. */ static inline void -_eglUnlockDisplay(_EGLDisplay *dpy) +_eglUnlockDisplay(_EGLDisplay *disp) { - mtx_unlock(&dpy->Mutex); + mtx_unlock(&disp->Mutex); } static EGLBoolean @@ -268,8 +283,7 @@ _eglSetFuncName(const char *funcName, _EGLDisplay *disp, EGLenum objectType, _EG return EGL_TRUE; } - _eglDebugReportFull(EGL_BAD_ALLOC, funcName, funcName, - EGL_DEBUG_MSG_CRITICAL_KHR, NULL, NULL); + _eglDebugReport(EGL_BAD_ALLOC, funcName, EGL_DEBUG_MSG_CRITICAL_KHR, NULL); return EGL_FALSE; } @@ -288,7 +302,7 @@ _eglSetFuncName(const char *funcName, _EGLDisplay *disp, EGLenum objectType, _EG * Return an EGL error code. The output parameter out_attrib_list is modified * only on success. */ -EGLint +static EGLint _eglConvertIntsToAttribs(const EGLint *int_list, EGLAttrib **out_attrib_list) { size_t len = 0; @@ -326,22 +340,16 @@ _eglConvertIntsToAttribs(const EGLint *int_list, EGLAttrib **out_attrib_list) static EGLint * _eglConvertAttribsToInt(const EGLAttrib *attr_list) { + size_t size = _eglNumAttribs(attr_list); EGLint *int_attribs = NULL; /* Convert attributes from EGLAttrib[] to EGLint[] */ - if (attr_list) { - int i, size = 0; - - while (attr_list[size] != EGL_NONE) - size += 2; - - size += 1; /* add space for EGL_NONE */ - + if (size) { int_attribs = calloc(size, sizeof(int_attribs[0])); if (!int_attribs) return NULL; - for (i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) int_attribs[i] = attr_list[i]; } return int_attribs; @@ -356,7 +364,7 @@ EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType nativeDisplay) { _EGLPlatformType plat; - _EGLDisplay *dpy; + _EGLDisplay *disp; void *native_display_ptr; _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY); @@ -365,65 +373,77 @@ eglGetDisplay(EGLNativeDisplayType nativeDisplay) native_display_ptr = (void*) nativeDisplay; plat = _eglGetNativePlatform(native_display_ptr); - dpy = _eglFindDisplay(plat, native_display_ptr); - return _eglGetDisplayHandle(dpy); + disp = _eglFindDisplay(plat, native_display_ptr, NULL); + return _eglGetDisplayHandle(disp); } static EGLDisplay _eglGetPlatformDisplayCommon(EGLenum platform, void *native_display, - const EGLint *attrib_list) + const EGLAttrib *attrib_list) { - _EGLDisplay *dpy; + _EGLDisplay *disp; switch (platform) { #ifdef HAVE_X11_PLATFORM case EGL_PLATFORM_X11_EXT: - dpy = _eglGetX11Display((Display*) native_display, attrib_list); + disp = _eglGetX11Display((Display*) native_display, attrib_list); break; #endif #ifdef HAVE_DRM_PLATFORM case EGL_PLATFORM_GBM_MESA: - dpy = _eglGetGbmDisplay((struct gbm_device*) native_display, + disp = _eglGetGbmDisplay((struct gbm_device*) native_display, attrib_list); break; #endif #ifdef HAVE_WAYLAND_PLATFORM case EGL_PLATFORM_WAYLAND_EXT: - dpy = _eglGetWaylandDisplay((struct wl_display*) native_display, + disp = _eglGetWaylandDisplay((struct wl_display*) native_display, attrib_list); break; #endif +#ifdef HAVE_SURFACELESS_PLATFORM + case EGL_PLATFORM_SURFACELESS_MESA: + disp = _eglGetSurfacelessDisplay(native_display, attrib_list); + break; +#endif +#ifdef HAVE_ANDROID_PLATFORM + case EGL_PLATFORM_ANDROID_KHR: + disp = _eglGetAndroidDisplay(native_display, attrib_list); + break; +#endif + case EGL_PLATFORM_DEVICE_EXT: + disp = _eglGetDeviceDisplay(native_display, attrib_list); + break; default: RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, NULL); } - return _eglGetDisplayHandle(dpy); + return _eglGetDisplayHandle(disp); } static EGLDisplay EGLAPIENTRY eglGetPlatformDisplayEXT(EGLenum platform, void *native_display, - const EGLint *attrib_list) + const EGLint *int_attribs) { + EGLAttrib *attrib_list; + EGLDisplay disp; + _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY); - return _eglGetPlatformDisplayCommon(platform, native_display, attrib_list); + + if (_eglConvertIntsToAttribs(int_attribs, &attrib_list) != EGL_SUCCESS) + RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, NULL); + + disp = _eglGetPlatformDisplayCommon(platform, native_display, attrib_list); + free(attrib_list); + return disp; } EGLDisplay EGLAPIENTRY eglGetPlatformDisplay(EGLenum platform, void *native_display, const EGLAttrib *attrib_list) { - EGLDisplay display; - EGLint *int_attribs; - _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY); - - int_attribs = _eglConvertAttribsToInt(attrib_list); - if (attrib_list && !int_attribs) - RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, NULL); - - display = _eglGetPlatformDisplayCommon(platform, native_display, int_attribs); - free(int_attribs); - return display; + return _eglGetPlatformDisplayCommon(platform, native_display, attrib_list); } /** @@ -454,21 +474,23 @@ _eglAppendExtension(char **str, const char *ext) * the driver's Extensions string. */ static void -_eglCreateExtensionsString(_EGLDisplay *dpy) +_eglCreateExtensionsString(_EGLDisplay *disp) { #define _EGL_CHECK_EXTENSION(ext) \ do { \ - if (dpy->Extensions.ext) { \ + if (disp->Extensions.ext) { \ _eglAppendExtension(&exts, "EGL_" #ext); \ - assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \ + assert(exts <= disp->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \ } \ } while (0) - char *exts = dpy->ExtensionsString; + char *exts = disp->ExtensionsString; /* Please keep these sorted alphabetically. */ + _EGL_CHECK_EXTENSION(ANDROID_blob_cache); _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target); _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer); + _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync); _EGL_CHECK_EXTENSION(ANDROID_recordable); _EGL_CHECK_EXTENSION(CHROMIUM_sync_control); @@ -476,10 +498,18 @@ _eglCreateExtensionsString(_EGLDisplay *dpy) _EGL_CHECK_EXTENSION(EXT_buffer_age); _EGL_CHECK_EXTENSION(EXT_create_context_robustness); _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import); + _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers); + _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata); + _EGL_CHECK_EXTENSION(EXT_surface_SMPTE2086_metadata); _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage); + _EGL_CHECK_EXTENSION(IMG_context_priority); + _EGL_CHECK_EXTENSION(KHR_cl_event2); + _EGL_CHECK_EXTENSION(KHR_config_attribs); + _EGL_CHECK_EXTENSION(KHR_context_flush_control); _EGL_CHECK_EXTENSION(KHR_create_context); + _EGL_CHECK_EXTENSION(KHR_create_context_no_error); _EGL_CHECK_EXTENSION(KHR_fence_sync); _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses); _EGL_CHECK_EXTENSION(KHR_gl_colorspace); @@ -487,19 +517,26 @@ _eglCreateExtensionsString(_EGLDisplay *dpy) _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image); _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image); _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image); - if (dpy->Extensions.KHR_image_base && dpy->Extensions.KHR_image_pixmap) - _eglAppendExtension(&exts, "EGL_KHR_image"); + if (disp->Extensions.KHR_image_base && disp->Extensions.KHR_image_pixmap) + disp->Extensions.KHR_image = EGL_TRUE; + _EGL_CHECK_EXTENSION(KHR_image); _EGL_CHECK_EXTENSION(KHR_image_base); _EGL_CHECK_EXTENSION(KHR_image_pixmap); + _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer); _EGL_CHECK_EXTENSION(KHR_no_config_context); + _EGL_CHECK_EXTENSION(KHR_partial_update); _EGL_CHECK_EXTENSION(KHR_reusable_sync); _EGL_CHECK_EXTENSION(KHR_surfaceless_context); + if (disp->Extensions.EXT_swap_buffers_with_damage) + _eglAppendExtension(&exts, "EGL_KHR_swap_buffers_with_damage"); + _EGL_CHECK_EXTENSION(EXT_pixel_format_float); _EGL_CHECK_EXTENSION(KHR_wait_sync); - if (dpy->Extensions.KHR_no_config_context) + if (disp->Extensions.KHR_no_config_context) _eglAppendExtension(&exts, "EGL_MESA_configless_context"); _EGL_CHECK_EXTENSION(MESA_drm_image); _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export); + _EGL_CHECK_EXTENSION(MESA_query_driver); _EGL_CHECK_EXTENSION(NOK_swap_region); _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap); @@ -513,21 +550,32 @@ _eglCreateExtensionsString(_EGLDisplay *dpy) } static void -_eglCreateAPIsString(_EGLDisplay *dpy) -{ - if (dpy->ClientAPIs & EGL_OPENGL_BIT) - strcat(dpy->ClientAPIsString, "OpenGL "); +_eglCreateAPIsString(_EGLDisplay *disp) +{ +#define addstr(str) \ + { \ + const size_t old_len = strlen(disp->ClientAPIsString); \ + const size_t add_len = sizeof(str); \ + const size_t max_len = sizeof(disp->ClientAPIsString) - 1; \ + if (old_len + add_len <= max_len) \ + strcat(disp->ClientAPIsString, str " "); \ + else \ + assert(!"disp->ClientAPIsString is not large enough"); \ + } + + if (disp->ClientAPIs & EGL_OPENGL_BIT) + addstr("OpenGL"); - if (dpy->ClientAPIs & EGL_OPENGL_ES_BIT || - dpy->ClientAPIs & EGL_OPENGL_ES2_BIT || - dpy->ClientAPIs & EGL_OPENGL_ES3_BIT_KHR) { - strcat(dpy->ClientAPIsString, "OpenGL_ES "); + if (disp->ClientAPIs & EGL_OPENGL_ES_BIT || + disp->ClientAPIs & EGL_OPENGL_ES2_BIT || + disp->ClientAPIs & EGL_OPENGL_ES3_BIT_KHR) { + addstr("OpenGL_ES"); } - if (dpy->ClientAPIs & EGL_OPENVG_BIT) - strcat(dpy->ClientAPIsString, "OpenVG "); + if (disp->ClientAPIs & EGL_OPENVG_BIT) + addstr("OpenVG"); - assert(strlen(dpy->ClientAPIsString) < sizeof(dpy->ClientAPIsString)); +#undef addstr } static void @@ -566,7 +614,7 @@ eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE); if (!disp->Initialized) { - if (!_eglMatchDriver(disp, EGL_FALSE)) + if (!_eglMatchDriver(disp)) RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE); /* limit to APIs supported by core */ @@ -589,12 +637,16 @@ eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) */ disp->Extensions.KHR_get_all_proc_addresses = EGL_TRUE; + /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware + * programs. It is driver agnostic and handled in the main EGL code. + */ + disp->Extensions.KHR_config_attribs = EGL_TRUE; + _eglComputeVersion(disp); _eglCreateExtensionsString(disp); _eglCreateAPIsString(disp); snprintf(disp->VersionString, sizeof(disp->VersionString), - "%d.%d (%s)", disp->Version / 10, disp->Version % 10, - disp->Driver->Name); + "%d.%d", disp->Version / 10, disp->Version % 10); } /* Update applications version of major and minor if not NULL */ @@ -624,6 +676,10 @@ eglTerminate(EGLDisplay dpy) /* do not reset disp->Driver */ disp->ClientAPIsString[0] = 0; disp->Initialized = EGL_FALSE; + + /* Reset blob cache funcs on terminate. */ + disp->BlobCacheSet = NULL; + disp->BlobCacheGet = NULL; } RETURN_EGL_SUCCESS(disp, EGL_TRUE); @@ -637,7 +693,11 @@ eglQueryString(EGLDisplay dpy, EGLint name) _EGLDriver *drv; if (dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS) { - RETURN_EGL_SUCCESS(NULL, _eglGlobal.ClientExtensionString); + const char *ret = _eglGetClientExtensionString(); + if (ret != NULL) + RETURN_EGL_SUCCESS(NULL, ret); + else + RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, NULL); } disp = _eglLockDisplay(dpy); @@ -670,7 +730,11 @@ eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); - ret = drv->API.GetConfigs(drv, disp, configs, config_size, num_config); + + if (!num_config) + RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); + + ret = _eglGetConfigs(drv, disp, configs, config_size, num_config); RETURN_EGL_EVAL(disp, ret); } @@ -687,8 +751,12 @@ eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); - ret = drv->API.ChooseConfig(drv, disp, attrib_list, configs, - config_size, num_config); + + if (!num_config) + RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); + + ret = _eglChooseConfig(drv, disp, attrib_list, configs, + config_size, num_config); RETURN_EGL_EVAL(disp, ret); } @@ -706,7 +774,8 @@ eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); _EGL_CHECK_CONFIG(disp, conf, EGL_FALSE, drv); - ret = drv->API.GetConfigAttrib(drv, disp, conf, attribute, value); + + ret = _eglGetConfigAttrib(drv, disp, conf, attribute, value); RETURN_EGL_EVAL(disp, ret); } @@ -727,7 +796,9 @@ eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list, _EGL_CHECK_DISPLAY(disp, EGL_NO_CONTEXT, drv); - if (!config && !disp->Extensions.KHR_no_config_context) + if (config != EGL_NO_CONFIG_KHR) + _EGL_CHECK_CONFIG(disp, conf, EGL_NO_CONTEXT, drv); + else if (!disp->Extensions.KHR_no_config_context) RETURN_EGL_ERROR(disp, EGL_BAD_CONFIG, EGL_NO_CONTEXT); if (!share && share_list != EGL_NO_CONTEXT) @@ -802,6 +873,14 @@ eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE); } + /* If a native window underlying either draw or read is no longer valid, + * an EGL_BAD_NATIVE_WINDOW error is generated. + */ + if (draw_surf && draw_surf->Lost) + RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_FALSE); + if (read_surf && read_surf->Lost) + RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_FALSE); + ret = drv->API.MakeCurrent(drv, disp, draw_surf, read_surf, context); RETURN_EGL_EVAL(disp, ret); @@ -820,12 +899,39 @@ eglQueryContext(EGLDisplay dpy, EGLContext ctx, _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE); _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv); - ret = drv->API.QueryContext(drv, disp, context, attribute, value); + + ret = _eglQueryContext(drv, disp, context, attribute, value); RETURN_EGL_EVAL(disp, ret); } +/* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says + * that if native_surface was already used to create a window or pixmap, we + * can't create a new one. This is what this function checks for. + */ +static bool +_eglNativeSurfaceAlreadyUsed(_EGLDisplay *disp, void *native_surface) +{ + _EGLResource *list; + + list = disp->ResourceLists[_EGL_RESOURCE_SURFACE]; + while (list) { + _EGLSurface *surf = (_EGLSurface *) list; + + list = list->Next; + + if (surf->Type == EGL_PBUFFER_BIT) + continue; + + if (surf->NativeSurface == native_surface) + return true; + } + + return false; +} + + static EGLSurface _eglCreateWindowSurfaceCommon(_EGLDisplay *disp, EGLConfig config, void *native_window, const EGLint *attrib_list) @@ -835,11 +941,35 @@ _eglCreateWindowSurfaceCommon(_EGLDisplay *disp, EGLConfig config, _EGLSurface *surf; EGLSurface ret; - _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv); if (native_window == NULL) RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); + if (disp && (disp->Platform == _EGL_PLATFORM_SURFACELESS || + disp->Platform == _EGL_PLATFORM_DEVICE)) { + /* From the EGL_MESA_platform_surfaceless spec (v1): + * + * eglCreatePlatformWindowSurface fails when called with a + * that belongs to the surfaceless platform. It returns + * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The + * justification for this unconditional failure is that the + * surfaceless platform has no native windows, and therefore the + * parameter is always invalid. + * + * This check must occur before checking the EGLConfig, which emits + * EGL_BAD_CONFIG. + */ + RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); + } + + _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv); + + if ((conf->SurfaceType & EGL_WINDOW_BIT) == 0) + RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE); + + if (_eglNativeSurfaceAlreadyUsed(disp, native_window)) + RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); + surf = drv->API.CreateWindowSurface(drv, disp, conf, native_window, attrib_list); ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE; @@ -861,10 +991,10 @@ eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, } static void * -fixupNativeWindow(_EGLDisplay *disp, void *native_window) +_fixupNativeWindow(_EGLDisplay *disp, void *native_window) { #ifdef HAVE_X11_PLATFORM - if (disp->Platform == _EGL_PLATFORM_X11 && native_window != NULL) { + if (disp && disp->Platform == _EGL_PLATFORM_X11 && native_window != NULL) { /* The `native_window` parameter for the X11 platform differs between * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In * eglCreateWindowSurface(), the type of `native_window` is an Xlib @@ -885,7 +1015,7 @@ eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config, { _EGLDisplay *disp = _eglLockDisplay(dpy); - native_window = fixupNativeWindow(disp, native_window); + native_window = _fixupNativeWindow(disp, native_window); _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); return _eglCreateWindowSurfaceCommon(disp, config, native_window, @@ -908,7 +1038,7 @@ eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config, if (attrib_list && !int_attribs) RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); - native_window = fixupNativeWindow(disp, native_window); + native_window = _fixupNativeWindow(disp, native_window); surface = _eglCreateWindowSurfaceCommon(disp, config, native_window, int_attribs); free(int_attribs); @@ -916,17 +1046,17 @@ eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config, } static void * -fixupNativePixmap(_EGLDisplay *disp, void *native_pixmap) +_fixupNativePixmap(_EGLDisplay *disp, void *native_pixmap) { #ifdef HAVE_X11_PLATFORM - /* The `native_pixmap` parameter for the X11 platform differs between - * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In - * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib - * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is - * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what - * dri2_x11_create_pixmap_surface() expects. - */ - if (disp->Platform == _EGL_PLATFORM_X11 && native_pixmap != NULL) + /* The `native_pixmap` parameter for the X11 platform differs between + * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In + * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib + * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is + * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what + * dri2_x11_create_pixmap_surface() expects. + */ + if (disp && disp->Platform == _EGL_PLATFORM_X11 && native_pixmap != NULL) return (void *)(* (Pixmap*) native_pixmap); #endif return native_pixmap; @@ -941,7 +1071,32 @@ _eglCreatePixmapSurfaceCommon(_EGLDisplay *disp, EGLConfig config, _EGLSurface *surf; EGLSurface ret; + if (disp && (disp->Platform == _EGL_PLATFORM_SURFACELESS || + disp->Platform == _EGL_PLATFORM_DEVICE)) { + /* From the EGL_MESA_platform_surfaceless spec (v1): + * + * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface + * also fails when called with a that belongs to the + * surfaceless platform. It returns EGL_NO_SURFACE and generates + * EGL_BAD_NATIVE_PIXMAP. + * + * This check must occur before checking the EGLConfig, which emits + * EGL_BAD_CONFIG. + */ + RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE); + } + _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv); + + if ((conf->SurfaceType & EGL_PIXMAP_BIT) == 0) + RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE); + + if (native_pixmap == NULL) + RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE); + + if (_eglNativeSurfaceAlreadyUsed(disp, native_pixmap)) + RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); + surf = drv->API.CreatePixmapSurface(drv, disp, conf, native_pixmap, attrib_list); ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE; @@ -959,18 +1114,18 @@ eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); STATIC_ASSERT(sizeof(void*) == sizeof(pixmap)); return _eglCreatePixmapSurfaceCommon(disp, config, (void*) pixmap, - attrib_list); + attrib_list); } static EGLSurface EGLAPIENTRY eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config, - void *native_pixmap, - const EGLint *attrib_list) + void *native_pixmap, + const EGLint *attrib_list) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); - native_pixmap = fixupNativePixmap(disp, native_pixmap); + native_pixmap = _fixupNativePixmap(disp, native_pixmap); return _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap, attrib_list); } @@ -991,7 +1146,7 @@ eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config, if (attrib_list && !int_attribs) RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); - native_pixmap = fixupNativePixmap(disp, native_pixmap); + native_pixmap = _fixupNativePixmap(disp, native_pixmap); surface = _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap, int_attribs); free(int_attribs); @@ -1012,6 +1167,9 @@ eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv); + if ((conf->SurfaceType & EGL_PBUFFER_BIT) == 0) + RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE); + surf = drv->API.CreatePbufferSurface(drv, disp, conf, attrib_list); ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE; @@ -1046,7 +1204,11 @@ eglQuerySurface(EGLDisplay dpy, EGLSurface surface, _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); - ret = drv->API.QuerySurface(drv, disp, surf, attribute, value); + + if (drv->API.QuerySurface) + ret = drv->API.QuerySurface(drv, disp, surf, attribute, value); + else + ret = _eglQuerySurface(drv, disp, surf, attribute, value); RETURN_EGL_EVAL(disp, ret); } @@ -1062,7 +1224,8 @@ eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); - ret = drv->API.SurfaceAttrib(drv, disp, surf, attribute, value); + + ret = _eglSurfaceAttrib(drv, disp, surf, attribute, value); RETURN_EGL_EVAL(disp, ret); } @@ -1119,7 +1282,25 @@ eglSwapInterval(EGLDisplay dpy, EGLint interval) if (_eglGetSurfaceHandle(surf) == EGL_NO_SURFACE) RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); - ret = drv->API.SwapInterval(drv, disp, surf, interval); + if (surf->Type != EGL_WINDOW_BIT) + RETURN_EGL_EVAL(disp, EGL_TRUE); + + interval = CLAMP(interval, + surf->Config->MinSwapInterval, + surf->Config->MaxSwapInterval); + + if (surf->SwapInterval != interval) { + if (drv->API.SwapInterval) + ret = drv->API.SwapInterval(drv, disp, surf, interval); + else + ret = _eglSwapInterval(drv, disp, surf, interval); + } + else { + ret = EGL_TRUE; + } + + if (ret) + surf->SwapInterval = interval; RETURN_EGL_EVAL(disp, ret); } @@ -1144,23 +1325,41 @@ eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); #endif + if (surf->Type != EGL_WINDOW_BIT) + RETURN_EGL_EVAL(disp, EGL_TRUE); + + /* From the EGL 1.5 spec: + * + * If eglSwapBuffers is called and the native window associated with + * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is + * generated. + */ + if (surf->Lost) + RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_FALSE); + ret = drv->API.SwapBuffers(drv, disp, surf); + /* EGL_KHR_partial_update + * Frame boundary successfully reached, + * reset damage region and reset BufferAgeRead + */ + if (ret) { + surf->SetDamageRegionCalled = EGL_FALSE; + surf->BufferAgeRead = EGL_FALSE; + } + RETURN_EGL_EVAL(disp, ret); } -static EGLBoolean EGLAPIENTRY -eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface, - EGLint *rects, EGLint n_rects) +static EGLBoolean +_eglSwapBuffersWithDamageCommon(_EGLDisplay *disp, _EGLSurface *surf, + EGLint *rects, EGLint n_rects) { _EGLContext *ctx = _eglGetCurrentContext(); - _EGLDisplay *disp = _eglLockDisplay(dpy); - _EGLSurface *surf = _eglLookupSurface(surface, disp); _EGLDriver *drv; EGLBoolean ret; - _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); /* surface must be bound to current context in EGL 1.4 */ @@ -1168,11 +1367,104 @@ eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface, surf != ctx->DrawSurface) RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); + if (surf->Type != EGL_WINDOW_BIT) + RETURN_EGL_EVAL(disp, EGL_TRUE); + if ((n_rects > 0 && rects == NULL) || n_rects < 0) RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); ret = drv->API.SwapBuffersWithDamageEXT(drv, disp, surf, rects, n_rects); + /* EGL_KHR_partial_update + * Frame boundary successfully reached, + * reset damage region and reset BufferAgeRead + */ + if (ret) { + surf->SetDamageRegionCalled = EGL_FALSE; + surf->BufferAgeRead = EGL_FALSE; + } + + RETURN_EGL_EVAL(disp, ret); +} + +static EGLBoolean EGLAPIENTRY +eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface, + EGLint *rects, EGLint n_rects) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSurface *surf = _eglLookupSurface(surface, disp); + _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); + return _eglSwapBuffersWithDamageCommon(disp, surf, rects, n_rects); +} + +static EGLBoolean EGLAPIENTRY +eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface, + EGLint *rects, EGLint n_rects) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSurface *surf = _eglLookupSurface(surface, disp); + _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); + return _eglSwapBuffersWithDamageCommon(disp, surf, rects, n_rects); +} + +/** + * Clamp the rectangles so that they lie within the surface. + */ + +static void +_eglSetDamageRegionKHRClampRects(_EGLDisplay* disp, _EGLSurface* surf, + EGLint *rects, EGLint n_rects) +{ + EGLint i; + EGLint surf_height = surf->Height; + EGLint surf_width = surf->Width; + + for (i = 0; i < (4 * n_rects); i += 4) { + EGLint x1, y1, x2, y2; + x1 = rects[i]; + y1 = rects[i + 1]; + x2 = rects[i + 2] + x1; + y2 = rects[i + 3] + y1; + + rects[i] = CLAMP(x1, 0, surf_width); + rects[i + 1] = CLAMP(y1, 0, surf_height); + rects[i + 2] = CLAMP(x2, 0, surf_width) - rects[i]; + rects[i + 3] = CLAMP(y2, 0, surf_height) - rects[i + 1]; + } +} + +static EGLBoolean EGLAPIENTRY +eglSetDamageRegionKHR(EGLDisplay dpy, EGLSurface surface, + EGLint *rects, EGLint n_rects) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSurface *surf = _eglLookupSurface(surface, disp); + _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); + _EGLContext *ctx = _eglGetCurrentContext(); + _EGLDriver *drv; + EGLBoolean ret; + _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); + + if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || + surf->Type != EGL_WINDOW_BIT || + ctx->DrawSurface != surf || + surf->SwapBehavior != EGL_BUFFER_DESTROYED) + RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE); + + /* If the damage region is already set or + * buffer age is not queried between + * frame boundaries, throw bad access error + */ + + if (surf->SetDamageRegionCalled || !surf->BufferAgeRead) + RETURN_EGL_ERROR(disp, EGL_BAD_ACCESS, EGL_FALSE); + + _eglSetDamageRegionKHRClampRects(disp, surf, rects, n_rects); + ret = drv->API.SetDamageRegion(drv, disp, surf, rects, n_rects); + + if (ret) + surf->SetDamageRegionCalled = EGL_TRUE; + RETURN_EGL_EVAL(disp, ret); } @@ -1190,8 +1482,6 @@ eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target) native_pixmap_ptr = (void*) target; _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); - if (disp->Platform != _eglGetNativePlatform(disp->PlatformDisplay)) - RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_FALSE); ret = drv->API.CopyBuffers(drv, disp, surf, native_pixmap_ptr); RETURN_EGL_EVAL(disp, ret); @@ -1397,18 +1687,13 @@ eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLConfig *conf = _eglLookupConfig(config, disp); _EGLDriver *drv; - _EGLSurface *surf; - EGLSurface ret; _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv); - surf = drv->API.CreatePbufferFromClientBuffer(drv, disp, buftype, buffer, - conf, attrib_list); - ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE; - - RETURN_EGL_EVAL(disp, ret); + /* OpenVG is not supported */ + RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); } @@ -1441,7 +1726,7 @@ eglReleaseThread(void) static EGLImage _eglCreateImageCommon(_EGLDisplay *disp, EGLContext ctx, EGLenum target, - EGLClientBuffer buffer, const EGLint *attr_list) + EGLClientBuffer buffer, const EGLint *attr_list) { _EGLContext *context = _eglLookupContext(ctx, disp); _EGLDriver *drv; @@ -1459,8 +1744,8 @@ _eglCreateImageCommon(_EGLDisplay *disp, EGLContext ctx, EGLenum target, if (ctx != EGL_NO_CONTEXT && target == EGL_LINUX_DMA_BUF_EXT) RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR); - img = drv->API.CreateImageKHR(drv, - disp, context, target, buffer, attr_list); + img = drv->API.CreateImageKHR(drv, disp, context, target, + buffer, attr_list); ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR; RETURN_EGL_EVAL(disp, ret); @@ -1496,16 +1781,12 @@ eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, } -EGLBoolean EGLAPIENTRY -eglDestroyImage(EGLDisplay dpy, EGLImage image) +static EGLBoolean +_eglDestroyImageCommon(_EGLDisplay *disp, _EGLImage *img) { - _EGLDisplay *disp = _eglLockDisplay(dpy); - _EGLImage *img = _eglLookupImage(image, disp); _EGLDriver *drv; EGLBoolean ret; - _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE); - _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); if (!disp->Extensions.KHR_image_base) RETURN_EGL_EVAL(disp, EGL_FALSE); @@ -1518,10 +1799,28 @@ eglDestroyImage(EGLDisplay dpy, EGLImage image) RETURN_EGL_EVAL(disp, ret); } +EGLBoolean EGLAPIENTRY +eglDestroyImage(EGLDisplay dpy, EGLImage image) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLImage *img = _eglLookupImage(image, disp); + _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE); + return _eglDestroyImageCommon(disp, img); +} + +static EGLBoolean EGLAPIENTRY +eglDestroyImageKHR(EGLDisplay dpy, EGLImage image) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLImage *img = _eglLookupImage(image, disp); + _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE); + return _eglDestroyImageCommon(disp, img); +} + static EGLSync -_eglCreateSync(_EGLDisplay *disp, EGLenum type, const EGLint *attrib_list, - const EGLAttrib *attrib_list64, EGLBoolean is64, +_eglCreateSync(_EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_list, + EGLBoolean orig_is_EGLAttrib, EGLenum invalid_type_error) { _EGLContext *ctx = _eglGetCurrentContext(); @@ -1531,7 +1830,7 @@ _eglCreateSync(_EGLDisplay *disp, EGLenum type, const EGLint *attrib_list, _EGL_CHECK_DISPLAY(disp, EGL_NO_SYNC_KHR, drv); - if (!disp->Extensions.KHR_cl_event2 && is64) { + if (!disp->Extensions.KHR_cl_event2 && orig_is_EGLAttrib) { /* There exist two EGLAttrib variants of eglCreateSync*: * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2 @@ -1544,9 +1843,18 @@ _eglCreateSync(_EGLDisplay *disp, EGLenum type, const EGLint *attrib_list, RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR); } - /* return an error if the client API doesn't support GL_OES_EGL_sync */ - if (!ctx || ctx->Resource.Display != disp || - ctx->ClientAPI != EGL_OPENGL_ES_API) + /* If type is EGL_SYNC_FENCE and no context is current for the bound API + * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH + * error is generated. + */ + if (!ctx && + (type == EGL_SYNC_FENCE_KHR || type == EGL_SYNC_NATIVE_FENCE_ANDROID)) + RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR); + + /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */ + if (ctx && (ctx->Resource.Display != disp || + (ctx->ClientAPI != EGL_OPENGL_ES_API && + ctx->ClientAPI != EGL_OPENGL_API))) RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR); switch (type) { @@ -1562,11 +1870,15 @@ _eglCreateSync(_EGLDisplay *disp, EGLenum type, const EGLint *attrib_list, if (!disp->Extensions.KHR_cl_event2) RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR); break; + case EGL_SYNC_NATIVE_FENCE_ANDROID: + if (!disp->Extensions.ANDROID_native_fence_sync) + RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR); + break; default: RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR); } - sync = drv->API.CreateSyncKHR(drv, disp, type, attrib_list, attrib_list64); + sync = drv->API.CreateSyncKHR(drv, disp, type, attrib_list); ret = (sync) ? _eglLinkSync(sync) : EGL_NO_SYNC_KHR; RETURN_EGL_EVAL(disp, ret); @@ -1574,12 +1886,31 @@ _eglCreateSync(_EGLDisplay *disp, EGLenum type, const EGLint *attrib_list, static EGLSync EGLAPIENTRY -eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) +eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *int_list) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); - return _eglCreateSync(disp, type, attrib_list, NULL, EGL_FALSE, + + EGLSync sync; + EGLAttrib *attrib_list; + EGLint err; + + if (sizeof(int_list[0]) == sizeof(attrib_list[0])) { + attrib_list = (EGLAttrib *) int_list; + } else { + err = _eglConvertIntsToAttribs(int_list, &attrib_list); + if (err != EGL_SUCCESS) + RETURN_EGL_ERROR(disp, err, EGL_NO_SYNC); + } + + sync = _eglCreateSync(disp, type, attrib_list, EGL_FALSE, EGL_BAD_ATTRIBUTE); + + if (sizeof(int_list[0]) != sizeof(attrib_list[0])) + free(attrib_list); + + /* Don't double-unlock the display. _eglCreateSync already unlocked it. */ + return sync; } @@ -1588,7 +1919,7 @@ eglCreateSync64KHR(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); - return _eglCreateSync(disp, type, NULL, attrib_list, EGL_TRUE, + return _eglCreateSync(disp, type, attrib_list, EGL_TRUE, EGL_BAD_ATTRIBUTE); } @@ -1598,24 +1929,21 @@ eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); - return _eglCreateSync(disp, type, NULL, attrib_list, EGL_TRUE, + return _eglCreateSync(disp, type, attrib_list, EGL_TRUE, EGL_BAD_PARAMETER); } -EGLBoolean EGLAPIENTRY -eglDestroySync(EGLDisplay dpy, EGLSync sync) +static EGLBoolean +_eglDestroySync(_EGLDisplay *disp, _EGLSync *s) { - _EGLDisplay *disp = _eglLockDisplay(dpy); - _EGLSync *s = _eglLookupSync(sync, disp); _EGLDriver *drv; EGLBoolean ret; - _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); - _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv); assert(disp->Extensions.KHR_reusable_sync || - disp->Extensions.KHR_fence_sync); + disp->Extensions.KHR_fence_sync || + disp->Extensions.ANDROID_native_fence_sync); _eglUnlinkSync(s); ret = drv->API.DestroySyncKHR(drv, disp, s); @@ -1623,20 +1951,36 @@ eglDestroySync(EGLDisplay dpy, EGLSync sync) RETURN_EGL_EVAL(disp, ret); } +EGLBoolean EGLAPIENTRY +eglDestroySync(EGLDisplay dpy, EGLSync sync) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSync *s = _eglLookupSync(sync, disp); + _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); + return _eglDestroySync(disp, s); +} -EGLint EGLAPIENTRY -eglClientWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout) +static EGLBoolean EGLAPIENTRY +eglDestroySyncKHR(EGLDisplay dpy, EGLSync sync) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLSync *s = _eglLookupSync(sync, disp); + _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); + return _eglDestroySync(disp, s); +} + + +static EGLint +_eglClientWaitSyncCommon(_EGLDisplay *disp, EGLDisplay dpy, + _EGLSync *s, EGLint flags, EGLTime timeout) +{ _EGLDriver *drv; EGLint ret; - _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); - _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv); assert(disp->Extensions.KHR_reusable_sync || - disp->Extensions.KHR_fence_sync); + disp->Extensions.KHR_fence_sync || + disp->Extensions.ANDROID_native_fence_sync); if (s->SyncStatus == EGL_SIGNALED_KHR) RETURN_EGL_EVAL(disp, EGL_CONDITION_SATISFIED_KHR); @@ -1661,6 +2005,26 @@ eglClientWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout) RETURN_EGL_EVAL(disp, ret); } +EGLint EGLAPIENTRY +eglClientWaitSync(EGLDisplay dpy, EGLSync sync, + EGLint flags, EGLTime timeout) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSync *s = _eglLookupSync(sync, disp); + _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); + return _eglClientWaitSyncCommon(disp, dpy, s, flags, timeout); +} + +static EGLint EGLAPIENTRY +eglClientWaitSyncKHR(EGLDisplay dpy, EGLSync sync, + EGLint flags, EGLTime timeout) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSync *s = _eglLookupSync(sync, disp); + _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); + return _eglClientWaitSyncCommon(disp, dpy, s, flags, timeout); +} + static EGLint _eglWaitSyncCommon(_EGLDisplay *disp, _EGLSync *s, EGLint flags) @@ -1672,8 +2036,10 @@ _eglWaitSyncCommon(_EGLDisplay *disp, _EGLSync *s, EGLint flags) _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv); assert(disp->Extensions.KHR_wait_sync); - /* return an error if the client API doesn't support GL_OES_EGL_sync */ - if (ctx == EGL_NO_CONTEXT || ctx->ClientAPI != EGL_OPENGL_ES_API) + /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */ + if (ctx == EGL_NO_CONTEXT || + (ctx->ClientAPI != EGL_OPENGL_ES_API && + ctx->ClientAPI != EGL_OPENGL_API)) RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE); /* the API doesn't allow any flags yet */ @@ -1735,8 +2101,10 @@ _eglGetSyncAttribCommon(_EGLDisplay *disp, _EGLSync *s, EGLint attribute, EGLAtt _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv); assert(disp->Extensions.KHR_reusable_sync || - disp->Extensions.KHR_fence_sync); - ret = drv->API.GetSyncAttrib(drv, disp, s, attribute, value); + disp->Extensions.KHR_fence_sync || + disp->Extensions.ANDROID_native_fence_sync); + + ret = _eglGetSyncAttrib(drv, disp, s, attribute, value); RETURN_EGL_EVAL(disp, ret); } @@ -1747,6 +2115,10 @@ eglGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *valu _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLSync *s = _eglLookupSync(sync, disp); _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); + + if (!value) + RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); + return _eglGetSyncAttribCommon(disp, s, attribute, value); } @@ -1778,10 +2150,33 @@ eglGetSyncAttribKHR(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLint *valu return result; } +static EGLint EGLAPIENTRY +eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSync sync) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSync *s = _eglLookupSync(sync, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); + + /* the spec doesn't seem to specify what happens if the fence + * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems + * sensible: + */ + if (!(s && (s->Type == EGL_SYNC_NATIVE_FENCE_ANDROID))) + RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_NO_NATIVE_FENCE_FD_ANDROID); + + _EGL_CHECK_SYNC(disp, s, EGL_NO_NATIVE_FENCE_FD_ANDROID, drv); + assert(disp->Extensions.ANDROID_native_fence_sync); + ret = drv->API.DupNativeFenceFDANDROID(drv, disp, s); + + RETURN_EGL_EVAL(disp, ret); +} static EGLBoolean EGLAPIENTRY eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface, - EGLint numRects, const EGLint *rects) + EGLint numRects, const EGLint *rects) { _EGLContext *ctx = _eglGetCurrentContext(); _EGLDisplay *disp = _eglLockDisplay(dpy); @@ -1829,7 +2224,7 @@ eglCreateDRMImageMESA(EGLDisplay dpy, const EGLint *attr_list) static EGLBoolean EGLAPIENTRY eglExportDRMImageMESA(EGLDisplay dpy, EGLImage image, - EGLint *name, EGLint *handle, EGLint *stride) + EGLint *name, EGLint *handle, EGLint *stride) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLImage *img = _eglLookupImage(image, disp); @@ -1925,7 +2320,8 @@ eglCreateWaylandBufferFromImageWL(EGLDisplay dpy, EGLImage image) _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); _EGL_CHECK_DISPLAY(disp, NULL, drv); - assert(disp->Extensions.WL_create_wayland_buffer_from_image); + if (!disp->Extensions.WL_create_wayland_buffer_from_image) + RETURN_EGL_EVAL(disp, NULL); img = _eglLookupImage(image, disp); @@ -1959,11 +2355,11 @@ eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface, } static EGLBoolean EGLAPIENTRY -eglGetSyncValuesCHROMIUM(EGLDisplay display, EGLSurface surface, +eglGetSyncValuesCHROMIUM(EGLDisplay dpy, EGLSurface surface, EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc) { - _EGLDisplay *disp = _eglLockDisplay(display); + _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLSurface *surf = _eglLookupSurface(surface, disp); _EGLDriver *drv; EGLBoolean ret; @@ -2028,104 +2424,354 @@ eglExportDMABUFImageMESA(EGLDisplay dpy, EGLImage image, RETURN_EGL_EVAL(disp, ret); } +static EGLint EGLAPIENTRY +eglLabelObjectKHR(EGLDisplay dpy, EGLenum objectType, EGLObjectKHR object, + EGLLabelKHR label) +{ + _EGLDisplay *disp = NULL; + _EGLResourceType type; + + _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC); + + if (objectType == EGL_OBJECT_THREAD_KHR) { + _EGLThreadInfo *t = _eglGetCurrentThread(); + + if (!_eglIsCurrentThreadDummy()) { + t->Label = label; + return EGL_SUCCESS; + } + + RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_BAD_ALLOC); + } + + disp = _eglLockDisplay(dpy); + if (disp == NULL) + RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_BAD_DISPLAY); + + if (objectType == EGL_OBJECT_DISPLAY_KHR) { + if (dpy != (EGLDisplay) object) + RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER); + + disp->Label = label; + RETURN_EGL_EVAL(disp, EGL_SUCCESS); + } + + switch (objectType) { + case EGL_OBJECT_CONTEXT_KHR: + type = _EGL_RESOURCE_CONTEXT; + break; + case EGL_OBJECT_SURFACE_KHR: + type = _EGL_RESOURCE_SURFACE; + break; + case EGL_OBJECT_IMAGE_KHR: + type = _EGL_RESOURCE_IMAGE; + break; + case EGL_OBJECT_SYNC_KHR: + type = _EGL_RESOURCE_SYNC; + break; + case EGL_OBJECT_STREAM_KHR: + default: + RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER); + } + + if (_eglCheckResource(object, type, disp)) { + _EGLResource *res = (_EGLResource *) object; + + res->Label = label; + RETURN_EGL_EVAL(disp, EGL_SUCCESS); + } + + RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER); +} + +static EGLint EGLAPIENTRY +eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback, + const EGLAttrib *attrib_list) +{ + unsigned int newEnabled; + + _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC); + + mtx_lock(_eglGlobal.Mutex); + + newEnabled = _eglGlobal.debugTypesEnabled; + if (attrib_list != NULL) { + int i; + + for (i = 0; attrib_list[i] != EGL_NONE; i += 2) { + switch (attrib_list[i]) { + case EGL_DEBUG_MSG_CRITICAL_KHR: + case EGL_DEBUG_MSG_ERROR_KHR: + case EGL_DEBUG_MSG_WARN_KHR: + case EGL_DEBUG_MSG_INFO_KHR: + if (attrib_list[i + 1]) + newEnabled |= DebugBitFromType(attrib_list[i]); + else + newEnabled &= ~DebugBitFromType(attrib_list[i]); + break; + default: + // On error, set the last error code, call the current + // debug callback, and return the error code. + mtx_unlock(_eglGlobal.Mutex); + _eglReportError(EGL_BAD_ATTRIBUTE, NULL, + "Invalid attribute 0x%04lx", (unsigned long) attrib_list[i]); + return EGL_BAD_ATTRIBUTE; + } + } + } + + if (callback != NULL) { + _eglGlobal.debugCallback = callback; + _eglGlobal.debugTypesEnabled = newEnabled; + } else { + _eglGlobal.debugCallback = NULL; + _eglGlobal.debugTypesEnabled = _EGL_DEBUG_BIT_CRITICAL | _EGL_DEBUG_BIT_ERROR; + } + + mtx_unlock(_eglGlobal.Mutex); + return EGL_SUCCESS; +} + +static EGLBoolean EGLAPIENTRY +eglQueryDebugKHR(EGLint attribute, EGLAttrib *value) +{ + _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC); + + mtx_lock(_eglGlobal.Mutex); + + switch (attribute) { + case EGL_DEBUG_MSG_CRITICAL_KHR: + case EGL_DEBUG_MSG_ERROR_KHR: + case EGL_DEBUG_MSG_WARN_KHR: + case EGL_DEBUG_MSG_INFO_KHR: + if (_eglGlobal.debugTypesEnabled & DebugBitFromType(attribute)) + *value = EGL_TRUE; + else + *value = EGL_FALSE; + break; + case EGL_DEBUG_CALLBACK_KHR: + *value = (EGLAttrib) _eglGlobal.debugCallback; + break; + default: + mtx_unlock(_eglGlobal.Mutex); + _eglReportError(EGL_BAD_ATTRIBUTE, NULL, + "Invalid attribute 0x%04lx", (unsigned long) attribute); + return EGL_FALSE; + } + + mtx_unlock(_eglGlobal.Mutex); + return EGL_TRUE; +} + +static int +_eglFunctionCompare(const void *key, const void *elem) +{ + const char *procname = key; + const struct _egl_entrypoint *entrypoint = elem; + return strcmp(procname, entrypoint->name); +} + +static EGLBoolean EGLAPIENTRY +eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint max_formats, + EGLint *formats, EGLint *num_formats) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE); + + _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); + + ret = drv->API.QueryDmaBufFormatsEXT(drv, disp, max_formats, formats, + num_formats); + + RETURN_EGL_EVAL(disp, ret); +} + +static EGLBoolean EGLAPIENTRY +eglQueryDmaBufModifiersEXT(EGLDisplay dpy, EGLint format, EGLint max_modifiers, + EGLuint64KHR *modifiers, EGLBoolean *external_only, + EGLint *num_modifiers) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE); + + _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); + + ret = drv->API.QueryDmaBufModifiersEXT(drv, disp, format, max_modifiers, + modifiers, external_only, + num_modifiers); + + RETURN_EGL_EVAL(disp, ret); +} + +static void EGLAPIENTRY +eglSetBlobCacheFuncsANDROID(EGLDisplay *dpy, EGLSetBlobFuncANDROID set, + EGLGetBlobFuncANDROID get) +{ + /* This function does not return anything so we cannot + * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY. + */ + _EGLDisplay *disp = _eglLockDisplay(dpy); + if (!_eglSetFuncName(__func__, disp, EGL_OBJECT_DISPLAY_KHR, NULL)) { + if (disp) + _eglUnlockDisplay(disp); + return; + } + + _EGLDriver *drv = _eglCheckDisplay(disp, __func__); + if (!drv) { + if (disp) + _eglUnlockDisplay(disp); + return; + } + + if (!set || !get) { + _eglError(EGL_BAD_PARAMETER, + "eglSetBlobCacheFuncsANDROID: NULL handler given"); + _eglUnlockDisplay(disp); + return; + } + + if (disp->BlobCacheSet) { + _eglError(EGL_BAD_PARAMETER, + "eglSetBlobCacheFuncsANDROID: functions already set"); + _eglUnlockDisplay(disp); + return; + } + + disp->BlobCacheSet = set; + disp->BlobCacheGet = get; + + drv->API.SetBlobCacheFuncsANDROID(drv, disp, set, get); + + _eglUnlockDisplay(disp); +} + +static EGLBoolean EGLAPIENTRY +eglQueryDeviceAttribEXT(EGLDeviceEXT device, + EGLint attribute, + EGLAttrib *value) +{ + _EGLDevice *dev = _eglLookupDevice(device); + EGLBoolean ret; + + _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE); + if (!dev) + RETURN_EGL_ERROR(NULL, EGL_BAD_DEVICE_EXT, EGL_FALSE); + + ret = _eglQueryDeviceAttribEXT(dev, attribute, value); + RETURN_EGL_EVAL(NULL, ret); +} + +static const char * EGLAPIENTRY +eglQueryDeviceStringEXT(EGLDeviceEXT device, + EGLint name) +{ + _EGLDevice *dev = _eglLookupDevice(device); + + _EGL_FUNC_START(NULL, EGL_NONE, NULL, NULL); + if (!dev) + RETURN_EGL_ERROR(NULL, EGL_BAD_DEVICE_EXT, NULL); + + RETURN_EGL_EVAL(NULL, _eglQueryDeviceStringEXT(dev, name)); +} + +static EGLBoolean EGLAPIENTRY +eglQueryDevicesEXT(EGLint max_devices, + EGLDeviceEXT *devices, + EGLint *num_devices) +{ + EGLBoolean ret; + + _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE); + ret = _eglQueryDevicesEXT(max_devices, (_EGLDevice **) devices, + num_devices); + RETURN_EGL_EVAL(NULL, ret); +} + +static EGLBoolean EGLAPIENTRY +eglQueryDisplayAttribEXT(EGLDisplay dpy, + EGLint attribute, + EGLAttrib *value) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLDriver *drv; + + _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE); + _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); + + switch (attribute) { + case EGL_DEVICE_EXT: + *value = (EGLAttrib) disp->Device; + break; + default: + RETURN_EGL_ERROR(disp, EGL_BAD_ATTRIBUTE, EGL_FALSE); + } + RETURN_EGL_SUCCESS(disp, EGL_TRUE); +} + +static char * EGLAPIENTRY +eglGetDisplayDriverConfig(EGLDisplay dpy) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLDriver *drv; + char *ret; + + _EGL_FUNC_START(disp, EGL_NONE, NULL, NULL); + _EGL_CHECK_DISPLAY(disp, NULL, drv); + + assert(disp->Extensions.MESA_query_driver); + + ret = drv->API.QueryDriverConfig(disp); + RETURN_EGL_EVAL(disp, ret); +} + +static const char * EGLAPIENTRY +eglGetDisplayDriverName(EGLDisplay dpy) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLDriver *drv; + const char *ret; + + _EGL_FUNC_START(disp, EGL_NONE, NULL, NULL); + _EGL_CHECK_DISPLAY(disp, NULL, drv); + + assert(disp->Extensions.MESA_query_driver); + + ret = drv->API.QueryDriverName(disp); + RETURN_EGL_EVAL(disp, ret); +} + __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress(const char *procname) { - static const struct { - const char *name; - _EGLProc function; - } egl_functions[] = { - /* core functions queryable in the presence of - * EGL_KHR_get_all_proc_addresses or EGL 1.5 - */ - /* alphabetical order */ - { "eglBindAPI", (_EGLProc) eglBindAPI }, - { "eglBindTexImage", (_EGLProc) eglBindTexImage }, - { "eglChooseConfig", (_EGLProc) eglChooseConfig }, - { "eglCopyBuffers", (_EGLProc) eglCopyBuffers }, - { "eglCreateContext", (_EGLProc) eglCreateContext }, - { "eglCreatePbufferFromClientBuffer", (_EGLProc) eglCreatePbufferFromClientBuffer }, - { "eglCreatePbufferSurface", (_EGLProc) eglCreatePbufferSurface }, - { "eglCreatePixmapSurface", (_EGLProc) eglCreatePixmapSurface }, - { "eglCreateWindowSurface", (_EGLProc) eglCreateWindowSurface }, - { "eglDestroyContext", (_EGLProc) eglDestroyContext }, - { "eglDestroySurface", (_EGLProc) eglDestroySurface }, - { "eglGetConfigAttrib", (_EGLProc) eglGetConfigAttrib }, - { "eglGetConfigs", (_EGLProc) eglGetConfigs }, - { "eglGetCurrentContext", (_EGLProc) eglGetCurrentContext }, - { "eglGetCurrentDisplay", (_EGLProc) eglGetCurrentDisplay }, - { "eglGetCurrentSurface", (_EGLProc) eglGetCurrentSurface }, - { "eglGetDisplay", (_EGLProc) eglGetDisplay }, - { "eglGetError", (_EGLProc) eglGetError }, - { "eglGetProcAddress", (_EGLProc) eglGetProcAddress }, - { "eglInitialize", (_EGLProc) eglInitialize }, - { "eglMakeCurrent", (_EGLProc) eglMakeCurrent }, - { "eglQueryAPI", (_EGLProc) eglQueryAPI }, - { "eglQueryContext", (_EGLProc) eglQueryContext }, - { "eglQueryString", (_EGLProc) eglQueryString }, - { "eglQuerySurface", (_EGLProc) eglQuerySurface }, - { "eglReleaseTexImage", (_EGLProc) eglReleaseTexImage }, - { "eglReleaseThread", (_EGLProc) eglReleaseThread }, - { "eglSurfaceAttrib", (_EGLProc) eglSurfaceAttrib }, - { "eglSwapBuffers", (_EGLProc) eglSwapBuffers }, - { "eglSwapInterval", (_EGLProc) eglSwapInterval }, - { "eglTerminate", (_EGLProc) eglTerminate }, - { "eglWaitClient", (_EGLProc) eglWaitClient }, - { "eglWaitGL", (_EGLProc) eglWaitGL }, - { "eglWaitNative", (_EGLProc) eglWaitNative }, - { "eglCreateSync", (_EGLProc) eglCreateSync }, - { "eglDestroySync", (_EGLProc) eglDestroySync }, - { "eglClientWaitSync", (_EGLProc) eglClientWaitSync }, - { "eglGetSyncAttrib", (_EGLProc) eglGetSyncAttrib }, - { "eglWaitSync", (_EGLProc) eglWaitSync }, - { "eglCreateImage", (_EGLProc) eglCreateImage }, - { "eglDestroyImage", (_EGLProc) eglDestroyImage }, - { "eglGetPlatformDisplay", (_EGLProc) eglGetPlatformDisplay }, - { "eglCreatePlatformWindowSurface", (_EGLProc) eglCreatePlatformWindowSurface }, - { "eglCreatePlatformPixmapSurface", (_EGLProc) eglCreatePlatformPixmapSurface }, - { "eglCreateImageKHR", (_EGLProc) eglCreateImageKHR }, - { "eglDestroyImageKHR", (_EGLProc) eglDestroyImage }, - { "eglCreateSyncKHR", (_EGLProc) eglCreateSyncKHR }, - { "eglCreateSync64KHR", (_EGLProc) eglCreateSync64KHR }, - { "eglDestroySyncKHR", (_EGLProc) eglDestroySync }, - { "eglClientWaitSyncKHR", (_EGLProc) eglClientWaitSync }, - { "eglWaitSyncKHR", (_EGLProc) eglWaitSyncKHR }, - { "eglSignalSyncKHR", (_EGLProc) eglSignalSyncKHR }, - { "eglGetSyncAttribKHR", (_EGLProc) eglGetSyncAttribKHR }, - { "eglSwapBuffersRegionNOK", (_EGLProc) eglSwapBuffersRegionNOK }, - { "eglCreateDRMImageMESA", (_EGLProc) eglCreateDRMImageMESA }, - { "eglExportDRMImageMESA", (_EGLProc) eglExportDRMImageMESA }, - { "eglBindWaylandDisplayWL", (_EGLProc) eglBindWaylandDisplayWL }, - { "eglUnbindWaylandDisplayWL", (_EGLProc) eglUnbindWaylandDisplayWL }, - { "eglQueryWaylandBufferWL", (_EGLProc) eglQueryWaylandBufferWL }, - { "eglCreateWaylandBufferFromImageWL", (_EGLProc) eglCreateWaylandBufferFromImageWL }, - { "eglPostSubBufferNV", (_EGLProc) eglPostSubBufferNV }, - { "eglSwapBuffersWithDamageEXT", (_EGLProc) eglSwapBuffersWithDamageEXT }, - { "eglGetPlatformDisplayEXT", (_EGLProc) eglGetPlatformDisplayEXT }, - { "eglCreatePlatformWindowSurfaceEXT", (_EGLProc) eglCreatePlatformWindowSurfaceEXT }, - { "eglCreatePlatformPixmapSurfaceEXT", (_EGLProc) eglCreatePlatformPixmapSurfaceEXT }, - { "eglGetSyncValuesCHROMIUM", (_EGLProc) eglGetSyncValuesCHROMIUM }, - { "eglExportDMABUFImageQueryMESA", (_EGLProc) eglExportDMABUFImageQueryMESA }, - { "eglExportDMABUFImageMESA", (_EGLProc) eglExportDMABUFImageMESA }, - { NULL, NULL } + static const struct _egl_entrypoint egl_functions[] = { +#define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f }, +#include "eglentrypoint.h" +#undef EGL_ENTRYPOINT }; - EGLint i; - _EGLProc ret; + _EGLProc ret = NULL; if (!procname) RETURN_EGL_SUCCESS(NULL, NULL); _EGL_FUNC_START(NULL, EGL_NONE, NULL, NULL); - ret = NULL; if (strncmp(procname, "egl", 3) == 0) { - for (i = 0; egl_functions[i].name; i++) { - if (strcmp(egl_functions[i].name, procname) == 0) { - ret = egl_functions[i].function; - break; - } - } + const struct _egl_entrypoint *entrypoint = + bsearch(procname, + egl_functions, ARRAY_SIZE(egl_functions), + sizeof(egl_functions[0]), + _eglFunctionCompare); + if (entrypoint) + ret = entrypoint->function; } + if (!ret) ret = _eglGetDriverProc(procname); @@ -2158,7 +2804,7 @@ _eglLockDisplayInterop(EGLDisplay dpy, EGLContext context, return MESA_GLINTEROP_SUCCESS; } -int +PUBLIC int MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy, EGLContext context, struct mesa_glinterop_device_info *out) { @@ -2180,7 +2826,7 @@ MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy, EGLContext context, return ret; } -int +PUBLIC int MesaGLInteropEGLExportObject(EGLDisplay dpy, EGLContext context, struct mesa_glinterop_export_in *in, struct mesa_glinterop_export_out *out)