Opened 14 years ago
Last modified 14 years ago
#2037 new enhancement
Enable multi-threaded rendering in QGIS
Reported by: | timlinux | Owned by: | nobody |
---|---|---|---|
Priority: | minor: annoyance | Milestone: | Version 1.7.0 |
Component: | MapCanvas | Version: | Trunk |
Keywords: | Cc: | ||
Must Fix for Release: | No | Platform: | Debian |
Platform Version: | Awaiting user input: | no |
Description
User story 1: Joe has a multicore processor but when QGIS is rendering a map, one of the cores is heavily utilised whilst the rest remain idle.
User story 2: Pam wishes she didnt need to wait so long for maps to draw as each layer draw carries out a long running query against a database backend.
Qt4 includes QThread which makes writing multithreaded cross platform libraries fairly easily. Thus it would be good to start thinking about how we can make QGIS take advantage of this.
In my mind there are two main areas of work required:
- making map layers inherit from QThread and adding in sufficient foundation for them to be able to render in a thread (pretty much covered in the attached patch).
- Updating qgsmaprenderer.cpp to orchestrate the threaded rendering of map layers and the composition of the results.
For the second (renderer part) we will need to split the render process into three parts I think:
- a setup phase which sets the render context for each maplayer (which would need to become a member of qgsmaplayer) and then calls the run() method to launch the thread
- a slot to listen for when each thread is done and tally up when all the rendering work is completed
- a finalise method to end the render process with label and acetate rendering and perform final compositing from layer render cache images.
Attachments (1)
Change History (5)
by , 14 years ago
Attachment: | qgis_threaded_render.v1.diff added |
---|
comment:1 by , 14 years ago
Hi Tim
Please also consider the QtConcurrent (http://doc.trolltech.com/4.5/threads.html#qtconcurrent) framework as an option. The advantage over inheritance from QThread is that the number of created threads automatically adapts depending on the number of cores. Furthermore it is more high-level and therefore simpler to use. And it does not require api changes in QgsMapLayer.
The Qt doc about QtConcurrent is not as good as the usual Qt docs. I once wrote an example to render a tiled raster in threads with QtConcurrent. We may look at this next week.
cheers, Marco
comment:2 by , 14 years ago
I'd like to second Marco's suggestion. Inheriting map layers from QThread looks like a bad design decision...
comment:3 by , 14 years ago
Component: | Build/Install → MapCanvas |
---|
comment:4 by , 14 years ago
Milestone: | Version 1.5.0 → Version 1.6.0 |
---|
There is an ongoing Summer of Code project dealing with this. Hopefully we'll see the results in a couple of months
first draft of patch - makes maplayers qthread children