OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/mac/io_surface.h" | 5 #include "ui/gfx/mac/io_surface.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/command_line.h" | |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
12 #include "base/mac/mach_logging.h" | 13 #include "base/mac/mach_logging.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
15 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
16 #include "ui/gfx/buffer_format_util.h" | 17 #include "ui/gfx/buffer_format_util.h" |
18 #include "ui/gfx/switches.h" | |
17 | 19 |
18 namespace gfx { | 20 namespace gfx { |
19 | 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 void AddIntegerValue(CFMutableDictionaryRef dictionary, | 24 void AddIntegerValue(CFMutableDictionaryRef dictionary, |
23 const CFStringRef key, | 25 const CFStringRef key, |
24 int32_t value) { | 26 int32_t value) { |
25 base::ScopedCFTypeRef<CFNumberRef> number( | 27 base::ScopedCFTypeRef<CFNumberRef> number( |
26 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); | 28 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 | 182 |
181 if (should_clear) { | 183 if (should_clear) { |
182 // Zero-initialize the IOSurface. Calling IOSurfaceLock/IOSurfaceUnlock | 184 // Zero-initialize the IOSurface. Calling IOSurfaceLock/IOSurfaceUnlock |
183 // appears to be sufficient. https://crbug.com/584760#c17 | 185 // appears to be sufficient. https://crbug.com/584760#c17 |
184 IOReturn r = IOSurfaceLock(surface, 0, nullptr); | 186 IOReturn r = IOSurfaceLock(surface, 0, nullptr); |
185 DCHECK_EQ(kIOReturnSuccess, r); | 187 DCHECK_EQ(kIOReturnSuccess, r); |
186 r = IOSurfaceUnlock(surface, 0, nullptr); | 188 r = IOSurfaceUnlock(surface, 0, nullptr); |
187 DCHECK_EQ(kIOReturnSuccess, r); | 189 DCHECK_EQ(kIOReturnSuccess, r); |
188 } | 190 } |
189 | 191 |
190 bool force_system_color_space = false; | 192 bool force_color_space = false; |
191 | 193 |
192 // Displaying an IOSurface that does not have a color space using an | 194 // Displaying an IOSurface that does not have a color space using an |
193 // AVSampleBufferDisplayLayer can result in a black screen. Specify the | 195 // AVSampleBufferDisplayLayer can result in a black screen. Ensure that |
194 // main display's color profile by default, which will result in no color | 196 // a color space always be specified. |
Avi (use Gerrit)
2017/05/09 14:53:22
... always is specified.
? I'm in an argument wit
ccameron
2017/05/09 16:18:25
This was intended to be the subjunctive mood ... b
| |
195 // correction being done for the main monitor (which is the behavior of not | |
196 // specifying a color space). | |
197 // https://crbug.com/608879 | 197 // https://crbug.com/608879 |
198 if (format == gfx::BufferFormat::YUV_420_BIPLANAR) | 198 if (format == gfx::BufferFormat::YUV_420_BIPLANAR) |
199 force_system_color_space = true; | 199 force_color_space = true; |
200 | 200 |
201 // On Sierra, all IOSurfaces are color corrected as though they are in sRGB | 201 // On Sierra, all IOSurfaces are color corrected as though they are in sRGB |
202 // color space by default. Prior to Sierra, IOSurfaces were not color | 202 // color space by default. Prior to Sierra, IOSurfaces were not color |
203 // corrected (they were treated as though they were in the display color | 203 // corrected (they were treated as though they were in the display color |
204 // space). Override this by defaulting IOSurfaces to be in the main display | 204 // space). Override this by defaulting IOSurfaces to be in the main display |
205 // color space. | 205 // color space. |
206 // https://crbug.com/654488 | 206 // https://crbug.com/654488 |
207 if (base::mac::IsAtLeastOS10_12()) | 207 if (base::mac::IsAtLeastOS10_12()) |
208 force_system_color_space = true; | 208 force_color_space = true; |
209 | 209 |
210 if (force_system_color_space) { | 210 // Ensure that all IOSurfaces start as sRGB when color correct rendering |
211 CGColorSpaceRef color_space = base::mac::GetSystemColorSpace(); | 211 // is enabled. |
212 static bool color_correct_rendering_enabled = | |
213 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
214 switches::kEnableColorCorrectRendering); | |
215 if (color_correct_rendering_enabled) | |
216 force_color_space = true; | |
217 | |
218 if (force_color_space) { | |
219 CGColorSpaceRef color_space = color_correct_rendering_enabled | |
220 ? base::mac::GetSRGBColorSpace() | |
221 : base::mac::GetSystemColorSpace(); | |
212 base::ScopedCFTypeRef<CFDataRef> color_space_icc( | 222 base::ScopedCFTypeRef<CFDataRef> color_space_icc( |
213 CGColorSpaceCopyICCProfile(color_space)); | 223 CGColorSpaceCopyICCProfile(color_space)); |
214 // Note that nullptr is an acceptable input to IOSurfaceSetValue. | 224 // Note that nullptr is an acceptable input to IOSurfaceSetValue. |
215 IOSurfaceSetValue(surface, CFSTR("IOSurfaceColorSpace"), color_space_icc); | 225 IOSurfaceSetValue(surface, CFSTR("IOSurfaceColorSpace"), color_space_icc); |
216 } | 226 } |
217 | 227 |
218 UMA_HISTOGRAM_TIMES("GPU.IOSurface.CreateTime", | 228 UMA_HISTOGRAM_TIMES("GPU.IOSurface.CreateTime", |
219 base::TimeTicks::Now() - start_time); | 229 base::TimeTicks::Now() - start_time); |
220 return surface; | 230 return surface; |
221 } | 231 } |
222 | 232 |
223 } // namespace gfx | 233 } // namespace gfx |
OLD | NEW |