qeglfsdeviceintegration.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/plugins/platforms/eglfs/qeglfsdeviceintegration.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
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 The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/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 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qeglfsdeviceintegration.h"-
41#include "qeglfsintegration.h"-
42#include "qeglfscursor.h"-
43#include "qeglfswindow.h"-
44#include <QtPlatformSupport/private/qeglconvenience_p.h>-
45#include <QGuiApplication>-
46#include <private/qguiapplication_p.h>-
47#include <QScreen>-
48#include <QDir>-
49#include <QRegularExpression>-
50#include <QLoggingCategory>-
51-
52#if defined(Q_OS_LINUX)-
53#include <fcntl.h>-
54#include <unistd.h>-
55#include <linux/fb.h>-
56#include <sys/ioctl.h>-
57#endif-
58-
59#include <private/qfactoryloader_p.h>-
60#include <private/qcore_unix_p.h>-
61-
62QT_BEGIN_NAMESPACE-
63-
64Q_LOGGING_CATEGORY(qLcEglDevDebug, "qt.qpa.egldeviceintegration")-
65-
#ifndef QT_NO_LIBRARYQ_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
67 (QEGLDeviceIntegrationFactoryInterface_iid, QLatin1String("/egldeviceintegrations"), Qt::CaseInsensitive))-
68-
69#ifndef QT_NO_LIBRARY-
70Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, directLoader,-
71 (QEGLDeviceIntegrationFactoryInterface_iid, QLatin1String(""), Qt::CaseInsensitive))-
static inline QEGLDeviceIntegration *loadIntegration(QFactoryLoader *loader, const QString &key)
{
const int index = loader->indexOf(key);
if (index != -1) {
QObject *plugin = loader->instance(index);
if (QEGLDeviceIntegrationPlugin *factory = qobject_cast<QEGLDeviceIntegrationPlugin *>(plugin))
{
if (QEGLDeviceIntegration *result = factory->create())
return result;
}
}
return Q_NULLPTR;
}#endif // QT_NO_LIBRARY
73-
74QStringList QEGLDeviceIntegrationFactory::keys(const QString &pluginPath)-
75{-
76 #ifndef QT_NO_LIBRARYQStringList list;-
77#ifndef QT_NO_LIBRARY-
78 if (!pluginPath.isEmpty()) {
!pluginPath.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
79 QCoreApplication::addLibraryPath(pluginPath);-
80 list = directLoader()->keyMap().values();-
81 if (!list.isEmpty()) {
!list.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
82 const QString postFix = QStringLiteralQLatin1String(" (from ")-
83 + QDir::toNativeSeparators(pluginPath)-
84 + QLatin1Char(')');-
85 const QStringList::iterator end = list.end();-
86 for (QStringList::iterator it = list.begin(); it != end; ++it)
it != endDescription
TRUEnever evaluated
FALSEnever evaluated
0
87 (*it).append(postFix);
never executed: (*it).append(postFix);
0
88 }
never executed: end of block
0
89 }
never executed: end of block
0
90#else-
91 Q_UNUSED(pluginPath);-
92#endif-
93 list.append(loader()->keyMap().values());-
94 qCDebug(qLcEglDevDebug) << "EGL device integration plugin keys:" << list;
never executed: QMessageLogger(__FILE__, 94, __PRETTY_FUNCTION__, qLcEglDevDebug().categoryName()).debug() << "EGL device integration plugin keys:" << list;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
95 return list;
never executed: return list;
0
#else
Q_UNUSED(pluginPath);
return QStringList();
#endif}
97-
98QEGLDeviceIntegration *QEGLDeviceIntegrationFactory::create(const QString &key, const QString &pluginPath)-
99{-
100 QEGLDeviceIntegration *integration = Q_NULLPTR;-
101#ifndef QT_NO_LIBRARY-
102 if (!pluginPath.isEmpty()) {
!pluginPath.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
103 QCoreApplication::addLibraryPath(pluginPath);-
104 integration = loadIntegration(qLoadPlugin<QEGLDeviceIntegration, QEGLDeviceIntegrationPlugin>(directLoader(), key);-
105 }
never executed: end of block
0
106#else-
107 Q_UNUSED(pluginPath);-
108#endif-
109 if (!integration)
!integrationDescription
TRUEnever evaluated
FALSEnever evaluated
0
110 integration = loadIntegration(qLoadPlugin<QEGLDeviceIntegration, QEGLDeviceIntegrationPlugin>(loader(), key);
never executed: integration = qLoadPlugin<QEGLDeviceIntegration, QEGLDeviceIntegrationPlugin>(loader(), key);
0
111 if (integration)
integrationDescription
TRUEnever evaluated
FALSEnever evaluated
0
112 qCDebug(qLcEglDevDebug) << "Using EGL device integration" << key;
never executed: QMessageLogger(__FILE__, 112, __PRETTY_FUNCTION__, qLcEglDevDebug().categoryName()).debug() << "Using EGL device integration" << key;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
113 else-
114 qCWarning(qLcEglDevDebug) << "Failed to load EGL device integration" << key;
never executed: QMessageLogger(__FILE__, 114, __PRETTY_FUNCTION__, qLcEglDevDebug().categoryName()).warning() << "Failed to load EGL device integration" << key;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
115-
116 #else
never executed: return integration;
0
Q_UNUSED(key);
never executed: return integration;
Q_UNUSED(pluginPath);
never executed: return integration;
#endif
never executed: return integration;
return integration;
never executed: return integration;
117}-
118-
119static int framebuffer = -1;-
120-
121QByteArray QEGLDeviceIntegration::fbDeviceName() const-
122{-
123#ifdef Q_OS_LINUX-
124 QByteArray fbDev = qgetenv("QT_QPA_EGLFS_FB");-
125 if (fbDev.isEmpty())
fbDev.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
126 fbDev = QByteArrayLiteral("/dev/fb0");
never executed: fbDev = ([]() -> QByteArray { enum { Size = sizeof("/dev/fb0") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "/dev/fb0" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }());
0
127-
128 return fbDev;
never executed: return fbDev;
0
129#else-
130 return QByteArray();-
131#endif-
132}-
133-
134int QEGLDeviceIntegration::framebufferIndex() const-
135{-
136 int fbIndex = 0;-
137#ifndef QT_NO_REGULAREXPRESSION-
138 QRegularExpression fbIndexRx(QLatin1String("fb(\\d+)"));-
139 QRegularExpressionMatch match = fbIndexRx.match(QString::fromLocal8Bit(fbDeviceName()));-
140 if (match.hasMatch())-
141 fbIndex = match.captured(1).toInt();-
142#endif-
143 return fbIndex;-
144}-
145-
146void QEGLDeviceIntegration::platformInit()-
147{-
148#ifdef Q_OS_LINUX-
149 QByteArray fbDev = fbDeviceName();-
150-
151 framebuffer = qt_safe_open(fbDev, O_RDONLY);-
152-
153 if (Q_UNLIKELY(framebuffer == -1))) {
__builtin_expe...== -1), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
154 qWarning("EGLFS: Failed to open %s", fbDev.constData());-
155 qFatal("EGLFS: Can't continue without a display");-
156 }
never executed: end of block
0
157-
158#ifdef FBIOBLANK-
159 ioctl(framebuffer, FBIOBLANK, VESA_NO_BLANKING);-
160#endif-
161#endif-
162}
never executed: end of block
0
163-
164void QEGLDeviceIntegration::platformDestroy()-
165{-
166#ifdef Q_OS_LINUX-
167 if (framebuffer != -1)
framebuffer != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
168 close(framebuffer);
never executed: close(framebuffer);
0
169#endif-
170}
never executed: end of block
0
171-
172EGLNativeDisplayType QEGLDeviceIntegration::platformDisplay() const-
173{-
174 return EGL_DEFAULT_DISPLAY;-
175}-
176-
177EGLDisplay QEGLDeviceIntegration::createDisplay(EGLNativeDisplayType nativeDisplay)-
178{-
179 return eglGetDisplay(nativeDisplay);-
180}-
181-
182bool QEGLDeviceIntegration::usesDefaultScreen()-
183{-
184 return true;-
185}-
186-
187void QEGLDeviceIntegration::screenInit()-
188{-
189 // Nothing to do here. Called only when usesDefaultScreen is false.-
190}-
191-
192void QEGLDeviceIntegration::screenDestroy()-
193{-
194 QGuiApplication *app = qGuiApp;-
195 QEglFSIntegration *platformIntegration = static_cast<QEglFSIntegration *>(-
196 QGuiApplicationPrivate::platformIntegration());-
197 while (!app->screens().isEmpty())-
198 platformIntegration->removeScreen(app->screens().last()->handle());-
199}-
200-
201QSizeF QEGLDeviceIntegration::physicalScreenSize() const-
202{-
203 return q_physicalScreenSizeFromFb(framebuffer, screenSize());-
204}-
205-
206QSize QEGLDeviceIntegration::screenSize() const-
207{-
208 return q_screenSizeFromFb(framebuffer);-
209}-
210-
211QDpi QEGLDeviceIntegration::logicalDpi() const-
212{-
213 const QSizeF ps = physicalScreenSize();-
214 const QSize s = screenSize();-
215-
216 if (!ps.isEmpty() && !s.isEmpty())-
217 return QDpi(25.4 * s.width() / ps.width(),-
218 25.4 * s.height() / ps.height());-
219 else-
220 return QDpi(100, 100);-
221}-
222-
223qreal QEGLDeviceIntegration::pixelDensity() const-
224{-
225 return qRound(logicalDpi().first / qreal(100));-
226}-
227-
228Qt::ScreenOrientation QEGLDeviceIntegration::nativeOrientation() const-
229{-
230 return Qt::PrimaryOrientation;-
231}-
232-
233Qt::ScreenOrientation QEGLDeviceIntegration::orientation() const-
234{-
235 return Qt::PrimaryOrientation;-
236}-
237-
238int QEGLDeviceIntegration::screenDepth() const-
239{-
240 return q_screenDepthFromFb(framebuffer);-
241}-
242-
243QImage::Format QEGLDeviceIntegration::screenFormat() const-
244{-
245 return screenDepth() == 16 ? QImage::Format_RGB16 : QImage::Format_RGB32;-
246}-
247-
248qreal QEGLDeviceIntegration::refreshRate() const-
249{-
250 return q_refreshRateFromFb(framebuffer);-
251}-
252-
253EGLint QEGLDeviceIntegration::surfaceType() const-
254{-
255 return EGL_WINDOW_BIT;-
256}-
257-
258QSurfaceFormat QEGLDeviceIntegration::surfaceFormatFor(const QSurfaceFormat &inputFormat) const-
259{-
260 QSurfaceFormat format = inputFormat;-
261-
262 static const bool force888 = qEnvironmentVariableIntValue("QT_QPA_EGLFS_FORCE888");-
263 if (force888) {-
264 format.setRedBufferSize(8);-
265 format.setGreenBufferSize(8);-
266 format.setBlueBufferSize(8);-
267 }-
268-
269 return format;-
270}-
271-
272bool QEGLDeviceIntegration::filterConfig(EGLDisplay, EGLConfig) const-
273{-
274 return true;-
275}-
276-
277QEglFSWindow *QEGLDeviceIntegration::createWindow(QWindow *window) const-
278{-
279 return new QEglFSWindow(window);-
280}-
281-
282EGLNativeWindowType QEGLDeviceIntegration::createNativeWindow(QPlatformWindow *platformWindow,-
283 const QSize &size,-
284 const QSurfaceFormat &format)-
285{-
286 Q_UNUSED(platformWindow);-
287 Q_UNUSED(size);-
288 Q_UNUSED(format);-
289 return 0;-
290}-
291-
292EGLNativeWindowType QEGLDeviceIntegration::createNativeOffscreenWindow(const QSurfaceFormat &format)-
293{-
294 Q_UNUSED(format);-
295 return 0;-
296}-
297-
298void QEGLDeviceIntegration::destroyNativeWindow(EGLNativeWindowType window)-
299{-
300 Q_UNUSED(window);-
301}-
302-
303bool QEGLDeviceIntegration::hasCapability(QPlatformIntegration::Capability cap) const-
304{-
305 Q_UNUSED(cap);-
306 return false;-
307}-
308-
309QPlatformCursor *QEGLDeviceIntegration::createCursor(QPlatformScreen *screen) const-
310{-
311 return new QEglFSCursor(screen);-
312}-
313-
314void QEGLDeviceIntegration::waitForVSync(QPlatformSurface *surface) const-
315{-
316 Q_UNUSED(surface);-
317-
318#if defined(Q_OS_LINUX) && defined(FBIO_WAITFORVSYNC)-
319 static const bool forceSync = qEnvironmentVariableIntValue("QT_QPA_EGLFS_FORCEVSYNC");-
320 if (forceSync && framebuffer != -1) {
forceSyncDescription
TRUEnever evaluated
FALSEnever evaluated
framebuffer != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
321 int arg = 0;-
322 if (ioctl(framebuffer, FBIO_WAITFORVSYNC, &arg) == -1)
ioctl(framebuf...), &arg) == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
323 qWarning("Could not wait for vsync.");
never executed: QMessageLogger(__FILE__, 323, __PRETTY_FUNCTION__).warning("Could not wait for vsync.");
0
324 }
never executed: end of block
0
325#endif-
326}
never executed: end of block
0
327-
328void QEGLDeviceIntegration::presentBuffer(QPlatformSurface *surface)-
329{-
330 Q_UNUSED(surface);-
331}-
332-
333bool QEGLDeviceIntegration::supportsPBuffers() const-
334{-
335 return true;-
336}-
337-
338bool QEGLDeviceIntegration::supportsSurfacelessContexts() const-
339{-
340 return true;-
341}-
342-
343void *QEGLDeviceIntegration::wlDisplay() const-
344{-
345 return Q_NULLPTR;-
346}-
347-
348QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9