| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/opengl/qopengl.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
| 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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | #include "qopengl.h" | - | ||||||||||||||||||
| 35 | #include "qopengl_p.h" | - | ||||||||||||||||||
| 36 | - | |||||||||||||||||||
| 37 | #include "qopenglcontext.h" | - | ||||||||||||||||||
| 38 | #include "qopenglfunctions.h" | - | ||||||||||||||||||
| 39 | #include "qoffscreensurface.h" | - | ||||||||||||||||||
| 40 | - | |||||||||||||||||||
| 41 | #include <QtCore/QDebug> | - | ||||||||||||||||||
| 42 | #include <QtCore/QJsonDocument> | - | ||||||||||||||||||
| 43 | #include <QtCore/QJsonValue> | - | ||||||||||||||||||
| 44 | #include <QtCore/QJsonObject> | - | ||||||||||||||||||
| 45 | #include <QtCore/QJsonArray> | - | ||||||||||||||||||
| 46 | #include <QtCore/QTextStream> | - | ||||||||||||||||||
| 47 | #include <QtCore/QFile> | - | ||||||||||||||||||
| 48 | #include <QtCore/QDir> | - | ||||||||||||||||||
| 49 | - | |||||||||||||||||||
| 50 | #include <set> | - | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | #if defined(QT_OPENGL_3) | - | ||||||||||||||||||
| 55 | typedef const GLubyte * (QOPENGLF_APIENTRYP qt_glGetStringi)(GLenum, GLuint); | - | ||||||||||||||||||
| 56 | #endif | - | ||||||||||||||||||
| 57 | - | |||||||||||||||||||
| 58 | QOpenGLExtensionMatcher::QOpenGLExtensionMatcher() | - | ||||||||||||||||||
| 59 | { | - | ||||||||||||||||||
| 60 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||||||||
| 61 | QOpenGLFunctions *funcs = ctx->functions(); | - | ||||||||||||||||||
| 62 | const char *extensionStr = 0; | - | ||||||||||||||||||
| 63 | - | |||||||||||||||||||
| 64 | if (ctx->isOpenGLES() || ctx->format().majorVersion() < 3)
| 0 | ||||||||||||||||||
| 65 | extensionStr = reinterpret_cast<const char *>(funcs->glGetString(GL_EXTENSIONS)); never executed: extensionStr = reinterpret_cast<const char *>(funcs->glGetString(0x1F03)); | 0 | ||||||||||||||||||
| 66 | - | |||||||||||||||||||
| 67 | if (extensionStr) {
| 0 | ||||||||||||||||||
| 68 | QByteArray ba(extensionStr); | - | ||||||||||||||||||
| 69 | QList<QByteArray> extensions = ba.split(' '); | - | ||||||||||||||||||
| 70 | m_extensions = extensions.toSet(); | - | ||||||||||||||||||
| 71 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 72 | #ifdef QT_OPENGL_3 | - | ||||||||||||||||||
| 73 | // clear error state | - | ||||||||||||||||||
| 74 | while (funcs->glGetError()) {} never executed: end of block
| 0 | ||||||||||||||||||
| 75 | - | |||||||||||||||||||
| 76 | if (ctx) {
| 0 | ||||||||||||||||||
| 77 | qt_glGetStringi glGetStringi = (qt_glGetStringi)ctx->getProcAddress("glGetStringi"); | - | ||||||||||||||||||
| 78 | - | |||||||||||||||||||
| 79 | if (!glGetStringi)
| 0 | ||||||||||||||||||
| 80 | return; never executed: return; | 0 | ||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | GLint numExtensions = 0; | - | ||||||||||||||||||
| 83 | funcs->glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); | - | ||||||||||||||||||
| 84 | - | |||||||||||||||||||
| 85 | for (int i = 0; i < numExtensions; ++i) {
| 0 | ||||||||||||||||||
| 86 | const char *str = reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i)); | - | ||||||||||||||||||
| 87 | m_extensions.insert(str); | - | ||||||||||||||||||
| 88 | } never executed: end of block | 0 | ||||||||||||||||||
| 89 | } never executed: end of block | 0 | ||||||||||||||||||
| 90 | #endif // QT_OPENGL_3 | - | ||||||||||||||||||
| 91 | } never executed: end of block | 0 | ||||||||||||||||||
| 92 | } | - | ||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | /* Helpers to read out the list of features matching a device from | - | ||||||||||||||||||
| 95 | * a Chromium driver bug list. Note that not all keys are supported and | - | ||||||||||||||||||
| 96 | * some may behave differently: gl_vendor is a substring match instead of regex. | - | ||||||||||||||||||
| 97 | { | - | ||||||||||||||||||
| 98 | "entries": [ | - | ||||||||||||||||||
| 99 | { | - | ||||||||||||||||||
| 100 | "id": 20, | - | ||||||||||||||||||
| 101 | "description": "Disable EXT_draw_buffers on GeForce GT 650M on Linux due to driver bugs", | - | ||||||||||||||||||
| 102 | "os": { | - | ||||||||||||||||||
| 103 | "type": "linux" | - | ||||||||||||||||||
| 104 | }, | - | ||||||||||||||||||
| 105 | // Optional: "exceptions" list | - | ||||||||||||||||||
| 106 | "vendor_id": "0x10de", | - | ||||||||||||||||||
| 107 | "device_id": ["0x0fd5"], | - | ||||||||||||||||||
| 108 | "multi_gpu_category": "any", | - | ||||||||||||||||||
| 109 | "features": [ | - | ||||||||||||||||||
| 110 | "disable_ext_draw_buffers" | - | ||||||||||||||||||
| 111 | ] | - | ||||||||||||||||||
| 112 | }, | - | ||||||||||||||||||
| 113 | .... | - | ||||||||||||||||||
| 114 | } | - | ||||||||||||||||||
| 115 | */ | - | ||||||||||||||||||
| 116 | - | |||||||||||||||||||
| 117 | QDebug operator<<(QDebug d, const QOpenGLConfig::Gpu &g) | - | ||||||||||||||||||
| 118 | { | - | ||||||||||||||||||
| 119 | QDebugStateSaver s(d); | - | ||||||||||||||||||
| 120 | d.nospace(); | - | ||||||||||||||||||
| 121 | d << "Gpu("; | - | ||||||||||||||||||
| 122 | if (g.isValid()) {
| 0 | ||||||||||||||||||
| 123 | d << "vendor=" << hex << showbase <<g.vendorId << ", device=" << g.deviceId | - | ||||||||||||||||||
| 124 | << "version=" << g.driverVersion; | - | ||||||||||||||||||
| 125 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 126 | d << 0; | - | ||||||||||||||||||
| 127 | } never executed: end of block | 0 | ||||||||||||||||||
| 128 | d << ')'; | - | ||||||||||||||||||
| 129 | return d; never executed: return d; | 0 | ||||||||||||||||||
| 130 | } | - | ||||||||||||||||||
| 131 | - | |||||||||||||||||||
| 132 | static never executed: return ([]() -> QString { enum { Size = sizeof(u"" "value")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "value" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: inline QString valueKey() { return QStringLiteral("value"); }return qstring_literal_temp;never executed: return ([]() -> QString { enum { Size = sizeof(u"" "value")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "value" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 133 | static never executed: return ([]() -> QString { enum { Size = sizeof(u"" "op")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "op" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: inline QString opKey() { return QStringLiteral("op"); }return qstring_literal_temp;never executed: return ([]() -> QString { enum { Size = sizeof(u"" "op")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "op" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 134 | static never executed: return ([]() -> QString { enum { Size = sizeof(u"" "version")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "version" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: inline QString versionKey() { return QStringLiteral("version"); }return qstring_literal_temp;never executed: return ([]() -> QString { enum { Size = sizeof(u"" "version")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "version" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 135 | static never executed: return ([]() -> QString { enum { Size = sizeof(u"" "release")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "release" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: inline QString releaseKey() { return QStringLiteral("release"); }return qstring_literal_temp;never executed: return ([]() -> QString { enum { Size = sizeof(u"" "release")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "release" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 136 | static never executed: return ([]() -> QString { enum { Size = sizeof(u"" "type")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "type" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: inline QString typeKey() { return QStringLiteral("type"); }return qstring_literal_temp;never executed: return ([]() -> QString { enum { Size = sizeof(u"" "type")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "type" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 137 | static never executed: return ([]() -> QString { enum { Size = sizeof(u"" "os")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "os" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: inline QString osKey() { return QStringLiteral("os"); }return qstring_literal_temp;never executed: return ([]() -> QString { enum { Size = sizeof(u"" "os")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "os" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 138 | static never executed: return ([]() -> QString { enum { Size = sizeof(u"" "vendor_id")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "vendor_id" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: inline QString vendorIdKey() { return QStringLiteral("vendor_id"); }return qstring_literal_temp;never executed: return ([]() -> QString { enum { Size = sizeof(u"" "vendor_id")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "vendor_id" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 139 | static never executed: return ([]() -> QString { enum { Size = sizeof(u"" "gl_vendor")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "gl_vendor" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: inline QString glVendorKey() { return QStringLiteral("gl_vendor"); }return qstring_literal_temp;never executed: return ([]() -> QString { enum { Size = sizeof(u"" "gl_vendor")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "gl_vendor" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 140 | static never executed: return ([]() -> QString { enum { Size = sizeof(u"" "device_id")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "device_id" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: inline QString deviceIdKey() { return QStringLiteral("device_id"); }return qstring_literal_temp;never executed: return ([]() -> QString { enum { Size = sizeof(u"" "device_id")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "device_id" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 141 | static never executed: return ([]() -> QString { enum { Size = sizeof(u"" "driver_version")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "driver_version" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: inline QString driverVersionKey() { return QStringLiteral("driver_version"); }return qstring_literal_temp;never executed: return ([]() -> QString { enum { Size = sizeof(u"" "driver_version")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "driver_version" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 142 | static never executed: return ([]() -> QString { enum { Size = sizeof(u"" "driver_description")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "driver_description" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: inline QString driverDescriptionKey() { return QStringLiteral("driver_description"); }return qstring_literal_temp;never executed: return ([]() -> QString { enum { Size = sizeof(u"" "driver_description")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "driver_description" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 143 | static never executed: return ([]() -> QString { enum { Size = sizeof(u"" "features")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "features" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: inline QString featuresKey() { return QStringLiteral("features"); }return qstring_literal_temp;never executed: return ([]() -> QString { enum { Size = sizeof(u"" "features")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "features" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 144 | static never executed: return ([]() -> QString { enum { Size = sizeof(u"" "id")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "id" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: inline QString idKey() { return QStringLiteral("id"); }return qstring_literal_temp;never executed: return ([]() -> QString { enum { Size = sizeof(u"" "id")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "id" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 145 | static never executed: return ([]() -> QString { enum { Size = sizeof(u"" "description")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "description" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: inline QString descriptionKey() { return QStringLiteral("description"); }return qstring_literal_temp;never executed: return ([]() -> QString { enum { Size = sizeof(u"" "description")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "description" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 146 | static never executed: return ([]() -> QString { enum { Size = sizeof(u"" "exceptions")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "exceptions" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: inline QString exceptionsKey() { return QStringLiteral("exceptions"); }return qstring_literal_temp;never executed: return ([]() -> QString { enum { Size = sizeof(u"" "exceptions")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "exceptions" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | typedef QJsonArray::ConstIterator JsonArrayConstIt; | - | ||||||||||||||||||
| 149 | - | |||||||||||||||||||
| 150 | static inline bool contains(const QJsonArray &haystack, unsigned needle) | - | ||||||||||||||||||
| 151 | { | - | ||||||||||||||||||
| 152 | for (JsonArrayConstIt it = haystack.constBegin(), cend = haystack.constEnd(); it != cend; ++it) {
| 0 | ||||||||||||||||||
| 153 | if (needle == it->toString().toUInt(Q_NULLPTR, /* base */ 0))
| 0 | ||||||||||||||||||
| 154 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 155 | } never executed: end of block | 0 | ||||||||||||||||||
| 156 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 157 | } | - | ||||||||||||||||||
| 158 | - | |||||||||||||||||||
| 159 | static inline bool contains(const QJsonArray &haystack, const QString &needle) | - | ||||||||||||||||||
| 160 | { | - | ||||||||||||||||||
| 161 | for (JsonArrayConstIt it = haystack.constBegin(), cend = haystack.constEnd(); it != cend; ++it) {
| 0 | ||||||||||||||||||
| 162 | if (needle == it->toString())
| 0 | ||||||||||||||||||
| 163 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 164 | } never executed: end of block | 0 | ||||||||||||||||||
| 165 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 166 | } | - | ||||||||||||||||||
| 167 | - | |||||||||||||||||||
| 168 | namespace { | - | ||||||||||||||||||
| 169 | enum Operator { NotEqual, LessThan, LessEqualThan, Equals, GreaterThan, GreaterEqualThan }; | - | ||||||||||||||||||
| 170 | static const char operators[][3] = {"!=", "<", "<=", "=", ">", ">="}; | - | ||||||||||||||||||
| 171 | - | |||||||||||||||||||
| 172 | // VersionTerm describing a version term consisting of number and operator | - | ||||||||||||||||||
| 173 | // found in os.version and driver_version. | - | ||||||||||||||||||
| 174 | struct VersionTerm { | - | ||||||||||||||||||
| 175 | VersionTerm() : op(NotEqual) {} never executed: end of block | 0 | ||||||||||||||||||
| 176 | static VersionTerm fromJson(const QJsonValue &v); | - | ||||||||||||||||||
| 177 | bool isNull() const { return number.isNull(); } never executed: return number.isNull(); | 0 | ||||||||||||||||||
| 178 | bool matches(const QVersionNumber &other) const; | - | ||||||||||||||||||
| 179 | - | |||||||||||||||||||
| 180 | QVersionNumber number; | - | ||||||||||||||||||
| 181 | Operator op; | - | ||||||||||||||||||
| 182 | }; | - | ||||||||||||||||||
| 183 | - | |||||||||||||||||||
| 184 | bool VersionTerm::matches(const QVersionNumber &other) const | - | ||||||||||||||||||
| 185 | { | - | ||||||||||||||||||
| 186 | if (isNull() || other.isNull()) {
| 0 | ||||||||||||||||||
| 187 | qWarning("called with invalid parameters"); | - | ||||||||||||||||||
| 188 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 189 | } | - | ||||||||||||||||||
| 190 | switch (op) { | - | ||||||||||||||||||
| 191 | case NotEqual: never executed: case NotEqual: | 0 | ||||||||||||||||||
| 192 | return other != number; never executed: return other != number; | 0 | ||||||||||||||||||
| 193 | case LessThan: never executed: case LessThan: | 0 | ||||||||||||||||||
| 194 | return other < number; never executed: return other < number; | 0 | ||||||||||||||||||
| 195 | case LessEqualThan: never executed: case LessEqualThan: | 0 | ||||||||||||||||||
| 196 | return other <= number; never executed: return other <= number; | 0 | ||||||||||||||||||
| 197 | case Equals: never executed: case Equals: | 0 | ||||||||||||||||||
| 198 | return other == number; never executed: return other == number; | 0 | ||||||||||||||||||
| 199 | case GreaterThan: never executed: case GreaterThan: | 0 | ||||||||||||||||||
| 200 | return other > number; never executed: return other > number; | 0 | ||||||||||||||||||
| 201 | case GreaterEqualThan: never executed: case GreaterEqualThan: | 0 | ||||||||||||||||||
| 202 | return other >= number; never executed: return other >= number; | 0 | ||||||||||||||||||
| 203 | } | - | ||||||||||||||||||
| 204 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 205 | } | - | ||||||||||||||||||
| 206 | - | |||||||||||||||||||
| 207 | VersionTerm VersionTerm::fromJson(const QJsonValue &v) | - | ||||||||||||||||||
| 208 | { | - | ||||||||||||||||||
| 209 | VersionTerm result; | - | ||||||||||||||||||
| 210 | if (!v.isObject())
| 0 | ||||||||||||||||||
| 211 | return result; never executed: return result; | 0 | ||||||||||||||||||
| 212 | const QJsonObject o = v.toObject(); | - | ||||||||||||||||||
| 213 | result.number = QVersionNumber::fromString(o.value(valueKey()).toString()); | - | ||||||||||||||||||
| 214 | const QString opS = o.value(opKey()).toString(); | - | ||||||||||||||||||
| 215 | for (size_t i = 0; i < sizeof(operators) / sizeof(operators[0]); ++i) {
| 0 | ||||||||||||||||||
| 216 | if (opS == QLatin1String(operators[i])) {
| 0 | ||||||||||||||||||
| 217 | result.op = static_cast<Operator>(i); | - | ||||||||||||||||||
| 218 | break; never executed: break; | 0 | ||||||||||||||||||
| 219 | } | - | ||||||||||||||||||
| 220 | } never executed: end of block | 0 | ||||||||||||||||||
| 221 | return result; never executed: return result; | 0 | ||||||||||||||||||
| 222 | } | - | ||||||||||||||||||
| 223 | - | |||||||||||||||||||
| 224 | // OS term consisting of name and optional version found in | - | ||||||||||||||||||
| 225 | // under "os" in main array and in "exceptions" lists. | - | ||||||||||||||||||
| 226 | struct OsTypeTerm | - | ||||||||||||||||||
| 227 | { | - | ||||||||||||||||||
| 228 | static OsTypeTerm fromJson(const QJsonValue &v); | - | ||||||||||||||||||
| 229 | static QString hostOs(); | - | ||||||||||||||||||
| 230 | static QVersionNumber hostKernelVersion() { return QVersionNumber::fromString(QSysInfo::kernelVersion()); } never executed: return QVersionNumber::fromString(QSysInfo::kernelVersion()); | 0 | ||||||||||||||||||
| 231 | static QString hostOsRelease() { | - | ||||||||||||||||||
| 232 | QString ver; | - | ||||||||||||||||||
| 233 | #ifdef Q_OS_WIN | - | ||||||||||||||||||
| 234 | switch (QSysInfo::windowsVersion()) { | - | ||||||||||||||||||
| 235 | case QSysInfo::WV_XP: | - | ||||||||||||||||||
| 236 | case QSysInfo::WV_2003: | - | ||||||||||||||||||
| 237 | ver = QStringLiteral("xp"); | - | ||||||||||||||||||
| 238 | break; | - | ||||||||||||||||||
| 239 | case QSysInfo::WV_VISTA: | - | ||||||||||||||||||
| 240 | ver = QStringLiteral("vista"); | - | ||||||||||||||||||
| 241 | break; | - | ||||||||||||||||||
| 242 | case QSysInfo::WV_WINDOWS7: | - | ||||||||||||||||||
| 243 | ver = QStringLiteral("7"); | - | ||||||||||||||||||
| 244 | break; | - | ||||||||||||||||||
| 245 | case QSysInfo::WV_WINDOWS8: | - | ||||||||||||||||||
| 246 | ver = QStringLiteral("8"); | - | ||||||||||||||||||
| 247 | break; | - | ||||||||||||||||||
| 248 | case QSysInfo::WV_WINDOWS8_1: | - | ||||||||||||||||||
| 249 | ver = QStringLiteral("8.1"); | - | ||||||||||||||||||
| 250 | break; | - | ||||||||||||||||||
| 251 | case QSysInfo::WV_WINDOWS10: | - | ||||||||||||||||||
| 252 | ver = QStringLiteral("10"); | - | ||||||||||||||||||
| 253 | break; | - | ||||||||||||||||||
| 254 | default: | - | ||||||||||||||||||
| 255 | break; | - | ||||||||||||||||||
| 256 | } | - | ||||||||||||||||||
| 257 | #endif | - | ||||||||||||||||||
| 258 | return ver; never executed: return ver; | 0 | ||||||||||||||||||
| 259 | } | - | ||||||||||||||||||
| 260 | - | |||||||||||||||||||
| 261 | bool isNull() const { return type.isEmpty(); } never executed: return type.isEmpty(); | 0 | ||||||||||||||||||
| 262 | bool matches(const QString &osName, const QVersionNumber &kernelVersion, const QString &osRelease) const | - | ||||||||||||||||||
| 263 | { | - | ||||||||||||||||||
| 264 | if (isNull() || osName.isEmpty() || kernelVersion.isNull()) {
| 0 | ||||||||||||||||||
| 265 | qWarning("called with invalid parameters"); | - | ||||||||||||||||||
| 266 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 267 | } | - | ||||||||||||||||||
| 268 | if (type != osName)
| 0 | ||||||||||||||||||
| 269 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 270 | if (!versionTerm.isNull() && !versionTerm.matches(kernelVersion))
| 0 | ||||||||||||||||||
| 271 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 272 | // release is a list of Windows versions where the rule should match | - | ||||||||||||||||||
| 273 | if (!release.isEmpty() && !contains(release, osRelease))
| 0 | ||||||||||||||||||
| 274 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 275 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 276 | } | - | ||||||||||||||||||
| 277 | - | |||||||||||||||||||
| 278 | QString type; | - | ||||||||||||||||||
| 279 | VersionTerm versionTerm; | - | ||||||||||||||||||
| 280 | QJsonArray release; | - | ||||||||||||||||||
| 281 | }; | - | ||||||||||||||||||
| 282 | - | |||||||||||||||||||
| 283 | OsTypeTerm OsTypeTerm::fromJson(const QJsonValue &v) | - | ||||||||||||||||||
| 284 | { | - | ||||||||||||||||||
| 285 | OsTypeTerm result; | - | ||||||||||||||||||
| 286 | if (!v.isObject())
| 0 | ||||||||||||||||||
| 287 | return result; never executed: return result; | 0 | ||||||||||||||||||
| 288 | const QJsonObject o = v.toObject(); | - | ||||||||||||||||||
| 289 | result.type = o.value(typeKey()).toString(); | - | ||||||||||||||||||
| 290 | result.versionTerm = VersionTerm::fromJson(o.value(versionKey())); | - | ||||||||||||||||||
| 291 | result.release = o.value(releaseKey()).toArray(); | - | ||||||||||||||||||
| 292 | return result; never executed: return result; | 0 | ||||||||||||||||||
| 293 | } | - | ||||||||||||||||||
| 294 | - | |||||||||||||||||||
| 295 | QString OsTypeTerm::hostOs() | - | ||||||||||||||||||
| 296 | { | - | ||||||||||||||||||
| 297 | // Determine Host OS. | - | ||||||||||||||||||
| 298 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||
| 299 | return QStringLiteral("win"); | - | ||||||||||||||||||
| 300 | #elif defined(Q_OS_LINUX) | - | ||||||||||||||||||
| 301 | return QStringLiteral("linux"); never executed: return ([]() -> QString { enum { Size = sizeof(u"" "linux")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "linux" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 302 | #elif defined(Q_OS_OSX) | - | ||||||||||||||||||
| 303 | return QStringLiteral("macosx"); | - | ||||||||||||||||||
| 304 | #elif defined(Q_OS_ANDROID) | - | ||||||||||||||||||
| 305 | return QStringLiteral("android"); | - | ||||||||||||||||||
| 306 | #else | - | ||||||||||||||||||
| 307 | return QString(); | - | ||||||||||||||||||
| 308 | #endif | - | ||||||||||||||||||
| 309 | } | - | ||||||||||||||||||
| 310 | } // anonymous namespace | - | ||||||||||||||||||
| 311 | - | |||||||||||||||||||
| 312 | static QString msgSyntaxWarning(const QJsonObject &object, const QString &what) | - | ||||||||||||||||||
| 313 | { | - | ||||||||||||||||||
| 314 | QString result; | - | ||||||||||||||||||
| 315 | QTextStream(&result) << "Id " << object.value(idKey()).toInt() | - | ||||||||||||||||||
| 316 | << " (\"" << object.value(descriptionKey()).toString() | - | ||||||||||||||||||
| 317 | << "\"): " << what; | - | ||||||||||||||||||
| 318 | return result; never executed: return result; | 0 | ||||||||||||||||||
| 319 | } | - | ||||||||||||||||||
| 320 | - | |||||||||||||||||||
| 321 | // Check whether an entry matches. Called recursively for | - | ||||||||||||||||||
| 322 | // "exceptions" list. | - | ||||||||||||||||||
| 323 | - | |||||||||||||||||||
| 324 | static bool matches(const QJsonObject &object, | - | ||||||||||||||||||
| 325 | const QString &osName, | - | ||||||||||||||||||
| 326 | const QVersionNumber &kernelVersion, | - | ||||||||||||||||||
| 327 | const QString &osRelease, | - | ||||||||||||||||||
| 328 | const QOpenGLConfig::Gpu &gpu) | - | ||||||||||||||||||
| 329 | { | - | ||||||||||||||||||
| 330 | const OsTypeTerm os = OsTypeTerm::fromJson(object.value(osKey())); | - | ||||||||||||||||||
| 331 | if (!os.isNull() && !os.matches(osName, kernelVersion, osRelease))
| 0 | ||||||||||||||||||
| 332 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 333 | - | |||||||||||||||||||
| 334 | const QJsonValue exceptionsV = object.value(exceptionsKey()); | - | ||||||||||||||||||
| 335 | if (exceptionsV.isArray()) {
| 0 | ||||||||||||||||||
| 336 | const QJsonArray exceptionsA = exceptionsV.toArray(); | - | ||||||||||||||||||
| 337 | for (JsonArrayConstIt it = exceptionsA.constBegin(), cend = exceptionsA.constEnd(); it != cend; ++it) {
| 0 | ||||||||||||||||||
| 338 | if (matches(it->toObject(), osName, kernelVersion, osRelease, gpu))
| 0 | ||||||||||||||||||
| 339 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 340 | } never executed: end of block | 0 | ||||||||||||||||||
| 341 | } never executed: end of block | 0 | ||||||||||||||||||
| 342 | - | |||||||||||||||||||
| 343 | const QJsonValue vendorV = object.value(vendorIdKey()); | - | ||||||||||||||||||
| 344 | if (vendorV.isString()) {
| 0 | ||||||||||||||||||
| 345 | if (gpu.vendorId != vendorV.toString().toUInt(Q_NULLPTR, /* base */ 0))
| 0 | ||||||||||||||||||
| 346 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 347 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 348 | if (object.contains(glVendorKey())) {
| 0 | ||||||||||||||||||
| 349 | const QByteArray glVendorV = object.value(glVendorKey()).toString().toUtf8(); | - | ||||||||||||||||||
| 350 | if (!gpu.glVendor.contains(glVendorV))
| 0 | ||||||||||||||||||
| 351 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 352 | } never executed: end of block | 0 | ||||||||||||||||||
| 353 | } never executed: end of block | 0 | ||||||||||||||||||
| 354 | - | |||||||||||||||||||
| 355 | if (gpu.deviceId) {
| 0 | ||||||||||||||||||
| 356 | const QJsonValue deviceIdV = object.value(deviceIdKey()); | - | ||||||||||||||||||
| 357 | switch (deviceIdV.type()) { | - | ||||||||||||||||||
| 358 | case QJsonValue::Array: never executed: case QJsonValue::Array: | 0 | ||||||||||||||||||
| 359 | if (!contains(deviceIdV.toArray(), gpu.deviceId))
| 0 | ||||||||||||||||||
| 360 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 361 | break; never executed: break; | 0 | ||||||||||||||||||
| 362 | case QJsonValue::Undefined: never executed: case QJsonValue::Undefined: | 0 | ||||||||||||||||||
| 363 | case QJsonValue::Null: never executed: case QJsonValue::Null: | 0 | ||||||||||||||||||
| 364 | break; never executed: break; | 0 | ||||||||||||||||||
| 365 | default: never executed: default: | 0 | ||||||||||||||||||
| 366 | qWarning().noquote() | - | ||||||||||||||||||
| 367 | << msgSyntaxWarning(object, | - | ||||||||||||||||||
| 368 | QLatin1String("Device ID must be of type array.")); | - | ||||||||||||||||||
| 369 | } never executed: end of block | 0 | ||||||||||||||||||
| 370 | } | - | ||||||||||||||||||
| 371 | if (!gpu.driverVersion.isNull()) {
| 0 | ||||||||||||||||||
| 372 | const QJsonValue driverVersionV = object.value(driverVersionKey()); | - | ||||||||||||||||||
| 373 | switch (driverVersionV.type()) { | - | ||||||||||||||||||
| 374 | case QJsonValue::Object: never executed: case QJsonValue::Object: | 0 | ||||||||||||||||||
| 375 | if (!VersionTerm::fromJson(driverVersionV).matches(gpu.driverVersion))
| 0 | ||||||||||||||||||
| 376 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 377 | break; never executed: break; | 0 | ||||||||||||||||||
| 378 | case QJsonValue::Undefined: never executed: case QJsonValue::Undefined: | 0 | ||||||||||||||||||
| 379 | case QJsonValue::Null: never executed: case QJsonValue::Null: | 0 | ||||||||||||||||||
| 380 | break; never executed: break; | 0 | ||||||||||||||||||
| 381 | default: never executed: default: | 0 | ||||||||||||||||||
| 382 | qWarning().noquote() | - | ||||||||||||||||||
| 383 | << msgSyntaxWarning(object, | - | ||||||||||||||||||
| 384 | QLatin1String("Driver version must be of type object.")); | - | ||||||||||||||||||
| 385 | } never executed: end of block | 0 | ||||||||||||||||||
| 386 | } | - | ||||||||||||||||||
| 387 | - | |||||||||||||||||||
| 388 | if (!gpu.driverDescription.isEmpty()) {
| 0 | ||||||||||||||||||
| 389 | const QJsonValue driverDescriptionV = object.value(driverDescriptionKey()); | - | ||||||||||||||||||
| 390 | if (driverDescriptionV.isString()) {
| 0 | ||||||||||||||||||
| 391 | if (!gpu.driverDescription.contains(driverDescriptionV.toString().toUtf8()))
| 0 | ||||||||||||||||||
| 392 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 393 | } never executed: end of block | 0 | ||||||||||||||||||
| 394 | } never executed: end of block | 0 | ||||||||||||||||||
| 395 | - | |||||||||||||||||||
| 396 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 397 | } | - | ||||||||||||||||||
| 398 | - | |||||||||||||||||||
| 399 | static bool readGpuFeatures(const QOpenGLConfig::Gpu &gpu, | - | ||||||||||||||||||
| 400 | const QString &osName, | - | ||||||||||||||||||
| 401 | const QVersionNumber &kernelVersion, | - | ||||||||||||||||||
| 402 | const QString &osRelease, | - | ||||||||||||||||||
| 403 | const QJsonDocument &doc, | - | ||||||||||||||||||
| 404 | QSet<QString> *result, | - | ||||||||||||||||||
| 405 | QString *errorMessage) | - | ||||||||||||||||||
| 406 | { | - | ||||||||||||||||||
| 407 | result->clear(); | - | ||||||||||||||||||
| 408 | errorMessage->clear(); | - | ||||||||||||||||||
| 409 | const QJsonValue entriesV = doc.object().value(QStringLiteral("entries")); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 410 | if (!entriesV.isArray()) {
| 0 | ||||||||||||||||||
| 411 | *errorMessage = QLatin1String("No entries read."); | - | ||||||||||||||||||
| 412 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 413 | } | - | ||||||||||||||||||
| 414 | - | |||||||||||||||||||
| 415 | const QJsonArray entriesA = entriesV.toArray(); | - | ||||||||||||||||||
| 416 | for (JsonArrayConstIt eit = entriesA.constBegin(), ecend = entriesA.constEnd(); eit != ecend; ++eit) {
| 0 | ||||||||||||||||||
| 417 | if (eit->isObject()) {
| 0 | ||||||||||||||||||
| 418 | const QJsonObject object = eit->toObject(); | - | ||||||||||||||||||
| 419 | if (matches(object, osName, kernelVersion, osRelease, gpu)) {
| 0 | ||||||||||||||||||
| 420 | const QJsonValue featuresListV = object.value(featuresKey()); | - | ||||||||||||||||||
| 421 | if (featuresListV.isArray()) {
| 0 | ||||||||||||||||||
| 422 | const QJsonArray featuresListA = featuresListV.toArray(); | - | ||||||||||||||||||
| 423 | for (JsonArrayConstIt fit = featuresListA.constBegin(), fcend = featuresListA.constEnd(); fit != fcend; ++fit)
| 0 | ||||||||||||||||||
| 424 | result->insert(fit->toString()); never executed: result->insert(fit->toString()); | 0 | ||||||||||||||||||
| 425 | } never executed: end of block | 0 | ||||||||||||||||||
| 426 | } never executed: end of block | 0 | ||||||||||||||||||
| 427 | } never executed: end of block | 0 | ||||||||||||||||||
| 428 | } never executed: end of block | 0 | ||||||||||||||||||
| 429 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 430 | } | - | ||||||||||||||||||
| 431 | - | |||||||||||||||||||
| 432 | static bool readGpuFeatures(const QOpenGLConfig::Gpu &gpu, | - | ||||||||||||||||||
| 433 | const QString &osName, | - | ||||||||||||||||||
| 434 | const QVersionNumber &kernelVersion, | - | ||||||||||||||||||
| 435 | const QString &osRelease, | - | ||||||||||||||||||
| 436 | const QByteArray &jsonAsciiData, | - | ||||||||||||||||||
| 437 | QSet<QString> *result, QString *errorMessage) | - | ||||||||||||||||||
| 438 | { | - | ||||||||||||||||||
| 439 | result->clear(); | - | ||||||||||||||||||
| 440 | errorMessage->clear(); | - | ||||||||||||||||||
| 441 | QJsonParseError error; | - | ||||||||||||||||||
| 442 | const QJsonDocument document = QJsonDocument::fromJson(jsonAsciiData, &error); | - | ||||||||||||||||||
| 443 | if (document.isNull()) {
| 0 | ||||||||||||||||||
| 444 | const int lineNumber = 1 + jsonAsciiData.left(error.offset).count('\n'); | - | ||||||||||||||||||
| 445 | QTextStream str(errorMessage); | - | ||||||||||||||||||
| 446 | str << "Failed to parse data: \"" << error.errorString() | - | ||||||||||||||||||
| 447 | << "\" at line " << lineNumber << " (offset: " | - | ||||||||||||||||||
| 448 | << error.offset << ")."; | - | ||||||||||||||||||
| 449 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 450 | } | - | ||||||||||||||||||
| 451 | return readGpuFeatures(gpu, osName, kernelVersion, osRelease, document, result, errorMessage); never executed: return readGpuFeatures(gpu, osName, kernelVersion, osRelease, document, result, errorMessage); | 0 | ||||||||||||||||||
| 452 | } | - | ||||||||||||||||||
| 453 | - | |||||||||||||||||||
| 454 | static bool readGpuFeatures(const QOpenGLConfig::Gpu &gpu, | - | ||||||||||||||||||
| 455 | const QString &osName, | - | ||||||||||||||||||
| 456 | const QVersionNumber &kernelVersion, | - | ||||||||||||||||||
| 457 | const QString &osRelease, | - | ||||||||||||||||||
| 458 | const QString &fileName, | - | ||||||||||||||||||
| 459 | QSet<QString> *result, QString *errorMessage) | - | ||||||||||||||||||
| 460 | { | - | ||||||||||||||||||
| 461 | result->clear(); | - | ||||||||||||||||||
| 462 | errorMessage->clear(); | - | ||||||||||||||||||
| 463 | QFile file(fileName); | - | ||||||||||||||||||
| 464 | if (!file.open(QIODevice::ReadOnly)) {
| 0 | ||||||||||||||||||
| 465 | QTextStream str(errorMessage); | - | ||||||||||||||||||
| 466 | str << "Cannot open \"" << QDir::toNativeSeparators(fileName) << "\": " | - | ||||||||||||||||||
| 467 | << file.errorString(); | - | ||||||||||||||||||
| 468 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 469 | } | - | ||||||||||||||||||
| 470 | const bool success = readGpuFeatures(gpu, osName, kernelVersion, osRelease, file.readAll(), result, errorMessage); | - | ||||||||||||||||||
| 471 | if (!success) {
| 0 | ||||||||||||||||||
| 472 | errorMessage->prepend(QLatin1String("Error reading \"") | - | ||||||||||||||||||
| 473 | + QDir::toNativeSeparators(fileName) | - | ||||||||||||||||||
| 474 | + QLatin1String("\": ")); | - | ||||||||||||||||||
| 475 | } never executed: end of block | 0 | ||||||||||||||||||
| 476 | return success; never executed: return success; | 0 | ||||||||||||||||||
| 477 | } | - | ||||||||||||||||||
| 478 | - | |||||||||||||||||||
| 479 | QSet<QString> QOpenGLConfig::gpuFeatures(const QOpenGLConfig::Gpu &gpu, | - | ||||||||||||||||||
| 480 | const QString &osName, | - | ||||||||||||||||||
| 481 | const QVersionNumber &kernelVersion, | - | ||||||||||||||||||
| 482 | const QString &osRelease, | - | ||||||||||||||||||
| 483 | const QJsonDocument &doc) | - | ||||||||||||||||||
| 484 | { | - | ||||||||||||||||||
| 485 | QSet<QString> result; | - | ||||||||||||||||||
| 486 | QString errorMessage; | - | ||||||||||||||||||
| 487 | if (!readGpuFeatures(gpu, osName, kernelVersion, osRelease, doc, &result, &errorMessage))
| 0 | ||||||||||||||||||
| 488 | qWarning().noquote() << errorMessage; never executed: QMessageLogger(__FILE__, 488, __PRETTY_FUNCTION__).warning().noquote() << errorMessage; | 0 | ||||||||||||||||||
| 489 | return result; never executed: return result; | 0 | ||||||||||||||||||
| 490 | } | - | ||||||||||||||||||
| 491 | - | |||||||||||||||||||
| 492 | QSet<QString> QOpenGLConfig::gpuFeatures(const QOpenGLConfig::Gpu &gpu, | - | ||||||||||||||||||
| 493 | const QString &osName, | - | ||||||||||||||||||
| 494 | const QVersionNumber &kernelVersion, | - | ||||||||||||||||||
| 495 | const QString &osRelease, | - | ||||||||||||||||||
| 496 | const QString &fileName) | - | ||||||||||||||||||
| 497 | { | - | ||||||||||||||||||
| 498 | QSet<QString> result; | - | ||||||||||||||||||
| 499 | QString errorMessage; | - | ||||||||||||||||||
| 500 | if (!readGpuFeatures(gpu, osName, kernelVersion, osRelease, fileName, &result, &errorMessage))
| 0 | ||||||||||||||||||
| 501 | qWarning().noquote() << errorMessage; never executed: QMessageLogger(__FILE__, 501, __PRETTY_FUNCTION__).warning().noquote() << errorMessage; | 0 | ||||||||||||||||||
| 502 | return result; never executed: return result; | 0 | ||||||||||||||||||
| 503 | } | - | ||||||||||||||||||
| 504 | - | |||||||||||||||||||
| 505 | QSet<QString> QOpenGLConfig::gpuFeatures(const Gpu &gpu, const QJsonDocument &doc) | - | ||||||||||||||||||
| 506 | { | - | ||||||||||||||||||
| 507 | return gpuFeatures(gpu, OsTypeTerm::hostOs(), OsTypeTerm::hostKernelVersion(), OsTypeTerm::hostOsRelease(), doc); never executed: return gpuFeatures(gpu, OsTypeTerm::hostOs(), OsTypeTerm::hostKernelVersion(), OsTypeTerm::hostOsRelease(), doc); | 0 | ||||||||||||||||||
| 508 | } | - | ||||||||||||||||||
| 509 | - | |||||||||||||||||||
| 510 | QSet<QString> QOpenGLConfig::gpuFeatures(const Gpu &gpu, const QString &fileName) | - | ||||||||||||||||||
| 511 | { | - | ||||||||||||||||||
| 512 | return gpuFeatures(gpu, OsTypeTerm::hostOs(), OsTypeTerm::hostKernelVersion(), OsTypeTerm::hostOsRelease(), fileName); never executed: return gpuFeatures(gpu, OsTypeTerm::hostOs(), OsTypeTerm::hostKernelVersion(), OsTypeTerm::hostOsRelease(), fileName); | 0 | ||||||||||||||||||
| 513 | } | - | ||||||||||||||||||
| 514 | - | |||||||||||||||||||
| 515 | QOpenGLConfig::Gpu QOpenGLConfig::Gpu::fromContext() | - | ||||||||||||||||||
| 516 | { | - | ||||||||||||||||||
| 517 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||||||||
| 518 | QScopedPointer<QOpenGLContext> tmpContext; | - | ||||||||||||||||||
| 519 | QScopedPointer<QOffscreenSurface> tmpSurface; | - | ||||||||||||||||||
| 520 | if (!ctx) {
| 0 | ||||||||||||||||||
| 521 | tmpContext.reset(new QOpenGLContext); | - | ||||||||||||||||||
| 522 | if (!tmpContext->create()) {
| 0 | ||||||||||||||||||
| 523 | qWarning("QOpenGLConfig::Gpu::fromContext: Failed to create temporary context"); | - | ||||||||||||||||||
| 524 | return QOpenGLConfig::Gpu(); never executed: return QOpenGLConfig::Gpu(); | 0 | ||||||||||||||||||
| 525 | } | - | ||||||||||||||||||
| 526 | tmpSurface.reset(new QOffscreenSurface); | - | ||||||||||||||||||
| 527 | tmpSurface->setFormat(tmpContext->format()); | - | ||||||||||||||||||
| 528 | tmpSurface->create(); | - | ||||||||||||||||||
| 529 | tmpContext->makeCurrent(tmpSurface.data()); | - | ||||||||||||||||||
| 530 | } never executed: end of block | 0 | ||||||||||||||||||
| 531 | - | |||||||||||||||||||
| 532 | QOpenGLConfig::Gpu gpu; | - | ||||||||||||||||||
| 533 | ctx = QOpenGLContext::currentContext(); | - | ||||||||||||||||||
| 534 | const GLubyte *p = ctx->functions()->glGetString(GL_VENDOR); | - | ||||||||||||||||||
| 535 | if (p)
| 0 | ||||||||||||||||||
| 536 | gpu.glVendor = QByteArray(reinterpret_cast<const char *>(p)); never executed: gpu.glVendor = QByteArray(reinterpret_cast<const char *>(p)); | 0 | ||||||||||||||||||
| 537 | - | |||||||||||||||||||
| 538 | return gpu; never executed: return gpu; | 0 | ||||||||||||||||||
| 539 | } | - | ||||||||||||||||||
| 540 | - | |||||||||||||||||||
| 541 | Q_GUI_EXPORT std::set<QByteArray> *qgpu_features(const QString &filename) | - | ||||||||||||||||||
| 542 | { | - | ||||||||||||||||||
| 543 | const QSet<QString> features = QOpenGLConfig::gpuFeatures(QOpenGLConfig::Gpu::fromContext(), filename); | - | ||||||||||||||||||
| 544 | std::set<QByteArray> *result = new std::set<QByteArray>; | - | ||||||||||||||||||
| 545 | foreach (const QString &feature, features) | - | ||||||||||||||||||
| 546 | result->insert(feature.toUtf8()); never executed: result->insert(feature.toUtf8()); | 0 | ||||||||||||||||||
| 547 | return result; never executed: return result; | 0 | ||||||||||||||||||
| 548 | } | - | ||||||||||||||||||
| 549 | - | |||||||||||||||||||
| 550 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |