summaryrefslogtreecommitdiffstats
path: root/src/opengl
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-12-02 07:50:11 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-12-02 07:50:11 (GMT)
commit1b56836c0e7715fb1321c9bd48c8d6fd5b56f217 (patch)
tree489f981d4a6df75eb3d3a09c35fba9ba8e2dfc11 /src/opengl
parent480b395bd652a4ac6e3f262bd99a045dff95c4ac (diff)
downloadQt-1b56836c0e7715fb1321c9bd48c8d6fd5b56f217.zip
Qt-1b56836c0e7715fb1321c9bd48c8d6fd5b56f217.tar.gz
Qt-1b56836c0e7715fb1321c9bd48c8d6fd5b56f217.tar.bz2
Reduce double-copying of textures when flipping upside down
bindTexture() flipped images in-place, to reduce data copying. But there is one case where the in-place is worse: when the QImage is not detached. In that case, the flip was copying the entire image and then flipping the lines, effectively processing the contents twice. The new version uses mirrored() to reduce the overhead for non-detached images. Reviewed-by: Samuel
Diffstat (limited to 'src/opengl')
-rw-r--r--src/opengl/qgl.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index d5ca218..5ada125 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -2277,13 +2277,21 @@ QGLTexture* QGLContextPrivate::bindTexture(const QImage &image, GLenum target, G
#ifdef QGL_BIND_TEXTURE_DEBUG
printf(" - flipping bits over y (%d ms)\n", time.elapsed());
#endif
- int ipl = img.bytesPerLine() / 4;
- int h = img.height();
- for (int y=0; y<h/2; ++y) {
- int *a = (int *) img.scanLine(y);
- int *b = (int *) img.scanLine(h - y - 1);
- for (int x=0; x<ipl; ++x)
- qSwap(a[x], b[x]);
+ if (img.isDetached()) {
+ int ipl = img.bytesPerLine() / 4;
+ int h = img.height();
+ for (int y=0; y<h/2; ++y) {
+ int *a = (int *) img.scanLine(y);
+ int *b = (int *) img.scanLine(h - y - 1);
+ for (int x=0; x<ipl; ++x)
+ qSwap(a[x], b[x]);
+ }
+ } else {
+ // Create a new image and copy across. If we use the
+ // above in-place code then a full copy of the image is
+ // made before the lines are swapped, which processes the
+ // data twice. This version should only do it once.
+ img = img.mirrored();
}
}