| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/adaptations/software/qsgsoftwarepainternode.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 "qsgsoftwarepainternode_p.h" | - | ||||||
| 41 | #include "qsgsoftwarepixmaptexture_p.h" | - | ||||||
| 42 | #include <qmath.h> | - | ||||||
| 43 | - | |||||||
| 44 | QT_BEGIN_NAMESPACE | - | ||||||
| 45 | - | |||||||
| 46 | QSGSoftwarePainterNode::QSGSoftwarePainterNode(QQuickPaintedItem *item) | - | ||||||
| 47 | : QSGPainterNode() | - | ||||||
| 48 | , m_preferredRenderTarget(QQuickPaintedItem::Image) | - | ||||||
| 49 | , m_item(item) | - | ||||||
| 50 | , m_texture(nullptr) | - | ||||||
| 51 | , m_dirtyContents(false) | - | ||||||
| 52 | , m_opaquePainting(false) | - | ||||||
| 53 | , m_linear_filtering(false) | - | ||||||
| 54 | , m_mipmapping(false) | - | ||||||
| 55 | , m_smoothPainting(false) | - | ||||||
| 56 | , m_fastFBOResizing(false) | - | ||||||
| 57 | , m_fillColor(Qt::transparent) | - | ||||||
| 58 | , m_contentsScale(1.0) | - | ||||||
| 59 | , m_dirtyGeometry(false) | - | ||||||
| 60 | { | - | ||||||
| 61 | setMaterial((QSGMaterial*)1); | - | ||||||
| 62 | setGeometry((QSGGeometry*)1); | - | ||||||
| 63 | } never executed:  end of block | 0 | ||||||
| 64 | - | |||||||
| 65 | QSGSoftwarePainterNode::~QSGSoftwarePainterNode() | - | ||||||
| 66 | { | - | ||||||
| 67 | delete m_texture; | - | ||||||
| 68 | } never executed:  end of block | 0 | ||||||
| 69 | - | |||||||
| 70 | void QSGSoftwarePainterNode::setPreferredRenderTarget(QQuickPaintedItem::RenderTarget target) | - | ||||||
| 71 | { | - | ||||||
| 72 | if (m_preferredRenderTarget == target) 
 | 0 | ||||||
| 73 | return; never executed:  return; | 0 | ||||||
| 74 | - | |||||||
| 75 | m_preferredRenderTarget = target; | - | ||||||
| 76 | } never executed:  end of block | 0 | ||||||
| 77 | - | |||||||
| 78 | void QSGSoftwarePainterNode::setSize(const QSize &size) | - | ||||||
| 79 | { | - | ||||||
| 80 | if (size == m_size) 
 | 0 | ||||||
| 81 | return; never executed:  return; | 0 | ||||||
| 82 | - | |||||||
| 83 | m_size = size; | - | ||||||
| 84 | - | |||||||
| 85 | m_dirtyGeometry = true; | - | ||||||
| 86 | } never executed:  end of block | 0 | ||||||
| 87 | - | |||||||
| 88 | void QSGSoftwarePainterNode::setDirty(const QRect &dirtyRect) | - | ||||||
| 89 | { | - | ||||||
| 90 | m_dirtyContents = true; | - | ||||||
| 91 | m_dirtyRect = dirtyRect; | - | ||||||
| 92 | markDirty(DirtyMaterial); | - | ||||||
| 93 | } never executed:  end of block | 0 | ||||||
| 94 | - | |||||||
| 95 | void QSGSoftwarePainterNode::setOpaquePainting(bool opaque) | - | ||||||
| 96 | { | - | ||||||
| 97 | if (opaque == m_opaquePainting) 
 | 0 | ||||||
| 98 | return; never executed:  return; | 0 | ||||||
| 99 | - | |||||||
| 100 | m_opaquePainting = opaque; | - | ||||||
| 101 | } never executed:  end of block | 0 | ||||||
| 102 | - | |||||||
| 103 | void QSGSoftwarePainterNode::setLinearFiltering(bool linearFiltering) | - | ||||||
| 104 | { | - | ||||||
| 105 | if (linearFiltering == m_linear_filtering) 
 | 0 | ||||||
| 106 | return; never executed:  return; | 0 | ||||||
| 107 | - | |||||||
| 108 | m_linear_filtering = linearFiltering; | - | ||||||
| 109 | } never executed:  end of block | 0 | ||||||
| 110 | - | |||||||
| 111 | void QSGSoftwarePainterNode::setMipmapping(bool mipmapping) | - | ||||||
| 112 | { | - | ||||||
| 113 | if (mipmapping == m_mipmapping) 
 | 0 | ||||||
| 114 | return; never executed:  return; | 0 | ||||||
| 115 | - | |||||||
| 116 | m_mipmapping = mipmapping; | - | ||||||
| 117 | } never executed:  end of block | 0 | ||||||
| 118 | - | |||||||
| 119 | void QSGSoftwarePainterNode::setSmoothPainting(bool s) | - | ||||||
| 120 | { | - | ||||||
| 121 | if (s == m_smoothPainting) 
 | 0 | ||||||
| 122 | return; never executed:  return; | 0 | ||||||
| 123 | - | |||||||
| 124 | m_smoothPainting = s; | - | ||||||
| 125 | } never executed:  end of block | 0 | ||||||
| 126 | - | |||||||
| 127 | void QSGSoftwarePainterNode::setFillColor(const QColor &c) | - | ||||||
| 128 | { | - | ||||||
| 129 | if (c == m_fillColor) 
 | 0 | ||||||
| 130 | return; never executed:  return; | 0 | ||||||
| 131 | - | |||||||
| 132 | m_fillColor = c; | - | ||||||
| 133 | markDirty(DirtyMaterial); | - | ||||||
| 134 | } never executed:  end of block | 0 | ||||||
| 135 | - | |||||||
| 136 | void QSGSoftwarePainterNode::setContentsScale(qreal s) | - | ||||||
| 137 | { | - | ||||||
| 138 | if (s == m_contentsScale) 
 | 0 | ||||||
| 139 | return; never executed:  return; | 0 | ||||||
| 140 | - | |||||||
| 141 | m_contentsScale = s; | - | ||||||
| 142 | markDirty(DirtyMaterial); | - | ||||||
| 143 | } never executed:  end of block | 0 | ||||||
| 144 | - | |||||||
| 145 | void QSGSoftwarePainterNode::setFastFBOResizing(bool dynamic) | - | ||||||
| 146 | { | - | ||||||
| 147 | m_fastFBOResizing = dynamic; | - | ||||||
| 148 | } never executed:  end of block | 0 | ||||||
| 149 | - | |||||||
| 150 | QImage QSGSoftwarePainterNode::toImage() const | - | ||||||
| 151 | { | - | ||||||
| 152 | return m_pixmap.toImage(); never executed:  return m_pixmap.toImage(); | 0 | ||||||
| 153 | } | - | ||||||
| 154 | - | |||||||
| 155 | void QSGSoftwarePainterNode::update() | - | ||||||
| 156 | { | - | ||||||
| 157 | if (m_dirtyGeometry) { 
 | 0 | ||||||
| 158 | m_pixmap = QPixmap(m_textureSize); | - | ||||||
| 159 | if (!m_opaquePainting) 
 | 0 | ||||||
| 160 | m_pixmap.fill(Qt::transparent); never executed:  m_pixmap.fill(Qt::transparent); | 0 | ||||||
| 161 | - | |||||||
| 162 | if (m_texture) 
 | 0 | ||||||
| 163 | delete m_texture; never executed:  delete m_texture; | 0 | ||||||
| 164 | m_texture = new QSGSoftwarePixmapTexture(m_pixmap); | - | ||||||
| 165 | } never executed:  end of block | 0 | ||||||
| 166 | - | |||||||
| 167 | if (m_dirtyContents) 
 | 0 | ||||||
| 168 | paint(); never executed:  paint(); | 0 | ||||||
| 169 | - | |||||||
| 170 | m_dirtyGeometry = false; | - | ||||||
| 171 | m_dirtyContents = false; | - | ||||||
| 172 | } never executed:  end of block | 0 | ||||||
| 173 | - | |||||||
| 174 | void QSGSoftwarePainterNode::paint(QPainter *painter) | - | ||||||
| 175 | { | - | ||||||
| 176 | painter->drawPixmap(0, 0, m_size.width(), m_size.height(), m_pixmap); | - | ||||||
| 177 | } never executed:  end of block | 0 | ||||||
| 178 | - | |||||||
| 179 | void QSGSoftwarePainterNode::paint() | - | ||||||
| 180 | { | - | ||||||
| 181 | QRect dirtyRect = m_dirtyRect.isNull() ? QRect(0, 0, m_size.width(), m_size.height()) : m_dirtyRect; 
 | 0 | ||||||
| 182 | - | |||||||
| 183 | QPainter painter; | - | ||||||
| 184 | - | |||||||
| 185 | painter.begin(&m_pixmap); | - | ||||||
| 186 | if (m_smoothPainting) { 
 | 0 | ||||||
| 187 | painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); | - | ||||||
| 188 | } never executed:  end of block | 0 | ||||||
| 189 | - | |||||||
| 190 | QRect clipRect; | - | ||||||
| 191 | - | |||||||
| 192 | if (m_contentsScale == 1) { 
 | 0 | ||||||
| 193 | qreal scaleX = m_textureSize.width() / (qreal) m_size.width(); | - | ||||||
| 194 | qreal scaleY = m_textureSize.height() / (qreal) m_size.height(); | - | ||||||
| 195 | painter.scale(scaleX, scaleY); | - | ||||||
| 196 | clipRect = dirtyRect; | - | ||||||
| 197 | } else { never executed:  end of block | 0 | ||||||
| 198 | painter.scale(m_contentsScale, m_contentsScale); | - | ||||||
| 199 | - | |||||||
| 200 | QRect sclip(qFloor(dirtyRect.x()/m_contentsScale), | - | ||||||
| 201 | qFloor(dirtyRect.y()/m_contentsScale), | - | ||||||
| 202 | qCeil(dirtyRect.width()/m_contentsScale+dirtyRect.x()/m_contentsScale-qFloor(dirtyRect.x()/m_contentsScale)), | - | ||||||
| 203 | qCeil(dirtyRect.height()/m_contentsScale+dirtyRect.y()/m_contentsScale-qFloor(dirtyRect.y()/m_contentsScale))); | - | ||||||
| 204 | - | |||||||
| 205 | clipRect = sclip; | - | ||||||
| 206 | } never executed:  end of block | 0 | ||||||
| 207 | - | |||||||
| 208 | if (!m_dirtyRect.isNull()) 
 | 0 | ||||||
| 209 | painter.setClipRect(clipRect); never executed:  painter.setClipRect(clipRect); | 0 | ||||||
| 210 | - | |||||||
| 211 | painter.setCompositionMode(QPainter::CompositionMode_Source); | - | ||||||
| 212 | painter.fillRect(clipRect, m_fillColor); | - | ||||||
| 213 | painter.setCompositionMode(QPainter::CompositionMode_SourceOver); | - | ||||||
| 214 | - | |||||||
| 215 | m_item->paint(&painter); | - | ||||||
| 216 | painter.end(); | - | ||||||
| 217 | - | |||||||
| 218 | m_dirtyRect = QRect(); | - | ||||||
| 219 | } never executed:  end of block | 0 | ||||||
| 220 | - | |||||||
| 221 | - | |||||||
| 222 | void QSGSoftwarePainterNode::setTextureSize(const QSize &size) | - | ||||||
| 223 | { | - | ||||||
| 224 | if (size == m_textureSize) 
 | 0 | ||||||
| 225 | return; never executed:  return; | 0 | ||||||
| 226 | - | |||||||
| 227 | m_textureSize = size; | - | ||||||
| 228 | m_dirtyGeometry = true; | - | ||||||
| 229 | } never executed:  end of block | 0 | ||||||
| 230 | - | |||||||
| 231 | QT_END_NAMESPACE | - | ||||||
| Source code | Switch to Preprocessed file |