Threaded rendering question

In your threaded rendering approach how do you finally draw the result. The original paint event that triggered the threads is over and you can't draw to a widget outside of a paint event. Do you use a timer to fire a paint event and then use the computed result?



  • Yes, basically that is the way it is done.

    The basic class implementing that in KLayout is lay::LayoutCanvas ( in LayoutCanvas::update_image. This class connects to the drawing threads through asynchronous callbacks (signal_transfer_done, signal_end_of_drawing).

    "Asynchronous" means they can be called from any thread. They will be dispatched into the main thread by a mechanism called deferred execution in KLayout's source (tl::DeferredExecution object). That is nothing else than a Qt timer which is used to delegate the execution of a method to the main thread. Today there is "Qt::QueuedConnection" mode which to my understanding works the same way, but wasn't there when KLayout was initiated.

    If you want to look further, the actual drawing happens inside a thread that is implemented in and (the names are slighly confusing as RedrawThread is actually a thread group while RedrawThreadWorker is one of the multiple drawing threads). RedrawThreadWorker regularly calles test_snapshot which itself calls wakeup from RedrawThread after having stashed the current bitmaps for image composition. The latter will trigger signal_transfer_done and this is the call that is delegated into the main thread and updates the screen image from the bitmaps.

    Hope that helps,


Sign In or Register to comment.