Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsintegration.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||
2 | ** | - | ||||||
3 | ** Copyright (C) 2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> | - | ||||||
4 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||
5 | ** Copyright (C) 2016 Pelagicore AG | - | ||||||
6 | ** Contact: https://www.qt.io/licensing/ | - | ||||||
7 | ** | - | ||||||
8 | ** This file is part of the plugins of the Qt Toolkit. | - | ||||||
9 | ** | - | ||||||
10 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||
11 | ** Commercial License Usage | - | ||||||
12 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
13 | ** accordance with the commercial license agreement provided with the | - | ||||||
14 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
15 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
16 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||
17 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||
18 | ** | - | ||||||
19 | ** GNU Lesser General Public License Usage | - | ||||||
20 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
21 | ** General Public License version 3 as published by the Free Software | - | ||||||
22 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||
23 | ** packaging of this file. Please review the following information to | - | ||||||
24 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||
25 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||
26 | ** | - | ||||||
27 | ** GNU General Public License Usage | - | ||||||
28 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||
29 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||
30 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||
31 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||
32 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||
33 | ** included in the packaging of this file. Please review the following | - | ||||||
34 | ** information to ensure the GNU General Public License requirements will | - | ||||||
35 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||
36 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||
37 | ** | - | ||||||
38 | ** $QT_END_LICENSE$ | - | ||||||
39 | ** | - | ||||||
40 | ****************************************************************************/ | - | ||||||
41 | - | |||||||
42 | #include "qeglfskmsintegration.h" | - | ||||||
43 | #include "qeglfskmsdevice.h" | - | ||||||
44 | #include "qeglfskmsscreen.h" | - | ||||||
45 | #include "qeglfswindow.h" | - | ||||||
46 | #include "qeglfscursor.h" | - | ||||||
47 | - | |||||||
48 | #include <QtPlatformSupport/private/qeglconvenience_p.h> | - | ||||||
49 | #include <QtCore/QJsonDocument> | - | ||||||
50 | #include <QtCore/QJsonObject> | - | ||||||
51 | #include <QtCore/QJsonArray> | - | ||||||
52 | #include <QtGui/qpa/qplatformwindow.h> | - | ||||||
53 | #include <QtGui/qpa/qplatformcursor.h> | - | ||||||
54 | #include <QtGui/QScreen> | - | ||||||
55 | - | |||||||
56 | #include <xf86drm.h> | - | ||||||
57 | #include <xf86drmMode.h> | - | ||||||
58 | - | |||||||
59 | QT_BEGIN_NAMESPACE | - | ||||||
60 | - | |||||||
61 | Q_LOGGING_CATEGORY(qLcEglfsKmsDebug, "qt.qpa.eglfs.kms") never executed: return category; | 0 | ||||||
62 | - | |||||||
63 | QEglFSKmsIntegration::QEglFSKmsIntegration() | - | ||||||
64 | : m_device(Q_NULLPTR) | - | ||||||
65 | , m_hwCursor(false) | - | ||||||
66 | , m_pbuffers(false) | - | ||||||
67 | , m_separateScreens(false) | - | ||||||
68 | {} never executed: end of block | 0 | ||||||
69 | - | |||||||
70 | void QEglFSKmsIntegration::platformInit() | - | ||||||
71 | { | - | ||||||
72 | loadConfig(); | - | ||||||
73 | - | |||||||
74 | if (!m_devicePath.isEmpty()) {
| 0 | ||||||
75 | qCDebug(qLcEglfsKmsDebug) << "Using DRM device" << m_devicePath << "specified in config file"; never executed: QMessageLogger(__FILE__, 75, __PRETTY_FUNCTION__, qLcEglfsKmsDebug().categoryName()).debug() << "Using DRM device" << m_devicePath << "specified in config file";
| 0 | ||||||
76 | } never executed: end of block | 0 | ||||||
77 | - | |||||||
78 | m_device = createDevice(m_devicePath); | - | ||||||
79 | if (Q_UNLIKELY(!m_device->open()))
| 0 | ||||||
80 | qFatal("Could not open device %s - aborting!", qPrintable(m_devicePath)); never executed: QMessageLogger(__FILE__, 80, __PRETTY_FUNCTION__).fatal("Could not open device %s - aborting!", QString(m_devicePath).toLocal8Bit().constData()); | 0 | ||||||
81 | } never executed: end of block | 0 | ||||||
82 | - | |||||||
83 | void QEglFSKmsIntegration::platformDestroy() | - | ||||||
84 | { | - | ||||||
85 | m_device->close(); | - | ||||||
86 | delete m_device; | - | ||||||
87 | m_device = Q_NULLPTR; | - | ||||||
88 | } never executed: end of block | 0 | ||||||
89 | - | |||||||
90 | EGLNativeDisplayType QEglFSKmsIntegration::platformDisplay() const | - | ||||||
91 | { | - | ||||||
92 | Q_ASSERT(m_device); | - | ||||||
93 | return m_device->nativeDisplay(); never executed: return m_device->nativeDisplay(); | 0 | ||||||
94 | } | - | ||||||
95 | - | |||||||
96 | bool QEglFSKmsIntegration::usesDefaultScreen() | - | ||||||
97 | { | - | ||||||
98 | return false; never executed: return false; | 0 | ||||||
99 | } | - | ||||||
100 | - | |||||||
101 | void QEglFSKmsIntegration::screenInit() | - | ||||||
102 | { | - | ||||||
103 | m_device->createScreens(); | - | ||||||
104 | } never executed: end of block | 0 | ||||||
105 | - | |||||||
106 | QSurfaceFormat QEglFSKmsIntegration::surfaceFormatFor(const QSurfaceFormat &inputFormat) const | - | ||||||
107 | { | - | ||||||
108 | QSurfaceFormat format(inputFormat); | - | ||||||
109 | format.setRenderableType(QSurfaceFormat::OpenGLES); | - | ||||||
110 | format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); | - | ||||||
111 | format.setRedBufferSize(8); | - | ||||||
112 | format.setGreenBufferSize(8); | - | ||||||
113 | format.setBlueBufferSize(8); | - | ||||||
114 | return format; never executed: return format; | 0 | ||||||
115 | } | - | ||||||
116 | - | |||||||
117 | bool QEglFSKmsIntegration::hasCapability(QPlatformIntegration::Capability cap) const | - | ||||||
118 | { | - | ||||||
119 | switch (cap) { | - | ||||||
120 | case QPlatformIntegration::ThreadedPixmaps: never executed: case QPlatformIntegration::ThreadedPixmaps: | 0 | ||||||
121 | case QPlatformIntegration::OpenGL: never executed: case QPlatformIntegration::OpenGL: | 0 | ||||||
122 | case QPlatformIntegration::ThreadedOpenGL: never executed: case QPlatformIntegration::ThreadedOpenGL: | 0 | ||||||
123 | return true; never executed: return true; | 0 | ||||||
124 | default: never executed: default: | 0 | ||||||
125 | return false; never executed: return false; | 0 | ||||||
126 | } | - | ||||||
127 | } | - | ||||||
128 | - | |||||||
129 | void QEglFSKmsIntegration::waitForVSync(QPlatformSurface *surface) const | - | ||||||
130 | { | - | ||||||
131 | QWindow *window = static_cast<QWindow *>(surface->surface()); | - | ||||||
132 | QEglFSKmsScreen *screen = static_cast<QEglFSKmsScreen *>(window->screen()->handle()); | - | ||||||
133 | - | |||||||
134 | screen->waitForFlip(); | - | ||||||
135 | } never executed: end of block | 0 | ||||||
136 | - | |||||||
137 | bool QEglFSKmsIntegration::supportsPBuffers() const | - | ||||||
138 | { | - | ||||||
139 | return m_pbuffers; never executed: return m_pbuffers; | 0 | ||||||
140 | } | - | ||||||
141 | - | |||||||
142 | bool QEglFSKmsIntegration::hwCursor() const | - | ||||||
143 | { | - | ||||||
144 | return m_hwCursor; never executed: return m_hwCursor; | 0 | ||||||
145 | } | - | ||||||
146 | - | |||||||
147 | bool QEglFSKmsIntegration::separateScreens() const | - | ||||||
148 | { | - | ||||||
149 | return m_separateScreens; never executed: return m_separateScreens; | 0 | ||||||
150 | } | - | ||||||
151 | - | |||||||
152 | QMap<QString, QVariantMap> QEglFSKmsIntegration::outputSettings() const | - | ||||||
153 | { | - | ||||||
154 | return m_outputSettings; never executed: return m_outputSettings; | 0 | ||||||
155 | } | - | ||||||
156 | - | |||||||
157 | QEglFSKmsDevice *QEglFSKmsIntegration::device() const | - | ||||||
158 | { | - | ||||||
159 | return m_device; never executed: return m_device; | 0 | ||||||
160 | } | - | ||||||
161 | - | |||||||
162 | void QEglFSKmsIntegration::loadConfig() | - | ||||||
163 | { | - | ||||||
164 | static QByteArray json = qgetenv("QT_QPA_EGLFS_KMS_CONFIG"); | - | ||||||
165 | if (json.isEmpty())
| 0 | ||||||
166 | return; never executed: return; | 0 | ||||||
167 | - | |||||||
168 | qCDebug(qLcEglfsKmsDebug) << "Loading KMS setup from" << json; never executed: QMessageLogger(__FILE__, 168, __PRETTY_FUNCTION__, qLcEglfsKmsDebug().categoryName()).debug() << "Loading KMS setup from" << json;
| 0 | ||||||
169 | - | |||||||
170 | QFile file(QString::fromUtf8(json)); | - | ||||||
171 | if (!file.open(QFile::ReadOnly)) {
| 0 | ||||||
172 | qCDebug(qLcEglfsKmsDebug) << "Could not open config file" never executed: QMessageLogger(__FILE__, 172, __PRETTY_FUNCTION__, qLcEglfsKmsDebug().categoryName()).debug() << "Could not open config file" << json << "for reading";
| 0 | ||||||
173 | << json << "for reading"; never executed: QMessageLogger(__FILE__, 172, __PRETTY_FUNCTION__, qLcEglfsKmsDebug().categoryName()).debug() << "Could not open config file" << json << "for reading"; | 0 | ||||||
174 | return; never executed: return; | 0 | ||||||
175 | } | - | ||||||
176 | - | |||||||
177 | const QJsonDocument doc = QJsonDocument::fromJson(file.readAll()); | - | ||||||
178 | if (!doc.isObject()) {
| 0 | ||||||
179 | qCDebug(qLcEglfsKmsDebug) << "Invalid config file" << json never executed: QMessageLogger(__FILE__, 179, __PRETTY_FUNCTION__, qLcEglfsKmsDebug().categoryName()).debug() << "Invalid config file" << json << "- no top-level JSON object";
| 0 | ||||||
180 | << "- no top-level JSON object"; never executed: QMessageLogger(__FILE__, 179, __PRETTY_FUNCTION__, qLcEglfsKmsDebug().categoryName()).debug() << "Invalid config file" << json << "- no top-level JSON object"; | 0 | ||||||
181 | return; never executed: return; | 0 | ||||||
182 | } | - | ||||||
183 | - | |||||||
184 | const QJsonObject object = doc.object(); | - | ||||||
185 | - | |||||||
186 | m_hwCursor = object.value(QLatin1String("hwcursor")).toBool(m_hwCursor); | - | ||||||
187 | m_pbuffers = object.value(QLatin1String("pbuffers")).toBool(m_pbuffers); | - | ||||||
188 | m_devicePath = object.value(QLatin1String("device")).toString(); | - | ||||||
189 | m_separateScreens = object.value(QLatin1String("separateScreens")).toBool(m_separateScreens); | - | ||||||
190 | - | |||||||
191 | const QJsonArray outputs = object.value(QLatin1String("outputs")).toArray(); | - | ||||||
192 | for (int i = 0; i < outputs.size(); i++) {
| 0 | ||||||
193 | const QVariantMap outputSettings = outputs.at(i).toObject().toVariantMap(); | - | ||||||
194 | - | |||||||
195 | if (outputSettings.contains(QStringLiteral("name"))) { never executed: return qstring_literal_temp;
| 0 | ||||||
196 | const QString name = outputSettings.value(QStringLiteral("name")).toString(); never executed: return qstring_literal_temp; | 0 | ||||||
197 | - | |||||||
198 | if (m_outputSettings.contains(name)) {
| 0 | ||||||
199 | qCDebug(qLcEglfsKmsDebug) << "Output" << name << "configured multiple times!"; never executed: QMessageLogger(__FILE__, 199, __PRETTY_FUNCTION__, qLcEglfsKmsDebug().categoryName()).debug() << "Output" << name << "configured multiple times!";
| 0 | ||||||
200 | } never executed: end of block | 0 | ||||||
201 | - | |||||||
202 | m_outputSettings.insert(name, outputSettings); | - | ||||||
203 | } never executed: end of block | 0 | ||||||
204 | } never executed: end of block | 0 | ||||||
205 | - | |||||||
206 | qCDebug(qLcEglfsKmsDebug) << "Configuration:\n" never executed: QMessageLogger(__FILE__, 206, __PRETTY_FUNCTION__, qLcEglfsKmsDebug().categoryName()).debug() << "Configuration:\n" << "\thwcursor:" << m_hwCursor << "\n" << "\tpbuffers:" << m_pbuffers << "\n" << "\tseparateScreens:" << m_separateScreens << "\n" << "\toutputs:" << m_outputSettings;
| 0 | ||||||
207 | << "\thwcursor:" << m_hwCursor << "\n" never executed: QMessageLogger(__FILE__, 206, __PRETTY_FUNCTION__, qLcEglfsKmsDebug().categoryName()).debug() << "Configuration:\n" << "\thwcursor:" << m_hwCursor << "\n" << "\tpbuffers:" << m_pbuffers << "\n" << "\tseparateScreens:" << m_separateScreens << "\n" << "\toutputs:" << m_outputSettings; | 0 | ||||||
208 | << "\tpbuffers:" << m_pbuffers << "\n" never executed: QMessageLogger(__FILE__, 206, __PRETTY_FUNCTION__, qLcEglfsKmsDebug().categoryName()).debug() << "Configuration:\n" << "\thwcursor:" << m_hwCursor << "\n" << "\tpbuffers:" << m_pbuffers << "\n" << "\tseparateScreens:" << m_separateScreens << "\n" << "\toutputs:" << m_outputSettings; | 0 | ||||||
209 | << "\tseparateScreens:" << m_separateScreens << "\n" never executed: QMessageLogger(__FILE__, 206, __PRETTY_FUNCTION__, qLcEglfsKmsDebug().categoryName()).debug() << "Configuration:\n" << "\thwcursor:" << m_hwCursor << "\n" << "\tpbuffers:" << m_pbuffers << "\n" << "\tseparateScreens:" << m_separateScreens << "\n" << "\toutputs:" << m_outputSettings; | 0 | ||||||
210 | << "\toutputs:" << m_outputSettings; never executed: QMessageLogger(__FILE__, 206, __PRETTY_FUNCTION__, qLcEglfsKmsDebug().categoryName()).debug() << "Configuration:\n" << "\thwcursor:" << m_hwCursor << "\n" << "\tpbuffers:" << m_pbuffers << "\n" << "\tseparateScreens:" << m_separateScreens << "\n" << "\toutputs:" << m_outputSettings; | 0 | ||||||
211 | } never executed: end of block | 0 | ||||||
212 | - | |||||||
213 | QT_END_NAMESPACE | - | ||||||
Source code | Switch to Preprocessed file |