diff options
author | Andy Nichols <andy.nichols@qt.io> | 2016-07-15 15:46:33 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2016-07-19 10:41:01 +0000 |
commit | 764ca4053dbcb44555e9286a25f21f3a5be504e4 (patch) | |
tree | 7c3e45226c439c4aa5a8e1ab17188cade9ac3b42 | |
parent | 4cb2552313280384b59ee1e7d7fc557c7bd64a68 (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>
-rw-r--r-- | src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp | 54 | ||||
-rw-r--r-- | src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes_p.h | 17 |
2 files changed, 63 insertions, 8 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); diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes_p.h b/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes_p.h index 8a11f25c82..9f1913205b 100644 --- a/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes_p.h +++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes_p.h @@ -88,17 +88,17 @@ public: void setSourceRect(const QRectF &r) override { m_sourceRect = r; } QRectF sourceRect() const override { return m_sourceRect; } - void setTexture(QSGTexture *texture) override { m_texture = texture; markDirty(DirtyMaterial); } + void setTexture(QSGTexture *texture) override; QSGTexture *texture() const override { return m_texture; } - void setFiltering(QSGTexture::Filtering) override { } - QSGTexture::Filtering filtering() const override { return QSGTexture::None; } + void setFiltering(QSGTexture::Filtering filtering) override { m_filtering = filtering; markDirty(DirtyMaterial); } + QSGTexture::Filtering filtering() const override { return m_filtering; } void setMipmapFiltering(QSGTexture::Filtering) override { } QSGTexture::Filtering mipmapFiltering() const override { return QSGTexture::None; } - void setTextureCoordinatesTransform(TextureCoordinatesTransformMode) override { } - TextureCoordinatesTransformMode textureCoordinatesTransform() const override { return NoTransform; } + void setTextureCoordinatesTransform(TextureCoordinatesTransformMode transformNode) override; + TextureCoordinatesTransformMode textureCoordinatesTransform() const override { return m_transformMode; } void setOwnsTexture(bool owns) override { m_owns = owns; } bool ownsTexture() const override { return m_owns; } @@ -106,11 +106,16 @@ public: void paint(QPainter *painter); private: - QPixmap m_pixmap; + void updateCachedMirroredPixmap(); + + QPixmap m_cachedPixmap; QSGTexture *m_texture; QRectF m_rect; QRectF m_sourceRect; bool m_owns; + QSGTexture::Filtering m_filtering; + TextureCoordinatesTransformMode m_transformMode; + bool m_cachedMirroredPixmapIsDirty; }; class QSGSoftwareNinePatchNode : public QSGNinePatchNode |