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

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

Issue 2092533002: Clean up gfx::ColorProfile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git cl try Created 4 years, 5 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.cc ('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> 7 #import <Cocoa/Cocoa.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
11 #include "base/mac/scoped_cftyperef.h" 11 #include "base/mac/scoped_cftyperef.h"
12 #include "ui/gfx/mac/coordinate_conversion.h" 12 #include "ui/gfx/mac/coordinate_conversion.h"
13 13
14 namespace {
15
16 NSScreen* GetNSScreenFromBounds(const gfx::Rect& bounds) {
17 NSScreen* screen = nil;
18 int overlap = 0;
19
20 for (NSScreen* monitor in [NSScreen screens]) {
21 gfx::Rect monitor_rect = gfx::ScreenRectFromNSRect([monitor frame]);
22 gfx::Rect overlap_rect = gfx::IntersectRects(monitor_rect, bounds);
23 int overlap_size = overlap_rect.width() * overlap_rect.height();
24 if (overlap_size > overlap) {
25 overlap = overlap_size;
26 screen = monitor;
27 }
28 }
29
30 return screen;
31 }
32
33 } // namespace
34
35 namespace gfx { 14 namespace gfx {
36 15
37 bool GetDisplayColorProfile(const gfx::Rect& bounds, 16 // static
38 std::vector<char>* profile) { 17 ColorProfile ColorProfile::GetFromBestMonitor() {
39 DCHECK(profile->empty()); 18 ColorProfile profile;
40
41 NSScreen* screen = GetNSScreenFromBounds(bounds);
42 if (!screen || bounds.IsEmpty())
43 return false;
44 NSColorSpace* color_space = [screen colorSpace];
45 if (!color_space)
46 return false;
47
48 if ([color_space isEqual:[NSColorSpace sRGBColorSpace]])
49 return true;
50 NSData* profile_data = [color_space ICCProfileData];
51 const char* data = static_cast<const char*>([profile_data bytes]);
52 size_t length = [profile_data length];
53 if (data && !gfx::InvalidColorProfileLength(length))
54 profile->assign(data, data + length);
55 return true;
56 }
57
58 GFX_EXPORT bool GetDisplayColorProfile(gfx::NativeWindow window,
59 std::vector<char>* profile) {
60 DCHECK(profile->empty());
61
62 NSColorSpace* color_space = [window colorSpace];
63 if (!color_space || NSIsEmptyRect([window frame]))
64 return false;
65
66 if ([color_space isEqual:[NSColorSpace sRGBColorSpace]])
67 return true;
68 NSData* profile_data = [color_space ICCProfileData];
69 const char* data = static_cast<const char*>([profile_data bytes]);
70 size_t length = [profile_data length];
71 if (data && !gfx::InvalidColorProfileLength(length))
72 profile->assign(data, data + length);
73 return true;
74 }
75
76 void ReadColorProfile(std::vector<char>* profile) {
77 CGColorSpaceRef monitor_color_space(base::mac::GetSystemColorSpace()); 19 CGColorSpaceRef monitor_color_space(base::mac::GetSystemColorSpace());
78 base::ScopedCFTypeRef<CFDataRef> icc_profile( 20 base::ScopedCFTypeRef<CFDataRef> icc_profile(
79 CGColorSpaceCopyICCProfile(monitor_color_space)); 21 CGColorSpaceCopyICCProfile(monitor_color_space));
80 if (!icc_profile) 22 if (!icc_profile)
81 return; 23 return profile;
82 size_t length = CFDataGetLength(icc_profile); 24 size_t length = CFDataGetLength(icc_profile);
83 if (gfx::InvalidColorProfileLength(length)) 25 if (!IsValidProfileLength(length))
84 return; 26 return profile;
85 const unsigned char* data = CFDataGetBytePtr(icc_profile); 27 const unsigned char* data = CFDataGetBytePtr(icc_profile);
86 profile->assign(data, data + length); 28 profile.profile_.assign(data, data + length);
29 return profile;
87 } 30 }
88 31
89 } // namespace gfx 32 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/color_profile.cc ('k') | ui/gfx/color_profile_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698