OpenCoverage

qsgdefaultspritenode.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/qsgdefaultspritenode.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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 "qsgdefaultspritenode_p.h"-
41-
42#include <QtQuick/QSGMaterial>-
43#include <QtGui/QOpenGLShaderProgram>-
44-
45QT_BEGIN_NAMESPACE-
46-
47struct SpriteVertex {-
48 float x;-
49 float y;-
50 float tx;-
51 float ty;-
52};-
53-
54struct SpriteVertices {-
55 SpriteVertex v1;-
56 SpriteVertex v2;-
57 SpriteVertex v3;-
58 SpriteVertex v4;-
59};-
60-
61class QQuickSpriteMaterial : public QSGMaterial-
62{-
63public:-
64 QQuickSpriteMaterial();-
65 ~QQuickSpriteMaterial();-
66 QSGMaterialType *type() const override { static QSGMaterialType type; return &type; }
executed 2033 times by 2 tests: return &type;
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
2033
67 QSGMaterialShader *createShader() const override;-
68 int compare(const QSGMaterial *other) const override-
69 {-
70 return this - static_cast<const QQuickSpriteMaterial *>(other);
never executed: return this - static_cast<const QQuickSpriteMaterial *>(other);
0
71 }-
72-
73 QSGTexture *texture = nullptr;-
74-
75 float animT = 0.0f;-
76 float animX1 = 0.0f;-
77 float animY1 = 0.0f;-
78 float animX2 = 0.0f;-
79 float animY2 = 0.0f;-
80 float animW = 1.0f;-
81 float animH = 1.0f;-
82};-
83-
84QQuickSpriteMaterial::QQuickSpriteMaterial()-
85{-
86 setFlag(Blending, true);-
87}
executed 30 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
30
88-
89QQuickSpriteMaterial::~QQuickSpriteMaterial()-
90{-
91 delete texture;-
92}
executed 30 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
30
93-
94class SpriteMaterialData : public QSGMaterialShader-
95{-
96public:-
97 SpriteMaterialData()-
98 {-
99 setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/sprite.vert"));
executed 30 times by 2 tests: return qstring_literal_temp;
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
30
100 setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/sprite.frag"));
executed 30 times by 2 tests: return qstring_literal_temp;
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
30
101 }
executed 30 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
30
102-
103 void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *) override-
104 {-
105 QQuickSpriteMaterial *m = static_cast<QQuickSpriteMaterial *>(newEffect);-
106 m->texture->bind();-
107-
108 program()->setUniformValue(m_opacity_id, state.opacity());-
109 program()->setUniformValue(m_animData_id, m->animW, m->animH, m->animT);-
110 program()->setUniformValue(m_animPos_id, m->animX1, m->animY1, m->animX2, m->animY2);-
111-
112 if (state.isMatrixDirty())
state.isMatrixDirty()Description
TRUEevaluated 2033 times by 2 tests
Evaluated by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
FALSEnever evaluated
0-2033
113 program()->setUniformValue(m_matrix_id, state.combinedMatrix());
executed 2033 times by 2 tests: program()->setUniformValue(m_matrix_id, state.combinedMatrix());
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
2033
114 }
executed 2033 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
2033
115-
116 void initialize() override {-
117 m_matrix_id = program()->uniformLocation("qt_Matrix");-
118 m_opacity_id = program()->uniformLocation("qt_Opacity");-
119 m_animData_id = program()->uniformLocation("animData");-
120 m_animPos_id = program()->uniformLocation("animPos");-
121 }
executed 30 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
30
122-
123 char const *const *attributeNames() const override {-
124 static const char *attr[] = {-
125 "vPos",-
126 "vTex",-
127 nullptr-
128 };-
129 return attr;
executed 6129 times by 2 tests: return attr;
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
6129
130 }-
131-
132 int m_matrix_id;-
133 int m_opacity_id;-
134 int m_animData_id;-
135 int m_animPos_id;-
136};-
137-
138QSGMaterialShader *QQuickSpriteMaterial::createShader() const-
139{-
140 return new SpriteMaterialData;
executed 30 times by 2 tests: return new SpriteMaterialData;
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
30
141}-
142-
143static QSGGeometry::Attribute Sprite_Attributes[] = {-
144 QSGGeometry::Attribute::create(0, 2, QSGGeometry::FloatType, true), // pos-
145 QSGGeometry::Attribute::create(1, 2, QSGGeometry::FloatType), // tex-
146};-
147-
148static QSGGeometry::AttributeSet Sprite_AttributeSet =-
149{-
150 2, // Attribute Count-
151 (2+2) * sizeof(float),-
152 Sprite_Attributes-
153};-
154-
155QSGDefaultSpriteNode::QSGDefaultSpriteNode()-
156 : m_material(new QQuickSpriteMaterial)-
157 , m_geometryDirty(true)-
158 , m_sheetSize(QSize(64, 64))-
159{-
160 // Setup geometry data-
161 m_geometry = new QSGGeometry(Sprite_AttributeSet, 4, 6);-
162 m_geometry->setDrawingMode(QSGGeometry::DrawTriangles);-
163 quint16 *indices = m_geometry->indexDataAsUShort();-
164 indices[0] = 0;-
165 indices[1] = 1;-
166 indices[2] = 2;-
167 indices[3] = 1;-
168 indices[4] = 3;-
169 indices[5] = 2;-
170-
171 setGeometry(m_geometry);-
172 setMaterial(m_material);-
173 setFlag(OwnsGeometry, true);-
174 setFlag(OwnsMaterial, true);-
175}
executed 30 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
30
176-
177void QSGDefaultSpriteNode::setTexture(QSGTexture *texture)-
178{-
179 m_material->texture = texture;-
180 m_geometryDirty = true;-
181 markDirty(DirtyMaterial);-
182}
executed 30 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
30
183-
184void QSGDefaultSpriteNode::setTime(float time)-
185{-
186 m_material->animT = time;-
187 markDirty(DirtyMaterial);-
188}
executed 2051 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
2051
189-
190void QSGDefaultSpriteNode::setSourceA(const QPoint &source)-
191{-
192 if (m_sourceA != source) {
m_sourceA != sourceDescription
TRUEevaluated 689 times by 2 tests
Evaluated by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
FALSEevaluated 1362 times by 2 tests
Evaluated by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
689-1362
193 m_sourceA = source;-
194 m_material->animX1 = static_cast<float>(source.x()) / m_sheetSize.width();-
195 m_material->animY1 = static_cast<float>(source.y()) / m_sheetSize.height();-
196 markDirty(DirtyMaterial);-
197 }
executed 689 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
689
198}
executed 2051 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
2051
199-
200void QSGDefaultSpriteNode::setSourceB(const QPoint &source)-
201{-
202 if (m_sourceB != source) {
m_sourceB != sourceDescription
TRUEevaluated 697 times by 2 tests
Evaluated by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
FALSEevaluated 1354 times by 2 tests
Evaluated by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
697-1354
203 m_sourceB = source;-
204 m_material->animX2 = static_cast<float>(source.x()) / m_sheetSize.width();-
205 m_material->animY2 = static_cast<float>(source.y()) / m_sheetSize.height();-
206 markDirty(DirtyMaterial);-
207 }
executed 697 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
697
208}
executed 2051 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
2051
209-
210void QSGDefaultSpriteNode::setSpriteSize(const QSize &size)-
211{-
212 if (m_spriteSize != size) {
m_spriteSize != sizeDescription
TRUEevaluated 32 times by 2 tests
Evaluated by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
FALSEevaluated 2019 times by 2 tests
Evaluated by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
32-2019
213 m_spriteSize = size;-
214 m_material->animW = static_cast<float>(size.width()) / m_sheetSize.width();-
215 m_material->animH = static_cast<float>(size.height()) / m_sheetSize.height();-
216 markDirty(DirtyMaterial);-
217 }
executed 32 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
32
218-
219}
executed 2051 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
2051
220-
221void QSGDefaultSpriteNode::setSheetSize(const QSize &size)-
222{-
223 if (m_sheetSize != size) {
m_sheetSize != sizeDescription
TRUEevaluated 30 times by 2 tests
Evaluated by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
FALSEnever evaluated
0-30
224 m_sheetSize = size;-
225-
226 // Update all dependent properties-
227 m_material->animX1 = static_cast<float>(m_sourceA.x()) / m_sheetSize.width();-
228 m_material->animY1 = static_cast<float>(m_sourceA.y()) / m_sheetSize.height();-
229 m_material->animX2 = static_cast<float>(m_sourceB.x()) / m_sheetSize.width();-
230 m_material->animY2 = static_cast<float>(m_sourceB.y()) / m_sheetSize.height();-
231 m_material->animW = static_cast<float>(m_spriteSize.width()) / m_sheetSize.width();-
232 m_material->animH = static_cast<float>(m_spriteSize.height()) / m_sheetSize.height();-
233 markDirty(DirtyMaterial);-
234 }
executed 30 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
30
235}
executed 30 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
30
236-
237void QSGDefaultSpriteNode::setSize(const QSizeF &size)-
238{-
239 if (m_size != size) {
m_size != sizeDescription
TRUEevaluated 30 times by 2 tests
Evaluated by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
FALSEevaluated 2021 times by 2 tests
Evaluated by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
30-2021
240 m_size = size;-
241 m_geometryDirty = true;-
242 }
executed 30 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
30
243}
executed 2051 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
2051
244-
245void QSGDefaultSpriteNode::setFiltering(QSGTexture::Filtering filtering)-
246{-
247 m_material->texture->setFiltering(filtering);-
248 markDirty(DirtyMaterial);-
249}
executed 2021 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
2021
250-
251void QSGDefaultSpriteNode::update()-
252{-
253 if (m_geometryDirty) {
m_geometryDirtyDescription
TRUEevaluated 30 times by 2 tests
Evaluated by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
FALSEevaluated 1991 times by 2 tests
Evaluated by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
30-1991
254 updateGeometry();-
255 m_geometryDirty = false;-
256 }
executed 30 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
30
257}
executed 2021 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
2021
258-
259void QSGDefaultSpriteNode::updateGeometry()-
260{-
261 if (!m_material->texture)
!m_material->textureDescription
TRUEnever evaluated
FALSEevaluated 30 times by 2 tests
Evaluated by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
0-30
262 return;
never executed: return;
0
263-
264 SpriteVertices *p = (SpriteVertices *) m_geometry->vertexData();-
265-
266 QRectF texRect = m_material->texture->normalizedTextureSubRect();-
267-
268 p->v1.tx = texRect.topLeft().x();-
269 p->v1.ty = texRect.topLeft().y();-
270-
271 p->v2.tx = texRect.topRight().x();-
272 p->v2.ty = texRect.topRight().y();-
273-
274 p->v3.tx = texRect.bottomLeft().x();-
275 p->v3.ty = texRect.bottomLeft().y();-
276-
277 p->v4.tx = texRect.bottomRight().x();-
278 p->v4.ty = texRect.bottomRight().y();-
279-
280 p->v1.x = 0;-
281 p->v1.y = 0;-
282-
283 p->v2.x = m_size.width();-
284 p->v2.y = 0;-
285-
286 p->v3.x = 0;-
287 p->v3.y = m_size.height();-
288-
289 p->v4.x = m_size.width();-
290 p->v4.y = m_size.height();-
291 markDirty(DirtyGeometry);-
292}
executed 30 times by 2 tests: end of block
Executed by:
  • tst_qquickanimatedsprite
  • tst_qquickspritesequence
30
293-
294QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0