aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-11-03 17:17:44 +0100
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-11-04 09:49:48 +0100
commite5dfa302fe227576aece1d5637251ac68ead0374 (patch)
tree0d714ad925c963f5d909a4be83d6f14a1079f3cf
parentcde1a8a10b611e3e3cf048ec1b108c031ef1b2a9 (diff)
QQuickStyleItem: reuse QImage when painting, if possible
If the size of the QImage we draw on hasn't changed between subsequent calls to paintControlToImage, we can just reuse the one we already got. This way we avoid creating and throwing away images unnecessary. Change-Id: Icf65bb8d9008a21e7114e588df46bc1e4cbdea97 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
-rw-r--r--src/imports/nativestyle/items/qquickstyleitem.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/imports/nativestyle/items/qquickstyleitem.cpp b/src/imports/nativestyle/items/qquickstyleitem.cpp
index 506392cb..9f6ce676 100644
--- a/src/imports/nativestyle/items/qquickstyleitem.cpp
+++ b/src/imports/nativestyle/items/qquickstyleitem.cpp
@@ -284,8 +284,13 @@ void QQuickStyleItem::paintControlToImage()
m_dirty.setFlag(DirtyFlag::Image, false);
const qreal scale = window()->devicePixelRatio();
- m_paintedImage = QImage(imageSize() * scale, QImage::Format_ARGB32_Premultiplied);
- m_paintedImage.setDevicePixelRatio(scale);
+ const QSize scaledImageSize = imageSize() * scale;
+
+ if (m_paintedImage.size() != scaledImageSize) {
+ m_paintedImage = QImage(scaledImageSize, QImage::Format_ARGB32_Premultiplied);
+ m_paintedImage.setDevicePixelRatio(scale);
+ }
+
m_paintedImage.fill(Qt::transparent);
QPainter painter(&m_paintedImage);