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) { | |
14 NSScreen* screen = NULL; | |
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; | |
Robert Sesek
2014/10/06 17:56:00
Why do this and not assign the profile data?
Noel Gordon
2014/10/07 01:57:43
The sRGB profile is common, and renderers can inte
Robert Sesek
2014/10/07 14:20:10
That's kind of an odd thing to bake into this API,
| |
47 NSData* profile_data = [color_space ICCProfileData]; | |
48 if (const char* data = (char *)[profile_data bytes]) | |
Robert Sesek
2014/10/06 17:56:00
C-style casts are banned.
http://google-styleguid
Noel Gordon
2014/10/07 01:57:43
Done.
| |
49 profile->assign(data, data + [profile_data length]); | |
50 size_t length = profile->size(); | |
51 if (gfx::InvalidColorProfileLength(length)) | |
Robert Sesek
2014/10/06 17:56:00
Why not check the length before assigning into the
Noel Gordon
2014/10/07 01:57:43
Done.
| |
52 profile->clear(); | |
53 return true; | |
17 } | 54 } |
18 | 55 |
19 void ReadColorProfile(std::vector<char>* profile) { | 56 void ReadColorProfile(std::vector<char>* profile) { |
20 CGColorSpaceRef monitor_color_space(base::mac::GetSystemColorSpace()); | 57 CGColorSpaceRef monitor_color_space(base::mac::GetSystemColorSpace()); |
21 base::ScopedCFTypeRef<CFDataRef> icc_profile( | 58 base::ScopedCFTypeRef<CFDataRef> icc_profile( |
22 CGColorSpaceCopyICCProfile(monitor_color_space)); | 59 CGColorSpaceCopyICCProfile(monitor_color_space)); |
23 if (!icc_profile) | 60 if (!icc_profile) |
24 return; | 61 return; |
25 size_t length = CFDataGetLength(icc_profile); | 62 size_t length = CFDataGetLength(icc_profile); |
26 if (gfx::InvalidColorProfileLength(length)) | 63 if (gfx::InvalidColorProfileLength(length)) |
27 return; | 64 return; |
28 const unsigned char* data = CFDataGetBytePtr(icc_profile); | 65 const unsigned char* data = CFDataGetBytePtr(icc_profile); |
29 profile->assign(data, data + length); | 66 profile->assign(data, data + length); |
30 } | 67 } |
31 | 68 |
32 } // namespace gfx | 69 } // namespace gfx |
OLD | NEW |