So, as mentioned in this answer and in the iOS 4.0 release notes, UIKit now has some thread-safe drawing facilities:
Drawing to a graphics context in UIKit is now thread-safe. Specifically:
- The routines used to access and manipulate the graphics context can now correctly handle contexts residing on different threads.
- String and image drawing is now thread-safe.
- Using color and font objects in multiple threads is now safe to do.
That's great, but how do you use it?
As far as I'm aware, any time you're not inside -drawRect:
you can only draw using the UIKit/UIGraphics stuff if you've created your own context through UIGraphicsBeginImageContext()
or UIGraphicsPushContext()
, but those functions are not thread safe according to the docs, and -drawRect()
is always called on the main thread.
I assume that creating an image context on the main thread and then starting the background method would be a really bad idea, due to race conditions aplenty.
So, how do I use this multithreaded UIKit-based drawing stuff that was introduced in iOS 4? What other ways of getting an active UIKit graphics context have I missed?
P.S. I know that I could just draw using Core Graphics and be done with it. For various reasons (legacy code) I'd like to continue using the UIKit based drawing methods.