[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

darin at apple.com darin at apple.com
Wed Dec 22 14:21:12 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 33f7529905aa247ec22afd9dfe7b534fa14386e9
Author: darin at apple.com <darin at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Oct 7 00:15:57 2010 +0000

    2010-10-06  Darin Adler  <darin at apple.com>
    
            Reviewed by Alexey Proskuryakov.
    
            Cache CGColor as we do NSColor
            https://bugs.webkit.org/show_bug.cgi?id=47226
    
            This fixes performance problems on certain web pages that use
            multiple colors. Once in the past we were using NSColor. Now that
            we are using CGColor, we need the same sort of caching that we have
            for NSColor.
    
            One example: <http://results.active.com/uploads/html/100759.html>.
    
            * WebCore.xcodeproj/project.pbxproj: Add GraphicsContextCG.h.
    
            * platform/graphics/Color.h: Replace createCGColor with cachedCGColor.
    
            * platform/graphics/cg/ColorCG.cpp:
            (WebCore::cachedCGColorSpace): Added.
            (WebCore::leakCGColor): Added.
            (WebCore::cachedCGColor): Added.
    
            * platform/graphics/cg/GraphicsContextCG.cpp:
            (WebCore::setCGFillColor): Use cachedCGColor.
            (WebCore::setCGStrokeColor): Ditto.
            (WebCore::GraphicsContext::fillRect): Ditto.
            (WebCore::GraphicsContext::setPlatformShadow): Ditto.
    
            * platform/graphics/cg/GraphicsContextCG.h: Added.
            * platform/graphics/cg/GraphicsContextPlatformPrivateCG.h:
            Moved the color space functions here.
    
            * platform/graphics/cg/ImageCG.cpp: Tweaked headers and formatting.
    
            * platform/graphics/mac/ColorMac.mm: Removed the createCGColor
            function.
    
            * platform/graphics/mac/GraphicsContextMac.mm:
            (WebCore::drawFocusRingToContext): Removed innappropriate use of
            RetainPtr for the arguments to this function.
            (WebCore::GraphicsContext::drawFocusRing): Use cachedCGColor.
    
            * platform/graphics/mac/GraphicsLayerCA.mm:
            (WebCore::setLayerBorderColor): Use cachedCGColor.
            (WebCore::setLayerBackgroundColor): Ditto.
            * platform/graphics/win/GraphicsContextCGWin.cpp:
            (WebCore::GraphicsContext::drawFocusRing): Ditto.
            * platform/graphics/win/GraphicsLayerCACF.cpp:
            (WebCore::setLayerBorderColor): Ditto.
            (WebCore::setLayerBackgroundColor): Ditto.
    
            * platform/graphics/win/WKCACFLayerRenderer.cpp:
            (WebCore::WKCACFLayerRenderer::WKCACFLayerRenderer): Use
            CGColorCreateGenericRGB for color used only for debugging.
            * platform/graphics/win/WebTiledLayer.cpp:
            (WebCore::WebTiledLayer::addTile): Ditto.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@69259 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 176644a..6aff4a7 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,61 @@
+2010-10-06  Darin Adler  <darin at apple.com>
+
+        Reviewed by Alexey Proskuryakov.
+
+        Cache CGColor as we do NSColor
+        https://bugs.webkit.org/show_bug.cgi?id=47226
+
+        This fixes performance problems on certain web pages that use
+        multiple colors. Once in the past we were using NSColor. Now that
+        we are using CGColor, we need the same sort of caching that we have
+        for NSColor.
+
+        One example: <http://results.active.com/uploads/html/100759.html>.
+
+        * WebCore.xcodeproj/project.pbxproj: Add GraphicsContextCG.h.
+
+        * platform/graphics/Color.h: Replace createCGColor with cachedCGColor.
+
+        * platform/graphics/cg/ColorCG.cpp:
+        (WebCore::cachedCGColorSpace): Added.
+        (WebCore::leakCGColor): Added. 
+        (WebCore::cachedCGColor): Added.
+
+        * platform/graphics/cg/GraphicsContextCG.cpp:
+        (WebCore::setCGFillColor): Use cachedCGColor.
+        (WebCore::setCGStrokeColor): Ditto.
+        (WebCore::GraphicsContext::fillRect): Ditto.
+        (WebCore::GraphicsContext::setPlatformShadow): Ditto.
+
+        * platform/graphics/cg/GraphicsContextCG.h: Added.
+        * platform/graphics/cg/GraphicsContextPlatformPrivateCG.h:
+        Moved the color space functions here.
+
+        * platform/graphics/cg/ImageCG.cpp: Tweaked headers and formatting.
+
+        * platform/graphics/mac/ColorMac.mm: Removed the createCGColor
+        function.
+
+        * platform/graphics/mac/GraphicsContextMac.mm:
+        (WebCore::drawFocusRingToContext): Removed innappropriate use of
+        RetainPtr for the arguments to this function.
+        (WebCore::GraphicsContext::drawFocusRing): Use cachedCGColor.
+
+        * platform/graphics/mac/GraphicsLayerCA.mm:
+        (WebCore::setLayerBorderColor): Use cachedCGColor.
+        (WebCore::setLayerBackgroundColor): Ditto.
+        * platform/graphics/win/GraphicsContextCGWin.cpp:
+        (WebCore::GraphicsContext::drawFocusRing): Ditto.
+        * platform/graphics/win/GraphicsLayerCACF.cpp:
+        (WebCore::setLayerBorderColor): Ditto.
+        (WebCore::setLayerBackgroundColor): Ditto.
+
+        * platform/graphics/win/WKCACFLayerRenderer.cpp:
+        (WebCore::WKCACFLayerRenderer::WKCACFLayerRenderer): Use
+        CGColorCreateGenericRGB for color used only for debugging.
+        * platform/graphics/win/WebTiledLayer.cpp:
+        (WebCore::WebTiledLayer::addTile): Ditto.
+
 2010-10-06  Peter Kasting  <pkasting at google.com>
 
         Reviewed by James Robinson
diff --git a/WebCore/WebCore.xcodeproj/project.pbxproj b/WebCore/WebCore.xcodeproj/project.pbxproj
index 8f1efe9..15c23ed 100644
--- a/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -2684,6 +2684,7 @@
 		933A14B90B7D1D5200A53FFD /* JSTextEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 933A14B70B7D1D5200A53FFD /* JSTextEvent.h */; };
 		93442C9E0D2B335C00338FF9 /* HTMLTableRowsCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 93442C9D0D2B335C00338FF9 /* HTMLTableRowsCollection.h */; };
 		93442CA00D2B336000338FF9 /* HTMLTableRowsCollection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93442C9F0D2B336000338FF9 /* HTMLTableRowsCollection.cpp */; };
+		934907E4125BBBC8007F23A0 /* GraphicsContextCG.h in Headers */ = {isa = PBXBuildFile; fileRef = 934907E3125BBBC8007F23A0 /* GraphicsContextCG.h */; };
 		934CC0E10ED39D6F00A658F2 /* ScriptValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 934CC0DF0ED39D6F00A658F2 /* ScriptValue.cpp */; };
 		934CC0E20ED39D6F00A658F2 /* ScriptValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 934CC0E00ED39D6F00A658F2 /* ScriptValue.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		934CC10A0EDB223900A658F2 /* ScriptSourceCode.h in Headers */ = {isa = PBXBuildFile; fileRef = 934CC1090EDB223900A658F2 /* ScriptSourceCode.h */; };
@@ -8734,6 +8735,7 @@
 		933A14B70B7D1D5200A53FFD /* JSTextEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTextEvent.h; sourceTree = "<group>"; };
 		93442C9D0D2B335C00338FF9 /* HTMLTableRowsCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLTableRowsCollection.h; sourceTree = "<group>"; };
 		93442C9F0D2B336000338FF9 /* HTMLTableRowsCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLTableRowsCollection.cpp; sourceTree = "<group>"; };
+		934907E3125BBBC8007F23A0 /* GraphicsContextCG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContextCG.h; sourceTree = "<group>"; };
 		934CC0DF0ED39D6F00A658F2 /* ScriptValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptValue.cpp; sourceTree = "<group>"; };
 		934CC0E00ED39D6F00A658F2 /* ScriptValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptValue.h; sourceTree = "<group>"; };
 		934CC1090EDB223900A658F2 /* ScriptSourceCode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptSourceCode.h; sourceTree = "<group>"; };
@@ -16343,6 +16345,7 @@
 				BC53C60A0DA56CF10021EB5D /* GradientCG.cpp */,
 				6E21C6C11126339900A7BE02 /* GraphicsContext3DCG.cpp */,
 				B2ED97700B1F55CE00257D0F /* GraphicsContextCG.cpp */,
+				934907E3125BBBC8007F23A0 /* GraphicsContextCG.h */,
 				A80D67070E9E9DEB00E420F0 /* GraphicsContextPlatformPrivateCG.h */,
 				B2A10B930B3818D700099AA4 /* ImageBufferCG.cpp */,
 				BCA979161215D055005C485C /* ImageBufferData.h */,
@@ -21051,6 +21054,7 @@
 				081668D4125603BF006F25DE /* SVGTextChunkBuilder.h in Headers */,
 				081668DA125603D5006F25DE /* SVGTextLayoutEngine.h in Headers */,
 				1AF8E11A1256592600230FF7 /* ProxyServer.h in Headers */,
+				934907E4125BBBC8007F23A0 /* GraphicsContextCG.h in Headers */,
 				893C48011248BD3A002B3D86 /* DirectoryEntrySync.h in Headers */,
 				893C48031248BD3A002B3D86 /* DirectoryReaderSync.h in Headers */,
 				893C48051248BD3A002B3D86 /* DOMFileSystemBase.h in Headers */,
@@ -21125,6 +21129,7 @@
 			isa = PBXProject;
 			buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
 			compatibilityVersion = "Xcode 2.4";
+			developmentRegion = English;
 			hasScannedForEncodings = 1;
 			knownRegions = (
 				English,
diff --git a/WebCore/platform/graphics/Color.h b/WebCore/platform/graphics/Color.h
index b4efcb5..2e4e962 100644
--- a/WebCore/platform/graphics/Color.h
+++ b/WebCore/platform/graphics/Color.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2003-6 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2003, 2004, 2005, 2006, 2010 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -31,6 +31,7 @@
 #include <wtf/unicode/Unicode.h>
 
 #if PLATFORM(CG)
+#include "ColorSpace.h"
 typedef struct CGColor* CGColorRef;
 #endif
 
@@ -169,7 +170,7 @@ Color colorFromPremultipliedARGB(unsigned);
 unsigned premultipliedARGBFromColor(const Color&);
 
 #if PLATFORM(CG)
-CGColorRef createCGColor(const Color&);
+CGColorRef cachedCGColor(const Color&, ColorSpace);
 #endif
 
 } // namespace WebCore
diff --git a/WebCore/platform/graphics/cg/ColorCG.cpp b/WebCore/platform/graphics/cg/ColorCG.cpp
index 6f05c38..57971dd 100644
--- a/WebCore/platform/graphics/cg/ColorCG.cpp
+++ b/WebCore/platform/graphics/cg/ColorCG.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc.  All rights reserved.
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,6 +28,7 @@
 
 #if PLATFORM(CG)
 
+#include "GraphicsContextCG.h"
 #include <wtf/Assertions.h>
 #include <wtf/RetainPtr.h>
 #include <ApplicationServices/ApplicationServices.h>
@@ -69,37 +70,72 @@ Color::Color(CGColorRef color)
     m_valid = true;
 }
 
-#if OS(WINDOWS)
+static inline CGColorSpaceRef cachedCGColorSpace(ColorSpace colorSpace)
+{
+    switch (colorSpace) {
+    case DeviceColorSpace:
+        return deviceRGBColorSpaceRef();
+    case sRGBColorSpace:
+        return sRGBColorSpaceRef();
+    }
+    ASSERT_NOT_REACHED();
+    return deviceRGBColorSpaceRef();
+}
 
-CGColorRef createCGColor(const Color& c)
+static CGColorRef leakCGColor(const Color& color, ColorSpace colorSpace)
 {
-    CGColorRef color = NULL;
-#ifdef OBSOLETE_COLORSYNC_API
-    CMProfileRef prof = NULL;
-    CMGetSystemProfile(&prof);
-    RetainPtr<CGColorSpaceRef> rgbSpace(AdoptCF, CGColorSpaceCreateWithPlatformColorSpace(prof));
-#else
-    ColorSyncProfileRef prof = ColorSyncProfileCreateWithDisplayID(0);
-    RetainPtr<CGColorSpaceRef> rgbSpace(AdoptCF, CGColorSpaceCreateWithPlatformColorSpace(const_cast<void*>(reinterpret_cast<const void*>(prof))));
-#endif
-
-    if (rgbSpace) {
-        CGFloat components[4] = { static_cast<CGFloat>(c.red()) / 255, static_cast<CGFloat>(c.green()) / 255,
-                                  static_cast<CGFloat>(c.blue()) / 255, static_cast<CGFloat>(c.alpha()) / 255 };
-        color = CGColorCreate(rgbSpace.get(), components);
+    CGFloat components[4];
+    color.getRGBA(components[0], components[1], components[2], components[3]);
+    return CGColorCreate(cachedCGColorSpace(colorSpace), components);
+}
+
+template<ColorSpace colorSpace> static CGColorRef cachedCGColor(const Color& color)
+{
+    switch (color.rgb()) {
+    case Color::transparent:
+        static CGColorRef transparentCGColor = leakCGColor(color, colorSpace);
+        return transparentCGColor;
+    case Color::black:
+        static CGColorRef blackCGColor = leakCGColor(color, colorSpace);
+        return blackCGColor;
+    case Color::white:
+        static CGColorRef whiteCGColor = leakCGColor(color, colorSpace);
+        return whiteCGColor;
+    }
+
+    ASSERT(color.rgb());
+
+    const size_t cacheSize = 32;
+    static RGBA32 cachedRGBAValues[cacheSize];
+    static RetainPtr<CGColorRef>* cachedCGColors = new RetainPtr<CGColorRef>[cacheSize];
+
+    for (size_t i = 0; i < cacheSize; ++i) {
+        if (cachedRGBAValues[i] == color.rgb())
+            return cachedCGColors[i].get();
     }
 
-#ifdef OBSOLETE_COLORSYNC_API
-    CMCloseProfile(prof);
-#else
-    if (prof)
-        CFRelease(prof);
-#endif
+    CGColorRef newCGColor = leakCGColor(color, colorSpace);
+
+    static size_t cursor;
+    cachedRGBAValues[cursor] = color.rgb();
+    cachedCGColors[cursor].adoptCF(newCGColor);
+    if (++cursor == cacheSize)
+        cursor = 0;
 
-    return color;
+    return newCGColor;
 }
 
-#endif // OS(WINDOWS)
+CGColorRef cachedCGColor(const Color& color, ColorSpace colorSpace)
+{
+    switch (colorSpace) {
+    case DeviceColorSpace:
+        return cachedCGColor<DeviceColorSpace>(color);
+    case sRGBColorSpace:
+        return cachedCGColor<sRGBColorSpace>(color);
+    }
+    ASSERT_NOT_REACHED();
+    return cachedCGColor(color, DeviceColorSpace);
+}
 
 }
 
diff --git a/WebCore/platform/graphics/cg/GraphicsContextCG.cpp b/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
index e5079dc..bd8e850 100644
--- a/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
+++ b/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
@@ -26,7 +26,7 @@
 
 #define _USE_MATH_DEFINES 1
 #include "config.h"
-#include "GraphicsContext.h"
+#include "GraphicsContextCG.h"
 
 #include "AffineTransform.h"
 #include "FloatConversion.h"
@@ -69,32 +69,14 @@ using namespace std;
 
 namespace WebCore {
 
-static CGColorRef createCGColorWithColorSpace(const Color& color, ColorSpace colorSpace)
-{
-    CGFloat components[4];
-    color.getRGBA(components[0], components[1], components[2], components[3]);
-
-    CGColorRef cgColor = 0;
-    if (colorSpace == sRGBColorSpace)
-        cgColor = CGColorCreate(sRGBColorSpaceRef(), components);
-    else
-        cgColor = CGColorCreate(deviceRGBColorSpaceRef(), components);
-
-    return cgColor;
-}
-
 static void setCGFillColor(CGContextRef context, const Color& color, ColorSpace colorSpace)
 {
-    CGColorRef cgColor = createCGColorWithColorSpace(color, colorSpace);
-    CGContextSetFillColorWithColor(context, cgColor);
-    CFRelease(cgColor);
+    CGContextSetFillColorWithColor(context, cachedCGColor(color, colorSpace));
 }
 
 static void setCGStrokeColor(CGContextRef context, const Color& color, ColorSpace colorSpace)
 {
-    CGColorRef cgColor = createCGColorWithColorSpace(color, colorSpace);
-    CGContextSetStrokeColorWithColor(context, cgColor);
-    CFRelease(cgColor);
+    CGContextSetStrokeColorWithColor(context, cachedCGColor(color, colorSpace));
 }
 
 static void setCGFillColorSpace(CGContextRef context, ColorSpace colorSpace)
@@ -659,17 +641,18 @@ void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, ColorS
 {
     if (paintingDisabled())
         return;
+
     CGContextRef context = platformContext();
     Color oldFillColor = fillColor();
     ColorSpace oldColorSpace = fillColorSpace();
 
     if (oldFillColor != color || oldColorSpace != colorSpace)
-      setCGFillColor(context, color, colorSpace);
+        setCGFillColor(context, color, colorSpace);
 
     CGContextFillRect(context, rect);
 
     if (oldFillColor != color || oldColorSpace != colorSpace)
-      setCGFillColor(context, oldFillColor, oldColorSpace);
+        setCGFillColor(context, oldFillColor, oldColorSpace);
 }
 
 void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color& color, ColorSpace colorSpace)
@@ -821,13 +804,8 @@ void GraphicsContext::setPlatformShadow(const FloatSize& offset, float blur, con
     // and we should therefore just use the default shadow color.
     if (!color.isValid())
         CGContextSetShadow(context, CGSizeMake(xOffset, yOffset), blurRadius);
-    else {
-        RetainPtr<CGColorRef> colorCG(AdoptCF, createCGColorWithColorSpace(color, colorSpace));
-        CGContextSetShadowWithColor(context,
-                                    CGSizeMake(xOffset, yOffset),
-                                    blurRadius,
-                                    colorCG.get());
-    }
+    else
+        CGContextSetShadowWithColor(context, CGSizeMake(xOffset, yOffset), blurRadius, cachedCGColor(color, colorSpace));
 }
 
 void GraphicsContext::clearPlatformShadow()
diff --git a/WebCore/platform/graphics/cg/GraphicsContextCG.h b/WebCore/platform/graphics/cg/GraphicsContextCG.h
new file mode 100644
index 0000000..b36cbf3
--- /dev/null
+++ b/WebCore/platform/graphics/cg/GraphicsContextCG.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2006, 2007, 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef GraphicsContextCG_h
+#define GraphicsContextCG_h
+
+#include "GraphicsContext.h"
+
+typedef struct CGColorSpace *CGColorSpaceRef;
+
+namespace WebCore {
+
+CGColorSpaceRef deviceRGBColorSpaceRef();
+CGColorSpaceRef sRGBColorSpaceRef();
+
+}
+
+#endif
diff --git a/WebCore/platform/graphics/cg/GraphicsContextPlatformPrivateCG.h b/WebCore/platform/graphics/cg/GraphicsContextPlatformPrivateCG.h
index aac4f45..1d0a99f 100644
--- a/WebCore/platform/graphics/cg/GraphicsContextPlatformPrivateCG.h
+++ b/WebCore/platform/graphics/cg/GraphicsContextPlatformPrivateCG.h
@@ -28,12 +28,6 @@
 
 namespace WebCore {
 
-// FIXME: This would be in GraphicsContextCG.h if that existed.
-CGColorSpaceRef deviceRGBColorSpaceRef();
-
-// FIXME: This would be in GraphicsContextCG.h if that existed.
-CGColorSpaceRef sRGBColorSpaceRef();
-
 class GraphicsContextPlatformPrivate {
 public:
     GraphicsContextPlatformPrivate(CGContextRef cgContext)
diff --git a/WebCore/platform/graphics/cg/ImageCG.cpp b/WebCore/platform/graphics/cg/ImageCG.cpp
index 70a80a0..9de516e 100644
--- a/WebCore/platform/graphics/cg/ImageCG.cpp
+++ b/WebCore/platform/graphics/cg/ImageCG.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2004, 2005, 2006 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -31,8 +31,7 @@
 #include "AffineTransform.h"
 #include "FloatConversion.h"
 #include "FloatRect.h"
-#include "GraphicsContext.h"
-#include "GraphicsContextPlatformPrivateCG.h"
+#include "GraphicsContextCG.h"
 #include "ImageObserver.h"
 #include "PDFDocumentImage.h"
 #include "PlatformString.h"
@@ -141,8 +140,7 @@ static RetainPtr<CGImageRef> imageWithColorSpace(CGImageRef originalImage, Color
     case DeviceColorSpace:
         return originalImage;
     case sRGBColorSpace:
-        return RetainPtr<CGImageRef>(AdoptCF, CGImageCreateCopyWithColorSpace(originalImage, 
-            sRGBColorSpaceRef()));
+        return RetainPtr<CGImageRef>(AdoptCF, CGImageCreateCopyWithColorSpace(originalImage, sRGBColorSpaceRef()));
     }
 
     ASSERT_NOT_REACHED();
diff --git a/WebCore/platform/graphics/mac/ColorMac.mm b/WebCore/platform/graphics/mac/ColorMac.mm
index c8ea9b1..07d6353 100644
--- a/WebCore/platform/graphics/mac/ColorMac.mm
+++ b/WebCore/platform/graphics/mac/ColorMac.mm
@@ -88,14 +88,15 @@ NSColor *nsColor(const Color& color)
             static unsigned cachedRGBAValues[cacheSize];
             static RetainPtr<NSColor>* cachedColors = new RetainPtr<NSColor>[cacheSize];
 
-            for (int i = 0; i != cacheSize; ++i)
+            for (int i = 0; i != cacheSize; ++i) {
                 if (cachedRGBAValues[i] == c)
                     return cachedColors[i].get();
+            }
 
             NSColor *result = [NSColor colorWithDeviceRed:static_cast<CGFloat>(color.red()) / 255
                                                     green:static_cast<CGFloat>(color.green()) / 255
                                                      blue:static_cast<CGFloat>(color.blue()) / 255
-                                                    alpha:static_cast<CGFloat>(color.alpha()) /255];
+                                                    alpha:static_cast<CGFloat>(color.alpha()) / 255];
 
             static int cursor;
             cachedRGBAValues[cursor] = c;
@@ -107,24 +108,5 @@ NSColor *nsColor(const Color& color)
     }
 }
 
-static CGColorRef CGColorFromNSColor(NSColor *color)
-{
-    // This needs to always use device colorspace so it can de-calibrate the color for
-    // CGColor to possibly recalibrate it.
-    CGFloat components[4];
-    NSColor *deviceColor = [color colorUsingColorSpaceName:NSDeviceRGBColorSpace];
-    [deviceColor getRed:&components[0] green:&components[1] blue:&components[2] alpha:&components[3]];
-    static CGColorSpaceRef deviceRGBColorSpace = CGColorSpaceCreateDeviceRGB();
-    CGColorRef cgColor = CGColorCreate(deviceRGBColorSpace, components);
-    return cgColor;
-}
-
-CGColorRef createCGColor(const Color& c)
-{
-    // We could directly create a CGColor here, but that would
-    // skip any RGB caching the nsColor method does. A direct 
-    // creation could be investigated for a possible performance win.
-    return CGColorFromNSColor(nsColor(c));
-}
 
 } // namespace WebCore
diff --git a/WebCore/platform/graphics/mac/GraphicsContextMac.mm b/WebCore/platform/graphics/mac/GraphicsContextMac.mm
index f3301d8..2c4012e 100644
--- a/WebCore/platform/graphics/mac/GraphicsContextMac.mm
+++ b/WebCore/platform/graphics/mac/GraphicsContextMac.mm
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2003, 2004, 2005, 2006, 2010 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -43,14 +43,14 @@ namespace WebCore {
 // calls in this file are all exception-safe, so we don't block
 // exceptions for those.
 
-static void drawFocusRingToContext(CGContextRef context, RetainPtr<CGPathRef> focusRingPath, RetainPtr<CGColorRef> colorRef, int radius)
+static void drawFocusRingToContext(CGContextRef context, CGPathRef focusRingPath, CGColorRef color, int radius)
 {
 #ifdef BUILDING_ON_TIGER
     CGContextBeginTransparencyLayer(context, 0);
 #endif
     CGContextBeginPath(context);
-    CGContextAddPath(context, focusRingPath.get());
-    wkDrawFocusRing(context, colorRef.get(), radius);
+    CGContextAddPath(context, focusRingPath);
+    wkDrawFocusRing(context, color, radius);
 #ifdef BUILDING_ON_TIGER
     CGContextEndTransparencyLayer(context);
 #endif
@@ -63,16 +63,14 @@ void GraphicsContext::drawFocusRing(const Vector<Path>& paths, int width, int of
     
     int radius = (width - 1) / 2;
     offset += radius;
-    RetainPtr<CGColorRef> colorRef;
-    if (color.isValid())
-        colorRef.adoptCF(createCGColor(color));
-    
+    CGColorRef colorRef = color.isValid() ? cachedCGColor(color, DeviceColorSpace) : 0;
+
     RetainPtr<CGMutablePathRef> focusRingPath(AdoptCF, CGPathCreateMutable());
     unsigned pathCount = paths.size();
     for (unsigned i = 0; i < pathCount; i++)
         CGPathAddPath(focusRingPath.get(), 0, paths[i].platformPath());
     
-    drawFocusRingToContext(platformContext(), focusRingPath, colorRef, radius);
+    drawFocusRingToContext(platformContext(), focusRingPath.get(), colorRef, radius);
 }    
     
 void GraphicsContext::drawFocusRing(const Vector<IntRect>& rects, int width, int offset, const Color& color)
@@ -82,16 +80,14 @@ void GraphicsContext::drawFocusRing(const Vector<IntRect>& rects, int width, int
 
     int radius = (width - 1) / 2;
     offset += radius;
-    RetainPtr<CGColorRef> colorRef;
-    if (color.isValid())
-        colorRef.adoptCF(createCGColor(color));
+    CGColorRef colorRef = color.isValid() ? cachedCGColor(color, DeviceColorSpace) : 0;
 
     RetainPtr<CGMutablePathRef> focusRingPath(AdoptCF, CGPathCreateMutable());
     unsigned rectCount = rects.size();
     for (unsigned i = 0; i < rectCount; i++)
         CGPathAddRect(focusRingPath.get(), 0, CGRectInset(rects[i], -offset, -offset));
 
-    drawFocusRingToContext(platformContext(), focusRingPath, colorRef, radius);
+    drawFocusRingToContext(platformContext(), focusRingPath.get(), colorRef, radius);
 }
 
 #ifdef BUILDING_ON_TIGER // Post-Tiger's setCompositeOperation() is defined in GraphicsContextCG.cpp.
diff --git a/WebCore/platform/graphics/mac/GraphicsLayerCA.mm b/WebCore/platform/graphics/mac/GraphicsLayerCA.mm
index d4cd851..76d6a3b 100644
--- a/WebCore/platform/graphics/mac/GraphicsLayerCA.mm
+++ b/WebCore/platform/graphics/mac/GraphicsLayerCA.mm
@@ -265,9 +265,7 @@ static CAMediaTimingFunction* getCAMediaTimingFunction(const TimingFunction* tim
 
 static void setLayerBorderColor(PlatformLayer* layer, const Color& color)
 {
-    CGColorRef borderColor = createCGColor(color);
-    [layer setBorderColor:borderColor];
-    CGColorRelease(borderColor);
+    [layer setBorderColor:cachedCGColor(color, DeviceColorSpace)];
 }
 
 static void clearBorderColor(PlatformLayer* layer)
@@ -277,9 +275,7 @@ static void clearBorderColor(PlatformLayer* layer)
 
 static void setLayerBackgroundColor(PlatformLayer* layer, const Color& color)
 {
-    CGColorRef bgColor = createCGColor(color);
-    [layer setBackgroundColor:bgColor];
-    CGColorRelease(bgColor);
+    [layer setBackgroundColor:cachedCGColor(color, DeviceColorSpace)];
 }
 
 static void clearLayerBackgroundColor(PlatformLayer* layer)
diff --git a/WebCore/platform/graphics/win/GraphicsContextCGWin.cpp b/WebCore/platform/graphics/win/GraphicsContextCGWin.cpp
index 0203d42..7d90890 100644
--- a/WebCore/platform/graphics/win/GraphicsContextCGWin.cpp
+++ b/WebCore/platform/graphics/win/GraphicsContextCGWin.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -129,6 +129,8 @@ void GraphicsContext::drawFocusRing(const Vector<Path>& paths, int width, int of
     // FIXME: implement
 }
 
+// FIXME: This is nearly identical to the GraphicsContext::drawFocusRing function in GraphicsContextMac.mm.
+// The code could move to GraphicsContextCG.cpp and be shared.
 void GraphicsContext::drawFocusRing(const Vector<IntRect>& rects, int width, int offset, const Color& color)
 {
     if (paintingDisabled())
@@ -136,7 +138,7 @@ void GraphicsContext::drawFocusRing(const Vector<IntRect>& rects, int width, int
 
     float radius = (width - 1) / 2.0f;
     offset += radius;
-    CGColorRef colorRef = color.isValid() ? createCGColor(color) : 0;
+    CGColorRef colorRef = color.isValid() ? cachedCGColor(color, DeviceColorSpace) : 0;
 
     CGMutablePathRef focusRingPath = CGPathCreateMutable();
     unsigned rectCount = rects.size();
@@ -151,8 +153,6 @@ void GraphicsContext::drawFocusRing(const Vector<IntRect>& rects, int width, int
 
     wkDrawFocusRing(context, colorRef, radius);
 
-    CGColorRelease(colorRef);
-
     CGPathRelease(focusRingPath);
 
     CGContextRestoreGState(context);
diff --git a/WebCore/platform/graphics/win/GraphicsLayerCACF.cpp b/WebCore/platform/graphics/win/GraphicsLayerCACF.cpp
index dad5da1..dcec0c8 100644
--- a/WebCore/platform/graphics/win/GraphicsLayerCACF.cpp
+++ b/WebCore/platform/graphics/win/GraphicsLayerCACF.cpp
@@ -99,9 +99,7 @@ TransformationMatrix CAToTransform3D(const CATransform3D& fromT3D)
 
 static void setLayerBorderColor(WKCACFLayer* layer, const Color& color)
 {
-    CGColorRef borderColor = createCGColor(color);
-    layer->setBorderColor(borderColor);
-    CGColorRelease(borderColor);
+    layer->setBorderColor(cachedCGColor(color, DeviceColorSpace));
 }
 
 static void clearBorderColor(WKCACFLayer* layer)
@@ -111,9 +109,7 @@ static void clearBorderColor(WKCACFLayer* layer)
 
 static void setLayerBackgroundColor(WKCACFLayer* layer, const Color& color)
 {
-    CGColorRef bgColor = createCGColor(color);
-    layer->setBackgroundColor(bgColor);
-    CGColorRelease(bgColor);
+    layer->setBackgroundColor(cachedCGColor(color, DeviceColorSpace));
 }
 
 static void clearLayerBackgroundColor(WKCACFLayer* layer)
diff --git a/WebCore/platform/graphics/win/WKCACFLayerRenderer.cpp b/WebCore/platform/graphics/win/WKCACFLayerRenderer.cpp
index 4f39b13..8082217 100644
--- a/WebCore/platform/graphics/win/WKCACFLayerRenderer.cpp
+++ b/WebCore/platform/graphics/win/WKCACFLayerRenderer.cpp
@@ -250,7 +250,7 @@ WKCACFLayerRenderer::WKCACFLayerRenderer(WKCACFLayerRendererClient* client)
     m_rootLayer->setGeometryFlipped(true);
 
 #ifndef NDEBUG
-    CGColorRef debugColor = createCGColor(Color(255, 0, 0, 204));
+    CGColorRef debugColor = CGColorCreateGenericRGB(1, 0, 0, 0.8);
     m_rootLayer->setBackgroundColor(debugColor);
     CGColorRelease(debugColor);
 #endif
diff --git a/WebCore/platform/graphics/win/WebTiledLayer.cpp b/WebCore/platform/graphics/win/WebTiledLayer.cpp
index 01dd6ae..4705033 100644
--- a/WebCore/platform/graphics/win/WebTiledLayer.cpp
+++ b/WebCore/platform/graphics/win/WebTiledLayer.cpp
@@ -201,7 +201,7 @@ void WebTiledLayer::addTile()
     CACFLayerInsertSublayer(m_tileParent.get(), newLayer.get(), sublayers ? CFArrayGetCount(sublayers) : 0);
 
     if (m_owner->showDebugBorders()) {
-        CGColorRef borderColor = createCGColor(Color(128, 0, 128, 180));
+        CGColorRef borderColor = CGColorCreateGenericRGB(0.5, 0, 0.5, 0.7);
         CACFLayerSetBorderColor(newLayer.get(), borderColor);
         CGColorRelease(borderColor);
         CACFLayerSetBorderWidth(newLayer.get(), 2);

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list