1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the plugins of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qxcbintegration.h"
43 #include "qxcbconnection.h"
44 #include "qxcbscreen.h"
45 #include "qxcbwindow.h"
46 #include "qxcbbackingstore.h"
47 #include "qxcbnativeinterface.h"
48 #include "qxcbclipboard.h"
50 #include "qxcbsharedgraphicscache.h"
54 #include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h>
55 #include <QtPlatformSupport/private/qgenericunixfontdatabase_p.h>
56 #include <QtPlatformSupport/private/qgenericunixfontdatabase_p.h>
57 #include <QtPlatformSupport/private/qgenericunixservices_p.h>
61 //this has to be included before egl, since egl pulls in X headers
62 #include <QtGui/private/qguiapplication_p.h>
72 #include <private/qplatforminputcontextfactory_qpa_p.h>
73 #include <private/qgenericunixthemes_p.h>
74 #include <qplatforminputcontext_qpa.h>
76 #if defined(XCB_USE_GLX)
77 #include "qglxintegration.h"
78 #elif defined(XCB_USE_EGL)
79 #include "qxcbeglsurface.h"
80 #include <QtPlatformSupport/private/qeglplatformcontext_p.h>
83 #include <QtGui/QOpenGLContext>
84 #include <QtGui/QScreen>
85 #ifndef QT_NO_ACCESSIBILITY
86 #include <QtGui/QPlatformAccessibility>
91 QXcbIntegration::QXcbIntegration(const QStringList ¶meters)
92 : m_eventDispatcher(createUnixEventDispatcher()),
93 m_services(new QGenericUnixServices)
95 QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher);
100 m_nativeInterface.reset(new QXcbNativeInterface);
102 m_connections << new QXcbConnection(m_nativeInterface.data());
104 for (int i = 0; i < parameters.size() - 1; i += 2) {
106 qDebug() << "QXcbIntegration: Connecting to additional display: " << parameters.at(i) << parameters.at(i+1);
108 QString display = parameters.at(i) + ':' + parameters.at(i+1);
109 m_connections << new QXcbConnection(m_nativeInterface.data(), display.toAscii().constData());
112 foreach (QXcbConnection *connection, m_connections)
113 foreach (QXcbScreen *screen, connection->screens())
116 m_fontDatabase.reset(new QGenericUnixFontDatabase());
117 m_inputContext.reset(QPlatformInputContextFactory::create());
118 #ifndef QT_NO_ACCESSIBILITY
119 m_accessibility.reset(new QPlatformAccessibility());
122 #if defined(QT_USE_XCB_SHARED_GRAPHICS_CACHE)
123 m_sharedGraphicsCache.reset(new QXcbSharedGraphicsCache);
127 QXcbIntegration::~QXcbIntegration()
129 qDeleteAll(m_connections);
132 QPlatformWindow *QXcbIntegration::createPlatformWindow(QWindow *window) const
134 return new QXcbWindow(window);
137 #if defined(XCB_USE_EGL)
138 class QEGLXcbPlatformContext : public QEGLPlatformContext
141 QEGLXcbPlatformContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share,
142 EGLDisplay display, QXcbConnection *c)
143 : QEGLPlatformContext(glFormat, share, display)
146 Q_XCB_NOOP(m_connection);
149 void swapBuffers(QPlatformSurface *surface)
151 Q_XCB_NOOP(m_connection);
152 QEGLPlatformContext::swapBuffers(surface);
153 Q_XCB_NOOP(m_connection);
156 bool makeCurrent(QPlatformSurface *surface)
158 Q_XCB_NOOP(m_connection);
159 bool ret = QEGLPlatformContext::makeCurrent(surface);
160 Q_XCB_NOOP(m_connection);
166 Q_XCB_NOOP(m_connection);
167 QEGLPlatformContext::doneCurrent();
168 Q_XCB_NOOP(m_connection);
171 EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface)
173 return static_cast<QXcbWindow *>(surface)->eglSurface()->surface();
177 QXcbConnection *m_connection;
182 QPlatformOpenGLContext *QXcbIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
184 QXcbScreen *screen = static_cast<QXcbScreen *>(context->screen()->handle());
185 #if defined(XCB_USE_GLX)
186 return new QGLXContext(screen, context->format(), context->shareHandle());
187 #elif defined(XCB_USE_EGL)
188 return new QEGLXcbPlatformContext(context->format(), context->shareHandle(),
189 screen->connection()->egl_display(), screen->connection());
190 #elif defined(XCB_USE_DRI2)
191 return new QDri2Context(context->format(), context->shareHandle());
193 qWarning("QXcbIntegration: Cannot create platform OpenGL context, none of GLX, EGL, or DRI2 are enabled");
198 QPlatformBackingStore *QXcbIntegration::createPlatformBackingStore(QWindow *window) const
200 return new QXcbBackingStore(window);
203 bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const
206 #if defined(QT_USE_XCB_SHARED_GRAPHICS_CACHE)
207 case SharedGraphicsCache: return true;
210 case ThreadedPixmaps: return true;
211 case OpenGL: return true;
212 case ThreadedOpenGL: return false;
213 default: return QPlatformIntegration::hasCapability(cap);
217 QAbstractEventDispatcher *QXcbIntegration::guiThreadEventDispatcher() const
219 return m_eventDispatcher;
222 void QXcbIntegration::moveToScreen(QWindow *window, int screen)
228 QPlatformFontDatabase *QXcbIntegration::fontDatabase() const
230 return m_fontDatabase.data();
233 QPlatformNativeInterface * QXcbIntegration::nativeInterface() const
235 return m_nativeInterface.data();
238 QPlatformClipboard *QXcbIntegration::clipboard() const
240 return m_connections.at(0)->clipboard();
243 QPlatformDrag *QXcbIntegration::drag() const
245 return m_connections.at(0)->drag();
248 QPlatformInputContext *QXcbIntegration::inputContext() const
250 return m_inputContext.data();
253 #ifndef QT_NO_ACCESSIBILITY
254 QPlatformAccessibility *QXcbIntegration::accessibility() const
256 return m_accessibility.data();
260 #if defined(QT_USE_XCB_SHARED_GRAPHICS_CACHE)
261 static bool sharedGraphicsCacheDisabled()
263 static const char *environmentVariable = "QT_DISABLE_SHARED_CACHE";
264 static bool cacheDisabled = !qgetenv(environmentVariable).isEmpty()
265 && qgetenv(environmentVariable).toInt() != 0;
266 return cacheDisabled;
269 QPlatformSharedGraphicsCache *QXcbIntegration::createPlatformSharedGraphicsCache(const char *cacheId) const
273 if (sharedGraphicsCacheDisabled())
276 return m_sharedGraphicsCache.data();
280 QPlatformServices *QXcbIntegration::services() const
282 return m_services.data();
285 QStringList QXcbIntegration::themeNames() const
287 return QGenericUnixTheme::themeNames();
290 QPlatformTheme *QXcbIntegration::createPlatformTheme(const QString &name) const
292 return QGenericUnixTheme::createUnixTheme(name);