summaryrefslogtreecommitdiff
path: root/Tools/DumpRenderTree/chromium/LayoutTestHelper.mm
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/DumpRenderTree/chromium/LayoutTestHelper.mm')
-rw-r--r--Tools/DumpRenderTree/chromium/LayoutTestHelper.mm99
1 files changed, 94 insertions, 5 deletions
diff --git a/Tools/DumpRenderTree/chromium/LayoutTestHelper.mm b/Tools/DumpRenderTree/chromium/LayoutTestHelper.mm
index 978f74c06..5ecac6692 100644
--- a/Tools/DumpRenderTree/chromium/LayoutTestHelper.mm
+++ b/Tools/DumpRenderTree/chromium/LayoutTestHelper.mm
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2012 Apple Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -40,13 +41,97 @@
namespace {
+#if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
+
+CFURLRef sUserColorProfileURL;
+
+void installLayoutTestColorProfile()
+{
+ // To make sure we get consistent colors (not dependent on the chosen color
+ // space of the main display), we force the generic RGB color profile.
+ // This causes a change the user can see.
+
+ CFUUIDRef mainDisplayID = CGDisplayCreateUUIDFromDisplayID(CGMainDisplayID());
+
+ if (!sUserColorProfileURL) {
+ CFDictionaryRef deviceInfo = ColorSyncDeviceCopyDeviceInfo(kColorSyncDisplayDeviceClass, mainDisplayID);
+
+ if (!deviceInfo) {
+ NSLog(@"No display attached to system; not setting main display's color profile.");
+ CFRelease(mainDisplayID);
+ return;
+ }
+
+ CFDictionaryRef profileInfo = (CFDictionaryRef)CFDictionaryGetValue(deviceInfo, kColorSyncCustomProfiles);
+ if (profileInfo) {
+ sUserColorProfileURL = (CFURLRef)CFDictionaryGetValue(profileInfo, CFSTR("1"));
+ CFRetain(sUserColorProfileURL);
+ } else {
+ profileInfo = (CFDictionaryRef)CFDictionaryGetValue(deviceInfo, kColorSyncFactoryProfiles);
+ CFDictionaryRef factoryProfile = (CFDictionaryRef)CFDictionaryGetValue(profileInfo, CFSTR("1"));
+ sUserColorProfileURL = (CFURLRef)CFDictionaryGetValue(factoryProfile, kColorSyncDeviceProfileURL);
+ CFRetain(sUserColorProfileURL);
+ }
+
+ CFRelease(deviceInfo);
+ }
+
+ ColorSyncProfileRef genericRGBProfile = ColorSyncProfileCreateWithName(kColorSyncGenericRGBProfile);
+ CFErrorRef error;
+ CFURLRef profileURL = ColorSyncProfileGetURL(genericRGBProfile, &error);
+ if (!profileURL) {
+ NSLog(@"Failed to get URL of Generic RGB color profile! Many pixel tests may fail as a result. Error: %@", error);
+
+ if (sUserColorProfileURL) {
+ CFRelease(sUserColorProfileURL);
+ sUserColorProfileURL = 0;
+ }
+
+ CFRelease(genericRGBProfile);
+ CFRelease(mainDisplayID);
+ return;
+ }
+
+ CFMutableDictionaryRef profileInfo = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+ CFDictionarySetValue(profileInfo, kColorSyncDeviceDefaultProfileID, profileURL);
+
+ if (!ColorSyncDeviceSetCustomProfiles(kColorSyncDisplayDeviceClass, mainDisplayID, profileInfo)) {
+ NSLog(@"Failed to set color profile for main display! Many pixel tests may fail as a result.");
+
+ if (sUserColorProfileURL) {
+ CFRelease(sUserColorProfileURL);
+ sUserColorProfileURL = 0;
+ }
+ }
+
+ CFRelease(profileInfo);
+ CFRelease(genericRGBProfile);
+ CFRelease(mainDisplayID);
+}
+
+void restoreUserColorProfile(void)
+{
+ // This is used as a signal handler, and thus the calls into ColorSync are unsafe.
+ // But we might as well try to restore the user's color profile, we're going down anyway...
+
+ if (!sUserColorProfileURL)
+ return;
+
+ CFUUIDRef mainDisplayID = CGDisplayCreateUUIDFromDisplayID(CGMainDisplayID());
+ CFMutableDictionaryRef profileInfo = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+ CFDictionarySetValue(profileInfo, kColorSyncDeviceDefaultProfileID, sUserColorProfileURL);
+ ColorSyncDeviceSetCustomProfiles(kColorSyncDisplayDeviceClass, mainDisplayID, profileInfo);
+ CFRelease(mainDisplayID);
+ CFRelease(profileInfo);
+}
+
+#else // For Snow Leopard and before, use older CM* API.
+
const char colorProfilePath[] = "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc";
CMProfileLocation initialColorProfileLocation; // The locType field is initialized to 0 which is the same as cmNoProfileBase.
-} // namespace
-
-static void installLayoutTestColorProfile()
+void installLayoutTestColorProfile()
{
// To make sure we get consistent colors (not dependent on the Main display),
// we force the generic rgb color profile. This cases a change the user can
@@ -76,7 +161,7 @@ static void installLayoutTestColorProfile()
}
}
-static void restoreUserColorProfile(void)
+void restoreUserColorProfile(void)
{
// This is used as a signal handler, and thus the calls into ColorSync are unsafe.
// But we might as well try to restore the user's color profile, we're going down anyway...
@@ -90,13 +175,17 @@ static void restoreUserColorProfile(void)
}
}
-static void simpleSignalHandler(int sig)
+#endif
+
+void simpleSignalHandler(int sig)
{
// Try to restore the color profile and try to go down cleanly
restoreUserColorProfile();
exit(128 + sig);
}
+} // namespace
+
int main(int argc, char* argv[])
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];