Title: [225915] trunk/Source/WebCore
Revision
225915
Author
[email protected]
Date
2017-12-14 11:33:09 -0800 (Thu, 14 Dec 2017)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (225914 => 225915)


--- trunk/Source/WebCore/ChangeLog	2017-12-14 19:13:56 UTC (rev 225914)
+++ trunk/Source/WebCore/ChangeLog	2017-12-14 19:33:09 UTC (rev 225915)
@@ -1,3 +1,27 @@
+2017-12-14  Simon Fraser  <[email protected]>
+
+        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):
+
 2017-12-13  Keith Miller  <[email protected]>
 
         JSObjects should have a mask for loading indexed properties

Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp (225914 => 225915)


--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp	2017-12-14 19:13:56 UTC (rev 225914)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp	2017-12-14 19:33:09 UTC (rev 225915)
@@ -74,15 +74,20 @@
 
 CGColorSpaceRef sRGBColorSpaceRef()
 {
-    static CGColorSpaceRef sRGBSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
+    static CGColorSpaceRef sRGBColorSpace;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
+        sRGBColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
 #if PLATFORM(WIN)
-    // Out-of-date CG installations will not honor kCGColorSpaceSRGB. This logic avoids
-    // causing a crash under those conditions. Since the default color space in Windows
-    // is sRGB, this all works out nicely.
-    if (!sRGBSpace)
-        sRGBSpace = CGColorSpaceCreateDeviceRGB();
+        // Out-of-date CG installations will not honor kCGColorSpaceSRGB. This logic avoids
+        // causing a crash under those conditions. Since the default color space in Windows
+        // is sRGB, this all works out nicely.
+        // FIXME: Is this still needed? rdar://problem/15213515 was fixed.
+        if (!sRGBColorSpace)
+            sRGBColorSpace = CGColorSpaceCreateDeviceRGB();
 #endif // PLATFORM(WIN)
-    return sRGBSpace;
+    });
+    return sRGBColorSpace;
 }
 
 #if PLATFORM(WIN) || PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200)
@@ -89,38 +94,48 @@
 // See GraphicsContextCocoa for the pre-10.12 implementation.
 CGColorSpaceRef linearRGBColorSpaceRef()
 {
+    static CGColorSpaceRef linearRGBColorSpace;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
 #if PLATFORM(WIN)
-    // FIXME: Windows should be able to use linear sRGB, this is tracked by http://webkit.org/b/80000.
-    return CGColorSpaceCreateDeviceRGB();
+        // FIXME: Windows should be able to use linear sRGB, this is tracked by http://webkit.org/b/80000.
+        linearRGBColorSpace = sRGBColorSpaceRef();
 #else
-    static CGColorSpaceRef linearRGBSpace;
-    linearRGBSpace = CGColorSpaceCreateWithName(kCGColorSpaceLinearSRGB);
-    return linearRGBSpace;
+        linearRGBColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceLinearSRGB);
 #endif
+    });
+
+    return linearRGBColorSpace;
 }
 #endif
 
 CGColorSpaceRef extendedSRGBColorSpaceRef()
 {
-    static CGColorSpaceRef extendedSRGBSpace;
+    static CGColorSpaceRef extendedSRGBColorSpace;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
 #if PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200)
-    extendedSRGBSpace = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB);
+        extendedSRGBColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB);
 #endif
-    // If there is no support for exteneded sRGB, fall back to sRGB.
-    if (!extendedSRGBSpace)
-        extendedSRGBSpace = CGColorSpaceCreateDeviceRGB();
-    return extendedSRGBSpace;
+        // If there is no support for extended sRGB, fall back to sRGB.
+        if (!extendedSRGBColorSpace)
+            extendedSRGBColorSpace = sRGBColorSpaceRef();
+    });
+    return extendedSRGBColorSpace;
 }
 
 CGColorSpaceRef displayP3ColorSpaceRef()
 {
-    static CGColorSpaceRef displayP3Space;
+    static CGColorSpaceRef displayP3ColorSpace;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
 #if PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED > 101100)
-    displayP3Space = CGColorSpaceCreateWithName(kCGColorSpaceDisplayP3);
+        displayP3ColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceDisplayP3);
 #else
-    displayP3Space = sRGBColorSpaceRef();
+        displayP3ColorSpace = sRGBColorSpaceRef();
 #endif
-    return displayP3Space;
+    });
+    return displayP3ColorSpace;
 }
 
 static InterpolationQuality convertInterpolationQuality(CGInterpolationQuality quality)

Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextCocoa.mm (225914 => 225915)


--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextCocoa.mm	2017-12-14 19:13:56 UTC (rev 225914)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextCocoa.mm	2017-12-14 19:33:09 UTC (rev 225915)
@@ -368,25 +368,22 @@
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200
 CGColorSpaceRef linearRGBColorSpaceRef()
 {
-    static CGColorSpaceRef linearSRGBSpace = nullptr;
-
-    if (linearSRGBSpace)
-        return linearSRGBSpace;
-
-    RetainPtr<NSString> iccProfilePath = [[NSBundle bundleWithIdentifier:@"com.apple.WebCore"] pathForResource:@"linearSRGB" ofType:@"icc"];
-    RetainPtr<NSData> iccProfileData = adoptNS([[NSData alloc] initWithContentsOfFile:iccProfilePath.get()]);
-
-    if (iccProfileData)
+    static CGColorSpaceRef linearSRGBColorSpace;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
+        RetainPtr<NSString> iccProfilePath = [[NSBundle bundleWithIdentifier:@"com.apple.WebCore"] pathForResource:@"linearSRGB" ofType:@"icc"];
+        RetainPtr<NSData> iccProfileData = adoptNS([[NSData alloc] initWithContentsOfFile:iccProfilePath.get()]);
+        if (iccProfileData)
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
-        linearSRGBSpace = CGColorSpaceCreateWithICCProfile((CFDataRef)iccProfileData.get());
+            linearSRGBColorSpace = CGColorSpaceCreateWithICCProfile((CFDataRef)iccProfileData.get());
 #pragma clang diagnostic pop
 
-    // If we fail to load the linearized sRGB ICC profile, fall back to sRGB.
-    if (!linearSRGBSpace)
-        return sRGBColorSpaceRef();
-
-    return linearSRGBSpace;
+        // If we fail to load the linearized sRGB ICC profile, fall back to sRGB.
+        if (!linearSRGBColorSpace)
+            linearSRGBColorSpace = sRGBColorSpaceRef();
+    });
+    return linearSRGBColorSpace;
 }
 #endif
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to