| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 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 #import <AppKit/AppKit.h> | |
| 6 #include <signal.h> | |
| 7 #include <stdio.h> | |
| 8 #include <stdlib.h> | |
| 9 | |
| 10 // This is a simple helper app that changes the color sync profile to the | |
| 11 // generic profile and back when done. This program is managed by the layout | |
| 12 // test script, so it can do the job for multiple test shells while they are | |
| 13 // running layout tests. | |
| 14 | |
| 15 static CMProfileRef gUsersColorProfile = NULL; | |
| 16 | |
| 17 static void SaveCurrentColorProfile(void) { | |
| 18 CGDirectDisplayID displayID = CGMainDisplayID(); | |
| 19 CMProfileRef previousProfile; | |
| 20 CMError error = CMGetProfileByAVID((UInt32)displayID, &previousProfile); | |
| 21 if (error) { | |
| 22 NSLog(@"failed to get the current color profile, pixmaps won't match. " | |
| 23 @"Error: %d", (int)error); | |
| 24 } else { | |
| 25 gUsersColorProfile = previousProfile; | |
| 26 } | |
| 27 } | |
| 28 | |
| 29 static void InstallLayoutTestColorProfile(void) { | |
| 30 // To make sure we get consistent colors (not dependent on the Main display), | |
| 31 // we force the generic rgb color profile. This cases a change the user can | |
| 32 // see. | |
| 33 | |
| 34 CGDirectDisplayID displayID = CGMainDisplayID(); | |
| 35 NSColorSpace *genericSpace = [NSColorSpace genericRGBColorSpace]; | |
| 36 CMProfileRef genericProfile = (CMProfileRef)[genericSpace colorSyncProfile]; | |
| 37 CMError error = CMSetProfileByAVID((UInt32)displayID, genericProfile); | |
| 38 if (error) { | |
| 39 NSLog(@"failed install the generic color profile, pixmaps won't match. " | |
| 40 @"Error: %d", (int)error); | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 static void RestoreUsersColorProfile(void) { | |
| 45 if (gUsersColorProfile) { | |
| 46 CGDirectDisplayID displayID = CGMainDisplayID(); | |
| 47 CMError error = CMSetProfileByAVID((UInt32)displayID, gUsersColorProfile); | |
| 48 CMCloseProfile(gUsersColorProfile); | |
| 49 if (error) { | |
| 50 NSLog(@"Failed to restore color profile, use System Preferences -> " | |
| 51 @"Displays -> Color to reset. Error: %d", (int)error); | |
| 52 } | |
| 53 gUsersColorProfile = NULL; | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 static void SimpleSignalHandler(int sig) { | |
| 58 // Try to restore the color profile and try to go down cleanly | |
| 59 RestoreUsersColorProfile(); | |
| 60 exit(128 + sig); | |
| 61 } | |
| 62 | |
| 63 int main(int argc, char *argv[]) { | |
| 64 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
| 65 | |
| 66 // Hooks the ways we might get told to clean up... | |
| 67 signal(SIGINT, SimpleSignalHandler); | |
| 68 signal(SIGHUP, SimpleSignalHandler); | |
| 69 signal(SIGTERM, SimpleSignalHandler); | |
| 70 | |
| 71 // Save off the current profile, and then install the layout test profile. | |
| 72 SaveCurrentColorProfile(); | |
| 73 InstallLayoutTestColorProfile(); | |
| 74 | |
| 75 // Let the script know we're ready | |
| 76 printf("ready\n"); | |
| 77 fflush(stdout); | |
| 78 | |
| 79 // Wait for any key (or signal) | |
| 80 getchar(); | |
| 81 | |
| 82 // Restore the profile | |
| 83 RestoreUsersColorProfile(); | |
| 84 | |
| 85 [pool release]; | |
| 86 return 0; | |
| 87 } | |
| OLD | NEW |