From 71490ac4d7c9211aff8e0c1a5af8597271de0117 Mon Sep 17 00:00:00 2001 From: Andy Nichols Date: Wed, 3 Sep 2014 12:58:50 +0200 Subject: Add support for Image mirror property The is probably not the ideal path (as there is at least one copy), but we can document that mirror is slow. There is no clear path to blit mirrored though, so it is better to do this than to render un-mirrored or use QPixamp.toImage().mirrored().toPixmap() Change-Id: Ife751f3635e8f9d8ea08676fb1f263bdb727aa2f Reviewed-by: Lars Knoll --- .../scenegraph/softwarecontext/imagenode.cpp | 24 ++++++++++++++++++---- src/plugins/scenegraph/softwarecontext/imagenode.h | 2 ++ 2 files changed, 22 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/plugins/scenegraph/softwarecontext/imagenode.cpp b/src/plugins/scenegraph/softwarecontext/imagenode.cpp index 7718831b65..27583821ae 100644 --- a/src/plugins/scenegraph/softwarecontext/imagenode.cpp +++ b/src/plugins/scenegraph/softwarecontext/imagenode.cpp @@ -294,6 +294,7 @@ ImageNode::ImageNode() , m_smooth(true) , m_tileHorizontal(false) , m_tileVertical(false) + , m_cachedMirroredPixmapIsDirty(false) { setMaterial((QSGMaterial*)1); setGeometry((QSGGeometry*)1); @@ -322,13 +323,18 @@ void ImageNode::setSubSourceRect(const QRectF &rect) void ImageNode::setTexture(QSGTexture *texture) { - m_texture = texture; + if (m_texture != texture) { + m_texture = texture; + m_cachedMirroredPixmapIsDirty = true; + } } void ImageNode::setMirror(bool mirror) { - // ### implement support for mirrored pixmaps - m_mirror = mirror; + if (m_mirror != mirror) { + m_mirror = mirror; + m_cachedMirroredPixmapIsDirty = true; + } } void ImageNode::setMipmapFiltering(QSGTexture::Filtering /*filtering*/) @@ -352,6 +358,16 @@ void ImageNode::setVerticalWrapMode(QSGTexture::WrapMode wrapMode) void ImageNode::update() { + if (m_cachedMirroredPixmapIsDirty) { + if (m_mirror) { + m_cachedMirroredPixmap = pixmap().transformed(QTransform(-1, 0, 0, 1, 0, 0)); + } else { + //Cleanup cached pixmap if necessary + if (!m_cachedMirroredPixmap.isNull()) + m_cachedMirroredPixmap = QPixmap(); + } + m_cachedMirroredPixmapIsDirty = false; + } } void ImageNode::preprocess() @@ -382,7 +398,7 @@ void ImageNode::paint(QPainter *painter) { painter->setRenderHint(QPainter::SmoothPixmapTransform, m_smooth); - const QPixmap &pm = pixmap(); + const QPixmap &pm = m_mirror ? m_cachedMirroredPixmap : pixmap(); if (m_innerTargetRect != m_targetRect) { // border image diff --git a/src/plugins/scenegraph/softwarecontext/imagenode.h b/src/plugins/scenegraph/softwarecontext/imagenode.h index a0c059a889..05d40773a1 100644 --- a/src/plugins/scenegraph/softwarecontext/imagenode.h +++ b/src/plugins/scenegraph/softwarecontext/imagenode.h @@ -98,11 +98,13 @@ private: QRectF m_subSourceRect; QSGTexture *m_texture; + QPixmap m_cachedMirroredPixmap; bool m_mirror; bool m_smooth; bool m_tileHorizontal; bool m_tileVertical; + bool m_cachedMirroredPixmapIsDirty; }; #endif // IMAGENODE_H -- cgit v1.2.3