OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 /* | |
6 * Copyright (C) 2010 Google Inc. All rights reserved. | |
7 * Copyright (C) 2012 Apple Inc. | |
8 * | |
9 * Redistribution and use in source and binary forms, with or without | |
10 * modification, are permitted provided that the following conditions are | |
11 * met: | |
12 * | |
13 * * Redistributions of source code must retain the above copyright | |
14 * notice, this list of conditions and the following disclaimer. | |
15 * * Redistributions in binary form must reproduce the above | |
16 * copyright notice, this list of conditions and the following disclaimer | |
17 * in the documentation and/or other materials provided with the | |
18 * distribution. | |
19 * * Neither the name of Google Inc. nor the names of its | |
20 * contributors may be used to endorse or promote products derived from | |
21 * this software without specific prior written permission. | |
22 * | |
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
34 */ | |
35 | |
36 #import <AvailabilityMacros.h> | |
37 #import <AppKit/AppKit.h> | |
38 #include <signal.h> | |
39 #include <stdio.h> | |
40 #include <stdlib.h> | |
41 | |
42 // This is a simple helper app that changes the color sync profile to the | |
43 // generic profile and back when done. This program is managed by the layout | |
44 // test script, so it can do the job for multiple DumpRenderTree while they are | |
45 // running layout tests. | |
46 | |
47 namespace { | |
48 | |
49 #if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_V ERSION_10_7 | |
jochen (gone - plz use gerrit)
2014/01/03 14:08:58
nit. wrap at 80c
tfarina
2014/01/03 22:08:52
Done.
| |
50 | |
51 CFURLRef sUserColorProfileURL; | |
jochen (gone - plz use gerrit)
2014/01/03 14:08:58
nit. user_color_profile_url
tfarina
2014/01/03 22:08:52
Done.
| |
52 | |
53 void installLayoutTestColorProfile() { | |
jochen (gone - plz use gerrit)
2014/01/03 14:08:58
InstallLayout... (with a capital I)
tfarina
2014/01/03 22:08:52
Done.
| |
54 // To make sure we get consistent colors (not dependent on the chosen color | |
55 // space of the main display), we force the generic RGB color profile. | |
56 // This causes a change the user can see. | |
57 | |
58 CFUUIDRef mainDisplayID = CGDisplayCreateUUIDFromDisplayID(CGMainDisplayID()); | |
jochen (gone - plz use gerrit)
2014/01/03 14:08:58
main_display_id
tfarina
2014/01/03 22:08:52
Done.
| |
59 | |
60 if (!sUserColorProfileURL) { | |
61 CFDictionaryRef deviceInfo = ColorSyncDeviceCopyDeviceInfo( | |
jochen (gone - plz use gerrit)
2014/01/03 14:08:58
device_info
tfarina
2014/01/03 22:08:52
Done.
| |
62 kColorSyncDisplayDeviceClass, mainDisplayID); | |
63 | |
64 if (!deviceInfo) { | |
65 NSLog(@"No display attached to system; not setting main display's color " | |
66 "profile."); | |
67 CFRelease(mainDisplayID); | |
68 return; | |
69 } | |
70 | |
71 CFDictionaryRef profileInfo = (CFDictionaryRef)CFDictionaryGetValue( | |
jochen (gone - plz use gerrit)
2014/01/03 14:08:58
profile_info
tfarina
2014/01/03 22:08:52
Done.
| |
72 deviceInfo, kColorSyncCustomProfiles); | |
73 if (profileInfo) { | |
74 sUserColorProfileURL = | |
75 (CFURLRef)CFDictionaryGetValue(profileInfo, CFSTR("1")); | |
76 CFRetain(sUserColorProfileURL); | |
77 } else { | |
78 profileInfo = (CFDictionaryRef)CFDictionaryGetValue( | |
79 deviceInfo, kColorSyncFactoryProfiles); | |
80 CFDictionaryRef factoryProfile = | |
jochen (gone - plz use gerrit)
2014/01/03 14:08:58
factory_profile
tfarina
2014/01/03 22:08:52
Done.
| |
81 (CFDictionaryRef)CFDictionaryGetValue(profileInfo, CFSTR("1")); | |
82 sUserColorProfileURL = (CFURLRef)CFDictionaryGetValue( | |
83 factoryProfile, kColorSyncDeviceProfileURL); | |
84 CFRetain(sUserColorProfileURL); | |
85 } | |
86 | |
87 CFRelease(deviceInfo); | |
88 } | |
89 | |
90 ColorSyncProfileRef genericRGBProfile = | |
jochen (gone - plz use gerrit)
2014/01/03 14:08:58
generic_rgb_profile
tfarina
2014/01/03 22:08:52
Done.
| |
91 ColorSyncProfileCreateWithName(kColorSyncGenericRGBProfile); | |
92 CFErrorRef error; | |
93 CFURLRef profileURL = ColorSyncProfileGetURL(genericRGBProfile, &error); | |
jochen (gone - plz use gerrit)
2014/01/03 14:08:58
profile_url
tfarina
2014/01/03 22:08:52
Done.
| |
94 if (!profileURL) { | |
95 NSLog(@"Failed to get URL of Generic RGB color profile! Many pixel tests " | |
96 "may fail as a result. Error: %@", | |
97 error); | |
98 | |
99 if (sUserColorProfileURL) { | |
100 CFRelease(sUserColorProfileURL); | |
101 sUserColorProfileURL = 0; | |
102 } | |
103 | |
104 CFRelease(genericRGBProfile); | |
105 CFRelease(mainDisplayID); | |
106 return; | |
107 } | |
108 | |
109 CFMutableDictionaryRef profileInfo = | |
jochen (gone - plz use gerrit)
2014/01/03 14:08:58
profile_info
tfarina
2014/01/03 22:08:52
Done.
| |
110 CFDictionaryCreateMutable(kCFAllocatorDefault, | |
111 0, | |
112 &kCFTypeDictionaryKeyCallBacks, | |
113 &kCFTypeDictionaryValueCallBacks); | |
114 CFDictionarySetValue( | |
115 profileInfo, kColorSyncDeviceDefaultProfileID, profileURL); | |
116 | |
117 if (!ColorSyncDeviceSetCustomProfiles( | |
118 kColorSyncDisplayDeviceClass, mainDisplayID, profileInfo)) { | |
119 NSLog(@"Failed to set color profile for main display! Many pixel tests may " | |
120 "fail as a result."); | |
121 | |
122 if (sUserColorProfileURL) { | |
123 CFRelease(sUserColorProfileURL); | |
124 sUserColorProfileURL = 0; | |
125 } | |
126 } | |
127 | |
128 CFRelease(profileInfo); | |
129 CFRelease(genericRGBProfile); | |
130 CFRelease(mainDisplayID); | |
131 } | |
132 | |
133 void restoreUserColorProfile(void) { | |
jochen (gone - plz use gerrit)
2014/01/03 14:08:58
Restore... and only () instead of (void)
tfarina
2014/01/03 22:08:52
Done.
| |
134 // This is used as a signal handler, and thus the calls into ColorSync are | |
135 // unsafe. | |
136 // But we might as well try to restore the user's color profile, we're going | |
137 // down anyway... | |
138 | |
139 if (!sUserColorProfileURL) | |
140 return; | |
141 | |
142 CFUUIDRef mainDisplayID = CGDisplayCreateUUIDFromDisplayID(CGMainDisplayID()); | |
jochen (gone - plz use gerrit)
2014/01/03 14:08:58
main_display_id
tfarina
2014/01/03 22:08:52
Done.
| |
143 CFMutableDictionaryRef profileInfo = | |
jochen (gone - plz use gerrit)
2014/01/03 14:08:58
profile_info
tfarina
2014/01/03 22:08:52
Done.
| |
144 CFDictionaryCreateMutable(kCFAllocatorDefault, | |
145 0, | |
146 &kCFTypeDictionaryKeyCallBacks, | |
147 &kCFTypeDictionaryValueCallBacks); | |
148 CFDictionarySetValue( | |
149 profileInfo, kColorSyncDeviceDefaultProfileID, sUserColorProfileURL); | |
150 ColorSyncDeviceSetCustomProfiles( | |
151 kColorSyncDisplayDeviceClass, mainDisplayID, profileInfo); | |
152 CFRelease(mainDisplayID); | |
153 CFRelease(profileInfo); | |
154 } | |
155 | |
156 #else // For Snow Leopard and before, use older CM* API. | |
157 | |
158 const char colorProfilePath[] = | |
jochen (gone - plz use gerrit)
2014/01/03 14:08:58
color_profile_path
tfarina
2014/01/03 22:08:52
Done.
| |
159 "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"; | |
160 | |
161 CMProfileLocation initialColorProfileLocation; // The locType field is | |
jochen (gone - plz use gerrit)
2014/01/03 14:08:58
initial_color_profile_location. Can you put the co
tfarina
2014/01/03 22:08:52
Done.
| |
162 // initialized to 0 which is the | |
163 // same as cmNoProfileBase. | |
164 | |
165 void installLayoutTestColorProfile() { | |
jochen (gone - plz use gerrit)
2014/01/03 14:08:58
Install..
tfarina
2014/01/03 22:08:52
Done.
| |
166 // To make sure we get consistent colors (not dependent on the Main display), | |
167 // we force the generic rgb color profile. This cases a change the user can | |
168 // see. | |
169 const CMDeviceScope scope = {kCFPreferencesCurrentUser, | |
170 kCFPreferencesCurrentHost}; | |
171 | |
172 CMProfileRef profile = 0; | |
173 int error = | |
174 CMGetProfileByAVID((CMDisplayIDType)kCGDirectMainDisplay, &profile); | |
175 if (!error) { | |
176 UInt32 size = sizeof(initialColorProfileLocation); | |
177 error = NCMGetProfileLocation(profile, &initialColorProfileLocation, &size); | |
178 CMCloseProfile(profile); | |
179 } | |
180 if (error) { | |
181 NSLog(@"failed to get the current color profile, pixmaps won't match. " | |
182 "Error: %d", | |
183 (int)error); | |
184 initialColorProfileLocation.locType = cmNoProfileBase; | |
185 return; | |
186 } | |
187 | |
188 CMProfileLocation location; | |
189 location.locType = cmPathBasedProfile; | |
190 strncpy(location.u.pathLoc.path, | |
191 colorProfilePath, | |
192 sizeof(location.u.pathLoc.path)); | |
193 error = CMSetDeviceProfile(cmDisplayDeviceClass, | |
194 (CMDeviceID)kCGDirectMainDisplay, | |
195 &scope, | |
196 cmDefaultProfileID, | |
197 &location); | |
198 if (error) { | |
199 NSLog(@"failed install the generic color profile, pixmaps won't match. " | |
200 "Error: %d", | |
201 (int)error); | |
202 initialColorProfileLocation.locType = cmNoProfileBase; | |
203 } | |
204 } | |
205 | |
206 void restoreUserColorProfile(void) { | |
jochen (gone - plz use gerrit)
2014/01/03 14:08:58
Restore and no (void)
| |
207 // This is used as a signal handler, and thus the calls into ColorSync are | |
208 // unsafe. | |
209 // But we might as well try to restore the user's color profile, we're going | |
210 // down anyway... | |
211 if (initialColorProfileLocation.locType != cmNoProfileBase) { | |
212 const CMDeviceScope scope = {kCFPreferencesCurrentUser, | |
213 kCFPreferencesCurrentHost}; | |
214 int error = CMSetDeviceProfile(cmDisplayDeviceClass, | |
215 (CMDeviceID)kCGDirectMainDisplay, | |
216 &scope, | |
217 cmDefaultProfileID, | |
218 &initialColorProfileLocation); | |
219 if (error) { | |
220 NSLog(@"Failed to restore color profile, use System Preferences -> " | |
221 "Displays -> Color to reset. Error: %d", | |
222 (int)error); | |
223 } | |
224 initialColorProfileLocation.locType = cmNoProfileBase; | |
225 } | |
226 } | |
227 | |
228 #endif | |
229 | |
230 void simpleSignalHandler(int sig) { | |
jochen (gone - plz use gerrit)
2014/01/03 14:08:58
SimpleSignal..
| |
231 // Try to restore the color profile and try to go down cleanly | |
232 restoreUserColorProfile(); | |
233 exit(128 + sig); | |
234 } | |
235 | |
236 } // namespace | |
237 | |
238 int main(int argc, char* argv[]) { | |
239 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; | |
240 | |
241 // Hooks the ways we might get told to clean up... | |
242 signal(SIGINT, simpleSignalHandler); | |
243 signal(SIGHUP, simpleSignalHandler); | |
244 signal(SIGTERM, simpleSignalHandler); | |
245 | |
246 // Save off the current profile, and then install the layout test profile. | |
247 installLayoutTestColorProfile(); | |
248 | |
249 // Let the script know we're ready | |
250 printf("ready\n"); | |
251 fflush(stdout); | |
252 | |
253 // Wait for any key (or signal) | |
254 getchar(); | |
255 | |
256 // Restore the profile | |
257 restoreUserColorProfile(); | |
258 | |
259 [pool release]; | |
260 return 0; | |
261 } | |
OLD | NEW |