Fix xcb plugin compilation for -qconfig large
[profile/ivi/qtbase.git] / src / plugins / platforms / xcb / qxcbintegration.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
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"
49 #include "qxcbdrag.h"
50
51 #include <xcb/xcb.h>
52
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>
57
58 #include <stdio.h>
59
60 //this has to be included before egl, since egl pulls in X headers
61 #include <QtGui/private/qguiapplication_p.h>
62
63 #ifdef XCB_USE_EGL
64 #include <EGL/egl.h>
65 #endif
66
67 #ifdef XCB_USE_XLIB
68 #include <X11/Xlib.h>
69 #endif
70
71 #include <qpa/qplatforminputcontextfactory_p.h>
72 #include <private/qgenericunixthemes_p.h>
73 #include <qpa/qplatforminputcontext.h>
74
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>
80 #endif
81
82 #include <QtGui/QOpenGLContext>
83 #include <QtGui/QScreen>
84 #ifndef QT_NO_ACCESSIBILITY
85 #include <qpa/qplatformaccessibility.h>
86 #endif
87
88 QT_BEGIN_NAMESPACE
89
90 QXcbIntegration::QXcbIntegration(const QStringList &parameters)
91     : m_eventDispatcher(createUnixEventDispatcher()),
92       m_services(new QGenericUnixServices)
93 {
94     QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher);
95
96 #ifdef XCB_USE_XLIB
97     XInitThreads();
98 #endif
99     m_nativeInterface.reset(new QXcbNativeInterface);
100
101     m_connections << new QXcbConnection(m_nativeInterface.data());
102
103     for (int i = 0; i < parameters.size() - 1; i += 2) {
104 #ifdef Q_XCB_DEBUG
105         qDebug() << "QXcbIntegration: Connecting to additional display: " << parameters.at(i) << parameters.at(i+1);
106 #endif
107         QString display = parameters.at(i) + ':' + parameters.at(i+1);
108         m_connections << new QXcbConnection(m_nativeInterface.data(), display.toLatin1().constData());
109     }
110
111     foreach (QXcbConnection *connection, m_connections)
112         foreach (QXcbScreen *screen, connection->screens())
113             screenAdded(screen);
114
115     m_fontDatabase.reset(new QGenericUnixFontDatabase());
116     m_inputContext.reset(QPlatformInputContextFactory::create());
117 #ifndef QT_NO_ACCESSIBILITY
118     m_accessibility.reset(new QPlatformAccessibility());
119 #endif
120 }
121
122 QXcbIntegration::~QXcbIntegration()
123 {
124     qDeleteAll(m_connections);
125 }
126
127 QPlatformWindow *QXcbIntegration::createPlatformWindow(QWindow *window) const
128 {
129     return new QXcbWindow(window);
130 }
131
132 #if defined(XCB_USE_EGL)
133 class QEGLXcbPlatformContext : public QEGLPlatformContext
134 {
135 public:
136     QEGLXcbPlatformContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share,
137                            EGLDisplay display, QXcbConnection *c)
138         : QEGLPlatformContext(glFormat, share, display)
139         , m_connection(c)
140     {
141         Q_XCB_NOOP(m_connection);
142     }
143
144     void swapBuffers(QPlatformSurface *surface)
145     {
146         Q_XCB_NOOP(m_connection);
147         QEGLPlatformContext::swapBuffers(surface);
148         Q_XCB_NOOP(m_connection);
149     }
150
151     bool makeCurrent(QPlatformSurface *surface)
152     {
153         Q_XCB_NOOP(m_connection);
154         bool ret = QEGLPlatformContext::makeCurrent(surface);
155         Q_XCB_NOOP(m_connection);
156         return ret;
157     }
158
159     void doneCurrent()
160     {
161         Q_XCB_NOOP(m_connection);
162         QEGLPlatformContext::doneCurrent();
163         Q_XCB_NOOP(m_connection);
164     }
165
166     EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface)
167     {
168         return static_cast<QXcbWindow *>(surface)->eglSurface()->surface();
169     }
170
171 private:
172     QXcbConnection *m_connection;
173 };
174 #endif
175
176 #ifndef QT_NO_OPENGL
177 QPlatformOpenGLContext *QXcbIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
178 {
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());
187 #endif
188     qWarning("QXcbIntegration: Cannot create platform OpenGL context, none of GLX, EGL, or DRI2 are enabled");
189     return 0;
190 }
191 #endif
192
193 QPlatformBackingStore *QXcbIntegration::createPlatformBackingStore(QWindow *window) const
194 {
195     return new QXcbBackingStore(window);
196 }
197
198 bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const
199 {
200     switch (cap) {
201     case ThreadedPixmaps: return true;
202     case OpenGL: return true;
203     case ThreadedOpenGL: return false;
204     default: return QPlatformIntegration::hasCapability(cap);
205     }
206 }
207
208 QAbstractEventDispatcher *QXcbIntegration::guiThreadEventDispatcher() const
209 {
210     return m_eventDispatcher;
211 }
212
213 void QXcbIntegration::moveToScreen(QWindow *window, int screen)
214 {
215     Q_UNUSED(window);
216     Q_UNUSED(screen);
217 }
218
219 QPlatformFontDatabase *QXcbIntegration::fontDatabase() const
220 {
221     return m_fontDatabase.data();
222 }
223
224 QPlatformNativeInterface * QXcbIntegration::nativeInterface() const
225 {
226     return m_nativeInterface.data();
227 }
228
229 #ifndef QT_NO_CLIPBOARD
230 QPlatformClipboard *QXcbIntegration::clipboard() const
231 {
232     return m_connections.at(0)->clipboard();
233 }
234 #endif
235
236 #ifndef QT_NO_DRAGANDDROP
237 QPlatformDrag *QXcbIntegration::drag() const
238 {
239     return m_connections.at(0)->drag();
240 }
241 #endif
242
243 QPlatformInputContext *QXcbIntegration::inputContext() const
244 {
245     return m_inputContext.data();
246 }
247
248 #ifndef QT_NO_ACCESSIBILITY
249 QPlatformAccessibility *QXcbIntegration::accessibility() const
250 {
251     return m_accessibility.data();
252 }
253 #endif
254
255 QPlatformServices *QXcbIntegration::services() const
256 {
257     return m_services.data();
258 }
259
260 QStringList QXcbIntegration::themeNames() const
261 {
262     return QGenericUnixTheme::themeNames();
263 }
264
265 QPlatformTheme *QXcbIntegration::createPlatformTheme(const QString &name) const
266 {
267     return QGenericUnixTheme::createUnixTheme(name);
268 }
269
270 QT_END_NAMESPACE