Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/qsgdefaultspritenode.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | - | |||||||
4 | - | |||||||
5 | struct SpriteVertex { | - | ||||||
6 | float x; | - | ||||||
7 | float y; | - | ||||||
8 | float tx; | - | ||||||
9 | float ty; | - | ||||||
10 | }; | - | ||||||
11 | - | |||||||
12 | struct SpriteVertices { | - | ||||||
13 | SpriteVertex v1; | - | ||||||
14 | SpriteVertex v2; | - | ||||||
15 | SpriteVertex v3; | - | ||||||
16 | SpriteVertex v4; | - | ||||||
17 | }; | - | ||||||
18 | - | |||||||
19 | class QQuickSpriteMaterial : public QSGMaterial | - | ||||||
20 | { | - | ||||||
21 | public: | - | ||||||
22 | QQuickSpriteMaterial(); | - | ||||||
23 | ~QQuickSpriteMaterial(); | - | ||||||
24 | QSGMaterialType *type() const override { static QSGMaterialType type; return executed 2033 times by 2 tests: &type;return &type; Executed by:
executed 2033 times by 2 tests: }return &type; Executed by:
| 2033 | ||||||
25 | QSGMaterialShader *createShader() const override; | - | ||||||
26 | int compare(const QSGMaterial *other) const override | - | ||||||
27 | { | - | ||||||
28 | return never executed: this - static_cast<const QQuickSpriteMaterial *>(other);return this - static_cast<const QQuickSpriteMaterial *>(other); never executed: return this - static_cast<const QQuickSpriteMaterial *>(other); | 0 | ||||||
29 | } | - | ||||||
30 | - | |||||||
31 | QSGTexture *texture = nullptr; | - | ||||||
32 | - | |||||||
33 | float animT = 0.0f; | - | ||||||
34 | float animX1 = 0.0f; | - | ||||||
35 | float animY1 = 0.0f; | - | ||||||
36 | float animX2 = 0.0f; | - | ||||||
37 | float animY2 = 0.0f; | - | ||||||
38 | float animW = 1.0f; | - | ||||||
39 | float animH = 1.0f; | - | ||||||
40 | }; | - | ||||||
41 | - | |||||||
42 | QQuickSpriteMaterial::QQuickSpriteMaterial() | - | ||||||
43 | { | - | ||||||
44 | setFlag(Blending, true); | - | ||||||
45 | } executed 30 times by 2 tests: end of block Executed by:
| 30 | ||||||
46 | - | |||||||
47 | QQuickSpriteMaterial::~QQuickSpriteMaterial() | - | ||||||
48 | { | - | ||||||
49 | delete texture; | - | ||||||
50 | } executed 30 times by 2 tests: end of block Executed by:
| 30 | ||||||
51 | - | |||||||
52 | class SpriteMaterialData : public QSGMaterialShader | - | ||||||
53 | { | - | ||||||
54 | public: | - | ||||||
55 | SpriteMaterialData() | - | ||||||
56 | { | - | ||||||
57 | setShaderSourceFile(QOpenGLShader::Vertex, ([]() noexcept -> QString { enum { Size = sizeof(u"" ":/qt-project.org/scenegraph/shaders/sprite.vert")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" ":/qt-project.org/scenegraph/shaders/sprite.vert" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 30 times by 2 tests: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 30 times by 2 tests: }()));return qstring_literal_temp; Executed by:
| 30 | ||||||
58 | setShaderSourceFile(QOpenGLShader::Fragment, ([]() noexcept -> QString { enum { Size = sizeof(u"" ":/qt-project.org/scenegraph/shaders/sprite.frag")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" ":/qt-project.org/scenegraph/shaders/sprite.frag" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 30 times by 2 tests: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 30 times by 2 tests: }()));return qstring_literal_temp; Executed by:
| 30 | ||||||
59 | } executed 30 times by 2 tests: end of block Executed by:
| 30 | ||||||
60 | - | |||||||
61 | void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *) override | - | ||||||
62 | { | - | ||||||
63 | QQuickSpriteMaterial *m = static_cast<QQuickSpriteMaterial *>(newEffect); | - | ||||||
64 | m->texture->bind(); | - | ||||||
65 | - | |||||||
66 | program()->setUniformValue(m_opacity_id, state.opacity()); | - | ||||||
67 | program()->setUniformValue(m_animData_id, m->animW, m->animH, m->animT); | - | ||||||
68 | program()->setUniformValue(m_animPos_id, m->animX1, m->animY1, m->animX2, m->animY2); | - | ||||||
69 | - | |||||||
70 | if (state.isMatrixDirty()
| 0-2033 | ||||||
71 | program()->setUniformValue(m_matrix_id, state.combinedMatrix()); executed 2033 times by 2 tests: program()->setUniformValue(m_matrix_id, state.combinedMatrix()); Executed by:
| 2033 | ||||||
72 | } executed 2033 times by 2 tests: end of block Executed by:
| 2033 | ||||||
73 | - | |||||||
74 | void initialize() override { | - | ||||||
75 | m_matrix_id = program()->uniformLocation("qt_Matrix"); | - | ||||||
76 | m_opacity_id = program()->uniformLocation("qt_Opacity"); | - | ||||||
77 | m_animData_id = program()->uniformLocation("animData"); | - | ||||||
78 | m_animPos_id = program()->uniformLocation("animPos"); | - | ||||||
79 | } executed 30 times by 2 tests: end of block Executed by:
| 30 | ||||||
80 | - | |||||||
81 | char const *const *attributeNames() const override { | - | ||||||
82 | static const char *attr[] = { | - | ||||||
83 | "vPos", | - | ||||||
84 | "vTex", | - | ||||||
85 | nullptr | - | ||||||
86 | }; | - | ||||||
87 | return executed 6129 times by 2 tests: attr;return attr; Executed by:
executed 6129 times by 2 tests: return attr; Executed by:
| 6129 | ||||||
88 | } | - | ||||||
89 | - | |||||||
90 | int m_matrix_id; | - | ||||||
91 | int m_opacity_id; | - | ||||||
92 | int m_animData_id; | - | ||||||
93 | int m_animPos_id; | - | ||||||
94 | }; | - | ||||||
95 | - | |||||||
96 | QSGMaterialShader *QQuickSpriteMaterial::createShader() const | - | ||||||
97 | { | - | ||||||
98 | return executed 30 times by 2 tests: new SpriteMaterialData;return new SpriteMaterialData; Executed by:
executed 30 times by 2 tests: return new SpriteMaterialData; Executed by:
| 30 | ||||||
99 | } | - | ||||||
100 | - | |||||||
101 | static QSGGeometry::Attribute Sprite_Attributes[] = { | - | ||||||
102 | QSGGeometry::Attribute::create(0, 2, QSGGeometry::FloatType, true), | - | ||||||
103 | QSGGeometry::Attribute::create(1, 2, QSGGeometry::FloatType), | - | ||||||
104 | }; | - | ||||||
105 | - | |||||||
106 | static QSGGeometry::AttributeSet Sprite_AttributeSet = | - | ||||||
107 | { | - | ||||||
108 | 2, | - | ||||||
109 | (2+2) * sizeof(float), | - | ||||||
110 | Sprite_Attributes | - | ||||||
111 | }; | - | ||||||
112 | - | |||||||
113 | QSGDefaultSpriteNode::QSGDefaultSpriteNode() | - | ||||||
114 | : m_material(new QQuickSpriteMaterial) | - | ||||||
115 | , m_geometryDirty(true) | - | ||||||
116 | , m_sheetSize(QSize(64, 64)) | - | ||||||
117 | { | - | ||||||
118 | - | |||||||
119 | m_geometry = new QSGGeometry(Sprite_AttributeSet, 4, 6); | - | ||||||
120 | m_geometry->setDrawingMode(QSGGeometry::DrawTriangles); | - | ||||||
121 | quint16 *indices = m_geometry->indexDataAsUShort(); | - | ||||||
122 | indices[0] = 0; | - | ||||||
123 | indices[1] = 1; | - | ||||||
124 | indices[2] = 2; | - | ||||||
125 | indices[3] = 1; | - | ||||||
126 | indices[4] = 3; | - | ||||||
127 | indices[5] = 2; | - | ||||||
128 | - | |||||||
129 | setGeometry(m_geometry); | - | ||||||
130 | setMaterial(m_material); | - | ||||||
131 | setFlag(OwnsGeometry, true); | - | ||||||
132 | setFlag(OwnsMaterial, true); | - | ||||||
133 | } executed 30 times by 2 tests: end of block Executed by:
| 30 | ||||||
134 | - | |||||||
135 | void QSGDefaultSpriteNode::setTexture(QSGTexture *texture) | - | ||||||
136 | { | - | ||||||
137 | m_material->texture = texture; | - | ||||||
138 | m_geometryDirty = true; | - | ||||||
139 | markDirty(DirtyMaterial); | - | ||||||
140 | } executed 30 times by 2 tests: end of block Executed by:
| 30 | ||||||
141 | - | |||||||
142 | void QSGDefaultSpriteNode::setTime(float time) | - | ||||||
143 | { | - | ||||||
144 | m_material->animT = time; | - | ||||||
145 | markDirty(DirtyMaterial); | - | ||||||
146 | } executed 2051 times by 2 tests: end of block Executed by:
| 2051 | ||||||
147 | - | |||||||
148 | void QSGDefaultSpriteNode::setSourceA(const QPoint &source) | - | ||||||
149 | { | - | ||||||
150 | if (m_sourceA != source
| 689-1362 | ||||||
151 | m_sourceA = source; | - | ||||||
152 | m_material->animX1 = static_cast<float>(source.x()) / m_sheetSize.width(); | - | ||||||
153 | m_material->animY1 = static_cast<float>(source.y()) / m_sheetSize.height(); | - | ||||||
154 | markDirty(DirtyMaterial); | - | ||||||
155 | } executed 689 times by 2 tests: end of block Executed by:
| 689 | ||||||
156 | } executed 2051 times by 2 tests: end of block Executed by:
| 2051 | ||||||
157 | - | |||||||
158 | void QSGDefaultSpriteNode::setSourceB(const QPoint &source) | - | ||||||
159 | { | - | ||||||
160 | if (m_sourceB != source
| 697-1354 | ||||||
161 | m_sourceB = source; | - | ||||||
162 | m_material->animX2 = static_cast<float>(source.x()) / m_sheetSize.width(); | - | ||||||
163 | m_material->animY2 = static_cast<float>(source.y()) / m_sheetSize.height(); | - | ||||||
164 | markDirty(DirtyMaterial); | - | ||||||
165 | } executed 697 times by 2 tests: end of block Executed by:
| 697 | ||||||
166 | } executed 2051 times by 2 tests: end of block Executed by:
| 2051 | ||||||
167 | - | |||||||
168 | void QSGDefaultSpriteNode::setSpriteSize(const QSize &size) | - | ||||||
169 | { | - | ||||||
170 | if (m_spriteSize != size
| 32-2019 | ||||||
171 | m_spriteSize = size; | - | ||||||
172 | m_material->animW = static_cast<float>(size.width()) / m_sheetSize.width(); | - | ||||||
173 | m_material->animH = static_cast<float>(size.height()) / m_sheetSize.height(); | - | ||||||
174 | markDirty(DirtyMaterial); | - | ||||||
175 | } executed 32 times by 2 tests: end of block Executed by:
| 32 | ||||||
176 | - | |||||||
177 | } executed 2051 times by 2 tests: end of block Executed by:
| 2051 | ||||||
178 | - | |||||||
179 | void QSGDefaultSpriteNode::setSheetSize(const QSize &size) | - | ||||||
180 | { | - | ||||||
181 | if (m_sheetSize != size
| 0-30 | ||||||
182 | m_sheetSize = size; | - | ||||||
183 | - | |||||||
184 | - | |||||||
185 | m_material->animX1 = static_cast<float>(m_sourceA.x()) / m_sheetSize.width(); | - | ||||||
186 | m_material->animY1 = static_cast<float>(m_sourceA.y()) / m_sheetSize.height(); | - | ||||||
187 | m_material->animX2 = static_cast<float>(m_sourceB.x()) / m_sheetSize.width(); | - | ||||||
188 | m_material->animY2 = static_cast<float>(m_sourceB.y()) / m_sheetSize.height(); | - | ||||||
189 | m_material->animW = static_cast<float>(m_spriteSize.width()) / m_sheetSize.width(); | - | ||||||
190 | m_material->animH = static_cast<float>(m_spriteSize.height()) / m_sheetSize.height(); | - | ||||||
191 | markDirty(DirtyMaterial); | - | ||||||
192 | } executed 30 times by 2 tests: end of block Executed by:
| 30 | ||||||
193 | } executed 30 times by 2 tests: end of block Executed by:
| 30 | ||||||
194 | - | |||||||
195 | void QSGDefaultSpriteNode::setSize(const QSizeF &size) | - | ||||||
196 | { | - | ||||||
197 | if (m_size != size
| 30-2021 | ||||||
198 | m_size = size; | - | ||||||
199 | m_geometryDirty = true; | - | ||||||
200 | } executed 30 times by 2 tests: end of block Executed by:
| 30 | ||||||
201 | } executed 2051 times by 2 tests: end of block Executed by:
| 2051 | ||||||
202 | - | |||||||
203 | void QSGDefaultSpriteNode::setFiltering(QSGTexture::Filtering filtering) | - | ||||||
204 | { | - | ||||||
205 | m_material->texture->setFiltering(filtering); | - | ||||||
206 | markDirty(DirtyMaterial); | - | ||||||
207 | } executed 2021 times by 2 tests: end of block Executed by:
| 2021 | ||||||
208 | - | |||||||
209 | void QSGDefaultSpriteNode::update() | - | ||||||
210 | { | - | ||||||
211 | if (m_geometryDirty
| 30-1991 | ||||||
212 | updateGeometry(); | - | ||||||
213 | m_geometryDirty = false; | - | ||||||
214 | } executed 30 times by 2 tests: end of block Executed by:
| 30 | ||||||
215 | } executed 2021 times by 2 tests: end of block Executed by:
| 2021 | ||||||
216 | - | |||||||
217 | void QSGDefaultSpriteNode::updateGeometry() | - | ||||||
218 | { | - | ||||||
219 | if (!m_material->texture
| 0-30 | ||||||
220 | return; never executed: return; | 0 | ||||||
221 | - | |||||||
222 | SpriteVertices *p = (SpriteVertices *) m_geometry->vertexData(); | - | ||||||
223 | - | |||||||
224 | QRectF texRect = m_material->texture->normalizedTextureSubRect(); | - | ||||||
225 | - | |||||||
226 | p->v1.tx = texRect.topLeft().x(); | - | ||||||
227 | p->v1.ty = texRect.topLeft().y(); | - | ||||||
228 | - | |||||||
229 | p->v2.tx = texRect.topRight().x(); | - | ||||||
230 | p->v2.ty = texRect.topRight().y(); | - | ||||||
231 | - | |||||||
232 | p->v3.tx = texRect.bottomLeft().x(); | - | ||||||
233 | p->v3.ty = texRect.bottomLeft().y(); | - | ||||||
234 | - | |||||||
235 | p->v4.tx = texRect.bottomRight().x(); | - | ||||||
236 | p->v4.ty = texRect.bottomRight().y(); | - | ||||||
237 | - | |||||||
238 | p->v1.x = 0; | - | ||||||
239 | p->v1.y = 0; | - | ||||||
240 | - | |||||||
241 | p->v2.x = m_size.width(); | - | ||||||
242 | p->v2.y = 0; | - | ||||||
243 | - | |||||||
244 | p->v3.x = 0; | - | ||||||
245 | p->v3.y = m_size.height(); | - | ||||||
246 | - | |||||||
247 | p->v4.x = m_size.width(); | - | ||||||
248 | p->v4.y = m_size.height(); | - | ||||||
249 | markDirty(DirtyGeometry); | - | ||||||
250 | } executed 30 times by 2 tests: end of block Executed by:
| 30 | ||||||
251 | - | |||||||
252 | - | |||||||
Switch to Source code | Preprocessed file |