Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/qsgdefaultlayer.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 | #include "qsgdefaultlayer_p.h" | - | ||||||||||||||||||||||||||||||
40 | - | |||||||||||||||||||||||||||||||
41 | #include <private/qqmlglobal_p.h> | - | ||||||||||||||||||||||||||||||
42 | #include <private/qsgrenderer_p.h> | - | ||||||||||||||||||||||||||||||
43 | #include <private/qsgdefaultrendercontext_p.h> | - | ||||||||||||||||||||||||||||||
44 | - | |||||||||||||||||||||||||||||||
45 | #include <QtGui/QOpenGLFramebufferObject> | - | ||||||||||||||||||||||||||||||
46 | #include <QtGui/QOpenGLFunctions> | - | ||||||||||||||||||||||||||||||
47 | #include <QtGui/private/qopenglextensions_p.h> | - | ||||||||||||||||||||||||||||||
48 | - | |||||||||||||||||||||||||||||||
49 | #include <QtQuick/private/qsgdepthstencilbuffer_p.h> | - | ||||||||||||||||||||||||||||||
50 | - | |||||||||||||||||||||||||||||||
51 | #ifdef QSG_DEBUG_FBO_OVERLAY | - | ||||||||||||||||||||||||||||||
52 | DEFINE_BOOL_CONFIG_OPTION(qmlFboOverlay, QML_FBO_OVERLAY) never executed: status = Yes; never executed: end of block executed 10 times by 5 tests: end of block Executed by:
executed 170 times by 5 tests: return status == Yes; Executed by:
| 0-170 | ||||||||||||||||||||||||||||||
53 | #endif | - | ||||||||||||||||||||||||||||||
54 | DEFINE_BOOL_CONFIG_OPTION(qmlFboFlushBeforeDetach, QML_FBO_FLUSH_BEFORE_DETACH) never executed: status = Yes; never executed: end of block executed 10 times by 5 tests: end of block Executed by:
executed 85 times by 5 tests: return status == Yes; Executed by:
| 0-85 | ||||||||||||||||||||||||||||||
55 | - | |||||||||||||||||||||||||||||||
56 | namespace | - | ||||||||||||||||||||||||||||||
57 | { | - | ||||||||||||||||||||||||||||||
58 | class BindableFbo : public QSGBindable | - | ||||||||||||||||||||||||||||||
59 | { | - | ||||||||||||||||||||||||||||||
60 | public: | - | ||||||||||||||||||||||||||||||
61 | BindableFbo(QOpenGLFramebufferObject *fbo, QSGDepthStencilBuffer *depthStencil); | - | ||||||||||||||||||||||||||||||
62 | virtual ~BindableFbo(); | - | ||||||||||||||||||||||||||||||
63 | void bind() const override; | - | ||||||||||||||||||||||||||||||
64 | private: | - | ||||||||||||||||||||||||||||||
65 | QOpenGLFramebufferObject *m_fbo; | - | ||||||||||||||||||||||||||||||
66 | QSGDepthStencilBuffer *m_depthStencil; | - | ||||||||||||||||||||||||||||||
67 | }; | - | ||||||||||||||||||||||||||||||
68 | - | |||||||||||||||||||||||||||||||
69 | BindableFbo::BindableFbo(QOpenGLFramebufferObject *fbo, QSGDepthStencilBuffer *depthStencil) | - | ||||||||||||||||||||||||||||||
70 | : m_fbo(fbo) | - | ||||||||||||||||||||||||||||||
71 | , m_depthStencil(depthStencil) | - | ||||||||||||||||||||||||||||||
72 | { | - | ||||||||||||||||||||||||||||||
73 | } executed 85 times by 5 tests: end of block Executed by:
| 85 | ||||||||||||||||||||||||||||||
74 | - | |||||||||||||||||||||||||||||||
75 | BindableFbo::~BindableFbo() | - | ||||||||||||||||||||||||||||||
76 | { | - | ||||||||||||||||||||||||||||||
77 | if (qmlFboFlushBeforeDetach())
| 0-85 | ||||||||||||||||||||||||||||||
78 | QOpenGLContext::currentContext()->functions()->glFlush(); never executed: QOpenGLContext::currentContext()->functions()->glFlush(); | 0 | ||||||||||||||||||||||||||||||
79 | if (m_depthStencil)
| 0-85 | ||||||||||||||||||||||||||||||
80 | m_depthStencil->detach(); executed 85 times by 5 tests: m_depthStencil->detach(); Executed by:
| 85 | ||||||||||||||||||||||||||||||
81 | } executed 85 times by 5 tests: end of block Executed by:
| 85 | ||||||||||||||||||||||||||||||
82 | - | |||||||||||||||||||||||||||||||
83 | void BindableFbo::bind() const | - | ||||||||||||||||||||||||||||||
84 | { | - | ||||||||||||||||||||||||||||||
85 | m_fbo->bind(); | - | ||||||||||||||||||||||||||||||
86 | if (m_depthStencil)
| 0-85 | ||||||||||||||||||||||||||||||
87 | m_depthStencil->attach(); executed 85 times by 5 tests: m_depthStencil->attach(); Executed by:
| 85 | ||||||||||||||||||||||||||||||
88 | } executed 85 times by 5 tests: end of block Executed by:
| 85 | ||||||||||||||||||||||||||||||
89 | } | - | ||||||||||||||||||||||||||||||
90 | - | |||||||||||||||||||||||||||||||
91 | QSGDefaultLayer::QSGDefaultLayer(QSGRenderContext *context) | - | ||||||||||||||||||||||||||||||
92 | : QSGLayer() | - | ||||||||||||||||||||||||||||||
93 | , m_item(nullptr) | - | ||||||||||||||||||||||||||||||
94 | , m_device_pixel_ratio(1) | - | ||||||||||||||||||||||||||||||
95 | , m_format(GL_RGBA) | - | ||||||||||||||||||||||||||||||
96 | , m_renderer(nullptr) | - | ||||||||||||||||||||||||||||||
97 | , m_fbo(nullptr) | - | ||||||||||||||||||||||||||||||
98 | , m_secondaryFbo(nullptr) | - | ||||||||||||||||||||||||||||||
99 | , m_transparentTexture(0) | - | ||||||||||||||||||||||||||||||
100 | #ifdef QSG_DEBUG_FBO_OVERLAY | - | ||||||||||||||||||||||||||||||
101 | , m_debugOverlay(nullptr) | - | ||||||||||||||||||||||||||||||
102 | #endif | - | ||||||||||||||||||||||||||||||
103 | , m_samples(0) | - | ||||||||||||||||||||||||||||||
104 | , m_mipmap(false) | - | ||||||||||||||||||||||||||||||
105 | , m_live(true) | - | ||||||||||||||||||||||||||||||
106 | , m_recursive(false) | - | ||||||||||||||||||||||||||||||
107 | , m_dirtyTexture(true) | - | ||||||||||||||||||||||||||||||
108 | , m_multisamplingChecked(false) | - | ||||||||||||||||||||||||||||||
109 | , m_multisampling(false) | - | ||||||||||||||||||||||||||||||
110 | , m_grab(false) | - | ||||||||||||||||||||||||||||||
111 | , m_mirrorHorizontal(false) | - | ||||||||||||||||||||||||||||||
112 | , m_mirrorVertical(true) | - | ||||||||||||||||||||||||||||||
113 | { | - | ||||||||||||||||||||||||||||||
114 | m_context = static_cast<QSGDefaultRenderContext *>(context); | - | ||||||||||||||||||||||||||||||
115 | } executed 109 times by 6 tests: end of block Executed by:
| 109 | ||||||||||||||||||||||||||||||
116 | - | |||||||||||||||||||||||||||||||
117 | QSGDefaultLayer::~QSGDefaultLayer() | - | ||||||||||||||||||||||||||||||
118 | { | - | ||||||||||||||||||||||||||||||
119 | invalidated(); | - | ||||||||||||||||||||||||||||||
120 | } executed 109 times by 6 tests: end of block Executed by:
| 109 | ||||||||||||||||||||||||||||||
121 | - | |||||||||||||||||||||||||||||||
122 | void QSGDefaultLayer::invalidated() | - | ||||||||||||||||||||||||||||||
123 | { | - | ||||||||||||||||||||||||||||||
124 | delete m_renderer; | - | ||||||||||||||||||||||||||||||
125 | m_renderer = nullptr; | - | ||||||||||||||||||||||||||||||
126 | delete m_fbo; | - | ||||||||||||||||||||||||||||||
127 | delete m_secondaryFbo; | - | ||||||||||||||||||||||||||||||
128 | m_fbo = m_secondaryFbo = nullptr; | - | ||||||||||||||||||||||||||||||
129 | #ifdef QSG_DEBUG_FBO_OVERLAY | - | ||||||||||||||||||||||||||||||
130 | delete m_debugOverlay; | - | ||||||||||||||||||||||||||||||
131 | m_debugOverlay = nullptr; | - | ||||||||||||||||||||||||||||||
132 | #endif | - | ||||||||||||||||||||||||||||||
133 | if (m_transparentTexture) {
| 0-109 | ||||||||||||||||||||||||||||||
134 | QOpenGLContext::currentContext()->functions()->glDeleteTextures(1, &m_transparentTexture); | - | ||||||||||||||||||||||||||||||
135 | m_transparentTexture = 0; | - | ||||||||||||||||||||||||||||||
136 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
137 | } executed 109 times by 6 tests: end of block Executed by:
| 109 | ||||||||||||||||||||||||||||||
138 | - | |||||||||||||||||||||||||||||||
139 | int QSGDefaultLayer::textureId() const | - | ||||||||||||||||||||||||||||||
140 | { | - | ||||||||||||||||||||||||||||||
141 | return m_fbo ? m_fbo->texture() : 0; executed 26 times by 2 tests: return m_fbo ? m_fbo->texture() : 0; Executed by:
| 26 | ||||||||||||||||||||||||||||||
142 | } | - | ||||||||||||||||||||||||||||||
143 | - | |||||||||||||||||||||||||||||||
144 | bool QSGDefaultLayer::hasAlphaChannel() const | - | ||||||||||||||||||||||||||||||
145 | { | - | ||||||||||||||||||||||||||||||
146 | return m_format != GL_RGB; executed 318 times by 2 tests: return m_format != 0x1907 ; Executed by:
| 318 | ||||||||||||||||||||||||||||||
147 | } | - | ||||||||||||||||||||||||||||||
148 | - | |||||||||||||||||||||||||||||||
149 | bool QSGDefaultLayer::hasMipmaps() const | - | ||||||||||||||||||||||||||||||
150 | { | - | ||||||||||||||||||||||||||||||
151 | return m_mipmap; executed 96 times by 5 tests: return m_mipmap; Executed by:
| 96 | ||||||||||||||||||||||||||||||
152 | } | - | ||||||||||||||||||||||||||||||
153 | - | |||||||||||||||||||||||||||||||
154 | - | |||||||||||||||||||||||||||||||
155 | void QSGDefaultLayer::bind() | - | ||||||||||||||||||||||||||||||
156 | { | - | ||||||||||||||||||||||||||||||
157 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||||||||||||||
158 | if (!m_recursive && m_fbo && ((m_multisampling && m_secondaryFbo->isBound()) || m_fbo->isBound()))
| 0-425 | ||||||||||||||||||||||||||||||
159 | qWarning("ShaderEffectSource: \'recursive\' must be set to true when rendering recursively."); never executed: QMessageLogger(__FILE__, 159, __PRETTY_FUNCTION__).warning("ShaderEffectSource: \'recursive\' must be set to true when rendering recursively."); | 0 | ||||||||||||||||||||||||||||||
160 | #endif | - | ||||||||||||||||||||||||||||||
161 | QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); | - | ||||||||||||||||||||||||||||||
162 | if (!m_fbo && m_format == GL_RGBA) {
| 0-425 | ||||||||||||||||||||||||||||||
163 | if (m_transparentTexture == 0) {
| 0 | ||||||||||||||||||||||||||||||
164 | funcs->glGenTextures(1, &m_transparentTexture); | - | ||||||||||||||||||||||||||||||
165 | funcs->glBindTexture(GL_TEXTURE_2D, m_transparentTexture); | - | ||||||||||||||||||||||||||||||
166 | const uint zero = 0; | - | ||||||||||||||||||||||||||||||
167 | funcs->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &zero); | - | ||||||||||||||||||||||||||||||
168 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
169 | funcs->glBindTexture(GL_TEXTURE_2D, m_transparentTexture); | - | ||||||||||||||||||||||||||||||
170 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
171 | } else { | - | ||||||||||||||||||||||||||||||
172 | funcs->glBindTexture(GL_TEXTURE_2D, m_fbo ? m_fbo->texture() : 0); | - | ||||||||||||||||||||||||||||||
173 | updateBindOptions(); | - | ||||||||||||||||||||||||||||||
174 | } executed 425 times by 3 tests: end of block Executed by:
| 425 | ||||||||||||||||||||||||||||||
175 | } | - | ||||||||||||||||||||||||||||||
176 | - | |||||||||||||||||||||||||||||||
177 | bool QSGDefaultLayer::updateTexture() | - | ||||||||||||||||||||||||||||||
178 | { | - | ||||||||||||||||||||||||||||||
179 | bool doGrab = (m_live || m_grab) && m_dirtyTexture;
| 0-433 | ||||||||||||||||||||||||||||||
180 | if (doGrab)
| 85-348 | ||||||||||||||||||||||||||||||
181 | grab(); executed 85 times by 5 tests: grab(); Executed by:
| 85 | ||||||||||||||||||||||||||||||
182 | if (m_grab)
| 85-348 | ||||||||||||||||||||||||||||||
183 | emit scheduledUpdateCompleted(); executed 85 times by 5 tests: scheduledUpdateCompleted(); Executed by:
| 85 | ||||||||||||||||||||||||||||||
184 | m_grab = false; | - | ||||||||||||||||||||||||||||||
185 | return doGrab; executed 433 times by 5 tests: return doGrab; Executed by:
| 433 | ||||||||||||||||||||||||||||||
186 | } | - | ||||||||||||||||||||||||||||||
187 | - | |||||||||||||||||||||||||||||||
188 | void QSGDefaultLayer::setHasMipmaps(bool mipmap) | - | ||||||||||||||||||||||||||||||
189 | { | - | ||||||||||||||||||||||||||||||
190 | if (mipmap == m_mipmap)
| 2-181 | ||||||||||||||||||||||||||||||
191 | return; executed 181 times by 4 tests: return; Executed by:
| 181 | ||||||||||||||||||||||||||||||
192 | m_mipmap = mipmap; | - | ||||||||||||||||||||||||||||||
193 | if (m_mipmap && m_fbo && !m_fbo->format().mipmap())
| 0-2 | ||||||||||||||||||||||||||||||
194 | markDirtyTexture(); never executed: markDirtyTexture(); | 0 | ||||||||||||||||||||||||||||||
195 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||
196 | - | |||||||||||||||||||||||||||||||
197 | - | |||||||||||||||||||||||||||||||
198 | void QSGDefaultLayer::setItem(QSGNode *item) | - | ||||||||||||||||||||||||||||||
199 | { | - | ||||||||||||||||||||||||||||||
200 | if (item == m_item)
| 84-111 | ||||||||||||||||||||||||||||||
201 | return; executed 84 times by 3 tests: return; Executed by:
| 84 | ||||||||||||||||||||||||||||||
202 | m_item = item; | - | ||||||||||||||||||||||||||||||
203 | - | |||||||||||||||||||||||||||||||
204 | if (m_live && !m_item) {
| 0-111 | ||||||||||||||||||||||||||||||
205 | delete m_fbo; | - | ||||||||||||||||||||||||||||||
206 | delete m_secondaryFbo; | - | ||||||||||||||||||||||||||||||
207 | m_fbo = m_secondaryFbo = nullptr; | - | ||||||||||||||||||||||||||||||
208 | m_depthStencilBuffer.clear(); | - | ||||||||||||||||||||||||||||||
209 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||
210 | - | |||||||||||||||||||||||||||||||
211 | markDirtyTexture(); | - | ||||||||||||||||||||||||||||||
212 | } executed 111 times by 6 tests: end of block Executed by:
| 111 | ||||||||||||||||||||||||||||||
213 | - | |||||||||||||||||||||||||||||||
214 | void QSGDefaultLayer::setRect(const QRectF &rect) | - | ||||||||||||||||||||||||||||||
215 | { | - | ||||||||||||||||||||||||||||||
216 | if (rect == m_rect)
| 82-109 | ||||||||||||||||||||||||||||||
217 | return; executed 82 times by 3 tests: return; Executed by:
| 82 | ||||||||||||||||||||||||||||||
218 | m_rect = rect; | - | ||||||||||||||||||||||||||||||
219 | markDirtyTexture(); | - | ||||||||||||||||||||||||||||||
220 | } executed 109 times by 6 tests: end of block Executed by:
| 109 | ||||||||||||||||||||||||||||||
221 | - | |||||||||||||||||||||||||||||||
222 | void QSGDefaultLayer::setSize(const QSize &size) | - | ||||||||||||||||||||||||||||||
223 | { | - | ||||||||||||||||||||||||||||||
224 | if (size == m_size)
| 82-109 | ||||||||||||||||||||||||||||||
225 | return; executed 82 times by 3 tests: return; Executed by:
| 82 | ||||||||||||||||||||||||||||||
226 | m_size = size; | - | ||||||||||||||||||||||||||||||
227 | - | |||||||||||||||||||||||||||||||
228 | if (m_live && m_size.isNull()) {
| 0-109 | ||||||||||||||||||||||||||||||
229 | delete m_fbo; | - | ||||||||||||||||||||||||||||||
230 | delete m_secondaryFbo; | - | ||||||||||||||||||||||||||||||
231 | m_fbo = m_secondaryFbo = nullptr; | - | ||||||||||||||||||||||||||||||
232 | m_depthStencilBuffer.clear(); | - | ||||||||||||||||||||||||||||||
233 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
234 | - | |||||||||||||||||||||||||||||||
235 | markDirtyTexture(); | - | ||||||||||||||||||||||||||||||
236 | } executed 109 times by 6 tests: end of block Executed by:
| 109 | ||||||||||||||||||||||||||||||
237 | - | |||||||||||||||||||||||||||||||
238 | void QSGDefaultLayer::setFormat(GLenum format) | - | ||||||||||||||||||||||||||||||
239 | { | - | ||||||||||||||||||||||||||||||
240 | if (format == m_format)
| 0-183 | ||||||||||||||||||||||||||||||
241 | return; executed 183 times by 4 tests: return; Executed by:
| 183 | ||||||||||||||||||||||||||||||
242 | m_format = format; | - | ||||||||||||||||||||||||||||||
243 | markDirtyTexture(); | - | ||||||||||||||||||||||||||||||
244 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
245 | - | |||||||||||||||||||||||||||||||
246 | void QSGDefaultLayer::setLive(bool live) | - | ||||||||||||||||||||||||||||||
247 | { | - | ||||||||||||||||||||||||||||||
248 | if (live == m_live)
| 0-183 | ||||||||||||||||||||||||||||||
249 | return; executed 183 times by 4 tests: return; Executed by:
| 183 | ||||||||||||||||||||||||||||||
250 | m_live = live; | - | ||||||||||||||||||||||||||||||
251 | - | |||||||||||||||||||||||||||||||
252 | if (m_live && (!m_item || m_size.isNull())) {
| 0 | ||||||||||||||||||||||||||||||
253 | delete m_fbo; | - | ||||||||||||||||||||||||||||||
254 | delete m_secondaryFbo; | - | ||||||||||||||||||||||||||||||
255 | m_fbo = m_secondaryFbo = nullptr; | - | ||||||||||||||||||||||||||||||
256 | m_depthStencilBuffer.clear(); | - | ||||||||||||||||||||||||||||||
257 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
258 | - | |||||||||||||||||||||||||||||||
259 | markDirtyTexture(); | - | ||||||||||||||||||||||||||||||
260 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
261 | - | |||||||||||||||||||||||||||||||
262 | void QSGDefaultLayer::scheduleUpdate() | - | ||||||||||||||||||||||||||||||
263 | { | - | ||||||||||||||||||||||||||||||
264 | if (m_grab)
| 0-109 | ||||||||||||||||||||||||||||||
265 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
266 | m_grab = true; | - | ||||||||||||||||||||||||||||||
267 | if (m_dirtyTexture)
| 0-109 | ||||||||||||||||||||||||||||||
268 | emit updateRequested(); executed 109 times by 6 tests: updateRequested(); Executed by:
| 109 | ||||||||||||||||||||||||||||||
269 | } executed 109 times by 6 tests: end of block Executed by:
| 109 | ||||||||||||||||||||||||||||||
270 | - | |||||||||||||||||||||||||||||||
271 | void QSGDefaultLayer::setRecursive(bool recursive) | - | ||||||||||||||||||||||||||||||
272 | { | - | ||||||||||||||||||||||||||||||
273 | m_recursive = recursive; | - | ||||||||||||||||||||||||||||||
274 | } executed 183 times by 4 tests: end of block Executed by:
| 183 | ||||||||||||||||||||||||||||||
275 | - | |||||||||||||||||||||||||||||||
276 | void QSGDefaultLayer::setMirrorHorizontal(bool mirror) | - | ||||||||||||||||||||||||||||||
277 | { | - | ||||||||||||||||||||||||||||||
278 | m_mirrorHorizontal = mirror; | - | ||||||||||||||||||||||||||||||
279 | } executed 183 times by 4 tests: end of block Executed by:
| 183 | ||||||||||||||||||||||||||||||
280 | - | |||||||||||||||||||||||||||||||
281 | void QSGDefaultLayer::setMirrorVertical(bool mirror) | - | ||||||||||||||||||||||||||||||
282 | { | - | ||||||||||||||||||||||||||||||
283 | m_mirrorVertical = mirror; | - | ||||||||||||||||||||||||||||||
284 | } executed 183 times by 4 tests: end of block Executed by:
| 183 | ||||||||||||||||||||||||||||||
285 | - | |||||||||||||||||||||||||||||||
286 | void QSGDefaultLayer::markDirtyTexture() | - | ||||||||||||||||||||||||||||||
287 | { | - | ||||||||||||||||||||||||||||||
288 | m_dirtyTexture = true; | - | ||||||||||||||||||||||||||||||
289 | if (m_live || m_grab)
| 0-499 | ||||||||||||||||||||||||||||||
290 | emit updateRequested(); executed 499 times by 6 tests: updateRequested(); Executed by:
| 499 | ||||||||||||||||||||||||||||||
291 | } executed 499 times by 6 tests: end of block Executed by:
| 499 | ||||||||||||||||||||||||||||||
292 | - | |||||||||||||||||||||||||||||||
293 | void QSGDefaultLayer::grab() | - | ||||||||||||||||||||||||||||||
294 | { | - | ||||||||||||||||||||||||||||||
295 | if (!m_item || m_size.isNull()) {
| 0-85 | ||||||||||||||||||||||||||||||
296 | delete m_fbo; | - | ||||||||||||||||||||||||||||||
297 | delete m_secondaryFbo; | - | ||||||||||||||||||||||||||||||
298 | m_fbo = m_secondaryFbo = nullptr; | - | ||||||||||||||||||||||||||||||
299 | m_depthStencilBuffer.clear(); | - | ||||||||||||||||||||||||||||||
300 | m_dirtyTexture = false; | - | ||||||||||||||||||||||||||||||
301 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
302 | } | - | ||||||||||||||||||||||||||||||
303 | QSGNode *root = m_item; | - | ||||||||||||||||||||||||||||||
304 | while (root->firstChild() && root->type() != QSGNode::RootNodeType)
| 0-237 | ||||||||||||||||||||||||||||||
305 | root = root->firstChild(); executed 152 times by 5 tests: root = root->firstChild(); Executed by:
| 152 | ||||||||||||||||||||||||||||||
306 | if (root->type() != QSGNode::RootNodeType)
| 0-85 | ||||||||||||||||||||||||||||||
307 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
308 | - | |||||||||||||||||||||||||||||||
309 | if (!m_renderer) {
| 0-85 | ||||||||||||||||||||||||||||||
310 | m_renderer = m_context->createRenderer(); | - | ||||||||||||||||||||||||||||||
311 | connect(m_renderer, SIGNAL(sceneGraphChanged()), this, SLOT(markDirtyTexture())); | - | ||||||||||||||||||||||||||||||
312 | } executed 85 times by 5 tests: end of block Executed by:
| 85 | ||||||||||||||||||||||||||||||
313 | m_renderer->setDevicePixelRatio(m_device_pixel_ratio); | - | ||||||||||||||||||||||||||||||
314 | m_renderer->setRootNode(static_cast<QSGRootNode *>(root)); | - | ||||||||||||||||||||||||||||||
315 | - | |||||||||||||||||||||||||||||||
316 | QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); | - | ||||||||||||||||||||||||||||||
317 | bool deleteFboLater = false; | - | ||||||||||||||||||||||||||||||
318 | - | |||||||||||||||||||||||||||||||
319 | int effectiveSamples = m_samples; | - | ||||||||||||||||||||||||||||||
320 | // By default m_samples is 0. Fall back to the context's setting in this case. | - | ||||||||||||||||||||||||||||||
321 | if (effectiveSamples == 0)
| 2-83 | ||||||||||||||||||||||||||||||
322 | effectiveSamples = m_context->openglContext()->format().samples(); executed 83 times by 5 tests: effectiveSamples = m_context->openglContext()->format().samples(); Executed by:
| 83 | ||||||||||||||||||||||||||||||
323 | - | |||||||||||||||||||||||||||||||
324 | const bool needsNewFbo = !m_fbo || m_fbo->size() != m_size || m_fbo->format().internalTextureFormat() != m_format;
| 0-85 | ||||||||||||||||||||||||||||||
325 | const bool mipmapGotEnabled = m_fbo && !m_fbo->format().mipmap() && m_mipmap;
| 0-85 | ||||||||||||||||||||||||||||||
326 | const bool msaaGotEnabled = effectiveSamples > 1 && (!m_secondaryFbo || m_secondaryFbo->format().samples() != effectiveSamples);
| 0-83 | ||||||||||||||||||||||||||||||
327 | const bool msaaGotDisabled = effectiveSamples <= 1 && m_secondaryFbo;
| 0-83 | ||||||||||||||||||||||||||||||
328 | - | |||||||||||||||||||||||||||||||
329 | if (needsNewFbo || mipmapGotEnabled || msaaGotEnabled || msaaGotDisabled) {
| 0-85 | ||||||||||||||||||||||||||||||
330 | if (!m_multisamplingChecked) {
| 0-85 | ||||||||||||||||||||||||||||||
331 | if (effectiveSamples <= 1) {
| 2-83 | ||||||||||||||||||||||||||||||
332 | m_multisampling = false; | - | ||||||||||||||||||||||||||||||
333 | } else { executed 83 times by 5 tests: end of block Executed by:
| 83 | ||||||||||||||||||||||||||||||
334 | QOpenGLExtensions *e = static_cast<QOpenGLExtensions *>(funcs); | - | ||||||||||||||||||||||||||||||
335 | m_multisampling = e->hasOpenGLExtension(QOpenGLExtensions::FramebufferMultisample)
| 0-2 | ||||||||||||||||||||||||||||||
336 | && e->hasOpenGLExtension(QOpenGLExtensions::FramebufferBlit);
| 0-2 | ||||||||||||||||||||||||||||||
337 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||
338 | m_multisamplingChecked = true; | - | ||||||||||||||||||||||||||||||
339 | } executed 85 times by 5 tests: end of block Executed by:
| 85 | ||||||||||||||||||||||||||||||
340 | if (m_multisampling) {
| 2-83 | ||||||||||||||||||||||||||||||
341 | // Don't delete the FBO right away in case it is used recursively. | - | ||||||||||||||||||||||||||||||
342 | deleteFboLater = true; | - | ||||||||||||||||||||||||||||||
343 | delete m_secondaryFbo; | - | ||||||||||||||||||||||||||||||
344 | QOpenGLFramebufferObjectFormat format; | - | ||||||||||||||||||||||||||||||
345 | - | |||||||||||||||||||||||||||||||
346 | format.setInternalTextureFormat(m_format); | - | ||||||||||||||||||||||||||||||
347 | format.setSamples(effectiveSamples); | - | ||||||||||||||||||||||||||||||
348 | m_secondaryFbo = new QOpenGLFramebufferObject(m_size, format); | - | ||||||||||||||||||||||||||||||
349 | m_depthStencilBuffer = m_context->depthStencilBufferForFbo(m_secondaryFbo); | - | ||||||||||||||||||||||||||||||
350 | } else { executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||
351 | QOpenGLFramebufferObjectFormat format; | - | ||||||||||||||||||||||||||||||
352 | format.setInternalTextureFormat(m_format); | - | ||||||||||||||||||||||||||||||
353 | format.setMipmap(m_mipmap); | - | ||||||||||||||||||||||||||||||
354 | if (m_recursive) {
| 0-83 | ||||||||||||||||||||||||||||||
355 | deleteFboLater = true; | - | ||||||||||||||||||||||||||||||
356 | delete m_secondaryFbo; | - | ||||||||||||||||||||||||||||||
357 | m_secondaryFbo = new QOpenGLFramebufferObject(m_size, format); | - | ||||||||||||||||||||||||||||||
358 | funcs->glBindTexture(GL_TEXTURE_2D, m_secondaryFbo->texture()); | - | ||||||||||||||||||||||||||||||
359 | updateBindOptions(true); | - | ||||||||||||||||||||||||||||||
360 | m_depthStencilBuffer = m_context->depthStencilBufferForFbo(m_secondaryFbo); | - | ||||||||||||||||||||||||||||||
361 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
362 | delete m_fbo; | - | ||||||||||||||||||||||||||||||
363 | delete m_secondaryFbo; | - | ||||||||||||||||||||||||||||||
364 | m_fbo = new QOpenGLFramebufferObject(m_size, format); | - | ||||||||||||||||||||||||||||||
365 | m_secondaryFbo = nullptr; | - | ||||||||||||||||||||||||||||||
366 | funcs->glBindTexture(GL_TEXTURE_2D, m_fbo->texture()); | - | ||||||||||||||||||||||||||||||
367 | updateBindOptions(true); | - | ||||||||||||||||||||||||||||||
368 | m_depthStencilBuffer = m_context->depthStencilBufferForFbo(m_fbo); | - | ||||||||||||||||||||||||||||||
369 | } executed 83 times by 5 tests: end of block Executed by:
| 83 | ||||||||||||||||||||||||||||||
370 | } | - | ||||||||||||||||||||||||||||||
371 | } | - | ||||||||||||||||||||||||||||||
372 | - | |||||||||||||||||||||||||||||||
373 | if (m_recursive && !m_secondaryFbo) {
| 0-85 | ||||||||||||||||||||||||||||||
374 | // m_fbo already created, m_recursive was just set. | - | ||||||||||||||||||||||||||||||
375 | Q_ASSERT(m_fbo); | - | ||||||||||||||||||||||||||||||
376 | Q_ASSERT(!m_multisampling); | - | ||||||||||||||||||||||||||||||
377 | - | |||||||||||||||||||||||||||||||
378 | m_secondaryFbo = new QOpenGLFramebufferObject(m_size, m_fbo->format()); | - | ||||||||||||||||||||||||||||||
379 | funcs->glBindTexture(GL_TEXTURE_2D, m_secondaryFbo->texture()); | - | ||||||||||||||||||||||||||||||
380 | updateBindOptions(true); | - | ||||||||||||||||||||||||||||||
381 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
382 | - | |||||||||||||||||||||||||||||||
383 | // Render texture. | - | ||||||||||||||||||||||||||||||
384 | root->markDirty(QSGNode::DirtyForceUpdate); // Force matrix, clip and opacity update. | - | ||||||||||||||||||||||||||||||
385 | m_renderer->nodeChanged(root, QSGNode::DirtyForceUpdate); // Force render list update. | - | ||||||||||||||||||||||||||||||
386 | - | |||||||||||||||||||||||||||||||
387 | #ifdef QSG_DEBUG_FBO_OVERLAY | - | ||||||||||||||||||||||||||||||
388 | if (qmlFboOverlay()) {
| 0-85 | ||||||||||||||||||||||||||||||
389 | if (!m_debugOverlay)
| 0 | ||||||||||||||||||||||||||||||
390 | m_debugOverlay = new QSGSimpleRectNode(); never executed: m_debugOverlay = new QSGSimpleRectNode(); | 0 | ||||||||||||||||||||||||||||||
391 | m_debugOverlay->setRect(QRectF(0, 0, m_size.width(), m_size.height())); | - | ||||||||||||||||||||||||||||||
392 | m_debugOverlay->setColor(QColor(0xff, 0x00, 0x80, 0x40)); | - | ||||||||||||||||||||||||||||||
393 | root->appendChildNode(m_debugOverlay); | - | ||||||||||||||||||||||||||||||
394 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
395 | #endif | - | ||||||||||||||||||||||||||||||
396 | - | |||||||||||||||||||||||||||||||
397 | m_dirtyTexture = false; | - | ||||||||||||||||||||||||||||||
398 | - | |||||||||||||||||||||||||||||||
399 | m_renderer->setDeviceRect(m_size); | - | ||||||||||||||||||||||||||||||
400 | m_renderer->setViewportRect(m_size); | - | ||||||||||||||||||||||||||||||
401 | QRectF mirrored(m_mirrorHorizontal ? m_rect.right() : m_rect.left(), | - | ||||||||||||||||||||||||||||||
402 | m_mirrorVertical ? m_rect.bottom() : m_rect.top(), | - | ||||||||||||||||||||||||||||||
403 | m_mirrorHorizontal ? -m_rect.width() : m_rect.width(), | - | ||||||||||||||||||||||||||||||
404 | m_mirrorVertical ? -m_rect.height() : m_rect.height()); | - | ||||||||||||||||||||||||||||||
405 | m_renderer->setProjectionMatrixToRect(mirrored); | - | ||||||||||||||||||||||||||||||
406 | m_renderer->setClearColor(Qt::transparent); | - | ||||||||||||||||||||||||||||||
407 | - | |||||||||||||||||||||||||||||||
408 | if (m_multisampling) {
| 2-83 | ||||||||||||||||||||||||||||||
409 | m_renderer->renderScene(BindableFbo(m_secondaryFbo, m_depthStencilBuffer.data())); | - | ||||||||||||||||||||||||||||||
410 | - | |||||||||||||||||||||||||||||||
411 | if (deleteFboLater) {
| 0-2 | ||||||||||||||||||||||||||||||
412 | delete m_fbo; | - | ||||||||||||||||||||||||||||||
413 | QOpenGLFramebufferObjectFormat format; | - | ||||||||||||||||||||||||||||||
414 | format.setInternalTextureFormat(m_format); | - | ||||||||||||||||||||||||||||||
415 | format.setAttachment(QOpenGLFramebufferObject::NoAttachment); | - | ||||||||||||||||||||||||||||||
416 | format.setMipmap(m_mipmap); | - | ||||||||||||||||||||||||||||||
417 | format.setSamples(0); | - | ||||||||||||||||||||||||||||||
418 | m_fbo = new QOpenGLFramebufferObject(m_size, format); | - | ||||||||||||||||||||||||||||||
419 | funcs->glBindTexture(GL_TEXTURE_2D, m_fbo->texture()); | - | ||||||||||||||||||||||||||||||
420 | updateBindOptions(true); | - | ||||||||||||||||||||||||||||||
421 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||
422 | - | |||||||||||||||||||||||||||||||
423 | QRect r(QPoint(), m_size); | - | ||||||||||||||||||||||||||||||
424 | QOpenGLFramebufferObject::blitFramebuffer(m_fbo, r, m_secondaryFbo, r); | - | ||||||||||||||||||||||||||||||
425 | } else { executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||
426 | if (m_recursive) {
| 0-83 | ||||||||||||||||||||||||||||||
427 | m_renderer->renderScene(BindableFbo(m_secondaryFbo, m_depthStencilBuffer.data())); | - | ||||||||||||||||||||||||||||||
428 | - | |||||||||||||||||||||||||||||||
429 | if (deleteFboLater) {
| 0 | ||||||||||||||||||||||||||||||
430 | delete m_fbo; | - | ||||||||||||||||||||||||||||||
431 | QOpenGLFramebufferObjectFormat format; | - | ||||||||||||||||||||||||||||||
432 | format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); | - | ||||||||||||||||||||||||||||||
433 | format.setInternalTextureFormat(m_format); | - | ||||||||||||||||||||||||||||||
434 | format.setMipmap(m_mipmap); | - | ||||||||||||||||||||||||||||||
435 | m_fbo = new QOpenGLFramebufferObject(m_size, format); | - | ||||||||||||||||||||||||||||||
436 | funcs->glBindTexture(GL_TEXTURE_2D, m_fbo->texture()); | - | ||||||||||||||||||||||||||||||
437 | updateBindOptions(true); | - | ||||||||||||||||||||||||||||||
438 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
439 | qSwap(m_fbo, m_secondaryFbo); | - | ||||||||||||||||||||||||||||||
440 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
441 | m_renderer->renderScene(BindableFbo(m_fbo, m_depthStencilBuffer.data())); | - | ||||||||||||||||||||||||||||||
442 | } executed 83 times by 5 tests: end of block Executed by:
| 83 | ||||||||||||||||||||||||||||||
443 | } | - | ||||||||||||||||||||||||||||||
444 | - | |||||||||||||||||||||||||||||||
445 | if (m_mipmap) {
| 2-83 | ||||||||||||||||||||||||||||||
446 | funcs->glBindTexture(GL_TEXTURE_2D, textureId()); | - | ||||||||||||||||||||||||||||||
447 | funcs->glGenerateMipmap(GL_TEXTURE_2D); | - | ||||||||||||||||||||||||||||||
448 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||
449 | - | |||||||||||||||||||||||||||||||
450 | root->markDirty(QSGNode::DirtyForceUpdate); // Force matrix, clip, opacity and render list update. | - | ||||||||||||||||||||||||||||||
451 | - | |||||||||||||||||||||||||||||||
452 | #ifdef QSG_DEBUG_FBO_OVERLAY | - | ||||||||||||||||||||||||||||||
453 | if (qmlFboOverlay())
| 0-85 | ||||||||||||||||||||||||||||||
454 | root->removeChildNode(m_debugOverlay); never executed: root->removeChildNode(m_debugOverlay); | 0 | ||||||||||||||||||||||||||||||
455 | #endif | - | ||||||||||||||||||||||||||||||
456 | if (m_recursive)
| 0-85 | ||||||||||||||||||||||||||||||
457 | markDirtyTexture(); // Continuously update if 'live' and 'recursive'. never executed: markDirtyTexture(); | 0 | ||||||||||||||||||||||||||||||
458 | } executed 85 times by 5 tests: end of block Executed by:
| 85 | ||||||||||||||||||||||||||||||
459 | - | |||||||||||||||||||||||||||||||
460 | QImage QSGDefaultLayer::toImage() const | - | ||||||||||||||||||||||||||||||
461 | { | - | ||||||||||||||||||||||||||||||
462 | if (m_fbo)
| 0-8 | ||||||||||||||||||||||||||||||
463 | return m_fbo->toImage(); executed 8 times by 2 tests: return m_fbo->toImage(); Executed by:
| 8 | ||||||||||||||||||||||||||||||
464 | - | |||||||||||||||||||||||||||||||
465 | return QImage(); never executed: return QImage(); | 0 | ||||||||||||||||||||||||||||||
466 | } | - | ||||||||||||||||||||||||||||||
467 | - | |||||||||||||||||||||||||||||||
468 | QRectF QSGDefaultLayer::normalizedTextureSubRect() const | - | ||||||||||||||||||||||||||||||
469 | { | - | ||||||||||||||||||||||||||||||
470 | return QRectF(m_mirrorHorizontal ? 1 : 0, executed 126 times by 2 tests: return QRectF(m_mirrorHorizontal ? 1 : 0, m_mirrorVertical ? 0 : 1, m_mirrorHorizontal ? -1 : 1, m_mirrorVertical ? 1 : -1); Executed by:
| 126 | ||||||||||||||||||||||||||||||
471 | m_mirrorVertical ? 0 : 1, executed 126 times by 2 tests: return QRectF(m_mirrorHorizontal ? 1 : 0, m_mirrorVertical ? 0 : 1, m_mirrorHorizontal ? -1 : 1, m_mirrorVertical ? 1 : -1); Executed by:
| 126 | ||||||||||||||||||||||||||||||
472 | m_mirrorHorizontal ? -1 : 1, executed 126 times by 2 tests: return QRectF(m_mirrorHorizontal ? 1 : 0, m_mirrorVertical ? 0 : 1, m_mirrorHorizontal ? -1 : 1, m_mirrorVertical ? 1 : -1); Executed by:
| 126 | ||||||||||||||||||||||||||||||
473 | m_mirrorVertical ? 1 : -1); executed 126 times by 2 tests: return QRectF(m_mirrorHorizontal ? 1 : 0, m_mirrorVertical ? 0 : 1, m_mirrorHorizontal ? -1 : 1, m_mirrorVertical ? 1 : -1); Executed by:
| 126 | ||||||||||||||||||||||||||||||
474 | } | - | ||||||||||||||||||||||||||||||
475 | - | |||||||||||||||||||||||||||||||
476 | #include "moc_qsgdefaultlayer_p.cpp" | - | ||||||||||||||||||||||||||||||
Source code | Switch to Preprocessed file |