Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/util/qsgshadersourcebuilder.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||||||||
3 | ** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). | - | ||||||||||||||||||||||||||||||
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 "qsgshadersourcebuilder_p.h" | - | ||||||||||||||||||||||||||||||
41 | - | |||||||||||||||||||||||||||||||
42 | #include <QtGui/qopenglcontext.h> | - | ||||||||||||||||||||||||||||||
43 | #include <QtGui/qopenglshaderprogram.h> | - | ||||||||||||||||||||||||||||||
44 | - | |||||||||||||||||||||||||||||||
45 | #include <QtCore/qdebug.h> | - | ||||||||||||||||||||||||||||||
46 | #include <QtCore/qfile.h> | - | ||||||||||||||||||||||||||||||
47 | - | |||||||||||||||||||||||||||||||
48 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||||||||
49 | - | |||||||||||||||||||||||||||||||
50 | namespace QSGShaderParser { | - | ||||||||||||||||||||||||||||||
51 | - | |||||||||||||||||||||||||||||||
52 | struct Tokenizer { | - | ||||||||||||||||||||||||||||||
53 | - | |||||||||||||||||||||||||||||||
54 | enum Token { | - | ||||||||||||||||||||||||||||||
55 | Token_Invalid, | - | ||||||||||||||||||||||||||||||
56 | Token_Void, | - | ||||||||||||||||||||||||||||||
57 | Token_OpenBrace, | - | ||||||||||||||||||||||||||||||
58 | Token_CloseBrace, | - | ||||||||||||||||||||||||||||||
59 | Token_SemiColon, | - | ||||||||||||||||||||||||||||||
60 | Token_Identifier, | - | ||||||||||||||||||||||||||||||
61 | Token_Macro, | - | ||||||||||||||||||||||||||||||
62 | Token_Version, | - | ||||||||||||||||||||||||||||||
63 | Token_Extension, | - | ||||||||||||||||||||||||||||||
64 | Token_SingleLineComment, | - | ||||||||||||||||||||||||||||||
65 | Token_MultiLineCommentStart, | - | ||||||||||||||||||||||||||||||
66 | Token_MultiLineCommentEnd, | - | ||||||||||||||||||||||||||||||
67 | Token_NewLine, | - | ||||||||||||||||||||||||||||||
68 | Token_Unspecified, | - | ||||||||||||||||||||||||||||||
69 | Token_EOF | - | ||||||||||||||||||||||||||||||
70 | }; | - | ||||||||||||||||||||||||||||||
71 | - | |||||||||||||||||||||||||||||||
72 | static const char *NAMES[]; | - | ||||||||||||||||||||||||||||||
73 | - | |||||||||||||||||||||||||||||||
74 | void initialize(const char *input); | - | ||||||||||||||||||||||||||||||
75 | Token next(); | - | ||||||||||||||||||||||||||||||
76 | - | |||||||||||||||||||||||||||||||
77 | const char *stream; | - | ||||||||||||||||||||||||||||||
78 | const char *pos; | - | ||||||||||||||||||||||||||||||
79 | const char *identifier; | - | ||||||||||||||||||||||||||||||
80 | }; | - | ||||||||||||||||||||||||||||||
81 | - | |||||||||||||||||||||||||||||||
82 | const char *Tokenizer::NAMES[] = { | - | ||||||||||||||||||||||||||||||
83 | "Invalid", | - | ||||||||||||||||||||||||||||||
84 | "Void", | - | ||||||||||||||||||||||||||||||
85 | "OpenBrace", | - | ||||||||||||||||||||||||||||||
86 | "CloseBrace", | - | ||||||||||||||||||||||||||||||
87 | "SemiColon", | - | ||||||||||||||||||||||||||||||
88 | "Identifier", | - | ||||||||||||||||||||||||||||||
89 | "Macro", | - | ||||||||||||||||||||||||||||||
90 | "Version", | - | ||||||||||||||||||||||||||||||
91 | "Extension", | - | ||||||||||||||||||||||||||||||
92 | "SingleLineComment", | - | ||||||||||||||||||||||||||||||
93 | "MultiLineCommentStart", | - | ||||||||||||||||||||||||||||||
94 | "MultiLineCommentEnd", | - | ||||||||||||||||||||||||||||||
95 | "NewLine", | - | ||||||||||||||||||||||||||||||
96 | "Unspecified", | - | ||||||||||||||||||||||||||||||
97 | "EOF" | - | ||||||||||||||||||||||||||||||
98 | }; | - | ||||||||||||||||||||||||||||||
99 | - | |||||||||||||||||||||||||||||||
100 | void Tokenizer::initialize(const char *input) | - | ||||||||||||||||||||||||||||||
101 | { | - | ||||||||||||||||||||||||||||||
102 | stream = input; | - | ||||||||||||||||||||||||||||||
103 | pos = input; | - | ||||||||||||||||||||||||||||||
104 | identifier = input; | - | ||||||||||||||||||||||||||||||
105 | } executed 76 times by 3 tests: end of block Executed by:
| 76 | ||||||||||||||||||||||||||||||
106 | - | |||||||||||||||||||||||||||||||
107 | Tokenizer::Token Tokenizer::next() | - | ||||||||||||||||||||||||||||||
108 | { | - | ||||||||||||||||||||||||||||||
109 | while (*pos != 0) {
| 0-18122 | ||||||||||||||||||||||||||||||
110 | char c = *pos++; | - | ||||||||||||||||||||||||||||||
111 | switch (c) { | - | ||||||||||||||||||||||||||||||
112 | case '/': executed 532 times by 3 tests: case '/': Executed by:
| 532 | ||||||||||||||||||||||||||||||
113 | if (*pos == '/') {
| 266 | ||||||||||||||||||||||||||||||
114 | // '//' comment | - | ||||||||||||||||||||||||||||||
115 | return Token_SingleLineComment; executed 266 times by 3 tests: return Token_SingleLineComment; Executed by:
| 266 | ||||||||||||||||||||||||||||||
116 | } else if (*pos == '*') {
| 0-266 | ||||||||||||||||||||||||||||||
117 | // /* */ comment | - | ||||||||||||||||||||||||||||||
118 | return Token_MultiLineCommentStart; never executed: return Token_MultiLineCommentStart; | 0 | ||||||||||||||||||||||||||||||
119 | } | - | ||||||||||||||||||||||||||||||
120 | break; executed 266 times by 3 tests: break; Executed by:
| 266 | ||||||||||||||||||||||||||||||
121 | - | |||||||||||||||||||||||||||||||
122 | case '*': never executed: case '*': | 0 | ||||||||||||||||||||||||||||||
123 | if (*pos == '/')
| 0 | ||||||||||||||||||||||||||||||
124 | return Token_MultiLineCommentEnd; never executed: return Token_MultiLineCommentEnd; | 0 | ||||||||||||||||||||||||||||||
125 | Q_FALLTHROUGH(); | - | ||||||||||||||||||||||||||||||
126 | - | |||||||||||||||||||||||||||||||
127 | case '\n': code before this statement never executed: case '\n': executed 1710 times by 3 tests: case '\n': Executed by:
| 0-1710 | ||||||||||||||||||||||||||||||
128 | return Token_NewLine; executed 1710 times by 3 tests: return Token_NewLine; Executed by:
| 1710 | ||||||||||||||||||||||||||||||
129 | - | |||||||||||||||||||||||||||||||
130 | case '\r': never executed: case '\r': | 0 | ||||||||||||||||||||||||||||||
131 | if (*pos == '\n')
| 0 | ||||||||||||||||||||||||||||||
132 | return Token_NewLine; never executed: return Token_NewLine; | 0 | ||||||||||||||||||||||||||||||
133 | Q_FALLTHROUGH(); | - | ||||||||||||||||||||||||||||||
134 | - | |||||||||||||||||||||||||||||||
135 | case '#': { code before this statement never executed: case '#': executed 1098 times by 3 tests: case '#': Executed by:
| 0-1098 | ||||||||||||||||||||||||||||||
136 | if (*pos == 'v' && pos[1] == 'e' && pos[2] == 'r' && pos[3] == 's'
| 0-1022 | ||||||||||||||||||||||||||||||
137 | && pos[4] == 'i' && pos[5] == 'o' && pos[6] == 'n') {
| 0-76 | ||||||||||||||||||||||||||||||
138 | return Token_Version; executed 76 times by 3 tests: return Token_Version; Executed by:
| 76 | ||||||||||||||||||||||||||||||
139 | } else if (*pos == 'e' && pos[1] == 'x' && pos[2] == 't' && pos[3] == 'e'
| 0-570 | ||||||||||||||||||||||||||||||
140 | && pos[4] == 'n' && pos[5] == 's' && pos[6] == 'i'&& pos[7] == 'o'
| 0 | ||||||||||||||||||||||||||||||
141 | && pos[8] == 'n') {
| 0 | ||||||||||||||||||||||||||||||
142 | return Token_Extension; never executed: return Token_Extension; | 0 | ||||||||||||||||||||||||||||||
143 | } else { | - | ||||||||||||||||||||||||||||||
144 | while (*pos != 0) {
| 0-12460 | ||||||||||||||||||||||||||||||
145 | if (*pos == '\n') {
| 1022-11438 | ||||||||||||||||||||||||||||||
146 | ++pos; | - | ||||||||||||||||||||||||||||||
147 | break; executed 1022 times by 3 tests: break; Executed by:
| 1022 | ||||||||||||||||||||||||||||||
148 | } else if (*pos == '\\') {
| 0-11438 | ||||||||||||||||||||||||||||||
149 | ++pos; | - | ||||||||||||||||||||||||||||||
150 | while (*pos != 0 && (*pos == ' ' || *pos == '\t'))
| 0 | ||||||||||||||||||||||||||||||
151 | ++pos; never executed: ++pos; | 0 | ||||||||||||||||||||||||||||||
152 | if (*pos != 0 && (*pos == '\n' || (*pos == '\r' && pos[1] == '\n')))
| 0 | ||||||||||||||||||||||||||||||
153 | pos+=2; never executed: pos+=2; | 0 | ||||||||||||||||||||||||||||||
154 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
155 | ++pos; | - | ||||||||||||||||||||||||||||||
156 | } executed 11438 times by 3 tests: end of block Executed by:
| 11438 | ||||||||||||||||||||||||||||||
157 | } | - | ||||||||||||||||||||||||||||||
158 | } executed 1022 times by 3 tests: end of block Executed by:
| 1022 | ||||||||||||||||||||||||||||||
159 | break; executed 1022 times by 3 tests: break; Executed by:
| 1022 | ||||||||||||||||||||||||||||||
160 | } | - | ||||||||||||||||||||||||||||||
161 | - | |||||||||||||||||||||||||||||||
162 | case ';': executed 1064 times by 3 tests: case ';': Executed by:
| 1064 | ||||||||||||||||||||||||||||||
163 | return Token_SemiColon; executed 1064 times by 3 tests: return Token_SemiColon; Executed by:
| 1064 | ||||||||||||||||||||||||||||||
164 | - | |||||||||||||||||||||||||||||||
165 | case 0: never executed: case 0: | 0 | ||||||||||||||||||||||||||||||
166 | return Token_EOF; never executed: return Token_EOF; | 0 | ||||||||||||||||||||||||||||||
167 | - | |||||||||||||||||||||||||||||||
168 | case '{': never executed: case '{': | 0 | ||||||||||||||||||||||||||||||
169 | return Token_OpenBrace; never executed: return Token_OpenBrace; | 0 | ||||||||||||||||||||||||||||||
170 | - | |||||||||||||||||||||||||||||||
171 | case '}': never executed: case '}': | 0 | ||||||||||||||||||||||||||||||
172 | return Token_CloseBrace; never executed: return Token_CloseBrace; | 0 | ||||||||||||||||||||||||||||||
173 | - | |||||||||||||||||||||||||||||||
174 | case ' ': executed 5700 times by 3 tests: case ' ': Executed by:
| 5700 | ||||||||||||||||||||||||||||||
175 | break; executed 5700 times by 3 tests: break; Executed by:
| 5700 | ||||||||||||||||||||||||||||||
176 | - | |||||||||||||||||||||||||||||||
177 | case 'v': { executed 1672 times by 3 tests: case 'v': Executed by:
| 1672 | ||||||||||||||||||||||||||||||
178 | if (*pos == 'o' && pos[1] == 'i' && pos[2] == 'd') {
| 0-1596 | ||||||||||||||||||||||||||||||
179 | pos += 3; | - | ||||||||||||||||||||||||||||||
180 | return Token_Void; executed 76 times by 3 tests: return Token_Void; Executed by:
| 76 | ||||||||||||||||||||||||||||||
181 | } | - | ||||||||||||||||||||||||||||||
182 | Q_FALLTHROUGH(); | - | ||||||||||||||||||||||||||||||
183 | } | - | ||||||||||||||||||||||||||||||
184 | default: code before this statement executed 1596 times by 3 tests: default: Executed by:
executed 7942 times by 3 tests: default: Executed by:
| 1596-7942 | ||||||||||||||||||||||||||||||
185 | // Identifier... | - | ||||||||||||||||||||||||||||||
186 | if ((c >= 'a' && c <= 'z' ) || (c >= 'A' && c <= 'Z' ) || c == '_') {
| 0-6232 | ||||||||||||||||||||||||||||||
187 | identifier = pos - 1; | - | ||||||||||||||||||||||||||||||
188 | while (*pos != 0 && ((*pos >= 'a' && *pos <= 'z')
| 0-33516 | ||||||||||||||||||||||||||||||
189 | || (*pos >= 'A' && *pos <= 'Z')
| 190-6992 | ||||||||||||||||||||||||||||||
190 | || *pos == '_'
| 114-7068 | ||||||||||||||||||||||||||||||
191 | || (*pos >= '0' && *pos <= '9'))) {
| 760-5244 | ||||||||||||||||||||||||||||||
192 | ++pos; | - | ||||||||||||||||||||||||||||||
193 | } executed 27208 times by 3 tests: end of block Executed by:
| 27208 | ||||||||||||||||||||||||||||||
194 | return Token_Identifier; executed 6308 times by 3 tests: return Token_Identifier; Executed by:
| 6308 | ||||||||||||||||||||||||||||||
195 | } else { | - | ||||||||||||||||||||||||||||||
196 | return Token_Unspecified; executed 1634 times by 3 tests: return Token_Unspecified; Executed by:
| 1634 | ||||||||||||||||||||||||||||||
197 | } | - | ||||||||||||||||||||||||||||||
198 | } | - | ||||||||||||||||||||||||||||||
199 | } | - | ||||||||||||||||||||||||||||||
200 | - | |||||||||||||||||||||||||||||||
201 | return Token_Invalid; never executed: return Token_Invalid; | 0 | ||||||||||||||||||||||||||||||
202 | } | - | ||||||||||||||||||||||||||||||
203 | - | |||||||||||||||||||||||||||||||
204 | } // namespace QSGShaderParser | - | ||||||||||||||||||||||||||||||
205 | - | |||||||||||||||||||||||||||||||
206 | using namespace QSGShaderParser; | - | ||||||||||||||||||||||||||||||
207 | - | |||||||||||||||||||||||||||||||
208 | QSGShaderSourceBuilder::QSGShaderSourceBuilder() | - | ||||||||||||||||||||||||||||||
209 | { | - | ||||||||||||||||||||||||||||||
210 | } | - | ||||||||||||||||||||||||||||||
211 | - | |||||||||||||||||||||||||||||||
212 | void QSGShaderSourceBuilder::initializeProgramFromFiles(QOpenGLShaderProgram *program, | - | ||||||||||||||||||||||||||||||
213 | const QString &vertexShader, | - | ||||||||||||||||||||||||||||||
214 | const QString &fragmentShader) | - | ||||||||||||||||||||||||||||||
215 | { | - | ||||||||||||||||||||||||||||||
216 | Q_ASSERT(program); | - | ||||||||||||||||||||||||||||||
217 | program->removeAllShaders(); | - | ||||||||||||||||||||||||||||||
218 | - | |||||||||||||||||||||||||||||||
219 | QSGShaderSourceBuilder builder; | - | ||||||||||||||||||||||||||||||
220 | - | |||||||||||||||||||||||||||||||
221 | builder.appendSourceFile(vertexShader); | - | ||||||||||||||||||||||||||||||
222 | program->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, builder.source()); | - | ||||||||||||||||||||||||||||||
223 | builder.clear(); | - | ||||||||||||||||||||||||||||||
224 | - | |||||||||||||||||||||||||||||||
225 | builder.appendSourceFile(fragmentShader); | - | ||||||||||||||||||||||||||||||
226 | program->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, builder.source()); | - | ||||||||||||||||||||||||||||||
227 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||
228 | - | |||||||||||||||||||||||||||||||
229 | QByteArray QSGShaderSourceBuilder::source() const | - | ||||||||||||||||||||||||||||||
230 | { | - | ||||||||||||||||||||||||||||||
231 | return m_source; executed 8969 times by 70 tests: return m_source; Executed by:
| 8969 | ||||||||||||||||||||||||||||||
232 | } | - | ||||||||||||||||||||||||||||||
233 | - | |||||||||||||||||||||||||||||||
234 | void QSGShaderSourceBuilder::clear() | - | ||||||||||||||||||||||||||||||
235 | { | - | ||||||||||||||||||||||||||||||
236 | m_source.clear(); | - | ||||||||||||||||||||||||||||||
237 | } executed 76 times by 25 tests: end of block Executed by:
| 76 | ||||||||||||||||||||||||||||||
238 | - | |||||||||||||||||||||||||||||||
239 | void QSGShaderSourceBuilder::appendSource(const QByteArray &source) | - | ||||||||||||||||||||||||||||||
240 | { | - | ||||||||||||||||||||||||||||||
241 | m_source += source; | - | ||||||||||||||||||||||||||||||
242 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
243 | - | |||||||||||||||||||||||||||||||
244 | void QSGShaderSourceBuilder::appendSourceFile(const QString &fileName) | - | ||||||||||||||||||||||||||||||
245 | { | - | ||||||||||||||||||||||||||||||
246 | const QString resolvedFileName = resolveShaderPath(fileName); | - | ||||||||||||||||||||||||||||||
247 | QFile f(resolvedFileName); | - | ||||||||||||||||||||||||||||||
248 | if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
| 0-8973 | ||||||||||||||||||||||||||||||
249 | qWarning() << "Failed to find shader" << resolvedFileName; | - | ||||||||||||||||||||||||||||||
250 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
251 | } | - | ||||||||||||||||||||||||||||||
252 | m_source += f.readAll(); | - | ||||||||||||||||||||||||||||||
253 | } executed 8973 times by 70 tests: end of block Executed by:
| 8973 | ||||||||||||||||||||||||||||||
254 | - | |||||||||||||||||||||||||||||||
255 | void QSGShaderSourceBuilder::addDefinition(const QByteArray &definition) | - | ||||||||||||||||||||||||||||||
256 | { | - | ||||||||||||||||||||||||||||||
257 | if (definition.isEmpty())
| 0-76 | ||||||||||||||||||||||||||||||
258 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
259 | - | |||||||||||||||||||||||||||||||
260 | Tokenizer tok; | - | ||||||||||||||||||||||||||||||
261 | const char *input = m_source.constData(); | - | ||||||||||||||||||||||||||||||
262 | tok.initialize(input); | - | ||||||||||||||||||||||||||||||
263 | - | |||||||||||||||||||||||||||||||
264 | // First find #version, #extension's and "void main() { ... " | - | ||||||||||||||||||||||||||||||
265 | const char *versionPos = nullptr; | - | ||||||||||||||||||||||||||||||
266 | const char *extensionPos = nullptr; | - | ||||||||||||||||||||||||||||||
267 | bool inSingleLineComment = false; | - | ||||||||||||||||||||||||||||||
268 | bool inMultiLineComment = false; | - | ||||||||||||||||||||||||||||||
269 | bool foundVersionStart = false; | - | ||||||||||||||||||||||||||||||
270 | bool foundExtensionStart = false; | - | ||||||||||||||||||||||||||||||
271 | - | |||||||||||||||||||||||||||||||
272 | Tokenizer::Token lt = Tokenizer::Token_Unspecified; | - | ||||||||||||||||||||||||||||||
273 | Tokenizer::Token t = tok.next(); | - | ||||||||||||||||||||||||||||||
274 | while (t != Tokenizer::Token_EOF) {
| 0-11134 | ||||||||||||||||||||||||||||||
275 | // Handle comment blocks | - | ||||||||||||||||||||||||||||||
276 | if (t == Tokenizer::Token_MultiLineCommentStart )
| 0-11134 | ||||||||||||||||||||||||||||||
277 | inMultiLineComment = true; never executed: inMultiLineComment = true; | 0 | ||||||||||||||||||||||||||||||
278 | if (t == Tokenizer::Token_MultiLineCommentEnd)
| 0-11134 | ||||||||||||||||||||||||||||||
279 | inMultiLineComment = false; never executed: inMultiLineComment = false; | 0 | ||||||||||||||||||||||||||||||
280 | if (t == Tokenizer::Token_SingleLineComment)
| 266-10868 | ||||||||||||||||||||||||||||||
281 | inSingleLineComment = true; executed 266 times by 3 tests: inSingleLineComment = true; Executed by:
| 266 | ||||||||||||||||||||||||||||||
282 | if (t == Tokenizer::Token_NewLine && inSingleLineComment && !inMultiLineComment)
| 0-9424 | ||||||||||||||||||||||||||||||
283 | inSingleLineComment = false; executed 266 times by 3 tests: inSingleLineComment = false; Executed by:
| 266 | ||||||||||||||||||||||||||||||
284 | - | |||||||||||||||||||||||||||||||
285 | // Have we found #version, #extension or void main()? | - | ||||||||||||||||||||||||||||||
286 | if (t == Tokenizer::Token_Version && !inSingleLineComment && !inMultiLineComment)
| 0-11058 | ||||||||||||||||||||||||||||||
287 | foundVersionStart = true; executed 76 times by 3 tests: foundVersionStart = true; Executed by:
| 76 | ||||||||||||||||||||||||||||||
288 | - | |||||||||||||||||||||||||||||||
289 | if (t == Tokenizer::Token_Extension && !inSingleLineComment && !inMultiLineComment)
| 0-11134 | ||||||||||||||||||||||||||||||
290 | foundExtensionStart = true; never executed: foundExtensionStart = true; | 0 | ||||||||||||||||||||||||||||||
291 | - | |||||||||||||||||||||||||||||||
292 | if (foundVersionStart && t == Tokenizer::Token_NewLine) {
| 76-10678 | ||||||||||||||||||||||||||||||
293 | versionPos = tok.pos; | - | ||||||||||||||||||||||||||||||
294 | foundVersionStart = false; | - | ||||||||||||||||||||||||||||||
295 | } else if (foundExtensionStart && t == Tokenizer::Token_NewLine) { executed 76 times by 3 tests: end of block Executed by:
| 0-11058 | ||||||||||||||||||||||||||||||
296 | extensionPos = tok.pos; | - | ||||||||||||||||||||||||||||||
297 | foundExtensionStart = false; | - | ||||||||||||||||||||||||||||||
298 | } else if (lt == Tokenizer::Token_Void && t == Tokenizer::Token_Identifier) { never executed: end of block
| 0-10982 | ||||||||||||||||||||||||||||||
299 | if (qstrncmp("main", tok.identifier, 4) == 0)
| 0-76 | ||||||||||||||||||||||||||||||
300 | break; executed 76 times by 3 tests: break; Executed by:
| 76 | ||||||||||||||||||||||||||||||
301 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
302 | - | |||||||||||||||||||||||||||||||
303 | // Scan to next token | - | ||||||||||||||||||||||||||||||
304 | lt = t; | - | ||||||||||||||||||||||||||||||
305 | t = tok.next(); | - | ||||||||||||||||||||||||||||||
306 | } executed 11058 times by 3 tests: end of block Executed by:
| 11058 | ||||||||||||||||||||||||||||||
307 | - | |||||||||||||||||||||||||||||||
308 | // Determine where to insert the definition. | - | ||||||||||||||||||||||||||||||
309 | // If we found #extension directives, insert after last one, | - | ||||||||||||||||||||||||||||||
310 | // else, if we found #version insert after #version | - | ||||||||||||||||||||||||||||||
311 | // otherwise, insert at beginning. | - | ||||||||||||||||||||||||||||||
312 | const char *insertionPos = extensionPos ? extensionPos : (versionPos ? versionPos : input);
| 0-76 | ||||||||||||||||||||||||||||||
313 | - | |||||||||||||||||||||||||||||||
314 | // Construct a new shader string, inserting the definition | - | ||||||||||||||||||||||||||||||
315 | QByteArray newSource = QByteArray::fromRawData(input, insertionPos - input) | - | ||||||||||||||||||||||||||||||
316 | + "#define " + definition + '\n' | - | ||||||||||||||||||||||||||||||
317 | + QByteArray::fromRawData(insertionPos, m_source.size() - (insertionPos - input)); | - | ||||||||||||||||||||||||||||||
318 | m_source = std::move(newSource); | - | ||||||||||||||||||||||||||||||
319 | } executed 76 times by 3 tests: end of block Executed by:
| 76 | ||||||||||||||||||||||||||||||
320 | - | |||||||||||||||||||||||||||||||
321 | void QSGShaderSourceBuilder::removeVersion() | - | ||||||||||||||||||||||||||||||
322 | { | - | ||||||||||||||||||||||||||||||
323 | Tokenizer tok; | - | ||||||||||||||||||||||||||||||
324 | const char *input = m_source.constData(); | - | ||||||||||||||||||||||||||||||
325 | tok.initialize(input); | - | ||||||||||||||||||||||||||||||
326 | - | |||||||||||||||||||||||||||||||
327 | // First find #version beginning and end (if present) | - | ||||||||||||||||||||||||||||||
328 | const char *versionStartPos = nullptr; | - | ||||||||||||||||||||||||||||||
329 | const char *versionEndPos = nullptr; | - | ||||||||||||||||||||||||||||||
330 | bool inSingleLineComment = false; | - | ||||||||||||||||||||||||||||||
331 | bool inMultiLineComment = false; | - | ||||||||||||||||||||||||||||||
332 | bool foundVersionStart = false; | - | ||||||||||||||||||||||||||||||
333 | - | |||||||||||||||||||||||||||||||
334 | Tokenizer::Token lt = Tokenizer::Token_Unspecified; | - | ||||||||||||||||||||||||||||||
335 | Tokenizer::Token t = tok.next(); | - | ||||||||||||||||||||||||||||||
336 | while (t != Tokenizer::Token_EOF) {
| 0 | ||||||||||||||||||||||||||||||
337 | // Handle comment blocks | - | ||||||||||||||||||||||||||||||
338 | if (t == Tokenizer::Token_MultiLineCommentStart )
| 0 | ||||||||||||||||||||||||||||||
339 | inMultiLineComment = true; never executed: inMultiLineComment = true; | 0 | ||||||||||||||||||||||||||||||
340 | if (t == Tokenizer::Token_MultiLineCommentEnd)
| 0 | ||||||||||||||||||||||||||||||
341 | inMultiLineComment = false; never executed: inMultiLineComment = false; | 0 | ||||||||||||||||||||||||||||||
342 | if (t == Tokenizer::Token_SingleLineComment)
| 0 | ||||||||||||||||||||||||||||||
343 | inSingleLineComment = true; never executed: inSingleLineComment = true; | 0 | ||||||||||||||||||||||||||||||
344 | if (t == Tokenizer::Token_NewLine && inSingleLineComment && !inMultiLineComment)
| 0 | ||||||||||||||||||||||||||||||
345 | inSingleLineComment = false; never executed: inSingleLineComment = false; | 0 | ||||||||||||||||||||||||||||||
346 | - | |||||||||||||||||||||||||||||||
347 | // Have we found #version, #extension or void main()? | - | ||||||||||||||||||||||||||||||
348 | if (t == Tokenizer::Token_Version && !inSingleLineComment && !inMultiLineComment) {
| 0 | ||||||||||||||||||||||||||||||
349 | versionStartPos = tok.pos - 1; | - | ||||||||||||||||||||||||||||||
350 | foundVersionStart = true; | - | ||||||||||||||||||||||||||||||
351 | } else if (foundVersionStart && t == Tokenizer::Token_NewLine) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
352 | versionEndPos = tok.pos; | - | ||||||||||||||||||||||||||||||
353 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
354 | } else if (lt == Tokenizer::Token_Void && t == Tokenizer::Token_Identifier) {
| 0 | ||||||||||||||||||||||||||||||
355 | if (qstrncmp("main", tok.identifier, 4) == 0)
| 0 | ||||||||||||||||||||||||||||||
356 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
357 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
358 | - | |||||||||||||||||||||||||||||||
359 | // Scan to next token | - | ||||||||||||||||||||||||||||||
360 | lt = t; | - | ||||||||||||||||||||||||||||||
361 | t = tok.next(); | - | ||||||||||||||||||||||||||||||
362 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
363 | - | |||||||||||||||||||||||||||||||
364 | if (versionStartPos == nullptr)
| 0 | ||||||||||||||||||||||||||||||
365 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
366 | - | |||||||||||||||||||||||||||||||
367 | // Construct a new shader string, inserting the definition | - | ||||||||||||||||||||||||||||||
368 | QByteArray newSource; | - | ||||||||||||||||||||||||||||||
369 | newSource.reserve(m_source.size() - (versionEndPos - versionStartPos)); | - | ||||||||||||||||||||||||||||||
370 | newSource += QByteArray::fromRawData(input, versionStartPos - input); | - | ||||||||||||||||||||||||||||||
371 | newSource += QByteArray::fromRawData(versionEndPos, m_source.size() - (versionEndPos - versionStartPos)); | - | ||||||||||||||||||||||||||||||
372 | - | |||||||||||||||||||||||||||||||
373 | m_source = newSource; | - | ||||||||||||||||||||||||||||||
374 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
375 | - | |||||||||||||||||||||||||||||||
376 | QString QSGShaderSourceBuilder::resolveShaderPath(const QString &path) const | - | ||||||||||||||||||||||||||||||
377 | { | - | ||||||||||||||||||||||||||||||
378 | if (contextProfile() != QSurfaceFormat::CoreProfile) {
| 0-8973 | ||||||||||||||||||||||||||||||
379 | return path; executed 8973 times by 70 tests: return path; Executed by:
| 8973 | ||||||||||||||||||||||||||||||
380 | } else { | - | ||||||||||||||||||||||||||||||
381 | int idx = path.lastIndexOf(QLatin1Char('.')); | - | ||||||||||||||||||||||||||||||
382 | QString resolvedPath; | - | ||||||||||||||||||||||||||||||
383 | if (idx != -1)
| 0 | ||||||||||||||||||||||||||||||
384 | resolvedPath = path.leftRef(idx) never executed: resolvedPath = path.leftRef(idx) + QLatin1String("_core") + path.rightRef(path.length() - idx); | 0 | ||||||||||||||||||||||||||||||
385 | + QLatin1String("_core") never executed: resolvedPath = path.leftRef(idx) + QLatin1String("_core") + path.rightRef(path.length() - idx); | 0 | ||||||||||||||||||||||||||||||
386 | + path.rightRef(path.length() - idx); never executed: resolvedPath = path.leftRef(idx) + QLatin1String("_core") + path.rightRef(path.length() - idx); | 0 | ||||||||||||||||||||||||||||||
387 | return resolvedPath; never executed: return resolvedPath; | 0 | ||||||||||||||||||||||||||||||
388 | } | - | ||||||||||||||||||||||||||||||
389 | } | - | ||||||||||||||||||||||||||||||
390 | - | |||||||||||||||||||||||||||||||
391 | QSurfaceFormat::OpenGLContextProfile QSGShaderSourceBuilder::contextProfile() const | - | ||||||||||||||||||||||||||||||
392 | { | - | ||||||||||||||||||||||||||||||
393 | QOpenGLContext *context = QOpenGLContext::currentContext(); | - | ||||||||||||||||||||||||||||||
394 | QSurfaceFormat::OpenGLContextProfile profile = QSurfaceFormat::NoProfile; | - | ||||||||||||||||||||||||||||||
395 | if (context)
| 0-8973 | ||||||||||||||||||||||||||||||
396 | profile = context->format().profile(); executed 8973 times by 70 tests: profile = context->format().profile(); Executed by:
| 8973 | ||||||||||||||||||||||||||||||
397 | return profile; executed 8973 times by 70 tests: return profile; Executed by:
| 8973 | ||||||||||||||||||||||||||||||
398 | } | - | ||||||||||||||||||||||||||||||
399 | - | |||||||||||||||||||||||||||||||
400 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||||||||
Source code | Switch to Preprocessed file |