History

cocoa-cb: add support for macOS color space transformation (EDR/HDR)

by default utilises the color space of the screen on which the window is located. if a specific value is defined, it will instead be utilised. depending on the chosen color space the macOS EDR (HDR) support is activated and that OS's transformation (tone mapping) is used. Fixes #7341

der richter committed 2 years ago

Commit 8a619291 parent cb75ecf10 files · +143 −2Browse files

Unified · Split

10 files
  1. DOCS/man/options.rst +31 −0
  2. meson.build +12 −0
  3. meson_options.txt +2 −0
  4. osdep/mac/app_bridge.h +19 −0
  5. osdep/mac/app_bridge.m +18 −1
  6. osdep/mac/meson.build +8 −0
  7. video/out/cocoa_cb_common.swift +49 −1
  8. video/out/mac/common.swift +2 −0
  9. video/out/mac/gl_layer.swift +1 −0
  10. video/out/mac/view.swift +1 −0
DOCS/man/options.rst+31−0
@@ -6285,6 +6285,37 @@ them. · 6284 unmodified lines
6285 6285
6286 macOS and cocoa-cb only.6286 macOS and cocoa-cb only.
6287 6287
6288``--cocoa-cb-output-csp=<csp>``
6289 This sets the color space of the layer to activate the macOS color
6290 transformation. Depending on the color space used the system's EDR (HDR)
6291 support will be activated. To get correct results, this needs to be set to
6292 the color primaries/transfer characteristics of the VO target. It is recommended
6293 to use this switch together with ``--target-trc`` and ``--target-prim``.
6294
6295 ``<csp>`` can be one of the following:
6296
6297 :auto: Sets the color space to the icc profile of the
6298 screen (default).
6299 :display-p3: DCI P3 primaries, a D65 white point and the sRGB
6300 transfer function.
6301 :display-p3-hlg: DCI P3 primaries, a D65 white point and the Hybrid
6302 Log-Gamma (HLG) transfer function.
6303 :display-p3-pq: DCI P3 primaries, a D65 white point and the Perceptual
6304 Quantizer (PQ) transfer function.
6305 :display-p3-linear: DCI P3 primaries, a D65 white point and linear transfer function.
6306 :dci-p3: DCI P3 color space.
6307 :bt.2020: ITU BT.2020 color space.
6308 :bt.2020-linear: ITU BT.2020 color space and linear transfer function.
6309 :bt.2100-hlg: ITU BT.2100 and the Hybrid Log-Gamma (HLG) transfer function.
6310 :bt.2100-pq: ITU BT.2100 and the Perceptual Quantizer (PQ) transfer function.
6311 :bt.709: ITU BT.709 color space.
6312 :srgb: sRGB colorimetry and non-linear transfer function.
6313 :srgb-linear: Same as sRGB but linear transfer function.
6314 :rgb-linear: RGB and linear transfer function.
6315 :adobe: Adobe RGB (1998) color space.
6316
6317 macOS and cocoa-cb only.
6318
6288``--macos-title-bar-appearance=<appearance>``6319``--macos-title-bar-appearance=<appearance>``
6289 Sets the appearance of the title bar (default: auto). Not all combinations6320 Sets the appearance of the title bar (default: auto). Not all combinations
6290 of appearances and ``--macos-title-bar-material`` materials make sense or6321 of appearances and ``--macos-title-bar-material`` materials make sense or
meson.build+12−0
@@ -1570,6 +1570,18 @@ if features['cocoa'] and features['swift'] · 1569 unmodified lines
1570 'video/out/mac/window.swift')1570 'video/out/mac/window.swift')
1571endif1571endif
1572 1572
1573macos_11_features = get_option('macos-11-features').require(
1574 macos_sdk_version.version_compare('>= 11'),
1575 error_message: 'A macos sdk version >= 11 could not be found!',
1576)
1577features += {'macos-11-features': macos_11_features.allowed()}
1578
1579macos_12_features = get_option('macos-12-features').require(
1580 macos_sdk_version.version_compare('>= 12'),
1581 error_message: 'A macos sdk version >= 12 could not be found!',
1582)
1583features += {'macos-12-features': macos_12_features.allowed()}
1584
1573macos_cocoa_cb = get_option('macos-cocoa-cb').require(1585macos_cocoa_cb = get_option('macos-cocoa-cb').require(
1574 features['cocoa'] and features['gl-cocoa'] and features['swift'],1586 features['cocoa'] and features['gl-cocoa'] and features['swift'],
1575 error_message: 'Either cocoa, gl-cocoa or swift could not be found!',1587 error_message: 'Either cocoa, gl-cocoa or swift could not be found!',
meson_options.txt+2−0
@@ -106,6 +106,8 @@ option('videotoolbox-pl', type: 'feature', value: 'auto', description: 'Videotoo · 105 unmodified lines
106option('vulkan-interop', type: 'feature', value: 'auto', description: 'Vulkan graphics interop')106option('vulkan-interop', type: 'feature', value: 'auto', description: 'Vulkan graphics interop')
107 107
108# macOS features108# macOS features
109option('macos-11-features', type: 'feature', value: 'auto', description: 'macOS 11 SDK Features')
110option('macos-12-features', type: 'feature', value: 'auto', description: 'macOS 12 SDK Features')
109option('macos-cocoa-cb', type: 'feature', value: 'auto', description: 'macOS libmpv backend')111option('macos-cocoa-cb', type: 'feature', value: 'auto', description: 'macOS libmpv backend')
110option('macos-media-player', type: 'feature', value: 'auto', description: 'macOS Media Player support')112option('macos-media-player', type: 'feature', value: 'auto', description: 'macOS Media Player support')
111option('macos-touchbar', type: 'feature', value: 'auto', description: 'macOS Touch Bar support')113option('macos-touchbar', type: 'feature', value: 'auto', description: 'macOS Touch Bar support')
osdep/mac/app_bridge.h+19−0
@@ -35,6 +35,24 @@ enum { · 34 unmodified lines
35 RENDER_TIMER_PRECISE,35 RENDER_TIMER_PRECISE,
36};36};
37 37
38enum {
39 MAC_CSP_AUTO = -1,
40 MAC_CSP_DISPLAY_P3,
41 MAC_CSP_DISPLAY_P3_HLG,
42 MAC_CSP_DISPLAY_P3_PQ,
43 MAC_CSP_DISPLAY_P3_LINEAR,
44 MAC_CSP_DCI_P3,
45 MAC_CSP_BT_2020,
46 MAC_CSP_BT_2020_LINEAR,
47 MAC_CSP_BT_2100_HLG,
48 MAC_CSP_BT_2100_PQ,
49 MAC_CSP_BT_709,
50 MAC_CSP_SRGB,
51 MAC_CSP_SRGB_LINEAR,
52 MAC_CSP_RGB_LINEAR,
53 MAC_CSP_ADOBE,
54};
55
38struct macos_opts {56struct macos_opts {
39 int macos_title_bar_appearance;57 int macos_title_bar_appearance;
40 int macos_title_bar_material;58 int macos_title_bar_material;
@@ -46,6 +64,7 @@ struct macos_opts { · 5 unmodified lines
46 int macos_render_timer;64 int macos_render_timer;
47 int cocoa_cb_sw_renderer;65 int cocoa_cb_sw_renderer;
48 bool cocoa_cb_10bit_context;66 bool cocoa_cb_10bit_context;
67 int cocoa_cb_output_csp;
49};68};
50 69
51void cocoa_init_media_keys(void);70void cocoa_init_media_keys(void);
osdep/mac/app_bridge.m+18−1
@@ -55,6 +55,22 @@ const struct m_sub_options macos_conf = { · 54 unmodified lines
55 {"cocoa-cb-sw-renderer", OPT_CHOICE(cocoa_cb_sw_renderer,55 {"cocoa-cb-sw-renderer", OPT_CHOICE(cocoa_cb_sw_renderer,
56 {"auto", -1}, {"no", 0}, {"yes", 1})},56 {"auto", -1}, {"no", 0}, {"yes", 1})},
57 {"cocoa-cb-10bit-context", OPT_BOOL(cocoa_cb_10bit_context)},57 {"cocoa-cb-10bit-context", OPT_BOOL(cocoa_cb_10bit_context)},
58 {"cocoa-cb-output-csp", OPT_CHOICE(cocoa_cb_output_csp,
59 {"auto", MAC_CSP_AUTO},
60 {"display-p3", MAC_CSP_DISPLAY_P3},
61 {"display-p3-hlg", MAC_CSP_DISPLAY_P3_HLG},
62 {"display-p3-pq", MAC_CSP_DISPLAY_P3_PQ},
63 {"display-p3-linear", MAC_CSP_DISPLAY_P3_LINEAR},
64 {"dci-p3", MAC_CSP_DCI_P3},
65 {"bt.2020", MAC_CSP_BT_2020},
66 {"bt.2020-linear", MAC_CSP_BT_2020_LINEAR},
67 {"bt.2100-hlg", MAC_CSP_BT_2100_HLG},
68 {"bt.2100-pq", MAC_CSP_BT_2100_PQ},
69 {"bt.709", MAC_CSP_BT_709},
70 {"srgb", MAC_CSP_SRGB},
71 {"srgb-linear", MAC_CSP_SRGB_LINEAR},
72 {"rgb-linear", MAC_CSP_RGB_LINEAR},
73 {"adobe", MAC_CSP_ADOBE})},
58 {0}74 {0}
59 },75 },
60 .size = sizeof(struct macos_opts),76 .size = sizeof(struct macos_opts),
@@ -63,7 +79,8 @@ const struct m_sub_options macos_conf = { · 2 unmodified lines
63 .macos_fs_animation_duration = -1,79 .macos_fs_animation_duration = -1,
64 .macos_render_timer = RENDER_TIMER_CALLBACK,80 .macos_render_timer = RENDER_TIMER_CALLBACK,
65 .cocoa_cb_sw_renderer = -1,81 .cocoa_cb_sw_renderer = -1,
66 .cocoa_cb_10bit_context = true82 .cocoa_cb_10bit_context = true,
83 .cocoa_cb_output_csp = MAC_CSP_AUTO,
67 },84 },
68};85};
69 86
osdep/mac/meson.build+8−0
@@ -19,6 +19,14 @@ if get_option('optimization') != '0' · 18 unmodified lines
19 swift_flags += '-O'19 swift_flags += '-O'
20endif20endif
21 21
22if macos_11_features.allowed()
23 swift_flags += ['-D', 'HAVE_MACOS_11_FEATURES']
24endif
25
26if macos_12_features.allowed()
27 swift_flags += ['-D', 'HAVE_MACOS_12_FEATURES']
28endif
29
22if macos_cocoa_cb.allowed()30if macos_cocoa_cb.allowed()
23 swift_flags += ['-D', 'HAVE_MACOS_COCOA_CB']31 swift_flags += ['-D', 'HAVE_MACOS_COCOA_CB']
24endif32endif
video/out/cocoa_cb_common.swift+49−1
@@ -120,7 +120,55 @@ class CocoaCB: Common, EventSubscriber { · 119 unmodified lines
120 }120 }
121 121
122 libmpv.setRenderICCProfile(colorSpace)122 libmpv.setRenderICCProfile(colorSpace)
123 layer?.colorspace = colorSpace.cgColorSpace123 layer?.colorspace = getColorSpace()
124 }
125
126 func getColorSpace() -> CGColorSpace? {
127 guard let colorSpace = window?.screen?.colorSpace?.cgColorSpace else {
128 log.warning("Couldn't retrieve ICC Profile, no color space available")
129 return nil
130 }
131
132 let outputCsp = Int(option.mac.cocoa_cb_output_csp)
133
134 switch outputCsp {
135 case MAC_CSP_AUTO: return colorSpace
136 case MAC_CSP_DISPLAY_P3: return CGColorSpace(name: CGColorSpace.displayP3)
137 case MAC_CSP_DISPLAY_P3_HLG: return CGColorSpace(name: CGColorSpace.displayP3_HLG)
138 case MAC_CSP_DISPLAY_P3_PQ: return CGColorSpace(name: CGColorSpace.displayP3_PQ)
139 case MAC_CSP_DCI_P3: return CGColorSpace(name: CGColorSpace.dcip3)
140 case MAC_CSP_BT_2020: return CGColorSpace(name: CGColorSpace.itur_2020)
141 case MAC_CSP_BT_709: return CGColorSpace(name: CGColorSpace.itur_709)
142 case MAC_CSP_SRGB: return CGColorSpace(name: CGColorSpace.sRGB)
143 case MAC_CSP_SRGB_LINEAR: return CGColorSpace(name: CGColorSpace.linearSRGB)
144 case MAC_CSP_RGB_LINEAR: return CGColorSpace(name: CGColorSpace.genericRGBLinear)
145 case MAC_CSP_ADOBE: return CGColorSpace(name: CGColorSpace.adobeRGB1998)
146 default: break
147 }
148
149#if HAVE_MACOS_11_FEATURES
150 if #available(macOS 11.0, *) {
151 switch outputCsp {
152 case MAC_CSP_BT_2100_HLG: return CGColorSpace(name: CGColorSpace.itur_2100_HLG)
153 case MAC_CSP_BT_2100_PQ: return CGColorSpace(name: CGColorSpace.itur_2100_PQ)
154 default: break
155 }
156 }
157#endif
158
159#if HAVE_MACOS_12_FEATURES
160 if #available(macOS 12.0, *) {
161 switch outputCsp {
162 case MAC_CSP_DISPLAY_P3_LINEAR: return CGColorSpace(name: CGColorSpace.linearDisplayP3)
163 case MAC_CSP_BT_2020_LINEAR: return CGColorSpace(name: CGColorSpace.linearITUR_2020)
164 default: break
165 }
166 }
167#endif
168
169 log.warning("Couldn't retrieve configured color space, falling back to auto")
170
171 return colorSpace
124 }172 }
125 173
126 override func windowDidEndAnimation() {174 override func windowDidEndAnimation() {
video/out/mac/common.swift+2−0
@@ -668,6 +668,8 @@ class Common: NSObject { · 667 unmodified lines
668 titleBar?.set(material: Int(option.mac.macos_title_bar_material))668 titleBar?.set(material: Int(option.mac.macos_title_bar_material))
669 case TypeHelper.toPointer(&option.macPtr.pointee.macos_title_bar_color):669 case TypeHelper.toPointer(&option.macPtr.pointee.macos_title_bar_color):
670 titleBar?.set(color: option.mac.macos_title_bar_color)670 titleBar?.set(color: option.mac.macos_title_bar_color)
671 case TypeHelper.toPointer(&option.macPtr.pointee.cocoa_cb_output_csp):
672 updateICCProfile()
671 default:673 default:
672 break674 break
673 }675 }
video/out/mac/gl_layer.swift+1−0
@@ -106,6 +106,7 @@ class GLLayer: CAOpenGLLayer { · 105 unmodified lines
106 super.init()106 super.init()
107 autoresizingMask = [.layerWidthSizable, .layerHeightSizable]107 autoresizingMask = [.layerWidthSizable, .layerHeightSizable]
108 backgroundColor = NSColor.black.cgColor108 backgroundColor = NSColor.black.cgColor
109 wantsExtendedDynamicRangeContent = true
109 110
110 if bufferDepth > 8 {111 if bufferDepth > 8 {
111 contentsFormat = .RGBA16Float112 contentsFormat = .RGBA16Float
video/out/mac/view.swift+1−0
@@ -32,6 +32,7 @@ class View: NSView, CALayerDelegate { · 31 unmodified lines
32 super.init(frame: frame)32 super.init(frame: frame)
33 autoresizingMask = [.width, .height]33 autoresizingMask = [.width, .height]
34 wantsBestResolutionOpenGLSurface = true34 wantsBestResolutionOpenGLSurface = true
35 wantsExtendedDynamicRangeOpenGLSurface = true
35 registerForDraggedTypes([ .fileURL, .URL, .string ])36 registerForDraggedTypes([ .fileURL, .URL, .string ])
36 }37 }
37 38

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t