Skip to content

Commit

Permalink
render: fix EGL extensions not loaded
Browse files Browse the repository at this point in the history
Some extensions are only advertised by the EGL implementation with a
non-zero EGLDisplay. That's the case when the extension can only be
enabled when the hardware/driver supports it for instance.

Instead of checking for all extensions without a display, check only for
EGL_EXT_platform_base and EGL_KHR_debug which are used before
eglGetDisplay. Check for all other extensions when we have a display.

Closes: swaywm#1955
  • Loading branch information
emersion authored and filips committed Mar 15, 2020
1 parent 1122b2b commit b4eb577
Showing 1 changed file with 49 additions and 40 deletions.
89 changes: 49 additions & 40 deletions render/egl.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ static void init_dmabuf_formats(struct wlr_egl *egl) {

bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *remote_display,
EGLint *config_attribs, EGLint visual_id) {
// Check for EGL_EXT_platform_base before creating a display, because we
// actually use this extension to create displays. Check for EGL_KHR_debug
// before creating display to get EGL logs as soon as possible.
const char *exts_str = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
if (exts_str == NULL) {
wlr_log(WLR_ERROR, "Failed to query EGL extensions");
Expand All @@ -148,6 +151,52 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *remote_display,
load_egl_proc(&egl->procs.eglCreatePlatformWindowSurfaceEXT,
"eglCreatePlatformWindowSurfaceEXT");

if (check_egl_ext(exts_str, "EGL_KHR_debug")) {
load_egl_proc(&egl->procs.eglDebugMessageControlKHR,
"eglDebugMessageControlKHR");

static const EGLAttrib debug_attribs[] = {
EGL_DEBUG_MSG_CRITICAL_KHR, EGL_TRUE,
EGL_DEBUG_MSG_ERROR_KHR, EGL_TRUE,
EGL_DEBUG_MSG_WARN_KHR, EGL_TRUE,
EGL_DEBUG_MSG_INFO_KHR, EGL_TRUE,
EGL_NONE,
};
egl->procs.eglDebugMessageControlKHR(egl_log, debug_attribs);
}

if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) {
wlr_log(WLR_ERROR, "Failed to bind to the OpenGL ES API");
goto error;
}

if (platform == EGL_PLATFORM_SURFACELESS_MESA) {
assert(remote_display == NULL);
egl->display = egl->procs.eglGetPlatformDisplayEXT(platform,
EGL_DEFAULT_DISPLAY, NULL);
} else {
egl->display = egl->procs.eglGetPlatformDisplayEXT(platform,
remote_display, NULL);
}
if (egl->display == EGL_NO_DISPLAY) {
wlr_log(WLR_ERROR, "Failed to create EGL display");
goto error;
}

egl->platform = platform;

EGLint major, minor;
if (eglInitialize(egl->display, &major, &minor) == EGL_FALSE) {
wlr_log(WLR_ERROR, "Failed to initialize EGL");
goto error;
}

exts_str = eglQueryString(egl->display, EGL_EXTENSIONS);
if (exts_str == NULL) {
wlr_log(WLR_ERROR, "Failed to query EGL extensions");
return false;
}

if (check_egl_ext(exts_str, "EGL_KHR_image_base")) {
egl->exts.image_base_khr = true;
load_egl_proc(&egl->procs.eglCreateImageKHR, "eglCreateImageKHR");
Expand Down Expand Up @@ -195,46 +244,6 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *remote_display,
"eglQueryWaylandBufferWL");
}

if (check_egl_ext(exts_str, "EGL_KHR_debug")) {
load_egl_proc(&egl->procs.eglDebugMessageControlKHR,
"eglDebugMessageControlKHR");

static const EGLAttrib debug_attribs[] = {
EGL_DEBUG_MSG_CRITICAL_KHR, EGL_TRUE,
EGL_DEBUG_MSG_ERROR_KHR, EGL_TRUE,
EGL_DEBUG_MSG_WARN_KHR, EGL_TRUE,
EGL_DEBUG_MSG_INFO_KHR, EGL_TRUE,
EGL_NONE,
};
egl->procs.eglDebugMessageControlKHR(egl_log, debug_attribs);
}

if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) {
wlr_log(WLR_ERROR, "Failed to bind to the OpenGL ES API");
goto error;
}

if (platform == EGL_PLATFORM_SURFACELESS_MESA) {
assert(remote_display == NULL);
egl->display = egl->procs.eglGetPlatformDisplayEXT(platform,
EGL_DEFAULT_DISPLAY, NULL);
} else {
egl->display = egl->procs.eglGetPlatformDisplayEXT(platform,
remote_display, NULL);
}
if (egl->display == EGL_NO_DISPLAY) {
wlr_log(WLR_ERROR, "Failed to create EGL display");
goto error;
}

egl->platform = platform;

EGLint major, minor;
if (eglInitialize(egl->display, &major, &minor) == EGL_FALSE) {
wlr_log(WLR_ERROR, "Failed to initialize EGL");
goto error;
}

if (!egl_get_config(egl->display, config_attribs, &egl->config, visual_id)) {
wlr_log(WLR_ERROR, "Failed to get EGL config");
goto error;
Expand Down

0 comments on commit b4eb577

Please sign in to comment.