From 0ccecbc4275783e217d3c1ab1d3acd6988368757 Mon Sep 17 00:00:00 2001 From: Alexey Min Date: Fri, 6 Apr 2018 00:17:08 +0300 Subject: [PATCH] drm backend: choose correct EGL config with mesa-18 Do not blindly select first EGL config from returned list, but choose the one that matches GBM surfaces, that will be created later. GBM surfaces are created with GBM_FORMAT_XRGB8888 format, so choose the config that matches it. With wrong format EglGbmBackend::resetOutput() will later fail with error EGL_BAD_MATCH. Test Plan: Compile, run startplasmacompositor. Verify that OpenGL compositing is used, either by kwin debug console, or by kwin support information. Reviewers: graesslin, davidedmundson, #kwin, #plasma_on_wayland, bshah Reviewed By: davidedmundson Subscribers: zzag, kwin, #kwin Tags: #kwin, #plasma_on_wayland Differential Revision: https://phabricator.kde.org/D11758 --- plugins/platforms/drm/egl_gbm_backend.cpp | 38 ++++++++++++++++++----- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/plugins/platforms/drm/egl_gbm_backend.cpp b/plugins/platforms/drm/egl_gbm_backend.cpp index 092cee3774..73755d8334 100644 --- a/plugins/platforms/drm/egl_gbm_backend.cpp +++ b/plugins/platforms/drm/egl_gbm_backend.cpp @@ -243,17 +243,41 @@ bool EglGbmBackend::initBufferConfigs() EGLint count; EGLConfig configs[1024]; - if (eglChooseConfig(eglDisplay(), config_attribs, configs, 1, &count) == EGL_FALSE) { + if (!eglChooseConfig(eglDisplay(), config_attribs, configs, sizeof(configs)/sizeof(EGLConfig), &count)) { qCCritical(KWIN_DRM) << "choose config failed"; return false; } - if (count != 1) { - qCCritical(KWIN_DRM) << "choose config did not return a config" << count; - return false; - } - setConfig(configs[0]); - return true; + qCDebug(KWIN_DRM) << "EGL buffer configs count:" << count; + + // loop through all configs, chosing the first one that has suitable format + for (EGLint i = 0; i < count; i++) { + EGLint gbmFormat; + // query some configuration parameters, to show in debug log + eglGetConfigAttrib(eglDisplay(), configs[i], EGL_NATIVE_VISUAL_ID, &gbmFormat); + + if (KWIN_DRM().isDebugEnabled()) { + // GBM formats are declared as FOURCC code (integer from ASCII chars, so use this fact) + char gbmFormatStr[sizeof(EGLint) + 1] = {0}; + memcpy(gbmFormatStr, &gbmFormat, sizeof(EGLint)); + // query number of bits for color channel + EGLint blueSize, redSize, greenSize, alphaSize; + eglGetConfigAttrib(eglDisplay(), configs[i], EGL_RED_SIZE, &redSize); + eglGetConfigAttrib(eglDisplay(), configs[i], EGL_GREEN_SIZE, &greenSize); + eglGetConfigAttrib(eglDisplay(), configs[i], EGL_BLUE_SIZE, &blueSize); + eglGetConfigAttrib(eglDisplay(), configs[i], EGL_ALPHA_SIZE, &alphaSize); + qCDebug(KWIN_DRM) << " EGL config #" << i << " has GBM FOURCC format:" << gbmFormatStr + << "; color sizes (RGBA order):" << redSize << greenSize << blueSize << alphaSize; + } + + if ((gbmFormat == GBM_FORMAT_XRGB8888) || (gbmFormat == GBM_FORMAT_ARGB8888)) { + setConfig(configs[i]); + return true; + } + } + + qCCritical(KWIN_DRM) << "choose EGL config did not return a suitable config" << count; + return false; } void EglGbmBackend::present()