aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp
diff options
context:
space:
mode:
authorAndy Nichols <andy.nichols@qt.io>2016-07-15 15:46:33 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2016-07-19 10:41:01 +0000
commit764ca4053dbcb44555e9286a25f21f3a5be504e4 (patch)
tree7c3e45226c439c4aa5a8e1ab17188cade9ac3b42 /src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp
parent4cb2552313280384b59ee1e7d7fc557c7bd64a68 (diff)
SoftwareImageNodes: Support textureFiltering and mirroring
Missing features in the QSGImageNode based software node. Change-Id: If6a759873d201307e013a3ab019bd906d98ba7d5 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp')
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp54
1 files changed, 52 insertions, 2 deletions
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp
index c8291edd10..1fa5234377 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp
@@ -57,7 +57,10 @@ void QSGSoftwareRectangleNode::paint(QPainter *painter)
QSGSoftwareImageNode::QSGSoftwareImageNode()
: m_texture(nullptr),
- m_owns(false)
+ m_owns(false),
+ m_filtering(QSGTexture::None),
+ m_transformMode(NoTransform),
+ m_cachedMirroredPixmapIsDirty(false)
{
setMaterial((QSGMaterial*)1);
setGeometry((QSGGeometry*)1);
@@ -69,9 +72,33 @@ QSGSoftwareImageNode::~QSGSoftwareImageNode()
delete m_texture;
}
+void QSGSoftwareImageNode::setTexture(QSGTexture *texture)
+{
+ m_texture = texture; markDirty(DirtyMaterial);
+ m_cachedMirroredPixmapIsDirty = true;
+}
+
+void QSGSoftwareImageNode::setTextureCoordinatesTransform(QSGImageNode::TextureCoordinatesTransformMode transformNode)
+{
+ if (m_transformMode == transformNode)
+ return;
+
+ m_transformMode = transformNode;
+ m_cachedMirroredPixmapIsDirty = true;
+
+ markDirty(DirtyGeometry);
+}
+
void QSGSoftwareImageNode::paint(QPainter *painter)
{
- if (QSGSoftwarePixmapTexture *pt = dynamic_cast<QSGSoftwarePixmapTexture *>(m_texture)) {
+ if (m_cachedMirroredPixmapIsDirty)
+ updateCachedMirroredPixmap();
+
+ painter->setRenderHint(QPainter::SmoothPixmapTransform, (m_filtering == QSGTexture::Linear));
+
+ if (!m_cachedPixmap.isNull()) {
+ painter->drawPixmap(m_rect, m_cachedPixmap, m_sourceRect);
+ } else if (QSGSoftwarePixmapTexture *pt = dynamic_cast<QSGSoftwarePixmapTexture *>(m_texture)) {
const QPixmap &pm = pt->pixmap();
painter->drawPixmap(m_rect, pm, m_sourceRect);
} else if (QSGPlainTexture *pt = dynamic_cast<QSGPlainTexture *>(m_texture)) {
@@ -80,6 +107,29 @@ void QSGSoftwareImageNode::paint(QPainter *painter)
}
}
+void QSGSoftwareImageNode::updateCachedMirroredPixmap()
+{
+ if (m_transformMode == NoTransform) {
+ m_cachedPixmap = QPixmap();
+ } else {
+
+ if (QSGSoftwarePixmapTexture *pt = dynamic_cast<QSGSoftwarePixmapTexture *>(m_texture)) {
+ QTransform mirrorTransform;
+ if (m_transformMode.testFlag(MirrorVertically))
+ mirrorTransform = mirrorTransform.scale(1, -1);
+ if (m_transformMode.testFlag(MirrorHorizontally))
+ mirrorTransform = mirrorTransform.scale(-1, 1);
+ m_cachedPixmap = pt->pixmap().transformed(mirrorTransform);
+ } else if (QSGPlainTexture *pt = dynamic_cast<QSGPlainTexture *>(m_texture)) {
+ m_cachedPixmap = QPixmap::fromImage(pt->image().mirrored(m_transformMode.testFlag(MirrorHorizontally), m_transformMode.testFlag(MirrorVertically)));
+ } else {
+ m_cachedPixmap = QPixmap();
+ }
+ }
+
+ m_cachedMirroredPixmapIsDirty = false;
+}
+
QSGSoftwareNinePatchNode::QSGSoftwareNinePatchNode()
{
setMaterial((QSGMaterial*)1);