path: root/src
diff options
authorAllan Sandfeld Jensen <>2014-04-23 13:07:04 +0200
committerThe Qt Project <>2014-04-25 15:18:29 +0200
commitfab46b1c6fb170bd8adc9a289fd5b33e7c6200ab (patch)
tree1334649d82dc96df5d72bcbd6c119534ae1759a7 /src
parent8ab1323842433fb6b45e7d6f381b4b9710a81da9 (diff)
Avoid a double memory copy during bindTexture
If a painter is active on a QPixmap being uploaded, it will be copied twice, first to create a QImage and then from QImage into a texture. The first copy is unnecessary since the QImage is only temporary, so we can force it to be created as a reference instead of a copy. Change-Id: Iabcfb514a634446a01f1c4031349c185ec09290b Reviewed-by: Gunnar Sletta <>
Diffstat (limited to 'src')
1 files changed, 13 insertions, 1 deletions
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index 3cfdcc549c..d73109dfd9 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -2497,7 +2497,19 @@ QGLTexture *QGLContextPrivate::bindTexture(const QPixmap &pixmap, GLenum target,
if (!texture) {
- QImage image = pixmap.toImage();
+ QImage image;
+ QPaintEngine* paintEngine = pixmap.paintEngine();
+ if (!paintEngine || paintEngine->type() != QPaintEngine::Raster)
+ image = pixmap.toImage();
+ else {
+ // QRasterPixmapData::toImage() will deep-copy the backing QImage if there's an active QPainter on it.
+ // For performance reasons, we don't want that here, so we temporarily redirect the paint engine.
+ QPaintDevice* currentPaintDevice = paintEngine->paintDevice();
+ paintEngine->setPaintDevice(0);
+ image = pixmap.toImage();
+ paintEngine->setPaintDevice(currentPaintDevice);
+ }
// If the system depth is 16 and the pixmap doesn't have an alpha channel
// then we convert it to RGB16 in the hope that it gets uploaded as a 16
// bit texture which is much faster to access than a 32-bit one.