CATiledLayer drawLayer:inContext always being called on Main thread - MacOS El Capitan
<p>I'm using a CATiledLayer backed NSView (Mac not iOS) and according to Apple docs <a href="https://developer.apple.com/reference/quartzcore/catiledlayer">https://developer.apple.com/reference/quartzcore/catiledlayer</a> I expect this to be called asynchronously, on multiple threads to aid performance, however it only appears to ever get called on the main thread.</p>

<p>I'm doing the work in <code>drawLayer(layer: CALayer, inContext ctx: CGContext)</code></p>

<p>I have enabled <code>canDrawConcurrently</code> on the NSView as well as ensuring the window has <code>allowsConcurrentViewDrawing</code> set as true (default), but it still always calls on the main thread for each tile rect.</p>

<p>I need to do some image manipulation prior to display dependant on the rect area needing display, and running on the main thread impacts performance. </p>

<p>Any ideas how I can either force it to call on a background thread?</p>

<p>I have tried marshalling the image a operation onto background thread and then recalling the main queue with the following but it displays a blank rect:</p>

<pre><code>backgroundQueue.addOperationWithBlock({ [ weak self ] in            
    guard let strongSelf = self else { return }

    // ** This is the part I nee to do in background that can take some time
    guard let image = strongSelf.imageForTileRect(layerBounds, imageSize: imageSize) else { return }
    // ** End background bit

    var rect = layerBounds
    let rectImageRef = image.CGImageForProposedRect(&amp;rect, context: nil, hints: nil)

    if (rectImageRef != nil) {
        NSOperationQueue.mainQueue().addOperationWithBlock({ 
            CGContextDrawImage(ctx, rect, rectImageRef)
        })
    }
})
</code></pre>