9#include <private/qsgplaintexture_p.h>
13QSGSoftwareRectangleNode::QSGSoftwareRectangleNode()
14 : m_color(QColor(255, 255, 255))
16 setMaterial((QSGMaterial*)1);
17 setGeometry((QSGGeometry*)1);
20void QSGSoftwareRectangleNode::paint(QPainter *painter)
22 painter->fillRect(m_rect, m_color);
25QSGSoftwareImageNode::QSGSoftwareImageNode()
28 m_filtering(QSGTexture::None),
29 m_transformMode(NoTransform),
30 m_cachedMirroredPixmapIsDirty(
false)
32 setMaterial((QSGMaterial*)1);
33 setGeometry((QSGGeometry*)1);
36QSGSoftwareImageNode::~QSGSoftwareImageNode()
42void QSGSoftwareImageNode::setTexture(QSGTexture *texture)
47 m_texture = texture; markDirty(DirtyMaterial);
48 m_cachedMirroredPixmapIsDirty =
true;
51void QSGSoftwareImageNode::setTextureCoordinatesTransform(QSGImageNode::TextureCoordinatesTransformMode transformNode)
53 if (m_transformMode == transformNode)
56 m_transformMode = transformNode;
57 m_cachedMirroredPixmapIsDirty =
true;
59 markDirty(DirtyGeometry);
62void QSGSoftwareImageNode::paint(QPainter *painter)
64 if (m_cachedMirroredPixmapIsDirty)
65 updateCachedMirroredPixmap();
67 painter->setRenderHint(QPainter::SmoothPixmapTransform, (m_filtering == QSGTexture::Linear));
69 painter->setRenderHint(QPainter::Antialiasing,
false);
71 if (!m_cachedPixmap.isNull()) {
72 painter->drawPixmap(m_rect, m_cachedPixmap, m_sourceRect);
73 }
else if (QSGSoftwarePixmapTexture *pt = qobject_cast<QSGSoftwarePixmapTexture *>(m_texture)) {
74 const QPixmap &pm = pt->pixmap();
75 painter->drawPixmap(m_rect, pm, m_sourceRect);
76 }
else if (QSGSoftwareLayer *pt = qobject_cast<QSGSoftwareLayer *>(m_texture)) {
77 const QPixmap &pm = pt->pixmap();
78 painter->drawPixmap(m_rect, pm, m_sourceRect);
79 }
else if (QSGPlainTexture *pt = qobject_cast<QSGPlainTexture *>(m_texture)) {
80 const QImage &im = pt->image();
81 painter->drawImage(m_rect, im, m_sourceRect);
85void QSGSoftwareImageNode::updateCachedMirroredPixmap()
87 if (m_transformMode == NoTransform) {
88 m_cachedPixmap = QPixmap();
90 if (QSGSoftwarePixmapTexture *pt = qobject_cast<QSGSoftwarePixmapTexture *>(m_texture)) {
91 QTransform mirrorTransform;
92 if (m_transformMode.testFlag(MirrorVertically))
93 mirrorTransform = mirrorTransform.scale(1, -1);
94 if (m_transformMode.testFlag(MirrorHorizontally))
95 mirrorTransform = mirrorTransform.scale(-1, 1);
96 m_cachedPixmap = pt->pixmap().transformed(mirrorTransform);
97 }
else if (QSGSoftwareLayer *pt = qobject_cast<QSGSoftwareLayer *>(m_texture)) {
98 QTransform mirrorTransform;
99 if (m_transformMode.testFlag(MirrorVertically))
100 mirrorTransform = mirrorTransform.scale(1, -1);
101 if (m_transformMode.testFlag(MirrorHorizontally))
102 mirrorTransform = mirrorTransform.scale(-1, 1);
103 m_cachedPixmap = pt->pixmap().transformed(mirrorTransform);
104 }
else if (QSGPlainTexture *pt = qobject_cast<QSGPlainTexture *>(m_texture)) {
105 static constexpr Qt::Orientation none = Qt::Orientation(0);
106 const auto orientation = (m_transformMode.testFlag(MirrorHorizontally) ? Qt::Horizontal : none)
107 | (m_transformMode.testFlag(MirrorVertically) ? Qt::Vertical : none);
108 m_cachedPixmap = QPixmap::fromImage(pt->image().flipped(orientation));
110 m_cachedPixmap = QPixmap();
114 m_cachedMirroredPixmapIsDirty =
false;
117QSGSoftwareNinePatchNode::QSGSoftwareNinePatchNode()
119 setMaterial((QSGMaterial*)1);
120 setGeometry((QSGGeometry*)1);
123void QSGSoftwareNinePatchNode::setTexture(QSGTexture *texture)
125 QSGSoftwarePixmapTexture *pt = qobject_cast<QSGSoftwarePixmapTexture*>(texture);
127 qWarning() <<
"Image used with invalid texture format.";
129 m_pixmap = pt->pixmap();
130 markDirty(DirtyMaterial);
135void QSGSoftwareNinePatchNode::setBounds(
const QRectF &bounds)
137 if (m_bounds == bounds)
141 markDirty(DirtyGeometry);
144void QSGSoftwareNinePatchNode::setDevicePixelRatio(qreal ratio)
146 if (m_pixelRatio == ratio)
149 m_pixelRatio = ratio;
150 markDirty(DirtyGeometry);
153void QSGSoftwareNinePatchNode::setPadding(qreal left, qreal top, qreal right, qreal bottom)
155 QMargins margins(qRound(left), qRound(top), qRound(right), qRound(bottom));
156 if (m_margins == margins)
159 m_margins = QMargins(qRound(left), qRound(top), qRound(right), qRound(bottom));
160 markDirty(DirtyGeometry);
163void QSGSoftwareNinePatchNode::update()
167void QSGSoftwareNinePatchNode::paint(QPainter *painter)
170 painter->setRenderHint(QPainter::Antialiasing,
false);
172 if (m_margins.isNull())
173 painter->drawPixmap(m_bounds, m_pixmap, QRectF(0, 0, m_pixmap.width(), m_pixmap.height()));
175 QSGSoftwareHelpers::qDrawBorderPixmap(painter, m_bounds.toRect(), m_margins, m_pixmap, QRect(0, 0, m_pixmap.width(), m_pixmap.height()),
176 m_margins, Qt::StretchTile, QSGSoftwareHelpers::QDrawBorderPixmap::DrawingHints{});
179QRectF QSGSoftwareNinePatchNode::bounds()
const