What would be the best way to use the
DncPainter to render to an offscreen canvas?
You might think you could just start with
OffscreenRenderingExample and change it to use a layout that includes the DNC painter. But this always produces a completely blank, black image. Some debugging shows that the DNC painter fires up a number of background threads (managed by the
asyncExec,
iconsExec, and
labelsExec members, plus the render cache has others). So naively just building the layout and immediately calling
canvas.toBufferedImage() doesn't give those threads enough time to do their work. See attached file
NaiveAttempt.java.
So I tried subclassing DncPainter to override paintTo so that it would wait until the background threads are done and call the superclass paintTo again. But this is unreliable. Sometimes everything draws, sometimes not. See attached file WaitForAsyncAndRepaint.java. If you were to run it a few times, it'll produce slightly different images each time.
Is there some easy way to un-thread
DncPainter and its moving parts? Or to force it to pre-load everything in the view so that the
paintTo method can render everything immediately?
Thanks for any input or ideas!