From 8c91c9912f556897db4f05be1acc335ef3a5d1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 19 Mar 2014 11:26:30 +0100 Subject: Avoid QImage copy in toTexture() Desktop OpenGL has GL_UNPACK_ROW_LENGTH which we can use use to specify the image row stride. This removes the need to call QImage::copy(). On a retina MacbBok pro this reduces toTexture's share of the total run time by 1-4%. (on tests/manual/ qopenglwidget/openglwidget) Change-Id: Ia7f49d5c4ffcc347a495701bbaca6aecc2dc3433 Reviewed-by: Paul Olav Tvete Reviewed-by: Laszlo Agocs --- src/gui/painting/qplatformbackingstore.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/gui') diff --git a/src/gui/painting/qplatformbackingstore.cpp b/src/gui/painting/qplatformbackingstore.cpp index add3624feb..710d84e3aa 100644 --- a/src/gui/painting/qplatformbackingstore.cpp +++ b/src/gui/painting/qplatformbackingstore.cpp @@ -330,6 +330,13 @@ GLuint QPlatformBackingStore::toTexture(const QRegion &dirtyRegion) const funcs->glBindTexture(GL_TEXTURE_2D, d_ptr->textureId); QRect imageRect = image.rect(); QRect rect = dirtyRegion.boundingRect() & imageRect; + +#ifndef QT_OPENGL_ES_2 + funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, image.width()); + funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), GL_RGBA, GL_UNSIGNED_BYTE, + image.constScanLine(rect.y()) + rect.x() * 4); + funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); +#else // if the rect is wide enough it's cheaper to just // extend it instead of doing an image copy if (rect.width() >= imageRect.width() / 2) { @@ -347,6 +354,7 @@ GLuint QPlatformBackingStore::toTexture(const QRegion &dirtyRegion) const funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), GL_RGBA, GL_UNSIGNED_BYTE, image.copy(rect).constBits()); } +#endif } return d_ptr->textureId; -- cgit v1.2.3