After looking into the Qt source code more carefully and debugging the application I found the following:
Everytime setPixel is called, detach is also called. Detach looks like the following:
{
if (d) {
if (qt_image_cleanup_hook_64 && d->ref == 1)
qt_image_cleanup_hook_64(cacheKey());
if (d->ref != 1 || d->ro_data)
*this = copy();
++d->detach_no;
}
}
void QImage::detach()
{
if (d) {
if (qt_image_cleanup_hook_64 && d->ref == 1)
qt_image_cleanup_hook_64(cacheKey());
if (d->ref != 1 || d->ro_data)
*this = copy();
++d->detach_no;
}
}
To copy to clipboard, switch view to plain text mode
The important part here is "qt_image_cleanup_hook_64". This global (!) function pointer is initialized to qt_gl_image_cleanup only by the OpenGL module (so when rendering normally, the following functions won't be called).
qt_gl_image_cleanup might then call qt_gl_clean_cache which also does some processing.
You see, it adds a lot of overhead to the simple setPixel operation (and therefore reduces the performance). To conclude it's necessary to manipulate the bits directly in order to avoid the performance hit (just call QImage::bits() once for each image update)
Bookmarks