2
我正在寻找在macOS上绘制屏幕外CALayer内容(无需alpha)的最快方法。请注意,这些示例不是线程化的,但重点是(以及为什么我不只是使用CALayer.setNeedsDisplay),因为我正在后台线程上执行此绘图。绘制屏幕外CALayer内容的最快方法
我的原代码,这样做:
let bounds = layer.bounds.size
let contents = NSImage(size: size)
contents.lockFocusFlipped(true)
let context = NSGraphicsContext.current()!.cgContext
layer.draw(in: context)
contents.unlockFocus()
layer.contents = contents