From f74b368c08f9bd1f638f32bccdb4da6dbd89cfea Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Fri, 24 Jul 2009 16:54:55 +0200 Subject: Add an ARGB check for EGL-provided X visuals Don't just assume they're going to be ARGB just because the config has an alpha channel. This makes QGLWidgets with WA_TranslucentBackground set work again on the rx71 when running under xcompmgr. Reviewed-By: Trustme --- src/opengl/qgl_x11egl.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/opengl/qgl_x11egl.cpp b/src/opengl/qgl_x11egl.cpp index 99b026d..c6904fe 100644 --- a/src/opengl/qgl_x11egl.cpp +++ b/src/opengl/qgl_x11egl.cpp @@ -258,7 +258,8 @@ void QGLWidget::setContext(QGLContext *context, const QGLContext* shareContext, // If the application has set WA_TranslucentBackground and not explicitly set // the alpha buffer size to zero, modify the format so it have an alpha channel QGLFormat& fmt = d->glcx->d_func()->glFormat; - if (testAttribute(Qt::WA_TranslucentBackground) && fmt.alphaBufferSize() == -1) + const bool useArgbVisual = testAttribute(Qt::WA_TranslucentBackground); + if (useArgbVisual && fmt.alphaBufferSize() == -1) fmt.setAlphaBufferSize(1); bool createFailed = false; @@ -297,8 +298,24 @@ void QGLWidget::setContext(QGLContext *context, const QGLContext* shareContext, int matchingCount = 0; chosenVisualInfo = XGetVisualInfo(x11Info().display(), VisualIDMask, &vi, &matchingCount); if (chosenVisualInfo) { - qDebug("Using X Visual ID (%d) provided by EGL", (int)vi.visualid); - vi = *chosenVisualInfo; + if (useArgbVisual) { + // Check to make sure the visual provided by EGL is ARGB + XRenderPictFormat *format; + format = XRenderFindVisualFormat(x11Info().display(), chosenVisualInfo->visual); + if (format->type == PictTypeDirect && format->direct.alphaMask) { + qDebug("Using opaque X Visual ID (%d) provided by EGL", (int)vi.visualid); + vi = *chosenVisualInfo; + } + else { + qWarning("Warning: EGL suggested using X visual ID %d for config %d, but this is not ARGB", + nativeVisualId, (int)qeglCtx->config()); + vi.visualid = 0; + } + } + else { + qDebug("Using opaque X Visual ID (%d) provided by EGL", (int)vi.visualid); + vi = *chosenVisualInfo; + } XFree(chosenVisualInfo); } else { -- cgit v0.12