Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/color_profile.h" | 5 #include "ui/gfx/color_profile.h" |
| 6 | 6 |
| 7 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
| 8 #include "base/mac/sdk_forward_declarations.h" | |
| 9 #include "ui/gfx/mac/coordinate_conversion.h" | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 NSScreen* GetNSScreenFromBounds(const gfx::Rect& bounds) { | |
|
Robert Sesek
2014/10/07 14:20:10
I just noticed that this code is very similar to t
| |
| 14 NSScreen* screen = NULL; | |
|
Robert Sesek
2014/10/07 14:20:10
nit: NULL -> nil
Noel Gordon
2014/10/07 23:34:27
Done.
| |
| 15 int overlap = 0; | |
| 16 | |
| 17 for (NSScreen* monitor in [NSScreen screens]) { | |
| 18 gfx::Rect monitor_rect = gfx::ScreenRectFromNSRect([monitor frame]); | |
| 19 gfx::Rect overlap_rect = gfx::IntersectRects(monitor_rect, bounds); | |
| 20 int overlap_size = overlap_rect.width() * overlap_rect.height(); | |
| 21 if (overlap_size > overlap) { | |
| 22 overlap = overlap_size; | |
| 23 screen = monitor; | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 return screen; | |
| 28 } | |
| 29 | |
| 30 } // namespace | |
| 8 | 31 |
| 9 namespace gfx { | 32 namespace gfx { |
| 10 | 33 |
| 11 bool GetDisplayColorProfile(const gfx::Rect& bounds, | 34 bool GetDisplayColorProfile(const gfx::Rect& bounds, |
| 12 std::vector<char>* profile) { | 35 std::vector<char>* profile) { |
| 13 if (bounds.IsEmpty()) | 36 DCHECK(profile->empty()); |
| 37 | |
| 38 NSScreen* screen = GetNSScreenFromBounds(bounds); | |
| 39 if (!screen || bounds.IsEmpty()) | |
| 14 return false; | 40 return false; |
| 15 // TODO(noel): implement. | 41 NSColorSpace* color_space = [screen colorSpace]; |
| 16 return false; | 42 if (!color_space) |
| 43 return false; | |
| 44 | |
| 45 if ([color_space isEqual:[NSColorSpace sRGBColorSpace]]) | |
| 46 return true; | |
| 47 NSData* profile_data = [color_space ICCProfileData]; | |
| 48 const char* data = static_cast<const char *>([profile_data bytes]); | |
|
Robert Sesek
2014/10/07 14:20:10
nti: no space before * in the cast parameter
Noel Gordon
2014/10/07 23:34:27
Done.
| |
| 49 size_t length = [profile_data length]; | |
| 50 if (data && !gfx::InvalidColorProfileLength(length)) | |
| 51 profile->assign(data, data + length); | |
| 52 return true; | |
| 17 } | 53 } |
| 18 | 54 |
| 19 void ReadColorProfile(std::vector<char>* profile) { | 55 void ReadColorProfile(std::vector<char>* profile) { |
| 20 CGColorSpaceRef monitor_color_space(base::mac::GetSystemColorSpace()); | 56 CGColorSpaceRef monitor_color_space(base::mac::GetSystemColorSpace()); |
| 21 base::ScopedCFTypeRef<CFDataRef> icc_profile( | 57 base::ScopedCFTypeRef<CFDataRef> icc_profile( |
| 22 CGColorSpaceCopyICCProfile(monitor_color_space)); | 58 CGColorSpaceCopyICCProfile(monitor_color_space)); |
| 23 if (!icc_profile) | 59 if (!icc_profile) |
| 24 return; | 60 return; |
| 25 size_t length = CFDataGetLength(icc_profile); | 61 size_t length = CFDataGetLength(icc_profile); |
| 26 if (gfx::InvalidColorProfileLength(length)) | 62 if (gfx::InvalidColorProfileLength(length)) |
| 27 return; | 63 return; |
| 28 const unsigned char* data = CFDataGetBytePtr(icc_profile); | 64 const unsigned char* data = CFDataGetBytePtr(icc_profile); |
| 29 profile->assign(data, data + length); | 65 profile->assign(data, data + length); |
| 30 } | 66 } |
| 31 | 67 |
| 32 } // namespace gfx | 68 } // namespace gfx |
| OLD | NEW |