diff options
| author | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2023-11-29 11:25:12 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2023-11-29 11:25:12 +0100 |
| commit | 082b61f32344872d4360ad4c71cf62c99de62ae8 (patch) | |
| tree | 7af9ade0ae9ecd822a49b1b023719ae36b203021 /Captura/Core Extensions/CVImageBuffer+cgImage.swift | |
| parent | 9431168da5eb1338d8c9fc8cc92e6245c539e73d (diff) | |
Add multimonitor support1.0.0rbdr-multimonitor
Diffstat (limited to 'Captura/Core Extensions/CVImageBuffer+cgImage.swift')
| -rw-r--r-- | Captura/Core Extensions/CVImageBuffer+cgImage.swift | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/Captura/Core Extensions/CVImageBuffer+cgImage.swift b/Captura/Core Extensions/CVImageBuffer+cgImage.swift index f8958f2..3f59b8e 100644 --- a/Captura/Core Extensions/CVImageBuffer+cgImage.swift +++ b/Captura/Core Extensions/CVImageBuffer+cgImage.swift @@ -3,10 +3,19 @@ import ReplayKit extension CVImageBuffer { - static let sharedContext = CIContext() + private static let contextQueue = DispatchQueue(label: "com.example.contextQueue") + static let sharedContext: CIContext = { + return CIContext() + }() var cgImage: CGImage? { - let ciImage = CIImage(cvImageBuffer: self) - return CVImageBuffer.sharedContext.createCGImage(ciImage, from: CGRect(x: 0, y: 0, width: CVPixelBufferGetWidth(self), height: CVPixelBufferGetHeight(self))) + var result: CGImage? + CVImageBuffer.contextQueue.sync { + let ciImage = CIImage(cvImageBuffer: self) + let width = CVPixelBufferGetWidth(self) + let height = CVPixelBufferGetHeight(self) + result = CVImageBuffer.sharedContext.createCGImage(ciImage, from: CGRect(x: 0, y: 0, width: width, height: height)) + } + return result } } |