OpenCoverage

qsgflatcolormaterial.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/util/qsgflatcolormaterial.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 "qsgflatcolormaterial.h"-
41#include <private/qsgmaterialshader_p.h>-
42#if QT_CONFIG(opengl)-
43# include <qopenglshaderprogram.h>-
44#endif-
45-
46QT_BEGIN_NAMESPACE-
47-
48class FlatColorMaterialShader : public QSGMaterialShader-
49{-
50public:-
51 FlatColorMaterialShader();-
52-
53 void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override;-
54 char const *const *attributeNames() const override;-
55-
56 static QSGMaterialType type;-
57-
58private:-
59 void initialize() override;-
60#if QT_CONFIG(opengl)-
61 int m_matrix_id;-
62 int m_color_id;-
63#endif-
64};-
65-
66QSGMaterialType FlatColorMaterialShader::type;-
67-
68FlatColorMaterialShader::FlatColorMaterialShader()-
69 : QSGMaterialShader(*new QSGMaterialShaderPrivate)-
70{-
71#if QT_CONFIG(opengl)-
72 setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/flatcolor.vert"));
executed 6 times by 2 tests: return qstring_literal_temp;
Executed by:
  • tst_drawingmodes
  • tst_scenegraph
6
73 setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/flatcolor.frag"));
executed 6 times by 2 tests: return qstring_literal_temp;
Executed by:
  • tst_drawingmodes
  • tst_scenegraph
6
74#endif-
75}
executed 6 times by 2 tests: end of block
Executed by:
  • tst_drawingmodes
  • tst_scenegraph
6
76-
77void FlatColorMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)-
78{-
79#if QT_CONFIG(opengl)-
80 Q_ASSERT(oldEffect == nullptr || newEffect->type() == oldEffect->type());-
81 QSGFlatColorMaterial *oldMaterial = static_cast<QSGFlatColorMaterial *>(oldEffect);-
82 QSGFlatColorMaterial *newMaterial = static_cast<QSGFlatColorMaterial *>(newEffect);-
83-
84 const QColor &c = newMaterial->color();-
85-
86 if (oldMaterial == nullptr || c != oldMaterial->color() || state.isOpacityDirty()) {
oldMaterial == nullptrDescription
TRUEevaluated 78 times by 2 tests
Evaluated by:
  • tst_drawingmodes
  • tst_scenegraph
FALSEevaluated 52 times by 2 tests
Evaluated by:
  • tst_drawingmodes
  • tst_scenegraph
c != oldMaterial->color()Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • tst_scenegraph
FALSEevaluated 20 times by 1 test
Evaluated by:
  • tst_drawingmodes
state.isOpacityDirty()Description
TRUEnever evaluated
FALSEevaluated 20 times by 1 test
Evaluated by:
  • tst_drawingmodes
0-78
87 float opacity = state.opacity() * c.alphaF();-
88 QVector4D v(c.redF() * opacity,-
89 c.greenF() * opacity,-
90 c.blueF() * opacity,-
91 opacity);-
92 program()->setUniformValue(m_color_id, v);-
93 }
executed 110 times by 2 tests: end of block
Executed by:
  • tst_drawingmodes
  • tst_scenegraph
110
94-
95 if (state.isMatrixDirty())
state.isMatrixDirty()Description
TRUEevaluated 130 times by 2 tests
Evaluated by:
  • tst_drawingmodes
  • tst_scenegraph
FALSEnever evaluated
0-130
96 program()->setUniformValue(m_matrix_id, state.combinedMatrix());
executed 130 times by 2 tests: program()->setUniformValue(m_matrix_id, state.combinedMatrix());
Executed by:
  • tst_drawingmodes
  • tst_scenegraph
130
97#else-
98 Q_UNUSED(state)-
99 Q_UNUSED(newEffect)-
100 Q_UNUSED(oldEffect)-
101#endif-
102}
executed 130 times by 2 tests: end of block
Executed by:
  • tst_drawingmodes
  • tst_scenegraph
130
103-
104char const *const *FlatColorMaterialShader::attributeNames() const-
105{-
106 static char const *const attr[] = { "vCoord", nullptr };-
107 return attr;
executed 292 times by 2 tests: return attr;
Executed by:
  • tst_drawingmodes
  • tst_scenegraph
292
108}-
109-
110void FlatColorMaterialShader::initialize()-
111{-
112#if QT_CONFIG(opengl)-
113 m_matrix_id = program()->uniformLocation("matrix");-
114 m_color_id = program()->uniformLocation("color");-
115#endif-
116}
executed 6 times by 2 tests: end of block
Executed by:
  • tst_drawingmodes
  • tst_scenegraph
6
117-
118-
119-
120/*!-
121 \class QSGFlatColorMaterial-
122-
123 \brief The QSGFlatColorMaterial class provides a convenient way of rendering-
124 solid colored geometry in the scene graph.-
125-
126 \inmodule QtQuick-
127 \ingroup qtquick-scenegraph-materials-
128-
129 \warning This utility class is only functional when running with the OpenGL-
130 backend of the Qt Quick scenegraph.-
131-
132 The flat color material will fill every pixel in a geometry using-
133 a solid color. The color can contain transparency.-
134-
135 The geometry to be rendered with a flat color material requires-
136 vertices in attribute location 0 in the QSGGeometry object to render-
137 correctly. The QSGGeometry::defaultAttributes_Point2D() returns an attribute-
138 set compatible with this material.-
139-
140 The flat color material respects both current opacity and current matrix-
141 when updating its rendering state.-
142 */-
143-
144-
145/*!-
146 Constructs a new flat color material.-
147-
148 The default color is white.-
149 */-
150-
151QSGFlatColorMaterial::QSGFlatColorMaterial() : m_color(QColor(255, 255, 255))-
152{-
153}
executed 200024 times by 4 tests: end of block
Executed by:
  • tst_drawingmodes
  • tst_nodestest
  • tst_qquickshape
  • tst_scenegraph
200024
154-
155-
156-
157/*!-
158 \fn const QColor &QSGFlatColorMaterial::color() const-
159-
160 Returns this flat color material's color.-
161-
162 The default color is white.-
163 */-
164-
165-
166-
167/*!-
168 Sets this flat color material's color to \a color.-
169 */-
170-
171void QSGFlatColorMaterial::setColor(const QColor &color)-
172{-
173 m_color = color;-
174 setFlag(Blending, m_color.alpha() != 0xff);-
175}
executed 200014 times by 2 tests: end of block
Executed by:
  • tst_drawingmodes
  • tst_scenegraph
200014
176-
177-
178-
179/*!-
180 \internal-
181 */-
182-
183QSGMaterialType *QSGFlatColorMaterial::type() const-
184{-
185 return &FlatColorMaterialShader::type;
executed 1800194 times by 2 tests: return &FlatColorMaterialShader::type;
Executed by:
  • tst_drawingmodes
  • tst_scenegraph
1800194
186}-
187-
188-
189-
190/*!-
191 \internal-
192 */-
193-
194QSGMaterialShader *QSGFlatColorMaterial::createShader() const-
195{-
196 return new FlatColorMaterialShader;
executed 6 times by 2 tests: return new FlatColorMaterialShader;
Executed by:
  • tst_drawingmodes
  • tst_scenegraph
6
197}-
198-
199-
200/*!-
201 \internal-
202 */-
203-
204int QSGFlatColorMaterial::compare(const QSGMaterial *other) const-
205{-
206 const QSGFlatColorMaterial *flat = static_cast<const QSGFlatColorMaterial *>(other);-
207 return m_color.rgba() - flat->color().rgba();
executed 899990 times by 2 tests: return m_color.rgba() - flat->color().rgba();
Executed by:
  • tst_drawingmodes
  • tst_scenegraph
899990
208-
209}-
210-
211QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0