1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the plugins of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #include "qxcbintegration.h"
43 #include "qxcbconnection.h"
44 #include "qxcbscreen.h"
45 #include "qxcbwindow.h"
46 #include "qxcbcursor.h"
47 #include "qxcbkeyboard.h"
48 #include "qxcbbackingstore.h"
49 #include "qxcbnativeinterface.h"
50 #include "qxcbclipboard.h"
55 #include <QtPlatformSupport/private/qgenericunixeventdispatcher_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 <qpa/qplatforminputcontextfactory_p.h>
73 #include <private/qgenericunixthemes_p.h>
74 #include <qpa/qplatforminputcontext.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 <qpa/qplatformaccessibility.h>
87 #include "../../../platformsupport/linuxaccessibility/bridge_p.h"
92 QXcbIntegration::QXcbIntegration(const QStringList ¶meters)
93 : m_eventDispatcher(createUnixEventDispatcher())
94 , m_services(new QGenericUnixServices)
96 QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher);
101 m_nativeInterface.reset(new QXcbNativeInterface);
103 m_connections << new QXcbConnection(m_nativeInterface.data());
105 for (int i = 0; i < parameters.size() - 1; i += 2) {
107 qDebug() << "QXcbIntegration: Connecting to additional display: " << parameters.at(i) << parameters.at(i+1);
109 QString display = parameters.at(i) + ':' + parameters.at(i+1);
110 m_connections << new QXcbConnection(m_nativeInterface.data(), display.toLatin1().constData());
113 m_fontDatabase.reset(new QGenericUnixFontDatabase());
114 m_inputContext.reset(QPlatformInputContextFactory::create());
115 #ifndef QT_NO_ACCESSIBILITY
116 m_accessibility.reset(new QSpiAccessibleBridge());
120 QXcbIntegration::~QXcbIntegration()
122 #if !defined(QT_NO_OPENGL) && defined(XCB_USE_GLX)
123 qDeleteAll(m_defaultContextInfos);
125 qDeleteAll(m_connections);
128 QPlatformWindow *QXcbIntegration::createPlatformWindow(QWindow *window) const
130 return new QXcbWindow(window);
133 #if defined(XCB_USE_EGL)
134 class QEGLXcbPlatformContext : public QEGLPlatformContext
137 QEGLXcbPlatformContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share,
138 EGLDisplay display, QXcbConnection *c)
139 : QEGLPlatformContext(glFormat, share, display)
142 Q_XCB_NOOP(m_connection);
145 void swapBuffers(QPlatformSurface *surface)
147 Q_XCB_NOOP(m_connection);
148 QEGLPlatformContext::swapBuffers(surface);
149 Q_XCB_NOOP(m_connection);
152 bool makeCurrent(QPlatformSurface *surface)
154 Q_XCB_NOOP(m_connection);
155 bool ret = QEGLPlatformContext::makeCurrent(surface);
156 Q_XCB_NOOP(m_connection);
162 Q_XCB_NOOP(m_connection);
163 QEGLPlatformContext::doneCurrent();
164 Q_XCB_NOOP(m_connection);
167 EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface)
169 return static_cast<QXcbWindow *>(surface)->eglSurface()->surface();
173 QXcbConnection *m_connection;
178 QPlatformOpenGLContext *QXcbIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
180 QXcbScreen *screen = static_cast<QXcbScreen *>(context->screen()->handle());
181 #if defined(XCB_USE_GLX)
182 QOpenGLDefaultContextInfo *defaultContextInfo;
183 if (m_defaultContextInfos.contains(screen)) {
184 defaultContextInfo = m_defaultContextInfos.value(screen);
186 defaultContextInfo = QOpenGLDefaultContextInfo::create(screen);
187 m_defaultContextInfos.insert(screen, defaultContextInfo);
189 return new QGLXContext(screen, context->format(), context->shareHandle(), defaultContextInfo);
190 #elif defined(XCB_USE_EGL)
191 return new QEGLXcbPlatformContext(context->format(), context->shareHandle(),
192 screen->connection()->egl_display(), screen->connection());
195 qWarning("QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled");
201 QPlatformBackingStore *QXcbIntegration::createPlatformBackingStore(QWindow *window) const
203 return new QXcbBackingStore(window);
206 bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const
209 case ThreadedPixmaps: return true;
210 #if defined(XCB_USE_GLX)
211 case OpenGL: return m_connections.at(0)->hasGLX();
212 #elif defined(XCB_USE_EGL)
213 case OpenGL: return true;
215 case OpenGL: return false;
217 case ThreadedOpenGL: return m_connections.at(0)->supportsThreadedRendering();
218 case WindowMasks: return true;
219 case MultipleWindows: return true;
220 default: return QPlatformIntegration::hasCapability(cap);
224 QAbstractEventDispatcher *QXcbIntegration::guiThreadEventDispatcher() const
226 return m_eventDispatcher;
229 void QXcbIntegration::moveToScreen(QWindow *window, int screen)
235 QPlatformFontDatabase *QXcbIntegration::fontDatabase() const
237 return m_fontDatabase.data();
240 QPlatformNativeInterface * QXcbIntegration::nativeInterface() const
242 return m_nativeInterface.data();
245 #ifndef QT_NO_CLIPBOARD
246 QPlatformClipboard *QXcbIntegration::clipboard() const
248 return m_connections.at(0)->clipboard();
252 #ifndef QT_NO_DRAGANDDROP
253 QPlatformDrag *QXcbIntegration::drag() const
255 return m_connections.at(0)->drag();
259 QPlatformInputContext *QXcbIntegration::inputContext() const
261 return m_inputContext.data();
264 #ifndef QT_NO_ACCESSIBILITY
265 QPlatformAccessibility *QXcbIntegration::accessibility() const
267 return m_accessibility.data();
271 QPlatformServices *QXcbIntegration::services() const
273 return m_services.data();
276 Qt::KeyboardModifiers QXcbIntegration::queryKeyboardModifiers() const
279 QXcbConnection *conn = m_connections.at(0);
280 QXcbCursor::queryPointer(conn, 0, 0, &keybMask);
281 return conn->keyboard()->translateModifiers(keybMask);
284 QStringList QXcbIntegration::themeNames() const
286 return QGenericUnixTheme::themeNames();
289 QPlatformTheme *QXcbIntegration::createPlatformTheme(const QString &name) const
291 return QGenericUnixTheme::createUnixTheme(name);
295 Called by QXcbConnection prior to a QQnxScreen being deleted.
297 Destroys and cleans up any default OpenGL context info for this screen.
299 void QXcbIntegration::removeDefaultOpenGLContextInfo(QXcbScreen *screen)
301 #if !defined(QT_NO_OPENGL) && defined(XCB_USE_GLX)
302 if (!m_defaultContextInfos.contains(screen))
304 QOpenGLDefaultContextInfo* info = m_defaultContextInfos.take(screen);