From 8758f532ae6209bcf9447e27edc4fd412c0f173d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Wed, 10 Sep 2014 16:31:32 +0200 Subject: Make GLX and EGL dynamic dependencies for xcb [ChangeLog][QPA][Xcb] GLX and EGL code paths are now dynamically resolved, making it possible for one build of a plugin to use both code paths. Default is to use the GLX code path if available. This can be overwritten by specifying QT_XCB_GL_INTEGRATION=xcb_egl as an evnironment variable. Enable qt.xcb.glintegration.debug to get debug log output of what integration is used Change-Id: Ia9fa95fcca3d901b91dadb8c98a695fea0ae3b1e Reviewed-by: Laszlo Agocs --- .../xcb/gl_integrations/gl_integrations.pri | 13 + .../xcb/gl_integrations/gl_integrations.pro | 9 + .../gl_integrations_plugin_base.pri | 38 ++ .../xcb/gl_integrations/qxcbglintegration.cpp | 62 ++ .../xcb/gl_integrations/qxcbglintegration.h | 76 +++ .../gl_integrations/qxcbglintegrationfactory.cpp | 108 +++ .../xcb/gl_integrations/qxcbglintegrationfactory.h | 61 ++ .../xcb/gl_integrations/qxcbglintegrationplugin.h | 67 ++ .../gl_integrations/qxcbnativeinterfacehandler.cpp | 93 +++ .../gl_integrations/qxcbnativeinterfacehandler.h | 72 ++ .../xcb/gl_integrations/xcb_egl/qxcbeglcontext.h | 104 +++ .../xcb/gl_integrations/xcb_egl/qxcbeglinclude.h | 57 ++ .../gl_integrations/xcb_egl/qxcbeglintegration.cpp | 108 +++ .../gl_integrations/xcb_egl/qxcbeglintegration.h | 83 +++ .../xcb/gl_integrations/xcb_egl/qxcbeglmain.cpp | 62 ++ .../xcb_egl/qxcbeglnativeinterfacehandler.cpp | 120 ++++ .../xcb_egl/qxcbeglnativeinterfacehandler.h | 70 ++ .../xcb/gl_integrations/xcb_egl/qxcbeglwindow.cpp | 92 +++ .../xcb/gl_integrations/xcb_egl/qxcbeglwindow.h | 75 +++ .../xcb/gl_integrations/xcb_egl/xcb_egl.json | 3 + .../xcb/gl_integrations/xcb_egl/xcb_egl.pro | 27 + .../gl_integrations/xcb_glx/qglxintegration.cpp | 723 +++++++++++++++++++++ .../xcb/gl_integrations/xcb_glx/qglxintegration.h | 110 ++++ .../gl_integrations/xcb_glx/qxcbglxintegration.cpp | 217 +++++++ .../gl_integrations/xcb_glx/qxcbglxintegration.h | 72 ++ .../xcb/gl_integrations/xcb_glx/qxcbglxmain.cpp | 62 ++ .../xcb_glx/qxcbglxnativeinterfacehandler.cpp | 95 +++ .../xcb_glx/qxcbglxnativeinterfacehandler.h | 67 ++ .../xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp | 68 ++ .../xcb/gl_integrations/xcb_glx/qxcbglxwindow.h | 63 ++ .../xcb/gl_integrations/xcb_glx/xcb_glx.json | 3 + .../xcb/gl_integrations/xcb_glx/xcb_glx.pro | 31 + src/plugins/platforms/xcb/qglxintegration.cpp | 723 --------------------- src/plugins/platforms/xcb/qglxintegration.h | 110 ---- src/plugins/platforms/xcb/qxcbconnection.cpp | 179 +---- src/plugins/platforms/xcb/qxcbconnection.h | 29 +- src/plugins/platforms/xcb/qxcbeglsurface.h | 64 -- src/plugins/platforms/xcb/qxcbexport.h | 49 ++ src/plugins/platforms/xcb/qxcbintegration.cpp | 140 +--- src/plugins/platforms/xcb/qxcbintegration.h | 4 +- src/plugins/platforms/xcb/qxcbnativeinterface.cpp | 272 +++++--- src/plugins/platforms/xcb/qxcbnativeinterface.h | 33 +- src/plugins/platforms/xcb/qxcbscreen.h | 3 +- src/plugins/platforms/xcb/qxcbwindow.cpp | 74 +-- src/plugins/platforms/xcb/qxcbwindow.h | 22 +- src/plugins/platforms/xcb/xcb-plugin.pro | 116 +--- src/plugins/platforms/xcb/xcb.pro | 3 + src/plugins/platforms/xcb/xcb_qpa_lib.pro | 111 ++++ 48 files changed, 3370 insertions(+), 1473 deletions(-) create mode 100644 src/plugins/platforms/xcb/gl_integrations/gl_integrations.pri create mode 100644 src/plugins/platforms/xcb/gl_integrations/gl_integrations.pro create mode 100644 src/plugins/platforms/xcb/gl_integrations/gl_integrations_plugin_base.pri create mode 100644 src/plugins/platforms/xcb/gl_integrations/qxcbglintegration.cpp create mode 100644 src/plugins/platforms/xcb/gl_integrations/qxcbglintegration.h create mode 100644 src/plugins/platforms/xcb/gl_integrations/qxcbglintegrationfactory.cpp create mode 100644 src/plugins/platforms/xcb/gl_integrations/qxcbglintegrationfactory.h create mode 100644 src/plugins/platforms/xcb/gl_integrations/qxcbglintegrationplugin.h create mode 100644 src/plugins/platforms/xcb/gl_integrations/qxcbnativeinterfacehandler.cpp create mode 100644 src/plugins/platforms/xcb/gl_integrations/qxcbnativeinterfacehandler.h create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglcontext.h create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglinclude.h create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.h create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglmain.cpp create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglnativeinterfacehandler.cpp create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglnativeinterfacehandler.h create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglwindow.cpp create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglwindow.h create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_egl/xcb_egl.json create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_egl/xcb_egl.pro create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.h create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.cpp create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.h create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxmain.cpp create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxnativeinterfacehandler.cpp create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxnativeinterfacehandler.h create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.h create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_glx/xcb_glx.json create mode 100644 src/plugins/platforms/xcb/gl_integrations/xcb_glx/xcb_glx.pro delete mode 100644 src/plugins/platforms/xcb/qglxintegration.cpp delete mode 100644 src/plugins/platforms/xcb/qglxintegration.h delete mode 100644 src/plugins/platforms/xcb/qxcbeglsurface.h create mode 100644 src/plugins/platforms/xcb/qxcbexport.h create mode 100644 src/plugins/platforms/xcb/xcb_qpa_lib.pro (limited to 'src/plugins') diff --git a/src/plugins/platforms/xcb/gl_integrations/gl_integrations.pri b/src/plugins/platforms/xcb/gl_integrations/gl_integrations.pri new file mode 100644 index 0000000000..56bc126652 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/gl_integrations.pri @@ -0,0 +1,13 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/qxcbglintegration.h \ + $$PWD/qxcbglintegrationfactory.h \ + $$PWD/qxcbglintegrationplugin.h \ + $$PWD/qxcbnativeinterfacehandler.h + +SOURCES += \ + $$PWD/qxcbglintegrationfactory.cpp \ + $$PWD/qxcbglintegration.cpp \ + $$PWD/qxcbnativeinterfacehandler.cpp + diff --git a/src/plugins/platforms/xcb/gl_integrations/gl_integrations.pro b/src/plugins/platforms/xcb/gl_integrations/gl_integrations.pro new file mode 100644 index 0000000000..29fddeabd4 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/gl_integrations.pro @@ -0,0 +1,9 @@ +TEMPLATE = subdirs + +contains(QT_CONFIG, egl):contains(QT_CONFIG, egl_x11) { + SUBDIRS += xcb_egl +} + +contains(QT_CONFIG, xcb-xlib):!contains(QT_CONFIG, opengles2) { + SUBDIRS += xcb_glx +} diff --git a/src/plugins/platforms/xcb/gl_integrations/gl_integrations_plugin_base.pri b/src/plugins/platforms/xcb/gl_integrations/gl_integrations_plugin_base.pri new file mode 100644 index 0000000000..8c60268e0d --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/gl_integrations_plugin_base.pri @@ -0,0 +1,38 @@ +QT += core-private gui-private platformsupport-private xcb_qpa_lib-private + +INCLUDEPATH += $$PWD +INCLUDEPATH += $$PWD/../ + +# needed by Xcursor ... +contains(QT_CONFIG, xcb-xlib) { + DEFINES += XCB_USE_XLIB + contains(QT_CONFIG, xinput2) { + DEFINES += XCB_USE_XINPUT2 + } +} + +# to support custom cursors with depth > 1 +contains(QT_CONFIG, xcb-render) { + DEFINES += XCB_USE_RENDER +} + +# build with session management support +contains(QT_CONFIG, xcb-sm) { + DEFINES += XCB_USE_SM +} + +DEFINES += $$QMAKE_DEFINES_XCB +LIBS += $$QMAKE_LIBS_XCB +QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_XCB + +CONFIG += qpa/genericunixfontdatabase + +contains(QT_CONFIG, xcb-qt) { + DEFINES += XCB_USE_RENDER + XCB_DIR = ../../../3rdparty/xcb + INCLUDEPATH += $$XCB_DIR/include $$XCB_DIR/sysinclude + LIBS += -lxcb -L$$OUT_PWD/xcb-static -lxcb-static +} else { + LIBS += -lxcb -lxcb-image -lxcb-icccm -lxcb-sync -lxcb-xfixes -lxcb-shm -lxcb-randr -lxcb-shape -lxcb-keysyms + !contains(DEFINES, QT_NO_XKB):LIBS += -lxcb-xkb +} diff --git a/src/plugins/platforms/xcb/gl_integrations/qxcbglintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/qxcbglintegration.cpp new file mode 100644 index 0000000000..d864ee1198 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/qxcbglintegration.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxcbglintegration.h" + +QT_BEGIN_NAMESPACE + +Q_LOGGING_CATEGORY(QT_XCB_GLINTEGRATION, "qt.xcb.glintegration") + +QXcbGlIntegration::QXcbGlIntegration() +{ +} +QXcbGlIntegration::~QXcbGlIntegration() +{ +} + +bool QXcbGlIntegration::handleXcbEvent(xcb_generic_event_t *event, uint responseType) +{ + Q_UNUSED(event); + Q_UNUSED(responseType); + return false; +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/gl_integrations/qxcbglintegration.h b/src/plugins/platforms/xcb/gl_integrations/qxcbglintegration.h new file mode 100644 index 0000000000..947ef15162 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/qxcbglintegration.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBGLINTEGRATION_H + +#include "qxcbexport.h" +#include "qxcbwindow.h" + +#include + +QT_BEGIN_NAMESPACE + +class QPlatformOffscreenSurface; +class QOffscreenSurface; +class QXcbNativeInterfaceHandler; + +Q_XCB_EXPORT Q_DECLARE_LOGGING_CATEGORY(QT_XCB_GLINTEGRATION) + +class Q_XCB_EXPORT QXcbGlIntegration +{ +public: + QXcbGlIntegration(); + virtual ~QXcbGlIntegration(); + virtual bool initialize(QXcbConnection *connection) = 0; + + virtual bool supportsThreadedOpenGL() const { return false; } + virtual bool handleXcbEvent(xcb_generic_event_t *event, uint responseType); + + virtual QXcbWindow *createWindow(QWindow *window) const = 0; + virtual QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const = 0; + virtual QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const = 0; + + virtual QXcbNativeInterfaceHandler *nativeInterfaceHandler() const { return Q_NULLPTR; } +}; + +QT_END_NAMESPACE + +#endif //QXCBGLINTEGRATION_H diff --git a/src/plugins/platforms/xcb/gl_integrations/qxcbglintegrationfactory.cpp b/src/plugins/platforms/xcb/gl_integrations/qxcbglintegrationfactory.cpp new file mode 100644 index 0000000000..c4546b990a --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/qxcbglintegrationfactory.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxcbglintegrationfactory.h" +#include "qxcbglintegrationplugin.h" + +#include "qxcbglintegrationplugin.h" +#include "private/qfactoryloader_p.h" +#include "qguiapplication.h" +#include "qdir.h" + +QT_BEGIN_NAMESPACE + +#ifndef QT_NO_LIBRARY +Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, + (QXcbGlIntegrationFactoryInterface_iid, QLatin1String("/xcbglintegrations"), Qt::CaseInsensitive)) +Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, directLoader, + (QXcbGlIntegrationFactoryInterface_iid, QLatin1String(""), Qt::CaseInsensitive)) + +static inline QXcbGlIntegration *loadIntegration(QFactoryLoader *loader, const QString &key) +{ + const int index = loader->indexOf(key); + if (index != -1) { + if (QXcbGlIntegrationPlugin *factory = qobject_cast(loader->instance(index))) + if (QXcbGlIntegration *result = factory->create()) + return result; + } + return Q_NULLPTR; +} +#endif // !QT_NO_LIBRARY + +QStringList QXcbGlIntegrationFactory::keys(const QString &pluginPath) +{ +#ifndef QT_NO_LIBRARY + QStringList list; + if (!pluginPath.isEmpty()) { + QCoreApplication::addLibraryPath(pluginPath); + list = directLoader()->keyMap().values(); + if (!list.isEmpty()) { + const QString postFix = QStringLiteral(" (from ") + + QDir::toNativeSeparators(pluginPath) + + QLatin1Char(')'); + const QStringList::iterator end = list.end(); + for (QStringList::iterator it = list.begin(); it != end; ++it) + (*it).append(postFix); + } + } + list.append(loader()->keyMap().values()); + return list; +#else + return QStringList(); +#endif +} + +QXcbGlIntegration *QXcbGlIntegrationFactory::create(const QString &platform, const QString &pluginPath) +{ +#ifndef QT_NO_LIBRARY + // Try loading the plugin from platformPluginPath first: + if (!pluginPath.isEmpty()) { + QCoreApplication::addLibraryPath(pluginPath); + if (QXcbGlIntegration *ret = loadIntegration(directLoader(), platform)) + return ret; + } + if (QXcbGlIntegration *ret = loadIntegration(loader(), platform)) + return ret; +#endif + return Q_NULLPTR; +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/gl_integrations/qxcbglintegrationfactory.h b/src/plugins/platforms/xcb/gl_integrations/qxcbglintegrationfactory.h new file mode 100644 index 0000000000..d1fb91dee8 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/qxcbglintegrationfactory.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBGLINTEGRATIONFACTORY_H +#define QXCBGLINTEGRATIONFACTORY_H + +#include + +QT_BEGIN_NAMESPACE + +class QXcbGlIntegration; + +class QXcbGlIntegrationFactory +{ +public: + static QStringList keys(const QString &pluginPath = QString()); + static QXcbGlIntegration *create(const QString &name, const QString &platformPluginPath = QString()); +}; + +QT_END_NAMESPACE + +#endif //QXCBGLINTEGRATIONFACTORY_H + diff --git a/src/plugins/platforms/xcb/gl_integrations/qxcbglintegrationplugin.h b/src/plugins/platforms/xcb/gl_integrations/qxcbglintegrationplugin.h new file mode 100644 index 0000000000..ef630a4fbe --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/qxcbglintegrationplugin.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBGLINTEGRATIONPLUGIN_H +#define QXCBGLINTEGRATIONPLUGIN_H + +#include "qxcbexport.h" +#include +#include + +QT_BEGIN_NAMESPACE + +#define QXcbGlIntegrationFactoryInterface_iid "org.qt-project.Qt.QPA.Xcb.QXcbGlIntegrationFactoryInterface.5.5" + +class QXcbGlIntegration; + +class Q_XCB_EXPORT QXcbGlIntegrationPlugin : public QObject +{ + Q_OBJECT +public: + explicit QXcbGlIntegrationPlugin(QObject *parent = 0) + : QObject(parent) + { } + + virtual QXcbGlIntegration *create() = 0; +}; +QT_END_NAMESPACE + +#endif //QXCBGLINTEGRATIONPLUGIN_H diff --git a/src/plugins/platforms/xcb/gl_integrations/qxcbnativeinterfacehandler.cpp b/src/plugins/platforms/xcb/gl_integrations/qxcbnativeinterfacehandler.cpp new file mode 100644 index 0000000000..78c6fe0ccb --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/qxcbnativeinterfacehandler.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxcbnativeinterfacehandler.h" + +#include "qxcbnativeinterface.h" + +QT_BEGIN_NAMESPACE + +QXcbNativeInterfaceHandler::QXcbNativeInterfaceHandler(QXcbNativeInterface *nativeInterface) +{ + nativeInterface->addHandler(this); +} +QXcbNativeInterfaceHandler::~QXcbNativeInterfaceHandler() +{ + m_native_interface->removeHandler(this); +} + +QPlatformNativeInterface::NativeResourceForIntegrationFunction QXcbNativeInterfaceHandler::nativeResourceFunctionForIntegration(const QByteArray &resource) const +{ + Q_UNUSED(resource); + return Q_NULLPTR; +} + +QPlatformNativeInterface::NativeResourceForContextFunction QXcbNativeInterfaceHandler::nativeResourceFunctionForContext(const QByteArray &resource) const +{ + Q_UNUSED(resource); + return Q_NULLPTR; +} + +QPlatformNativeInterface::NativeResourceForScreenFunction QXcbNativeInterfaceHandler::nativeResourceFunctionForScreen(const QByteArray &resource) const +{ + Q_UNUSED(resource); + return Q_NULLPTR; +} + +QPlatformNativeInterface::NativeResourceForWindowFunction QXcbNativeInterfaceHandler::nativeResourceFunctionForWindow(const QByteArray &resource) const +{ + Q_UNUSED(resource); + return Q_NULLPTR; +} + +QPlatformNativeInterface::NativeResourceForBackingStoreFunction QXcbNativeInterfaceHandler::nativeResourceFunctionForBackingStore(const QByteArray &resource) const +{ + Q_UNUSED(resource); + return Q_NULLPTR; +} + +QFunctionPointer QXcbNativeInterfaceHandler::platformFunction(const QByteArray &function) const +{ + Q_UNUSED(function); + return Q_NULLPTR; +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/gl_integrations/qxcbnativeinterfacehandler.h b/src/plugins/platforms/xcb/gl_integrations/qxcbnativeinterfacehandler.h new file mode 100644 index 0000000000..3c239c443d --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/qxcbnativeinterfacehandler.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBNATIVEINTERFACEHANDLER_H +#define QXCBNATIVEINTERFACEHANDLER_H + +#include +#include + +#include "qxcbexport.h" + +QT_BEGIN_NAMESPACE + +class QXcbNativeInterface; +class Q_XCB_EXPORT QXcbNativeInterfaceHandler +{ +public: + QXcbNativeInterfaceHandler(QXcbNativeInterface *nativeInterface); + virtual ~QXcbNativeInterfaceHandler(); + + virtual QPlatformNativeInterface::NativeResourceForIntegrationFunction nativeResourceFunctionForIntegration(const QByteArray &resource) const; + virtual QPlatformNativeInterface::NativeResourceForContextFunction nativeResourceFunctionForContext(const QByteArray &resource) const; + virtual QPlatformNativeInterface::NativeResourceForScreenFunction nativeResourceFunctionForScreen(const QByteArray &resource) const; + virtual QPlatformNativeInterface::NativeResourceForWindowFunction nativeResourceFunctionForWindow(const QByteArray &resource) const; + virtual QPlatformNativeInterface::NativeResourceForBackingStoreFunction nativeResourceFunctionForBackingStore(const QByteArray &resource) const; + + virtual QFunctionPointer platformFunction(const QByteArray &function) const; +protected: + QXcbNativeInterface *m_native_interface; +}; + +QT_END_NAMESPACE + +#endif //QXCBNATIVEINTERFACEHANDLER_H diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglcontext.h b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglcontext.h new file mode 100644 index 0000000000..0dce728019 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglcontext.h @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBEGLCONTEXT_H +#define QXCBEGLCONTEXT_H + +#include "qxcbeglwindow.h" +#include +#include +#include + +QT_BEGIN_NAMESPACE + +//####todo remove the noops (looks like their where there in the initial commit) +class QXcbEglContext : public QEGLPlatformContext +{ +public: + QXcbEglContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share, + EGLDisplay display, QXcbConnection *c, const QVariant &nativeHandle) + : QEGLPlatformContext(glFormat, share, display, 0, nativeHandle) + , m_connection(c) + { + Q_XCB_NOOP(m_connection); + } + + void swapBuffers(QPlatformSurface *surface) + { + Q_XCB_NOOP(m_connection); + QEGLPlatformContext::swapBuffers(surface); + Q_XCB_NOOP(m_connection); + } + + bool makeCurrent(QPlatformSurface *surface) + { + Q_XCB_NOOP(m_connection); + bool ret = QEGLPlatformContext::makeCurrent(surface); + Q_XCB_NOOP(m_connection); + return ret; + } + + void doneCurrent() + { + Q_XCB_NOOP(m_connection); + QEGLPlatformContext::doneCurrent(); + Q_XCB_NOOP(m_connection); + } + + EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) + { + if (surface->surface()->surfaceClass() == QSurface::Window) + return static_cast(surface)->eglSurface(); + else + return static_cast(surface)->pbuffer(); + } + + QVariant nativeHandle() const { + return QVariant::fromValue(QEGLNativeContext(eglContext(), eglDisplay())); + } + +private: + QXcbConnection *m_connection; +}; + +QT_END_NAMESPACE +#endif //QXCBEGLCONTEXT_H + diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglinclude.h b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglinclude.h new file mode 100644 index 0000000000..bcde872423 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglinclude.h @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBINCLUDE_H +#define QXCBINCLUDE_H + +#include +#include +#include +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +QT_END_NAMESPACE + +#endif //QXCBINCLUDE_H diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp new file mode 100644 index 0000000000..f5fc2e74c4 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxcbeglintegration.h" + +#include "qxcbeglcontext.h" + +#include + +#include "qxcbeglnativeinterfacehandler.h" + +QT_BEGIN_NAMESPACE + +QXcbEglIntegration::QXcbEglIntegration() + : m_connection(Q_NULLPTR) + , m_egl_display(EGL_NO_DISPLAY) +{ + qCDebug(QT_XCB_GLINTEGRATION) << "Xcb EGL gl-integration created"; +} + +QXcbEglIntegration::~QXcbEglIntegration() +{ + if (m_egl_display != EGL_NO_DISPLAY) + eglTerminate(m_egl_display); +} + +bool QXcbEglIntegration::initialize(QXcbConnection *connection) +{ + m_connection = connection; + + Display *dpy = (Display *)m_connection->xlib_display(); + m_egl_display = eglGetDisplay(dpy); + + EGLint major, minor; + bool success = eglInitialize(m_egl_display, &major, &minor); + if (!success) { + m_egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + qCDebug(QT_XCB_GLINTEGRATION) << "Xcb EGL gl-integration retrying with display" << m_egl_display; + success = eglInitialize(m_egl_display, &major, &minor); + } + + m_native_interface_handler.reset(new QXcbEglNativeInterfaceHandler(connection->nativeInterface())); + + qCDebug(QT_XCB_GLINTEGRATION) << "Xcb EGL gl-integration successfully initialized"; + return success; +} + +QXcbWindow *QXcbEglIntegration::createWindow(QWindow *window) const +{ + return new QXcbEglWindow(window, const_cast(this)); +} + +QPlatformOpenGLContext *QXcbEglIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const +{ + QXcbScreen *screen = static_cast(context->screen()->handle()); + QXcbEglContext *platformContext = new QXcbEglContext(context->format(), + context->shareHandle(), + eglDisplay(), + screen->connection(), + context->nativeHandle()); + context->setNativeHandle(platformContext->nativeHandle()); + return platformContext; +} + +QPlatformOffscreenSurface *QXcbEglIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const +{ + return new QEGLPbuffer(eglDisplay(), surface->requestedFormat(), surface); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.h b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.h new file mode 100644 index 0000000000..9f42051804 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBEGLINTEGRATION_H +#define QXCBEGLINTEGRATION_H + +#include "qxcbglintegration.h" + +#include "qxcbeglwindow.h" + +#include +#include +#include + +#include "qxcbscreen.h" + +#include "qxcbeglinclude.h" + +QT_BEGIN_NAMESPACE + +class QXcbEglNativeInterfaceHandler; + +class QXcbEglIntegration : public QXcbGlIntegration +{ +public: + QXcbEglIntegration(); + ~QXcbEglIntegration(); + + bool initialize(QXcbConnection *connection) Q_DECL_OVERRIDE; + + QXcbWindow *createWindow(QWindow *window) const Q_DECL_OVERRIDE; + QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const Q_DECL_OVERRIDE; + QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const Q_DECL_OVERRIDE; + + EGLDisplay eglDisplay() const { return m_egl_display; } + void *xlib_display() const { return m_connection->xlib_display(); } +private: + QXcbConnection *m_connection; + EGLDisplay m_egl_display; + + QScopedPointer m_native_interface_handler; +}; + +QT_END_NAMESPACE +#endif //QXCBEGLINTEGRATION_H diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglmain.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglmain.cpp new file mode 100644 index 0000000000..9feb8f31ca --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglmain.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxcbglintegrationplugin.h" + +#include "qxcbeglintegration.h" + +QT_BEGIN_NAMESPACE + +class QXcbEglIntegrationPlugin : public QXcbGlIntegrationPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QXcbGlIntegrationFactoryInterface_iid FILE "xcb_egl.json") +public: + QXcbGlIntegration *create() + { + return new QXcbEglIntegration(); + } + +}; + +QT_END_NAMESPACE + +#include "qxcbeglmain.moc" diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglnativeinterfacehandler.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglnativeinterfacehandler.cpp new file mode 100644 index 0000000000..3037d1e331 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglnativeinterfacehandler.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxcbeglnativeinterfacehandler.h" + +#include "qxcbeglwindow.h" +#include "qxcbeglintegration.h" +#include "qxcbeglcontext.h" + +QT_BEGIN_NAMESPACE + +static int resourceType(const QByteArray &key) +{ + static const QByteArray names[] = { // match QXcbEglNativeInterfaceHandler::ResourceType + QByteArrayLiteral("egldisplay"), + QByteArrayLiteral("eglcontext"), + QByteArrayLiteral("eglconfig") + }; + for (size_t i = 0; i < sizeof(names) / sizeof(names[0]); i++) { + if (key == names[i]) + return i; + } + + if (key == QByteArrayLiteral("get_egl_context")) + return QXcbEglNativeInterfaceHandler::EglContext; + + return sizeof(names) / sizeof(names[0]); +} + +QXcbEglNativeInterfaceHandler::QXcbEglNativeInterfaceHandler(QXcbNativeInterface *nativeInterface) + : QXcbNativeInterfaceHandler(nativeInterface) +{ +} + +QPlatformNativeInterface::NativeResourceForContextFunction QXcbEglNativeInterfaceHandler::nativeResourceFunctionForContext(const QByteArray &resource) const +{ + switch (resourceType(resource)) { + case EglContext: + return eglContextForContext; + case EglConfig: + return eglConfigForContext; + default: + break; + } + return Q_NULLPTR; +} + +QPlatformNativeInterface::NativeResourceForWindowFunction QXcbEglNativeInterfaceHandler::nativeResourceFunctionForWindow(const QByteArray &resource) const +{ + switch (resourceType(resource)) { + case EglDisplay: + return eglDisplayForWindow; + default: + break; + } + return Q_NULLPTR; +} + +void *QXcbEglNativeInterfaceHandler::eglDisplayForWindow(QWindow *window) +{ + Q_ASSERT(window); + Q_ASSERT(window->handle()); + if (window->supportsOpenGL()) + return static_cast(window->handle())->glIntegration()->eglDisplay(); + return Q_NULLPTR; +} + +void *QXcbEglNativeInterfaceHandler::eglContextForContext(QOpenGLContext *context) +{ + Q_ASSERT(context); + Q_ASSERT(context->handle()); + return static_cast(context->handle())->eglContext(); +} + +void *QXcbEglNativeInterfaceHandler::eglConfigForContext(QOpenGLContext *context) +{ + Q_ASSERT(context); + Q_ASSERT(context->handle()); + return static_cast(context->handle())->eglConfig(); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglnativeinterfacehandler.h b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglnativeinterfacehandler.h new file mode 100644 index 0000000000..0485a87558 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglnativeinterfacehandler.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBEGLNATIVEINTERFACEHANDLER_H +#define QXCBEGLNATIVEINTERFACEHANDLER_H + +#include "qxcbnativeinterfacehandler.h" + +QT_BEGIN_NAMESPACE + +class QXcbEglNativeInterfaceHandler : public QXcbNativeInterfaceHandler +{ +public: + enum ResourceType { + EglDisplay, + EglContext, + EglConfig + }; + + QXcbEglNativeInterfaceHandler(QXcbNativeInterface *nativeInterface); + + QPlatformNativeInterface::NativeResourceForContextFunction nativeResourceFunctionForContext(const QByteArray &resource) const Q_DECL_OVERRIDE; + QPlatformNativeInterface::NativeResourceForWindowFunction nativeResourceFunctionForWindow(const QByteArray &resource) const Q_DECL_OVERRIDE; +private: + static void *eglDisplayForWindow(QWindow *window); + static void *eglContextForContext(QOpenGLContext *context); + static void *eglConfigForContext(QOpenGLContext *context); +}; + +QT_END_NAMESPACE + +#endif //QXCBEGLNATIVEINTERFACEHANDLER_H diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglwindow.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglwindow.cpp new file mode 100644 index 0000000000..61dd8d5069 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglwindow.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxcbeglwindow.h" + +#include "qxcbeglintegration.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +QXcbEglWindow::QXcbEglWindow(QWindow *window, QXcbEglIntegration *glIntegration) + : QXcbWindow(window) + , m_glIntegration(glIntegration) + , m_config(Q_NULLPTR) + , m_surface(EGL_NO_SURFACE) +{ +} + +QXcbEglWindow::~QXcbEglWindow() +{ + eglDestroySurface(m_glIntegration->eglDisplay(), m_surface); +} + +void QXcbEglWindow::resolveFormat() +{ + m_config = q_configFromGLFormat(m_glIntegration->eglDisplay(), window()->requestedFormat(), true); + m_format = q_glFormatFromConfig(m_glIntegration->eglDisplay(), m_config, m_format); +} + +void *QXcbEglWindow::createVisual() +{ + Display *xdpy = static_cast(m_glIntegration->xlib_display()); + VisualID id = QXlibEglIntegration::getCompatibleVisualId(xdpy, m_glIntegration->eglDisplay(), m_config); + + XVisualInfo visualInfoTemplate; + memset(&visualInfoTemplate, 0, sizeof(XVisualInfo)); + visualInfoTemplate.visualid = id; + + XVisualInfo *visualInfo; + int matchingCount = 0; + visualInfo = XGetVisualInfo(xdpy, VisualIDMask, &visualInfoTemplate, &matchingCount); + return visualInfo; +} + +void QXcbEglWindow::create() +{ + QXcbWindow::create(); + + m_surface = eglCreateWindowSurface(m_glIntegration->eglDisplay(), m_config, m_window, 0); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglwindow.h b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglwindow.h new file mode 100644 index 0000000000..7d1a4c8e37 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglwindow.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBEGLWINDOW_H +#define QXCBEGLWINDOW_H + +#include "qxcbwindow.h" + +#include "qxcbeglinclude.h" + +QT_BEGIN_NAMESPACE + +class QXcbEglIntegration; + +class QXcbEglWindow : public QXcbWindow +{ +public: + QXcbEglWindow(QWindow *window, QXcbEglIntegration *glIntegration); + ~QXcbEglWindow(); + + EGLSurface eglSurface() const { return m_surface; } + + QXcbEglIntegration *glIntegration() const { return m_glIntegration; } + +protected: + void create() Q_DECL_OVERRIDE; + void resolveFormat() Q_DECL_OVERRIDE; + void *createVisual() Q_DECL_OVERRIDE; + +private: + QXcbEglIntegration *m_glIntegration; + EGLConfig m_config; + EGLSurface m_surface; +}; + +QT_END_NAMESPACE +#endif //QXCBEGLWINDOW_H diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/xcb_egl.json b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/xcb_egl.json new file mode 100644 index 0000000000..6d6785691d --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/xcb_egl.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "xcb_egl" ] +} diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/xcb_egl.pro b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/xcb_egl.pro new file mode 100644 index 0000000000..082c22821a --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/xcb_egl.pro @@ -0,0 +1,27 @@ +TARGET = qxcb-egl-integration + +PLUGIN_CLASS_NAME = QXcbEglIntegrationPlugin +PLUGIN_TYPE = xcbglintegrations + +load(qt_plugin) + +include(../gl_integrations_plugin_base.pri) + +CONFIG += egl + +DEFINES += SUPPORT_X11 +#should be removed from sources +DEFINES += XCB_USE_EGL XCB_USE_XLIB + + +HEADERS += \ + qxcbeglcontext.h \ + qxcbeglintegration.h \ + qxcbeglwindow.h \ + qxcbeglnativeinterfacehandler.h + +SOURCES += \ + qxcbeglintegration.cpp \ + qxcbeglwindow.cpp \ + qxcbeglmain.cpp \ + qxcbeglnativeinterfacehandler.cpp diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp new file mode 100644 index 0000000000..c0be836bce --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp @@ -0,0 +1,723 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include "qxcbwindow.h" +#include "qxcbscreen.h" + +#include +#include +#include + +#include +#include + +#include "qglxintegration.h" +#include +#include + +#if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) +#include +#endif + +QT_BEGIN_NAMESPACE + +typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*); + +#ifndef GLX_CONTEXT_CORE_PROFILE_BIT_ARB +#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 +#endif + +#ifndef GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB +#define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 +#endif + +#ifndef GLX_CONTEXT_ES2_PROFILE_BIT_EXT +#define GLX_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 +#endif + +#ifndef GLX_CONTEXT_PROFILE_MASK_ARB +#define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126 +#endif + +#ifndef GL_CONTEXT_FLAG_DEBUG_BIT +#define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002 +#endif + +static Window createDummyWindow(Display *dpy, XVisualInfo *visualInfo, int screenNumber, Window rootWin) +{ + Colormap cmap = XCreateColormap(dpy, rootWin, visualInfo->visual, AllocNone); + XSetWindowAttributes a; + a.background_pixel = WhitePixel(dpy, screenNumber); + a.border_pixel = BlackPixel(dpy, screenNumber); + a.colormap = cmap; + a.override_redirect = true; + + Window window = XCreateWindow(dpy, rootWin, + 0, 0, 100, 100, + 0, visualInfo->depth, InputOutput, visualInfo->visual, + CWBackPixel|CWBorderPixel|CWColormap|CWOverrideRedirect, &a); +#ifndef QT_NO_DEBUG + XStoreName(dpy, window, "Qt GLX dummy window"); +#endif + XFreeColormap(dpy, cmap); + return window; +} + +static Window createDummyWindow(Display *dpy, GLXFBConfig config, int screenNumber, Window rootWin) +{ + XVisualInfo *visualInfo = glXGetVisualFromFBConfig(dpy, config); + if (!visualInfo) + qFatal("Could not initialize GLX"); + Window window = createDummyWindow(dpy, visualInfo, screenNumber, rootWin); + XFree(visualInfo); + return window; +} + +static inline QByteArray getGlString(GLenum param) +{ + if (const GLubyte *s = glGetString(param)) + return QByteArray(reinterpret_cast(s)); + return QByteArray(); +} + +static void updateFormatFromContext(QSurfaceFormat &format) +{ + // Update the version, profile, and context bit of the format + int major = 0, minor = 0; + QByteArray versionString(getGlString(GL_VERSION)); + if (QPlatformOpenGLContext::parseOpenGLVersion(versionString, major, minor)) { + format.setMajorVersion(major); + format.setMinorVersion(minor); + } + + format.setProfile(QSurfaceFormat::NoProfile); + format.setOptions(QSurfaceFormat::FormatOptions()); + + if (format.renderableType() == QSurfaceFormat::OpenGL) { + if (format.version() < qMakePair(3, 0)) { + format.setOption(QSurfaceFormat::DeprecatedFunctions); + return; + } + + // Version 3.0 onwards - check if it includes deprecated functionality or is + // a debug context + GLint value = 0; + glGetIntegerv(GL_CONTEXT_FLAGS, &value); + if (!(value & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)) + format.setOption(QSurfaceFormat::DeprecatedFunctions); + if (value & GL_CONTEXT_FLAG_DEBUG_BIT) + format.setOption(QSurfaceFormat::DebugContext); + if (format.version() < qMakePair(3, 2)) + return; + + // Version 3.2 and newer have a profile + value = 0; + glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &value); + + if (value & GL_CONTEXT_CORE_PROFILE_BIT) + format.setProfile(QSurfaceFormat::CoreProfile); + else if (value & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) + format.setProfile(QSurfaceFormat::CompatibilityProfile); + } +} + +QGLXContext::QGLXContext(QXcbScreen *screen, const QSurfaceFormat &format, QPlatformOpenGLContext *share, + const QVariant &nativeHandle) + : QPlatformOpenGLContext() + , m_display(DISPLAY_FROM_XCB(screen)) + , m_config(0) + , m_context(0) + , m_shareContext(0) + , m_format(format) + , m_isPBufferCurrent(false) + , m_swapInterval(-1) + , m_ownsContext(nativeHandle.isNull()) +{ + if (nativeHandle.isNull()) + init(screen, share); + else + init(screen, share, nativeHandle); +} + +void QGLXContext::init(QXcbScreen *screen, QPlatformOpenGLContext *share) +{ + if (m_format.renderableType() == QSurfaceFormat::DefaultRenderableType) + m_format.setRenderableType(QSurfaceFormat::OpenGL); + if (m_format.renderableType() != QSurfaceFormat::OpenGL && m_format.renderableType() != QSurfaceFormat::OpenGLES) + return; + + if (share) + m_shareContext = static_cast(share)->glxContext(); + + GLXFBConfig config = qglx_findConfig(DISPLAY_FROM_XCB(screen),screen->screenNumber(),m_format); + m_config = config; + XVisualInfo *visualInfo = 0; + Window window = 0; // Temporary window used to query OpenGL context + + if (config) { + // Resolve entry point for glXCreateContextAttribsARB + glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0; + glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc) glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB"); + + QList glxExt = QByteArray(glXQueryExtensionsString(m_display, screen->screenNumber())).split(' '); + bool supportsProfiles = glxExt.contains("GLX_ARB_create_context_profile"); + + // Use glXCreateContextAttribsARB if available + // Also, GL ES context creation requires GLX_EXT_create_context_es2_profile + if (glxExt.contains("GLX_ARB_create_context") && glXCreateContextAttribsARB != 0 + && (m_format.renderableType() != QSurfaceFormat::OpenGLES || (supportsProfiles && glxExt.contains("GLX_EXT_create_context_es2_profile")))) { + // Try to create an OpenGL context for each known OpenGL version in descending + // order from the requested version. + const int requestedVersion = m_format.majorVersion() * 10 + qMin(m_format.minorVersion(), 9); + + QVector glVersions; + if (m_format.renderableType() == QSurfaceFormat::OpenGL) { + if (requestedVersion > 45) + glVersions << requestedVersion; + + // Don't bother with versions below 2.0 + glVersions << 45 << 44 << 43 << 42 << 41 << 40 << 33 << 32 << 31 << 30 << 21 << 20; + } else if (m_format.renderableType() == QSurfaceFormat::OpenGLES) { + if (requestedVersion > 31) + glVersions << requestedVersion; + + // Don't bother with versions below ES 2.0 + glVersions << 31 << 30 << 20; + // ES does not support any format option + m_format.setOptions(QSurfaceFormat::FormatOptions()); + } + + Q_ASSERT(glVersions.count() > 0); + + for (int i = 0; !m_context && i < glVersions.count(); i++) { + const int version = glVersions[i]; + if (version > requestedVersion) + continue; + + const int majorVersion = version / 10; + const int minorVersion = version % 10; + + QVector contextAttributes; + contextAttributes << GLX_CONTEXT_MAJOR_VERSION_ARB << majorVersion + << GLX_CONTEXT_MINOR_VERSION_ARB << minorVersion; + + + if (m_format.renderableType() == QSurfaceFormat::OpenGL) { + // If asking for OpenGL 3.2 or newer we should also specify a profile + if (version >= 32 && supportsProfiles) { + if (m_format.profile() == QSurfaceFormat::CoreProfile) + contextAttributes << GLX_CONTEXT_PROFILE_MASK_ARB << GLX_CONTEXT_CORE_PROFILE_BIT_ARB; + else + contextAttributes << GLX_CONTEXT_PROFILE_MASK_ARB << GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; + } + + int flags = 0; + + if (m_format.testOption(QSurfaceFormat::DebugContext)) + flags |= GLX_CONTEXT_DEBUG_BIT_ARB; + + // A forward-compatible context may be requested for 3.0 and later + if (version >= 30 && !m_format.testOption(QSurfaceFormat::DeprecatedFunctions)) + flags |= GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; + + if (flags != 0) + contextAttributes << GLX_CONTEXT_FLAGS_ARB << flags; + } else if (m_format.renderableType() == QSurfaceFormat::OpenGLES) { + contextAttributes << GLX_CONTEXT_PROFILE_MASK_ARB << GLX_CONTEXT_ES2_PROFILE_BIT_EXT; + } + + contextAttributes << None; + + m_context = glXCreateContextAttribsARB(m_display, config, m_shareContext, true, contextAttributes.data()); + if (!m_context && m_shareContext) { + // re-try without a shared glx context + m_context = glXCreateContextAttribsARB(m_display, config, 0, true, contextAttributes.data()); + if (m_context) + m_shareContext = 0; + } + } + } + + // Could not create a context using glXCreateContextAttribsARB, falling back to glXCreateNewContext. + if (!m_context) { + // requesting an OpenGL ES context requires glXCreateContextAttribsARB, so bail out + if (m_format.renderableType() == QSurfaceFormat::OpenGLES) + return; + + m_context = glXCreateNewContext(m_display, config, GLX_RGBA_TYPE, m_shareContext, true); + if (!m_context && m_shareContext) { + // re-try without a shared glx context + m_context = glXCreateNewContext(m_display, config, GLX_RGBA_TYPE, 0, true); + if (m_context) + m_shareContext = 0; + } + } + + // Get the basic surface format details + if (m_context) + qglx_surfaceFormatFromGLXFBConfig(&m_format, DISPLAY_FROM_XCB(screen), config); + + // Create a temporary window so that we can make the new context current + window = createDummyWindow(DISPLAY_FROM_XCB(screen), config, screen->screenNumber(), screen->root()); + } else { + // requesting an OpenGL ES context requires glXCreateContextAttribsARB, so bail out + if (m_format.renderableType() == QSurfaceFormat::OpenGLES) + return; + + // Note that m_format gets updated with the used surface format + visualInfo = qglx_findVisualInfo(m_display, screen->screenNumber(), &m_format); + if (!visualInfo) + qFatal("Could not initialize GLX"); + m_context = glXCreateContext(m_display, visualInfo, m_shareContext, true); + if (!m_context && m_shareContext) { + // re-try without a shared glx context + m_shareContext = 0; + m_context = glXCreateContext(m_display, visualInfo, Q_NULLPTR, true); + } + + // Create a temporary window so that we can make the new context current + window = createDummyWindow(DISPLAY_FROM_XCB(screen), visualInfo, screen->screenNumber(), screen->root()); + XFree(visualInfo); + } + + // Query the OpenGL version and profile + if (m_context && window) { + GLXContext prevContext = glXGetCurrentContext(); + GLXDrawable prevDrawable = glXGetCurrentDrawable(); + glXMakeCurrent(m_display, window, m_context); + updateFormatFromContext(m_format); + + // Make our context non-current + glXMakeCurrent(m_display, prevDrawable, prevContext); + } + + // Destroy our temporary window + XDestroyWindow(m_display, window); +} + +void QGLXContext::init(QXcbScreen *screen, QPlatformOpenGLContext *share, const QVariant &nativeHandle) +{ + if (!nativeHandle.canConvert()) { + qWarning("QGLXContext: Requires a QGLXNativeContext"); + return; + } + QGLXNativeContext handle = nativeHandle.value(); + GLXContext context = handle.context(); + if (!context) { + qWarning("QGLXContext: No GLXContext given"); + return; + } + + // Use the provided Display, if available. If not, use our own. It may still work. + Display *dpy = handle.display(); + if (!dpy) + dpy = DISPLAY_FROM_XCB(screen); + + // Legacy contexts created using glXCreateContext are created using a visual + // and the FBConfig cannot be queried. The only way to adapt these contexts + // is to figure out the visual id. + XVisualInfo *vinfo = 0; + // If the VisualID is provided use it. + VisualID vid = handle.visualId(); + if (!vid) { + // In the absence of the VisualID figure it out from the window. + Window wnd = handle.window(); + if (wnd) { + XWindowAttributes attrs; + XGetWindowAttributes(dpy, wnd, &attrs); + vid = XVisualIDFromVisual(attrs.visual); + } + } + if (vid) { + XVisualInfo v; + v.screen = screen->screenNumber(); + v.visualid = vid; + int n = 0; + vinfo = XGetVisualInfo(dpy, VisualScreenMask | VisualIDMask, &v, &n); + if (n < 1) { + XFree(vinfo); + vinfo = 0; + } + } + + // For contexts created with an FBConfig using the modern functions providing the + // visual or window is not mandatory. Just query the config from the context. + GLXFBConfig config = 0; + if (!vinfo) { + int configId = 0; + if (glXQueryContext(dpy, context, GLX_FBCONFIG_ID, &configId) != Success) { + qWarning("QGLXContext: Failed to query config from the provided context"); + return; + } + + GLXFBConfig *configs; + int numConfigs = 0; + static const int attribs[] = { GLX_FBCONFIG_ID, configId, None }; + configs = glXChooseFBConfig(dpy, screen->screenNumber(), attribs, &numConfigs); + if (!configs || numConfigs < 1) { + qWarning("QGLXContext: Failed to find config"); + return; + } + if (configs && numConfigs > 1) // this is suspicious so warn but let it continue + qWarning("QGLXContext: Multiple configs for FBConfig ID %d", configId); + + config = configs[0]; + // Store the config. + m_config = config; + } + + Q_ASSERT(vinfo || config); + + int screenNumber = DefaultScreen(dpy); + Window window; + if (vinfo) + window = createDummyWindow(dpy, vinfo, screenNumber, RootWindow(dpy, screenNumber)); + else + window = createDummyWindow(dpy, config, screenNumber, RootWindow(dpy, screenNumber)); + if (!window) { + qWarning("QGLXContext: Failed to create dummy window"); + return; + } + + // Update OpenGL version and buffer sizes in our format. + GLXContext prevContext = glXGetCurrentContext(); + GLXDrawable prevDrawable = glXGetCurrentDrawable(); + if (!glXMakeCurrent(dpy, window, context)) { + qWarning("QGLXContext: Failed to make provided context current"); + return; + } + m_format = QSurfaceFormat(); + m_format.setRenderableType(QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL + ? QSurfaceFormat::OpenGL : QSurfaceFormat::OpenGLES); + updateFormatFromContext(m_format); + if (vinfo) + qglx_surfaceFormatFromVisualInfo(&m_format, dpy, vinfo); + else + qglx_surfaceFormatFromGLXFBConfig(&m_format, dpy, config); + glXMakeCurrent(dpy, prevDrawable, prevContext); + XDestroyWindow(dpy, window); + + if (vinfo) + XFree(vinfo); + + // Success. Store the context. From this point on isValid() is true. + m_context = context; + + if (share) + m_shareContext = static_cast(share)->glxContext(); +} + +QGLXContext::~QGLXContext() +{ + if (m_ownsContext) + glXDestroyContext(m_display, m_context); +} + +static QXcbScreen *screenForPlatformSurface(QPlatformSurface *surface) +{ + QSurface::SurfaceClass surfaceClass = surface->surface()->surfaceClass(); + if (surfaceClass == QSurface::Window) { + return static_cast(static_cast(surface)->screen()); + } else if (surfaceClass == QSurface::Offscreen) { + return static_cast(static_cast(surface)->screen()); + } + return Q_NULLPTR; +} + +QVariant QGLXContext::nativeHandle() const +{ + return QVariant::fromValue(QGLXNativeContext(m_context)); +} + +bool QGLXContext::makeCurrent(QPlatformSurface *surface) +{ + bool success = false; + Q_ASSERT(surface->surface()->supportsOpenGL()); + + GLXDrawable glxDrawable = 0; + QSurface::SurfaceClass surfaceClass = surface->surface()->surfaceClass(); + if (surfaceClass == QSurface::Window) { + m_isPBufferCurrent = false; + QXcbWindow *window = static_cast(surface); + glxDrawable = window->xcb_window(); + success = glXMakeCurrent(m_display, glxDrawable, m_context); + } else if (surfaceClass == QSurface::Offscreen) { + m_isPBufferCurrent = true; + QGLXPbuffer *pbuffer = static_cast(surface); + glxDrawable = pbuffer->pbuffer(); + success = glXMakeContextCurrent(m_display, glxDrawable, glxDrawable, m_context); + } + + if (success) { + int interval = surface->format().swapInterval(); + QXcbScreen *screen = screenForPlatformSurface(surface); + if (interval >= 0 && m_swapInterval != interval && screen) { + m_swapInterval = interval; + typedef void (*qt_glXSwapIntervalEXT)(Display *, GLXDrawable, int); + typedef void (*qt_glXSwapIntervalMESA)(unsigned int); + static qt_glXSwapIntervalEXT glXSwapIntervalEXT = 0; + static qt_glXSwapIntervalMESA glXSwapIntervalMESA = 0; + static bool resolved = false; + if (!resolved) { + resolved = true; + QList glxExt = QByteArray(glXQueryExtensionsString(m_display, + screen->screenNumber())).split(' '); + if (glxExt.contains("GLX_EXT_swap_control")) + glXSwapIntervalEXT = (qt_glXSwapIntervalEXT) getProcAddress("glXSwapIntervalEXT"); + if (glxExt.contains("GLX_MESA_swap_control")) + glXSwapIntervalMESA = (qt_glXSwapIntervalMESA) getProcAddress("glXSwapIntervalMESA"); + } + if (glXSwapIntervalEXT) + glXSwapIntervalEXT(m_display, glxDrawable, interval); + else if (glXSwapIntervalMESA) + glXSwapIntervalMESA(interval); + } + } + + return success; +} + +void QGLXContext::doneCurrent() +{ + if (m_isPBufferCurrent) + glXMakeContextCurrent(m_display, 0, 0, 0); + else + glXMakeCurrent(m_display, 0, 0); + m_isPBufferCurrent = false; +} + +void QGLXContext::swapBuffers(QPlatformSurface *surface) +{ + GLXDrawable glxDrawable = 0; + if (surface->surface()->surfaceClass() == QSurface::Offscreen) + glxDrawable = static_cast(surface)->pbuffer(); + else + glxDrawable = static_cast(surface)->xcb_window(); + glXSwapBuffers(m_display, glxDrawable); + + if (surface->surface()->surfaceClass() == QSurface::Window) { + QXcbWindow *platformWindow = static_cast(surface); + // OpenGL context might be bound to a non-gui thread use QueuedConnection to sync + // the window from the platformWindow's thread as QXcbWindow is no QObject, an + // event is sent to QXcbConnection. (this is faster than a metacall) + if (platformWindow->needsSync()) + platformWindow->postSyncWindowRequest(); + } +} + +void (*QGLXContext::getProcAddress(const QByteArray &procName)) () +{ + typedef void *(*qt_glXGetProcAddressARB)(const GLubyte *); + static qt_glXGetProcAddressARB glXGetProcAddressARB = 0; + static bool resolved = false; + + if (resolved && !glXGetProcAddressARB) + return 0; + if (!glXGetProcAddressARB) { + QList glxExt = QByteArray(glXGetClientString(m_display, GLX_EXTENSIONS)).split(' '); + if (glxExt.contains("GLX_ARB_get_proc_address")) { +#if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) + void *handle = dlopen(NULL, RTLD_LAZY); + if (handle) { + glXGetProcAddressARB = (qt_glXGetProcAddressARB) dlsym(handle, "glXGetProcAddressARB"); + dlclose(handle); + } + if (!glXGetProcAddressARB) +#endif + { + extern const QString qt_gl_library_name(); +// QLibrary lib(qt_gl_library_name()); + QLibrary lib(QLatin1String("GL")); + glXGetProcAddressARB = (qt_glXGetProcAddressARB) lib.resolve("glXGetProcAddressARB"); + } + } + resolved = true; + } + if (!glXGetProcAddressARB) + return 0; + return (void (*)())glXGetProcAddressARB(reinterpret_cast(procName.constData())); +} + +QSurfaceFormat QGLXContext::format() const +{ + return m_format; +} + +bool QGLXContext::isSharing() const +{ + return m_shareContext != 0; +} + +bool QGLXContext::isValid() const +{ + return m_context != 0; +} + +bool QGLXContext::m_queriedDummyContext = false; +bool QGLXContext::m_supportsThreading = true; + + +// If this list grows to any significant size, change it a +// proper string table and make the implementation below use +// binary search. +static const char *qglx_threadedgl_blacklist_renderer[] = { + "Chromium", // QTBUG-32225 (initialization fails) + 0 +}; + +// This disables threaded rendering on anything using mesa, e.g. +// - nvidia/nouveau +// - amd/gallium +// - intel +// - some software opengl implementations +// +// The client glx vendor string is used to identify those setups as that seems to show the least +// variance between the bad configurations. It's always "Mesa Project and SGI". There are some +// configurations which don't use mesa and which can do threaded rendering (amd and nvidia chips +// with their own proprietary drivers). +// +// This, of course, is very broad and disables threaded rendering on a lot of devices which would +// be able to use it. However, the bugs listed below don't follow any easily recognizable pattern +// and we should rather be safe. +// +// http://cgit.freedesktop.org/xcb/libxcb/commit/?id=be0fe56c3bcad5124dcc6c47a2fad01acd16f71a will +// fix some of the issues. Basically, the proprietary drivers seem to have a way of working around +// a fundamental flaw with multithreaded access to xcb, but mesa doesn't. The blacklist should be +// reevaluated once that patch is released in some version of xcb. +static const char *qglx_threadedgl_blacklist_vendor[] = { + "Mesa Project and SGI", // QTCREATORBUG-10875 (crash in creator) + // QTBUG-34492 (flickering in fullscreen) + // QTBUG-38221 + 0 +}; + +void QGLXContext::queryDummyContext() +{ + if (m_queriedDummyContext) + return; + m_queriedDummyContext = true; + + static bool skip = qEnvironmentVariableIsSet("QT_OPENGL_NO_SANITY_CHECK"); + if (skip) + return; + + QOpenGLContext *oldContext = QOpenGLContext::currentContext(); + QSurface *oldSurface = 0; + if (oldContext) + oldSurface = oldContext->surface(); + + QScopedPointer surface; + const char *glxvendor = glXGetClientString(glXGetCurrentDisplay(), GLX_VENDOR); + if (glxvendor && !strcmp(glxvendor, "ATI")) { + QWindow *window = new QWindow; + window->resize(64, 64); + window->setSurfaceType(QSurface::OpenGLSurface); + window->create(); + surface.reset(window); + } else { + QOffscreenSurface *offSurface = new QOffscreenSurface; + offSurface->create(); + surface.reset(offSurface); + } + + QOpenGLContext context; + context.create(); + context.makeCurrent(surface.data()); + + m_supportsThreading = true; + + if (const char *renderer = (const char *) glGetString(GL_RENDERER)) { + for (int i = 0; qglx_threadedgl_blacklist_renderer[i]; ++i) { + if (strstr(renderer, qglx_threadedgl_blacklist_renderer[i]) != 0) { + m_supportsThreading = false; + break; + } + } + } + + if (glxvendor) { + for (int i = 0; qglx_threadedgl_blacklist_vendor[i]; ++i) { + if (strstr(glxvendor, qglx_threadedgl_blacklist_vendor[i]) != 0) { + m_supportsThreading = false; + break; + } + } + } + + context.doneCurrent(); + if (oldContext && oldSurface) + oldContext->makeCurrent(oldSurface); +} + +bool QGLXContext::supportsThreading() +{ + if (!m_queriedDummyContext) + queryDummyContext(); + return m_supportsThreading; +} + +QGLXPbuffer::QGLXPbuffer(QOffscreenSurface *offscreenSurface) + : QPlatformOffscreenSurface(offscreenSurface) + , m_format(offscreenSurface->requestedFormat()) + , m_screen(static_cast(offscreenSurface->screen()->handle())) + , m_pbuffer(0) +{ + GLXFBConfig config = qglx_findConfig(DISPLAY_FROM_XCB(m_screen), m_screen->screenNumber(), m_format); + + if (config) { + const int attributes[] = { + GLX_PBUFFER_WIDTH, offscreenSurface->size().width(), + GLX_PBUFFER_HEIGHT, offscreenSurface->size().height(), + GLX_LARGEST_PBUFFER, False, + GLX_PRESERVED_CONTENTS, False, + None + }; + + m_pbuffer = glXCreatePbuffer(DISPLAY_FROM_XCB(m_screen), config, attributes); + + if (m_pbuffer) + qglx_surfaceFormatFromGLXFBConfig(&m_format, DISPLAY_FROM_XCB(m_screen), config); + } +} + +QGLXPbuffer::~QGLXPbuffer() +{ + if (m_pbuffer) + glXDestroyPbuffer(DISPLAY_FROM_XCB(m_screen), m_pbuffer); +} + + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.h b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.h new file mode 100644 index 0000000000..73a17d69b4 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.h @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGLXINTEGRATION_H +#define QGLXINTEGRATION_H + +#include "qxcbwindow.h" +#include "qxcbscreen.h" + +#include +#include +#include + +#include + +#include + +QT_BEGIN_NAMESPACE + +class QGLXContext : public QPlatformOpenGLContext +{ +public: + QGLXContext(QXcbScreen *screen, const QSurfaceFormat &format, QPlatformOpenGLContext *share, + const QVariant &nativeHandle); + ~QGLXContext(); + + bool makeCurrent(QPlatformSurface *surface) Q_DECL_OVERRIDE; + void doneCurrent() Q_DECL_OVERRIDE; + void swapBuffers(QPlatformSurface *surface) Q_DECL_OVERRIDE; + void (*getProcAddress(const QByteArray &procName)) () Q_DECL_OVERRIDE; + + QSurfaceFormat format() const Q_DECL_OVERRIDE; + bool isSharing() const Q_DECL_OVERRIDE; + bool isValid() const Q_DECL_OVERRIDE; + + GLXContext glxContext() const { return m_context; } + GLXFBConfig glxConfig() const { return m_config; } + + QVariant nativeHandle() const; + + static bool supportsThreading(); + static void queryDummyContext(); + +private: + void init(QXcbScreen *screen, QPlatformOpenGLContext *share); + void init(QXcbScreen *screen, QPlatformOpenGLContext *share, const QVariant &nativeHandle); + + Display *m_display; + GLXFBConfig m_config; + GLXContext m_context; + GLXContext m_shareContext; + QSurfaceFormat m_format; + bool m_isPBufferCurrent; + int m_swapInterval; + bool m_ownsContext; + static bool m_queriedDummyContext; + static bool m_supportsThreading; +}; + + +class QGLXPbuffer : public QPlatformOffscreenSurface +{ +public: + explicit QGLXPbuffer(QOffscreenSurface *offscreenSurface); + ~QGLXPbuffer(); + + QSurfaceFormat format() const Q_DECL_OVERRIDE { return m_format; } + bool isValid() const Q_DECL_OVERRIDE { return m_pbuffer != 0; } + + GLXPbuffer pbuffer() const { return m_pbuffer; } + +private: + QSurfaceFormat m_format; + QXcbScreen *m_screen; + GLXPbuffer m_pbuffer; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.cpp new file mode 100644 index 0000000000..a4e603f599 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.cpp @@ -0,0 +1,217 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxcbglxintegration.h" + +#if defined(XCB_HAS_XCB_GLX) +#include +#endif + +#include "qxcbnativeinterface.h" +#include "qxcbglxwindow.h" +#include "qxcbscreen.h" +#include "qglxintegration.h" + +#include + +#include "qxcbglxnativeinterfacehandler.h" + +#include + +QT_BEGIN_NAMESPACE + +#if defined(XCB_HAS_XCB_GLX) && XCB_GLX_MAJOR_VERSION == 1 && XCB_GLX_MINOR_VERSION < 4 + +#define XCB_GLX_BUFFER_SWAP_COMPLETE 1 + +typedef struct xcb_glx_buffer_swap_complete_event_t { + uint8_t response_type; + uint8_t pad0; + uint16_t sequence; + uint16_t event_type; + uint8_t pad1[2]; + xcb_glx_drawable_t drawable; + uint32_t ust_hi; + uint32_t ust_lo; + uint32_t msc_hi; + uint32_t msc_lo; + uint32_t sbc; +} xcb_glx_buffer_swap_complete_event_t; +#endif + +#if defined(XCB_USE_XLIB) && defined(XCB_USE_GLX) +typedef struct { + int type; + unsigned long serial; /* # of last request processed by server */ + Bool send_event; /* true if this came from a SendEvent request */ + Display *display; /* Display the event was read from */ + Drawable drawable; /* drawable on which event was requested in event mask */ + int event_type; + int64_t ust; + int64_t msc; + int64_t sbc; +} QGLXBufferSwapComplete; +#endif + +QXcbGlxIntegration::QXcbGlxIntegration() + : m_connection(Q_NULLPTR) + , m_glx_first_event(0) +{ + qCDebug(QT_XCB_GLINTEGRATION) << "Xcb GLX gl-integration created"; +} + +QXcbGlxIntegration::~QXcbGlxIntegration() +{ +} + +bool QXcbGlxIntegration::initialize(QXcbConnection *connection) +{ + m_connection = connection; +#ifdef XCB_HAS_XCB_GLX + + const xcb_query_extension_reply_t *reply = xcb_get_extension_data(m_connection->xcb_connection(), &xcb_glx_id); + if (!reply || !reply->present) + return false; + + m_glx_first_event = reply->first_event; + + xcb_generic_error_t *error = 0; + xcb_glx_query_version_cookie_t xglx_query_cookie = xcb_glx_query_version(m_connection->xcb_connection(), + XCB_GLX_MAJOR_VERSION, + XCB_GLX_MINOR_VERSION); + xcb_glx_query_version_reply_t *xglx_query = xcb_glx_query_version_reply(m_connection->xcb_connection(), + xglx_query_cookie, &error); + if (!xglx_query || error) { + qCWarning(QT_XCB_GLINTEGRATION) << "QXcbConnection: Failed to initialize GLX"; + free(error); + return false; + } + free(xglx_query); +#endif + + m_native_interface_handler.reset(new QXcbGlxNativeInterfaceHandler(connection->nativeInterface())); + + qCDebug(QT_XCB_GLINTEGRATION) << "Xcb GLX gl-integration successfully initialized"; + return true; +} + +bool QXcbGlxIntegration::handleXcbEvent(xcb_generic_event_t *event, uint responseType) +{ + bool handled = false; + // Check if a custom XEvent constructor was registered in xlib for this event type, and call it discarding the constructed XEvent if any. + // XESetWireToEvent might be used by libraries to intercept messages from the X server e.g. the OpenGL lib waiting for DRI2 events. + Display *xdisplay = static_cast(m_connection->xlib_display()); + XLockDisplay(xdisplay); + bool locked = true; + Bool (*proc)(Display*, XEvent*, xEvent*) = XESetWireToEvent(xdisplay, responseType, 0); + if (proc) { + XESetWireToEvent(xdisplay, responseType, proc); + XEvent dummy; + event->sequence = LastKnownRequestProcessed(xdisplay); + if (proc(xdisplay, &dummy, (xEvent*)event)) { +#ifdef XCB_HAS_XCB_GLX + // DRI2 clients don't receive GLXBufferSwapComplete events on the wire. + // Instead the GLX event is synthesized from the DRI2BufferSwapComplete event + // by DRI2WireToEvent(). For an application to be able to see the event + // we have to convert it to an xcb_glx_buffer_swap_complete_event_t and + // pass it to the native event filter. + const uint swap_complete = m_glx_first_event + XCB_GLX_BUFFER_SWAP_COMPLETE; + QAbstractEventDispatcher* dispatcher = QAbstractEventDispatcher::instance(); + if (dispatcher && uint(dummy.type) == swap_complete && responseType != swap_complete) { + QGLXBufferSwapComplete *xev = reinterpret_cast(&dummy); + xcb_glx_buffer_swap_complete_event_t ev; + memset(&ev, 0, sizeof(xcb_glx_buffer_swap_complete_event_t)); + ev.response_type = xev->type; + ev.sequence = xev->serial; + ev.event_type = xev->event_type; + ev.drawable = xev->drawable; + ev.ust_hi = xev->ust >> 32; + ev.ust_lo = xev->ust & 0xffffffff; + ev.msc_hi = xev->msc >> 32; + ev.msc_lo = xev->msc & 0xffffffff; + ev.sbc = xev->sbc & 0xffffffff; + // Unlock the display before calling the native event filter + XUnlockDisplay(xdisplay); + locked = false; + QByteArray genericEventFilterType = m_connection->nativeInterface()->genericEventFilterType(); + long result = 0; + handled = dispatcher->filterNativeEvent(genericEventFilterType, &ev, &result); + } +#endif + } + } + if (locked) + XUnlockDisplay(xdisplay); + return handled; +} + +QXcbWindow *QXcbGlxIntegration::createWindow(QWindow *window) const +{ + return new QXcbGlxWindow(window); +} + +QPlatformOpenGLContext *QXcbGlxIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const +{ + QXcbScreen *screen = static_cast(context->screen()->handle()); + QGLXContext *platformContext = new QGLXContext(screen, context->format(), + context->shareHandle(), context->nativeHandle()); + context->setNativeHandle(platformContext->nativeHandle()); + return platformContext; +} + +QPlatformOffscreenSurface *QXcbGlxIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const +{ + static bool vendorChecked = false; + static bool glxPbufferUsable = true; + if (!vendorChecked) { + vendorChecked = true; + const char *glxvendor = glXGetClientString(glXGetCurrentDisplay(), GLX_VENDOR); + if (glxvendor && !strcmp(glxvendor, "ATI")) + glxPbufferUsable = false; + } + if (glxPbufferUsable) + return new QGLXPbuffer(surface); + else + return 0; // trigger fallback to hidden QWindow + +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.h b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.h new file mode 100644 index 0000000000..2ef40f9ab6 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBGLXINTEGRATION_H +#define QXCBGLXINTEGRATION_H + +#include "qxcbglintegration.h" + +QT_BEGIN_NAMESPACE + +class QXcbNativeInterfaceHandler; + +class QXcbGlxIntegration : public QXcbGlIntegration +{ +public: + QXcbGlxIntegration(); + ~QXcbGlxIntegration(); + + bool initialize(QXcbConnection *connection) Q_DECL_OVERRIDE; + bool handleXcbEvent(xcb_generic_event_t *event, uint responseType) Q_DECL_OVERRIDE; + + QXcbWindow *createWindow(QWindow *window) const Q_DECL_OVERRIDE; + QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const Q_DECL_OVERRIDE; + QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const Q_DECL_OVERRIDE; +private: + QXcbConnection *m_connection; + uint32_t m_glx_first_event; + + QScopedPointer m_native_interface_handler; +}; + +QT_END_NAMESPACE + +#endif //QXCBGLXINTEGRATION_H diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxmain.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxmain.cpp new file mode 100644 index 0000000000..93bb76f92f --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxmain.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxcbglintegrationplugin.h" + +#include "qxcbglxintegration.h" + +QT_BEGIN_NAMESPACE + +class QXcbGlxIntegrationPlugin : public QXcbGlIntegrationPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QXcbGlIntegrationFactoryInterface_iid FILE "xcb_glx.json") +public: + QXcbGlIntegration *create() + { + return new QXcbGlxIntegration(); + } + +}; + +QT_END_NAMESPACE + +#include "qxcbglxmain.moc" diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxnativeinterfacehandler.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxnativeinterfacehandler.cpp new file mode 100644 index 0000000000..6cdd4101e0 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxnativeinterfacehandler.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxcbglxnativeinterfacehandler.h" + +#include "qglxintegration.h" +#include +QT_BEGIN_NAMESPACE + +static int resourceType(const QByteArray &key) +{ + static const QByteArray names[] = { // match QXcbGlxNativeInterfaceHandler::ResourceType + QByteArrayLiteral("glxconfig"), + QByteArrayLiteral("glxcontext"), + }; + for (size_t i = 0; i < sizeof(names) / sizeof(names[0]); i++) { + if (key == names[i]) + return i; + } + + return sizeof(names) / sizeof(names[0]); +} + +QXcbGlxNativeInterfaceHandler::QXcbGlxNativeInterfaceHandler(QXcbNativeInterface *nativeInterface) + : QXcbNativeInterfaceHandler(nativeInterface) +{ +} + +QPlatformNativeInterface::NativeResourceForContextFunction QXcbGlxNativeInterfaceHandler::nativeResourceFunctionForContext(const QByteArray &resource) const +{ + switch (resourceType(resource)) { + case GLXConfig: + return glxConfigForContext; + case GLXContext: + return glxContextForContext; + default: + break; + } + return Q_NULLPTR; +} + +void *QXcbGlxNativeInterfaceHandler::glxContextForContext(QOpenGLContext *context) +{ + Q_ASSERT(context); + QGLXContext *glxPlatformContext = static_cast(context->handle()); + return glxPlatformContext->glxContext(); +} + +void *QXcbGlxNativeInterfaceHandler::glxConfigForContext(QOpenGLContext *context) +{ + Q_ASSERT(context); + QGLXContext *glxPlatformContext = static_cast(context->handle()); + return glxPlatformContext->glxConfig(); + +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxnativeinterfacehandler.h b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxnativeinterfacehandler.h new file mode 100644 index 0000000000..e9df28ea39 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxnativeinterfacehandler.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBGLXNATIVEINTERFACEHANDLER_H +#define QXCBGLXNATIVEINTERFACEHANDLER_H + +#include "qxcbnativeinterfacehandler.h" + +QT_BEGIN_NAMESPACE + +class QXcbGlxNativeInterfaceHandler : public QXcbNativeInterfaceHandler +{ +public: + enum ResourceType { + GLXConfig, + GLXContext, + }; + + QXcbGlxNativeInterfaceHandler(QXcbNativeInterface *nativeInterface); + QPlatformNativeInterface::NativeResourceForContextFunction nativeResourceFunctionForContext(const QByteArray &resource) const Q_DECL_OVERRIDE; + +private: + static void *glxContextForContext(QOpenGLContext *context); + static void *glxConfigForContext(QOpenGLContext *context); +}; + +QT_END_NAMESPACE + +#endif //QXCBGLXNATIVEINTERFACEHANDLER_H diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp new file mode 100644 index 0000000000..8aabde8129 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxcbglxwindow.h" + +#include "qxcbscreen.h" +#include + +QT_BEGIN_NAMESPACE + +QXcbGlxWindow::QXcbGlxWindow(QWindow *window) + : QXcbWindow(window) +{ +} + +QXcbGlxWindow::~QXcbGlxWindow() +{ +} + +void QXcbGlxWindow::resolveFormat() +{ + m_format = window()->requestedFormat(); //qglx_findVisualInfo sets the resovled format +} + +void *QXcbGlxWindow::createVisual() +{ + return qglx_findVisualInfo(DISPLAY_FROM_XCB(m_screen), m_screen->screenNumber(), &m_format); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.h b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.h new file mode 100644 index 0000000000..bb7cd7bef2 --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBGLXWINDOW_H +#define QXCBGLXWINDOW_H + +#include "qxcbglxintegration.h" +#include "qxcbwindow.h" + +QT_BEGIN_NAMESPACE + +class QXcbGlxWindow : public QXcbWindow +{ +public: + QXcbGlxWindow(QWindow *window); + ~QXcbGlxWindow(); + +protected: + void resolveFormat() Q_DECL_OVERRIDE; + void *createVisual() Q_DECL_OVERRIDE; +}; + +QT_END_NAMESPACE + +#endif //QXCBGLXWINDOW_H diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/xcb_glx.json b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/xcb_glx.json new file mode 100644 index 0000000000..1e2641ae7c --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/xcb_glx.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "xcb_glx" ] +} diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/xcb_glx.pro b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/xcb_glx.pro new file mode 100644 index 0000000000..57cd81ec3b --- /dev/null +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/xcb_glx.pro @@ -0,0 +1,31 @@ +TARGET = qxcb-glx-integration + +PLUGIN_CLASS_NAME = QXcbGlxIntegrationPlugin +PLUGIN_TYPE = xcbglintegrations + +load(qt_plugin) + +include(../gl_integrations_plugin_base.pri) + +#should be removed from the sources +DEFINES += XCB_USE_GLX XCB_USE_XLIB + +LIBS += -lxcb + +contains(QT_CONFIG, xcb-glx) { + DEFINES += XCB_HAS_XCB_GLX + LIBS += -lxcb-glx +} + +HEADERS += \ + qxcbglxintegration.h \ + qxcbglxwindow.h \ + qglxintegration.h \ + qxcbglxnativeinterfacehandler.h + +SOURCES += \ + qxcbglxmain.cpp \ + qxcbglxintegration.cpp \ + qxcbglxwindow.cpp \ + qglxintegration.cpp \ + qxcbglxnativeinterfacehandler.cpp diff --git a/src/plugins/platforms/xcb/qglxintegration.cpp b/src/plugins/platforms/xcb/qglxintegration.cpp deleted file mode 100644 index c0be836bce..0000000000 --- a/src/plugins/platforms/xcb/qglxintegration.cpp +++ /dev/null @@ -1,723 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -#include "qxcbwindow.h" -#include "qxcbscreen.h" - -#include -#include -#include - -#include -#include - -#include "qglxintegration.h" -#include -#include - -#if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) -#include -#endif - -QT_BEGIN_NAMESPACE - -typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*); - -#ifndef GLX_CONTEXT_CORE_PROFILE_BIT_ARB -#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 -#endif - -#ifndef GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB -#define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 -#endif - -#ifndef GLX_CONTEXT_ES2_PROFILE_BIT_EXT -#define GLX_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 -#endif - -#ifndef GLX_CONTEXT_PROFILE_MASK_ARB -#define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126 -#endif - -#ifndef GL_CONTEXT_FLAG_DEBUG_BIT -#define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002 -#endif - -static Window createDummyWindow(Display *dpy, XVisualInfo *visualInfo, int screenNumber, Window rootWin) -{ - Colormap cmap = XCreateColormap(dpy, rootWin, visualInfo->visual, AllocNone); - XSetWindowAttributes a; - a.background_pixel = WhitePixel(dpy, screenNumber); - a.border_pixel = BlackPixel(dpy, screenNumber); - a.colormap = cmap; - a.override_redirect = true; - - Window window = XCreateWindow(dpy, rootWin, - 0, 0, 100, 100, - 0, visualInfo->depth, InputOutput, visualInfo->visual, - CWBackPixel|CWBorderPixel|CWColormap|CWOverrideRedirect, &a); -#ifndef QT_NO_DEBUG - XStoreName(dpy, window, "Qt GLX dummy window"); -#endif - XFreeColormap(dpy, cmap); - return window; -} - -static Window createDummyWindow(Display *dpy, GLXFBConfig config, int screenNumber, Window rootWin) -{ - XVisualInfo *visualInfo = glXGetVisualFromFBConfig(dpy, config); - if (!visualInfo) - qFatal("Could not initialize GLX"); - Window window = createDummyWindow(dpy, visualInfo, screenNumber, rootWin); - XFree(visualInfo); - return window; -} - -static inline QByteArray getGlString(GLenum param) -{ - if (const GLubyte *s = glGetString(param)) - return QByteArray(reinterpret_cast(s)); - return QByteArray(); -} - -static void updateFormatFromContext(QSurfaceFormat &format) -{ - // Update the version, profile, and context bit of the format - int major = 0, minor = 0; - QByteArray versionString(getGlString(GL_VERSION)); - if (QPlatformOpenGLContext::parseOpenGLVersion(versionString, major, minor)) { - format.setMajorVersion(major); - format.setMinorVersion(minor); - } - - format.setProfile(QSurfaceFormat::NoProfile); - format.setOptions(QSurfaceFormat::FormatOptions()); - - if (format.renderableType() == QSurfaceFormat::OpenGL) { - if (format.version() < qMakePair(3, 0)) { - format.setOption(QSurfaceFormat::DeprecatedFunctions); - return; - } - - // Version 3.0 onwards - check if it includes deprecated functionality or is - // a debug context - GLint value = 0; - glGetIntegerv(GL_CONTEXT_FLAGS, &value); - if (!(value & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)) - format.setOption(QSurfaceFormat::DeprecatedFunctions); - if (value & GL_CONTEXT_FLAG_DEBUG_BIT) - format.setOption(QSurfaceFormat::DebugContext); - if (format.version() < qMakePair(3, 2)) - return; - - // Version 3.2 and newer have a profile - value = 0; - glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &value); - - if (value & GL_CONTEXT_CORE_PROFILE_BIT) - format.setProfile(QSurfaceFormat::CoreProfile); - else if (value & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) - format.setProfile(QSurfaceFormat::CompatibilityProfile); - } -} - -QGLXContext::QGLXContext(QXcbScreen *screen, const QSurfaceFormat &format, QPlatformOpenGLContext *share, - const QVariant &nativeHandle) - : QPlatformOpenGLContext() - , m_display(DISPLAY_FROM_XCB(screen)) - , m_config(0) - , m_context(0) - , m_shareContext(0) - , m_format(format) - , m_isPBufferCurrent(false) - , m_swapInterval(-1) - , m_ownsContext(nativeHandle.isNull()) -{ - if (nativeHandle.isNull()) - init(screen, share); - else - init(screen, share, nativeHandle); -} - -void QGLXContext::init(QXcbScreen *screen, QPlatformOpenGLContext *share) -{ - if (m_format.renderableType() == QSurfaceFormat::DefaultRenderableType) - m_format.setRenderableType(QSurfaceFormat::OpenGL); - if (m_format.renderableType() != QSurfaceFormat::OpenGL && m_format.renderableType() != QSurfaceFormat::OpenGLES) - return; - - if (share) - m_shareContext = static_cast(share)->glxContext(); - - GLXFBConfig config = qglx_findConfig(DISPLAY_FROM_XCB(screen),screen->screenNumber(),m_format); - m_config = config; - XVisualInfo *visualInfo = 0; - Window window = 0; // Temporary window used to query OpenGL context - - if (config) { - // Resolve entry point for glXCreateContextAttribsARB - glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0; - glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc) glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB"); - - QList glxExt = QByteArray(glXQueryExtensionsString(m_display, screen->screenNumber())).split(' '); - bool supportsProfiles = glxExt.contains("GLX_ARB_create_context_profile"); - - // Use glXCreateContextAttribsARB if available - // Also, GL ES context creation requires GLX_EXT_create_context_es2_profile - if (glxExt.contains("GLX_ARB_create_context") && glXCreateContextAttribsARB != 0 - && (m_format.renderableType() != QSurfaceFormat::OpenGLES || (supportsProfiles && glxExt.contains("GLX_EXT_create_context_es2_profile")))) { - // Try to create an OpenGL context for each known OpenGL version in descending - // order from the requested version. - const int requestedVersion = m_format.majorVersion() * 10 + qMin(m_format.minorVersion(), 9); - - QVector glVersions; - if (m_format.renderableType() == QSurfaceFormat::OpenGL) { - if (requestedVersion > 45) - glVersions << requestedVersion; - - // Don't bother with versions below 2.0 - glVersions << 45 << 44 << 43 << 42 << 41 << 40 << 33 << 32 << 31 << 30 << 21 << 20; - } else if (m_format.renderableType() == QSurfaceFormat::OpenGLES) { - if (requestedVersion > 31) - glVersions << requestedVersion; - - // Don't bother with versions below ES 2.0 - glVersions << 31 << 30 << 20; - // ES does not support any format option - m_format.setOptions(QSurfaceFormat::FormatOptions()); - } - - Q_ASSERT(glVersions.count() > 0); - - for (int i = 0; !m_context && i < glVersions.count(); i++) { - const int version = glVersions[i]; - if (version > requestedVersion) - continue; - - const int majorVersion = version / 10; - const int minorVersion = version % 10; - - QVector contextAttributes; - contextAttributes << GLX_CONTEXT_MAJOR_VERSION_ARB << majorVersion - << GLX_CONTEXT_MINOR_VERSION_ARB << minorVersion; - - - if (m_format.renderableType() == QSurfaceFormat::OpenGL) { - // If asking for OpenGL 3.2 or newer we should also specify a profile - if (version >= 32 && supportsProfiles) { - if (m_format.profile() == QSurfaceFormat::CoreProfile) - contextAttributes << GLX_CONTEXT_PROFILE_MASK_ARB << GLX_CONTEXT_CORE_PROFILE_BIT_ARB; - else - contextAttributes << GLX_CONTEXT_PROFILE_MASK_ARB << GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; - } - - int flags = 0; - - if (m_format.testOption(QSurfaceFormat::DebugContext)) - flags |= GLX_CONTEXT_DEBUG_BIT_ARB; - - // A forward-compatible context may be requested for 3.0 and later - if (version >= 30 && !m_format.testOption(QSurfaceFormat::DeprecatedFunctions)) - flags |= GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; - - if (flags != 0) - contextAttributes << GLX_CONTEXT_FLAGS_ARB << flags; - } else if (m_format.renderableType() == QSurfaceFormat::OpenGLES) { - contextAttributes << GLX_CONTEXT_PROFILE_MASK_ARB << GLX_CONTEXT_ES2_PROFILE_BIT_EXT; - } - - contextAttributes << None; - - m_context = glXCreateContextAttribsARB(m_display, config, m_shareContext, true, contextAttributes.data()); - if (!m_context && m_shareContext) { - // re-try without a shared glx context - m_context = glXCreateContextAttribsARB(m_display, config, 0, true, contextAttributes.data()); - if (m_context) - m_shareContext = 0; - } - } - } - - // Could not create a context using glXCreateContextAttribsARB, falling back to glXCreateNewContext. - if (!m_context) { - // requesting an OpenGL ES context requires glXCreateContextAttribsARB, so bail out - if (m_format.renderableType() == QSurfaceFormat::OpenGLES) - return; - - m_context = glXCreateNewContext(m_display, config, GLX_RGBA_TYPE, m_shareContext, true); - if (!m_context && m_shareContext) { - // re-try without a shared glx context - m_context = glXCreateNewContext(m_display, config, GLX_RGBA_TYPE, 0, true); - if (m_context) - m_shareContext = 0; - } - } - - // Get the basic surface format details - if (m_context) - qglx_surfaceFormatFromGLXFBConfig(&m_format, DISPLAY_FROM_XCB(screen), config); - - // Create a temporary window so that we can make the new context current - window = createDummyWindow(DISPLAY_FROM_XCB(screen), config, screen->screenNumber(), screen->root()); - } else { - // requesting an OpenGL ES context requires glXCreateContextAttribsARB, so bail out - if (m_format.renderableType() == QSurfaceFormat::OpenGLES) - return; - - // Note that m_format gets updated with the used surface format - visualInfo = qglx_findVisualInfo(m_display, screen->screenNumber(), &m_format); - if (!visualInfo) - qFatal("Could not initialize GLX"); - m_context = glXCreateContext(m_display, visualInfo, m_shareContext, true); - if (!m_context && m_shareContext) { - // re-try without a shared glx context - m_shareContext = 0; - m_context = glXCreateContext(m_display, visualInfo, Q_NULLPTR, true); - } - - // Create a temporary window so that we can make the new context current - window = createDummyWindow(DISPLAY_FROM_XCB(screen), visualInfo, screen->screenNumber(), screen->root()); - XFree(visualInfo); - } - - // Query the OpenGL version and profile - if (m_context && window) { - GLXContext prevContext = glXGetCurrentContext(); - GLXDrawable prevDrawable = glXGetCurrentDrawable(); - glXMakeCurrent(m_display, window, m_context); - updateFormatFromContext(m_format); - - // Make our context non-current - glXMakeCurrent(m_display, prevDrawable, prevContext); - } - - // Destroy our temporary window - XDestroyWindow(m_display, window); -} - -void QGLXContext::init(QXcbScreen *screen, QPlatformOpenGLContext *share, const QVariant &nativeHandle) -{ - if (!nativeHandle.canConvert()) { - qWarning("QGLXContext: Requires a QGLXNativeContext"); - return; - } - QGLXNativeContext handle = nativeHandle.value(); - GLXContext context = handle.context(); - if (!context) { - qWarning("QGLXContext: No GLXContext given"); - return; - } - - // Use the provided Display, if available. If not, use our own. It may still work. - Display *dpy = handle.display(); - if (!dpy) - dpy = DISPLAY_FROM_XCB(screen); - - // Legacy contexts created using glXCreateContext are created using a visual - // and the FBConfig cannot be queried. The only way to adapt these contexts - // is to figure out the visual id. - XVisualInfo *vinfo = 0; - // If the VisualID is provided use it. - VisualID vid = handle.visualId(); - if (!vid) { - // In the absence of the VisualID figure it out from the window. - Window wnd = handle.window(); - if (wnd) { - XWindowAttributes attrs; - XGetWindowAttributes(dpy, wnd, &attrs); - vid = XVisualIDFromVisual(attrs.visual); - } - } - if (vid) { - XVisualInfo v; - v.screen = screen->screenNumber(); - v.visualid = vid; - int n = 0; - vinfo = XGetVisualInfo(dpy, VisualScreenMask | VisualIDMask, &v, &n); - if (n < 1) { - XFree(vinfo); - vinfo = 0; - } - } - - // For contexts created with an FBConfig using the modern functions providing the - // visual or window is not mandatory. Just query the config from the context. - GLXFBConfig config = 0; - if (!vinfo) { - int configId = 0; - if (glXQueryContext(dpy, context, GLX_FBCONFIG_ID, &configId) != Success) { - qWarning("QGLXContext: Failed to query config from the provided context"); - return; - } - - GLXFBConfig *configs; - int numConfigs = 0; - static const int attribs[] = { GLX_FBCONFIG_ID, configId, None }; - configs = glXChooseFBConfig(dpy, screen->screenNumber(), attribs, &numConfigs); - if (!configs || numConfigs < 1) { - qWarning("QGLXContext: Failed to find config"); - return; - } - if (configs && numConfigs > 1) // this is suspicious so warn but let it continue - qWarning("QGLXContext: Multiple configs for FBConfig ID %d", configId); - - config = configs[0]; - // Store the config. - m_config = config; - } - - Q_ASSERT(vinfo || config); - - int screenNumber = DefaultScreen(dpy); - Window window; - if (vinfo) - window = createDummyWindow(dpy, vinfo, screenNumber, RootWindow(dpy, screenNumber)); - else - window = createDummyWindow(dpy, config, screenNumber, RootWindow(dpy, screenNumber)); - if (!window) { - qWarning("QGLXContext: Failed to create dummy window"); - return; - } - - // Update OpenGL version and buffer sizes in our format. - GLXContext prevContext = glXGetCurrentContext(); - GLXDrawable prevDrawable = glXGetCurrentDrawable(); - if (!glXMakeCurrent(dpy, window, context)) { - qWarning("QGLXContext: Failed to make provided context current"); - return; - } - m_format = QSurfaceFormat(); - m_format.setRenderableType(QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL - ? QSurfaceFormat::OpenGL : QSurfaceFormat::OpenGLES); - updateFormatFromContext(m_format); - if (vinfo) - qglx_surfaceFormatFromVisualInfo(&m_format, dpy, vinfo); - else - qglx_surfaceFormatFromGLXFBConfig(&m_format, dpy, config); - glXMakeCurrent(dpy, prevDrawable, prevContext); - XDestroyWindow(dpy, window); - - if (vinfo) - XFree(vinfo); - - // Success. Store the context. From this point on isValid() is true. - m_context = context; - - if (share) - m_shareContext = static_cast(share)->glxContext(); -} - -QGLXContext::~QGLXContext() -{ - if (m_ownsContext) - glXDestroyContext(m_display, m_context); -} - -static QXcbScreen *screenForPlatformSurface(QPlatformSurface *surface) -{ - QSurface::SurfaceClass surfaceClass = surface->surface()->surfaceClass(); - if (surfaceClass == QSurface::Window) { - return static_cast(static_cast(surface)->screen()); - } else if (surfaceClass == QSurface::Offscreen) { - return static_cast(static_cast(surface)->screen()); - } - return Q_NULLPTR; -} - -QVariant QGLXContext::nativeHandle() const -{ - return QVariant::fromValue(QGLXNativeContext(m_context)); -} - -bool QGLXContext::makeCurrent(QPlatformSurface *surface) -{ - bool success = false; - Q_ASSERT(surface->surface()->supportsOpenGL()); - - GLXDrawable glxDrawable = 0; - QSurface::SurfaceClass surfaceClass = surface->surface()->surfaceClass(); - if (surfaceClass == QSurface::Window) { - m_isPBufferCurrent = false; - QXcbWindow *window = static_cast(surface); - glxDrawable = window->xcb_window(); - success = glXMakeCurrent(m_display, glxDrawable, m_context); - } else if (surfaceClass == QSurface::Offscreen) { - m_isPBufferCurrent = true; - QGLXPbuffer *pbuffer = static_cast(surface); - glxDrawable = pbuffer->pbuffer(); - success = glXMakeContextCurrent(m_display, glxDrawable, glxDrawable, m_context); - } - - if (success) { - int interval = surface->format().swapInterval(); - QXcbScreen *screen = screenForPlatformSurface(surface); - if (interval >= 0 && m_swapInterval != interval && screen) { - m_swapInterval = interval; - typedef void (*qt_glXSwapIntervalEXT)(Display *, GLXDrawable, int); - typedef void (*qt_glXSwapIntervalMESA)(unsigned int); - static qt_glXSwapIntervalEXT glXSwapIntervalEXT = 0; - static qt_glXSwapIntervalMESA glXSwapIntervalMESA = 0; - static bool resolved = false; - if (!resolved) { - resolved = true; - QList glxExt = QByteArray(glXQueryExtensionsString(m_display, - screen->screenNumber())).split(' '); - if (glxExt.contains("GLX_EXT_swap_control")) - glXSwapIntervalEXT = (qt_glXSwapIntervalEXT) getProcAddress("glXSwapIntervalEXT"); - if (glxExt.contains("GLX_MESA_swap_control")) - glXSwapIntervalMESA = (qt_glXSwapIntervalMESA) getProcAddress("glXSwapIntervalMESA"); - } - if (glXSwapIntervalEXT) - glXSwapIntervalEXT(m_display, glxDrawable, interval); - else if (glXSwapIntervalMESA) - glXSwapIntervalMESA(interval); - } - } - - return success; -} - -void QGLXContext::doneCurrent() -{ - if (m_isPBufferCurrent) - glXMakeContextCurrent(m_display, 0, 0, 0); - else - glXMakeCurrent(m_display, 0, 0); - m_isPBufferCurrent = false; -} - -void QGLXContext::swapBuffers(QPlatformSurface *surface) -{ - GLXDrawable glxDrawable = 0; - if (surface->surface()->surfaceClass() == QSurface::Offscreen) - glxDrawable = static_cast(surface)->pbuffer(); - else - glxDrawable = static_cast(surface)->xcb_window(); - glXSwapBuffers(m_display, glxDrawable); - - if (surface->surface()->surfaceClass() == QSurface::Window) { - QXcbWindow *platformWindow = static_cast(surface); - // OpenGL context might be bound to a non-gui thread use QueuedConnection to sync - // the window from the platformWindow's thread as QXcbWindow is no QObject, an - // event is sent to QXcbConnection. (this is faster than a metacall) - if (platformWindow->needsSync()) - platformWindow->postSyncWindowRequest(); - } -} - -void (*QGLXContext::getProcAddress(const QByteArray &procName)) () -{ - typedef void *(*qt_glXGetProcAddressARB)(const GLubyte *); - static qt_glXGetProcAddressARB glXGetProcAddressARB = 0; - static bool resolved = false; - - if (resolved && !glXGetProcAddressARB) - return 0; - if (!glXGetProcAddressARB) { - QList glxExt = QByteArray(glXGetClientString(m_display, GLX_EXTENSIONS)).split(' '); - if (glxExt.contains("GLX_ARB_get_proc_address")) { -#if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) - void *handle = dlopen(NULL, RTLD_LAZY); - if (handle) { - glXGetProcAddressARB = (qt_glXGetProcAddressARB) dlsym(handle, "glXGetProcAddressARB"); - dlclose(handle); - } - if (!glXGetProcAddressARB) -#endif - { - extern const QString qt_gl_library_name(); -// QLibrary lib(qt_gl_library_name()); - QLibrary lib(QLatin1String("GL")); - glXGetProcAddressARB = (qt_glXGetProcAddressARB) lib.resolve("glXGetProcAddressARB"); - } - } - resolved = true; - } - if (!glXGetProcAddressARB) - return 0; - return (void (*)())glXGetProcAddressARB(reinterpret_cast(procName.constData())); -} - -QSurfaceFormat QGLXContext::format() const -{ - return m_format; -} - -bool QGLXContext::isSharing() const -{ - return m_shareContext != 0; -} - -bool QGLXContext::isValid() const -{ - return m_context != 0; -} - -bool QGLXContext::m_queriedDummyContext = false; -bool QGLXContext::m_supportsThreading = true; - - -// If this list grows to any significant size, change it a -// proper string table and make the implementation below use -// binary search. -static const char *qglx_threadedgl_blacklist_renderer[] = { - "Chromium", // QTBUG-32225 (initialization fails) - 0 -}; - -// This disables threaded rendering on anything using mesa, e.g. -// - nvidia/nouveau -// - amd/gallium -// - intel -// - some software opengl implementations -// -// The client glx vendor string is used to identify those setups as that seems to show the least -// variance between the bad configurations. It's always "Mesa Project and SGI". There are some -// configurations which don't use mesa and which can do threaded rendering (amd and nvidia chips -// with their own proprietary drivers). -// -// This, of course, is very broad and disables threaded rendering on a lot of devices which would -// be able to use it. However, the bugs listed below don't follow any easily recognizable pattern -// and we should rather be safe. -// -// http://cgit.freedesktop.org/xcb/libxcb/commit/?id=be0fe56c3bcad5124dcc6c47a2fad01acd16f71a will -// fix some of the issues. Basically, the proprietary drivers seem to have a way of working around -// a fundamental flaw with multithreaded access to xcb, but mesa doesn't. The blacklist should be -// reevaluated once that patch is released in some version of xcb. -static const char *qglx_threadedgl_blacklist_vendor[] = { - "Mesa Project and SGI", // QTCREATORBUG-10875 (crash in creator) - // QTBUG-34492 (flickering in fullscreen) - // QTBUG-38221 - 0 -}; - -void QGLXContext::queryDummyContext() -{ - if (m_queriedDummyContext) - return; - m_queriedDummyContext = true; - - static bool skip = qEnvironmentVariableIsSet("QT_OPENGL_NO_SANITY_CHECK"); - if (skip) - return; - - QOpenGLContext *oldContext = QOpenGLContext::currentContext(); - QSurface *oldSurface = 0; - if (oldContext) - oldSurface = oldContext->surface(); - - QScopedPointer surface; - const char *glxvendor = glXGetClientString(glXGetCurrentDisplay(), GLX_VENDOR); - if (glxvendor && !strcmp(glxvendor, "ATI")) { - QWindow *window = new QWindow; - window->resize(64, 64); - window->setSurfaceType(QSurface::OpenGLSurface); - window->create(); - surface.reset(window); - } else { - QOffscreenSurface *offSurface = new QOffscreenSurface; - offSurface->create(); - surface.reset(offSurface); - } - - QOpenGLContext context; - context.create(); - context.makeCurrent(surface.data()); - - m_supportsThreading = true; - - if (const char *renderer = (const char *) glGetString(GL_RENDERER)) { - for (int i = 0; qglx_threadedgl_blacklist_renderer[i]; ++i) { - if (strstr(renderer, qglx_threadedgl_blacklist_renderer[i]) != 0) { - m_supportsThreading = false; - break; - } - } - } - - if (glxvendor) { - for (int i = 0; qglx_threadedgl_blacklist_vendor[i]; ++i) { - if (strstr(glxvendor, qglx_threadedgl_blacklist_vendor[i]) != 0) { - m_supportsThreading = false; - break; - } - } - } - - context.doneCurrent(); - if (oldContext && oldSurface) - oldContext->makeCurrent(oldSurface); -} - -bool QGLXContext::supportsThreading() -{ - if (!m_queriedDummyContext) - queryDummyContext(); - return m_supportsThreading; -} - -QGLXPbuffer::QGLXPbuffer(QOffscreenSurface *offscreenSurface) - : QPlatformOffscreenSurface(offscreenSurface) - , m_format(offscreenSurface->requestedFormat()) - , m_screen(static_cast(offscreenSurface->screen()->handle())) - , m_pbuffer(0) -{ - GLXFBConfig config = qglx_findConfig(DISPLAY_FROM_XCB(m_screen), m_screen->screenNumber(), m_format); - - if (config) { - const int attributes[] = { - GLX_PBUFFER_WIDTH, offscreenSurface->size().width(), - GLX_PBUFFER_HEIGHT, offscreenSurface->size().height(), - GLX_LARGEST_PBUFFER, False, - GLX_PRESERVED_CONTENTS, False, - None - }; - - m_pbuffer = glXCreatePbuffer(DISPLAY_FROM_XCB(m_screen), config, attributes); - - if (m_pbuffer) - qglx_surfaceFormatFromGLXFBConfig(&m_format, DISPLAY_FROM_XCB(m_screen), config); - } -} - -QGLXPbuffer::~QGLXPbuffer() -{ - if (m_pbuffer) - glXDestroyPbuffer(DISPLAY_FROM_XCB(m_screen), m_pbuffer); -} - - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/qglxintegration.h b/src/plugins/platforms/xcb/qglxintegration.h deleted file mode 100644 index 73a17d69b4..0000000000 --- a/src/plugins/platforms/xcb/qglxintegration.h +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGLXINTEGRATION_H -#define QGLXINTEGRATION_H - -#include "qxcbwindow.h" -#include "qxcbscreen.h" - -#include -#include -#include - -#include - -#include - -QT_BEGIN_NAMESPACE - -class QGLXContext : public QPlatformOpenGLContext -{ -public: - QGLXContext(QXcbScreen *screen, const QSurfaceFormat &format, QPlatformOpenGLContext *share, - const QVariant &nativeHandle); - ~QGLXContext(); - - bool makeCurrent(QPlatformSurface *surface) Q_DECL_OVERRIDE; - void doneCurrent() Q_DECL_OVERRIDE; - void swapBuffers(QPlatformSurface *surface) Q_DECL_OVERRIDE; - void (*getProcAddress(const QByteArray &procName)) () Q_DECL_OVERRIDE; - - QSurfaceFormat format() const Q_DECL_OVERRIDE; - bool isSharing() const Q_DECL_OVERRIDE; - bool isValid() const Q_DECL_OVERRIDE; - - GLXContext glxContext() const { return m_context; } - GLXFBConfig glxConfig() const { return m_config; } - - QVariant nativeHandle() const; - - static bool supportsThreading(); - static void queryDummyContext(); - -private: - void init(QXcbScreen *screen, QPlatformOpenGLContext *share); - void init(QXcbScreen *screen, QPlatformOpenGLContext *share, const QVariant &nativeHandle); - - Display *m_display; - GLXFBConfig m_config; - GLXContext m_context; - GLXContext m_shareContext; - QSurfaceFormat m_format; - bool m_isPBufferCurrent; - int m_swapInterval; - bool m_ownsContext; - static bool m_queriedDummyContext; - static bool m_supportsThreading; -}; - - -class QGLXPbuffer : public QPlatformOffscreenSurface -{ -public: - explicit QGLXPbuffer(QOffscreenSurface *offscreenSurface); - ~QGLXPbuffer(); - - QSurfaceFormat format() const Q_DECL_OVERRIDE { return m_format; } - bool isValid() const Q_DECL_OVERRIDE { return m_pbuffer != 0; } - - GLXPbuffer pbuffer() const { return m_pbuffer; } - -private: - QSurfaceFormat m_format; - QXcbScreen *m_screen; - GLXPbuffer m_pbuffer; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index ea13502a21..2e429939ba 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -44,6 +44,8 @@ #include "qxcbnativeinterface.h" #include "qxcbintegration.h" #include "qxcbsystemtraytracker.h" +#include "qxcbglintegrationfactory.h" +#include "qxcbglintegration.h" #include #include @@ -74,14 +76,6 @@ #include #endif -#if defined(XCB_HAS_XCB_GLX) -#include -#endif - -#ifdef XCB_USE_EGL //don't pull in eglext prototypes -#include -#endif - QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(lcQpaXInput, "qt.qpa.input") @@ -121,39 +115,6 @@ static int ioErrorHandler(Display *dpy) } #endif -#if defined(XCB_HAS_XCB_GLX) && XCB_GLX_MAJOR_VERSION == 1 && XCB_GLX_MINOR_VERSION < 4 - -#define XCB_GLX_BUFFER_SWAP_COMPLETE 1 - -typedef struct xcb_glx_buffer_swap_complete_event_t { - uint8_t response_type; - uint8_t pad0; - uint16_t sequence; - uint16_t event_type; - uint8_t pad1[2]; - xcb_glx_drawable_t drawable; - uint32_t ust_hi; - uint32_t ust_lo; - uint32_t msc_hi; - uint32_t msc_lo; - uint32_t sbc; -} xcb_glx_buffer_swap_complete_event_t; -#endif - -#if defined(XCB_USE_XLIB) && defined(XCB_USE_GLX) -typedef struct { - int type; - unsigned long serial; /* # of last request processed by server */ - Bool send_event; /* true if this came from a SendEvent request */ - Display *display; /* Display the event was read from */ - Drawable drawable; /* drawable on which event was requested in event mask */ - int event_type; - int64_t ust; - int64_t msc; - int64_t sbc; -} QGLXBufferSwapComplete; -#endif - QXcbScreen* QXcbConnection::findOrCreateScreen(QList& newScreens, int screenNumber, xcb_screen_t* xcbScreen, xcb_randr_get_output_info_reply_t *output) { @@ -309,11 +270,12 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra , m_primaryScreenNumber(0) , m_displayName(displayName ? QByteArray(displayName) : qgetenv("DISPLAY")) , m_nativeInterface(nativeInterface) +#ifdef XCB_USE_XLIB + , m_xlib_display(0) +#endif , xfixes_first_event(0) , xrandr_first_event(0) , xkb_first_event(0) - , glx_first_event(0) - , has_glx_extension(false) , has_shape_extension(false) , has_randr_extension(false) , has_input_shape(false) @@ -322,14 +284,10 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra , m_buttons(0) , m_focusWindow(0) , m_systemTrayTracker(0) + , m_glIntegration(Q_NULLPTR) { -#ifdef XCB_USE_EGL - EGLNativeDisplayType dpy = EGL_DEFAULT_DISPLAY; -#elif defined(XCB_USE_XLIB) - Display *dpy; -#endif #ifdef XCB_USE_XLIB - dpy = XOpenDisplay(m_displayName.constData()); + Display *dpy = XOpenDisplay(m_displayName.constData()); if (dpy) { m_primaryScreenNumber = DefaultScreen(dpy); m_connection = XGetXCBConnection(dpy); @@ -345,12 +303,6 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra if (!m_connection || xcb_connection_has_error(m_connection)) qFatal("QXcbConnection: Could not connect to display %s", m_displayName.constData()); -#ifdef XCB_USE_EGL - EGLDisplay eglDisplay = eglGetDisplay(dpy); - m_egl_display = eglDisplay; - EGLint major, minor; - m_has_egl = eglInitialize(eglDisplay, &major, &minor); -#endif //XCB_USE_EGL m_reader = new QXcbEventReader(this); m_reader->start(); @@ -362,9 +314,6 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra #endif #ifdef XCB_USE_RENDER &xcb_render_id, -#endif -#ifdef XCB_HAS_XCB_GLX - &xcb_glx_id, #endif 0 }; @@ -382,7 +331,6 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra initializeXRandr(); updateScreens(); - initializeGLX(); initializeXFixes(); initializeXRender(); m_xi2Enabled = false; @@ -405,6 +353,27 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra if (!m_startupId.isNull()) qunsetenv("DESKTOP_STARTUP_ID"); + + QStringList glIntegrationNames; + glIntegrationNames << QStringLiteral("xcb_glx") << QStringLiteral("xcb_egl"); + QString glIntegrationName = QString::fromLocal8Bit(qgetenv("QT_XCB_GL_INTEGRATION")); + if (glIntegrationName.size()) { + glIntegrationNames.removeAll(glIntegrationName); + glIntegrationNames.prepend(glIntegrationName); + } + + qCDebug(QT_XCB_GLINTEGRATION) << "Choosing xcb gl-integration based on following priority\n" << glIntegrationNames; + for (int i = 0; i < glIntegrationNames.size() && !m_glIntegration; i++) { + m_glIntegration = QXcbGlIntegrationFactory::create(glIntegrationNames.at(i)); + if (m_glIntegration && !m_glIntegration->initialize(this)) { + qCDebug(QT_XCB_GLINTEGRATION) << "Failed to initialize xcb gl-integration" << glIntegrationNames.at(i); + delete m_glIntegration; + m_glIntegration = Q_NULLPTR; + } + } + if (!m_glIntegration) + qCDebug(QT_XCB_GLINTEGRATION) << "Failed to create xcb gl-integration"; + sync(); if (qEnvironmentVariableIsEmpty("QT_IM_MODULE")) @@ -435,11 +404,6 @@ QXcbConnection::~QXcbConnection() while (!m_screens.isEmpty()) delete m_screens.takeLast(); -#ifdef XCB_USE_EGL - if (m_has_egl) - eglTerminate(m_egl_display); -#endif //XCB_USE_EGL - #ifdef XCB_USE_XLIB XCloseDisplay((Display *)m_xlib_display); #else @@ -990,51 +954,8 @@ void QXcbConnection::handleXcbEvent(xcb_generic_event_t *event) } } -#ifdef XCB_USE_XLIB - if (!handled) { - // Check if a custom XEvent constructor was registered in xlib for this event type, and call it discarding the constructed XEvent if any. - // XESetWireToEvent might be used by libraries to intercept messages from the X server e.g. the OpenGL lib waiting for DRI2 events. - Display *xdisplay = (Display *)m_xlib_display; - XLockDisplay(xdisplay); - bool locked = true; - Bool (*proc)(Display*, XEvent*, xEvent*) = XESetWireToEvent(xdisplay, response_type, 0); - if (proc) { - XESetWireToEvent(xdisplay, response_type, proc); - XEvent dummy; - event->sequence = LastKnownRequestProcessed(m_xlib_display); - if (proc(xdisplay, &dummy, (xEvent*)event)) { -#if defined(XCB_USE_GLX) && defined(XCB_HAS_XCB_GLX) - // DRI2 clients don't receive GLXBufferSwapComplete events on the wire. - // Instead the GLX event is synthesized from the DRI2BufferSwapComplete event - // by DRI2WireToEvent(). For an application to be able to see the event - // we have to convert it to an xcb_glx_buffer_swap_complete_event_t and - // pass it to the native event filter. - const uint swap_complete = glx_first_event + XCB_GLX_BUFFER_SWAP_COMPLETE; - if (dispatcher && has_glx_extension && uint(dummy.type) == swap_complete && response_type != swap_complete) { - QGLXBufferSwapComplete *xev = reinterpret_cast(&dummy); - xcb_glx_buffer_swap_complete_event_t ev; - memset(&ev, 0, sizeof(xcb_glx_buffer_swap_complete_event_t)); - ev.response_type = xev->type; - ev.sequence = xev->serial; - ev.event_type = xev->event_type; - ev.drawable = xev->drawable; - ev.ust_hi = xev->ust >> 32; - ev.ust_lo = xev->ust & 0xffffffff; - ev.msc_hi = xev->msc >> 32; - ev.msc_lo = xev->msc & 0xffffffff; - ev.sbc = xev->sbc & 0xffffffff; - // Unlock the display before calling the native event filter - XUnlockDisplay(xdisplay); - locked = false; - handled = dispatcher->filterNativeEvent(m_nativeInterface->genericEventFilterType(), &ev, &result); - } -#endif - } - } - if (locked) - XUnlockDisplay(xdisplay); - } -#endif + if (!handled) + handled = m_glIntegration->handleXcbEvent(event, response_type); if (handled) printXcbEvent("Handled XCB event", event); @@ -1232,6 +1153,11 @@ xcb_window_t QXcbConnection::rootWindow() return primaryScreen()->root(); } +void *QXcbConnection::xlib_display() const +{ + return m_xlib_display; +} + void QXcbConnection::processXcbEvents() { int connection_error = xcb_connection_has_error(xcb_connection()); @@ -1674,34 +1600,6 @@ void QXcbConnection::initializeXRender() #endif } -void QXcbConnection::initializeGLX() -{ -#ifdef XCB_HAS_XCB_GLX - const xcb_query_extension_reply_t *reply = xcb_get_extension_data(m_connection, &xcb_glx_id); - if (!reply || !reply->present) - return; - - has_glx_extension = true; - glx_first_event = reply->first_event; - - xcb_generic_error_t *error = 0; - xcb_glx_query_version_cookie_t xglx_query_cookie = xcb_glx_query_version(m_connection, - XCB_GLX_MAJOR_VERSION, - XCB_GLX_MINOR_VERSION); - xcb_glx_query_version_reply_t *xglx_query = xcb_glx_query_version_reply(m_connection, - xglx_query_cookie, &error); - if (!xglx_query || error) { - qWarning("QXcbConnection: Failed to initialize GLX"); - free(error); - has_glx_extension = false; - } - free(xglx_query); -#else - // no way to check, assume GLX is present - has_glx_extension = true; -#endif -} - void QXcbConnection::initializeXRandr() { const xcb_query_extension_reply_t *reply = xcb_get_extension_data(m_connection, &xcb_randr_id); @@ -1811,13 +1709,6 @@ void QXcbConnection::initializeXKB() #endif } -#if defined(XCB_USE_EGL) -bool QXcbConnection::hasEgl() const -{ - return m_has_egl; -} -#endif // defined(XCB_USE_EGL) - #if defined(XCB_USE_XINPUT2) static int xi2ValuatorOffset(unsigned char *maskPtr, int maskLen, int number) { diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index 65d117cc02..18fc8113e1 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -36,6 +36,7 @@ #include +#include "qxcbexport.h" #include #include #include @@ -85,6 +86,7 @@ class QXcbClipboard; class QXcbWMSupport; class QXcbNativeInterface; class QXcbSystemTrayTracker; +class QXcbGlIntegration; namespace QXcbAtom { enum Atom { @@ -360,7 +362,7 @@ private: }; class QAbstractEventDispatcher; -class QXcbConnection : public QObject +class Q_XCB_EXPORT QXcbConnection : public QObject { Q_OBJECT public: @@ -395,15 +397,9 @@ public: QXcbWMSupport *wmSupport() const { return m_wmSupport.data(); } xcb_window_t rootWindow(); #ifdef XCB_USE_XLIB - void *xlib_display() const { return m_xlib_display; } + void *xlib_display() const; #endif -#ifdef XCB_USE_EGL - bool hasEgl() const; -#endif -#if defined(XCB_USE_EGL) - void *egl_display() const { return m_egl_display; } -#endif #if defined(XCB_USE_XINPUT2) void xi2Select(xcb_window_t window); #endif @@ -437,7 +433,6 @@ public: inline xcb_timestamp_t netWmUserTime() const { return m_netWmUserTime; } inline void setNetWmUserTime(xcb_timestamp_t t) { if (t > m_netWmUserTime) m_netWmUserTime = t; } - bool hasGLX() const { return has_glx_extension; } bool hasXFixes() const { return xfixes_first_event > 0; } bool hasXShape() const { return has_shape_extension; } bool hasXRandr() const { return has_randr_extension; } @@ -446,6 +441,7 @@ public: bool hasXKB() const { return has_xkb; } bool supportsThreadedRendering() const { return m_reader->isRunning(); } + bool threadedEventHandling() const { return m_reader->isRunning(); } xcb_timestamp_t getTimestamp(); @@ -472,6 +468,8 @@ public: QXcbEventReader *eventReader() const { return m_reader; } bool canGrab() const { return m_canGrabServer; } + + QXcbGlIntegration *glIntegration() const { return m_glIntegration; } protected: bool event(QEvent *e) Q_DECL_OVERRIDE; @@ -484,7 +482,6 @@ private slots: private: void initializeAllAtoms(); void sendConnectionEvent(QXcbAtom::Atom atom, uint id = 0); - void initializeGLX(); void initializeXFixes(); void initializeXRender(); void initializeXRandr(); @@ -580,10 +577,6 @@ private: QHash m_touchPoints; QHash m_touchDevices; #endif -#if defined(XCB_USE_EGL) - void *m_egl_display; - bool m_has_egl; -#endif #ifdef Q_XCB_DEBUG struct CallInfo { int sequence; @@ -604,9 +597,7 @@ private: uint32_t xfixes_first_event; uint32_t xrandr_first_event; uint32_t xkb_first_event; - uint32_t glx_first_event; - bool has_glx_extension; bool has_shape_extension; bool has_randr_extension; bool has_input_shape; @@ -619,6 +610,7 @@ private: QByteArray m_startupId; QXcbSystemTrayTracker *m_systemTrayTracker; + QXcbGlIntegration *m_glIntegration; friend class QXcbEventReader; }; @@ -668,11 +660,6 @@ cookie_t q_xcb_call_template(const cookie_t &cookie, QXcbConnection *connection, #define Q_XCB_NOOP(c) #endif - -#if defined(XCB_USE_EGL) -#define EGL_DISPLAY_FROM_XCB(object) ((EGLDisplay)(object->connection()->egl_display())) -#endif - QT_END_NAMESPACE #endif diff --git a/src/plugins/platforms/xcb/qxcbeglsurface.h b/src/plugins/platforms/xcb/qxcbeglsurface.h deleted file mode 100644 index b03a029094..0000000000 --- a/src/plugins/platforms/xcb/qxcbeglsurface.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QXCBEGLSURFACE_H -#define QXCBEGLSURFACE_H - -#include - -QT_BEGIN_NAMESPACE - -class QXcbEGLSurface -{ -public: - QXcbEGLSurface(EGLDisplay display, EGLSurface surface) - : m_display(display) - , m_surface(surface) - { - } - - ~QXcbEGLSurface() - { - eglDestroySurface(m_display, m_surface); - } - - EGLSurface surface() const { return m_surface; } - -private: - EGLDisplay m_display; - EGLSurface m_surface; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/platforms/xcb/qxcbexport.h b/src/plugins/platforms/xcb/qxcbexport.h new file mode 100644 index 0000000000..caf5124133 --- /dev/null +++ b/src/plugins/platforms/xcb/qxcbexport.h @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBEXPORT_H +#define QXCBEXPORT_H + +#include + +QT_BEGIN_NAMESPACE + +# if defined(QT_BUILD_XCB_PLUGIN) +# define Q_XCB_EXPORT Q_DECL_EXPORT +# else +# define Q_XCB_EXPORT Q_DECL_IMPORT +# endif + +QT_END_NAMESPACE +#endif //QXCBEXPORT_H + diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index 1a10a865ab..f8b2c4090f 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -41,6 +41,7 @@ #include "qxcbnativeinterface.h" #include "qxcbclipboard.h" #include "qxcbdrag.h" +#include "qxcbglintegration.h" #ifndef QT_NO_SESSIONMANAGER #include "qxcbsessionmanager.h" @@ -69,15 +70,6 @@ #include #include -#if defined(XCB_USE_GLX) -#include "qglxintegration.h" -#elif defined(XCB_USE_EGL) -#include "qxcbeglsurface.h" -#include -#include -#include -#endif - #include #include #include @@ -191,82 +183,32 @@ QXcbIntegration::~QXcbIntegration() QPlatformWindow *QXcbIntegration::createPlatformWindow(QWindow *window) const { - return new QXcbWindow(window); -} - -#if defined(XCB_USE_EGL) -class QEGLXcbPlatformContext : public QEGLPlatformContext -{ -public: - QEGLXcbPlatformContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share, - EGLDisplay display, QXcbConnection *c, const QVariant &nativeHandle) - : QEGLPlatformContext(glFormat, share, display, 0, nativeHandle) - , m_connection(c) - { - Q_XCB_NOOP(m_connection); - } - - void swapBuffers(QPlatformSurface *surface) - { - Q_XCB_NOOP(m_connection); - QEGLPlatformContext::swapBuffers(surface); - Q_XCB_NOOP(m_connection); - } - - bool makeCurrent(QPlatformSurface *surface) - { - Q_XCB_NOOP(m_connection); - bool ret = QEGLPlatformContext::makeCurrent(surface); - Q_XCB_NOOP(m_connection); - return ret; - } - - void doneCurrent() - { - Q_XCB_NOOP(m_connection); - QEGLPlatformContext::doneCurrent(); - Q_XCB_NOOP(m_connection); - } - - EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) - { - if (surface->surface()->surfaceClass() == QSurface::Window) - return static_cast(surface)->eglSurface()->surface(); - else - return static_cast(surface)->pbuffer(); - } - - QVariant nativeHandle() const { - return QVariant::fromValue(QEGLNativeContext(eglContext(), eglDisplay())); + if (window->type() != Qt::Desktop) { + QXcbScreen *screen = static_cast(window->screen()->handle()); + QXcbGlIntegration *glIntegration = screen->connection()->glIntegration(); + if (glIntegration) { + QXcbWindow *xcbWindow = glIntegration->createWindow(window); + xcbWindow->create(); + return xcbWindow; + } } -private: - QXcbConnection *m_connection; -}; -#endif + Q_ASSERT(window->type() == Qt::Desktop || !window->supportsOpenGL()); + QXcbWindow *xcbWindow = new QXcbWindow(window); + xcbWindow->create(); + return xcbWindow; +} #ifndef QT_NO_OPENGL QPlatformOpenGLContext *QXcbIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const { QXcbScreen *screen = static_cast(context->screen()->handle()); -#if defined(XCB_USE_GLX) - QGLXContext *platformContext = new QGLXContext(screen, context->format(), - context->shareHandle(), context->nativeHandle()); - context->setNativeHandle(platformContext->nativeHandle()); - return platformContext; -#elif defined(XCB_USE_EGL) - QEGLXcbPlatformContext *platformContext = new QEGLXcbPlatformContext(context->format(), - context->shareHandle(), - screen->connection()->egl_display(), - screen->connection(), - context->nativeHandle()); - context->setNativeHandle(platformContext->nativeHandle()); - return platformContext; -#else - Q_UNUSED(screen); - qWarning("QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled"); - return 0; -#endif + QXcbGlIntegration *glIntegration = screen->connection()->glIntegration(); + if (!glIntegration) { + qWarning("QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled"); + return Q_NULLPTR; + } + return glIntegration->createPlatformOpenGLContext(context); } #endif @@ -277,45 +219,23 @@ QPlatformBackingStore *QXcbIntegration::createPlatformBackingStore(QWindow *wind QPlatformOffscreenSurface *QXcbIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const { -#if defined(XCB_USE_GLX) - static bool vendorChecked = false; - static bool glxPbufferUsable = true; - if (!vendorChecked) { - vendorChecked = true; - const char *glxvendor = glXGetClientString(glXGetCurrentDisplay(), GLX_VENDOR); - if (glxvendor && !strcmp(glxvendor, "ATI")) - glxPbufferUsable = false; - } - if (glxPbufferUsable) - return new QGLXPbuffer(surface); - else - return 0; // trigger fallback to hidden QWindow -#elif defined(XCB_USE_EGL) QXcbScreen *screen = static_cast(surface->screen()->handle()); - return new QEGLPbuffer(screen->connection()->egl_display(), surface->requestedFormat(), surface); -#else - Q_UNUSED(surface); - qWarning("QXcbIntegration: Cannot create platform offscreen surface, neither GLX nor EGL are enabled"); - return 0; -#endif + QXcbGlIntegration *glIntegration = screen->connection()->glIntegration(); + if (!glIntegration) { + qWarning("QXcbIntegration: Cannot create platform offscreen surface, neither GLX nor EGL are enabled"); + return Q_NULLPTR; + } + return glIntegration->createPlatformOffscreenSurface(surface); } bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const { switch (cap) { case ThreadedPixmaps: return true; -#if defined(XCB_USE_GLX) - case OpenGL: return m_connections.at(0)->hasGLX(); -#elif defined(XCB_USE_EGL) - case OpenGL: return true; -#else - case OpenGL: return false; -#endif -#if defined(XCB_USE_GLX) - case ThreadedOpenGL: return m_connections.at(0)->supportsThreadedRendering() && QGLXContext::supportsThreading(); -#else - case ThreadedOpenGL: return m_connections.at(0)->supportsThreadedRendering(); -#endif + case OpenGL: return m_connections.first()->glIntegration(); + case ThreadedOpenGL: return m_connections.at(0)->threadedEventHandling() + && m_connections.at(0)->glIntegration() + && m_connections.at(0)->glIntegration()->supportsThreadedOpenGL(); case WindowMasks: return true; case MultipleWindows: return true; case ForeignWindows: return true; diff --git a/src/plugins/platforms/xcb/qxcbintegration.h b/src/plugins/platforms/xcb/qxcbintegration.h index 5d73191097..150e3d57cb 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.h +++ b/src/plugins/platforms/xcb/qxcbintegration.h @@ -37,6 +37,8 @@ #include #include +#include "qxcbexport.h" + QT_BEGIN_NAMESPACE class QXcbConnection; @@ -44,7 +46,7 @@ class QAbstractEventDispatcher; class QXcbNativeInterface; class QXcbScreen; -class QXcbIntegration : public QPlatformIntegration +class Q_XCB_EXPORT QXcbIntegration : public QPlatformIntegration { public: QXcbIntegration(const QStringList ¶meters, int &argc, char **argv); diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp index 15ba7cc021..d5b8e6aead 100644 --- a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp +++ b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp @@ -46,12 +46,6 @@ #include #include -#if defined(XCB_USE_EGL) -#include "QtPlatformSupport/private/qeglplatformcontext_p.h" -#elif defined (XCB_USE_GLX) -#include "qglxintegration.h" -#endif - #include #ifdef XCB_USE_XLIB @@ -62,18 +56,17 @@ #include +#include "qxcbnativeinterfacehandler.h" + QT_BEGIN_NAMESPACE // return QXcbNativeInterface::ResourceType for the key. static int resourceType(const QByteArray &key) { static const QByteArray names[] = { // match QXcbNativeInterface::ResourceType - QByteArrayLiteral("display"), QByteArrayLiteral("egldisplay"), + QByteArrayLiteral("display"), QByteArrayLiteral("connection"), QByteArrayLiteral("screen"), - QByteArrayLiteral("eglcontext"), - QByteArrayLiteral("eglconfig"), - QByteArrayLiteral("glxconfig"), - QByteArrayLiteral("glxcontext"), QByteArrayLiteral("apptime"), + QByteArrayLiteral("apptime"), QByteArrayLiteral("appusertime"), QByteArrayLiteral("hintstyle"), QByteArrayLiteral("startupid"), QByteArrayLiteral("traywindow"), QByteArrayLiteral("gettimestamp"), QByteArrayLiteral("x11screen"), @@ -82,8 +75,6 @@ static int resourceType(const QByteArray &key) }; const QByteArray *end = names + sizeof(names) / sizeof(names[0]); const QByteArray *result = std::find(names, end, key); - if (result == end) - result = std::find(names, end, key.toLower()); return int(result - names); } @@ -222,8 +213,12 @@ void QXcbNativeInterface::setParentRelativeBackPixmap(const QWindow *qwindow) void *QXcbNativeInterface::nativeResourceForIntegration(const QByteArray &resourceString) { - void *result = 0; - switch (resourceType(resourceString)) { + QByteArray lowerCaseResource = resourceString.toLower(); + void *result = handlerNativeResourceForIntegration(lowerCaseResource); + if (result) + return result; + + switch (resourceType(lowerCaseResource)) { case StartupId: result = startupId(); break; @@ -242,32 +237,20 @@ void *QXcbNativeInterface::nativeResourceForIntegration(const QByteArray &resour void *QXcbNativeInterface::nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context) { - void *result = 0; - switch (resourceType(resourceString)) { - case EglContext: - result = eglContextForContext(context); - break; - case EglConfig: - result = eglConfigForContext(context); - break; - case GLXConfig: - result = glxConfigForContext(context); - break; - case GLXContext: - result = glxContextForContext(context); - break; - default: - break; - } - + QByteArray lowerCaseResource = resourceString.toLower(); + void *result = handlerNativeResourceForContext(lowerCaseResource, context); return result; } -void *QXcbNativeInterface::nativeResourceForScreen(const QByteArray &resource, QScreen *screen) +void *QXcbNativeInterface::nativeResourceForScreen(const QByteArray &resourceString, QScreen *screen) { - void *result = 0; + QByteArray lowerCaseResource = resourceString.toLower(); + void *result = handlerNativeResourceForScreen(lowerCaseResource ,screen); + if (result) + return result; + const QXcbScreen *xcbScreen = static_cast(screen->handle()); - switch (resourceType(resource)) { + switch (resourceType(lowerCaseResource)) { case Display: #ifdef XCB_USE_XLIB result = xcbScreen->connection()->xlib_display(); @@ -303,14 +286,15 @@ void *QXcbNativeInterface::nativeResourceForScreen(const QByteArray &resource, Q void *QXcbNativeInterface::nativeResourceForWindow(const QByteArray &resourceString, QWindow *window) { - void *result = 0; - switch (resourceType(resourceString)) { + QByteArray lowerCaseResource = resourceString.toLower(); + void *result = handlerNativeResourceForWindow(lowerCaseResource, window); + if (result) + return result; + + switch (resourceType(lowerCaseResource)) { case Display: result = displayForWindow(window); break; - case EglDisplay: - result = eglDisplayForWindow(window); - break; case Connection: result = connectionForWindow(window); break; @@ -324,17 +308,42 @@ void *QXcbNativeInterface::nativeResourceForWindow(const QByteArray &resourceStr return result; } +void *QXcbNativeInterface::nativeResourceForBackingStore(const QByteArray &resourceString, QBackingStore *backingStore) +{ + const QByteArray lowerCaseResource = resourceString.toLower(); + void *result = handlerNativeResourceForBackingStore(lowerCaseResource,backingStore); + return result; +} + + QPlatformNativeInterface::NativeResourceForIntegrationFunction QXcbNativeInterface::nativeResourceFunctionForIntegration(const QByteArray &resource) { - QByteArray lowerCaseResource = resource.toLower(); + const QByteArray lowerCaseResource = resource.toLower(); + QPlatformNativeInterface::NativeResourceForIntegrationFunction func = handlerNativeResourceFunctionForIntegration(lowerCaseResource); + if (func) + return func; + if (lowerCaseResource == "setstartupid") return NativeResourceForIntegrationFunction(setStartupId); return 0; } +QPlatformNativeInterface::NativeResourceForContextFunction QXcbNativeInterface::nativeResourceFunctionForContext(const QByteArray &resource) +{ + const QByteArray lowerCaseResource = resource.toLower(); + QPlatformNativeInterface::NativeResourceForContextFunction func = handlerNativeResourceFunctionForContext(lowerCaseResource); + if (func) + return func; + return Q_NULLPTR; +} + QPlatformNativeInterface::NativeResourceForScreenFunction QXcbNativeInterface::nativeResourceFunctionForScreen(const QByteArray &resource) { const QByteArray lowerCaseResource = resource.toLower(); + NativeResourceForScreenFunction func = handlerNativeResourceFunctionForScreen(lowerCaseResource); + if (func) + return func; + if (lowerCaseResource == "setapptime") return NativeResourceForScreenFunction(setAppTime); else if (lowerCaseResource == "setappusertime") @@ -342,8 +351,28 @@ QPlatformNativeInterface::NativeResourceForScreenFunction QXcbNativeInterface::n return 0; } +QPlatformNativeInterface::NativeResourceForWindowFunction QXcbNativeInterface::nativeResourceFunctionForWindow(const QByteArray &resource) +{ + const QByteArray lowerCaseResource = resource.toLower(); + NativeResourceForWindowFunction func = handlerNativeResourceFunctionForWindow(lowerCaseResource); + return func; +} + +QPlatformNativeInterface::NativeResourceForBackingStoreFunction QXcbNativeInterface::nativeResourceFunctionForBackingStore(const QByteArray &resource) +{ + const QByteArray lowerCaseResource = resource.toLower(); + NativeResourceForBackingStoreFunction func = handlerNativeResourceFunctionForBackingStore(resource); + return func; +} + QFunctionPointer QXcbNativeInterface::platformFunction(const QByteArray &function) const { + const QByteArray lowerCaseFunction = function.toLower(); + QFunctionPointer func = handlerPlatformFunction(lowerCaseFunction); + if (func) + return func; + + //case sensitive if (function == QXcbWindowFunctions::setWmWindowTypeIdentifier()) { return QFunctionPointer(QXcbWindow::setWmWindowTypeStatic); } @@ -411,15 +440,6 @@ void QXcbNativeInterface::setStartupId(const char *data) defaultConnection->setStartupId(startupId); } -QPlatformNativeInterface::NativeResourceForContextFunction QXcbNativeInterface::nativeResourceFunctionForContext(const QByteArray &resource) -{ - QByteArray lowerCaseResource = resource.toLower(); - if (lowerCaseResource == "get_egl_context") { - return eglContextForContext; - } - return 0; -} - QXcbScreen *QXcbNativeInterface::qPlatformScreenForWindow(QWindow *window) { QXcbScreen *screen; @@ -442,17 +462,6 @@ void *QXcbNativeInterface::displayForWindow(QWindow *window) #endif } -void *QXcbNativeInterface::eglDisplayForWindow(QWindow *window) -{ -#if defined(XCB_USE_EGL) - QXcbScreen *screen = qPlatformScreenForWindow(window); - return screen->connection()->egl_display(); -#else - Q_UNUSED(window) - return 0; -#endif -} - void *QXcbNativeInterface::connectionForWindow(QWindow *window) { QXcbScreen *screen = qPlatformScreenForWindow(window); @@ -465,54 +474,121 @@ void *QXcbNativeInterface::screenForWindow(QWindow *window) return screen->screen(); } -void * QXcbNativeInterface::eglContextForContext(QOpenGLContext *context) +void QXcbNativeInterface::addHandler(QXcbNativeInterfaceHandler *handler) { - Q_ASSERT(context); -#if defined(XCB_USE_EGL) - QEGLPlatformContext *eglPlatformContext = static_cast(context->handle()); - return eglPlatformContext->eglContext(); -#else - Q_UNUSED(context); - return 0; -#endif + m_handlers.removeAll(handler); + m_handlers.prepend(handler); } -void * QXcbNativeInterface::eglConfigForContext(QOpenGLContext *context) +void QXcbNativeInterface::removeHandler(QXcbNativeInterfaceHandler *handler) { - Q_ASSERT(context); -#if defined(XCB_USE_EGL) - QEGLPlatformContext *eglPlatformContext = static_cast(context->handle()); - return eglPlatformContext->eglConfig(); -#else - Q_UNUSED(context); - return 0; -#endif + m_handlers.removeAll(handler); } -void *QXcbNativeInterface::glxContextForContext(QOpenGLContext *context) +QPlatformNativeInterface::NativeResourceForIntegrationFunction QXcbNativeInterface::handlerNativeResourceFunctionForIntegration(const QByteArray &resource) const { - Q_ASSERT(context); -#if defined(XCB_USE_GLX) - QGLXContext *glxPlatformContext = static_cast(context->handle()); - return glxPlatformContext->glxContext(); -#else - Q_UNUSED(context); - return 0; -#endif + for (int i = 0; i < m_handlers.size(); i++) { + QXcbNativeInterfaceHandler *handler = m_handlers.at(i); + NativeResourceForIntegrationFunction result = handler->nativeResourceFunctionForIntegration(resource); + if (result) + return result; + } + return Q_NULLPTR; +} + +QPlatformNativeInterface::NativeResourceForContextFunction QXcbNativeInterface::handlerNativeResourceFunctionForContext(const QByteArray &resource) const +{ + for (int i = 0; i < m_handlers.size(); i++) { + QXcbNativeInterfaceHandler *handler = m_handlers.at(i); + NativeResourceForContextFunction result = handler->nativeResourceFunctionForContext(resource); + if (result) + return result; + } + return Q_NULLPTR; +} +QPlatformNativeInterface::NativeResourceForScreenFunction QXcbNativeInterface::handlerNativeResourceFunctionForScreen(const QByteArray &resource) const +{ + for (int i = 0; i < m_handlers.size(); i++) { + QXcbNativeInterfaceHandler *handler = m_handlers.at(i); + NativeResourceForScreenFunction result = handler->nativeResourceFunctionForScreen(resource); + if (result) + return result; + } + return Q_NULLPTR; } -void *QXcbNativeInterface::glxConfigForContext(QOpenGLContext *context) +QPlatformNativeInterface::NativeResourceForWindowFunction QXcbNativeInterface::handlerNativeResourceFunctionForWindow(const QByteArray &resource) const { - Q_ASSERT(context); -#if defined(XCB_USE_GLX) - QGLXContext *glxPlatformContext = static_cast(context->handle()); - return glxPlatformContext->glxConfig(); -#else - Q_UNUSED(context); - return 0; -#endif + for (int i = 0; i < m_handlers.size(); i++) { + QXcbNativeInterfaceHandler *handler = m_handlers.at(i); + NativeResourceForWindowFunction result = handler->nativeResourceFunctionForWindow(resource); + if (result) + return result; + } + return Q_NULLPTR; +} + +QPlatformNativeInterface::NativeResourceForBackingStoreFunction QXcbNativeInterface::handlerNativeResourceFunctionForBackingStore(const QByteArray &resource) const +{ + for (int i = 0; i < m_handlers.size(); i++) { + QXcbNativeInterfaceHandler *handler = m_handlers.at(i); + NativeResourceForBackingStoreFunction result = handler->nativeResourceFunctionForBackingStore(resource); + if (result) + return result; + } + return Q_NULLPTR; +} + +QFunctionPointer QXcbNativeInterface::handlerPlatformFunction(const QByteArray &function) const +{ + for (int i = 0; i < m_handlers.size(); i++) { + QXcbNativeInterfaceHandler *handler = m_handlers.at(i); + QFunctionPointer func = handler->platformFunction(function); + if (func) + return func; + } + return Q_NULLPTR; +} + +void *QXcbNativeInterface::handlerNativeResourceForIntegration(const QByteArray &resource) const +{ + NativeResourceForIntegrationFunction func = handlerNativeResourceFunctionForIntegration(resource); + if (func) + return func(); + return Q_NULLPTR; +} + +void *QXcbNativeInterface::handlerNativeResourceForContext(const QByteArray &resource, QOpenGLContext *context) const +{ + NativeResourceForContextFunction func = handlerNativeResourceFunctionForContext(resource); + if (func) + return func(context); + return Q_NULLPTR; +} + +void *QXcbNativeInterface::handlerNativeResourceForScreen(const QByteArray &resource, QScreen *screen) const +{ + NativeResourceForScreenFunction func = handlerNativeResourceFunctionForScreen(resource); + if (func) + return func(screen); + return Q_NULLPTR; +} +void *QXcbNativeInterface::handlerNativeResourceForWindow(const QByteArray &resource, QWindow *window) const +{ + NativeResourceForWindowFunction func = handlerNativeResourceFunctionForWindow(resource); + if (func) + return func(window); + return Q_NULLPTR; +} + +void *QXcbNativeInterface::handlerNativeResourceForBackingStore(const QByteArray &resource, QBackingStore *backingStore) const +{ + NativeResourceForBackingStoreFunction func = handlerNativeResourceFunctionForBackingStore(resource); + if (func) + return func(backingStore); + return Q_NULLPTR; } QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.h b/src/plugins/platforms/xcb/qxcbnativeinterface.h index 3ec96975f5..702aee63d8 100644 --- a/src/plugins/platforms/xcb/qxcbnativeinterface.h +++ b/src/plugins/platforms/xcb/qxcbnativeinterface.h @@ -39,25 +39,23 @@ #include +#include "qxcbexport.h" + QT_BEGIN_NAMESPACE class QWidget; class QXcbScreen; class QXcbConnection; +class QXcbNativeInterfaceHandler; -class QXcbNativeInterface : public QPlatformNativeInterface +class Q_XCB_EXPORT QXcbNativeInterface : public QPlatformNativeInterface { Q_OBJECT public: enum ResourceType { Display, - EglDisplay, Connection, Screen, - EglContext, - EglConfig, - GLXConfig, - GLXContext, AppTime, AppUserTime, ScreenHintStyle, @@ -76,17 +74,19 @@ public: void *nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context) Q_DECL_OVERRIDE; void *nativeResourceForScreen(const QByteArray &resource, QScreen *screen) Q_DECL_OVERRIDE; void *nativeResourceForWindow(const QByteArray &resourceString, QWindow *window) Q_DECL_OVERRIDE; + void *nativeResourceForBackingStore(const QByteArray &resource, QBackingStore *backingStore) Q_DECL_OVERRIDE; NativeResourceForIntegrationFunction nativeResourceFunctionForIntegration(const QByteArray &resource) Q_DECL_OVERRIDE; NativeResourceForContextFunction nativeResourceFunctionForContext(const QByteArray &resource) Q_DECL_OVERRIDE; NativeResourceForScreenFunction nativeResourceFunctionForScreen(const QByteArray &resource) Q_DECL_OVERRIDE; + NativeResourceForWindowFunction nativeResourceFunctionForWindow(const QByteArray &resource) Q_DECL_OVERRIDE; + NativeResourceForBackingStoreFunction nativeResourceFunctionForBackingStore(const QByteArray &resource) Q_DECL_OVERRIDE; QFunctionPointer platformFunction(const QByteArray &function) const Q_DECL_OVERRIDE; inline const QByteArray &genericEventFilterType() const { return m_genericEventFilterType; } void *displayForWindow(QWindow *window); - void *eglDisplayForWindow(QWindow *window); void *connectionForWindow(QWindow *window); void *screenForWindow(QWindow *window); void *appTime(const QXcbScreen *screen); @@ -98,10 +98,6 @@ public: static void setStartupId(const char *); static void setAppTime(QScreen *screen, xcb_timestamp_t time); static void setAppUserTime(QScreen *screen, xcb_timestamp_t time); - static void *eglContextForContext(QOpenGLContext *context); - static void *eglConfigForContext(QOpenGLContext *context); - static void *glxContextForContext(QOpenGLContext *context); - static void *glxConfigForContext(QOpenGLContext *context); Q_INVOKABLE void beep(); Q_INVOKABLE bool systemTrayAvailable(const QScreen *screen) const; @@ -111,6 +107,8 @@ public: Q_INVOKABLE bool requestSystemTrayWindowDock(const QWindow *window); Q_INVOKABLE QRect systemTrayWindowGlobalGeometry(const QWindow *window); + void addHandler(QXcbNativeInterfaceHandler *handler); + void removeHandler(QXcbNativeInterfaceHandler *handler); signals: void systemTrayWindowChanged(QScreen *screen); @@ -123,6 +121,19 @@ private: xcb_visualid_t m_systrayVisualId; static QXcbScreen *qPlatformScreenForWindow(QWindow *window); + + QList m_handlers; + NativeResourceForIntegrationFunction handlerNativeResourceFunctionForIntegration(const QByteArray &resource) const; + NativeResourceForContextFunction handlerNativeResourceFunctionForContext(const QByteArray &resource) const; + NativeResourceForScreenFunction handlerNativeResourceFunctionForScreen(const QByteArray &resource) const; + NativeResourceForWindowFunction handlerNativeResourceFunctionForWindow(const QByteArray &resource) const; + NativeResourceForBackingStoreFunction handlerNativeResourceFunctionForBackingStore(const QByteArray &resource) const; + QFunctionPointer handlerPlatformFunction(const QByteArray &function) const; + void *handlerNativeResourceForIntegration(const QByteArray &resource) const; + void *handlerNativeResourceForContext(const QByteArray &resource, QOpenGLContext *context) const; + void *handlerNativeResourceForScreen(const QByteArray &resource, QScreen *screen) const; + void *handlerNativeResourceForWindow(const QByteArray &resource, QWindow *window) const; + void *handlerNativeResourceForBackingStore(const QByteArray &resource, QBackingStore *backingStore) const; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h index 194b2ceb2f..4d0ae9847a 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.h +++ b/src/plugins/platforms/xcb/qxcbscreen.h @@ -41,6 +41,7 @@ #include #include "qxcbobject.h" +#include "qxcbscreen.h" #include @@ -50,7 +51,7 @@ class QXcbConnection; class QXcbCursor; class QXcbXSettings; -class QXcbScreen : public QXcbObject, public QPlatformScreen +class Q_XCB_EXPORT QXcbScreen : public QXcbObject, public QPlatformScreen { public: QXcbScreen(QXcbConnection *connection, xcb_screen_t *screen, diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index e1ccc3f086..54c32dd3c4 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -97,15 +97,6 @@ #include #endif -#if defined(XCB_USE_GLX) -#include "qglxintegration.h" -#include -#elif defined(XCB_USE_EGL) -#include "qxcbeglsurface.h" -#include -#include -#endif - #define XCOORD_MAX 16383 enum { defaultWindowWidth = 160, @@ -234,9 +225,6 @@ QXcbWindow::QXcbWindow(QWindow *window) , m_alertState(false) , m_netWmUserTimeWindow(XCB_NONE) , m_dirtyFrameMargins(false) -#if defined(XCB_USE_EGL) - , m_eglSurface(0) -#endif , m_lastWindowStateEvent(-1) , m_syncState(NoSyncNeeded) , m_pendingSyncRequest(0) @@ -244,11 +232,6 @@ QXcbWindow::QXcbWindow(QWindow *window) m_screen = static_cast(window->screen()->handle()); setConnection(m_screen->connection()); - - if (window->type() != Qt::ForeignWindow) - create(); - else - m_window = window->winId(); } #ifdef Q_COMPILER_CLASS_ENUM @@ -274,6 +257,11 @@ enum { void QXcbWindow::create() { + if (window()->type() == Qt::ForeignWindow) { + m_window = window()->winId(); + return; + } + destroy(); m_deferredExpose = false; @@ -337,27 +325,11 @@ void QXcbWindow::create() window()->setFormat(parentFormat); } } - m_format = window()->requestedFormat(); -#if (defined(XCB_USE_GLX) || defined(XCB_USE_EGL)) && defined(XCB_USE_XLIB) + resolveFormat(); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)) { -#if defined(XCB_USE_GLX) - XVisualInfo *visualInfo = qglx_findVisualInfo(DISPLAY_FROM_XCB(m_screen), m_screen->screenNumber(), &m_format); -#elif defined(XCB_USE_EGL) - EGLDisplay eglDisplay = connection()->egl_display(); - EGLConfig eglConfig = q_configFromGLFormat(eglDisplay, m_format, true); - m_format = q_glFormatFromConfig(eglDisplay, eglConfig, m_format); - - VisualID id = QXlibEglIntegration::getCompatibleVisualId(DISPLAY_FROM_XCB(this), eglDisplay, eglConfig); - - XVisualInfo visualInfoTemplate; - memset(&visualInfoTemplate, 0, sizeof(XVisualInfo)); - visualInfoTemplate.visualid = id; - - XVisualInfo *visualInfo; - int matchingCount = 0; - visualInfo = XGetVisualInfo(DISPLAY_FROM_XCB(this), VisualIDMask, &visualInfoTemplate, &matchingCount); -#endif //XCB_USE_GLX + XVisualInfo *visualInfo = static_cast(createVisual()); if (!visualInfo && window()->surfaceType() == QSurface::OpenGLSurface) qFatal("Could not initialize OpenGL"); @@ -365,6 +337,7 @@ void QXcbWindow::create() qWarning("Could not initialize OpenGL for RasterGLSurface, reverting to RasterSurface."); window()->setSurfaceType(QSurface::RasterSurface); } + if (visualInfo) { m_depth = visualInfo->depth; m_imageFormat = imageFormatForVisual(visualInfo->depth, visualInfo->red_mask, visualInfo->blue_mask); @@ -388,7 +361,6 @@ void QXcbWindow::create() } if (!m_window) -#endif //defined(XCB_USE_GLX) || defined(XCB_USE_EGL) { m_window = xcb_generate_id(xcb_connection()); m_visualId = m_screen->screen()->root_visual; @@ -449,12 +421,10 @@ void QXcbWindow::create() properties[propertyCount++] = atom(QXcbAtom::WM_TAKE_FOCUS); properties[propertyCount++] = atom(QXcbAtom::_NET_WM_PING); - m_usingSyncProtocol = m_screen->syncRequestSupported(); -#if !defined(XCB_USE_GLX) - // synced resize only implemented on GLX - if (window()->supportsOpenGL()) + if (m_screen->syncRequestSupported()) + m_usingSyncProtocol = supportsSyncProtocol(); + else m_usingSyncProtocol = false; -#endif if (m_usingSyncProtocol) properties[propertyCount++] = atom(QXcbAtom::_NET_WM_SYNC_REQUEST); @@ -576,11 +546,6 @@ void QXcbWindow::destroy() } m_mapped = false; -#if defined(XCB_USE_EGL) - delete m_eglSurface; - m_eglSurface = 0; -#endif - if (m_pendingSyncRequest) m_pendingSyncRequest->invalidate(); } @@ -1557,21 +1522,6 @@ QSurfaceFormat QXcbWindow::format() const return m_format; } -#if defined(XCB_USE_EGL) -QXcbEGLSurface *QXcbWindow::eglSurface() const -{ - if (!m_eglSurface) { - EGLDisplay display = connection()->egl_display(); - EGLConfig config = q_configFromGLFormat(display, window()->requestedFormat(), true); - EGLSurface surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType)m_window, 0); - - m_eglSurface = new QXcbEGLSurface(display, surface); - } - - return m_eglSurface; -} -#endif - void QXcbWindow::setWmWindowTypeStatic(QWindow *window, QXcbWindowFunctions::WmWindowTypes windowTypes) { if (window->handle()) diff --git a/src/plugins/platforms/xcb/qxcbwindow.h b/src/plugins/platforms/xcb/qxcbwindow.h index db194f0318..340070e882 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.h +++ b/src/plugins/platforms/xcb/qxcbwindow.h @@ -48,11 +48,10 @@ QT_BEGIN_NAMESPACE class QXcbScreen; -class QXcbEGLSurface; class QXcbSyncWindowRequest; class QIcon; -class QXcbWindow : public QXcbObject, public QXcbWindowEventListener, public QPlatformWindow +class Q_XCB_EXPORT QXcbWindow : public QXcbObject, public QXcbWindowEventListener, public QPlatformWindow { public: enum NetWmState { @@ -138,10 +137,6 @@ public: void updateNetWmUserTime(xcb_timestamp_t timestamp); -#if defined(XCB_USE_EGL) - QXcbEGLSurface *eglSurface() const; -#endif - static void setWmWindowTypeStatic(QWindow *window, QXcbWindowFunctions::WmWindowTypes windowTypes); QXcbWindowFunctions::WmWindowTypes wmWindowTypes() const; @@ -154,10 +149,16 @@ public: qreal devicePixelRatio() const Q_DECL_OVERRIDE; + virtual void create(); + virtual void destroy(); public Q_SLOTS: void updateSyncRequestCounter(); -private: +protected: + virtual void resolveFormat() { m_format = window()->requestedFormat(); } + virtual void *createVisual() { return Q_NULLPTR; } + virtual bool supportsSyncProtocol() { return !window()->supportsOpenGL(); } + void changeNetWmState(bool set, xcb_atom_t one, xcb_atom_t two = 0); NetWmStates netWmStates(); void setNetWmStates(NetWmStates); @@ -176,9 +177,6 @@ private: quint32 detail = 0, quint32 data1 = 0, quint32 data2 = 0); void handleXEmbedMessage(const xcb_client_message_event_t *event); - void create(); - void destroy(); - void show(); void hide(); @@ -215,10 +213,6 @@ private: mutable bool m_dirtyFrameMargins; mutable QMargins m_frameMargins; -#if defined(XCB_USE_EGL) - mutable QXcbEGLSurface *m_eglSurface; -#endif - QRegion m_exposeRegion; xcb_visualid_t m_visualId; diff --git a/src/plugins/platforms/xcb/xcb-plugin.pro b/src/plugins/platforms/xcb/xcb-plugin.pro index f14fcde73f..8dfe08d413 100644 --- a/src/plugins/platforms/xcb/xcb-plugin.pro +++ b/src/plugins/platforms/xcb/xcb-plugin.pro @@ -5,122 +5,10 @@ PLUGIN_CLASS_NAME = QXcbIntegrationPlugin !equals(TARGET, $$QT_DEFAULT_QPA_PLUGIN): PLUGIN_EXTENDS = - load(qt_plugin) -QT += core-private gui-private platformsupport-private +QT += core-private gui-private platformsupport-private xcb_qpa_lib-private SOURCES = \ - qxcbclipboard.cpp \ - qxcbconnection.cpp \ - qxcbintegration.cpp \ - qxcbkeyboard.cpp \ - qxcbmime.cpp \ - qxcbdrag.cpp \ - qxcbscreen.cpp \ - qxcbwindow.cpp \ - qxcbbackingstore.cpp \ - qxcbwmsupport.cpp \ - qxcbmain.cpp \ - qxcbnativeinterface.cpp \ - qxcbcursor.cpp \ - qxcbimage.cpp \ - qxcbxsettings.cpp \ - qxcbsystemtraytracker.cpp - -HEADERS = \ - qxcbclipboard.h \ - qxcbconnection.h \ - qxcbintegration.h \ - qxcbkeyboard.h \ - qxcbdrag.h \ - qxcbmime.h \ - qxcbobject.h \ - qxcbscreen.h \ - qxcbwindow.h \ - qxcbbackingstore.h \ - qxcbwmsupport.h \ - qxcbnativeinterface.h \ - qxcbcursor.h \ - qxcbimage.h \ - qxcbxsettings.h \ - qxcbsystemtraytracker.h - -LIBS += $$QMAKE_LIBS_DYNLOAD - -# needed by GLX, Xcursor ... -contains(QT_CONFIG, xcb-xlib) { - DEFINES += XCB_USE_XLIB - LIBS += -lX11 -lX11-xcb - - contains(QT_CONFIG, xinput2) { - DEFINES += XCB_USE_XINPUT2 - SOURCES += qxcbconnection_xi2.cpp - LIBS += -lXi - } -} - -# to support custom cursors with depth > 1 -contains(QT_CONFIG, xcb-render) { - DEFINES += XCB_USE_RENDER - LIBS += -lxcb-render -lxcb-render-util -} - -# build with session management support -contains(QT_CONFIG, xcb-sm) { - DEFINES += XCB_USE_SM - LIBS += -lSM -lICE - SOURCES += qxcbsessionmanager.cpp - HEADERS += qxcbsessionmanager.h -} - -contains(QT_CONFIG, opengl) { - contains(QT_CONFIG, xcb-xlib):!contains(QT_CONFIG, opengles2) { - DEFINES += XCB_USE_GLX - HEADERS += qglxintegration.h - SOURCES += qglxintegration.cpp - LIBS += $$QMAKE_LIBS_DYNLOAD - contains(QT_CONFIG, xcb-glx) { - DEFINES += XCB_HAS_XCB_GLX - LIBS += -lxcb-glx - } - } else:contains(QT_CONFIG, egl):contains(QT_CONFIG, egl_x11) { - DEFINES += XCB_USE_EGL - CONFIG += egl - HEADERS += qxcbeglsurface.h - - # EGL on MeeGo 1.2 Harmattan needs this macro to map EGLNativeDisplayType - # and other types to the correct X11 types - DEFINES += SUPPORT_X11 - } -} - -DEFINES += $$QMAKE_DEFINES_XCB -LIBS += $$QMAKE_LIBS_XCB -QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_XCB -QMAKE_CFLAGS += $$QMAKE_CFLAGS_XCB - -CONFIG += qpa/genericunixfontdatabase - -contains(QT_CONFIG, dbus) { -QT += dbus -LIBS += -ldbus-1 -} + qxcbmain.cpp OTHER_FILES += xcb.json README -contains(QT_CONFIG, xcb-qt) { - DEFINES += XCB_USE_RENDER - XCB_DIR = ../../../3rdparty/xcb - INCLUDEPATH += $$XCB_DIR/include $$XCB_DIR/sysinclude - LIBS += -lxcb -L$$OUT_PWD/xcb-static -lxcb-static -} else { - LIBS += -lxcb -lxcb-image -lxcb-icccm -lxcb-sync -lxcb-xfixes -lxcb-shm -lxcb-randr -lxcb-shape -lxcb-keysyms - !contains(DEFINES, QT_NO_XKB):LIBS += -lxcb-xkb -} - -# libxkbcommon -contains(QT_CONFIG, xkbcommon-qt): { - QT_CONFIG += use-xkbcommon-x11support - include(../../../3rdparty/xkbcommon.pri) -} else { - LIBS += $$QMAKE_LIBS_XKBCOMMON - QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_XKBCOMMON -} diff --git a/src/plugins/platforms/xcb/xcb.pro b/src/plugins/platforms/xcb/xcb.pro index dab0d8cb14..5915a59c0b 100644 --- a/src/plugins/platforms/xcb/xcb.pro +++ b/src/plugins/platforms/xcb/xcb.pro @@ -2,4 +2,7 @@ TEMPLATE = subdirs CONFIG += ordered contains(QT_CONFIG, xcb-qt):SUBDIRS+=xcb-static + +SUBDIRS += xcb_qpa_lib.pro SUBDIRS += xcb-plugin.pro +SUBDIRS += gl_integrations diff --git a/src/plugins/platforms/xcb/xcb_qpa_lib.pro b/src/plugins/platforms/xcb/xcb_qpa_lib.pro new file mode 100644 index 0000000000..770236acc7 --- /dev/null +++ b/src/plugins/platforms/xcb/xcb_qpa_lib.pro @@ -0,0 +1,111 @@ +TARGET = QtXcbQpa +CONFIG += no_module_headers internal_module + +MODULE_INCLUDES = \ + \$\$QT_MODULE_INCLUDE_BASE \ + \$\$QT_MODULE_INCLUDE_BASE/QtQGui +MODULE_PRIVATE_INCLUDES = \ + \$\$QT_MODULE_INCLUDE_BASE/QtGui/$$QT.gui.VERSION \ + \$\$QT_MODULE_INCLUDE_BASE/QtGui/$$QT.gui.VERSION/QtGui + +load(qt_module) + +QT += core-private gui-private platformsupport-private + +SOURCES = \ + qxcbclipboard.cpp \ + qxcbconnection.cpp \ + qxcbintegration.cpp \ + qxcbkeyboard.cpp \ + qxcbmime.cpp \ + qxcbdrag.cpp \ + qxcbscreen.cpp \ + qxcbwindow.cpp \ + qxcbbackingstore.cpp \ + qxcbwmsupport.cpp \ + qxcbnativeinterface.cpp \ + qxcbcursor.cpp \ + qxcbimage.cpp \ + qxcbxsettings.cpp \ + qxcbsystemtraytracker.cpp + +HEADERS = \ + qxcbclipboard.h \ + qxcbconnection.h \ + qxcbintegration.h \ + qxcbkeyboard.h \ + qxcbdrag.h \ + qxcbmime.h \ + qxcbobject.h \ + qxcbscreen.h \ + qxcbwindow.h \ + qxcbbackingstore.h \ + qxcbwmsupport.h \ + qxcbnativeinterface.h \ + qxcbcursor.h \ + qxcbimage.h \ + qxcbxsettings.h \ + qxcbsystemtraytracker.h + +LIBS += $$QMAKE_LIBS_DYNLOAD + +DEFINES += QT_BUILD_XCB_PLUGIN +# needed by Xcursor ... +contains(QT_CONFIG, xcb-xlib) { + DEFINES += XCB_USE_XLIB + LIBS += -lX11 -lX11-xcb + + contains(QT_CONFIG, xinput2) { + DEFINES += XCB_USE_XINPUT2 + SOURCES += qxcbconnection_xi2.cpp + LIBS += -lXi + } +} + +# to support custom cursors with depth > 1 +contains(QT_CONFIG, xcb-render) { + DEFINES += XCB_USE_RENDER + LIBS += -lxcb-render -lxcb-render-util +} + +# build with session management support +contains(QT_CONFIG, xcb-sm) { + DEFINES += XCB_USE_SM + LIBS += -lSM -lICE + SOURCES += qxcbsessionmanager.cpp + HEADERS += qxcbsessionmanager.h +} + +include(gl_integrations/gl_integrations.pri) + +DEFINES += $$QMAKE_DEFINES_XCB +LIBS += $$QMAKE_LIBS_XCB +QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_XCB +QMAKE_CFLAGS += $$QMAKE_CFLAGS_XCB + +CONFIG += qpa/genericunixfontdatabase + +contains(QT_CONFIG, dbus) { + QT += dbus + LIBS += -ldbus-1 +} + +contains(QT_CONFIG, xcb-qt) { + DEFINES += XCB_USE_RENDER + XCB_DIR = ../../../3rdparty/xcb + INCLUDEPATH += $$XCB_DIR/include $$XCB_DIR/sysinclude + LIBS += -lxcb -L$$OUT_PWD/xcb-static -lxcb-static +} else { + LIBS += -lxcb -lxcb-image -lxcb-icccm -lxcb-sync -lxcb-xfixes -lxcb-shm -lxcb-randr -lxcb-shape -lxcb-keysyms + !contains(DEFINES, QT_NO_XKB):LIBS += -lxcb-xkb +} + +# libxkbcommon +contains(QT_CONFIG, xkbcommon-qt) { + QT_CONFIG += use-xkbcommon-x11support + include(../../../3rdparty/xkbcommon.pri) +} else { + LIBS += $$QMAKE_LIBS_XKBCOMMON + QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_XKBCOMMON +} + -- cgit v1.2.3