summaryrefslogtreecommitdiffstats
path: root/src/egl/main/eglapi.c
diff options
context:
space:
mode:
authorMatt Turner <[email protected]>2015-03-10 11:41:57 -0700
committerMatt Turner <[email protected]>2015-03-13 10:42:38 -0700
commitdac2e7deaae2540645a6b485c7d1f47195689116 (patch)
tree4168a4bdc7f1dacc9459af876bcd43ce23310bb8 /src/egl/main/eglapi.c
parentb43bbfa90ace596c8b2e0b3954a5f69924726c59 (diff)
egl: Create queryable strings in eglInitialize().
Creating/recreating the strings in eglQueryString() is extra work and isn't thread-safe, as exhibited by shader-db's run.c using libepoxy. Multiple threads in run.c call eglReleaseThread() around the same time. libepoxy calls eglQueryString() to determine whether eglReleaseThread() exists, and our EGL implementation passes a pointer to the version string to libepoxy while simultaneously overwriting the string, leading to a failure in libepoxy. Moreover, the EGL spec says (emphasis mine): "eglQueryString returns a pointer to a *static*, zero-terminated string" This patch moves some auxiliary functions from eglmisc.c to eglapi.c so that they may be used to create the extension, API, and version strings once during eglInitialize(). The auxiliary functions are renamed from _eglUpdate* to _eglCreate*, and some checks made unnecessary by calling the functions from eglInitialize() are removed. Reviewed-by: Chad Versace <[email protected]>
Diffstat (limited to 'src/egl/main/eglapi.c')
-rw-r--r--src/egl/main/eglapi.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index a74efcd8f99..bd8ffa0a493 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -102,6 +102,7 @@
#include "eglmode.h"
#include "eglimage.h"
#include "eglsync.h"
+#include "eglstring.h"
/**
@@ -343,6 +344,111 @@ eglGetPlatformDisplayEXT(EGLenum platform, void *native_display,
}
/**
+ * Copy the extension into the string and update the string pointer.
+ */
+static EGLint
+_eglAppendExtension(char **str, const char *ext)
+{
+ char *s = *str;
+ size_t len = strlen(ext);
+
+ if (s) {
+ memcpy(s, ext, len);
+ s[len++] = ' ';
+ s[len] = '\0';
+
+ *str += len;
+ }
+ else {
+ len++;
+ }
+
+ return (EGLint) len;
+}
+
+/**
+ * Examine the individual extension enable/disable flags and recompute
+ * the driver's Extensions string.
+ */
+static void
+_eglCreateExtensionsString(_EGLDisplay *dpy)
+{
+#define _EGL_CHECK_EXTENSION(ext) \
+ do { \
+ if (dpy->Extensions.ext) { \
+ _eglAppendExtension(&exts, "EGL_" #ext); \
+ assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
+ } \
+ } while (0)
+
+ char *exts = dpy->ExtensionsString;
+
+ _EGL_CHECK_EXTENSION(MESA_screen_surface);
+ _EGL_CHECK_EXTENSION(MESA_copy_context);
+ _EGL_CHECK_EXTENSION(MESA_drm_display);
+ _EGL_CHECK_EXTENSION(MESA_drm_image);
+ _EGL_CHECK_EXTENSION(MESA_configless_context);
+
+ _EGL_CHECK_EXTENSION(WL_bind_wayland_display);
+ _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image);
+
+ _EGL_CHECK_EXTENSION(KHR_image_base);
+ _EGL_CHECK_EXTENSION(KHR_image_pixmap);
+ if (dpy->Extensions.KHR_image_base && dpy->Extensions.KHR_image_pixmap)
+ _eglAppendExtension(&exts, "EGL_KHR_image");
+
+ _EGL_CHECK_EXTENSION(KHR_vg_parent_image);
+ _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses);
+ _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image);
+ _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image);
+ _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image);
+ _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image);
+
+ _EGL_CHECK_EXTENSION(KHR_reusable_sync);
+ _EGL_CHECK_EXTENSION(KHR_fence_sync);
+
+ _EGL_CHECK_EXTENSION(KHR_surfaceless_context);
+ _EGL_CHECK_EXTENSION(KHR_create_context);
+
+ _EGL_CHECK_EXTENSION(NOK_swap_region);
+ _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap);
+
+ _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer);
+
+ _EGL_CHECK_EXTENSION(CHROMIUM_sync_control);
+
+ _EGL_CHECK_EXTENSION(EXT_create_context_robustness);
+ _EGL_CHECK_EXTENSION(EXT_buffer_age);
+ _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage);
+ _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import);
+
+ _EGL_CHECK_EXTENSION(NV_post_sub_buffer);
+#undef _EGL_CHECK_EXTENSION
+}
+
+static void
+_eglCreateAPIsString(_EGLDisplay *dpy)
+{
+ if (dpy->ClientAPIs & EGL_OPENGL_BIT)
+ strcat(dpy->ClientAPIsString, "OpenGL ");
+
+ if (dpy->ClientAPIs & EGL_OPENGL_ES_BIT)
+ strcat(dpy->ClientAPIsString, "OpenGL_ES ");
+
+ if (dpy->ClientAPIs & EGL_OPENGL_ES2_BIT)
+ strcat(dpy->ClientAPIsString, "OpenGL_ES2 ");
+
+ if (dpy->ClientAPIs & EGL_OPENGL_ES3_BIT_KHR)
+ strcat(dpy->ClientAPIsString, "OpenGL_ES3 ");
+
+ if (dpy->ClientAPIs & EGL_OPENVG_BIT)
+ strcat(dpy->ClientAPIsString, "OpenVG ");
+
+ assert(strlen(dpy->ClientAPIsString) < sizeof(dpy->ClientAPIsString));
+}
+
+
+/**
* This is typically the second EGL function that an application calls.
* Here we load/initialize the actual hardware driver.
*/
@@ -377,6 +483,12 @@ eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
* EGL_KHR_get_all_proc_addresses also.
*/
disp->Extensions.KHR_get_all_proc_addresses = EGL_TRUE;
+
+ _eglCreateExtensionsString(disp);
+ _eglCreateAPIsString(disp);
+ _eglsnprintf(disp->VersionString, sizeof(disp->VersionString),
+ "%d.%d (%s)", disp->VersionMajor, disp->VersionMinor,
+ disp->Driver->Name);
}
/* Update applications version of major and minor if not NULL */