8#include <private/qsgplaintexture_p.h>
12QSGSoftwareRectangleNode::QSGSoftwareRectangleNode()
13 : m_color(QColor(255, 255, 255))
15 setMaterial((QSGMaterial*)1);
16 setGeometry((QSGGeometry*)1);
19void QSGSoftwareRectangleNode::paint(QPainter *painter)
21 painter->fillRect(m_rect, m_color);
24QSGSoftwareImageNode::QSGSoftwareImageNode()
27 m_filtering(QSGTexture::None),
28 m_transformMode(NoTransform),
29 m_cachedMirroredPixmapIsDirty(
false)
31 setMaterial((QSGMaterial*)1);
32 setGeometry((QSGGeometry*)1);
35QSGSoftwareImageNode::~QSGSoftwareImageNode()
41void QSGSoftwareImageNode::setTexture(QSGTexture *texture)
46 m_texture = texture; markDirty(DirtyMaterial);
47 m_cachedMirroredPixmapIsDirty =
true;
50void QSGSoftwareImageNode::setTextureCoordinatesTransform(QSGImageNode::TextureCoordinatesTransformMode transformNode)
52 if (m_transformMode == transformNode)
55 m_transformMode = transformNode;
56 m_cachedMirroredPixmapIsDirty =
true;
58 markDirty(DirtyGeometry);
61void QSGSoftwareImageNode::paint(QPainter *painter)
63 if (m_cachedMirroredPixmapIsDirty)
64 updateCachedMirroredPixmap();
66 painter->setRenderHint(QPainter::SmoothPixmapTransform, (m_filtering == QSGTexture::Linear));
68 painter->setRenderHint(QPainter::Antialiasing,
false);
70 if (!m_cachedPixmap.isNull()) {
71 painter->drawPixmap(m_rect, m_cachedPixmap, m_sourceRect);
72 }
else if (QSGSoftwarePixmapTexture *pt = qobject_cast<QSGSoftwarePixmapTexture *>(m_texture)) {
73 const QPixmap &pm = pt->pixmap();
74 painter->drawPixmap(m_rect, pm, m_sourceRect);
75 }
else if (QSGSoftwareLayer *pt = qobject_cast<QSGSoftwareLayer *>(m_texture)) {
76 const QPixmap &pm = pt->pixmap();
77 painter->drawPixmap(m_rect, pm, m_sourceRect);
78 }
else if (QSGPlainTexture *pt = qobject_cast<QSGPlainTexture *>(m_texture)) {
79 const QImage &im = pt->image();
80 painter->drawImage(m_rect, im, m_sourceRect);
84void QSGSoftwareImageNode::updateCachedMirroredPixmap()
86 if (m_transformMode == NoTransform) {
87 m_cachedPixmap = QPixmap();
89 if (QSGSoftwarePixmapTexture *pt = qobject_cast<QSGSoftwarePixmapTexture *>(m_texture)) {
90 QTransform mirrorTransform;
91 if (m_transformMode.testFlag(MirrorVertically))
92 mirrorTransform = mirrorTransform.scale(1, -1);
93 if (m_transformMode.testFlag(MirrorHorizontally))
94 mirrorTransform = mirrorTransform.scale(-1, 1);
95 m_cachedPixmap = pt->pixmap().transformed(mirrorTransform);
96 }
else if (QSGSoftwareLayer *pt = qobject_cast<QSGSoftwareLayer *>(m_texture)) {
97 QTransform mirrorTransform;
98 if (m_transformMode.testFlag(MirrorVertically))
99 mirrorTransform = mirrorTransform.scale(1, -1);
100 if (m_transformMode.testFlag(MirrorHorizontally))
101 mirrorTransform = mirrorTransform.scale(-1, 1);
102 m_cachedPixmap = pt->pixmap().transformed(mirrorTransform);
103 }
else if (QSGPlainTexture *pt = qobject_cast<QSGPlainTexture *>(m_texture)) {
104 static constexpr Qt::Orientation none = Qt::Orientation(0);
105 const auto orientation = (m_transformMode.testFlag(MirrorHorizontally) ? Qt::Horizontal : none)
106 | (m_transformMode.testFlag(MirrorVertically) ? Qt::Vertical : none);
107 m_cachedPixmap = QPixmap::fromImage(pt->image().flipped(orientation));
109 m_cachedPixmap = QPixmap();
113 m_cachedMirroredPixmapIsDirty =
false;
116QSGSoftwareNinePatchNode::QSGSoftwareNinePatchNode()
118 setMaterial((QSGMaterial*)1);
119 setGeometry((QSGGeometry*)1);
122void QSGSoftwareNinePatchNode::setTexture(QSGTexture *texture)
124 QSGSoftwarePixmapTexture *pt = qobject_cast<QSGSoftwarePixmapTexture*>(texture);
126 qWarning() <<
"Image used with invalid texture format.";
128 m_pixmap = pt->pixmap();
129 markDirty(DirtyMaterial);
134void QSGSoftwareNinePatchNode::setBounds(
const QRectF &bounds)
136 if (m_bounds == bounds)
140 markDirty(DirtyGeometry);
143void QSGSoftwareNinePatchNode::setDevicePixelRatio(qreal ratio)
145 if (m_pixelRatio == ratio)
148 m_pixelRatio = ratio;
149 markDirty(DirtyGeometry);
152void QSGSoftwareNinePatchNode::setPadding(qreal left, qreal top, qreal right, qreal bottom)
154 QMargins margins(qRound(left), qRound(top), qRound(right), qRound(bottom));
155 if (m_margins == margins)
158 m_margins = QMargins(qRound(left), qRound(top), qRound(right), qRound(bottom));
159 markDirty(DirtyGeometry);
162void QSGSoftwareNinePatchNode::update()
166void QSGSoftwareNinePatchNode::paint(QPainter *painter)
169 painter->setRenderHint(QPainter::Antialiasing,
false);
171 if (m_margins.isNull())
172 painter->drawPixmap(m_bounds, m_pixmap, QRectF(0, 0, m_pixmap.width(), m_pixmap.height()));
174 QSGSoftwareHelpers::qDrawBorderPixmap(painter, m_bounds.toRect(), m_margins, m_pixmap, QRect(0, 0, m_pixmap.width(), m_pixmap.height()),
175 m_margins, Qt::StretchTile, QSGSoftwareHelpers::QDrawBorderPixmap::DrawingHints{});
178QRectF QSGSoftwareNinePatchNode::bounds()
const