Removed unused icon resources from app_list.
[chromium-blink-merge.git] / ui / gfx / color_profile_mac.mm
blobac877c0fb6754f5f2bc171edb8c2f5f5bd5fc05a
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
3 // found in the LICENSE file.
5 #include "ui/gfx/color_profile.h"
7 #import <Cocoa/Cocoa.h>
9 #include "base/mac/mac_util.h"
10 #include "ui/gfx/mac/coordinate_conversion.h"
12 namespace {
14 NSScreen* GetNSScreenFromBounds(const gfx::Rect& bounds) {
15   NSScreen* screen = nil;
16   int overlap = 0;
18   for (NSScreen* monitor in [NSScreen screens]) {
19     gfx::Rect monitor_rect = gfx::ScreenRectFromNSRect([monitor frame]);
20     gfx::Rect overlap_rect = gfx::IntersectRects(monitor_rect, bounds);
21     int overlap_size = overlap_rect.width() * overlap_rect.height();
22     if (overlap_size > overlap) {
23       overlap = overlap_size;
24       screen = monitor;
25     }
26   }
28   return screen;
31 }  // namespace
33 namespace gfx {
35 bool GetDisplayColorProfile(const gfx::Rect& bounds,
36                             std::vector<char>* profile) {
37   DCHECK(profile->empty());
39   NSScreen* screen = GetNSScreenFromBounds(bounds);
40   if (!screen || bounds.IsEmpty())
41     return false;
42   NSColorSpace* color_space = [screen colorSpace];
43   if (!color_space)
44     return false;
46   if ([color_space isEqual:[NSColorSpace sRGBColorSpace]])
47     return true;
48   NSData* profile_data = [color_space ICCProfileData];
49   const char* data = static_cast<const char*>([profile_data bytes]);
50   size_t length = [profile_data length];
51   if (data && !gfx::InvalidColorProfileLength(length))
52     profile->assign(data, data + length);
53   return true;
56 void ReadColorProfile(std::vector<char>* profile) {
57   CGColorSpaceRef monitor_color_space(base::mac::GetSystemColorSpace());
58   base::ScopedCFTypeRef<CFDataRef> icc_profile(
59       CGColorSpaceCopyICCProfile(monitor_color_space));
60   if (!icc_profile)
61     return;
62   size_t length = CFDataGetLength(icc_profile);
63   if (gfx::InvalidColorProfileLength(length))
64     return;
65   const unsigned char* data = CFDataGetBytePtr(icc_profile);
66   profile->assign(data, data + length);
69 }  // namespace gfx