diff options
author | Ilya Fedin <fedin-ilja2010@ya.ru> | 2021-10-04 10:32:38 +0400 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2022-06-20 15:53:33 +0000 |
commit | c3e624eb50ff56dd0d172999a49c454f37ca62cd (patch) | |
tree | 4d1919fb65e0e0cefc5395af6ee311f0ee1319d5 /src/gui/opengl | |
parent | 1c106b37c75adc96df33cd59e8a5e3822385b099 (diff) |
Port QXlibEglIntegration::getCompatibleVisualId to xcb
In combination with EGL_EXT_platform_xcb support, this allows xcb_egl
to be used without xlib. Without EGL_EXT_platform_xcb support, this
still reduces amount of code using xlib.
Pick-to: 6.4
Change-Id: I29e2b29f7ef8ea34320887f62697f84232b86fba
Reviewed-by: Liang Qi <liang.qi@qt.io>
Diffstat (limited to 'src/gui/opengl')
-rw-r--r-- | src/gui/opengl/platform/egl/qxlibeglintegration.cpp | 130 | ||||
-rw-r--r-- | src/gui/opengl/platform/egl/qxlibeglintegration_p.h | 33 |
2 files changed, 0 insertions, 163 deletions
diff --git a/src/gui/opengl/platform/egl/qxlibeglintegration.cpp b/src/gui/opengl/platform/egl/qxlibeglintegration.cpp deleted file mode 100644 index cfabedc8c0..0000000000 --- a/src/gui/opengl/platform/egl/qxlibeglintegration.cpp +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (C) 2020 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include <QtCore/qloggingcategory.h> -#include "qxlibeglintegration_p.h" - -QT_BEGIN_NAMESPACE - -Q_LOGGING_CATEGORY(lcXlibEglDebug, "qt.egl.xlib.debug") - -VisualID QXlibEglIntegration::getCompatibleVisualId(Display *display, EGLDisplay eglDisplay, EGLConfig config) -{ - VisualID visualId = 0; - EGLint eglValue = 0; - - EGLint configRedSize = 0; - eglGetConfigAttrib(eglDisplay, config, EGL_RED_SIZE, &configRedSize); - - EGLint configGreenSize = 0; - eglGetConfigAttrib(eglDisplay, config, EGL_GREEN_SIZE, &configGreenSize); - - EGLint configBlueSize = 0; - eglGetConfigAttrib(eglDisplay, config, EGL_BLUE_SIZE, &configBlueSize); - - EGLint configAlphaSize = 0; - eglGetConfigAttrib(eglDisplay, config, EGL_ALPHA_SIZE, &configAlphaSize); - - eglGetConfigAttrib(eglDisplay, config, EGL_CONFIG_ID, &eglValue); - int configId = eglValue; - - // See if EGL provided a valid VisualID: - eglGetConfigAttrib(eglDisplay, config, EGL_NATIVE_VISUAL_ID, &eglValue); - visualId = (VisualID)eglValue; - if (visualId) { - // EGL has suggested a visual id, so get the rest of the visual info for that id: - XVisualInfo visualInfoTemplate; - memset(&visualInfoTemplate, 0, sizeof(XVisualInfo)); - visualInfoTemplate.visualid = visualId; - - XVisualInfo *chosenVisualInfo; - int matchingCount = 0; - chosenVisualInfo = XGetVisualInfo(display, VisualIDMask, &visualInfoTemplate, &matchingCount); - if (chosenVisualInfo) { - // Skip size checks if implementation supports non-matching visual - // and config (QTBUG-9444). - if (q_hasEglExtension(eglDisplay,"EGL_NV_post_convert_rounding")) { - XFree(chosenVisualInfo); - return visualId; - } - // Skip also for i.MX6 where 565 visuals are suggested for the default 444 configs and it works just fine. - const char *vendor = eglQueryString(eglDisplay, EGL_VENDOR); - if (vendor && strstr(vendor, "Vivante")) { - XFree(chosenVisualInfo); - return visualId; - } - - int visualRedSize = qPopulationCount(chosenVisualInfo->red_mask); - int visualGreenSize = qPopulationCount(chosenVisualInfo->green_mask); - int visualBlueSize = qPopulationCount(chosenVisualInfo->blue_mask); - int visualAlphaSize = chosenVisualInfo->depth - visualRedSize - visualBlueSize - visualGreenSize; - - const bool visualMatchesConfig = visualRedSize >= configRedSize - && visualGreenSize >= configGreenSize - && visualBlueSize >= configBlueSize - && visualAlphaSize >= configAlphaSize; - - // In some cases EGL tends to suggest a 24-bit visual for 8888 - // configs. In such a case we have to fall back to XGetVisualInfo. - if (!visualMatchesConfig) { - visualId = 0; - qCDebug(lcXlibEglDebug, - "EGL suggested using X Visual ID %d (%d %d %d %d depth %d) for EGL config %d" - "(%d %d %d %d), but this is incompatible", - (int)visualId, visualRedSize, visualGreenSize, visualBlueSize, visualAlphaSize, chosenVisualInfo->depth, - configId, configRedSize, configGreenSize, configBlueSize, configAlphaSize); - } - } else { - qCDebug(lcXlibEglDebug, "EGL suggested using X Visual ID %d for EGL config %d, but that isn't a valid ID", - (int)visualId, configId); - visualId = 0; - } - XFree(chosenVisualInfo); - } - else - qCDebug(lcXlibEglDebug, "EGL did not suggest a VisualID (EGL_NATIVE_VISUAL_ID was zero) for EGLConfig %d", configId); - - if (visualId) { - qCDebug(lcXlibEglDebug, configAlphaSize > 0 - ? "Using ARGB Visual ID %d provided by EGL for config %d" - : "Using Opaque Visual ID %d provided by EGL for config %d", (int)visualId, configId); - return visualId; - } - - // Finally, try to use XGetVisualInfo and only use the bit depths to match on: - if (!visualId) { - XVisualInfo visualInfoTemplate; - memset(&visualInfoTemplate, 0, sizeof(XVisualInfo)); - XVisualInfo *matchingVisuals; - int matchingCount = 0; - - visualInfoTemplate.depth = configRedSize + configGreenSize + configBlueSize + configAlphaSize; - matchingVisuals = XGetVisualInfo(display, - VisualDepthMask, - &visualInfoTemplate, - &matchingCount); - if (!matchingVisuals) { - // Try again without taking the alpha channel into account: - visualInfoTemplate.depth = configRedSize + configGreenSize + configBlueSize; - matchingVisuals = XGetVisualInfo(display, - VisualDepthMask, - &visualInfoTemplate, - &matchingCount); - } - - if (matchingVisuals) { - visualId = matchingVisuals[0].visualid; - XFree(matchingVisuals); - } - } - - if (visualId) { - qCDebug(lcXlibEglDebug, "Using Visual ID %d provided by XGetVisualInfo for EGL config %d", (int)visualId, configId); - return visualId; - } - - qWarning("Unable to find an X11 visual which matches EGL config %d", configId); - return (VisualID)0; -} - -QT_END_NAMESPACE diff --git a/src/gui/opengl/platform/egl/qxlibeglintegration_p.h b/src/gui/opengl/platform/egl/qxlibeglintegration_p.h deleted file mode 100644 index 3e0ecbc6ea..0000000000 --- a/src/gui/opengl/platform/egl/qxlibeglintegration_p.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2020 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#ifndef QXLIBEGLINTEGRATION_H -#define QXLIBEGLINTEGRATION_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtGui/private/qeglconvenience_p.h> -#include <X11/X.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> - -QT_BEGIN_NAMESPACE - -class Q_GUI_EXPORT QXlibEglIntegration -{ -public: - static VisualID getCompatibleVisualId(Display *display, EGLDisplay eglDisplay, EGLConfig config); -}; - -QT_END_NAMESPACE - -#endif // QXLIBEGLINTEGRATION_H |