Commit f4a41155 authored by Adam Jackson's avatar Adam Jackson 🎧

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's avatarAdam Jackson <ajax@redhat.com>
Reviewed-by: Eric Anholt's avatarEric Anholt <eric@anholt.net>
parent 95d3980c
......@@ -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
......@@ -43,9 +43,7 @@
#include <drm_fourcc.h>
#endif
#define MESA_EGL_NO_X11_HEADERS
#include <epoxy/gl.h>
#include <epoxy/egl.h>
#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
......
/*
* 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 <ajax@redhat.com>
*/
#ifndef GLAMOR_EGL_H
#define GLAMOR_EGL_H
#define MESA_EGL_NO_X11_HEADERS
#include <epoxy/gl.h>
#include <epoxy/egl.h>
/*
* 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
......@@ -31,8 +31,7 @@
#define MESA_EGL_NO_X11_HEADERS
#include <gbm.h>
#include <epoxy/egl.h>
#include <epoxy/gl.h>
#include <glamor_egl.h>
#include <glamor.h>
#include <glamor_context.h>
......@@ -292,9 +291,10 @@ xwl_drm_init_egl(struct xwl_screen *xwl_screen)
return;
}
xwl_screen->egl_display = eglGetDisplay(xwl_screen->gbm);
xwl_screen->egl_display = glamor_egl_get_display(EGL_PLATFORM_GBM_MESA,
xwl_screen->gbm);
if (xwl_screen->egl_display == EGL_NO_DISPLAY) {
ErrorF("eglGetDisplay() failed\n");
ErrorF("glamor_egl_get_display() failed\n");
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment