Add PLUGIN_CLASS_NAME to qtbase plugins
[profile/ivi/qtbase.git] / src / plugins / platforms / eglfs / qeglfsintegration.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
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.
16 **
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.
24 **
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.
28 **
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.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qeglfsintegration.h"
43
44 #include "qeglfswindow.h"
45 #include "qeglfsbackingstore.h"
46 #include "qeglfshooks.h"
47
48 #include <QtGui/private/qguiapplication_p.h>
49
50 #include <QtPlatformSupport/private/qgenericunixfontdatabase_p.h>
51 #include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h>
52 #include <QtPlatformSupport/private/qeglplatformcontext_p.h>
53
54 #if !defined(QT_NO_EVDEV)
55 #include <QtPlatformSupport/private/qevdevmousemanager_p.h>
56 #include <QtPlatformSupport/private/qevdevkeyboardmanager_p.h>
57 #include <QtPlatformSupport/private/qevdevtouch_p.h>
58 #endif
59
60 #include <qpa/qplatformwindow.h>
61 #include <QtGui/QSurfaceFormat>
62 #include <QtGui/QOpenGLContext>
63 #include <QtGui/QScreen>
64 #include <qpa/qplatformcursor.h>
65
66 #include "qeglfscontext.h"
67
68 #include <EGL/egl.h>
69
70 QT_BEGIN_NAMESPACE
71
72 QEglFSIntegration::QEglFSIntegration()
73     : mEventDispatcher(createUnixEventDispatcher()), mFontDb(new QGenericUnixFontDatabase())
74 {
75     QGuiApplicationPrivate::instance()->setEventDispatcher(mEventDispatcher);
76
77 #if !defined(QT_NO_EVDEV)
78     new QEvdevKeyboardManager(QLatin1String("EvdevKeyboard"), QString() /* spec */, this);
79     new QEvdevMouseManager(QLatin1String("EvdevMouse"), QString() /* spec */, this);
80     new QEvdevTouchScreenHandlerThread(QString() /* spec */, this);
81 #endif
82
83     hooks->platformInit();
84
85     EGLint major, minor;
86
87     if (!eglBindAPI(EGL_OPENGL_ES_API)) {
88         qWarning("Could not bind GL_ES API\n");
89         qFatal("EGL error");
90     }
91
92     mDisplay = eglGetDisplay(hooks ? hooks->platformDisplay() : EGL_DEFAULT_DISPLAY);
93     if (mDisplay == EGL_NO_DISPLAY) {
94         qWarning("Could not open egl display\n");
95         qFatal("EGL error");
96     }
97
98     if (!eglInitialize(mDisplay, &major, &minor)) {
99         qWarning("Could not initialize egl display\n");
100         qFatal("EGL error");
101     }
102
103     int swapInterval = 1;
104     QByteArray swapIntervalString = qgetenv("QT_QPA_EGLFS_SWAPINTERVAL");
105     if (!swapIntervalString.isEmpty()) {
106         bool ok;
107         swapInterval = swapIntervalString.toInt(&ok);
108         if (!ok)
109             swapInterval = 1;
110     }
111     eglSwapInterval(mDisplay, swapInterval);
112
113     mScreen = new QEglFSScreen(mDisplay);
114     screenAdded(mScreen);
115 }
116
117 QEglFSIntegration::~QEglFSIntegration()
118 {
119     delete mScreen;
120
121     eglTerminate(mDisplay);
122     hooks->platformDestroy();
123 }
124
125 bool QEglFSIntegration::hasCapability(QPlatformIntegration::Capability cap) const
126 {
127     // We assume that devices will have more and not less capabilities
128     if (hooks && hooks->hasCapability(cap))
129         return true;
130
131     switch (cap) {
132     case ThreadedPixmaps: return true;
133     case OpenGL: return true;
134     case ThreadedOpenGL: return true;
135     default: return QPlatformIntegration::hasCapability(cap);
136     }
137 }
138
139 QPlatformWindow *QEglFSIntegration::createPlatformWindow(QWindow *window) const
140 {
141     QPlatformWindow *w = new QEglFSWindow(window);
142     w->requestActivateWindow();
143     return w;
144 }
145
146 QPlatformBackingStore *QEglFSIntegration::createPlatformBackingStore(QWindow *window) const
147 {
148     return new QEglFSBackingStore(window);
149 }
150
151 QPlatformOpenGLContext *QEglFSIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
152 {
153     return new QEglFSContext(context->format(), 0 /*share*/, mDisplay);
154 }
155
156 QPlatformFontDatabase *QEglFSIntegration::fontDatabase() const
157 {
158     return mFontDb;
159 }
160
161 QAbstractEventDispatcher *QEglFSIntegration::guiThreadEventDispatcher() const
162 {
163     return mEventDispatcher;
164 }
165
166 QVariant QEglFSIntegration::styleHint(QPlatformIntegration::StyleHint hint) const
167 {
168     if (hint == QPlatformIntegration::ShowIsFullScreen)
169         return true;
170
171     return QPlatformIntegration::styleHint(hint);
172 }
173
174 QPlatformNativeInterface *QEglFSIntegration::nativeInterface() const
175 {
176     return const_cast<QEglFSIntegration *>(this);
177 }
178
179 void *QEglFSIntegration::nativeResourceForIntegration(const QByteArray &resource)
180 {
181     QByteArray lowerCaseResource = resource.toLower();
182
183     if (lowerCaseResource == "egldisplay")
184         return static_cast<QEglFSScreen *>(mScreen)->display();
185
186     return 0;
187 }
188
189 void *QEglFSIntegration::nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context)
190 {
191     QByteArray lowerCaseResource = resource.toLower();
192
193     QEGLPlatformContext *handle = static_cast<QEGLPlatformContext *>(context->handle());
194
195     if (!handle)
196         return 0;
197
198     if (lowerCaseResource == "eglcontext")
199         return handle->eglContext();
200
201     return 0;
202 }
203
204 QT_END_NAMESPACE