Fixed platform plugin for "nogl" building
[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 <QtGui/QPlatformCursor>
58 #include <QtGui/QSurfaceFormat>
59 #include <QtGui/QOpenGLContext>
60
61 #include <private/qplatforminputcontextfactory_qpa_p.h>
62 #include <qplatformaccessibility_qpa.h>
63 #include <qplatforminputcontext_qpa.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 QPlatformNativeInterface * QWaylandIntegration::nativeInterface() const
91 {
92     return mNativeInterface;
93 }
94
95 bool QWaylandIntegration::hasCapability(QPlatformIntegration::Capability cap) const
96 {
97     switch (cap) {
98     case ThreadedPixmaps: return true;
99     case OpenGL:
100 #ifdef QT_WAYLAND_GL_SUPPORT
101         return true;
102 #else
103         return false;
104 #endif
105     case ThreadedOpenGL:
106         return hasCapability(OpenGL);
107     case BufferQueueingOpenGL:
108         return true;
109     default: return QPlatformIntegration::hasCapability(cap);
110     }
111 }
112
113 QPlatformWindow *QWaylandIntegration::createPlatformWindow(QWindow *window) const
114 {
115 #ifdef QT_WAYLAND_GL_SUPPORT
116     if (window->surfaceType() == QWindow::OpenGLSurface)
117         return mDisplay->eglIntegration()->createEglWindow(window);
118 #endif
119     return new QWaylandShmWindow(window);
120 }
121
122 QPlatformOpenGLContext *QWaylandIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
123 {
124 #ifdef QT_WAYLAND_GL_SUPPORT
125     return mDisplay->eglIntegration()->createPlatformOpenGLContext(context->format(), context->shareHandle());
126 #else
127     Q_UNUSED(context);
128     return 0;
129 #endif
130 }
131
132 QPlatformBackingStore *QWaylandIntegration::createPlatformBackingStore(QWindow *window) const
133 {
134     return new QWaylandShmBackingStore(window);
135 }
136
137 QAbstractEventDispatcher *QWaylandIntegration::guiThreadEventDispatcher() const
138 {
139     return mEventDispatcher;
140 }
141
142 QPlatformFontDatabase *QWaylandIntegration::fontDatabase() const
143 {
144     return mFontDb;
145 }
146
147 QPlatformClipboard *QWaylandIntegration::clipboard() const
148 {
149     return mClipboard;
150 }
151
152 QPlatformDrag *QWaylandIntegration::drag() const
153 {
154     return mDrag;
155 }
156
157 QPlatformInputContext *QWaylandIntegration::inputContext() const
158 {
159     return mInputContext;
160 }
161
162 QVariant QWaylandIntegration::styleHint(StyleHint hint) const
163 {
164 #ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT
165     if (hint == ShowIsFullScreen && mDisplay->windowManagerIntegration())
166         return mDisplay->windowManagerIntegration()->showIsFullScreen();
167 #endif
168     return QPlatformIntegration::styleHint(hint);
169 }
170
171 QPlatformAccessibility *QWaylandIntegration::accessibility() const
172 {
173     return mAccessibility;
174 }
175
176 QWaylandDisplay *QWaylandIntegration::display() const
177 {
178     return mDisplay;
179 }