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"
53 #include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h>
54 #include <QtPlatformSupport/private/qgenericunixfontdatabase_p.h>
55 #include <QtPlatformSupport/private/qgenericunixfontdatabase_p.h>
56 #include <QtPlatformSupport/private/qgenericunixservices_p.h>
60 //this has to be included before egl, since egl pulls in X headers
61 #include <QtGui/private/qguiapplication_p.h>
71 #include <private/qplatforminputcontextfactory_qpa_p.h>
72 #include <private/qgenericunixthemes_p.h>
73 #include <qplatforminputcontext_qpa.h>
75 #if defined(XCB_USE_GLX)
76 #include "qglxintegration.h"
77 #elif defined(XCB_USE_EGL)
78 #include "qxcbeglsurface.h"
79 #include <QtPlatformSupport/private/qeglplatformcontext_p.h>
82 #include <QtGui/QOpenGLContext>
83 #include <QtGui/QScreen>
84 #ifndef QT_NO_ACCESSIBILITY
85 #include <QtGui/QPlatformAccessibility>
90 QXcbIntegration::QXcbIntegration(const QStringList ¶meters)
91 : m_eventDispatcher(createUnixEventDispatcher()),
92 m_services(new QGenericUnixServices)
94 QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher);
99 m_nativeInterface.reset(new QXcbNativeInterface);
101 m_connections << new QXcbConnection(m_nativeInterface.data());
103 for (int i = 0; i < parameters.size() - 1; i += 2) {
105 qDebug() << "QXcbIntegration: Connecting to additional display: " << parameters.at(i) << parameters.at(i+1);
107 QString display = parameters.at(i) + ':' + parameters.at(i+1);
108 m_connections << new QXcbConnection(m_nativeInterface.data(), display.toAscii().constData());
111 foreach (QXcbConnection *connection, m_connections)
112 foreach (QXcbScreen *screen, connection->screens())
115 m_fontDatabase.reset(new QGenericUnixFontDatabase());
116 m_inputContext.reset(QPlatformInputContextFactory::create());
117 #ifndef QT_NO_ACCESSIBILITY
118 m_accessibility.reset(new QPlatformAccessibility());
122 QXcbIntegration::~QXcbIntegration()
124 qDeleteAll(m_connections);
127 QPlatformWindow *QXcbIntegration::createPlatformWindow(QWindow *window) const
129 return new QXcbWindow(window);
132 #if defined(XCB_USE_EGL)
133 class QEGLXcbPlatformContext : public QEGLPlatformContext
136 QEGLXcbPlatformContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share,
137 EGLDisplay display, QXcbConnection *c)
138 : QEGLPlatformContext(glFormat, share, display)
141 Q_XCB_NOOP(m_connection);
144 void swapBuffers(QPlatformSurface *surface)
146 Q_XCB_NOOP(m_connection);
147 QEGLPlatformContext::swapBuffers(surface);
148 Q_XCB_NOOP(m_connection);
151 bool makeCurrent(QPlatformSurface *surface)
153 Q_XCB_NOOP(m_connection);
154 bool ret = QEGLPlatformContext::makeCurrent(surface);
155 Q_XCB_NOOP(m_connection);
161 Q_XCB_NOOP(m_connection);
162 QEGLPlatformContext::doneCurrent();
163 Q_XCB_NOOP(m_connection);
166 EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface)
168 return static_cast<QXcbWindow *>(surface)->eglSurface()->surface();
172 QXcbConnection *m_connection;
177 QPlatformOpenGLContext *QXcbIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
179 QXcbScreen *screen = static_cast<QXcbScreen *>(context->screen()->handle());
180 #if defined(XCB_USE_GLX)
181 return new QGLXContext(screen, context->format(), context->shareHandle());
182 #elif defined(XCB_USE_EGL)
183 return new QEGLXcbPlatformContext(context->format(), context->shareHandle(),
184 screen->connection()->egl_display(), screen->connection());
185 #elif defined(XCB_USE_DRI2)
186 return new QDri2Context(context->format(), context->shareHandle());
188 qWarning("QXcbIntegration: Cannot create platform OpenGL context, none of GLX, EGL, or DRI2 are enabled");
193 QPlatformBackingStore *QXcbIntegration::createPlatformBackingStore(QWindow *window) const
195 return new QXcbBackingStore(window);
198 bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const
201 case ThreadedPixmaps: return true;
202 case OpenGL: return true;
203 case ThreadedOpenGL: return false;
204 default: return QPlatformIntegration::hasCapability(cap);
208 QAbstractEventDispatcher *QXcbIntegration::guiThreadEventDispatcher() const
210 return m_eventDispatcher;
213 void QXcbIntegration::moveToScreen(QWindow *window, int screen)
219 QPlatformFontDatabase *QXcbIntegration::fontDatabase() const
221 return m_fontDatabase.data();
224 QPlatformNativeInterface * QXcbIntegration::nativeInterface() const
226 return m_nativeInterface.data();
229 QPlatformClipboard *QXcbIntegration::clipboard() const
231 return m_connections.at(0)->clipboard();
234 QPlatformDrag *QXcbIntegration::drag() const
236 return m_connections.at(0)->drag();
239 QPlatformInputContext *QXcbIntegration::inputContext() const
241 return m_inputContext.data();
244 #ifndef QT_NO_ACCESSIBILITY
245 QPlatformAccessibility *QXcbIntegration::accessibility() const
247 return m_accessibility.data();
251 QPlatformServices *QXcbIntegration::services() const
253 return m_services.data();
256 QStringList QXcbIntegration::themeNames() const
258 return QGenericUnixTheme::themeNames();
261 QPlatformTheme *QXcbIntegration::createPlatformTheme(const QString &name) const
263 return QGenericUnixTheme::createUnixTheme(name);