Index: ui/gfx/color_profile_mac.mm |
diff --git a/ui/gfx/color_profile_mac.mm b/ui/gfx/color_profile_mac.mm |
index c36072d93308cee51a90ff71121c3201c9e84dcf..346207e9716736bb59e6675198c90b91edfba6a4 100644 |
--- a/ui/gfx/color_profile_mac.mm |
+++ b/ui/gfx/color_profile_mac.mm |
@@ -5,15 +5,52 @@ |
#include "ui/gfx/color_profile.h" |
#include "base/mac/mac_util.h" |
+#include "base/mac/sdk_forward_declarations.h" |
+#include "ui/gfx/mac/coordinate_conversion.h" |
+ |
+namespace { |
+ |
+NSScreen* GetNSScreenFromBounds(const gfx::Rect& bounds) { |
+ NSScreen* screen = NULL; |
+ int overlap = 0; |
+ |
+ for (NSScreen* monitor in [NSScreen screens]) { |
+ gfx::Rect monitor_rect = gfx::ScreenRectFromNSRect([monitor frame]); |
+ gfx::Rect overlap_rect = gfx::IntersectRects(monitor_rect, bounds); |
+ int overlap_size = overlap_rect.width() * overlap_rect.height(); |
+ if (overlap_size > overlap) { |
+ overlap = overlap_size; |
+ screen = monitor; |
+ } |
+ } |
+ |
+ return screen; |
+} |
+ |
+} // namespace |
namespace gfx { |
bool GetDisplayColorProfile(const gfx::Rect& bounds, |
std::vector<char>* profile) { |
- if (bounds.IsEmpty()) |
+ DCHECK(profile->empty()); |
+ |
+ NSScreen* screen = GetNSScreenFromBounds(bounds); |
+ if (!screen || bounds.IsEmpty()) |
+ return false; |
+ NSColorSpace* color_space = [screen colorSpace]; |
+ if (!color_space) |
return false; |
- // TODO(noel): implement. |
- return false; |
+ |
+ if ([color_space isEqual:[NSColorSpace sRGBColorSpace]]) |
+ 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,
|
+ NSData* profile_data = [color_space ICCProfileData]; |
+ 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.
|
+ profile->assign(data, data + [profile_data length]); |
+ size_t length = profile->size(); |
+ 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.
|
+ profile->clear(); |
+ return true; |
} |
void ReadColorProfile(std::vector<char>* profile) { |