From f4a41155479e68bf55740c1dfffafc78e4c02087 Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Wed, 5 Oct 2016 12:34:34 -0400 Subject: glamor: Use eglGetPlatformDisplay{,EXT} if we can eglGetDisplay forces the implementation to guess which kind of display it's been handed. glvnd does something different from Mesa, and in general it's impossible for the library to get this right. Add a new inline that gets the logic right, and works around a quirk in epoxy. Signed-off-by: Adam Jackson Reviewed-by: Eric Anholt --- glamor/Makefile.am | 4 ++- glamor/glamor_egl.c | 8 +++--- glamor/glamor_egl.h | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 glamor/glamor_egl.h (limited to 'glamor') diff --git a/glamor/Makefile.am b/glamor/Makefile.am index c631c530b..8c79994e0 100644 --- a/glamor/Makefile.am +++ b/glamor/Makefile.am @@ -54,6 +54,8 @@ libglamor_la_SOURCES += \ glamor_xv.c endif -libglamor_egl_stubs_la_SOURCES = glamor_egl_stubs.c +libglamor_egl_stubs_la_SOURCES = \ + glamor_egl_stubs.c \ + glamor_egl.h sdk_HEADERS = glamor.h diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c index 2b9e0e109..9cc0f8d6e 100644 --- a/glamor/glamor_egl.c +++ b/glamor/glamor_egl.c @@ -43,9 +43,7 @@ #include #endif -#define MESA_EGL_NO_X11_HEADERS -#include -#include +#include "glamor_egl.h" #include "glamor.h" #include "glamor_priv.h" @@ -768,7 +766,9 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd) ErrorF("couldn't get display device\n"); goto error; } - glamor_egl->display = eglGetDisplay(glamor_egl->gbm); + + glamor_egl->display = glamor_egl_get_display(EGL_PLATFORM_GBM_MESA, + glamor_egl->gbm); #else glamor_egl->display = eglGetDisplay((EGLNativeDisplayType) (intptr_t) fd); #endif diff --git a/glamor/glamor_egl.h b/glamor/glamor_egl.h new file mode 100644 index 000000000..147aae620 --- /dev/null +++ b/glamor/glamor_egl.h @@ -0,0 +1,82 @@ +/* + * Copyright © 2016 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Adam Jackson + */ + +#ifndef GLAMOR_EGL_H +#define GLAMOR_EGL_H + +#define MESA_EGL_NO_X11_HEADERS +#include +#include + +/* + * Create an EGLDisplay from a native display type. This is a little quirky + * for a few reasons. + * + * 1: GetPlatformDisplayEXT and GetPlatformDisplay are the API you want to + * use, but have different function signatures in the third argument; this + * happens not to matter for us, at the moment, but it means epoxy won't alias + * them together. + * + * 2: epoxy 1.3 and earlier don't understand EGL client extensions, which + * means you can't call "eglGetPlatformDisplayEXT" directly, as the resolver + * will crash. + * + * 3: You can't tell whether you have EGL 1.5 at this point, because + * eglQueryString(EGL_VERSION) is a property of the display, which we don't + * have yet. So you have to query for extensions no matter what. Fortunately + * epoxy_has_egl_extension _does_ let you query for client extensions, so + * we don't have to write our own extension string parsing. + */ +static inline EGLDisplay +glamor_egl_get_display(EGLint type, void *native) +{ + EGLDisplay dpy = NULL; + + /* If we're EGL 1.5, the KHR extension will be there, try that */ + if (epoxy_has_egl_extension(NULL, "EGL_KHR_platform_base")) { + PFNEGLGETPLATFORMDISPLAYPROC getPlatformDisplay = + (void *) eglGetProcAddress("eglGetPlatformDisplay"); + if (getPlatformDisplay) + dpy = getPlatformDisplay(type, native, NULL); + if (dpy) + return dpy; + } + + /* Okay, maybe the EXT extension works */ + if (epoxy_has_egl_extension(NULL, "EGL_EXT_platform_base")) { + PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplayEXT = + (void *) eglGetProcAddress("eglGetPlatformDisplayEXT"); + if (getPlatformDisplayEXT) + dpy = getPlatformDisplayEXT(type, native, NULL); + if (dpy) + return dpy; + } + + /* Welp, everything is awful. */ + return eglGetDisplay(native); +} + +#endif -- cgit v1.2.3