Revert "Suppress QWindowSystemInterface inclusion warnings."
[profile/ivi/qtwayland.git] / src / plugins / platforms / wayland / qwaylandintegration.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 config.tests 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 "qwaylandintegration.h"
43
44 #include "qwaylanddisplay.h"
45 #include "qwaylandshmbackingstore.h"
46 #include "qwaylandshmwindow.h"
47 #include "qwaylandnativeinterface.h"
48 #include "qwaylandclipboard.h"
49 #include "qwaylanddnd.h"
50
51 #include "QtPlatformSupport/private/qgenericunixfontdatabase_p.h"
52 #include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h>
53
54 #include <QtGui/private/qguiapplication_p.h>
55
56 #include <QtGui/QWindowSystemInterface>
57 #include <qpa/qplatformcursor.h>
58 #include <QtGui/QSurfaceFormat>
59 #include <QtGui/QOpenGLContext>
60
61 #include <qpa/qplatforminputcontextfactory_p.h>
62 #include <qpa/qplatformaccessibility.h>
63 #include <qpa/qplatforminputcontext.h>
64
65 #ifdef QT_WAYLAND_GL_SUPPORT
66 #include "gl_integration/qwaylandglintegration.h"
67 #endif
68
69 #ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT
70 #include "windowmanager_integration/qwaylandwindowmanagerintegration.h"
71 #endif
72
73 QWaylandIntegration::QWaylandIntegration()
74     : mFontDb(new QGenericUnixFontDatabase())
75     , mEventDispatcher(createUnixEventDispatcher())
76     , mNativeInterface(new QWaylandNativeInterface(this))
77     , mAccessibility(new QPlatformAccessibility())
78 {
79     QGuiApplicationPrivate::instance()->setEventDispatcher(mEventDispatcher);
80     mDisplay = new QWaylandDisplay();
81     mClipboard = new QWaylandClipboard(mDisplay);
82     mDrag = new QWaylandDrag(mDisplay);
83
84     foreach (QPlatformScreen *screen, mDisplay->screens())
85         screenAdded(screen);
86
87     mInputContext = QPlatformInputContextFactory::create();
88 }
89
90 QWaylandIntegration::~QWaylandIntegration()
91 {
92     delete mDrag;
93     delete mClipboard;
94     delete mAccessibility;
95     delete mNativeInterface;
96     delete mDisplay;
97 }
98
99 QPlatformNativeInterface * QWaylandIntegration::nativeInterface() const
100 {
101     return mNativeInterface;
102 }
103
104 bool QWaylandIntegration::hasCapability(QPlatformIntegration::Capability cap) const
105 {
106     switch (cap) {
107     case ThreadedPixmaps: return true;
108     case OpenGL:
109 #ifdef QT_WAYLAND_GL_SUPPORT
110         return true;
111 #else
112         return false;
113 #endif
114     case ThreadedOpenGL:
115 #ifdef QT_WAYLAND_GL_SUPPORT
116         return mDisplay->eglIntegration()->supportsThreadedOpenGL();
117 #else
118         return false;
119 #endif
120     case BufferQueueingOpenGL:
121         return true;
122     default: return QPlatformIntegration::hasCapability(cap);
123     }
124 }
125
126 QPlatformWindow *QWaylandIntegration::createPlatformWindow(QWindow *window) const
127 {
128 #ifdef QT_WAYLAND_GL_SUPPORT
129     if (window->surfaceType() == QWindow::OpenGLSurface)
130         return mDisplay->eglIntegration()->createEglWindow(window);
131 #endif
132     return new QWaylandShmWindow(window);
133 }
134
135 QPlatformOpenGLContext *QWaylandIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
136 {
137 #ifdef QT_WAYLAND_GL_SUPPORT
138     return mDisplay->eglIntegration()->createPlatformOpenGLContext(context->format(), context->shareHandle());
139 #else
140     Q_UNUSED(context);
141     return 0;
142 #endif
143 }
144
145 QPlatformBackingStore *QWaylandIntegration::createPlatformBackingStore(QWindow *window) const
146 {
147     return new QWaylandShmBackingStore(window);
148 }
149
150 QAbstractEventDispatcher *QWaylandIntegration::guiThreadEventDispatcher() const
151 {
152     return mEventDispatcher;
153 }
154
155 QPlatformFontDatabase *QWaylandIntegration::fontDatabase() const
156 {
157     return mFontDb;
158 }
159
160 QPlatformClipboard *QWaylandIntegration::clipboard() const
161 {
162     return mClipboard;
163 }
164
165 QPlatformDrag *QWaylandIntegration::drag() const
166 {
167     return mDrag;
168 }
169
170 QPlatformInputContext *QWaylandIntegration::inputContext() const
171 {
172     return mInputContext;
173 }
174
175 QVariant QWaylandIntegration::styleHint(StyleHint hint) const
176 {
177 #ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT
178     if (hint == ShowIsFullScreen && mDisplay->windowManagerIntegration())
179         return mDisplay->windowManagerIntegration()->showIsFullScreen();
180 #endif
181     return QPlatformIntegration::styleHint(hint);
182 }
183
184 QPlatformAccessibility *QWaylandIntegration::accessibility() const
185 {
186     return mAccessibility;
187 }
188
189 QPlatformServices *QWaylandIntegration::services() const
190 {
191 #ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT
192     return mDisplay->windowManagerIntegration();
193 #else
194     return QWaylandIntegration::services();
195 #endif
196 }
197
198 QWaylandDisplay *QWaylandIntegration::display() const
199 {
200     return mDisplay;
201 }