Как эффективно превратить CALayer в CVPixelBuffer? - PullRequest
0 голосов
/ 09 апреля 2019

Я хочу найти способ заменить функцию CALayer "layer.render (in: context)", которая может более эффективно

if let context = CGContext(data: pixelData, width: Int(contextSize.width), height: Int(contextSize.height), bitsPerComponent: 8, bytesPerRow: CVPixelBufferGetBytesPerRow(pixelBuffer), space: rgbColorSpace, bitmapInfo: CGImageAlphaInfo.noneSkipFirst.rawValue) {
    let contentRect = CGRect(x: 0.0, y: 0.0, width: contextSize.width, height: contextSize.height)
    context.clear(contentRect)
    let flipVertical = CGAffineTransform.init(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: contextSize.height)
    context.concatenate(flipVertical)
    // draw the layer in the context
    if let layer = self.delegate?.viedeoLayer?(atTime: Double(currentFrameCount)/Double(frameRate)) {
         //here is the Problem point
         layer.render(in: context)
    }            
   // unlock the buffer memory
   CVPixelBufferUnlockBaseAddress(pixelBuffer, CVPixelBufferLockFlags(rawValue: CVOptionFlags(0)))
}
...