From fab46b1c6fb170bd8adc9a289fd5b33e7c6200ab Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 23 Apr 2014 13:07:04 +0200 Subject: 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 --- src/opengl/qgl.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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. -- cgit v1.2.3