I am using CATILELayer supported by NSView (Mac is not iOS) and according to Apple docs https://developer.apple.com/reference/quartzcore/catiledlayer I expect this to be called asynchronously, on multiple threads but apparently , it appears only in the main stream.
I am doing work in drawLayer(layer: CALayer, inContext ctx: CGContext)
I turned on canDrawConcurrently in NSView and also set the allowsConcurrentViewDrawing window to true (the default), but it still always calls the main thread for each rectangle of the rectangle.
I need to do some manipulations with the images before the display, depending on the area of ββthe rectangle that needs to be displayed, and working on the main thread affects performance.
Any ideas how I can get her to cause a background thread?
I tried to arrange the image in the background thread and then called the main queue as follows, but it displays an empty rectangle:
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(&rect, context: nil, hints: nil) if (rectImageRef != nil) { NSOperationQueue.mainQueue().addOperationWithBlock({ CGContextDrawImage(ctx, rect, rectImageRef) }) } })
core-animation calayer nsview macos catiledlayer
Herwr
source share