Changeset 225915 in webkit


Ignore:
Timestamp:
Dec 14, 2017, 11:33:09 AM (7 years ago)
Author:
Simon Fraser
Message:

Remove ColorSpaceDeviceRGB and most users of the obsolete deviceRGB colorspace
https://bugs.webkit.org/show_bug.cgi?id=180689

Reviewed by Darin Adler.

Address issues noted by Darin in r225797:

Existing and new code mistakenly allocated colorspaces on every call, because
they didn't initialize the static variable on the first call. Avoid this mistake
by using dispatch_once() in these functions.

Fix a case where the extendedSRGBColorSpaceRef() fallback was returning deviceRGB
instead of sRGB.

  • platform/graphics/cg/GraphicsContextCG.cpp:

(WebCore::sRGBColorSpaceRef):
(WebCore::linearRGBColorSpaceRef):
(WebCore::extendedSRGBColorSpaceRef):
(WebCore::displayP3ColorSpaceRef):

  • platform/graphics/cocoa/GraphicsContextCocoa.mm:

(WebCore::linearRGBColorSpaceRef):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r225913 r225915  
     12017-12-14  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Remove ColorSpaceDeviceRGB and most users of the obsolete deviceRGB colorspace
     4        https://bugs.webkit.org/show_bug.cgi?id=180689
     5
     6        Reviewed by Darin Adler.
     7       
     8        Address issues noted by Darin in r225797:
     9       
     10        Existing and new code mistakenly allocated colorspaces on every call, because
     11        they didn't initialize the static variable on the first call. Avoid this mistake
     12        by using dispatch_once() in these functions.
     13
     14        Fix a case where the extendedSRGBColorSpaceRef() fallback was returning deviceRGB
     15        instead of sRGB.
     16
     17        * platform/graphics/cg/GraphicsContextCG.cpp:
     18        (WebCore::sRGBColorSpaceRef):
     19        (WebCore::linearRGBColorSpaceRef):
     20        (WebCore::extendedSRGBColorSpaceRef):
     21        (WebCore::displayP3ColorSpaceRef):
     22        * platform/graphics/cocoa/GraphicsContextCocoa.mm:
     23        (WebCore::linearRGBColorSpaceRef):
     24
    1252017-12-13  Keith Miller  <keith_miller@apple.com>
    226
  • trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp

    r225797 r225915  
    7575CGColorSpaceRef sRGBColorSpaceRef()
    7676{
    77     static CGColorSpaceRef sRGBSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
     77    static CGColorSpaceRef sRGBColorSpace;
     78    static dispatch_once_t onceToken;
     79    dispatch_once(&onceToken, ^{
     80        sRGBColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
    7881#if PLATFORM(WIN)
    79     // Out-of-date CG installations will not honor kCGColorSpaceSRGB. This logic avoids
    80     // causing a crash under those conditions. Since the default color space in Windows
    81     // is sRGB, this all works out nicely.
    82     if (!sRGBSpace)
    83         sRGBSpace = CGColorSpaceCreateDeviceRGB();
     82        // Out-of-date CG installations will not honor kCGColorSpaceSRGB. This logic avoids
     83        // causing a crash under those conditions. Since the default color space in Windows
     84        // is sRGB, this all works out nicely.
     85        // FIXME: Is this still needed? rdar://problem/15213515 was fixed.
     86        if (!sRGBColorSpace)
     87            sRGBColorSpace = CGColorSpaceCreateDeviceRGB();
    8488#endif // PLATFORM(WIN)
    85     return sRGBSpace;
     89    });
     90    return sRGBColorSpace;
    8691}
    8792
     
    9095CGColorSpaceRef linearRGBColorSpaceRef()
    9196{
     97    static CGColorSpaceRef linearRGBColorSpace;
     98    static dispatch_once_t onceToken;
     99    dispatch_once(&onceToken, ^{
    92100#if PLATFORM(WIN)
    93     // FIXME: Windows should be able to use linear sRGB, this is tracked by http://webkit.org/b/80000.
    94     return CGColorSpaceCreateDeviceRGB();
     101        // FIXME: Windows should be able to use linear sRGB, this is tracked by http://webkit.org/b/80000.
     102        linearRGBColorSpace = sRGBColorSpaceRef();
    95103#else
    96     static CGColorSpaceRef linearRGBSpace;
    97     linearRGBSpace = CGColorSpaceCreateWithName(kCGColorSpaceLinearSRGB);
    98     return linearRGBSpace;
     104        linearRGBColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceLinearSRGB);
    99105#endif
     106    });
     107
     108    return linearRGBColorSpace;
    100109}
    101110#endif
     
    103112CGColorSpaceRef extendedSRGBColorSpaceRef()
    104113{
    105     static CGColorSpaceRef extendedSRGBSpace;
     114    static CGColorSpaceRef extendedSRGBColorSpace;
     115    static dispatch_once_t onceToken;
     116    dispatch_once(&onceToken, ^{
    106117#if PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200)
    107     extendedSRGBSpace = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB);
     118        extendedSRGBColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB);
    108119#endif
    109     // If there is no support for exteneded sRGB, fall back to sRGB.
    110     if (!extendedSRGBSpace)
    111         extendedSRGBSpace = CGColorSpaceCreateDeviceRGB();
    112     return extendedSRGBSpace;
     120        // If there is no support for extended sRGB, fall back to sRGB.
     121        if (!extendedSRGBColorSpace)
     122            extendedSRGBColorSpace = sRGBColorSpaceRef();
     123    });
     124    return extendedSRGBColorSpace;
    113125}
    114126
    115127CGColorSpaceRef displayP3ColorSpaceRef()
    116128{
    117     static CGColorSpaceRef displayP3Space;
     129    static CGColorSpaceRef displayP3ColorSpace;
     130    static dispatch_once_t onceToken;
     131    dispatch_once(&onceToken, ^{
    118132#if PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED > 101100)
    119     displayP3Space = CGColorSpaceCreateWithName(kCGColorSpaceDisplayP3);
     133        displayP3ColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceDisplayP3);
    120134#else
    121     displayP3Space = sRGBColorSpaceRef();
     135        displayP3ColorSpace = sRGBColorSpaceRef();
    122136#endif
    123     return displayP3Space;
     137    });
     138    return displayP3ColorSpace;
    124139}
    125140
  • trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextCocoa.mm

    r225797 r225915  
    369369CGColorSpaceRef linearRGBColorSpaceRef()
    370370{
    371     static CGColorSpaceRef linearSRGBSpace = nullptr;
    372 
    373     if (linearSRGBSpace)
    374         return linearSRGBSpace;
    375 
    376     RetainPtr<NSString> iccProfilePath = [[NSBundle bundleWithIdentifier:@"com.apple.WebCore"] pathForResource:@"linearSRGB" ofType:@"icc"];
    377     RetainPtr<NSData> iccProfileData = adoptNS([[NSData alloc] initWithContentsOfFile:iccProfilePath.get()]);
    378 
    379     if (iccProfileData)
     371    static CGColorSpaceRef linearSRGBColorSpace;
     372    static dispatch_once_t onceToken;
     373    dispatch_once(&onceToken, ^{
     374        RetainPtr<NSString> iccProfilePath = [[NSBundle bundleWithIdentifier:@"com.apple.WebCore"] pathForResource:@"linearSRGB" ofType:@"icc"];
     375        RetainPtr<NSData> iccProfileData = adoptNS([[NSData alloc] initWithContentsOfFile:iccProfilePath.get()]);
     376        if (iccProfileData)
    380377#pragma clang diagnostic push
    381378#pragma clang diagnostic ignored "-Wdeprecated-declarations"
    382         linearSRGBSpace = CGColorSpaceCreateWithICCProfile((CFDataRef)iccProfileData.get());
     379            linearSRGBColorSpace = CGColorSpaceCreateWithICCProfile((CFDataRef)iccProfileData.get());
    383380#pragma clang diagnostic pop
    384381
    385     // If we fail to load the linearized sRGB ICC profile, fall back to sRGB.
    386     if (!linearSRGBSpace)
    387         return sRGBColorSpaceRef();
    388 
    389     return linearSRGBSpace;
     382        // If we fail to load the linearized sRGB ICC profile, fall back to sRGB.
     383        if (!linearSRGBColorSpace)
     384            linearSRGBColorSpace = sRGBColorSpaceRef();
     385    });
     386    return linearSRGBColorSpace;
    390387}
    391388#endif
Note: See TracChangeset for help on using the changeset viewer.