Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer.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 "qsgsoftwarelayer_p.h" | - | ||||||||||||||||||
41 | - | |||||||||||||||||||
42 | #include "qsgsoftwarecontext_p.h" | - | ||||||||||||||||||
43 | #include "qsgsoftwarepixmaprenderer_p.h" | - | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
46 | - | |||||||||||||||||||
47 | QSGSoftwareLayer::QSGSoftwareLayer(QSGRenderContext *renderContext) | - | ||||||||||||||||||
48 | : m_item(nullptr) | - | ||||||||||||||||||
49 | , m_context(renderContext) | - | ||||||||||||||||||
50 | , m_renderer(nullptr) | - | ||||||||||||||||||
51 | , m_device_pixel_ratio(1) | - | ||||||||||||||||||
52 | , m_mirrorHorizontal(false) | - | ||||||||||||||||||
53 | , m_mirrorVertical(true) | - | ||||||||||||||||||
54 | , m_live(true) | - | ||||||||||||||||||
55 | , m_grab(true) | - | ||||||||||||||||||
56 | , m_recursive(false) | - | ||||||||||||||||||
57 | , m_dirtyTexture(true) | - | ||||||||||||||||||
58 | { | - | ||||||||||||||||||
59 | - | |||||||||||||||||||
60 | } never executed: end of block | 0 | ||||||||||||||||||
61 | - | |||||||||||||||||||
62 | QSGSoftwareLayer::~QSGSoftwareLayer() | - | ||||||||||||||||||
63 | { | - | ||||||||||||||||||
64 | invalidated(); | - | ||||||||||||||||||
65 | } never executed: end of block | 0 | ||||||||||||||||||
66 | - | |||||||||||||||||||
67 | int QSGSoftwareLayer::textureId() const | - | ||||||||||||||||||
68 | { | - | ||||||||||||||||||
69 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
70 | } | - | ||||||||||||||||||
71 | - | |||||||||||||||||||
72 | QSize QSGSoftwareLayer::textureSize() const | - | ||||||||||||||||||
73 | { | - | ||||||||||||||||||
74 | return m_pixmap.size(); never executed: return m_pixmap.size(); | 0 | ||||||||||||||||||
75 | } | - | ||||||||||||||||||
76 | - | |||||||||||||||||||
77 | bool QSGSoftwareLayer::hasAlphaChannel() const | - | ||||||||||||||||||
78 | { | - | ||||||||||||||||||
79 | return m_pixmap.hasAlphaChannel(); never executed: return m_pixmap.hasAlphaChannel(); | 0 | ||||||||||||||||||
80 | } | - | ||||||||||||||||||
81 | - | |||||||||||||||||||
82 | bool QSGSoftwareLayer::hasMipmaps() const | - | ||||||||||||||||||
83 | { | - | ||||||||||||||||||
84 | return false; never executed: return false; | 0 | ||||||||||||||||||
85 | } | - | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | void QSGSoftwareLayer::bind() | - | ||||||||||||||||||
88 | { | - | ||||||||||||||||||
89 | } | - | ||||||||||||||||||
90 | - | |||||||||||||||||||
91 | bool QSGSoftwareLayer::updateTexture() | - | ||||||||||||||||||
92 | { | - | ||||||||||||||||||
93 | bool doGrab = (m_live || m_grab) && m_dirtyTexture;
| 0 | ||||||||||||||||||
94 | if (doGrab)
| 0 | ||||||||||||||||||
95 | grab(); never executed: grab(); | 0 | ||||||||||||||||||
96 | if (m_grab)
| 0 | ||||||||||||||||||
97 | emit scheduledUpdateCompleted(); never executed: scheduledUpdateCompleted(); | 0 | ||||||||||||||||||
98 | m_grab = false; | - | ||||||||||||||||||
99 | return doGrab; never executed: return doGrab; | 0 | ||||||||||||||||||
100 | } | - | ||||||||||||||||||
101 | - | |||||||||||||||||||
102 | void QSGSoftwareLayer::setItem(QSGNode *item) | - | ||||||||||||||||||
103 | { | - | ||||||||||||||||||
104 | if (item == m_item)
| 0 | ||||||||||||||||||
105 | return; never executed: return; | 0 | ||||||||||||||||||
106 | m_item = item; | - | ||||||||||||||||||
107 | - | |||||||||||||||||||
108 | if (m_live && !m_item)
| 0 | ||||||||||||||||||
109 | m_pixmap = QPixmap(); never executed: m_pixmap = QPixmap(); | 0 | ||||||||||||||||||
110 | - | |||||||||||||||||||
111 | markDirtyTexture(); | - | ||||||||||||||||||
112 | } never executed: end of block | 0 | ||||||||||||||||||
113 | - | |||||||||||||||||||
114 | void QSGSoftwareLayer::setRect(const QRectF &rect) | - | ||||||||||||||||||
115 | { | - | ||||||||||||||||||
116 | if (rect == m_rect)
| 0 | ||||||||||||||||||
117 | return; never executed: return; | 0 | ||||||||||||||||||
118 | m_rect = rect; | - | ||||||||||||||||||
119 | markDirtyTexture(); | - | ||||||||||||||||||
120 | } never executed: end of block | 0 | ||||||||||||||||||
121 | - | |||||||||||||||||||
122 | void QSGSoftwareLayer::setSize(const QSize &size) | - | ||||||||||||||||||
123 | { | - | ||||||||||||||||||
124 | if (size == m_size)
| 0 | ||||||||||||||||||
125 | return; never executed: return; | 0 | ||||||||||||||||||
126 | m_size = size; | - | ||||||||||||||||||
127 | - | |||||||||||||||||||
128 | if (m_live && m_size.isNull())
| 0 | ||||||||||||||||||
129 | m_pixmap = QPixmap(); never executed: m_pixmap = QPixmap(); | 0 | ||||||||||||||||||
130 | - | |||||||||||||||||||
131 | markDirtyTexture(); | - | ||||||||||||||||||
132 | } never executed: end of block | 0 | ||||||||||||||||||
133 | - | |||||||||||||||||||
134 | void QSGSoftwareLayer::scheduleUpdate() | - | ||||||||||||||||||
135 | { | - | ||||||||||||||||||
136 | if (m_grab)
| 0 | ||||||||||||||||||
137 | return; never executed: return; | 0 | ||||||||||||||||||
138 | m_grab = true; | - | ||||||||||||||||||
139 | if (m_dirtyTexture) {
| 0 | ||||||||||||||||||
140 | emit updateRequested(); | - | ||||||||||||||||||
141 | } never executed: end of block | 0 | ||||||||||||||||||
142 | } never executed: end of block | 0 | ||||||||||||||||||
143 | - | |||||||||||||||||||
144 | QImage QSGSoftwareLayer::toImage() const | - | ||||||||||||||||||
145 | { | - | ||||||||||||||||||
146 | return m_pixmap.toImage(); never executed: return m_pixmap.toImage(); | 0 | ||||||||||||||||||
147 | } | - | ||||||||||||||||||
148 | - | |||||||||||||||||||
149 | void QSGSoftwareLayer::setLive(bool live) | - | ||||||||||||||||||
150 | { | - | ||||||||||||||||||
151 | if (live == m_live)
| 0 | ||||||||||||||||||
152 | return; never executed: return; | 0 | ||||||||||||||||||
153 | m_live = live; | - | ||||||||||||||||||
154 | - | |||||||||||||||||||
155 | if (m_live && (!m_item || m_size.isNull()))
| 0 | ||||||||||||||||||
156 | m_pixmap = QPixmap(); never executed: m_pixmap = QPixmap(); | 0 | ||||||||||||||||||
157 | - | |||||||||||||||||||
158 | markDirtyTexture(); | - | ||||||||||||||||||
159 | } never executed: end of block | 0 | ||||||||||||||||||
160 | - | |||||||||||||||||||
161 | void QSGSoftwareLayer::setRecursive(bool recursive) | - | ||||||||||||||||||
162 | { | - | ||||||||||||||||||
163 | m_recursive = recursive; | - | ||||||||||||||||||
164 | } never executed: end of block | 0 | ||||||||||||||||||
165 | - | |||||||||||||||||||
166 | void QSGSoftwareLayer::setFormat(uint) | - | ||||||||||||||||||
167 | { | - | ||||||||||||||||||
168 | } | - | ||||||||||||||||||
169 | - | |||||||||||||||||||
170 | void QSGSoftwareLayer::setHasMipmaps(bool) | - | ||||||||||||||||||
171 | { | - | ||||||||||||||||||
172 | } | - | ||||||||||||||||||
173 | - | |||||||||||||||||||
174 | void QSGSoftwareLayer::setDevicePixelRatio(qreal ratio) | - | ||||||||||||||||||
175 | { | - | ||||||||||||||||||
176 | m_device_pixel_ratio = ratio; | - | ||||||||||||||||||
177 | } never executed: end of block | 0 | ||||||||||||||||||
178 | - | |||||||||||||||||||
179 | void QSGSoftwareLayer::setMirrorHorizontal(bool mirror) | - | ||||||||||||||||||
180 | { | - | ||||||||||||||||||
181 | if (m_mirrorHorizontal == mirror)
| 0 | ||||||||||||||||||
182 | return; never executed: return; | 0 | ||||||||||||||||||
183 | m_mirrorHorizontal = mirror; | - | ||||||||||||||||||
184 | markDirtyTexture(); | - | ||||||||||||||||||
185 | } never executed: end of block | 0 | ||||||||||||||||||
186 | - | |||||||||||||||||||
187 | void QSGSoftwareLayer::setMirrorVertical(bool mirror) | - | ||||||||||||||||||
188 | { | - | ||||||||||||||||||
189 | if (m_mirrorVertical == mirror)
| 0 | ||||||||||||||||||
190 | return; never executed: return; | 0 | ||||||||||||||||||
191 | m_mirrorVertical = mirror; | - | ||||||||||||||||||
192 | markDirtyTexture(); | - | ||||||||||||||||||
193 | } never executed: end of block | 0 | ||||||||||||||||||
194 | - | |||||||||||||||||||
195 | void QSGSoftwareLayer::markDirtyTexture() | - | ||||||||||||||||||
196 | { | - | ||||||||||||||||||
197 | m_dirtyTexture = true; | - | ||||||||||||||||||
198 | if (m_live || m_grab) {
| 0 | ||||||||||||||||||
199 | emit updateRequested(); | - | ||||||||||||||||||
200 | } never executed: end of block | 0 | ||||||||||||||||||
201 | } never executed: end of block | 0 | ||||||||||||||||||
202 | - | |||||||||||||||||||
203 | void QSGSoftwareLayer::invalidated() | - | ||||||||||||||||||
204 | { | - | ||||||||||||||||||
205 | delete m_renderer; | - | ||||||||||||||||||
206 | m_renderer = nullptr; | - | ||||||||||||||||||
207 | } never executed: end of block | 0 | ||||||||||||||||||
208 | - | |||||||||||||||||||
209 | void QSGSoftwareLayer::grab() | - | ||||||||||||||||||
210 | { | - | ||||||||||||||||||
211 | if (!m_item || m_size.isNull()) {
| 0 | ||||||||||||||||||
212 | m_pixmap = QPixmap(); | - | ||||||||||||||||||
213 | m_dirtyTexture = false; | - | ||||||||||||||||||
214 | return; never executed: return; | 0 | ||||||||||||||||||
215 | } | - | ||||||||||||||||||
216 | QSGNode *root = m_item; | - | ||||||||||||||||||
217 | while (root->firstChild() && root->type() != QSGNode::RootNodeType)
| 0 | ||||||||||||||||||
218 | root = root->firstChild(); never executed: root = root->firstChild(); | 0 | ||||||||||||||||||
219 | if (root->type() != QSGNode::RootNodeType)
| 0 | ||||||||||||||||||
220 | return; never executed: return; | 0 | ||||||||||||||||||
221 | - | |||||||||||||||||||
222 | if (!m_renderer) {
| 0 | ||||||||||||||||||
223 | m_renderer = new QSGSoftwarePixmapRenderer(m_context); | - | ||||||||||||||||||
224 | connect(m_renderer, SIGNAL(sceneGraphChanged()), this, SLOT(markDirtyTexture())); | - | ||||||||||||||||||
225 | } never executed: end of block | 0 | ||||||||||||||||||
226 | m_renderer->setDevicePixelRatio(m_device_pixel_ratio); | - | ||||||||||||||||||
227 | m_renderer->setRootNode(static_cast<QSGRootNode *>(root)); | - | ||||||||||||||||||
228 | - | |||||||||||||||||||
229 | if (m_pixmap.size() != m_size) {
| 0 | ||||||||||||||||||
230 | m_pixmap = QPixmap(m_size); | - | ||||||||||||||||||
231 | m_pixmap.setDevicePixelRatio(m_device_pixel_ratio); | - | ||||||||||||||||||
232 | } never executed: end of block | 0 | ||||||||||||||||||
233 | - | |||||||||||||||||||
234 | // Render texture. | - | ||||||||||||||||||
235 | root->markDirty(QSGNode::DirtyForceUpdate); // Force matrix, clip and opacity update. | - | ||||||||||||||||||
236 | m_renderer->nodeChanged(root, QSGNode::DirtyForceUpdate); // Force render list update. | - | ||||||||||||||||||
237 | - | |||||||||||||||||||
238 | m_dirtyTexture = false; | - | ||||||||||||||||||
239 | - | |||||||||||||||||||
240 | m_renderer->setDeviceRect(m_size); | - | ||||||||||||||||||
241 | m_renderer->setViewportRect(m_size); | - | ||||||||||||||||||
242 | QRect mirrored(m_mirrorHorizontal ? m_rect.right() * m_device_pixel_ratio : m_rect.left() * m_device_pixel_ratio, | - | ||||||||||||||||||
243 | m_mirrorVertical ? m_rect.bottom() * m_device_pixel_ratio : m_rect.top() * m_device_pixel_ratio, | - | ||||||||||||||||||
244 | m_mirrorHorizontal ? -m_rect.width() * m_device_pixel_ratio : m_rect.width() * m_device_pixel_ratio, | - | ||||||||||||||||||
245 | m_mirrorVertical ? -m_rect.height() * m_device_pixel_ratio : m_rect.height() * m_device_pixel_ratio); | - | ||||||||||||||||||
246 | m_renderer->setProjectionRect(mirrored); | - | ||||||||||||||||||
247 | m_renderer->setClearColor(Qt::transparent); | - | ||||||||||||||||||
248 | - | |||||||||||||||||||
249 | m_renderer->renderScene(); | - | ||||||||||||||||||
250 | m_renderer->render(&m_pixmap); | - | ||||||||||||||||||
251 | - | |||||||||||||||||||
252 | root->markDirty(QSGNode::DirtyForceUpdate); // Force matrix, clip, opacity and render list update. | - | ||||||||||||||||||
253 | - | |||||||||||||||||||
254 | if (m_recursive)
| 0 | ||||||||||||||||||
255 | markDirtyTexture(); // Continuously update if 'live' and 'recursive'. never executed: markDirtyTexture(); | 0 | ||||||||||||||||||
256 | } never executed: end of block | 0 | ||||||||||||||||||
257 | - | |||||||||||||||||||
258 | QT_END_NAMESPACE | - | ||||||||||||||||||
259 | - | |||||||||||||||||||
260 | #include "moc_qsgsoftwarelayer_p.cpp" | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |