| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/opengl/qopengl.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | typedef const GLubyte * ( * qt_glGetStringi)(GLenum, GLuint); | - | ||||||||||||
| 9 | - | |||||||||||||
| 10 | - | |||||||||||||
| 11 | QOpenGLExtensionMatcher::QOpenGLExtensionMatcher() | - | ||||||||||||
| 12 | { | - | ||||||||||||
| 13 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||
| 14 | QOpenGLFunctions *funcs = ctx->functions(); | - | ||||||||||||
| 15 | const char *extensionStr = 0; | - | ||||||||||||
| 16 | - | |||||||||||||
| 17 | if (ctx->isOpenGLES() || ctx->format().majorVersion() < 3) | - | ||||||||||||
| 18 | extensionStr = reinterpret_cast<const char *>(funcs->glGetString(0x1F03)); | - | ||||||||||||
| 19 | - | |||||||||||||
| 20 | if (extensionStr) { | - | ||||||||||||
| 21 | QByteArray ba(extensionStr); | - | ||||||||||||
| 22 | QList<QByteArray> extensions = ba.split(' '); | - | ||||||||||||
| 23 | m_extensions = extensions.toSet(); | - | ||||||||||||
| 24 | } else { | - | ||||||||||||
| 25 | - | |||||||||||||
| 26 | - | |||||||||||||
| 27 | while (funcs->glGetError()) {} | - | ||||||||||||
| 28 | - | |||||||||||||
| 29 | if (ctx) { | - | ||||||||||||
| 30 | qt_glGetStringi glGetStringi = (qt_glGetStringi)ctx->getProcAddress("glGetStringi"); | - | ||||||||||||
| 31 | - | |||||||||||||
| 32 | if (!glGetStringi) | - | ||||||||||||
| 33 | return; | - | ||||||||||||
| 34 | - | |||||||||||||
| 35 | GLint numExtensions = 0; | - | ||||||||||||
| 36 | funcs->glGetIntegerv(0x821D, &numExtensions); | - | ||||||||||||
| 37 | - | |||||||||||||
| 38 | for (int i = 0; i < numExtensions; ++i) { | - | ||||||||||||
| 39 | const char *str = reinterpret_cast<const char *>(glGetStringi(0x1F03, i)); | - | ||||||||||||
| 40 | m_extensions.insert(str); | - | ||||||||||||
| 41 | } | - | ||||||||||||
| 42 | } | - | ||||||||||||
| 43 | - | |||||||||||||
| 44 | } | - | ||||||||||||
| 45 | } | - | ||||||||||||
| 46 | QDebug operator<<(QDebug d, const QOpenGLConfig::Gpu &g) | - | ||||||||||||
| 47 | { | - | ||||||||||||
| 48 | QDebugStateSaver s(d); | - | ||||||||||||
| 49 | d.nospace(); | - | ||||||||||||
| 50 | d << "Gpu("; | - | ||||||||||||
| 51 | if (g.isValid()) { | - | ||||||||||||
| 52 | d << "vendor=" << hex << showbase <<g.vendorId << ", device=" << g.deviceId | - | ||||||||||||
| 53 | << "version=" << g.driverVersion; | - | ||||||||||||
| 54 | } else { | - | ||||||||||||
| 55 | d << 0; | - | ||||||||||||
| 56 | } | - | ||||||||||||
| 57 | d << ')'; | - | ||||||||||||
| 58 | return d; | - | ||||||||||||
| 59 | } | - | ||||||||||||
| 60 | - | |||||||||||||
| static inline QString valueKey() { 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; }()); } | ||||||||||||||
| static inline QString opKey() { 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; }()); } | ||||||||||||||
| static inline QString versionKey() { 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; }()); } | ||||||||||||||
| static inline QString releaseKey() { 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; }()); } | ||||||||||||||
| static inline QString typeKey() { 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; }()); } | ||||||||||||||
| static inline QString osKey() { 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; }()); } | ||||||||||||||
| static inline QString vendorIdKey() { 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; }()); } | ||||||||||||||
| static inline QString glVendorKey() { 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; }()); } | ||||||||||||||
| static inline QString deviceIdKey() { 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; }()); } | ||||||||||||||
| static inline QString driverVersionKey() { 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; }()); } | ||||||||||||||
| static inline QString driverDescriptionKey() { 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; }()); } | ||||||||||||||
| static inline QString featuresKey() { 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; }()); } | ||||||||||||||
| static inline QString idKey() { 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; }()); } | ||||||||||||||
| static inline QString descriptionKey() { 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; }()); } | ||||||||||||||
| static inline QString exceptionsKey() { 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; }()); }typedef QJsonArray::ConstIterator JsonArrayConstIt; | ||||||||||||||
| 62 | - | |||||||||||||
| 63 | static inline bool contains(const QJsonArray &haystack, unsigned needle) | - | ||||||||||||
| 64 | { | - | ||||||||||||
| 65 | for (JsonArrayConstIt it = haystack.constBegin(), cend = haystack.constEnd(); it != cend; ++it) { | - | ||||||||||||
| 66 | if (needle == it->toString().toUInt(nullptr, 0)) | - | ||||||||||||
| 67 | return true; | - | ||||||||||||
| 68 | } | - | ||||||||||||
| 69 | return false; | - | ||||||||||||
| 70 | } | - | ||||||||||||
| 71 | - | |||||||||||||
| 72 | static inline bool contains(const QJsonArray &haystack, const QString &needle) | - | ||||||||||||
| 73 | { | - | ||||||||||||
| 74 | for (JsonArrayConstIt it = haystack.constBegin(), cend = haystack.constEnd(); it != cend; ++it) { | - | ||||||||||||
| 75 | if (needle == it->toString()) | - | ||||||||||||
| 76 | return true; | - | ||||||||||||
| 77 | } | - | ||||||||||||
| 78 | return false; | - | ||||||||||||
| 79 | } | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | namespace { | - | ||||||||||||
| 82 | enum Operator { NotEqual, LessThan, LessEqualThan, Equals, GreaterThan, GreaterEqualThan }; | - | ||||||||||||
| 83 | static const char operators[][3] = {"!=", "<", "<=", "=", ">", ">="}; | - | ||||||||||||
| 84 | - | |||||||||||||
| 85 | - | |||||||||||||
| 86 | - | |||||||||||||
| 87 | struct VersionTerm { | - | ||||||||||||
| 88 | VersionTerm() : op(NotEqual) {} | - | ||||||||||||
| 89 | static VersionTerm fromJson(const QJsonValue &v); | - | ||||||||||||
| 90 | bool isNull() const { return number.isNull(); } | - | ||||||||||||
| 91 | bool matches(const QVersionNumber &other) const; | - | ||||||||||||
| 92 | - | |||||||||||||
| 93 | QVersionNumber number; | - | ||||||||||||
| 94 | Operator op; | - | ||||||||||||
| 95 | }; | - | ||||||||||||
| 96 | - | |||||||||||||
| 97 | bool VersionTerm::matches(const QVersionNumber &other) const | - | ||||||||||||
| 98 | { | - | ||||||||||||
| 99 | if (isNull() || other.isNull()) { | - | ||||||||||||
| 100 | QMessageLogger(__FILE__, 187177, __PRETTY_FUNCTION__).warning("called with invalid parameters"); | - | ||||||||||||
| 101 | return false; | - | ||||||||||||
| 102 | } | - | ||||||||||||
| 103 | switch (op) { | - | ||||||||||||
| 104 | case NotEqual: | - | ||||||||||||
| 105 | return other != number; | - | ||||||||||||
| 106 | case LessThan: | - | ||||||||||||
| 107 | return other < number; | - | ||||||||||||
| 108 | case LessEqualThan: | - | ||||||||||||
| 109 | return other <= number; | - | ||||||||||||
| 110 | case Equals: | - | ||||||||||||
| 111 | return other == number; | - | ||||||||||||
| 112 | case GreaterThan: | - | ||||||||||||
| 113 | return other > number; | - | ||||||||||||
| 114 | case GreaterEqualThan: | - | ||||||||||||
| 115 | return other >= number; | - | ||||||||||||
| 116 | } | - | ||||||||||||
| 117 | return false; | - | ||||||||||||
| 118 | } | - | ||||||||||||
| 119 | - | |||||||||||||
| 120 | VersionTerm VersionTerm::fromJson(const QJsonValue &v) | - | ||||||||||||
| 121 | { | - | ||||||||||||
| 122 | VersionTerm result; | - | ||||||||||||
| 123 | if (!v.isObject()
| 0 | ||||||||||||
| 124 | return never executed: result;return result;never executed: return result; | 0 | ||||||||||||
| 125 | const QJsonObject o = v.toObject(); | - | ||||||||||||
| 126 | result.number = QVersionNumber::fromString(o.value(valueKey()).QLatin1String("value")).toString()); | - | ||||||||||||
| 127 | const QString opS = o.value(opKey()).QLatin1String("op")).toString(); | - | ||||||||||||
| 128 | for (size_t i = 0; i < sizeof(operators) / sizeof(operators[0])
| 0 | ||||||||||||
| 129 | if (opS == QLatin1String(operators[i])
| 0 | ||||||||||||
| 130 | result.op = static_cast<Operator>(i); | - | ||||||||||||
| 131 | break; never executed: break; | 0 | ||||||||||||
| 132 | } | - | ||||||||||||
| 133 | } never executed: end of block | 0 | ||||||||||||
| 134 | return never executed: result;return result;never executed: return result; | 0 | ||||||||||||
| 135 | } | - | ||||||||||||
| 136 | - | |||||||||||||
| 137 | - | |||||||||||||
| 138 | - | |||||||||||||
| 139 | struct OsTypeTerm | - | ||||||||||||
| 140 | { | - | ||||||||||||
| 141 | static OsTypeTerm fromJson(const QJsonValue &v); | - | ||||||||||||
| 142 | static QString hostOs(); | - | ||||||||||||
| 143 | static QVersionNumber hostKernelVersion() { return QVersionNumber::fromString(QSysInfo::kernelVersion()); } | - | ||||||||||||
| 144 | static QString hostOsRelease() { | - | ||||||||||||
| 145 | QString ver; | - | ||||||||||||
| 146 | return ver; | - | ||||||||||||
| 147 | } | - | ||||||||||||
| 148 | - | |||||||||||||
| 149 | bool isNull() const { return type.isEmpty(); } | - | ||||||||||||
| 150 | bool matches(const QString &osName, const QVersionNumber &kernelVersion, const QString &osRelease) const | - | ||||||||||||
| 151 | { | - | ||||||||||||
| 152 | if (isNull() || osName.isEmpty() || kernelVersion.isNull()) { | - | ||||||||||||
| 153 | QMessageLogger(__FILE__, 265255, __PRETTY_FUNCTION__).warning("called with invalid parameters"); | - | ||||||||||||
| 154 | return false; | - | ||||||||||||
| 155 | } | - | ||||||||||||
| 156 | if (type != osName) | - | ||||||||||||
| 157 | return false; | - | ||||||||||||
| 158 | if (!versionTerm.isNull() && !versionTerm.matches(kernelVersion)) | - | ||||||||||||
| 159 | return false; | - | ||||||||||||
| 160 | - | |||||||||||||
| 161 | if (!release.isEmpty() && !contains(release, osRelease)) | - | ||||||||||||
| 162 | return false; | - | ||||||||||||
| 163 | return true; | - | ||||||||||||
| 164 | } | - | ||||||||||||
| 165 | - | |||||||||||||
| 166 | QString type; | - | ||||||||||||
| 167 | VersionTerm versionTerm; | - | ||||||||||||
| 168 | QJsonArray release; | - | ||||||||||||
| 169 | }; | - | ||||||||||||
| 170 | - | |||||||||||||
| 171 | OsTypeTerm OsTypeTerm::fromJson(const QJsonValue &v) | - | ||||||||||||
| 172 | { | - | ||||||||||||
| 173 | OsTypeTerm result; | - | ||||||||||||
| 174 | if (!v.isObject()
| 0 | ||||||||||||
| 175 | return never executed: result;return result;never executed: return result; | 0 | ||||||||||||
| 176 | const QJsonObject o = v.toObject(); | - | ||||||||||||
| 177 | result.type = o.value(typeKey()).QLatin1String("type")).toString(); | - | ||||||||||||
| 178 | result.versionTerm = VersionTerm::fromJson(o.value(versionKey()));QLatin1String("version"))); | - | ||||||||||||
| 179 | result.release = o.value(releaseKey()).QLatin1String("release")).toArray(); | - | ||||||||||||
| 180 | return never executed: result;return result;never executed: return result; | 0 | ||||||||||||
| 181 | } | - | ||||||||||||
| 182 | - | |||||||||||||
| 183 | QString OsTypeTerm::hostOs() | - | ||||||||||||
| 184 | { | - | ||||||||||||
| 185 | - | |||||||||||||
| 186 | - | |||||||||||||
| 187 | - | |||||||||||||
| 188 | - | |||||||||||||
| 189 | 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; }()); | - | ||||||||||||
| 190 | - | |||||||||||||
| 191 | - | |||||||||||||
| 192 | - | |||||||||||||
| 193 | - | |||||||||||||
| 194 | - | |||||||||||||
| 195 | - | |||||||||||||
| 196 | - | |||||||||||||
| 197 | } | - | ||||||||||||
| 198 | } | - | ||||||||||||
| 199 | - | |||||||||||||
| 200 | static QString msgSyntaxWarning(const QJsonObject &object, const QString &what) | - | ||||||||||||
| 201 | { | - | ||||||||||||
| 202 | QString result; | - | ||||||||||||
| 203 | QTextStream(&result) << "Id " << object.value(idKey()).QLatin1String("id")).toInt() | - | ||||||||||||
| 204 | << " (\"" << object.value(descriptionKey()).QLatin1String("description")).toString() | - | ||||||||||||
| 205 | << "\"): " << what; | - | ||||||||||||
| 206 | return never executed: result;return result;never executed: return result; | 0 | ||||||||||||
| 207 | } | - | ||||||||||||
| 208 | - | |||||||||||||
| 209 | - | |||||||||||||
| 210 | - | |||||||||||||
| 211 | - | |||||||||||||
| 212 | static bool matches(const QJsonObject &object, | - | ||||||||||||
| 213 | const QString &osName, | - | ||||||||||||
| 214 | const QVersionNumber &kernelVersion, | - | ||||||||||||
| 215 | const QString &osRelease, | - | ||||||||||||
| 216 | const QOpenGLConfig::Gpu &gpu) | - | ||||||||||||
| 217 | { | - | ||||||||||||
| 218 | const OsTypeTerm os = OsTypeTerm::fromJson(object.value(osKey()));QLatin1String("os"))); | - | ||||||||||||
| 219 | if (!os.isNull()
| 0 | ||||||||||||
| 220 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 221 | - | |||||||||||||
| 222 | const QJsonValue exceptionsV = object.value(exceptionsKey());QLatin1String("exceptions")); | - | ||||||||||||
| 223 | if (exceptionsV.isArray()
| 0 | ||||||||||||
| 224 | const QJsonArray exceptionsA = exceptionsV.toArray(); | - | ||||||||||||
| 225 | for (JsonArrayConstIt it = exceptionsA.constBegin(), cend = exceptionsA.constEnd(); it != cend
| 0 | ||||||||||||
| 226 | if (matches(it->toObject(), osName, kernelVersion, osRelease, gpu)
| 0 | ||||||||||||
| 227 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 228 | } never executed: end of block | 0 | ||||||||||||
| 229 | } never executed: end of block | 0 | ||||||||||||
| 230 | - | |||||||||||||
| 231 | const QJsonValue vendorV = object.value(vendorIdKey());QLatin1String("vendor_id")); | - | ||||||||||||
| 232 | if (vendorV.isString()
| 0 | ||||||||||||
| 233 | if (gpu.vendorId != vendorV.toString().toUInt(nullptr, 0)
| 0 | ||||||||||||
| 234 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 235 | } never executed: else {end of block | 0 | ||||||||||||
| 236 | if (object.contains(glVendorKey()))QLatin1String("gl_vendor"))
| 0 | ||||||||||||
| 237 | const QByteArray glVendorV = object.value(glVendorKey()).QLatin1String("gl_vendor")).toString().toUtf8(); | - | ||||||||||||
| 238 | if (!gpu.glVendor.contains(glVendorV)
| 0 | ||||||||||||
| 239 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 240 | } never executed: end of block | 0 | ||||||||||||
| 241 | } never executed: end of block | 0 | ||||||||||||
| 242 | - | |||||||||||||
| 243 | if (gpu.deviceId
| 0 | ||||||||||||
| 244 | const QJsonValue deviceIdV = object.value(deviceIdKey());QLatin1String("device_id")); | - | ||||||||||||
| 245 | switch (deviceIdV.type()) { | - | ||||||||||||
| 246 | case never executed: QJsonValue::Array:case QJsonValue::Array:never executed: case QJsonValue::Array: | 0 | ||||||||||||
| 247 | if (!contains(deviceIdV.toArray(), gpu.deviceId)
| 0 | ||||||||||||
| 248 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 249 | break; never executed: break; | 0 | ||||||||||||
| 250 | case never executed: QJsonValue::Undefined:case QJsonValue::Undefined:never executed: case QJsonValue::Undefined: | 0 | ||||||||||||
| 251 | case never executed: QJsonValue::Null:case QJsonValue::Null:never executed: case QJsonValue::Null: | 0 | ||||||||||||
| 252 | break; never executed: break; | 0 | ||||||||||||
| 253 | default never executed: :default:never executed: default: | 0 | ||||||||||||
| 254 | QMessageLogger(__FILE__, 366356, __PRETTY_FUNCTION__).warning().noquote() | - | ||||||||||||
| 255 | << msgSyntaxWarning(object, | - | ||||||||||||
| 256 | QLatin1String("Device ID must be of type array.")); | - | ||||||||||||
| 257 | } never executed: end of block | 0 | ||||||||||||
| 258 | } | - | ||||||||||||
| 259 | if (!gpu.driverVersion.isNull()
| 0 | ||||||||||||
| 260 | const QJsonValue driverVersionV = object.value(driverVersionKey());QLatin1String("driver_version")); | - | ||||||||||||
| 261 | switch (driverVersionV.type()) { | - | ||||||||||||
| 262 | case never executed: QJsonValue::Object:case QJsonValue::Object:never executed: case QJsonValue::Object: | 0 | ||||||||||||
| 263 | if (!VersionTerm::fromJson(driverVersionV).matches(gpu.driverVersion)
| 0 | ||||||||||||
| 264 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 265 | break; never executed: break; | 0 | ||||||||||||
| 266 | case never executed: QJsonValue::Undefined:case QJsonValue::Undefined:never executed: case QJsonValue::Undefined: | 0 | ||||||||||||
| 267 | case never executed: QJsonValue::Null:case QJsonValue::Null:never executed: case QJsonValue::Null: | 0 | ||||||||||||
| 268 | break; never executed: break; | 0 | ||||||||||||
| 269 | default never executed: :default:never executed: default: | 0 | ||||||||||||
| 270 | QMessageLogger(__FILE__, 382372, __PRETTY_FUNCTION__).warning().noquote() | - | ||||||||||||
| 271 | << msgSyntaxWarning(object, | - | ||||||||||||
| 272 | QLatin1String("Driver version must be of type object.")); | - | ||||||||||||
| 273 | } never executed: end of block | 0 | ||||||||||||
| 274 | } | - | ||||||||||||
| 275 | - | |||||||||||||
| 276 | if (!gpu.driverDescription.isEmpty()
| 0 | ||||||||||||
| 277 | const QJsonValue driverDescriptionV = object.value(driverDescriptionKey());QLatin1String("driver_description")); | - | ||||||||||||
| 278 | if (driverDescriptionV.isString()
| 0 | ||||||||||||
| 279 | if (!gpu.driverDescription.contains(driverDescriptionV.toString().toUtf8())
| 0 | ||||||||||||
| 280 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 281 | } never executed: end of block | 0 | ||||||||||||
| 282 | } never executed: end of block | 0 | ||||||||||||
| 283 | - | |||||||||||||
| 284 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||
| 285 | } | - | ||||||||||||
| 286 | - | |||||||||||||
| 287 | static bool readGpuFeatures(const QOpenGLConfig::Gpu &gpu, | - | ||||||||||||
| 288 | const QString &osName, | - | ||||||||||||
| 289 | const QVersionNumber &kernelVersion, | - | ||||||||||||
| 290 | const QString &osRelease, | - | ||||||||||||
| 291 | const QJsonDocument &doc, | - | ||||||||||||
| 292 | QSet<QString> *result, | - | ||||||||||||
| 293 | QString *errorMessage) | - | ||||||||||||
| 294 | { | - | ||||||||||||
| 295 | result->clear(); | - | ||||||||||||
| 296 | errorMessage->clear(); | - | ||||||||||||
| 297 | const QJsonValue entriesV = doc.object().value(([]() -> QString { enum { Size = sizeof(u"" "entries")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeofQLatin1String(QStringData) }, u"" "entries"}; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));)); | - | ||||||||||||
| 298 | if (!entriesV.isArray()
| 0 | ||||||||||||
| 299 | *errorMessage = QLatin1String("No entries read."); | - | ||||||||||||
| 300 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 301 | } | - | ||||||||||||
| 302 | - | |||||||||||||
| 303 | const QJsonArray entriesA = entriesV.toArray(); | - | ||||||||||||
| 304 | for (JsonArrayConstIt eit = entriesA.constBegin(), ecend = entriesA.constEnd(); eit != ecend
| 0 | ||||||||||||
| 305 | if (eit->isObject()
| 0 | ||||||||||||
| 306 | const QJsonObject object = eit->toObject(); | - | ||||||||||||
| 307 | if (matches(object, osName, kernelVersion, osRelease, gpu)
| 0 | ||||||||||||
| 308 | const QJsonValue featuresListV = object.value(featuresKey());QLatin1String("features")); | - | ||||||||||||
| 309 | if (featuresListV.isArray()
| 0 | ||||||||||||
| 310 | const QJsonArray featuresListA = featuresListV.toArray(); | - | ||||||||||||
| 311 | for (JsonArrayConstIt fit = featuresListA.constBegin(), fcend = featuresListA.constEnd(); fit != fcend
| 0 | ||||||||||||
| 312 | result->insert(fit->toString()); never executed: result->insert(fit->toString()); | 0 | ||||||||||||
| 313 | } never executed: end of block | 0 | ||||||||||||
| 314 | } never executed: end of block | 0 | ||||||||||||
| 315 | } never executed: end of block | 0 | ||||||||||||
| 316 | } never executed: end of block | 0 | ||||||||||||
| 317 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||
| 318 | } | - | ||||||||||||
| 319 | - | |||||||||||||
| 320 | static bool readGpuFeatures(const QOpenGLConfig::Gpu &gpu, | - | ||||||||||||
| 321 | const QString &osName, | - | ||||||||||||
| 322 | const QVersionNumber &kernelVersion, | - | ||||||||||||
| 323 | const QString &osRelease, | - | ||||||||||||
| 324 | const QByteArray &jsonAsciiData, | - | ||||||||||||
| 325 | QSet<QString> *result, QString *errorMessage) | - | ||||||||||||
| 326 | { | - | ||||||||||||
| 327 | result->clear(); | - | ||||||||||||
| 328 | errorMessage->clear(); | - | ||||||||||||
| 329 | QJsonParseError error; | - | ||||||||||||
| 330 | const QJsonDocument document = QJsonDocument::fromJson(jsonAsciiData, &error); | - | ||||||||||||
| 331 | if (document.isNull()) { | - | ||||||||||||
| 332 | const int lineNumber = 1 + jsonAsciiData.left(error.offset).count('\n'); | - | ||||||||||||
| 333 | QTextStream str(errorMessage); | - | ||||||||||||
| 334 | str << "Failed to parse data: \"" << error.errorString() | - | ||||||||||||
| 335 | << "\" at line " << lineNumber << " (offset: " | - | ||||||||||||
| 336 | << error.offset << ")."; | - | ||||||||||||
| 337 | return false; | - | ||||||||||||
| 338 | } | - | ||||||||||||
| 339 | return readGpuFeatures(gpu, osName, kernelVersion, osRelease, document, result, errorMessage); | - | ||||||||||||
| 340 | } | - | ||||||||||||
| 341 | - | |||||||||||||
| 342 | static bool readGpuFeatures(const QOpenGLConfig::Gpu &gpu, | - | ||||||||||||
| 343 | const QString &osName, | - | ||||||||||||
| 344 | const QVersionNumber &kernelVersion, | - | ||||||||||||
| 345 | const QString &osRelease, | - | ||||||||||||
| 346 | const QString &fileName, | - | ||||||||||||
| 347 | QSet<QString> *result, QString *errorMessage) | - | ||||||||||||
| 348 | { | - | ||||||||||||
| 349 | result->clear(); | - | ||||||||||||
| 350 | errorMessage->clear(); | - | ||||||||||||
| 351 | QFile file(fileName); | - | ||||||||||||
| 352 | if (!file.open(QIODevice::ReadOnly)) { | - | ||||||||||||
| 353 | QTextStream str(errorMessage); | - | ||||||||||||
| 354 | str << "Cannot open \"" << QDir::toNativeSeparators(fileName) << "\": " | - | ||||||||||||
| 355 | << file.errorString(); | - | ||||||||||||
| 356 | return false; | - | ||||||||||||
| 357 | } | - | ||||||||||||
| 358 | const bool success = readGpuFeatures(gpu, osName, kernelVersion, osRelease, file.readAll(), result, errorMessage); | - | ||||||||||||
| 359 | if (!success) { | - | ||||||||||||
| 360 | errorMessage->prepend(QLatin1String("Error reading \"") | - | ||||||||||||
| 361 | + QDir::toNativeSeparators(fileName) | - | ||||||||||||
| 362 | + QLatin1String("\": ")); | - | ||||||||||||
| 363 | } | - | ||||||||||||
| 364 | return success; | - | ||||||||||||
| 365 | } | - | ||||||||||||
| 366 | - | |||||||||||||
| 367 | QSet<QString> QOpenGLConfig::gpuFeatures(const QOpenGLConfig::Gpu &gpu, | - | ||||||||||||
| 368 | const QString &osName, | - | ||||||||||||
| 369 | const QVersionNumber &kernelVersion, | - | ||||||||||||
| 370 | const QString &osRelease, | - | ||||||||||||
| 371 | const QJsonDocument &doc) | - | ||||||||||||
| 372 | { | - | ||||||||||||
| 373 | QSet<QString> result; | - | ||||||||||||
| 374 | QString errorMessage; | - | ||||||||||||
| 375 | if (!readGpuFeatures(gpu, osName, kernelVersion, osRelease, doc, &result, &errorMessage)) | - | ||||||||||||
| 376 | QMessageLogger(__FILE__, 488478, __PRETTY_FUNCTION__).warning().noquote() << errorMessage; | - | ||||||||||||
| 377 | return result; | - | ||||||||||||
| 378 | } | - | ||||||||||||
| 379 | - | |||||||||||||
| 380 | QSet<QString> QOpenGLConfig::gpuFeatures(const QOpenGLConfig::Gpu &gpu, | - | ||||||||||||
| 381 | const QString &osName, | - | ||||||||||||
| 382 | const QVersionNumber &kernelVersion, | - | ||||||||||||
| 383 | const QString &osRelease, | - | ||||||||||||
| 384 | const QString &fileName) | - | ||||||||||||
| 385 | { | - | ||||||||||||
| 386 | QSet<QString> result; | - | ||||||||||||
| 387 | QString errorMessage; | - | ||||||||||||
| 388 | if (!readGpuFeatures(gpu, osName, kernelVersion, osRelease, fileName, &result, &errorMessage)) | - | ||||||||||||
| 389 | QMessageLogger(__FILE__, 501491, __PRETTY_FUNCTION__).warning().noquote() << errorMessage; | - | ||||||||||||
| 390 | return result; | - | ||||||||||||
| 391 | } | - | ||||||||||||
| 392 | - | |||||||||||||
| 393 | QSet<QString> QOpenGLConfig::gpuFeatures(const Gpu &gpu, const QJsonDocument &doc) | - | ||||||||||||
| 394 | { | - | ||||||||||||
| 395 | return gpuFeatures(gpu, OsTypeTerm::hostOs(), OsTypeTerm::hostKernelVersion(), OsTypeTerm::hostOsRelease(), doc); | - | ||||||||||||
| 396 | } | - | ||||||||||||
| 397 | - | |||||||||||||
| 398 | QSet<QString> QOpenGLConfig::gpuFeatures(const Gpu &gpu, const QString &fileName) | - | ||||||||||||
| 399 | { | - | ||||||||||||
| 400 | return gpuFeatures(gpu, OsTypeTerm::hostOs(), OsTypeTerm::hostKernelVersion(), OsTypeTerm::hostOsRelease(), fileName); | - | ||||||||||||
| 401 | } | - | ||||||||||||
| 402 | - | |||||||||||||
| 403 | QOpenGLConfig::Gpu QOpenGLConfig::Gpu::fromContext() | - | ||||||||||||
| 404 | { | - | ||||||||||||
| 405 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||
| 406 | QScopedPointer<QOpenGLContext> tmpContext; | - | ||||||||||||
| 407 | QScopedPointer<QOffscreenSurface> tmpSurface; | - | ||||||||||||
| 408 | if (!ctx) { | - | ||||||||||||
| 409 | tmpContext.reset(new QOpenGLContext); | - | ||||||||||||
| 410 | if (!tmpContext->create()) { | - | ||||||||||||
| 411 | QMessageLogger(__FILE__, 523513, __PRETTY_FUNCTION__).warning("QOpenGLConfig::Gpu::fromContext: Failed to create temporary context"); | - | ||||||||||||
| 412 | return QOpenGLConfig::Gpu(); | - | ||||||||||||
| 413 | } | - | ||||||||||||
| 414 | tmpSurface.reset(new QOffscreenSurface); | - | ||||||||||||
| 415 | tmpSurface->setFormat(tmpContext->format()); | - | ||||||||||||
| 416 | tmpSurface->create(); | - | ||||||||||||
| 417 | tmpContext->makeCurrent(tmpSurface.data()); | - | ||||||||||||
| 418 | } | - | ||||||||||||
| 419 | - | |||||||||||||
| 420 | QOpenGLConfig::Gpu gpu; | - | ||||||||||||
| 421 | ctx = QOpenGLContext::currentContext(); | - | ||||||||||||
| 422 | const GLubyte *p = ctx->functions()->glGetString(0x1F00); | - | ||||||||||||
| 423 | if (p) | - | ||||||||||||
| 424 | gpu.glVendor = QByteArray(reinterpret_cast<const char *>(p)); | - | ||||||||||||
| 425 | - | |||||||||||||
| 426 | return gpu; | - | ||||||||||||
| 427 | } | - | ||||||||||||
| 428 | - | |||||||||||||
| 429 | __attribute__((visibility("default"))) std::set<QByteArray> *qgpu_features(const QString &filename) | - | ||||||||||||
| 430 | { | - | ||||||||||||
| 431 | const QSet<QString> features = QOpenGLConfig::gpuFeatures(QOpenGLConfig::Gpu::fromContext(), filename); | - | ||||||||||||
| 432 | std::set<QByteArray> *result = new std::set<QByteArray>; | - | ||||||||||||
| 433 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(features)>::type> _container_((features)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QString &feature = *_container_.i; _container_.control; _container_.control = 0: features) | - | ||||||||||||
| 434 | result->insert(feature.toUtf8()); never executed: result->insert(feature.toUtf8()); | 0 | ||||||||||||
| 435 | return never executed: result;return result;never executed: return result; | 0 | ||||||||||||
| 436 | } | - | ||||||||||||
| 437 | - | |||||||||||||
| 438 | - | |||||||||||||
| Switch to Source code | Preprocessed file |