OpenCoverage

qsgdefaultglyphnode.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/qsgdefaultglyphnode.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 "qsgdefaultglyphnode_p.h"-
41#include "qsgdefaultglyphnode_p_p.h"-
42-
43QT_BEGIN_NAMESPACE-
44-
45QSGDefaultGlyphNode::QSGDefaultGlyphNode()-
46 : m_glyphNodeType(RootGlyphNode)-
47 , m_dirtyGeometry(false)-
48{-
49 setFlag(UsePreprocess);-
50}
executed 72 times by 1 test: end of block
Executed by:
  • tst_scenegraph
72
51-
52QSGDefaultGlyphNode::~QSGDefaultGlyphNode()-
53{-
54 if (m_glyphNodeType == SubGlyphNode)
m_glyphNodeTyp...= SubGlyphNodeDescription
TRUEnever evaluated
FALSEevaluated 72 times by 1 test
Evaluated by:
  • tst_scenegraph
0-72
55 return;
never executed: return;
0
56-
57 qDeleteAll(m_nodesToDelete);-
58 m_nodesToDelete.clear();-
59}
executed 72 times by 1 test: end of block
Executed by:
  • tst_scenegraph
72
60-
61void QSGDefaultGlyphNode::setMaterialColor(const QColor &color)-
62{-
63 static_cast<QSGTextMaskMaterial *>(m_material)->setColor(color);-
64}
never executed: end of block
0
65-
66void QSGDefaultGlyphNode::setGlyphs(const QPointF &position, const QGlyphRun &glyphs)-
67{-
68 QSGBasicGlyphNode::setGlyphs(position, glyphs);-
69 m_dirtyGeometry = true;-
70}
executed 72 times by 1 test: end of block
Executed by:
  • tst_scenegraph
72
71-
72void QSGDefaultGlyphNode::update()-
73{-
74 QRawFont font = m_glyphs.rawFont();-
75 QMargins margins(0, 0, 0, 0);-
76-
77 if (m_style == QQuickText::Normal) {
m_style == QQuickText::NormalDescription
TRUEevaluated 72 times by 1 test
Evaluated by:
  • tst_scenegraph
FALSEnever evaluated
0-72
78 m_material = new QSGTextMaskMaterial(font);-
79 } else if (m_style == QQuickText::Outline) {
executed 72 times by 1 test: end of block
Executed by:
  • tst_scenegraph
m_style == QQuickText::OutlineDescription
TRUEnever evaluated
FALSEnever evaluated
0-72
80 QSGOutlinedTextMaterial *material = new QSGOutlinedTextMaterial(font);-
81 material->setStyleColor(m_styleColor);-
82 m_material = material;-
83 margins = QMargins(1, 1, 1, 1);-
84 } else {
never executed: end of block
0
85 QSGStyledTextMaterial *material = new QSGStyledTextMaterial(font);-
86 if (m_style == QQuickText::Sunken) {
m_style == QQuickText::SunkenDescription
TRUEnever evaluated
FALSEnever evaluated
0
87 material->setStyleShift(QVector2D(0, -1));-
88 margins.setTop(1);-
89 } else if (m_style == QQuickText::Raised) {
never executed: end of block
m_style == QQuickText::RaisedDescription
TRUEnever evaluated
FALSEnever evaluated
0
90 material->setStyleShift(QVector2D(0, 1));-
91 margins.setBottom(1);-
92 }
never executed: end of block
0
93 material->setStyleColor(m_styleColor);-
94 m_material = material;-
95 }
never executed: end of block
0
96-
97 QSGTextMaskMaterial *textMaskMaterial = static_cast<QSGTextMaskMaterial *>(m_material);-
98 textMaskMaterial->setColor(m_color);-
99-
100 QRectF boundingRect;-
101 textMaskMaterial->populate(m_position, m_glyphs.glyphIndexes(), m_glyphs.positions(), geometry(),-
102 &boundingRect, &m_baseLine, margins);-
103 setBoundingRect(boundingRect);-
104-
105 setMaterial(m_material);-
106 markDirty(DirtyGeometry);-
107}
executed 72 times by 1 test: end of block
Executed by:
  • tst_scenegraph
72
108-
109void QSGDefaultGlyphNode::preprocess()-
110{-
111 qDeleteAll(m_nodesToDelete);-
112 m_nodesToDelete.clear();-
113-
114 if (m_dirtyGeometry)
m_dirtyGeometryDescription
TRUEevaluated 72 times by 1 test
Evaluated by:
  • tst_scenegraph
FALSEevaluated 144 times by 1 test
Evaluated by:
  • tst_scenegraph
72-144
115 updateGeometry();
executed 72 times by 1 test: updateGeometry();
Executed by:
  • tst_scenegraph
72
116}
executed 216 times by 1 test: end of block
Executed by:
  • tst_scenegraph
216
117-
118void QSGDefaultGlyphNode::updateGeometry()-
119{-
120 // Remove previously created sub glyph nodes-
121 // We assume all the children are sub glyph nodes-
122 QSGNode *subnode = firstChild();-
123 while (subnode) {
subnodeDescription
TRUEnever evaluated
FALSEevaluated 72 times by 1 test
Evaluated by:
  • tst_scenegraph
0-72
124 // We can't delete the node now as it might be in the preprocess list-
125 // It will be deleted in the next preprocess-
126 m_nodesToDelete.append(subnode);-
127 subnode = subnode->nextSibling();-
128 }
never executed: end of block
0
129 removeAllChildNodes();-
130-
131 GlyphInfo glyphInfo;-
132-
133 const QVector<quint32> indexes = m_glyphs.glyphIndexes();-
134 const QVector<QPointF> positions = m_glyphs.positions();-
135-
136 const int maxGlyphs = (USHRT_MAX + 1) / 4; // 16384-
137 const int maxVertices = maxGlyphs * 4; // 65536-
138 const int maxIndexes = maxGlyphs * 6; // 98304-
139-
140 for (int i = 0; i < indexes.size(); ++i) {
i < indexes.size()Description
TRUEevaluated 4968 times by 1 test
Evaluated by:
  • tst_scenegraph
FALSEevaluated 72 times by 1 test
Evaluated by:
  • tst_scenegraph
72-4968
141 const int glyphIndex = indexes.at(i);-
142 const QPointF position = positions.at(i);-
143-
144 // As we use UNSIGNED_SHORT indexing in the geometry, we overload the-
145 // "glyphsInOtherNodes" concept as overflow for if there are more than-
146 // 65536 (16384 * 4) vertices to render which would otherwise exceed-
147 // the maximum index size. This will cause sub-nodes to be recursively-
148 // created to handle any number of glyphs.-
149 if (i >= maxGlyphs) {
i >= maxGlyphsDescription
TRUEnever evaluated
FALSEevaluated 4968 times by 1 test
Evaluated by:
  • tst_scenegraph
0-4968
150 glyphInfo.indexes.append(glyphIndex);-
151 glyphInfo.positions.append(position);-
152 continue;
never executed: continue;
0
153 }-
154 }
executed 4968 times by 1 test: end of block
Executed by:
  • tst_scenegraph
4968
155-
156 if (!glyphInfo.indexes.isEmpty()) {
!glyphInfo.indexes.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 72 times by 1 test
Evaluated by:
  • tst_scenegraph
0-72
157 QGlyphRun subNodeGlyphRun(m_glyphs);-
158 subNodeGlyphRun.setGlyphIndexes(glyphInfo.indexes);-
159 subNodeGlyphRun.setPositions(glyphInfo.positions);-
160-
161 QSGDefaultGlyphNode *subNode = new QSGDefaultGlyphNode();-
162 subNode->setGlyphNodeType(SubGlyphNode);-
163 subNode->setColor(m_color);-
164 subNode->setStyle(m_style);-
165 subNode->setStyleColor(m_styleColor);-
166 subNode->setGlyphs(m_position, subNodeGlyphRun);-
167 subNode->update();-
168 subNode->updateGeometry(); // we have to explicitly call this now as preprocess won't be called before it's rendered-
169 appendChildNode(subNode);-
170-
171 QSGGeometry *g = geometry();-
172-
173 QSGGeometry::TexturedPoint2D *vertexData = g->vertexDataAsTexturedPoint2D();-
174 quint16 *indexData = g->indexDataAsUShort();-
175-
176 QVector<QSGGeometry::TexturedPoint2D> tempVertexData(maxVertices);-
177 QVector<quint16> tempIndexData(maxIndexes);-
178-
179 for (int i = 0; i < maxGlyphs; i++) {
i < maxGlyphsDescription
TRUEnever evaluated
FALSEnever evaluated
0
180 tempVertexData[i * 4 + 0] = vertexData[i * 4 + 0];-
181 tempVertexData[i * 4 + 1] = vertexData[i * 4 + 1];-
182 tempVertexData[i * 4 + 2] = vertexData[i * 4 + 2];-
183 tempVertexData[i * 4 + 3] = vertexData[i * 4 + 3];-
184-
185 tempIndexData[i * 6 + 0] = indexData[i * 6 + 0];-
186 tempIndexData[i * 6 + 1] = indexData[i * 6 + 1];-
187 tempIndexData[i * 6 + 2] = indexData[i * 6 + 2];-
188 tempIndexData[i * 6 + 3] = indexData[i * 6 + 3];-
189 tempIndexData[i * 6 + 4] = indexData[i * 6 + 4];-
190 tempIndexData[i * 6 + 5] = indexData[i * 6 + 5];-
191 }
never executed: end of block
0
192-
193 g->allocate(maxVertices, maxIndexes);-
194 vertexData = g->vertexDataAsTexturedPoint2D();-
195 indexData = g->indexDataAsUShort();-
196-
197 for (int i = 0; i < maxGlyphs; i++) {
i < maxGlyphsDescription
TRUEnever evaluated
FALSEnever evaluated
0
198 vertexData[i * 4 + 0] = tempVertexData[i * 4 + 0];-
199 vertexData[i * 4 + 1] = tempVertexData[i * 4 + 1];-
200 vertexData[i * 4 + 2] = tempVertexData[i * 4 + 2];-
201 vertexData[i * 4 + 3] = tempVertexData[i * 4 + 3];-
202-
203 indexData[i * 6 + 0] = tempIndexData[i * 6 + 0];-
204 indexData[i * 6 + 1] = tempIndexData[i * 6 + 1];-
205 indexData[i * 6 + 2] = tempIndexData[i * 6 + 2];-
206 indexData[i * 6 + 3] = tempIndexData[i * 6 + 3];-
207 indexData[i * 6 + 4] = tempIndexData[i * 6 + 4];-
208 indexData[i * 6 + 5] = tempIndexData[i * 6 + 5];-
209 }
never executed: end of block
0
210 }
never executed: end of block
0
211-
212 m_dirtyGeometry = false;-
213}
executed 72 times by 1 test: end of block
Executed by:
  • tst_scenegraph
72
214-
215QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0