xserver-multidpi/glamor/glamor_egl.h
Hans De Goede 05e1964425 glamor: Trust eglGetPlatformDisplayEXT if it exists
If the libEGL we are using has eglGetPlatformDisplayEXT, yet it still
returns NULL, then this very likely means that it does not support the
type (e.g. EGL_PLATFORM_GBM_MESA) passed in, and then returning NULL is
the right thing to do.

This avoids falling back to an eglGetDisplay() implementation which does
not understands the passed in gbm handle, treats it as a pointer to
something else completely, followed by a crash sooner or later.

Specifically this fixes using the nvidia binary driver, with nvidia's
libEGL + the modesetting driver on a secondary GPU crashing inside
glamor_egl_init() sometimes.

Cc: Eric Anholt <eric@anholt.net>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2017-01-02 13:07:25 -05:00

78 lines
3.1 KiB
C

/*
* 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.
*
* 4. There is no EGL_KHR_platform_base to complement the EXT one, thus one
* needs to know EGL 1.5 is supported in order to use the eglGetPlatformDisplay
* function pointer.
* We can workaround this (circular dependency) by probing for the EGL 1.5
* platform extensions (EGL_KHR_platform_gbm and friends) yet it doesn't seem
* like mesa will be able to adverise these (even though it can do EGL 1.5).
*/
static inline EGLDisplay
glamor_egl_get_display(EGLint type, void *native)
{
EGLDisplay dpy = NULL;
/* In practise any EGL 1.5 implementation would support the EXT extension */
if (epoxy_has_egl_extension(NULL, "EGL_EXT_platform_base")) {
PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplayEXT =
(void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
if (getPlatformDisplayEXT)
return getPlatformDisplayEXT(type, native, NULL);
}
/* Welp, everything is awful. */
return eglGetDisplay(native);
}
#endif