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

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: Change gfx::InvalidColorProfileLength test. 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/BUILD.gn ('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 #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
OLDNEW
« no previous file with comments | « ui/gfx/BUILD.gn ('k') | ui/gfx/color_profile_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698