Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 "qsgdefaultinternalimagenode_p.h" | - | ||||||||||||
41 | #include <private/qsgmaterialshader_p.h> | - | ||||||||||||
42 | #include <private/qsgtexturematerial_p.h> | - | ||||||||||||
43 | #include <QtGui/qopenglfunctions.h> | - | ||||||||||||
44 | #include <QtCore/qmath.h> | - | ||||||||||||
45 | - | |||||||||||||
46 | QT_BEGIN_NAMESPACE | - | ||||||||||||
47 | - | |||||||||||||
48 | class SmoothTextureMaterialShader : public QSGTextureMaterialShader | - | ||||||||||||
49 | { | - | ||||||||||||
50 | public: | - | ||||||||||||
51 | SmoothTextureMaterialShader(); | - | ||||||||||||
52 | - | |||||||||||||
53 | void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; | - | ||||||||||||
54 | char const *const *attributeNames() const override; | - | ||||||||||||
55 | - | |||||||||||||
56 | protected: | - | ||||||||||||
57 | void initialize() override; | - | ||||||||||||
58 | - | |||||||||||||
59 | int m_pixelSizeLoc; | - | ||||||||||||
60 | }; | - | ||||||||||||
61 | - | |||||||||||||
62 | - | |||||||||||||
63 | QSGSmoothTextureMaterial::QSGSmoothTextureMaterial() | - | ||||||||||||
64 | { | - | ||||||||||||
65 | setFlag(RequiresFullMatrixExceptTranslate, true); | - | ||||||||||||
66 | setFlag(Blending, true); | - | ||||||||||||
67 | } executed 5189 times by 10 tests: end of block Executed by:
| 5189 | ||||||||||||
68 | - | |||||||||||||
69 | void QSGSmoothTextureMaterial::setTexture(QSGTexture *texture) | - | ||||||||||||
70 | { | - | ||||||||||||
71 | m_texture = texture; | - | ||||||||||||
72 | } executed 5245 times by 10 tests: end of block Executed by:
| 5245 | ||||||||||||
73 | - | |||||||||||||
74 | QSGMaterialType *QSGSmoothTextureMaterial::type() const | - | ||||||||||||
75 | { | - | ||||||||||||
76 | static QSGMaterialType type; | - | ||||||||||||
77 | return &type; never executed: return &type; | 0 | ||||||||||||
78 | } | - | ||||||||||||
79 | - | |||||||||||||
80 | QSGMaterialShader *QSGSmoothTextureMaterial::createShader() const | - | ||||||||||||
81 | { | - | ||||||||||||
82 | return new SmoothTextureMaterialShader; never executed: return new SmoothTextureMaterialShader; | 0 | ||||||||||||
83 | } | - | ||||||||||||
84 | - | |||||||||||||
85 | SmoothTextureMaterialShader::SmoothTextureMaterialShader() | - | ||||||||||||
86 | { | - | ||||||||||||
87 | setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/smoothtexture.vert")); never executed: return qstring_literal_temp; | 0 | ||||||||||||
88 | setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/smoothtexture.frag")); never executed: return qstring_literal_temp; | 0 | ||||||||||||
89 | } never executed: end of block | 0 | ||||||||||||
90 | - | |||||||||||||
91 | void SmoothTextureMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) | - | ||||||||||||
92 | { | - | ||||||||||||
93 | if (oldEffect == nullptr) {
| 0 | ||||||||||||
94 | // The viewport is constant, so set the pixel size uniform only once. | - | ||||||||||||
95 | QRect r = state.viewportRect(); | - | ||||||||||||
96 | program()->setUniformValue(m_pixelSizeLoc, 2.0f / r.width(), 2.0f / r.height()); | - | ||||||||||||
97 | } never executed: end of block | 0 | ||||||||||||
98 | QSGTextureMaterialShader::updateState(state, newEffect, oldEffect); | - | ||||||||||||
99 | } never executed: end of block | 0 | ||||||||||||
100 | - | |||||||||||||
101 | char const *const *SmoothTextureMaterialShader::attributeNames() const | - | ||||||||||||
102 | { | - | ||||||||||||
103 | static char const *const attributes[] = { | - | ||||||||||||
104 | "vertex", | - | ||||||||||||
105 | "multiTexCoord", | - | ||||||||||||
106 | "vertexOffset", | - | ||||||||||||
107 | "texCoordOffset", | - | ||||||||||||
108 | nullptr | - | ||||||||||||
109 | }; | - | ||||||||||||
110 | return attributes; never executed: return attributes; | 0 | ||||||||||||
111 | } | - | ||||||||||||
112 | - | |||||||||||||
113 | void SmoothTextureMaterialShader::initialize() | - | ||||||||||||
114 | { | - | ||||||||||||
115 | m_pixelSizeLoc = program()->uniformLocation("pixelSize"); | - | ||||||||||||
116 | QSGTextureMaterialShader::initialize(); | - | ||||||||||||
117 | } never executed: end of block | 0 | ||||||||||||
118 | - | |||||||||||||
119 | QSGDefaultInternalImageNode::QSGDefaultInternalImageNode() | - | ||||||||||||
120 | { | - | ||||||||||||
121 | setMaterial(&m_materialO); | - | ||||||||||||
122 | setOpaqueMaterial(&m_material); | - | ||||||||||||
123 | } executed 5189 times by 10 tests: end of block Executed by:
| 5189 | ||||||||||||
124 | - | |||||||||||||
125 | void QSGDefaultInternalImageNode::setFiltering(QSGTexture::Filtering filtering) | - | ||||||||||||
126 | { | - | ||||||||||||
127 | if (m_material.filtering() == filtering)
| 184-5121 | ||||||||||||
128 | return; executed 184 times by 5 tests: return; Executed by:
| 184 | ||||||||||||
129 | - | |||||||||||||
130 | m_material.setFiltering(filtering); | - | ||||||||||||
131 | m_materialO.setFiltering(filtering); | - | ||||||||||||
132 | m_smoothMaterial.setFiltering(filtering); | - | ||||||||||||
133 | markDirty(DirtyMaterial); | - | ||||||||||||
134 | } executed 5121 times by 10 tests: end of block Executed by:
| 5121 | ||||||||||||
135 | - | |||||||||||||
136 | void QSGDefaultInternalImageNode::setMipmapFiltering(QSGTexture::Filtering filtering) | - | ||||||||||||
137 | { | - | ||||||||||||
138 | if (m_material.mipmapFiltering() == filtering)
| 6-5269 | ||||||||||||
139 | return; executed 5269 times by 9 tests: return; Executed by:
| 5269 | ||||||||||||
140 | - | |||||||||||||
141 | m_material.setMipmapFiltering(filtering); | - | ||||||||||||
142 | m_materialO.setMipmapFiltering(filtering); | - | ||||||||||||
143 | m_smoothMaterial.setMipmapFiltering(filtering); | - | ||||||||||||
144 | markDirty(DirtyMaterial); | - | ||||||||||||
145 | } executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||||||||
146 | - | |||||||||||||
147 | void QSGDefaultInternalImageNode::setVerticalWrapMode(QSGTexture::WrapMode wrapMode) | - | ||||||||||||
148 | { | - | ||||||||||||
149 | if (m_material.verticalWrapMode() == wrapMode)
| 6-5269 | ||||||||||||
150 | return; executed 5269 times by 9 tests: return; Executed by:
| 5269 | ||||||||||||
151 | - | |||||||||||||
152 | m_material.setVerticalWrapMode(wrapMode); | - | ||||||||||||
153 | m_materialO.setVerticalWrapMode(wrapMode); | - | ||||||||||||
154 | m_smoothMaterial.setVerticalWrapMode(wrapMode); | - | ||||||||||||
155 | markDirty(DirtyMaterial); | - | ||||||||||||
156 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||
157 | - | |||||||||||||
158 | void QSGDefaultInternalImageNode::setHorizontalWrapMode(QSGTexture::WrapMode wrapMode) | - | ||||||||||||
159 | { | - | ||||||||||||
160 | if (m_material.horizontalWrapMode() == wrapMode)
| 8-5267 | ||||||||||||
161 | return; executed 5267 times by 9 tests: return; Executed by:
| 5267 | ||||||||||||
162 | - | |||||||||||||
163 | m_material.setHorizontalWrapMode(wrapMode); | - | ||||||||||||
164 | m_materialO.setHorizontalWrapMode(wrapMode); | - | ||||||||||||
165 | m_smoothMaterial.setHorizontalWrapMode(wrapMode); | - | ||||||||||||
166 | markDirty(DirtyMaterial); | - | ||||||||||||
167 | } executed 8 times by 2 tests: end of block Executed by:
| 8 | ||||||||||||
168 | - | |||||||||||||
169 | void QSGDefaultInternalImageNode::updateMaterialAntialiasing() | - | ||||||||||||
170 | { | - | ||||||||||||
171 | if (m_antialiasing) {
| 0 | ||||||||||||
172 | setMaterial(&m_smoothMaterial); | - | ||||||||||||
173 | setOpaqueMaterial(nullptr); | - | ||||||||||||
174 | } else { never executed: end of block | 0 | ||||||||||||
175 | setMaterial(&m_materialO); | - | ||||||||||||
176 | setOpaqueMaterial(&m_material); | - | ||||||||||||
177 | } never executed: end of block | 0 | ||||||||||||
178 | } | - | ||||||||||||
179 | - | |||||||||||||
180 | void QSGDefaultInternalImageNode::setMaterialTexture(QSGTexture *texture) | - | ||||||||||||
181 | { | - | ||||||||||||
182 | m_material.setTexture(texture); | - | ||||||||||||
183 | m_materialO.setTexture(texture); | - | ||||||||||||
184 | m_smoothMaterial.setTexture(texture); | - | ||||||||||||
185 | } executed 5245 times by 10 tests: end of block Executed by:
| 5245 | ||||||||||||
186 | - | |||||||||||||
187 | QSGTexture *QSGDefaultInternalImageNode::materialTexture() const | - | ||||||||||||
188 | { | - | ||||||||||||
189 | return m_material.texture(); executed 16148 times by 10 tests: return m_material.texture(); Executed by:
| 16148 | ||||||||||||
190 | } | - | ||||||||||||
191 | - | |||||||||||||
192 | bool QSGDefaultInternalImageNode::updateMaterialBlending() | - | ||||||||||||
193 | { | - | ||||||||||||
194 | const bool alpha = m_material.flags() & QSGMaterial::Blending; | - | ||||||||||||
195 | if (materialTexture() && alpha != materialTexture()->hasAlphaChannel()) {
| 0-5371 | ||||||||||||
196 | m_material.setFlag(QSGMaterial::Blending, !alpha); | - | ||||||||||||
197 | return true; never executed: return true; | 0 | ||||||||||||
198 | } | - | ||||||||||||
199 | return false; executed 5371 times by 10 tests: return false; Executed by:
| 5371 | ||||||||||||
200 | } | - | ||||||||||||
201 | - | |||||||||||||
202 | inline static bool isPowerOfTwo(int x) | - | ||||||||||||
203 | { | - | ||||||||||||
204 | // Assumption: x >= 1 | - | ||||||||||||
205 | return x == (x & -x); never executed: return x == (x & -x); | 0 | ||||||||||||
206 | } | - | ||||||||||||
207 | - | |||||||||||||
208 | bool QSGDefaultInternalImageNode::supportsWrap(const QSize &size) const | - | ||||||||||||
209 | { | - | ||||||||||||
210 | bool wrapSupported = true; | - | ||||||||||||
211 | - | |||||||||||||
212 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||
213 | #ifndef QT_OPENGL_ES_2 | - | ||||||||||||
214 | if (ctx->isOpenGLES())
| 0-10 | ||||||||||||
215 | #endif | - | ||||||||||||
216 | { | - | ||||||||||||
217 | bool npotSupported = ctx->functions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextureRepeat); | - | ||||||||||||
218 | const bool isNpot = !isPowerOfTwo(size.width()) || !isPowerOfTwo(size.height());
| 0 | ||||||||||||
219 | wrapSupported = npotSupported || !isNpot;
| 0 | ||||||||||||
220 | } never executed: end of block | 0 | ||||||||||||
221 | - | |||||||||||||
222 | return wrapSupported; executed 10 times by 1 test: return wrapSupported; Executed by:
| 10 | ||||||||||||
223 | } | - | ||||||||||||
224 | - | |||||||||||||
225 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |