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 "qeglfsintegration.h"
44 #include "qeglfswindow.h"
45 #include "qeglfsbackingstore.h"
46 #include "qeglfshooks.h"
48 #include <QtGui/private/qguiapplication_p.h>
50 #include <QtPlatformSupport/private/qgenericunixfontdatabase_p.h>
51 #include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h>
52 #include <QtPlatformSupport/private/qeglplatformcontext_p.h>
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>
60 #include <qpa/qplatformwindow.h>
61 #include <QtGui/QSurfaceFormat>
62 #include <QtGui/QOpenGLContext>
63 #include <QtGui/QScreen>
64 #include <qpa/qplatformcursor.h>
66 #include "qeglfscontext.h"
72 QEglFSIntegration::QEglFSIntegration()
73 : mEventDispatcher(createUnixEventDispatcher()), mFontDb(new QGenericUnixFontDatabase())
75 QGuiApplicationPrivate::instance()->setEventDispatcher(mEventDispatcher);
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);
83 hooks->platformInit();
87 if (!eglBindAPI(EGL_OPENGL_ES_API)) {
88 qWarning("Could not bind GL_ES API\n");
92 mDisplay = eglGetDisplay(hooks ? hooks->platformDisplay() : EGL_DEFAULT_DISPLAY);
93 if (mDisplay == EGL_NO_DISPLAY) {
94 qWarning("Could not open egl display\n");
98 if (!eglInitialize(mDisplay, &major, &minor)) {
99 qWarning("Could not initialize egl display\n");
103 int swapInterval = 1;
104 QByteArray swapIntervalString = qgetenv("QT_QPA_EGLFS_SWAPINTERVAL");
105 if (!swapIntervalString.isEmpty()) {
107 swapInterval = swapIntervalString.toInt(&ok);
111 eglSwapInterval(mDisplay, swapInterval);
113 mScreen = new QEglFSScreen(mDisplay);
114 screenAdded(mScreen);
117 QEglFSIntegration::~QEglFSIntegration()
121 eglTerminate(mDisplay);
122 hooks->platformDestroy();
125 bool QEglFSIntegration::hasCapability(QPlatformIntegration::Capability cap) const
127 // We assume that devices will have more and not less capabilities
128 if (hooks && hooks->hasCapability(cap))
132 case ThreadedPixmaps: return true;
133 case OpenGL: return true;
134 case ThreadedOpenGL: return true;
135 default: return QPlatformIntegration::hasCapability(cap);
139 QPlatformWindow *QEglFSIntegration::createPlatformWindow(QWindow *window) const
141 QPlatformWindow *w = new QEglFSWindow(window);
142 w->requestActivateWindow();
146 QPlatformBackingStore *QEglFSIntegration::createPlatformBackingStore(QWindow *window) const
148 return new QEglFSBackingStore(window);
151 QPlatformOpenGLContext *QEglFSIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
153 return new QEglFSContext(context->format(), 0 /*share*/, mDisplay);
156 QPlatformFontDatabase *QEglFSIntegration::fontDatabase() const
161 QAbstractEventDispatcher *QEglFSIntegration::guiThreadEventDispatcher() const
163 return mEventDispatcher;
166 QVariant QEglFSIntegration::styleHint(QPlatformIntegration::StyleHint hint) const
168 if (hint == QPlatformIntegration::ShowIsFullScreen)
171 return QPlatformIntegration::styleHint(hint);
174 QPlatformNativeInterface *QEglFSIntegration::nativeInterface() const
176 return const_cast<QEglFSIntegration *>(this);
179 void *QEglFSIntegration::nativeResourceForIntegration(const QByteArray &resource)
181 QByteArray lowerCaseResource = resource.toLower();
183 if (lowerCaseResource == "egldisplay")
184 return static_cast<QEglFSScreen *>(mScreen)->display();
189 void *QEglFSIntegration::nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context)
191 QByteArray lowerCaseResource = resource.toLower();
193 QEGLPlatformContext *handle = static_cast<QEGLPlatformContext *>(context->handle());
198 if (lowerCaseResource == "eglcontext")
199 return handle->eglContext();