summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Nichols <andy.nichols@digia.com>2014-09-03 12:58:50 +0200
committerLars Knoll <lars.knoll@digia.com>2014-09-11 14:07:40 +0300
commit71490ac4d7c9211aff8e0c1a5af8597271de0117 (patch)
treee92169543e7787c9a33facda718c590930065f02
parent8efcafc5ff877ab54a7d4ee7673f02cbd900031e (diff)
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 <lars.knoll@digia.com>
-rw-r--r--src/plugins/scenegraph/softwarecontext/imagenode.cpp24
-rw-r--r--src/plugins/scenegraph/softwarecontext/imagenode.h2
2 files changed, 22 insertions, 4 deletions
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