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 <gunnar.sletta@jollamobile.com>
This commit is contained in:
parent
8ab1323842
commit
fab46b1c6f
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user