diff --git a/osdep/mac/swift_extensions.swift b/osdep/mac/swift_extensions.swift index 5d784f7026..264cff1827 100644 --- a/osdep/mac/swift_extensions.swift +++ b/osdep/mac/swift_extensions.swift @@ -136,3 +136,17 @@ extension MTLPixelFormat { return "raw pixel format " + String(self.rawValue) } } + +extension CGColorSpace { + public var longName: String { + let description = String(describing: self) + guard let colorSpaceName = self.name as? String, + let regex = try? NSRegularExpression(pattern: ".*\\((.*)\\)", options: .caseInsensitive), + let result = regex.firstMatch(in: description, options: [], range: NSRange(location: 0, length: description.count)), + let range = Range(result.range(at: 1), in: description) else { return description } + + let nameList = description[range].components(separatedBy: "; ").filter { !$0.hasPrefix("kCGColorSpace") } + let simpleName = colorSpaceName.replacingOccurrences(of: "kCGColorSpace", with: "") + return "\(simpleName) (\(nameList.joined(separator: ", ")))" + } +} diff --git a/video/out/mac/metal_layer.swift b/video/out/mac/metal_layer.swift index 47e7995f69..cb20353e2e 100644 --- a/video/out/mac/metal_layer.swift +++ b/video/out/mac/metal_layer.swift @@ -41,11 +41,23 @@ class MetalLayer: CAMetalLayer { } } + // workaround for nil to none-nil values, oldValue is same as current in those cases + var previousColorspace: CGColorSpace? + override var colorspace: CGColorSpace? { + didSet { + if colorspace != previousColorspace { + log.verbose("Metal layer colorspace changed: \(colorspace?.longName ?? "nil")") + } + previousColorspace = colorspace + } + } + init(common com: MacCommon) { common = com super.init() pixelFormat = .rgba16Float + previousColorspace = colorspace backgroundColor = NSColor.black.cgColor }