drawing thread-safety in iOS

  • I'm having trouble getting a handle on what's thread-safe in iOS drawing and what's not. The trouble is that the docs are so coy (and out-of-date, as far as I can tell). To the extent that the docs do say anything clear, it's all negative:

    "You cannot use any UIKit's drawing methods when drawing to a CATiledLayer, and you cannot do your drawing inside of a UIView's -drawRect: method. Instead you must implement -drawLayer:inContext: and draw only using Core Graphics and other thread-safe functions that accept a CGContextRef to target drawing to."

    "UIGraphicsBeginImageContext... You should call this function from the main thread of your application only."

    And so forth. However, in an obscure corner of the release notes, we read (for iOS 4):

    > • 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.

    Moreover, in the WWDC videos we see CATiledLayer being drawn to via drawRect: with UIKit.

    So what's true? And how can I find out precisely what is and isn't thread-safe? m.

    --
    matt neuburg, phd = <matt...>, <http://www.apeth.net/matt/>
    A fool + a tool + an autorelease pool = cool!
    AppleScript: the Definitive Guide - Second Edition!
    UIKit graphics drawing methods are thread safe on iOS 4.0 or greater. If you are referring to the QA on using a CATiledLayer with UIView, that probably does indeed need to be updated, but the methods it warns against should all be safe to use from secondary threads on iOS 4.0 or later.

    On Dec 2, 2010, at 10:45 AM, Matt Neuburg wrote:

    > I'm having trouble getting a handle on what's thread-safe in iOS drawing and what's not. The trouble is that the docs are so coy (and out-of-date, as far as I can tell). To the extent that the docs do say anything clear, it's all negative:
    >
    > "You cannot use any UIKit's drawing methods when drawing to a CATiledLayer, and you cannot do your drawing inside of a UIView's -drawRect: method. Instead you must implement -drawLayer:inContext: and draw only using Core Graphics and other thread-safe functions that accept a CGContextRef to target drawing to."
    >
    > "UIGraphicsBeginImageContext... You should call this function from the main thread of your application only."
    >
    > And so forth. However, in an obscure corner of the release notes, we read (for iOS 4):
    >
    >> • 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.
    >
    > Moreover, in the WWDC videos we see CATiledLayer being drawn to via drawRect: with UIKit.
    >
    > So what's true? And how can I find out precisely what is and isn't thread-safe? m.

    --
    David Duncan
previous month december 2010 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today