| 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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 170 |
| 171 if (should_clear) { | 171 if (should_clear) { |
| 172 // Zero-initialize the IOSurface. Calling IOSurfaceLock/IOSurfaceUnlock | 172 // Zero-initialize the IOSurface. Calling IOSurfaceLock/IOSurfaceUnlock |
| 173 // appears to be sufficient. https://crbug.com/584760#c17 | 173 // appears to be sufficient. https://crbug.com/584760#c17 |
| 174 IOReturn r = IOSurfaceLock(surface, 0, nullptr); | 174 IOReturn r = IOSurfaceLock(surface, 0, nullptr); |
| 175 DCHECK_EQ(kIOReturnSuccess, r); | 175 DCHECK_EQ(kIOReturnSuccess, r); |
| 176 r = IOSurfaceUnlock(surface, 0, nullptr); | 176 r = IOSurfaceUnlock(surface, 0, nullptr); |
| 177 DCHECK_EQ(kIOReturnSuccess, r); | 177 DCHECK_EQ(kIOReturnSuccess, r); |
| 178 } | 178 } |
| 179 | 179 |
| 180 bool force_system_color_space = false; |
| 181 |
| 180 // Displaying an IOSurface that does not have a color space using an | 182 // Displaying an IOSurface that does not have a color space using an |
| 181 // AVSampleBufferDisplayLayer can result in a black screen. Specify the | 183 // AVSampleBufferDisplayLayer can result in a black screen. Specify the |
| 182 // main display's color profile by default, which will result in no color | 184 // main display's color profile by default, which will result in no color |
| 183 // correction being done for the main monitor (which is the behavior of not | 185 // correction being done for the main monitor (which is the behavior of not |
| 184 // specifying a color space). | 186 // specifying a color space). |
| 185 // https://crbug.com/608879 | 187 // https://crbug.com/608879 |
| 186 if (format == gfx::BufferFormat::YUV_420_BIPLANAR) { | 188 if (format == gfx::BufferFormat::YUV_420_BIPLANAR) |
| 187 base::ScopedCFTypeRef<CGColorSpaceRef> color_space( | 189 force_system_color_space = true; |
| 188 CGDisplayCopyColorSpace(CGMainDisplayID())); | 190 |
| 191 // On Sierra, all IOSurfaces are color corrected as though they are in sRGB |
| 192 // color space by default. Prior to Sierra, IOSurfaces were not color |
| 193 // corrected (they were treated as though they were in the display color |
| 194 // space). Override this by defaulting IOSurfaces to be in the main display |
| 195 // color space. |
| 196 // https://crbug.com/654488 |
| 197 if (base::mac::IsAtLeastOS10_12()) |
| 198 force_system_color_space = true; |
| 199 |
| 200 if (force_system_color_space) { |
| 201 CGColorSpaceRef color_space = base::mac::GetSystemColorSpace(); |
| 189 base::ScopedCFTypeRef<CFDataRef> color_space_icc( | 202 base::ScopedCFTypeRef<CFDataRef> color_space_icc( |
| 190 CGColorSpaceCopyICCProfile(color_space)); | 203 CGColorSpaceCopyICCProfile(color_space)); |
| 191 // Note that nullptr is an acceptable input to IOSurfaceSetValue. | 204 // Note that nullptr is an acceptable input to IOSurfaceSetValue. |
| 192 IOSurfaceSetValue(surface, CFSTR("IOSurfaceColorSpace"), color_space_icc); | 205 IOSurfaceSetValue(surface, CFSTR("IOSurfaceColorSpace"), color_space_icc); |
| 193 } | 206 } |
| 194 | 207 |
| 195 UMA_HISTOGRAM_TIMES("GPU.IOSurface.CreateTime", | 208 UMA_HISTOGRAM_TIMES("GPU.IOSurface.CreateTime", |
| 196 base::TimeTicks::Now() - start_time); | 209 base::TimeTicks::Now() - start_time); |
| 197 return surface; | 210 return surface; |
| 198 } | 211 } |
| 199 | 212 |
| 200 } // namespace gfx | 213 } // namespace gfx |
| OLD | NEW |