diff options
author | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2010-06-01 07:39:57 (GMT) |
---|---|---|
committer | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2010-06-01 07:39:57 (GMT) |
commit | 2e1e1cff3696c93f983db78c99e564a791d5d0ef (patch) | |
tree | 5def48a08a0d4178678479e0cf47534d4ab2fd63 /src/gui | |
parent | 6750d0dcbf5a2e88fab2e127dc3e057f0d68bf71 (diff) | |
download | Qt-2e1e1cff3696c93f983db78c99e564a791d5d0ef.zip Qt-2e1e1cff3696c93f983db78c99e564a791d5d0ef.tar.gz Qt-2e1e1cff3696c93f983db78c99e564a791d5d0ef.tar.bz2 |
Avoid unnecessary detach / deep copy in QGraphicsItem::scroll().
QGraphicsItem::scroll() scrolls the cache pixmap when cacheMode is
enabled (for ItemCoordinateCache only). Because the pixmap exists both
in the cache and in a temp QPixmap copy, the ref count is 2, so the
scroll operation has to do a deep copy. To avoid this, we remove the
pixmap from the cache before and reinsert it again after calling
QPixmap::scroll().
Reviewed-by: Alexis Menard <alexis.menard@nokia.com>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 36d21a6..d284a29 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -5687,11 +5687,13 @@ void QGraphicsItem::scroll(qreal dx, qreal dy, const QRectF &rect) return; } + // Find pixmap in cache, then remove to avoid deep copy when modifying.s QPixmap cachedPixmap; if (!QPixmapCache::find(cache->key, &cachedPixmap)) { update(rect); return; } + QPixmapCache::remove(cache->key); QRegion exposed; const bool scrollEntirePixmap = rect.isNull(); @@ -5707,7 +5709,8 @@ void QGraphicsItem::scroll(qreal dx, qreal dy, const QRectF &rect) cachedPixmap.scroll(dx, dy, scrollRect.translated(-cache->boundingRect.topLeft()), &exposed); } - QPixmapCache::replace(cache->key, cachedPixmap); + // Reinsert into cache. + cache->key = QPixmapCache::insert(cachedPixmap); // Translate the existing expose. for (int i = 0; i < cache->exposed.size(); ++i) { |