Changeset 104745 in webkit


Ignore:
Timestamp:
Jan 11, 2012 2:10:18 PM (12 years ago)
Author:
jochen@chromium.org
Message:

[Chromium] mimic the (old) behavior of the mac port for (re)setting the color profile
https://bugs.webkit.org/show_bug.cgi?id=75618

Eventually, we should get away from setting the display's color profile, as the mac port is doing now.

Reviewed by Tony Chang.

  • DumpRenderTree/chromium/LayoutTestHelper.mm:

(installLayoutTestColorProfile):
(restoreUserColorProfile):
(main):

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r104740 r104745  
     12012-01-11  Jochen Eisinger  <jochen@chromium.org>
     2
     3        [Chromium] mimic the (old) behavior of the mac port for (re)setting the color profile
     4        https://bugs.webkit.org/show_bug.cgi?id=75618
     5
     6        Eventually, we should get away from setting the display's color profile, as the mac port is doing now.
     7
     8        Reviewed by Tony Chang.
     9
     10        * DumpRenderTree/chromium/LayoutTestHelper.mm:
     11        (installLayoutTestColorProfile):
     12        (restoreUserColorProfile):
     13        (main):
     14
    1152012-01-11  Dirk Pranke  <dpranke@chromium.org>
    216
  • trunk/Tools/DumpRenderTree/chromium/LayoutTestHelper.mm

    r57690 r104745  
    3939// running layout tests.
    4040
    41 static CMProfileRef userColorProfile = 0;
     41namespace {
    4242
    43 static void saveCurrentColorProfile()
    44 {
    45     CGDirectDisplayID displayID = CGMainDisplayID();
    46     CMProfileRef previousProfile;
    47     CMError error = CMGetProfileByAVID((UInt32)displayID, &previousProfile);
    48     if (error) {
    49         NSLog(@"failed to get the current color profile, pixmaps won't match. "
    50               @"Error: %d", (int)error);
    51     } else {
    52         userColorProfile = previousProfile;
    53     }
    54 }
     43const char colorProfilePath[] = "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc";
     44
     45CMProfileLocation initialColorProfileLocation; // The locType field is initialized to 0 which is the same as cmNoProfileBase.
     46
     47} // namespace
    5548
    5649static void installLayoutTestColorProfile()
     
    5952    // we force the generic rgb color profile.  This cases a change the user can
    6053    // see.
     54    const CMDeviceScope scope = { kCFPreferencesCurrentUser, kCFPreferencesCurrentHost };
    6155
    62     CGDirectDisplayID displayID = CGMainDisplayID();
    63     NSColorSpace* genericSpace = [NSColorSpace genericRGBColorSpace];
    64     CMProfileRef genericProfile = (CMProfileRef)[genericSpace colorSyncProfile];
    65     CMError error = CMSetProfileByAVID((UInt32)displayID, genericProfile);
     56    CMProfileRef profile = 0;
     57    int error = CMGetProfileByAVID((CMDisplayIDType)kCGDirectMainDisplay, &profile);
     58    if (!error) {
     59        UInt32 size = sizeof(initialColorProfileLocation);
     60        error = NCMGetProfileLocation(profile, &initialColorProfileLocation, &size);
     61        CMCloseProfile(profile);
     62    }
    6663    if (error) {
    67         NSLog(@"failed install the generic color profile, pixmaps won't match. "
    68               @"Error: %d", (int)error);
     64        NSLog(@"failed to get the current color profile, pixmaps won't match. Error: %d", (int)error);
     65        initialColorProfileLocation.locType = cmNoProfileBase;
     66        return;
     67    }
     68
     69    CMProfileLocation location;
     70    location.locType = cmPathBasedProfile;
     71    strncpy(location.u.pathLoc.path, colorProfilePath, sizeof(location.u.pathLoc.path));
     72    error = CMSetDeviceProfile(cmDisplayDeviceClass, (CMDeviceID)kCGDirectMainDisplay, &scope, cmDefaultProfileID, &location);
     73    if (error) {
     74        NSLog(@"failed install the generic color profile, pixmaps won't match. Error: %d", (int)error);
     75        initialColorProfileLocation.locType = cmNoProfileBase;
    6976    }
    7077}
     
    7279static void restoreUserColorProfile(void)
    7380{
    74     if (!userColorProfile)
    75         return;
    76     CGDirectDisplayID displayID = CGMainDisplayID();
    77     CMError error = CMSetProfileByAVID((UInt32)displayID, userColorProfile);
    78     CMCloseProfile(userColorProfile);
    79     if (error) {
    80         NSLog(@"Failed to restore color profile, use System Preferences -> "
    81               @"Displays -> Color to reset. Error: %d", (int)error);
     81    // This is used as a signal handler, and thus the calls into ColorSync are unsafe.
     82    // But we might as well try to restore the user's color profile, we're going down anyway...
     83    if (initialColorProfileLocation.locType != cmNoProfileBase) {
     84        const CMDeviceScope scope = { kCFPreferencesCurrentUser, kCFPreferencesCurrentHost };
     85        int error = CMSetDeviceProfile(cmDisplayDeviceClass, (CMDeviceID)kCGDirectMainDisplay, &scope, cmDefaultProfileID, &initialColorProfileLocation);
     86        if (error) {
     87            NSLog(@"Failed to restore color profile, use System Preferences -> Displays -> Color to reset. Error: %d", (int)error);
     88        }
     89        initialColorProfileLocation.locType = cmNoProfileBase;
    8290    }
    83     userColorProfile = 0;
    8491}
    8592
     
    101108
    102109    // Save off the current profile, and then install the layout test profile.
    103     saveCurrentColorProfile();
    104110    installLayoutTestColorProfile();
    105111
Note: See TracChangeset for help on using the changeset viewer.