| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquickopenglshadereffect.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtQuick module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #include <private/qquickopenglshadereffect_p.h> | - | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | #include <QtQuick/qsgmaterial.h> | - | ||||||||||||||||||
| 43 | #include <QtQuick/private/qsgshadersourcebuilder_p.h> | - | ||||||||||||||||||
| 44 | #include "qquickitem_p.h" | - | ||||||||||||||||||
| 45 | - | |||||||||||||||||||
| 46 | #include <QtQuick/private/qsgcontext_p.h> | - | ||||||||||||||||||
| 47 | #include <QtQuick/qsgtextureprovider.h> | - | ||||||||||||||||||
| 48 | #include "qquickwindow.h" | - | ||||||||||||||||||
| 49 | - | |||||||||||||||||||
| 50 | #include "qquickimage_p.h" | - | ||||||||||||||||||
| 51 | #include "qquickshadereffectsource_p.h" | - | ||||||||||||||||||
| 52 | #include "qquickshadereffectmesh_p.h" | - | ||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | #include <QtQml/qqmlfile.h> | - | ||||||||||||||||||
| 55 | #include <QtCore/qsignalmapper.h> | - | ||||||||||||||||||
| 56 | #include <QtCore/qfileselector.h> | - | ||||||||||||||||||
| 57 | - | |||||||||||||||||||
| 58 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | namespace { | - | ||||||||||||||||||
| 61 | - | |||||||||||||||||||
| 62 | enum VariableQualifier { | - | ||||||||||||||||||
| 63 | AttributeQualifier, | - | ||||||||||||||||||
| 64 | UniformQualifier | - | ||||||||||||||||||
| 65 | }; | - | ||||||||||||||||||
| 66 | - | |||||||||||||||||||
| 67 | inline bool qt_isalpha(char c) | - | ||||||||||||||||||
| 68 | { | - | ||||||||||||||||||
| 69 | char ch = c | 0x20; | - | ||||||||||||||||||
| 70 | return (ch >= 'a' && ch <= 'z') || c == '_'; executed 19442 times by 4 tests: return (ch >= 'a' && ch <= 'z') || c == '_';Executed by:
| 19442 | ||||||||||||||||||
| 71 | } | - | ||||||||||||||||||
| 72 | - | |||||||||||||||||||
| 73 | inline bool qt_isalnum(char c) | - | ||||||||||||||||||
| 74 | { | - | ||||||||||||||||||
| 75 | return qt_isalpha(c) || (c >= '0' && c <= '9'); executed 14798 times by 4 tests: return qt_isalpha(c) || (c >= '0' && c <= '9');Executed by:
| 14798 | ||||||||||||||||||
| 76 | } | - | ||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | inline bool qt_isspace(char c) | - | ||||||||||||||||||
| 79 | { | - | ||||||||||||||||||
| 80 | return c == ' ' || (c >= 0x09 && c <= 0x0d); executed 16856 times by 4 tests: return c == ' ' || (c >= 0x09 && c <= 0x0d);Executed by:
| 16856 | ||||||||||||||||||
| 81 | } | - | ||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | // Returns -1 if not found, returns index to first character after the name if found. | - | ||||||||||||||||||
| 84 | int qt_search_for_variable(const char *s, int length, int index, VariableQualifier &decl, | - | ||||||||||||||||||
| 85 | int &typeIndex, int &typeLength, | - | ||||||||||||||||||
| 86 | int &nameIndex, int &nameLength, | - | ||||||||||||||||||
| 87 | QQuickOpenGLShaderEffectCommon::Key::ShaderType shaderType) | - | ||||||||||||||||||
| 88 | { | - | ||||||||||||||||||
| 89 | enum Identifier { | - | ||||||||||||||||||
| 90 | QualifierIdentifier, // Base state | - | ||||||||||||||||||
| 91 | PrecisionIdentifier, | - | ||||||||||||||||||
| 92 | TypeIdentifier, | - | ||||||||||||||||||
| 93 | NameIdentifier | - | ||||||||||||||||||
| 94 | }; | - | ||||||||||||||||||
| 95 | Identifier expected = QualifierIdentifier; | - | ||||||||||||||||||
| 96 | bool compilerDirectiveExpected = index == 0; | - | ||||||||||||||||||
| 97 | - | |||||||||||||||||||
| 98 | while (index < length) {
| 146-4644 | ||||||||||||||||||
| 99 | // Skip whitespace. | - | ||||||||||||||||||
| 100 | while (qt_isspace(s[index])) {
| 4644-12212 | ||||||||||||||||||
| 101 | compilerDirectiveExpected |= s[index] == '\n'; | - | ||||||||||||||||||
| 102 | ++index; | - | ||||||||||||||||||
| 103 | } executed 12212 times by 4 tests: end of blockExecuted by:
| 12212 | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | if (qt_isalpha(s[index])) {
| 2264-2380 | ||||||||||||||||||
| 106 | // Read identifier. | - | ||||||||||||||||||
| 107 | int idIndex = index; | - | ||||||||||||||||||
| 108 | ++index; | - | ||||||||||||||||||
| 109 | while (qt_isalnum(s[index]))
| 2264-12534 | ||||||||||||||||||
| 110 | ++index; executed 12534 times by 4 tests: ++index;Executed by:
| 12534 | ||||||||||||||||||
| 111 | int idLength = index - idIndex; | - | ||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | const int attrLen = sizeof("attribute") - 1; | - | ||||||||||||||||||
| 114 | const int inLen = sizeof("in") - 1; | - | ||||||||||||||||||
| 115 | const int uniLen = sizeof("uniform") - 1; | - | ||||||||||||||||||
| 116 | const int loLen = sizeof("lowp") - 1; | - | ||||||||||||||||||
| 117 | const int medLen = sizeof("mediump") - 1; | - | ||||||||||||||||||
| 118 | const int hiLen = sizeof("highp") - 1; | - | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | switch (expected) { | - | ||||||||||||||||||
| 121 | case QualifierIdentifier: executed 1678 times by 4 tests: case QualifierIdentifier:Executed by:
| 1678 | ||||||||||||||||||
| 122 | if (idLength == attrLen && qstrncmp("attribute", s + idIndex, attrLen) == 0) {
| 46-1530 | ||||||||||||||||||
| 123 | decl = AttributeQualifier; | - | ||||||||||||||||||
| 124 | expected = PrecisionIdentifier; | - | ||||||||||||||||||
| 125 | } else if (shaderType == QQuickOpenGLShaderEffectCommon::Key::VertexShader executed 46 times by 1 test: end of blockExecuted by:
| 46-1188 | ||||||||||||||||||
| 126 | && idLength == inLen && qstrncmp("in", s + idIndex, inLen) == 0) {
| 0-438 | ||||||||||||||||||
| 127 | decl = AttributeQualifier; | - | ||||||||||||||||||
| 128 | expected = PrecisionIdentifier; | - | ||||||||||||||||||
| 129 | } else if (idLength == uniLen && qstrncmp("uniform", s + idIndex, uniLen) == 0) { never executed: end of block
| 0-1350 | ||||||||||||||||||
| 130 | decl = UniformQualifier; | - | ||||||||||||||||||
| 131 | expected = PrecisionIdentifier; | - | ||||||||||||||||||
| 132 | } executed 168 times by 3 tests: end of blockExecuted by:
| 168 | ||||||||||||||||||
| 133 | break; executed 1678 times by 4 tests: break;Executed by:
| 1678 | ||||||||||||||||||
| 134 | case PrecisionIdentifier: executed 214 times by 3 tests: case PrecisionIdentifier:Executed by:
| 214 | ||||||||||||||||||
| 135 | if ((idLength == loLen && qstrncmp("lowp", s + idIndex, loLen) == 0)
| 6-110 | ||||||||||||||||||
| 136 | || (idLength == medLen && qstrncmp("mediump", s + idIndex, medLen) == 0)
| 0-112 | ||||||||||||||||||
| 137 | || (idLength == hiLen && qstrncmp("highp", s + idIndex, hiLen) == 0))
| 0-60 | ||||||||||||||||||
| 138 | { | - | ||||||||||||||||||
| 139 | expected = TypeIdentifier; | - | ||||||||||||||||||
| 140 | break; executed 162 times by 3 tests: break;Executed by:
| 162 | ||||||||||||||||||
| 141 | } | - | ||||||||||||||||||
| 142 | Q_FALLTHROUGH(); | - | ||||||||||||||||||
| 143 | case TypeIdentifier: code before this statement executed 52 times by 3 tests: case TypeIdentifier:Executed by:
executed 162 times by 3 tests: case TypeIdentifier:Executed by:
| 52-162 | ||||||||||||||||||
| 144 | typeIndex = idIndex; | - | ||||||||||||||||||
| 145 | typeLength = idLength; | - | ||||||||||||||||||
| 146 | expected = NameIdentifier; | - | ||||||||||||||||||
| 147 | break; executed 214 times by 3 tests: break;Executed by:
| 214 | ||||||||||||||||||
| 148 | case NameIdentifier: executed 210 times by 3 tests: case NameIdentifier:Executed by:
| 210 | ||||||||||||||||||
| 149 | nameIndex = idIndex; | - | ||||||||||||||||||
| 150 | nameLength = idLength; | - | ||||||||||||||||||
| 151 | return index; // Attribute or uniform declaration found. Return result. executed 210 times by 3 tests: return index;Executed by:
| 210 | ||||||||||||||||||
| 152 | default: never executed: default: | 0 | ||||||||||||||||||
| 153 | break; never executed: break; | 0 | ||||||||||||||||||
| 154 | } | - | ||||||||||||||||||
| 155 | } else if (s[index] == '#' && compilerDirectiveExpected) {
| 0-2352 | ||||||||||||||||||
| 156 | // Skip compiler directives. | - | ||||||||||||||||||
| 157 | ++index; | - | ||||||||||||||||||
| 158 | while (index < length && (s[index] != '\n' || s[index - 1] == '\\'))
| 4-348 | ||||||||||||||||||
| 159 | ++index; executed 324 times by 1 test: ++index;Executed by:
| 324 | ||||||||||||||||||
| 160 | } else if (s[index] == '/' && s[index + 1] == '/') { executed 28 times by 1 test: end of blockExecuted by:
| 28-2264 | ||||||||||||||||||
| 161 | // Skip comments. | - | ||||||||||||||||||
| 162 | index += 2; | - | ||||||||||||||||||
| 163 | while (index < length && s[index] != '\n')
| 4-1078 | ||||||||||||||||||
| 164 | ++index; executed 1040 times by 2 tests: ++index;Executed by:
| 1040 | ||||||||||||||||||
| 165 | } else if (s[index] == '/' && s[index + 1] == '*') { executed 42 times by 2 tests: end of blockExecuted by:
| 14-2264 | ||||||||||||||||||
| 166 | // Skip comments. | - | ||||||||||||||||||
| 167 | index += 2; | - | ||||||||||||||||||
| 168 | while (index < length && (s[index] != '*' || s[index + 1] != '/'))
| 0-342 | ||||||||||||||||||
| 169 | ++index; executed 310 times by 1 test: ++index;Executed by:
| 310 | ||||||||||||||||||
| 170 | if (index < length)
| 0-32 | ||||||||||||||||||
| 171 | index += 2; // Skip star-slash. executed 32 times by 1 test: index += 2;Executed by:
| 32 | ||||||||||||||||||
| 172 | } else { executed 32 times by 1 test: end of blockExecuted by:
| 32 | ||||||||||||||||||
| 173 | expected = QualifierIdentifier; | - | ||||||||||||||||||
| 174 | ++index; | - | ||||||||||||||||||
| 175 | } executed 2278 times by 4 tests: end of blockExecuted by:
| 2278 | ||||||||||||||||||
| 176 | compilerDirectiveExpected = false; | - | ||||||||||||||||||
| 177 | } executed 4434 times by 4 tests: end of blockExecuted by:
| 4434 | ||||||||||||||||||
| 178 | return -1; executed 146 times by 4 tests: return -1;Executed by:
| 146 | ||||||||||||||||||
| 179 | } | - | ||||||||||||||||||
| 180 | } | - | ||||||||||||||||||
| 181 | - | |||||||||||||||||||
| 182 | namespace QtPrivate { | - | ||||||||||||||||||
| 183 | class MappedSlotObject: public QtPrivate::QSlotObjectBase | - | ||||||||||||||||||
| 184 | { | - | ||||||||||||||||||
| 185 | public: | - | ||||||||||||||||||
| 186 | typedef std::function<void()> PropChangedFunc; | - | ||||||||||||||||||
| 187 | - | |||||||||||||||||||
| 188 | explicit MappedSlotObject(PropChangedFunc func) | - | ||||||||||||||||||
| 189 | : QSlotObjectBase(&impl), _signalIndex(-1), func(func) | - | ||||||||||||||||||
| 190 | { ref(); } executed 124 times by 5 tests: end of blockExecuted by:
| 124 | ||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | void setSignalIndex(int idx) { _signalIndex = idx; } executed 98 times by 5 tests: end of blockExecuted by:
| 98 | ||||||||||||||||||
| 193 | int signalIndex() const { return _signalIndex; } executed 106 times by 3 tests: return _signalIndex;Executed by:
| 106 | ||||||||||||||||||
| 194 | - | |||||||||||||||||||
| 195 | private: | - | ||||||||||||||||||
| 196 | int _signalIndex; | - | ||||||||||||||||||
| 197 | PropChangedFunc func; | - | ||||||||||||||||||
| 198 | - | |||||||||||||||||||
| 199 | static void impl(int which, QSlotObjectBase *this_, QObject *, void **a, bool *ret) | - | ||||||||||||||||||
| 200 | { | - | ||||||||||||||||||
| 201 | auto thiz = static_cast<MappedSlotObject*>(this_); | - | ||||||||||||||||||
| 202 | switch (which) { | - | ||||||||||||||||||
| 203 | case Destroy: executed 96 times by 4 tests: case Destroy:Executed by:
| 96 | ||||||||||||||||||
| 204 | delete thiz; | - | ||||||||||||||||||
| 205 | break; executed 96 times by 4 tests: break;Executed by:
| 96 | ||||||||||||||||||
| 206 | case Call: executed 16 times by 4 tests: case Call:Executed by:
| 16 | ||||||||||||||||||
| 207 | thiz->func(); | - | ||||||||||||||||||
| 208 | break; executed 16 times by 4 tests: break;Executed by:
| 16 | ||||||||||||||||||
| 209 | case Compare: executed 4 times by 1 test: case Compare:Executed by:
| 4 | ||||||||||||||||||
| 210 | *ret = thiz == reinterpret_cast<MappedSlotObject *>(a[0]); | - | ||||||||||||||||||
| 211 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||
| 212 | case NumOperations: ; never executed: case NumOperations: | 0 | ||||||||||||||||||
| 213 | } never executed: end of block | 0 | ||||||||||||||||||
| 214 | } executed 116 times by 4 tests: end of blockExecuted by:
| 116 | ||||||||||||||||||
| 215 | }; | - | ||||||||||||||||||
| 216 | } | - | ||||||||||||||||||
| 217 | - | |||||||||||||||||||
| 218 | QQuickOpenGLShaderEffectCommon::~QQuickOpenGLShaderEffectCommon() | - | ||||||||||||||||||
| 219 | { | - | ||||||||||||||||||
| 220 | for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType)
| 116-232 | ||||||||||||||||||
| 221 | clearSignalMappers(shaderType); executed 232 times by 5 tests: clearSignalMappers(shaderType);Executed by:
| 232 | ||||||||||||||||||
| 222 | } executed 116 times by 5 tests: end of blockExecuted by:
| 116 | ||||||||||||||||||
| 223 | - | |||||||||||||||||||
| 224 | void QQuickOpenGLShaderEffectCommon::disconnectPropertySignals(QQuickItem *item, Key::ShaderType shaderType) | - | ||||||||||||||||||
| 225 | { | - | ||||||||||||||||||
| 226 | for (int i = 0; i < uniformData[shaderType].size(); ++i) {
| 230-444 | ||||||||||||||||||
| 227 | if (signalMappers[shaderType].at(i) == 0)
| 106-124 | ||||||||||||||||||
| 228 | continue; executed 124 times by 4 tests: continue;Executed by:
| 124 | ||||||||||||||||||
| 229 | const UniformData &d = uniformData[shaderType].at(i); | - | ||||||||||||||||||
| 230 | auto mapper = signalMappers[shaderType].at(i); | - | ||||||||||||||||||
| 231 | void *a = mapper; | - | ||||||||||||||||||
| 232 | QObjectPrivate::disconnect(item, mapper->signalIndex(), &a); | - | ||||||||||||||||||
| 233 | if (d.specialType == UniformData::Sampler || d.specialType == UniformData::SamplerExternal) {
| 0-72 | ||||||||||||||||||
| 234 | QQuickItem *source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(d.value)); | - | ||||||||||||||||||
| 235 | if (source) {
| 15-57 | ||||||||||||||||||
| 236 | if (item->window())
| 4-11 | ||||||||||||||||||
| 237 | QQuickItemPrivate::get(source)->derefWindow(); executed 4 times by 1 test: QQuickItemPrivate::get(source)->derefWindow();Executed by:
| 4 | ||||||||||||||||||
| 238 | QObject::disconnect(source, SIGNAL(destroyed(QObject*)), host, SLOT(sourceDestroyed(QObject*))); | - | ||||||||||||||||||
| 239 | } executed 15 times by 3 tests: end of blockExecuted by:
| 15 | ||||||||||||||||||
| 240 | } executed 72 times by 3 tests: end of blockExecuted by:
| 72 | ||||||||||||||||||
| 241 | } executed 106 times by 3 tests: end of blockExecuted by:
| 106 | ||||||||||||||||||
| 242 | } executed 444 times by 6 tests: end of blockExecuted by:
| 444 | ||||||||||||||||||
| 243 | - | |||||||||||||||||||
| 244 | void QQuickOpenGLShaderEffectCommon::connectPropertySignals(QQuickItem *item, | - | ||||||||||||||||||
| 245 | const QMetaObject *itemMetaObject, | - | ||||||||||||||||||
| 246 | Key::ShaderType shaderType) | - | ||||||||||||||||||
| 247 | { | - | ||||||||||||||||||
| 248 | QQmlPropertyCache *propCache = QQmlData::ensurePropertyCache(qmlEngine(item), item); | - | ||||||||||||||||||
| 249 | for (int i = 0; i < uniformData[shaderType].size(); ++i) {
| 232-282 | ||||||||||||||||||
| 250 | if (signalMappers[shaderType].at(i) == 0)
| 124-158 | ||||||||||||||||||
| 251 | continue; executed 158 times by 6 tests: continue;Executed by:
| 158 | ||||||||||||||||||
| 252 | const UniformData &d = uniformData[shaderType].at(i); | - | ||||||||||||||||||
| 253 | QQmlPropertyData *pd = propCache->property(QString::fromUtf8(d.name), nullptr, nullptr); | - | ||||||||||||||||||
| 254 | if (pd && !pd->isFunction()) {
| 0-98 | ||||||||||||||||||
| 255 | if (pd->notifyIndex() == -1) {
| 0-98 | ||||||||||||||||||
| 256 | qWarning("QQuickOpenGLShaderEffect: property '%s' does not have notification method!", d.name.constData()); | - | ||||||||||||||||||
| 257 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 258 | auto *mapper = signalMappers[shaderType].at(i); | - | ||||||||||||||||||
| 259 | mapper->setSignalIndex(itemMetaObject->property(d.propertyIndex).notifySignal().methodIndex()); | - | ||||||||||||||||||
| 260 | Q_ASSERT(item->metaObject() == itemMetaObject); | - | ||||||||||||||||||
| 261 | bool ok = QObjectPrivate::connectImpl(item, pd->notifyIndex(), item, nullptr, mapper, | - | ||||||||||||||||||
| 262 | Qt::AutoConnection, nullptr, itemMetaObject); | - | ||||||||||||||||||
| 263 | if (!ok)
| 0-98 | ||||||||||||||||||
| 264 | qWarning() << "Failed to connect to property" << itemMetaObject->property(d.propertyIndex).name() never executed: QMessageLogger(__FILE__, 264, __PRETTY_FUNCTION__).warning() << "Failed to connect to property" << itemMetaObject->property(d.propertyIndex).name() << "(" << d.propertyIndex << ", signal index" << pd->notifyIndex() << ") of item" << item; | 0 | ||||||||||||||||||
| 265 | << "(" << d.propertyIndex << ", signal index" << pd->notifyIndex() never executed: QMessageLogger(__FILE__, 264, __PRETTY_FUNCTION__).warning() << "Failed to connect to property" << itemMetaObject->property(d.propertyIndex).name() << "(" << d.propertyIndex << ", signal index" << pd->notifyIndex() << ") of item" << item; | 0 | ||||||||||||||||||
| 266 | << ") of item" << item; never executed: QMessageLogger(__FILE__, 264, __PRETTY_FUNCTION__).warning() << "Failed to connect to property" << itemMetaObject->property(d.propertyIndex).name() << "(" << d.propertyIndex << ", signal index" << pd->notifyIndex() << ") of item" << item; | 0 | ||||||||||||||||||
| 267 | } executed 98 times by 5 tests: end of blockExecuted by:
| 98 | ||||||||||||||||||
| 268 | } else { | - | ||||||||||||||||||
| 269 | // If the source is set via a dynamic property, like the layer is, then we need this | - | ||||||||||||||||||
| 270 | // check to disable the warning. | - | ||||||||||||||||||
| 271 | if (!item->property(d.name).isValid())
| 0-26 | ||||||||||||||||||
| 272 | qWarning("QQuickOpenGLShaderEffect: '%s' does not have a matching property!", d.name.constData()); never executed: QMessageLogger(__FILE__, 272, __PRETTY_FUNCTION__).warning("QQuickOpenGLShaderEffect: '%s' does not have a matching property!", d.name.constData()); | 0 | ||||||||||||||||||
| 273 | } executed 26 times by 2 tests: end of blockExecuted by:
| 26 | ||||||||||||||||||
| 274 | - | |||||||||||||||||||
| 275 | if (d.specialType == UniformData::Sampler || d.specialType == UniformData::SamplerExternal) {
| 0-86 | ||||||||||||||||||
| 276 | QQuickItem *source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(d.value)); | - | ||||||||||||||||||
| 277 | if (source) {
| 18-68 | ||||||||||||||||||
| 278 | if (item->window())
| 2-66 | ||||||||||||||||||
| 279 | QQuickItemPrivate::get(source)->refWindow(item->window()); executed 66 times by 4 tests: QQuickItemPrivate::get(source)->refWindow(item->window());Executed by:
| 66 | ||||||||||||||||||
| 280 | QObject::connect(source, SIGNAL(destroyed(QObject*)), host, SLOT(sourceDestroyed(QObject*))); | - | ||||||||||||||||||
| 281 | } executed 68 times by 5 tests: end of blockExecuted by:
| 68 | ||||||||||||||||||
| 282 | } executed 86 times by 5 tests: end of blockExecuted by:
| 86 | ||||||||||||||||||
| 283 | } executed 124 times by 5 tests: end of blockExecuted by:
| 124 | ||||||||||||||||||
| 284 | } executed 232 times by 6 tests: end of blockExecuted by:
| 232 | ||||||||||||||||||
| 285 | - | |||||||||||||||||||
| 286 | void QQuickOpenGLShaderEffectCommon::updateParseLog(bool ignoreAttributes) | - | ||||||||||||||||||
| 287 | { | - | ||||||||||||||||||
| 288 | parseLog.clear(); | - | ||||||||||||||||||
| 289 | if (!ignoreAttributes) {
| 2-88 | ||||||||||||||||||
| 290 | if (!attributes.contains(qtPositionAttributeName())) {
| 20-68 | ||||||||||||||||||
| 291 | parseLog += QLatin1String("Warning: Missing reference to \'") | - | ||||||||||||||||||
| 292 | + QLatin1String(qtPositionAttributeName()) | - | ||||||||||||||||||
| 293 | + QLatin1String("\'.\n"); | - | ||||||||||||||||||
| 294 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 295 | if (!attributes.contains(qtTexCoordAttributeName())) {
| 28-60 | ||||||||||||||||||
| 296 | parseLog += QLatin1String("Warning: Missing reference to \'") | - | ||||||||||||||||||
| 297 | + QLatin1String(qtTexCoordAttributeName()) | - | ||||||||||||||||||
| 298 | + QLatin1String("\'.\n"); | - | ||||||||||||||||||
| 299 | } executed 28 times by 1 test: end of blockExecuted by:
| 28 | ||||||||||||||||||
| 300 | } executed 88 times by 4 tests: end of blockExecuted by:
| 88 | ||||||||||||||||||
| 301 | bool respectsMatrix = false; | - | ||||||||||||||||||
| 302 | bool respectsOpacity = false; | - | ||||||||||||||||||
| 303 | for (int i = 0; i < uniformData[Key::VertexShader].size(); ++i)
| 74-90 | ||||||||||||||||||
| 304 | respectsMatrix |= uniformData[Key::VertexShader].at(i).specialType == UniformData::Matrix; executed 74 times by 5 tests: respectsMatrix |= uniformData[Key::VertexShader].at(i).specialType == UniformData::Matrix;Executed by:
| 74 | ||||||||||||||||||
| 305 | for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) {
| 90-180 | ||||||||||||||||||
| 306 | for (int i = 0; i < uniformData[shaderType].size(); ++i)
| 180-188 | ||||||||||||||||||
| 307 | respectsOpacity |= uniformData[shaderType].at(i).specialType == UniformData::Opacity; executed 188 times by 5 tests: respectsOpacity |= uniformData[shaderType].at(i).specialType == UniformData::Opacity;Executed by:
| 188 | ||||||||||||||||||
| 308 | } executed 180 times by 5 tests: end of blockExecuted by:
| 180 | ||||||||||||||||||
| 309 | if (!respectsMatrix)
| 24-66 | ||||||||||||||||||
| 310 | parseLog += QLatin1String("Warning: Vertex shader is missing reference to \'qt_Matrix\'.\n"); executed 24 times by 1 test: parseLog += QLatin1String("Warning: Vertex shader is missing reference to \'qt_Matrix\'.\n");Executed by:
| 24 | ||||||||||||||||||
| 311 | if (!respectsOpacity)
| 32-58 | ||||||||||||||||||
| 312 | parseLog += QLatin1String("Warning: Shaders are missing reference to \'qt_Opacity\'.\n"); executed 58 times by 4 tests: parseLog += QLatin1String("Warning: Shaders are missing reference to \'qt_Opacity\'.\n");Executed by:
| 58 | ||||||||||||||||||
| 313 | } executed 90 times by 5 tests: end of blockExecuted by:
| 90 | ||||||||||||||||||
| 314 | - | |||||||||||||||||||
| 315 | void QQuickOpenGLShaderEffectCommon::lookThroughShaderCode(QQuickItem *item, | - | ||||||||||||||||||
| 316 | const QMetaObject *itemMetaObject, | - | ||||||||||||||||||
| 317 | Key::ShaderType shaderType, | - | ||||||||||||||||||
| 318 | const QByteArray &code) | - | ||||||||||||||||||
| 319 | { | - | ||||||||||||||||||
| 320 | QQmlPropertyCache *propCache = QQmlData::ensurePropertyCache(qmlEngine(item), item); | - | ||||||||||||||||||
| 321 | int index = 0; | - | ||||||||||||||||||
| 322 | int typeIndex = -1; | - | ||||||||||||||||||
| 323 | int typeLength = 0; | - | ||||||||||||||||||
| 324 | int nameIndex = -1; | - | ||||||||||||||||||
| 325 | int nameLength = 0; | - | ||||||||||||||||||
| 326 | const char *s = code.constData(); | - | ||||||||||||||||||
| 327 | VariableQualifier decl = AttributeQualifier; | - | ||||||||||||||||||
| 328 | while ((index = qt_search_for_variable(s, code.size(), index, decl, typeIndex, typeLength,
| 146-210 | ||||||||||||||||||
| 329 | nameIndex, nameLength, shaderType)) != -1)
| 146-210 | ||||||||||||||||||
| 330 | { | - | ||||||||||||||||||
| 331 | if (decl == AttributeQualifier) {
| 44-166 | ||||||||||||||||||
| 332 | if (shaderType == Key::VertexShader)
| 0-44 | ||||||||||||||||||
| 333 | attributes.append(QByteArray(s + nameIndex, nameLength)); executed 44 times by 1 test: attributes.append(QByteArray(s + nameIndex, nameLength));Executed by:
| 44 | ||||||||||||||||||
| 334 | } else { executed 44 times by 1 test: end of blockExecuted by:
| 44 | ||||||||||||||||||
| 335 | Q_ASSERT(decl == UniformQualifier); | - | ||||||||||||||||||
| 336 | - | |||||||||||||||||||
| 337 | const int sampLen = sizeof("sampler2D") - 1; | - | ||||||||||||||||||
| 338 | const int sampExtLen = sizeof("samplerExternalOES") - 1; | - | ||||||||||||||||||
| 339 | const int opLen = sizeof("qt_Opacity") - 1; | - | ||||||||||||||||||
| 340 | const int matLen = sizeof("qt_Matrix") - 1; | - | ||||||||||||||||||
| 341 | const int srLen = sizeof("qt_SubRect_") - 1; | - | ||||||||||||||||||
| 342 | - | |||||||||||||||||||
| 343 | UniformData d; | - | ||||||||||||||||||
| 344 | QtPrivate::MappedSlotObject *mapper = nullptr; | - | ||||||||||||||||||
| 345 | d.name = QByteArray(s + nameIndex, nameLength); | - | ||||||||||||||||||
| 346 | if (nameLength == opLen && qstrncmp("qt_Opacity", s + nameIndex, opLen) == 0) {
| 2-120 | ||||||||||||||||||
| 347 | d.specialType = UniformData::Opacity; | - | ||||||||||||||||||
| 348 | } else if (nameLength == matLen && qstrncmp("qt_Matrix", s + nameIndex, matLen) == 0) { executed 44 times by 3 tests: end of blockExecuted by:
| 6-104 | ||||||||||||||||||
| 349 | d.specialType = UniformData::Matrix; | - | ||||||||||||||||||
| 350 | } else if (nameLength > srLen && qstrncmp("qt_SubRect_", s + nameIndex, srLen) == 0) { executed 12 times by 1 test: end of blockExecuted by:
| 0-106 | ||||||||||||||||||
| 351 | d.specialType = UniformData::SubRect; | - | ||||||||||||||||||
| 352 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 353 | if (QQmlPropertyData *pd = propCache->property(QString::fromUtf8(d.name), nullptr, nullptr)) {
| 24-86 | ||||||||||||||||||
| 354 | if (!pd->isFunction())
| 0-86 | ||||||||||||||||||
| 355 | d.propertyIndex = pd->coreIndex(); executed 86 times by 3 tests: d.propertyIndex = pd->coreIndex();Executed by:
| 86 | ||||||||||||||||||
| 356 | } executed 86 times by 3 tests: end of blockExecuted by:
| 86 | ||||||||||||||||||
| 357 | const int mappedId = uniformData[shaderType].size() | (shaderType << 16); | - | ||||||||||||||||||
| 358 | mapper = new QtPrivate::MappedSlotObject([this, mappedId](){ | - | ||||||||||||||||||
| 359 | this->mappedPropertyChanged(mappedId); | - | ||||||||||||||||||
| 360 | }); executed 8 times by 2 tests: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 361 | if (typeLength == sampLen && qstrncmp("sampler2D", s + typeIndex, sampLen) == 0)
| 0-72 | ||||||||||||||||||
| 362 | d.specialType = UniformData::Sampler; executed 72 times by 3 tests: d.specialType = UniformData::Sampler;Executed by:
| 72 | ||||||||||||||||||
| 363 | else if (typeLength == sampExtLen && qstrncmp("samplerExternalOES", s + typeIndex, sampExtLen) == 0)
| 0-38 | ||||||||||||||||||
| 364 | d.specialType = UniformData::SamplerExternal; never executed: d.specialType = UniformData::SamplerExternal; | 0 | ||||||||||||||||||
| 365 | else | - | ||||||||||||||||||
| 366 | d.specialType = UniformData::None; executed 38 times by 2 tests: d.specialType = UniformData::None;Executed by:
| 38 | ||||||||||||||||||
| 367 | d.setValueFromProperty(item, itemMetaObject); | - | ||||||||||||||||||
| 368 | } executed 110 times by 3 tests: end of blockExecuted by:
| 110 | ||||||||||||||||||
| 369 | uniformData[shaderType].append(d); | - | ||||||||||||||||||
| 370 | signalMappers[shaderType].append(mapper); | - | ||||||||||||||||||
| 371 | } executed 166 times by 3 tests: end of blockExecuted by:
| 166 | ||||||||||||||||||
| 372 | } | - | ||||||||||||||||||
| 373 | } executed 146 times by 4 tests: end of blockExecuted by:
| 146 | ||||||||||||||||||
| 374 | - | |||||||||||||||||||
| 375 | void QQuickOpenGLShaderEffectCommon::updateShader(QQuickItem *item, | - | ||||||||||||||||||
| 376 | const QMetaObject *itemMetaObject, | - | ||||||||||||||||||
| 377 | Key::ShaderType shaderType) | - | ||||||||||||||||||
| 378 | { | - | ||||||||||||||||||
| 379 | disconnectPropertySignals(item, shaderType); | - | ||||||||||||||||||
| 380 | uniformData[shaderType].clear(); | - | ||||||||||||||||||
| 381 | clearSignalMappers(shaderType); | - | ||||||||||||||||||
| 382 | if (shaderType == Key::VertexShader)
| 104-118 | ||||||||||||||||||
| 383 | attributes.clear(); executed 104 times by 5 tests: attributes.clear();Executed by:
| 104 | ||||||||||||||||||
| 384 | - | |||||||||||||||||||
| 385 | // A qrc or file URL means the shader source is to be read from the specified file. | - | ||||||||||||||||||
| 386 | QUrl srcUrl(QString::fromUtf8(source.sourceCode[shaderType])); | - | ||||||||||||||||||
| 387 | if (!srcUrl.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) || srcUrl.isLocalFile()) {
| 0-222 | ||||||||||||||||||
| 388 | if (!fileSelector) {
| 0 | ||||||||||||||||||
| 389 | fileSelector = new QFileSelector(item); | - | ||||||||||||||||||
| 390 | // There may not be an OpenGL context accessible here. So rely on | - | ||||||||||||||||||
| 391 | // the window's requestedFormat(). | - | ||||||||||||||||||
| 392 | if (item->window()
| 0 | ||||||||||||||||||
| 393 | && item->window()->requestedFormat().profile() == QSurfaceFormat::CoreProfile) {
| 0 | ||||||||||||||||||
| 394 | fileSelector->setExtraSelectors(QStringList() << QStringLiteral("glslcore")); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 395 | } never executed: end of block | 0 | ||||||||||||||||||
| 396 | } never executed: end of block | 0 | ||||||||||||||||||
| 397 | const QString fn = fileSelector->select(QQmlFile::urlToLocalFileOrQrc(srcUrl)); | - | ||||||||||||||||||
| 398 | QFile f(fn); | - | ||||||||||||||||||
| 399 | if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
| 0 | ||||||||||||||||||
| 400 | source.sourceCode[shaderType] = f.readAll(); | - | ||||||||||||||||||
| 401 | f.close(); | - | ||||||||||||||||||
| 402 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 403 | qWarning("ShaderEffect: Failed to read %s", qPrintable(fn)); | - | ||||||||||||||||||
| 404 | source.sourceCode[shaderType] = QByteArray(); | - | ||||||||||||||||||
| 405 | } never executed: end of block | 0 | ||||||||||||||||||
| 406 | } | - | ||||||||||||||||||
| 407 | - | |||||||||||||||||||
| 408 | const QByteArray &code = source.sourceCode[shaderType]; | - | ||||||||||||||||||
| 409 | if (code.isEmpty()) {
| 82-140 | ||||||||||||||||||
| 410 | // Optimize for default code. | - | ||||||||||||||||||
| 411 | if (shaderType == Key::VertexShader) {
| 14-68 | ||||||||||||||||||
| 412 | attributes.append(QByteArray(qtPositionAttributeName())); | - | ||||||||||||||||||
| 413 | attributes.append(QByteArray(qtTexCoordAttributeName())); | - | ||||||||||||||||||
| 414 | UniformData d; | - | ||||||||||||||||||
| 415 | d.name = "qt_Matrix"; | - | ||||||||||||||||||
| 416 | d.specialType = UniformData::Matrix; | - | ||||||||||||||||||
| 417 | uniformData[Key::VertexShader].append(d); | - | ||||||||||||||||||
| 418 | signalMappers[Key::VertexShader].append(0); | - | ||||||||||||||||||
| 419 | } else if (shaderType == Key::FragmentShader) { executed 68 times by 5 tests: end of blockExecuted by:
| 0-68 | ||||||||||||||||||
| 420 | UniformData d; | - | ||||||||||||||||||
| 421 | d.name = "qt_Opacity"; | - | ||||||||||||||||||
| 422 | d.specialType = UniformData::Opacity; | - | ||||||||||||||||||
| 423 | uniformData[Key::FragmentShader].append(d); | - | ||||||||||||||||||
| 424 | signalMappers[Key::FragmentShader].append(0); | - | ||||||||||||||||||
| 425 | auto mapper = new QtPrivate::MappedSlotObject([this](){ | - | ||||||||||||||||||
| 426 | mappedPropertyChanged(1 | (Key::FragmentShader << 16)); | - | ||||||||||||||||||
| 427 | }); executed 8 times by 3 tests: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 428 | const char *sourceName = "source"; | - | ||||||||||||||||||
| 429 | d.name = sourceName; | - | ||||||||||||||||||
| 430 | d.setValueFromProperty(item, itemMetaObject); | - | ||||||||||||||||||
| 431 | d.specialType = UniformData::Sampler; | - | ||||||||||||||||||
| 432 | uniformData[Key::FragmentShader].append(d); | - | ||||||||||||||||||
| 433 | signalMappers[Key::FragmentShader].append(mapper); | - | ||||||||||||||||||
| 434 | } executed 14 times by 4 tests: end of blockExecuted by:
| 14 | ||||||||||||||||||
| 435 | } else { executed 82 times by 6 tests: end of blockExecuted by:
| 82 | ||||||||||||||||||
| 436 | lookThroughShaderCode(item, itemMetaObject, shaderType, code); | - | ||||||||||||||||||
| 437 | } executed 140 times by 4 tests: end of blockExecuted by:
| 140 | ||||||||||||||||||
| 438 | - | |||||||||||||||||||
| 439 | connectPropertySignals(item, itemMetaObject, shaderType); | - | ||||||||||||||||||
| 440 | } executed 222 times by 6 tests: end of blockExecuted by:
| 222 | ||||||||||||||||||
| 441 | - | |||||||||||||||||||
| 442 | void QQuickOpenGLShaderEffectCommon::updateMaterial(QQuickOpenGLShaderEffectNode *node, | - | ||||||||||||||||||
| 443 | QQuickOpenGLShaderEffectMaterial *material, | - | ||||||||||||||||||
| 444 | bool updateUniforms, bool updateUniformValues, | - | ||||||||||||||||||
| 445 | bool updateTextureProviders) | - | ||||||||||||||||||
| 446 | { | - | ||||||||||||||||||
| 447 | if (updateUniforms) {
| 73-278 | ||||||||||||||||||
| 448 | for (int i = 0; i < material->textureProviders.size(); ++i) {
| 0-73 | ||||||||||||||||||
| 449 | QSGTextureProvider *t = material->textureProviders.at(i); | - | ||||||||||||||||||
| 450 | if (t) {
| 0 | ||||||||||||||||||
| 451 | QObject::disconnect(t, SIGNAL(textureChanged()), node, SLOT(markDirtyTexture())); | - | ||||||||||||||||||
| 452 | QObject::disconnect(t, SIGNAL(destroyed(QObject*)), node, SLOT(textureProviderDestroyed(QObject*))); | - | ||||||||||||||||||
| 453 | } never executed: end of block | 0 | ||||||||||||||||||
| 454 | } never executed: end of block | 0 | ||||||||||||||||||
| 455 | - | |||||||||||||||||||
| 456 | // First make room in the textureProviders array. Set to proper value further down. | - | ||||||||||||||||||
| 457 | int textureProviderCount = 0; | - | ||||||||||||||||||
| 458 | for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) {
| 73-146 | ||||||||||||||||||
| 459 | for (int i = 0; i < uniformData[shaderType].size(); ++i) {
| 146-213 | ||||||||||||||||||
| 460 | if (uniformData[shaderType].at(i).specialType == UniformData::Sampler ||
| 66-147 | ||||||||||||||||||
| 461 | uniformData[shaderType].at(i).specialType == UniformData::SamplerExternal)
| 0-147 | ||||||||||||||||||
| 462 | ++textureProviderCount; executed 66 times by 5 tests: ++textureProviderCount;Executed by:
| 66 | ||||||||||||||||||
| 463 | } executed 213 times by 6 tests: end of blockExecuted by:
| 213 | ||||||||||||||||||
| 464 | material->uniforms[shaderType] = uniformData[shaderType]; | - | ||||||||||||||||||
| 465 | } executed 146 times by 6 tests: end of blockExecuted by:
| 146 | ||||||||||||||||||
| 466 | material->textureProviders.fill(0, textureProviderCount); | - | ||||||||||||||||||
| 467 | updateUniformValues = false; | - | ||||||||||||||||||
| 468 | updateTextureProviders = true; | - | ||||||||||||||||||
| 469 | } executed 73 times by 6 tests: end of blockExecuted by:
| 73 | ||||||||||||||||||
| 470 | - | |||||||||||||||||||
| 471 | if (updateUniformValues) {
| 73-278 | ||||||||||||||||||
| 472 | for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) {
| 278-556 | ||||||||||||||||||
| 473 | Q_ASSERT(uniformData[shaderType].size() == material->uniforms[shaderType].size()); | - | ||||||||||||||||||
| 474 | for (int i = 0; i < uniformData[shaderType].size(); ++i)
| 556-1112 | ||||||||||||||||||
| 475 | material->uniforms[shaderType][i].value = uniformData[shaderType].at(i).value; executed 1112 times by 1 test: material->uniforms[shaderType][i].value = uniformData[shaderType].at(i).value;Executed by:
| 1112 | ||||||||||||||||||
| 476 | } executed 556 times by 1 test: end of blockExecuted by:
| 556 | ||||||||||||||||||
| 477 | } executed 278 times by 1 test: end of blockExecuted by:
| 278 | ||||||||||||||||||
| 478 | - | |||||||||||||||||||
| 479 | if (updateTextureProviders) {
| 73-278 | ||||||||||||||||||
| 480 | int index = 0; | - | ||||||||||||||||||
| 481 | for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) {
| 73-146 | ||||||||||||||||||
| 482 | for (int i = 0; i < uniformData[shaderType].size(); ++i) {
| 146-213 | ||||||||||||||||||
| 483 | const UniformData &d = uniformData[shaderType].at(i); | - | ||||||||||||||||||
| 484 | if (d.specialType != UniformData::Sampler && d.specialType != UniformData::SamplerExternal)
| 0-147 | ||||||||||||||||||
| 485 | continue; executed 147 times by 6 tests: continue;Executed by:
| 147 | ||||||||||||||||||
| 486 | QSGTextureProvider *oldProvider = material->textureProviders.at(index); | - | ||||||||||||||||||
| 487 | QSGTextureProvider *newProvider = nullptr; | - | ||||||||||||||||||
| 488 | QQuickItem *source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(d.value)); | - | ||||||||||||||||||
| 489 | if (source && source->isTextureProvider())
| 0-62 | ||||||||||||||||||
| 490 | newProvider = source->textureProvider(); executed 62 times by 5 tests: newProvider = source->textureProvider();Executed by:
| 62 | ||||||||||||||||||
| 491 | if (newProvider != oldProvider) {
| 4-62 | ||||||||||||||||||
| 492 | if (oldProvider) {
| 0-62 | ||||||||||||||||||
| 493 | QObject::disconnect(oldProvider, SIGNAL(textureChanged()), node, SLOT(markDirtyTexture())); | - | ||||||||||||||||||
| 494 | QObject::disconnect(oldProvider, SIGNAL(destroyed(QObject*)), node, SLOT(textureProviderDestroyed(QObject*))); | - | ||||||||||||||||||
| 495 | } never executed: end of block | 0 | ||||||||||||||||||
| 496 | if (newProvider) {
| 0-62 | ||||||||||||||||||
| 497 | Q_ASSERT_X(newProvider->thread() == QThread::currentThread(), | - | ||||||||||||||||||
| 498 | "QQuickOpenGLShaderEffect::updatePaintNode", | - | ||||||||||||||||||
| 499 | "Texture provider must belong to the rendering thread"); | - | ||||||||||||||||||
| 500 | QObject::connect(newProvider, SIGNAL(textureChanged()), node, SLOT(markDirtyTexture())); | - | ||||||||||||||||||
| 501 | QObject::connect(newProvider, SIGNAL(destroyed(QObject*)), node, SLOT(textureProviderDestroyed(QObject*))); | - | ||||||||||||||||||
| 502 | } else { executed 62 times by 5 tests: end of blockExecuted by:
| 62 | ||||||||||||||||||
| 503 | const char *typeName = source ? source->metaObject()->className() : d.value.typeName();
| 0 | ||||||||||||||||||
| 504 | qWarning("ShaderEffect: Property '%s' is not assigned a valid texture provider (%s).", | - | ||||||||||||||||||
| 505 | d.name.constData(), typeName); | - | ||||||||||||||||||
| 506 | } never executed: end of block | 0 | ||||||||||||||||||
| 507 | material->textureProviders[index] = newProvider; | - | ||||||||||||||||||
| 508 | } executed 62 times by 5 tests: end of blockExecuted by:
| 62 | ||||||||||||||||||
| 509 | ++index; | - | ||||||||||||||||||
| 510 | } executed 66 times by 5 tests: end of blockExecuted by:
| 66 | ||||||||||||||||||
| 511 | } executed 146 times by 6 tests: end of blockExecuted by:
| 146 | ||||||||||||||||||
| 512 | Q_ASSERT(index == material->textureProviders.size()); | - | ||||||||||||||||||
| 513 | } executed 73 times by 6 tests: end of blockExecuted by:
| 73 | ||||||||||||||||||
| 514 | } executed 351 times by 6 tests: end of blockExecuted by:
| 351 | ||||||||||||||||||
| 515 | - | |||||||||||||||||||
| 516 | void QQuickOpenGLShaderEffectCommon::updateWindow(QQuickWindow *window) | - | ||||||||||||||||||
| 517 | { | - | ||||||||||||||||||
| 518 | // See comment in QQuickOpenGLShaderEffectCommon::propertyChanged(). | - | ||||||||||||||||||
| 519 | if (window) {
| 77-79 | ||||||||||||||||||
| 520 | for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) {
| 79-158 | ||||||||||||||||||
| 521 | for (int i = 0; i < uniformData[shaderType].size(); ++i) {
| 16-158 | ||||||||||||||||||
| 522 | const UniformData &d = uniformData[shaderType].at(i); | - | ||||||||||||||||||
| 523 | if (d.specialType == UniformData::Sampler || d.specialType == UniformData::SamplerExternal) {
| 0-12 | ||||||||||||||||||
| 524 | QQuickItem *source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(d.value)); | - | ||||||||||||||||||
| 525 | if (source)
| 2 | ||||||||||||||||||
| 526 | QQuickItemPrivate::get(source)->refWindow(window); executed 2 times by 1 test: QQuickItemPrivate::get(source)->refWindow(window);Executed by:
| 2 | ||||||||||||||||||
| 527 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 528 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 529 | } executed 158 times by 6 tests: end of blockExecuted by:
| 158 | ||||||||||||||||||
| 530 | } else { executed 79 times by 6 tests: end of blockExecuted by:
| 79 | ||||||||||||||||||
| 531 | for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) {
| 77-154 | ||||||||||||||||||
| 532 | for (int i = 0; i < uniformData[shaderType].size(); ++i) {
| 154-224 | ||||||||||||||||||
| 533 | const UniformData &d = uniformData[shaderType].at(i); | - | ||||||||||||||||||
| 534 | if (d.specialType == UniformData::Sampler || d.specialType == UniformData::SamplerExternal) {
| 0-154 | ||||||||||||||||||
| 535 | QQuickItem *source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(d.value)); | - | ||||||||||||||||||
| 536 | if (source)
| 4-66 | ||||||||||||||||||
| 537 | QQuickItemPrivate::get(source)->derefWindow(); executed 66 times by 4 tests: QQuickItemPrivate::get(source)->derefWindow();Executed by:
| 66 | ||||||||||||||||||
| 538 | } executed 70 times by 4 tests: end of blockExecuted by:
| 70 | ||||||||||||||||||
| 539 | } executed 224 times by 5 tests: end of blockExecuted by:
| 224 | ||||||||||||||||||
| 540 | } executed 154 times by 5 tests: end of blockExecuted by:
| 154 | ||||||||||||||||||
| 541 | } executed 77 times by 5 tests: end of blockExecuted by:
| 77 | ||||||||||||||||||
| 542 | } | - | ||||||||||||||||||
| 543 | - | |||||||||||||||||||
| 544 | void QQuickOpenGLShaderEffectCommon::sourceDestroyed(QObject *object) | - | ||||||||||||||||||
| 545 | { | - | ||||||||||||||||||
| 546 | for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) {
| 47-94 | ||||||||||||||||||
| 547 | for (int i = 0; i < uniformData[shaderType].size(); ++i) {
| 94-140 | ||||||||||||||||||
| 548 | UniformData &d = uniformData[shaderType][i]; | - | ||||||||||||||||||
| 549 | if ((d.specialType == UniformData::Sampler || d.specialType == UniformData::SamplerExternal) && d.value.canConvert<QObject *>()) {
| 0-87 | ||||||||||||||||||
| 550 | if (qvariant_cast<QObject *>(d.value) == object)
| 4-47 | ||||||||||||||||||
| 551 | d.value = QVariant(); executed 47 times by 3 tests: d.value = QVariant();Executed by:
| 47 | ||||||||||||||||||
| 552 | } executed 51 times by 3 tests: end of blockExecuted by:
| 51 | ||||||||||||||||||
| 553 | } executed 140 times by 3 tests: end of blockExecuted by:
| 140 | ||||||||||||||||||
| 554 | } executed 94 times by 3 tests: end of blockExecuted by:
| 94 | ||||||||||||||||||
| 555 | } executed 47 times by 3 tests: end of blockExecuted by:
| 47 | ||||||||||||||||||
| 556 | - | |||||||||||||||||||
| 557 | static bool qquick_uniqueInUniformData(QQuickItem *source, const QVector<QQuickOpenGLShaderEffectMaterial::UniformData> *uniformData, int typeToSkip, int indexToSkip) | - | ||||||||||||||||||
| 558 | { | - | ||||||||||||||||||
| 559 | for (int s=0; s<QQuickOpenGLShaderEffectMaterialKey::ShaderTypeCount; ++s) {
| 0 | ||||||||||||||||||
| 560 | for (int i=0; i<uniformData[s].size(); ++i) {
| 0 | ||||||||||||||||||
| 561 | if (s == typeToSkip && i == indexToSkip)
| 0 | ||||||||||||||||||
| 562 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 563 | const QQuickOpenGLShaderEffectMaterial::UniformData &d = uniformData[s][i]; | - | ||||||||||||||||||
| 564 | if ((d.specialType == QQuickOpenGLShaderEffectMaterial::UniformData::Sampler || d.specialType == QQuickOpenGLShaderEffectMaterial::UniformData::SamplerExternal) && qvariant_cast<QObject *>(d.value) == source)
| 0 | ||||||||||||||||||
| 565 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 566 | } never executed: end of block | 0 | ||||||||||||||||||
| 567 | } never executed: end of block | 0 | ||||||||||||||||||
| 568 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 569 | } | - | ||||||||||||||||||
| 570 | - | |||||||||||||||||||
| 571 | void QQuickOpenGLShaderEffectCommon::propertyChanged(QQuickItem *item, | - | ||||||||||||||||||
| 572 | const QMetaObject *itemMetaObject, | - | ||||||||||||||||||
| 573 | int mappedId, bool *textureProviderChanged) | - | ||||||||||||||||||
| 574 | { | - | ||||||||||||||||||
| 575 | Key::ShaderType shaderType = Key::ShaderType(mappedId >> 16); | - | ||||||||||||||||||
| 576 | int index = mappedId & 0xffff; | - | ||||||||||||||||||
| 577 | UniformData &d = uniformData[shaderType][index]; | - | ||||||||||||||||||
| 578 | if (d.specialType == UniformData::Sampler || d.specialType == UniformData::SamplerExternal) {
| 0-12 | ||||||||||||||||||
| 579 | QQuickItem *source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(d.value)); | - | ||||||||||||||||||
| 580 | if (source) {
| 0-12 | ||||||||||||||||||
| 581 | if (item->window())
| 0 | ||||||||||||||||||
| 582 | QQuickItemPrivate::get(source)->derefWindow(); never executed: QQuickItemPrivate::get(source)->derefWindow(); | 0 | ||||||||||||||||||
| 583 | - | |||||||||||||||||||
| 584 | // QObject::disconnect() will disconnect all matching connections. If the same | - | ||||||||||||||||||
| 585 | // source has been attached to two separate samplers, then changing one of them | - | ||||||||||||||||||
| 586 | // would trigger both to be disconnected. Without the connection we'll end up | - | ||||||||||||||||||
| 587 | // with a dangling pointer in the uniformData. | - | ||||||||||||||||||
| 588 | if (qquick_uniqueInUniformData(source, uniformData, shaderType, index))
| 0 | ||||||||||||||||||
| 589 | QObject::disconnect(source, SIGNAL(destroyed(QObject*)), host, SLOT(sourceDestroyed(QObject*))); never executed: QObject::disconnect(source, qFlagLocation("2""destroyed(QObject*)" "\0" __FILE__ ":" "589"), host, qFlagLocation("1""sourceDestroyed(QObject*)" "\0" __FILE__ ":" "589")); | 0 | ||||||||||||||||||
| 590 | } never executed: end of block | 0 | ||||||||||||||||||
| 591 | - | |||||||||||||||||||
| 592 | d.setValueFromProperty(item, itemMetaObject); | - | ||||||||||||||||||
| 593 | - | |||||||||||||||||||
| 594 | source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(d.value)); | - | ||||||||||||||||||
| 595 | if (source) {
| 6 | ||||||||||||||||||
| 596 | // 'source' needs a window to get a scene graph node. It usually gets one through its | - | ||||||||||||||||||
| 597 | // parent, but if the source item is "inline" rather than a reference -- i.e. | - | ||||||||||||||||||
| 598 | // "property variant source: Image { }" instead of "property variant source: foo" -- it | - | ||||||||||||||||||
| 599 | // will not get a parent. In those cases, 'source' should get the window from 'item'. | - | ||||||||||||||||||
| 600 | if (item->window())
| 0-6 | ||||||||||||||||||
| 601 | QQuickItemPrivate::get(source)->refWindow(item->window()); executed 6 times by 2 tests: QQuickItemPrivate::get(source)->refWindow(item->window());Executed by:
| 6 | ||||||||||||||||||
| 602 | QObject::connect(source, SIGNAL(destroyed(QObject*)), host, SLOT(sourceDestroyed(QObject*))); | - | ||||||||||||||||||
| 603 | } executed 6 times by 2 tests: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 604 | if (textureProviderChanged)
| 0-12 | ||||||||||||||||||
| 605 | *textureProviderChanged = true; executed 12 times by 4 tests: *textureProviderChanged = true;Executed by:
| 12 | ||||||||||||||||||
| 606 | } else { executed 12 times by 4 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 607 | d.setValueFromProperty(item, itemMetaObject); | - | ||||||||||||||||||
| 608 | if (textureProviderChanged)
| 0-4 | ||||||||||||||||||
| 609 | *textureProviderChanged = false; executed 4 times by 1 test: *textureProviderChanged = false;Executed by:
| 4 | ||||||||||||||||||
| 610 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 611 | } | - | ||||||||||||||||||
| 612 | - | |||||||||||||||||||
| 613 | void QQuickOpenGLShaderEffectCommon::clearSignalMappers(int shader) | - | ||||||||||||||||||
| 614 | { | - | ||||||||||||||||||
| 615 | for (auto mapper : qAsConst(signalMappers[shader])) { | - | ||||||||||||||||||
| 616 | if (mapper)
| 122-154 | ||||||||||||||||||
| 617 | mapper->destroyIfLastRef(); executed 122 times by 4 tests: mapper->destroyIfLastRef();Executed by:
| 122 | ||||||||||||||||||
| 618 | } executed 276 times by 5 tests: end of blockExecuted by:
| 276 | ||||||||||||||||||
| 619 | signalMappers[shader].clear(); | - | ||||||||||||||||||
| 620 | } executed 464 times by 6 tests: end of blockExecuted by:
| 464 | ||||||||||||||||||
| 621 | - | |||||||||||||||||||
| 622 | QQuickOpenGLShaderEffect::QQuickOpenGLShaderEffect(QQuickShaderEffect *item, QObject *parent) | - | ||||||||||||||||||
| 623 | : QObject(parent) | - | ||||||||||||||||||
| 624 | , m_item(item) | - | ||||||||||||||||||
| 625 | , m_itemMetaObject(nullptr) | - | ||||||||||||||||||
| 626 | , m_meshResolution(1, 1) | - | ||||||||||||||||||
| 627 | , m_mesh(nullptr) | - | ||||||||||||||||||
| 628 | , m_cullMode(QQuickShaderEffect::NoCulling) | - | ||||||||||||||||||
| 629 | , m_status(QQuickShaderEffect::Uncompiled) | - | ||||||||||||||||||
| 630 | , m_common(this, [this](int mappedId){this->propertyChanged(mappedId);}) | - | ||||||||||||||||||
| 631 | , m_blending(true) | - | ||||||||||||||||||
| 632 | , m_dirtyUniforms(true) | - | ||||||||||||||||||
| 633 | , m_dirtyUniformValues(true) | - | ||||||||||||||||||
| 634 | , m_dirtyTextureProviders(true) | - | ||||||||||||||||||
| 635 | , m_dirtyProgram(true) | - | ||||||||||||||||||
| 636 | , m_dirtyParseLog(true) | - | ||||||||||||||||||
| 637 | , m_dirtyMesh(true) | - | ||||||||||||||||||
| 638 | , m_dirtyGeometry(true) | - | ||||||||||||||||||
| 639 | , m_customVertexShader(false) | - | ||||||||||||||||||
| 640 | , m_supportsAtlasTextures(false) | - | ||||||||||||||||||
| 641 | , m_vertNeedsUpdate(true) | - | ||||||||||||||||||
| 642 | , m_fragNeedsUpdate(true) | - | ||||||||||||||||||
| 643 | { | - | ||||||||||||||||||
| 644 | } executed 108 times by 5 tests: end of blockExecuted by:
| 108 | ||||||||||||||||||
| 645 | - | |||||||||||||||||||
| 646 | QQuickOpenGLShaderEffect::~QQuickOpenGLShaderEffect() | - | ||||||||||||||||||
| 647 | { | - | ||||||||||||||||||
| 648 | for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType)
| 106-212 | ||||||||||||||||||
| 649 | m_common.disconnectPropertySignals(m_item, Key::ShaderType(shaderType)); executed 212 times by 4 tests: m_common.disconnectPropertySignals(m_item, Key::ShaderType(shaderType));Executed by:
| 212 | ||||||||||||||||||
| 650 | } executed 106 times by 4 tests: end of blockExecuted by:
| 106 | ||||||||||||||||||
| 651 | - | |||||||||||||||||||
| 652 | void QQuickOpenGLShaderEffect::setFragmentShader(const QByteArray &code) | - | ||||||||||||||||||
| 653 | { | - | ||||||||||||||||||
| 654 | if (m_common.source.sourceCode[Key::FragmentShader].constData() == code.constData())
| 0-100 | ||||||||||||||||||
| 655 | return; never executed: return; | 0 | ||||||||||||||||||
| 656 | m_common.source.sourceCode[Key::FragmentShader] = code; | - | ||||||||||||||||||
| 657 | m_dirtyProgram = true; | - | ||||||||||||||||||
| 658 | m_dirtyParseLog = true; | - | ||||||||||||||||||
| 659 | - | |||||||||||||||||||
| 660 | m_fragNeedsUpdate = true; | - | ||||||||||||||||||
| 661 | if (m_item->isComponentComplete())
| 40-60 | ||||||||||||||||||
| 662 | maybeUpdateShaders(); executed 40 times by 1 test: maybeUpdateShaders();Executed by:
| 40 | ||||||||||||||||||
| 663 | - | |||||||||||||||||||
| 664 | m_item->update(); | - | ||||||||||||||||||
| 665 | if (m_status != QQuickShaderEffect::Uncompiled) {
| 0-100 | ||||||||||||||||||
| 666 | m_status = QQuickShaderEffect::Uncompiled; | - | ||||||||||||||||||
| 667 | emit m_item->statusChanged(); | - | ||||||||||||||||||
| 668 | } never executed: end of block | 0 | ||||||||||||||||||
| 669 | emit m_item->fragmentShaderChanged(); | - | ||||||||||||||||||
| 670 | } executed 100 times by 4 tests: end of blockExecuted by:
| 100 | ||||||||||||||||||
| 671 | - | |||||||||||||||||||
| 672 | void QQuickOpenGLShaderEffect::setVertexShader(const QByteArray &code) | - | ||||||||||||||||||
| 673 | { | - | ||||||||||||||||||
| 674 | if (m_common.source.sourceCode[Key::VertexShader].constData() == code.constData())
| 0-36 | ||||||||||||||||||
| 675 | return; never executed: return; | 0 | ||||||||||||||||||
| 676 | m_common.source.sourceCode[Key::VertexShader] = code; | - | ||||||||||||||||||
| 677 | m_dirtyProgram = true; | - | ||||||||||||||||||
| 678 | m_dirtyParseLog = true; | - | ||||||||||||||||||
| 679 | m_customVertexShader = true; | - | ||||||||||||||||||
| 680 | - | |||||||||||||||||||
| 681 | m_vertNeedsUpdate = true; | - | ||||||||||||||||||
| 682 | if (m_item->isComponentComplete())
| 0-36 | ||||||||||||||||||
| 683 | maybeUpdateShaders(); executed 36 times by 1 test: maybeUpdateShaders();Executed by:
| 36 | ||||||||||||||||||
| 684 | - | |||||||||||||||||||
| 685 | m_item->update(); | - | ||||||||||||||||||
| 686 | if (m_status != QQuickShaderEffect::Uncompiled) {
| 0-36 | ||||||||||||||||||
| 687 | m_status = QQuickShaderEffect::Uncompiled; | - | ||||||||||||||||||
| 688 | emit m_item->statusChanged(); | - | ||||||||||||||||||
| 689 | } never executed: end of block | 0 | ||||||||||||||||||
| 690 | emit m_item->vertexShaderChanged(); | - | ||||||||||||||||||
| 691 | } executed 36 times by 1 test: end of blockExecuted by:
| 36 | ||||||||||||||||||
| 692 | - | |||||||||||||||||||
| 693 | void QQuickOpenGLShaderEffect::setBlending(bool enable) | - | ||||||||||||||||||
| 694 | { | - | ||||||||||||||||||
| 695 | if (blending() == enable)
| 0 | ||||||||||||||||||
| 696 | return; never executed: return; | 0 | ||||||||||||||||||
| 697 | - | |||||||||||||||||||
| 698 | m_blending = enable; | - | ||||||||||||||||||
| 699 | m_item->update(); | - | ||||||||||||||||||
| 700 | - | |||||||||||||||||||
| 701 | emit m_item->blendingChanged(); | - | ||||||||||||||||||
| 702 | } never executed: end of block | 0 | ||||||||||||||||||
| 703 | - | |||||||||||||||||||
| 704 | QVariant QQuickOpenGLShaderEffect::mesh() const | - | ||||||||||||||||||
| 705 | { | - | ||||||||||||||||||
| 706 | return m_mesh ? qVariantFromValue(static_cast<QObject *>(m_mesh)) never executed: return m_mesh ? qVariantFromValue(static_cast<QObject *>(m_mesh)) : qVariantFromValue(m_meshResolution); | 0 | ||||||||||||||||||
| 707 | : qVariantFromValue(m_meshResolution); never executed: return m_mesh ? qVariantFromValue(static_cast<QObject *>(m_mesh)) : qVariantFromValue(m_meshResolution); | 0 | ||||||||||||||||||
| 708 | } | - | ||||||||||||||||||
| 709 | - | |||||||||||||||||||
| 710 | void QQuickOpenGLShaderEffect::setMesh(const QVariant &mesh) | - | ||||||||||||||||||
| 711 | { | - | ||||||||||||||||||
| 712 | QQuickShaderEffectMesh *newMesh = qobject_cast<QQuickShaderEffectMesh *>(qvariant_cast<QObject *>(mesh)); | - | ||||||||||||||||||
| 713 | if (newMesh && newMesh == m_mesh)
| 0-2 | ||||||||||||||||||
| 714 | return; never executed: return; | 0 | ||||||||||||||||||
| 715 | if (m_mesh)
| 0-2 | ||||||||||||||||||
| 716 | disconnect(m_mesh, SIGNAL(geometryChanged()), this, nullptr); never executed: disconnect(m_mesh, qFlagLocation("2""geometryChanged()" "\0" __FILE__ ":" "716"), this, nullptr); | 0 | ||||||||||||||||||
| 717 | m_mesh = newMesh; | - | ||||||||||||||||||
| 718 | if (m_mesh) {
| 0-2 | ||||||||||||||||||
| 719 | connect(m_mesh, SIGNAL(geometryChanged()), this, SLOT(updateGeometry())); | - | ||||||||||||||||||
| 720 | } else { executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 721 | if (mesh.canConvert<QSize>()) {
| 0 | ||||||||||||||||||
| 722 | m_meshResolution = mesh.toSize(); | - | ||||||||||||||||||
| 723 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 724 | QList<QByteArray> res = mesh.toByteArray().split('x'); | - | ||||||||||||||||||
| 725 | bool ok = res.size() == 2; | - | ||||||||||||||||||
| 726 | if (ok) {
| 0 | ||||||||||||||||||
| 727 | int w = res.at(0).toInt(&ok); | - | ||||||||||||||||||
| 728 | if (ok) {
| 0 | ||||||||||||||||||
| 729 | int h = res.at(1).toInt(&ok); | - | ||||||||||||||||||
| 730 | if (ok)
| 0 | ||||||||||||||||||
| 731 | m_meshResolution = QSize(w, h); never executed: m_meshResolution = QSize(w, h); | 0 | ||||||||||||||||||
| 732 | } never executed: end of block | 0 | ||||||||||||||||||
| 733 | } never executed: end of block | 0 | ||||||||||||||||||
| 734 | if (!ok)
| 0 | ||||||||||||||||||
| 735 | qWarning("ShaderEffect: mesh property must be size or object deriving from QQuickShaderEffectMesh."); never executed: QMessageLogger(__FILE__, 735, __PRETTY_FUNCTION__).warning("ShaderEffect: mesh property must be size or object deriving from QQuickShaderEffectMesh."); | 0 | ||||||||||||||||||
| 736 | } never executed: end of block | 0 | ||||||||||||||||||
| 737 | m_defaultMesh.setResolution(m_meshResolution); | - | ||||||||||||||||||
| 738 | } never executed: end of block | 0 | ||||||||||||||||||
| 739 | - | |||||||||||||||||||
| 740 | m_dirtyMesh = true; | - | ||||||||||||||||||
| 741 | m_dirtyParseLog = true; | - | ||||||||||||||||||
| 742 | m_item->update(); | - | ||||||||||||||||||
| 743 | emit m_item->meshChanged(); | - | ||||||||||||||||||
| 744 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 745 | - | |||||||||||||||||||
| 746 | void QQuickOpenGLShaderEffect::setCullMode(QQuickShaderEffect::CullMode face) | - | ||||||||||||||||||
| 747 | { | - | ||||||||||||||||||
| 748 | if (face == m_cullMode)
| 0 | ||||||||||||||||||
| 749 | return; never executed: return; | 0 | ||||||||||||||||||
| 750 | m_cullMode = face; | - | ||||||||||||||||||
| 751 | m_item->update(); | - | ||||||||||||||||||
| 752 | emit m_item->cullModeChanged(); | - | ||||||||||||||||||
| 753 | } never executed: end of block | 0 | ||||||||||||||||||
| 754 | - | |||||||||||||||||||
| 755 | void QQuickOpenGLShaderEffect::setSupportsAtlasTextures(bool supports) | - | ||||||||||||||||||
| 756 | { | - | ||||||||||||||||||
| 757 | if (supports == m_supportsAtlasTextures)
| 0-4 | ||||||||||||||||||
| 758 | return; never executed: return; | 0 | ||||||||||||||||||
| 759 | m_supportsAtlasTextures = supports; | - | ||||||||||||||||||
| 760 | updateGeometry(); | - | ||||||||||||||||||
| 761 | emit m_item->supportsAtlasTexturesChanged(); | - | ||||||||||||||||||
| 762 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 763 | - | |||||||||||||||||||
| 764 | QString QQuickOpenGLShaderEffect::parseLog() | - | ||||||||||||||||||
| 765 | { | - | ||||||||||||||||||
| 766 | maybeUpdateShaders(true); | - | ||||||||||||||||||
| 767 | - | |||||||||||||||||||
| 768 | if (m_dirtyParseLog) {
| 0-90 | ||||||||||||||||||
| 769 | m_common.updateParseLog(m_mesh != nullptr); | - | ||||||||||||||||||
| 770 | m_dirtyParseLog = false; | - | ||||||||||||||||||
| 771 | } executed 90 times by 5 tests: end of blockExecuted by:
| 90 | ||||||||||||||||||
| 772 | return m_common.parseLog; executed 90 times by 5 tests: return m_common.parseLog;Executed by:
| 90 | ||||||||||||||||||
| 773 | } | - | ||||||||||||||||||
| 774 | - | |||||||||||||||||||
| 775 | void QQuickOpenGLShaderEffect::handleEvent(QEvent *event) | - | ||||||||||||||||||
| 776 | { | - | ||||||||||||||||||
| 777 | if (event->type() == QEvent::DynamicPropertyChange) {
| 0-32 | ||||||||||||||||||
| 778 | QDynamicPropertyChangeEvent *e = static_cast<QDynamicPropertyChangeEvent *>(event); | - | ||||||||||||||||||
| 779 | for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) {
| 32-64 | ||||||||||||||||||
| 780 | for (int i = 0; i < m_common.uniformData[shaderType].size(); ++i) {
| 0-64 | ||||||||||||||||||
| 781 | if (m_common.uniformData[shaderType].at(i).name == e->propertyName()) {
| 0 | ||||||||||||||||||
| 782 | bool textureProviderChanged; | - | ||||||||||||||||||
| 783 | m_common.propertyChanged(m_item, m_itemMetaObject, | - | ||||||||||||||||||
| 784 | (shaderType << 16) | i, &textureProviderChanged); | - | ||||||||||||||||||
| 785 | m_dirtyTextureProviders |= textureProviderChanged; | - | ||||||||||||||||||
| 786 | m_dirtyUniformValues = true; | - | ||||||||||||||||||
| 787 | m_item->update(); | - | ||||||||||||||||||
| 788 | } never executed: end of block | 0 | ||||||||||||||||||
| 789 | } never executed: end of block | 0 | ||||||||||||||||||
| 790 | } executed 64 times by 2 tests: end of blockExecuted by:
| 64 | ||||||||||||||||||
| 791 | } executed 32 times by 2 tests: end of blockExecuted by:
| 32 | ||||||||||||||||||
| 792 | } executed 32 times by 2 tests: end of blockExecuted by:
| 32 | ||||||||||||||||||
| 793 | - | |||||||||||||||||||
| 794 | void QQuickOpenGLShaderEffect::updateGeometry() | - | ||||||||||||||||||
| 795 | { | - | ||||||||||||||||||
| 796 | m_dirtyGeometry = true; | - | ||||||||||||||||||
| 797 | m_item->update(); | - | ||||||||||||||||||
| 798 | } executed 8 times by 2 tests: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 799 | - | |||||||||||||||||||
| 800 | void QQuickOpenGLShaderEffect::updateGeometryIfAtlased() | - | ||||||||||||||||||
| 801 | { | - | ||||||||||||||||||
| 802 | if (m_supportsAtlasTextures)
| 0-236 | ||||||||||||||||||
| 803 | updateGeometry(); never executed: updateGeometry(); | 0 | ||||||||||||||||||
| 804 | } executed 236 times by 2 tests: end of blockExecuted by:
| 236 | ||||||||||||||||||
| 805 | - | |||||||||||||||||||
| 806 | void QQuickOpenGLShaderEffect::updateLogAndStatus(const QString &log, int status) | - | ||||||||||||||||||
| 807 | { | - | ||||||||||||||||||
| 808 | m_log = parseLog() + log; | - | ||||||||||||||||||
| 809 | m_status = QQuickShaderEffect::Status(status); | - | ||||||||||||||||||
| 810 | emit m_item->logChanged(); | - | ||||||||||||||||||
| 811 | emit m_item->statusChanged(); | - | ||||||||||||||||||
| 812 | } executed 54 times by 5 tests: end of blockExecuted by:
| 54 | ||||||||||||||||||
| 813 | - | |||||||||||||||||||
| 814 | void QQuickOpenGLShaderEffect::sourceDestroyed(QObject *object) | - | ||||||||||||||||||
| 815 | { | - | ||||||||||||||||||
| 816 | m_common.sourceDestroyed(object); | - | ||||||||||||||||||
| 817 | } executed 45 times by 3 tests: end of blockExecuted by:
| 45 | ||||||||||||||||||
| 818 | - | |||||||||||||||||||
| 819 | void QQuickOpenGLShaderEffect::propertyChanged(int mappedId) | - | ||||||||||||||||||
| 820 | { | - | ||||||||||||||||||
| 821 | bool textureProviderChanged; | - | ||||||||||||||||||
| 822 | m_common.propertyChanged(m_item, m_itemMetaObject, mappedId, &textureProviderChanged); | - | ||||||||||||||||||
| 823 | m_dirtyTextureProviders |= textureProviderChanged; | - | ||||||||||||||||||
| 824 | m_dirtyUniformValues = true; | - | ||||||||||||||||||
| 825 | m_item->update(); | - | ||||||||||||||||||
| 826 | } executed 14 times by 3 tests: end of blockExecuted by:
| 14 | ||||||||||||||||||
| 827 | - | |||||||||||||||||||
| 828 | void QQuickOpenGLShaderEffect::handleGeometryChanged(const QRectF &, const QRectF &) | - | ||||||||||||||||||
| 829 | { | - | ||||||||||||||||||
| 830 | m_dirtyGeometry = true; | - | ||||||||||||||||||
| 831 | } executed 122 times by 5 tests: end of blockExecuted by:
| 122 | ||||||||||||||||||
| 832 | - | |||||||||||||||||||
| 833 | QSGNode *QQuickOpenGLShaderEffect::handleUpdatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) | - | ||||||||||||||||||
| 834 | { | - | ||||||||||||||||||
| 835 | QQuickOpenGLShaderEffectNode *node = static_cast<QQuickOpenGLShaderEffectNode *>(oldNode); | - | ||||||||||||||||||
| 836 | - | |||||||||||||||||||
| 837 | // In the case of zero-size or a bad vertex shader, don't try to create a node... | - | ||||||||||||||||||
| 838 | if (m_common.attributes.isEmpty() || m_item->width() <= 0 || m_item->height() <= 0) {
| 0-72 | ||||||||||||||||||
| 839 | if (node)
| 0-8 | ||||||||||||||||||
| 840 | delete node; never executed: delete node; | 0 | ||||||||||||||||||
| 841 | return nullptr; executed 8 times by 1 test: return nullptr;Executed by:
| 8 | ||||||||||||||||||
| 842 | } | - | ||||||||||||||||||
| 843 | - | |||||||||||||||||||
| 844 | if (!node) {
| 0-64 | ||||||||||||||||||
| 845 | node = new QQuickOpenGLShaderEffectNode; | - | ||||||||||||||||||
| 846 | node->setMaterial(new QQuickOpenGLShaderEffectMaterial(node)); | - | ||||||||||||||||||
| 847 | node->setFlag(QSGNode::OwnsMaterial, true); | - | ||||||||||||||||||
| 848 | m_dirtyProgram = true; | - | ||||||||||||||||||
| 849 | m_dirtyUniforms = true; | - | ||||||||||||||||||
| 850 | m_dirtyGeometry = true; | - | ||||||||||||||||||
| 851 | connect(node, SIGNAL(logAndStatusChanged(QString,int)), this, SLOT(updateLogAndStatus(QString,int))); | - | ||||||||||||||||||
| 852 | connect(node, &QQuickOpenGLShaderEffectNode::dirtyTexture, | - | ||||||||||||||||||
| 853 | this, &QQuickOpenGLShaderEffect::updateGeometryIfAtlased); | - | ||||||||||||||||||
| 854 | } executed 64 times by 5 tests: end of blockExecuted by:
| 64 | ||||||||||||||||||
| 855 | - | |||||||||||||||||||
| 856 | QQuickOpenGLShaderEffectMaterial *material = static_cast<QQuickOpenGLShaderEffectMaterial *>(node->material()); | - | ||||||||||||||||||
| 857 | - | |||||||||||||||||||
| 858 | // Update blending | - | ||||||||||||||||||
| 859 | if (bool(material->flags() & QSGMaterial::Blending) != m_blending) {
| 0-64 | ||||||||||||||||||
| 860 | material->setFlag(QSGMaterial::Blending, m_blending); | - | ||||||||||||||||||
| 861 | node->markDirty(QSGNode::DirtyMaterial); | - | ||||||||||||||||||
| 862 | } never executed: end of block | 0 | ||||||||||||||||||
| 863 | - | |||||||||||||||||||
| 864 | if (int(material->cullMode) != int(m_cullMode)) {
| 0-64 | ||||||||||||||||||
| 865 | material->cullMode = QQuickShaderEffect::CullMode(m_cullMode); | - | ||||||||||||||||||
| 866 | node->markDirty(QSGNode::DirtyMaterial); | - | ||||||||||||||||||
| 867 | } never executed: end of block | 0 | ||||||||||||||||||
| 868 | - | |||||||||||||||||||
| 869 | if (m_dirtyProgram) {
| 0-64 | ||||||||||||||||||
| 870 | Key s = m_common.source; | - | ||||||||||||||||||
| 871 | QSGShaderSourceBuilder builder; | - | ||||||||||||||||||
| 872 | if (s.sourceCode[Key::FragmentShader].isEmpty()) {
| 6-58 | ||||||||||||||||||
| 873 | builder.appendSourceFile(QStringLiteral(":/qt-project.org/items/shaders/shadereffect.frag")); executed 6 times by 2 tests: return qstring_literal_temp;Executed by:
| 6 | ||||||||||||||||||
| 874 | s.sourceCode[Key::FragmentShader] = builder.source(); | - | ||||||||||||||||||
| 875 | builder.clear(); | - | ||||||||||||||||||
| 876 | } executed 6 times by 2 tests: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 877 | if (s.sourceCode[Key::VertexShader].isEmpty()) {
| 0-64 | ||||||||||||||||||
| 878 | builder.appendSourceFile(QStringLiteral(":/qt-project.org/items/shaders/shadereffect.vert")); executed 64 times by 5 tests: return qstring_literal_temp;Executed by:
| 64 | ||||||||||||||||||
| 879 | s.sourceCode[Key::VertexShader] = builder.source(); | - | ||||||||||||||||||
| 880 | } executed 64 times by 5 tests: end of blockExecuted by:
| 64 | ||||||||||||||||||
| 881 | - | |||||||||||||||||||
| 882 | material->setProgramSource(s); | - | ||||||||||||||||||
| 883 | material->attributes = m_common.attributes; | - | ||||||||||||||||||
| 884 | node->markDirty(QSGNode::DirtyMaterial); | - | ||||||||||||||||||
| 885 | m_dirtyProgram = false; | - | ||||||||||||||||||
| 886 | m_dirtyUniforms = true; | - | ||||||||||||||||||
| 887 | } executed 64 times by 5 tests: end of blockExecuted by:
| 64 | ||||||||||||||||||
| 888 | - | |||||||||||||||||||
| 889 | if (m_dirtyUniforms || m_dirtyUniformValues || m_dirtyTextureProviders) {
| 0-64 | ||||||||||||||||||
| 890 | m_common.updateMaterial(node, material, m_dirtyUniforms, m_dirtyUniformValues, | - | ||||||||||||||||||
| 891 | m_dirtyTextureProviders); | - | ||||||||||||||||||
| 892 | node->markDirty(QSGNode::DirtyMaterial); | - | ||||||||||||||||||
| 893 | m_dirtyUniforms = m_dirtyUniformValues = m_dirtyTextureProviders = false; | - | ||||||||||||||||||
| 894 | } executed 64 times by 5 tests: end of blockExecuted by:
| 64 | ||||||||||||||||||
| 895 | - | |||||||||||||||||||
| 896 | QRectF srcRect(0, 0, 1, 1); | - | ||||||||||||||||||
| 897 | bool geometryUsesTextureSubRect = false; | - | ||||||||||||||||||
| 898 | if (m_supportsAtlasTextures && material->textureProviders.size() == 1) {
| 0-60 | ||||||||||||||||||
| 899 | QSGTextureProvider *provider = material->textureProviders.at(0); | - | ||||||||||||||||||
| 900 | if (provider && provider->texture()) {
| 0-2 | ||||||||||||||||||
| 901 | srcRect = provider->texture()->normalizedTextureSubRect(); | - | ||||||||||||||||||
| 902 | geometryUsesTextureSubRect = true; | - | ||||||||||||||||||
| 903 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 904 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 905 | - | |||||||||||||||||||
| 906 | if (bool(material->flags() & QSGMaterial::RequiresFullMatrix) != m_customVertexShader) {
| 0-64 | ||||||||||||||||||
| 907 | material->setFlag(QSGMaterial::RequiresFullMatrix, m_customVertexShader); | - | ||||||||||||||||||
| 908 | node->markDirty(QSGNode::DirtyMaterial); | - | ||||||||||||||||||
| 909 | } executed 64 times by 5 tests: end of blockExecuted by:
| 64 | ||||||||||||||||||
| 910 | - | |||||||||||||||||||
| 911 | if (material->geometryUsesTextureSubRect != geometryUsesTextureSubRect) {
| 2-62 | ||||||||||||||||||
| 912 | material->geometryUsesTextureSubRect = geometryUsesTextureSubRect; | - | ||||||||||||||||||
| 913 | node->markDirty(QSGNode::DirtyMaterial); | - | ||||||||||||||||||
| 914 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 915 | - | |||||||||||||||||||
| 916 | if (m_dirtyMesh) {
| 0-64 | ||||||||||||||||||
| 917 | node->setGeometry(nullptr); | - | ||||||||||||||||||
| 918 | m_dirtyMesh = false; | - | ||||||||||||||||||
| 919 | m_dirtyGeometry = true; | - | ||||||||||||||||||
| 920 | } executed 64 times by 5 tests: end of blockExecuted by:
| 64 | ||||||||||||||||||
| 921 | - | |||||||||||||||||||
| 922 | if (m_dirtyGeometry) {
| 0-64 | ||||||||||||||||||
| 923 | node->setFlag(QSGNode::OwnsGeometry, false); | - | ||||||||||||||||||
| 924 | QSGGeometry *geometry = node->geometry(); | - | ||||||||||||||||||
| 925 | QRectF rect(0, 0, m_item->width(), m_item->height()); | - | ||||||||||||||||||
| 926 | QQuickShaderEffectMesh *mesh = m_mesh ? m_mesh : &m_defaultMesh;
| 2-62 | ||||||||||||||||||
| 927 | - | |||||||||||||||||||
| 928 | int posIndex = 0; | - | ||||||||||||||||||
| 929 | if (!mesh->validateAttributes(m_common.attributes, &posIndex)) {
| 0-64 | ||||||||||||||||||
| 930 | QString log = mesh->log(); | - | ||||||||||||||||||
| 931 | if (!log.isNull()) {
| 0 | ||||||||||||||||||
| 932 | m_log = parseLog() + QLatin1String("*** Mesh ***\n") + log; | - | ||||||||||||||||||
| 933 | m_status = QQuickShaderEffect::Error; | - | ||||||||||||||||||
| 934 | emit m_item->logChanged(); | - | ||||||||||||||||||
| 935 | emit m_item->statusChanged(); | - | ||||||||||||||||||
| 936 | } never executed: end of block | 0 | ||||||||||||||||||
| 937 | delete node; | - | ||||||||||||||||||
| 938 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||||||||
| 939 | } | - | ||||||||||||||||||
| 940 | - | |||||||||||||||||||
| 941 | geometry = mesh->updateGeometry(geometry, m_common.attributes.count(), posIndex, srcRect, rect); | - | ||||||||||||||||||
| 942 | - | |||||||||||||||||||
| 943 | node->setGeometry(geometry); | - | ||||||||||||||||||
| 944 | node->setFlag(QSGNode::OwnsGeometry, true); | - | ||||||||||||||||||
| 945 | - | |||||||||||||||||||
| 946 | m_dirtyGeometry = false; | - | ||||||||||||||||||
| 947 | } executed 64 times by 5 tests: end of blockExecuted by:
| 64 | ||||||||||||||||||
| 948 | - | |||||||||||||||||||
| 949 | return node; executed 64 times by 5 tests: return node;Executed by:
| 64 | ||||||||||||||||||
| 950 | } | - | ||||||||||||||||||
| 951 | - | |||||||||||||||||||
| 952 | void QQuickOpenGLShaderEffect::maybeUpdateShaders(bool force) | - | ||||||||||||||||||
| 953 | { | - | ||||||||||||||||||
| 954 | if (!m_itemMetaObject)
| 108-206 | ||||||||||||||||||
| 955 | m_itemMetaObject = m_item->metaObject(); executed 108 times by 5 tests: m_itemMetaObject = m_item->metaObject();Executed by:
| 108 | ||||||||||||||||||
| 956 | - | |||||||||||||||||||
| 957 | // Defer processing if a window is not yet associated with the item. This | - | ||||||||||||||||||
| 958 | // is because the actual scenegraph backend is not known so conditions | - | ||||||||||||||||||
| 959 | // based on GraphicsInfo.shaderType and similar evaluate to wrong results. | - | ||||||||||||||||||
| 960 | if (!m_item->window() && !force) {
| 36-188 | ||||||||||||||||||
| 961 | m_item->polish(); | - | ||||||||||||||||||
| 962 | return; executed 152 times by 5 tests: return;Executed by:
| 152 | ||||||||||||||||||
| 963 | } | - | ||||||||||||||||||
| 964 | - | |||||||||||||||||||
| 965 | if (m_vertNeedsUpdate) {
| 58-104 | ||||||||||||||||||
| 966 | m_vertNeedsUpdate = false; | - | ||||||||||||||||||
| 967 | m_common.updateShader(m_item, m_itemMetaObject, Key::VertexShader); | - | ||||||||||||||||||
| 968 | } executed 104 times by 5 tests: end of blockExecuted by:
| 104 | ||||||||||||||||||
| 969 | - | |||||||||||||||||||
| 970 | if (m_fragNeedsUpdate) {
| 54-108 | ||||||||||||||||||
| 971 | m_fragNeedsUpdate = false; | - | ||||||||||||||||||
| 972 | m_common.updateShader(m_item, m_itemMetaObject, Key::FragmentShader); | - | ||||||||||||||||||
| 973 | } executed 108 times by 5 tests: end of blockExecuted by:
| 108 | ||||||||||||||||||
| 974 | } executed 162 times by 5 tests: end of blockExecuted by:
| 162 | ||||||||||||||||||
| 975 | - | |||||||||||||||||||
| 976 | void QQuickOpenGLShaderEffect::handleItemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value) | - | ||||||||||||||||||
| 977 | { | - | ||||||||||||||||||
| 978 | if (change == QQuickItem::ItemSceneChange)
| 136-156 | ||||||||||||||||||
| 979 | m_common.updateWindow(value.window); executed 136 times by 5 tests: m_common.updateWindow(value.window);Executed by:
| 136 | ||||||||||||||||||
| 980 | } executed 292 times by 5 tests: end of blockExecuted by:
| 292 | ||||||||||||||||||
| 981 | - | |||||||||||||||||||
| 982 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 983 | - | |||||||||||||||||||
| 984 | #include "moc_qquickopenglshadereffect_p.cpp" | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |