| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quickshapes/qquickshapesoftwarerenderer.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 "qquickshapesoftwarerenderer_p.h" | - | ||||||||||||
| 41 | #include <private/qquickpath_p_p.h> | - | ||||||||||||
| 42 | - | |||||||||||||
| 43 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 44 | - | |||||||||||||
| 45 | void QQuickShapeSoftwareRenderer::beginSync(int totalCount) | - | ||||||||||||
| 46 | { | - | ||||||||||||
| 47 | if (m_sp.count() != totalCount) {
| 0-8 | ||||||||||||
| 48 | m_sp.resize(totalCount); | - | ||||||||||||
| 49 | m_accDirty |= DirtyList; | - | ||||||||||||
| 50 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||
| 51 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||
| 52 | - | |||||||||||||
| 53 | void QQuickShapeSoftwareRenderer::setPath(int index, const QQuickPath *path) | - | ||||||||||||
| 54 | { | - | ||||||||||||
| 55 | ShapePathGuiData &d(m_sp[index]); | - | ||||||||||||
| 56 | d.path = path ? path->path() : QPainterPath();
| 0-12 | ||||||||||||
| 57 | d.dirty |= DirtyPath; | - | ||||||||||||
| 58 | m_accDirty |= DirtyPath; | - | ||||||||||||
| 59 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||
| 60 | - | |||||||||||||
| 61 | void QQuickShapeSoftwareRenderer::setStrokeColor(int index, const QColor &color) | - | ||||||||||||
| 62 | { | - | ||||||||||||
| 63 | ShapePathGuiData &d(m_sp[index]); | - | ||||||||||||
| 64 | d.pen.setColor(color); | - | ||||||||||||
| 65 | d.dirty |= DirtyPen; | - | ||||||||||||
| 66 | m_accDirty |= DirtyPen; | - | ||||||||||||
| 67 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||
| 68 | - | |||||||||||||
| 69 | void QQuickShapeSoftwareRenderer::setStrokeWidth(int index, qreal w) | - | ||||||||||||
| 70 | { | - | ||||||||||||
| 71 | ShapePathGuiData &d(m_sp[index]); | - | ||||||||||||
| 72 | d.strokeWidth = w; | - | ||||||||||||
| 73 | if (w >= 0.0f)
| 0-12 | ||||||||||||
| 74 | d.pen.setWidthF(w); executed 12 times by 1 test: d.pen.setWidthF(w);Executed by:
| 12 | ||||||||||||
| 75 | d.dirty |= DirtyPen; | - | ||||||||||||
| 76 | m_accDirty |= DirtyPen; | - | ||||||||||||
| 77 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||
| 78 | - | |||||||||||||
| 79 | void QQuickShapeSoftwareRenderer::setFillColor(int index, const QColor &color) | - | ||||||||||||
| 80 | { | - | ||||||||||||
| 81 | ShapePathGuiData &d(m_sp[index]); | - | ||||||||||||
| 82 | d.fillColor = color; | - | ||||||||||||
| 83 | d.brush.setColor(color); | - | ||||||||||||
| 84 | d.dirty |= DirtyBrush; | - | ||||||||||||
| 85 | m_accDirty |= DirtyBrush; | - | ||||||||||||
| 86 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||
| 87 | - | |||||||||||||
| 88 | void QQuickShapeSoftwareRenderer::setFillRule(int index, QQuickShapePath::FillRule fillRule) | - | ||||||||||||
| 89 | { | - | ||||||||||||
| 90 | ShapePathGuiData &d(m_sp[index]); | - | ||||||||||||
| 91 | d.fillRule = Qt::FillRule(fillRule); | - | ||||||||||||
| 92 | d.dirty |= DirtyFillRule; | - | ||||||||||||
| 93 | m_accDirty |= DirtyFillRule; | - | ||||||||||||
| 94 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||
| 95 | - | |||||||||||||
| 96 | void QQuickShapeSoftwareRenderer::setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) | - | ||||||||||||
| 97 | { | - | ||||||||||||
| 98 | ShapePathGuiData &d(m_sp[index]); | - | ||||||||||||
| 99 | d.pen.setJoinStyle(Qt::PenJoinStyle(joinStyle)); | - | ||||||||||||
| 100 | d.pen.setMiterLimit(miterLimit); | - | ||||||||||||
| 101 | d.dirty |= DirtyPen; | - | ||||||||||||
| 102 | m_accDirty |= DirtyPen; | - | ||||||||||||
| 103 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||
| 104 | - | |||||||||||||
| 105 | void QQuickShapeSoftwareRenderer::setCapStyle(int index, QQuickShapePath::CapStyle capStyle) | - | ||||||||||||
| 106 | { | - | ||||||||||||
| 107 | ShapePathGuiData &d(m_sp[index]); | - | ||||||||||||
| 108 | d.pen.setCapStyle(Qt::PenCapStyle(capStyle)); | - | ||||||||||||
| 109 | d.dirty |= DirtyPen; | - | ||||||||||||
| 110 | m_accDirty |= DirtyPen; | - | ||||||||||||
| 111 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||
| 112 | - | |||||||||||||
| 113 | void QQuickShapeSoftwareRenderer::setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle, | - | ||||||||||||
| 114 | qreal dashOffset, const QVector<qreal> &dashPattern) | - | ||||||||||||
| 115 | { | - | ||||||||||||
| 116 | ShapePathGuiData &d(m_sp[index]); | - | ||||||||||||
| 117 | switch (strokeStyle) { | - | ||||||||||||
| 118 | case QQuickShapePath::SolidLine: executed 6 times by 1 test: case QQuickShapePath::SolidLine:Executed by:
| 6 | ||||||||||||
| 119 | d.pen.setStyle(Qt::SolidLine); | - | ||||||||||||
| 120 | break; executed 6 times by 1 test: break;Executed by:
| 6 | ||||||||||||
| 121 | case QQuickShapePath::DashLine: executed 6 times by 1 test: case QQuickShapePath::DashLine:Executed by:
| 6 | ||||||||||||
| 122 | d.pen.setStyle(Qt::CustomDashLine); | - | ||||||||||||
| 123 | d.pen.setDashPattern(dashPattern); | - | ||||||||||||
| 124 | d.pen.setDashOffset(dashOffset); | - | ||||||||||||
| 125 | break; executed 6 times by 1 test: break;Executed by:
| 6 | ||||||||||||
| 126 | default: never executed: default: | 0 | ||||||||||||
| 127 | break; never executed: break; | 0 | ||||||||||||
| 128 | } | - | ||||||||||||
| 129 | d.dirty |= DirtyPen; | - | ||||||||||||
| 130 | m_accDirty |= DirtyPen; | - | ||||||||||||
| 131 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||
| 132 | - | |||||||||||||
| 133 | static inline void setupPainterGradient(QGradient *painterGradient, const QQuickShapeGradient &g) | - | ||||||||||||
| 134 | { | - | ||||||||||||
| 135 | painterGradient->setStops(g.gradientStops()); // sorted | - | ||||||||||||
| 136 | switch (g.spread()) { | - | ||||||||||||
| 137 | case QQuickShapeGradient::PadSpread: executed 8 times by 1 test: case QQuickShapeGradient::PadSpread:Executed by:
| 8 | ||||||||||||
| 138 | painterGradient->setSpread(QGradient::PadSpread); | - | ||||||||||||
| 139 | break; executed 8 times by 1 test: break;Executed by:
| 8 | ||||||||||||
| 140 | case QQuickShapeGradient::RepeatSpread: never executed: case QQuickShapeGradient::RepeatSpread: | 0 | ||||||||||||
| 141 | painterGradient->setSpread(QGradient::RepeatSpread); | - | ||||||||||||
| 142 | break; never executed: break; | 0 | ||||||||||||
| 143 | case QQuickShapeGradient::ReflectSpread: never executed: case QQuickShapeGradient::ReflectSpread: | 0 | ||||||||||||
| 144 | painterGradient->setSpread(QGradient::ReflectSpread); | - | ||||||||||||
| 145 | break; never executed: break; | 0 | ||||||||||||
| 146 | default: never executed: default: | 0 | ||||||||||||
| 147 | break; never executed: break; | 0 | ||||||||||||
| 148 | } | - | ||||||||||||
| 149 | } | - | ||||||||||||
| 150 | - | |||||||||||||
| 151 | void QQuickShapeSoftwareRenderer::setFillGradient(int index, QQuickShapeGradient *gradient) | - | ||||||||||||
| 152 | { | - | ||||||||||||
| 153 | ShapePathGuiData &d(m_sp[index]); | - | ||||||||||||
| 154 | if (QQuickShapeLinearGradient *g = qobject_cast<QQuickShapeLinearGradient *>(gradient)) {
| 4-8 | ||||||||||||
| 155 | QLinearGradient painterGradient(g->x1(), g->y1(), g->x2(), g->y2()); | - | ||||||||||||
| 156 | setupPainterGradient(&painterGradient, *g); | - | ||||||||||||
| 157 | d.brush = QBrush(painterGradient); | - | ||||||||||||
| 158 | } else if (QQuickShapeRadialGradient *g = qobject_cast<QQuickShapeRadialGradient *>(gradient)) { executed 4 times by 1 test: end of blockExecuted by:
| 2-6 | ||||||||||||
| 159 | QRadialGradient painterGradient(g->centerX(), g->centerY(), g->centerRadius(), | - | ||||||||||||
| 160 | g->focalX(), g->focalY(), g->focalRadius()); | - | ||||||||||||
| 161 | setupPainterGradient(&painterGradient, *g); | - | ||||||||||||
| 162 | d.brush = QBrush(painterGradient); | - | ||||||||||||
| 163 | } else if (QQuickShapeConicalGradient *g = qobject_cast<QQuickShapeConicalGradient *>(gradient)) { executed 2 times by 1 test: end of blockExecuted by:
| 2-4 | ||||||||||||
| 164 | QConicalGradient painterGradient(g->centerX(), g->centerY(), g->angle()); | - | ||||||||||||
| 165 | setupPainterGradient(&painterGradient, *g); | - | ||||||||||||
| 166 | d.brush = QBrush(painterGradient); | - | ||||||||||||
| 167 | } else { executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||
| 168 | d.brush = QBrush(d.fillColor); | - | ||||||||||||
| 169 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||
| 170 | d.dirty |= DirtyBrush; | - | ||||||||||||
| 171 | m_accDirty |= DirtyBrush; | - | ||||||||||||
| 172 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||
| 173 | - | |||||||||||||
| 174 | void QQuickShapeSoftwareRenderer::endSync(bool) | - | ||||||||||||
| 175 | { | - | ||||||||||||
| 176 | } | - | ||||||||||||
| 177 | - | |||||||||||||
| 178 | void QQuickShapeSoftwareRenderer::setNode(QQuickShapeSoftwareRenderNode *node) | - | ||||||||||||
| 179 | { | - | ||||||||||||
| 180 | if (m_node != node) {
| 0-8 | ||||||||||||
| 181 | m_node = node; | - | ||||||||||||
| 182 | m_accDirty |= DirtyList; | - | ||||||||||||
| 183 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||
| 184 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||
| 185 | - | |||||||||||||
| 186 | void QQuickShapeSoftwareRenderer::updateNode() | - | ||||||||||||
| 187 | { | - | ||||||||||||
| 188 | if (!m_accDirty)
| 0-8 | ||||||||||||
| 189 | return; never executed: return; | 0 | ||||||||||||
| 190 | - | |||||||||||||
| 191 | const int count = m_sp.count(); | - | ||||||||||||
| 192 | const bool listChanged = m_accDirty & DirtyList; | - | ||||||||||||
| 193 | if (listChanged)
| 0-8 | ||||||||||||
| 194 | m_node->m_sp.resize(count); executed 8 times by 1 test: m_node->m_sp.resize(count);Executed by:
| 8 | ||||||||||||
| 195 | - | |||||||||||||
| 196 | m_node->m_boundingRect = QRectF(); | - | ||||||||||||
| 197 | - | |||||||||||||
| 198 | for (int i = 0; i < count; ++i) {
| 8-12 | ||||||||||||
| 199 | ShapePathGuiData &src(m_sp[i]); | - | ||||||||||||
| 200 | QQuickShapeSoftwareRenderNode::ShapePathRenderData &dst(m_node->m_sp[i]); | - | ||||||||||||
| 201 | - | |||||||||||||
| 202 | if (listChanged || (src.dirty & DirtyPath)) {
| 0-12 | ||||||||||||
| 203 | dst.path = src.path; | - | ||||||||||||
| 204 | dst.path.setFillRule(src.fillRule); | - | ||||||||||||
| 205 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||
| 206 | - | |||||||||||||
| 207 | if (listChanged || (src.dirty & DirtyFillRule))
| 0-12 | ||||||||||||
| 208 | dst.path.setFillRule(src.fillRule); executed 12 times by 1 test: dst.path.setFillRule(src.fillRule);Executed by:
| 12 | ||||||||||||
| 209 | - | |||||||||||||
| 210 | if (listChanged || (src.dirty & DirtyPen)) {
| 0-12 | ||||||||||||
| 211 | dst.pen = src.pen; | - | ||||||||||||
| 212 | dst.strokeWidth = src.strokeWidth; | - | ||||||||||||
| 213 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||
| 214 | - | |||||||||||||
| 215 | if (listChanged || (src.dirty & DirtyBrush))
| 0-12 | ||||||||||||
| 216 | dst.brush = src.brush; executed 12 times by 1 test: dst.brush = src.brush;Executed by:
| 12 | ||||||||||||
| 217 | - | |||||||||||||
| 218 | src.dirty = 0; | - | ||||||||||||
| 219 | - | |||||||||||||
| 220 | QRectF br = dst.path.boundingRect(); | - | ||||||||||||
| 221 | const float sw = qMax(1.0f, dst.strokeWidth); | - | ||||||||||||
| 222 | br.adjust(-sw, -sw, sw, sw); | - | ||||||||||||
| 223 | m_node->m_boundingRect |= br; | - | ||||||||||||
| 224 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||
| 225 | - | |||||||||||||
| 226 | m_node->markDirty(QSGNode::DirtyMaterial); | - | ||||||||||||
| 227 | m_accDirty = 0; | - | ||||||||||||
| 228 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||
| 229 | - | |||||||||||||
| 230 | QQuickShapeSoftwareRenderNode::QQuickShapeSoftwareRenderNode(QQuickShape *item) | - | ||||||||||||
| 231 | : m_item(item) | - | ||||||||||||
| 232 | { | - | ||||||||||||
| 233 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||
| 234 | - | |||||||||||||
| 235 | QQuickShapeSoftwareRenderNode::~QQuickShapeSoftwareRenderNode() | - | ||||||||||||
| 236 | { | - | ||||||||||||
| 237 | releaseResources(); | - | ||||||||||||
| 238 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||
| 239 | - | |||||||||||||
| 240 | void QQuickShapeSoftwareRenderNode::releaseResources() | - | ||||||||||||
| 241 | { | - | ||||||||||||
| 242 | } | - | ||||||||||||
| 243 | - | |||||||||||||
| 244 | void QQuickShapeSoftwareRenderNode::render(const RenderState *state) | - | ||||||||||||
| 245 | { | - | ||||||||||||
| 246 | if (m_sp.isEmpty())
| 0-8 | ||||||||||||
| 247 | return; never executed: return; | 0 | ||||||||||||
| 248 | - | |||||||||||||
| 249 | QSGRendererInterface *rif = m_item->window()->rendererInterface(); | - | ||||||||||||
| 250 | QPainter *p = static_cast<QPainter *>(rif->getResource(m_item->window(), QSGRendererInterface::PainterResource)); | - | ||||||||||||
| 251 | Q_ASSERT(p); | - | ||||||||||||
| 252 | - | |||||||||||||
| 253 | const QRegion *clipRegion = state->clipRegion(); | - | ||||||||||||
| 254 | if (clipRegion && !clipRegion->isEmpty())
| 0-8 | ||||||||||||
| 255 | p->setClipRegion(*clipRegion, Qt::ReplaceClip); // must be done before setTransform executed 8 times by 1 test: p->setClipRegion(*clipRegion, Qt::ReplaceClip);Executed by:
| 8 | ||||||||||||
| 256 | - | |||||||||||||
| 257 | p->setTransform(matrix()->toTransform()); | - | ||||||||||||
| 258 | p->setOpacity(inheritedOpacity()); | - | ||||||||||||
| 259 | - | |||||||||||||
| 260 | for (const ShapePathRenderData &d : qAsConst(m_sp)) { | - | ||||||||||||
| 261 | p->setPen(d.strokeWidth >= 0.0f && d.pen.color() != Qt::transparent ? d.pen : Qt::NoPen); | - | ||||||||||||
| 262 | p->setBrush(d.brush.color() != Qt::transparent ? d.brush : Qt::NoBrush); | - | ||||||||||||
| 263 | p->drawPath(d.path); | - | ||||||||||||
| 264 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||
| 265 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||
| 266 | - | |||||||||||||
| 267 | QSGRenderNode::StateFlags QQuickShapeSoftwareRenderNode::changedStates() const | - | ||||||||||||
| 268 | { | - | ||||||||||||
| 269 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||
| 270 | } | - | ||||||||||||
| 271 | - | |||||||||||||
| 272 | QSGRenderNode::RenderingFlags QQuickShapeSoftwareRenderNode::flags() const | - | ||||||||||||
| 273 | { | - | ||||||||||||
| 274 | return BoundedRectRendering; // avoid fullscreen updates by saying we won't draw outside rect() executed 16 times by 1 test: return BoundedRectRendering;Executed by:
| 16 | ||||||||||||
| 275 | } | - | ||||||||||||
| 276 | - | |||||||||||||
| 277 | QRectF QQuickShapeSoftwareRenderNode::rect() const | - | ||||||||||||
| 278 | { | - | ||||||||||||
| 279 | return m_boundingRect; executed 8 times by 1 test: return m_boundingRect;Executed by:
| 8 | ||||||||||||
| 280 | } | - | ||||||||||||
| 281 | - | |||||||||||||
| 282 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |