Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1321)

Side by Side Diff: ui/gfx/color_profile_mac.mm

Issue 612613002: ui/gfx/color_profile: implement GetDisplayColorProfile on mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Join OVERRIDE -> override party. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/color_profile.h ('k') | ui/gfx/color_profile_mac_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #import <Cocoa/Cocoa.h>
8
7 #include "base/mac/mac_util.h" 9 #include "base/mac/mac_util.h"
10 #include "ui/gfx/mac/coordinate_conversion.h"
11
12 namespace {
13
14 NSScreen* GetNSScreenFromBounds(const gfx::Rect& bounds) {
15 NSScreen* screen = nil;
16 int overlap = 0;
17
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 }
27
28 return screen;
29 }
30
31 } // namespace
8 32
9 namespace gfx { 33 namespace gfx {
10 34
11 bool GetDisplayColorProfile(const gfx::Rect& bounds, 35 bool GetDisplayColorProfile(const gfx::Rect& bounds,
12 std::vector<char>* profile) { 36 std::vector<char>* profile) {
13 if (bounds.IsEmpty()) 37 DCHECK(profile->empty());
38
39 NSScreen* screen = GetNSScreenFromBounds(bounds);
40 if (!screen || bounds.IsEmpty())
14 return false; 41 return false;
15 // TODO(noel): implement. 42 NSColorSpace* color_space = [screen colorSpace];
16 return false; 43 if (!color_space)
44 return false;
45
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);
sky 2014/10/10 02:36:10 I'm curious, what does this get mapped to? Does da
Noel Gordon 2014/10/12 01:31:00 I believe that plain-old-data pointers satisfy the
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
OLDNEW
« no previous file with comments | « ui/gfx/color_profile.h ('k') | ui/gfx/color_profile_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698