summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics/cg
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-10-22 13:02:20 +0100
committerBen Murdoch <benm@google.com>2010-10-26 15:21:41 +0100
commita94275402997c11dd2e778633dacf4b7e630a35d (patch)
treee66f56c67e3b01f22c9c23cd932271ee9ac558ed /WebCore/platform/graphics/cg
parent09e26c78506587b3f5d930d7bc72a23287ffbec0 (diff)
downloadexternal_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.zip
external_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.tar.gz
external_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.tar.bz2
Merge WebKit at r70209: Initial merge by Git
Change-Id: Id23a68efa36e9d1126bcce0b137872db00892c8e
Diffstat (limited to 'WebCore/platform/graphics/cg')
-rw-r--r--WebCore/platform/graphics/cg/ColorCG.cpp93
-rw-r--r--WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp112
-rw-r--r--WebCore/platform/graphics/cg/GraphicsContextCG.cpp93
-rw-r--r--WebCore/platform/graphics/cg/GraphicsContextCG.h41
-rw-r--r--WebCore/platform/graphics/cg/GraphicsContextPlatformPrivateCG.h6
-rw-r--r--WebCore/platform/graphics/cg/ImageBufferCG.cpp54
-rw-r--r--WebCore/platform/graphics/cg/ImageBufferData.h3
-rw-r--r--WebCore/platform/graphics/cg/ImageCG.cpp17
-rw-r--r--WebCore/platform/graphics/cg/PathCG.cpp52
9 files changed, 257 insertions, 214 deletions
diff --git a/WebCore/platform/graphics/cg/ColorCG.cpp b/WebCore/platform/graphics/cg/ColorCG.cpp
index 6f05c38..c9b05da 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,79 @@ Color::Color(CGColorRef color)
m_valid = true;
}
-#if OS(WINDOWS)
+static inline CGColorSpaceRef cachedCGColorSpace(ColorSpace colorSpace)
+{
+ switch (colorSpace) {
+ case ColorSpaceDeviceRGB:
+ return deviceRGBColorSpaceRef();
+ case ColorSpaceSRGB:
+ return sRGBColorSpaceRef();
+ case ColorSpaceLinearRGB:
+ return linearRGBColorSpaceRef();
+ }
+ 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;
+ }
}
-#ifdef OBSOLETE_COLORSYNC_API
- CMCloseProfile(prof);
-#else
- if (prof)
- CFRelease(prof);
-#endif
+ ASSERT(color.rgb());
- return color;
+ 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();
+ }
+
+ CGColorRef newCGColor = leakCGColor(color, colorSpace);
+
+ static size_t cursor;
+ cachedRGBAValues[cursor] = color.rgb();
+ cachedCGColors[cursor].adoptCF(newCGColor);
+ if (++cursor == cacheSize)
+ cursor = 0;
+
+ return newCGColor;
}
-#endif // OS(WINDOWS)
+CGColorRef cachedCGColor(const Color& color, ColorSpace colorSpace)
+{
+ switch (colorSpace) {
+ case ColorSpaceDeviceRGB:
+ return cachedCGColor<ColorSpaceDeviceRGB>(color);
+ case ColorSpaceSRGB:
+ return cachedCGColor<ColorSpaceSRGB>(color);
+ case ColorSpaceLinearRGB:
+ return cachedCGColor<ColorSpaceLinearRGB>(color);
+ }
+ ASSERT_NOT_REACHED();
+ return cachedCGColor(color, ColorSpaceDeviceRGB);
+}
}
diff --git a/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp b/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp
index 2a81fd2..fe4fc7f 100644
--- a/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp
+++ b/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp
@@ -64,9 +64,35 @@ bool GraphicsContext3D::getImageData(Image* image,
return false;
size_t width = CGImageGetWidth(cgImage);
size_t height = CGImageGetHeight(cgImage);
- if (!width || !height || CGImageGetBitsPerComponent(cgImage) != 8)
+ if (!width || !height)
return false;
- size_t componentsPerPixel = CGImageGetBitsPerPixel(cgImage) / 8;
+ size_t bitsPerComponent = CGImageGetBitsPerComponent(cgImage);
+ size_t bitsPerPixel = CGImageGetBitsPerPixel(cgImage);
+ if (bitsPerComponent != 8 && bitsPerComponent != 16)
+ return false;
+ if (bitsPerPixel % bitsPerComponent)
+ return false;
+ size_t componentsPerPixel = bitsPerPixel / bitsPerComponent;
+ bool srcByteOrder16Big = false;
+ if (bitsPerComponent == 16) {
+ CGBitmapInfo bitInfo = CGImageGetBitmapInfo(cgImage);
+ switch (bitInfo & kCGBitmapByteOrderMask) {
+ case kCGBitmapByteOrder16Big:
+ srcByteOrder16Big = true;
+ break;
+ case kCGBitmapByteOrder16Little:
+ srcByteOrder16Big = false;
+ break;
+ case kCGBitmapByteOrderDefault:
+ // This is a bug in earlier version of cg where the default endian
+ // is little whereas the decoded 16-bit png image data is actually
+ // Big. Later version (10.6.4) no longer returns ByteOrderDefault.
+ srcByteOrder16Big = true;
+ break;
+ default:
+ return false;
+ }
+ }
SourceDataFormat srcDataFormat = kSourceFormatRGBA8;
AlphaOp neededAlphaOp = kAlphaDoNothing;
switch (CGImageGetAlphaInfo(cgImage)) {
@@ -79,10 +105,16 @@ bool GraphicsContext3D::getImageData(Image* image,
neededAlphaOp = kAlphaDoUnmultiply;
switch (componentsPerPixel) {
case 2:
- srcDataFormat = kSourceFormatAR8;
+ if (bitsPerComponent == 8)
+ srcDataFormat = kSourceFormatAR8;
+ else
+ srcDataFormat = srcByteOrder16Big ? kSourceFormatAR16Big : kSourceFormatAR16Little;
break;
case 4:
- srcDataFormat = kSourceFormatARGB8;
+ if (bitsPerComponent == 8)
+ srcDataFormat = kSourceFormatARGB8;
+ else
+ srcDataFormat = srcByteOrder16Big ? kSourceFormatARGB16Big : kSourceFormatARGB16Little;
break;
default:
return false;
@@ -94,13 +126,22 @@ bool GraphicsContext3D::getImageData(Image* image,
neededAlphaOp = kAlphaDoPremultiply;
switch (componentsPerPixel) {
case 1:
- srcDataFormat = kSourceFormatA8;
+ if (bitsPerComponent == 8)
+ srcDataFormat = kSourceFormatA8;
+ else
+ srcDataFormat = srcByteOrder16Big ? kSourceFormatA16Big : kSourceFormatA16Little;
break;
case 2:
- srcDataFormat = kSourceFormatAR8;
+ if (bitsPerComponent == 8)
+ srcDataFormat = kSourceFormatAR8;
+ else
+ srcDataFormat = srcByteOrder16Big ? kSourceFormatAR16Big : kSourceFormatAR16Little;
break;
case 4:
- srcDataFormat = kSourceFormatARGB8;
+ if (bitsPerComponent == 8)
+ srcDataFormat = kSourceFormatARGB8;
+ else
+ srcDataFormat = srcByteOrder16Big ? kSourceFormatARGB16Big : kSourceFormatARGB16Little;
break;
default:
return false;
@@ -110,10 +151,16 @@ bool GraphicsContext3D::getImageData(Image* image,
// This path is only accessible for MacOS earlier than 10.6.4.
switch (componentsPerPixel) {
case 2:
- srcDataFormat = kSourceFormatAR8;
+ if (bitsPerComponent == 8)
+ srcDataFormat = kSourceFormatAR8;
+ else
+ srcDataFormat = srcByteOrder16Big ? kSourceFormatAR16Big : kSourceFormatAR16Little;
break;
case 4:
- srcDataFormat = kSourceFormatARGB8;
+ if (bitsPerComponent == 8)
+ srcDataFormat = kSourceFormatARGB8;
+ else
+ srcDataFormat = srcByteOrder16Big ? kSourceFormatARGB16Big : kSourceFormatARGB16Little;
break;
default:
return false;
@@ -127,10 +174,16 @@ bool GraphicsContext3D::getImageData(Image* image,
neededAlphaOp = kAlphaDoUnmultiply;
switch (componentsPerPixel) {
case 2:
- srcDataFormat = kSourceFormatRA8;
+ if (bitsPerComponent == 8)
+ srcDataFormat = kSourceFormatRA8;
+ else
+ srcDataFormat = srcByteOrder16Big ? kSourceFormatRA16Big : kSourceFormatRA16Little;
break;
case 4:
- srcDataFormat = kSourceFormatRGBA8;
+ if (bitsPerComponent == 8)
+ srcDataFormat = kSourceFormatRGBA8;
+ else
+ srcDataFormat = srcByteOrder16Big ? kSourceFormatRGBA16Big : kSourceFormatRGBA16Little;
break;
default:
return false;
@@ -141,13 +194,22 @@ bool GraphicsContext3D::getImageData(Image* image,
neededAlphaOp = kAlphaDoPremultiply;
switch (componentsPerPixel) {
case 1:
- srcDataFormat = kSourceFormatA8;
+ if (bitsPerComponent == 8)
+ srcDataFormat = kSourceFormatA8;
+ else
+ srcDataFormat = srcByteOrder16Big ? kSourceFormatA16Big : kSourceFormatA16Little;
break;
case 2:
- srcDataFormat = kSourceFormatRA8;
+ if (bitsPerComponent == 8)
+ srcDataFormat = kSourceFormatRA8;
+ else
+ srcDataFormat = srcByteOrder16Big ? kSourceFormatRA16Big : kSourceFormatRA16Little;
break;
case 4:
- srcDataFormat = kSourceFormatRGBA8;
+ if (bitsPerComponent == 8)
+ srcDataFormat = kSourceFormatRGBA8;
+ else
+ srcDataFormat = srcByteOrder16Big ? kSourceFormatRGBA16Big : kSourceFormatRGBA16Little;
break;
default:
return false;
@@ -156,10 +218,16 @@ bool GraphicsContext3D::getImageData(Image* image,
case kCGImageAlphaNoneSkipLast:
switch (componentsPerPixel) {
case 2:
- srcDataFormat = kSourceFormatRA8;
+ if (bitsPerComponent == 8)
+ srcDataFormat = kSourceFormatRA8;
+ else
+ srcDataFormat = srcByteOrder16Big ? kSourceFormatRA16Big : kSourceFormatRA16Little;
break;
case 4:
- srcDataFormat = kSourceFormatRGBA8;
+ if (bitsPerComponent == 8)
+ srcDataFormat = kSourceFormatRGBA8;
+ else
+ srcDataFormat = srcByteOrder16Big ? kSourceFormatRGBA16Big : kSourceFormatRGBA16Little;
break;
default:
return false;
@@ -168,10 +236,16 @@ bool GraphicsContext3D::getImageData(Image* image,
case kCGImageAlphaNone:
switch (componentsPerPixel) {
case 1:
- srcDataFormat = kSourceFormatR8;
+ if (bitsPerComponent == 8)
+ srcDataFormat = kSourceFormatR8;
+ else
+ srcDataFormat = srcByteOrder16Big ? kSourceFormatR16Big : kSourceFormatR16Little;
break;
case 3:
- srcDataFormat = kSourceFormatRGB8;
+ if (bitsPerComponent == 8)
+ srcDataFormat = kSourceFormatRGB8;
+ else
+ srcDataFormat = srcByteOrder16Big ? kSourceFormatRGB16Big : kSourceFormatRGB16Little;
break;
default:
return false;
@@ -188,7 +262,7 @@ bool GraphicsContext3D::getImageData(Image* image,
outputVector.resize(width * height * 4);
unsigned int srcUnpackAlignment = 0;
size_t bytesPerRow = CGImageGetBytesPerRow(cgImage);
- unsigned int padding = bytesPerRow - componentsPerPixel * width;
+ unsigned int padding = bytesPerRow - bitsPerPixel / 8 * width;
if (padding) {
srcUnpackAlignment = padding + 1;
while (bytesPerRow % srcUnpackAlignment)
diff --git a/WebCore/platform/graphics/cg/GraphicsContextCG.cpp b/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
index e5079dc..9e0a2f5 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,60 +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);
-}
-
-static void setCGFillColorSpace(CGContextRef context, ColorSpace colorSpace)
-{
- switch (colorSpace) {
- case DeviceColorSpace:
- break;
- case sRGBColorSpace:
- CGContextSetFillColorSpace(context, sRGBColorSpaceRef());
- break;
- default:
- ASSERT_NOT_REACHED();
- break;
- }
-}
-
-static void setCGStrokeColorSpace(CGContextRef context, ColorSpace colorSpace)
-{
- switch (colorSpace) {
- case DeviceColorSpace:
- break;
- case sRGBColorSpace:
- CGContextSetStrokeColorSpace(context, sRGBColorSpaceRef());
- break;
- default:
- ASSERT_NOT_REACHED();
- break;
- }
+ CGContextSetStrokeColorWithColor(context, cachedCGColor(color, colorSpace));
}
CGColorSpaceRef deviceRGBColorSpaceRef()
@@ -142,6 +96,17 @@ CGColorSpaceRef sRGBColorSpaceRef()
#endif
}
+CGColorSpaceRef linearRGBColorSpaceRef()
+{
+ // FIXME: Windows should be able to use kCGColorSpaceGenericRGBLinear, this is tracked by http://webkit.org/b/31363.
+#if PLATFORM(WIN) || defined(BUILDING_ON_TIGER)
+ return deviceRGBColorSpaceRef();
+#else
+ static CGColorSpaceRef linearRGBSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGBLinear);
+ return linearRGBSpace;
+#endif
+}
+
GraphicsContext::GraphicsContext(CGContextRef cgContext)
: m_common(createGraphicsContextPrivate())
, m_data(new GraphicsContextPlatformPrivate(cgContext))
@@ -586,9 +551,6 @@ void GraphicsContext::fillPath()
CGContextRef context = platformContext();
- // FIXME: Is this helpful and correct in the fillPattern and fillGradient cases?
- setCGFillColorSpace(context, m_common->state.fillColorSpace);
-
if (m_common->state.fillGradient) {
CGContextSaveGState(context);
if (fillRule() == RULE_EVENODD)
@@ -613,9 +575,6 @@ void GraphicsContext::strokePath()
CGContextRef context = platformContext();
- // FIXME: Is this helpful and correct in the strokePattern and strokeGradient cases?
- setCGStrokeColorSpace(context, m_common->state.strokeColorSpace);
-
if (m_common->state.strokeGradient) {
CGContextSaveGState(context);
CGContextReplacePathWithStrokedPath(context);
@@ -638,9 +597,6 @@ void GraphicsContext::fillRect(const FloatRect& rect)
CGContextRef context = platformContext();
- // FIXME: Is this helpful and correct in the fillPattern and fillGradient cases?
- setCGFillColorSpace(context, m_common->state.fillColorSpace);
-
if (m_common->state.fillGradient) {
CGContextSaveGState(context);
CGContextClipToRect(context, rect);
@@ -659,17 +615,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)
@@ -684,7 +641,9 @@ void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLef
if (oldFillColor != color || oldColorSpace != colorSpace)
setCGFillColor(context, color, colorSpace);
- addPath(Path::createRoundedRectangle(rect, topLeft, topRight, bottomLeft, bottomRight));
+ Path path;
+ path.addRoundedRect(rect, topLeft, topRight, bottomLeft, bottomRight);
+ addPath(path);
fillPath();
if (oldFillColor != color || oldColorSpace != colorSpace)
@@ -821,13 +780,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()
@@ -865,9 +819,6 @@ void GraphicsContext::strokeRect(const FloatRect& r, float lineWidth)
CGContextRef context = platformContext();
- // FIXME: Is this helpful and correct in the strokePattern and strokeGradient cases?
- setCGStrokeColorSpace(context, m_common->state.strokeColorSpace);
-
if (m_common->state.strokeGradient) {
CGContextSaveGState(context);
setStrokeThickness(lineWidth);
diff --git a/WebCore/platform/graphics/cg/GraphicsContextCG.h b/WebCore/platform/graphics/cg/GraphicsContextCG.h
new file mode 100644
index 0000000..5de95ef
--- /dev/null
+++ b/WebCore/platform/graphics/cg/GraphicsContextCG.h
@@ -0,0 +1,41 @@
+/*
+ * 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();
+CGColorSpaceRef linearRGBColorSpaceRef();
+
+}
+
+#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/ImageBufferCG.cpp b/WebCore/platform/graphics/cg/ImageBufferCG.cpp
index ecbcf60..640692a 100644
--- a/WebCore/platform/graphics/cg/ImageBufferCG.cpp
+++ b/WebCore/platform/graphics/cg/ImageBufferCG.cpp
@@ -31,12 +31,12 @@
#include "Base64.h"
#include "BitmapImage.h"
#include "GraphicsContext.h"
+#include "GraphicsContextCG.h"
#include "ImageData.h"
#include "MIMETypeRegistry.h"
-#include "PlatformString.h"
#include <ApplicationServices/ApplicationServices.h>
#include <wtf/Assertions.h>
-#include <wtf/text/CString.h>
+#include <wtf/text/StringConcatenate.h>
#include <wtf/OwnArrayPtr.h>
#include <wtf/RetainPtr.h>
#include <wtf/Threading.h>
@@ -56,7 +56,7 @@ ImageBufferData::ImageBufferData(const IntSize&)
{
}
-ImageBuffer::ImageBuffer(const IntSize& size, ImageColorSpace imageColorSpace, bool& success)
+ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace imageColorSpace, bool& success)
: m_data(size)
, m_size(size)
{
@@ -65,12 +65,11 @@ ImageBuffer::ImageBuffer(const IntSize& size, ImageColorSpace imageColorSpace, b
return;
unsigned bytesPerRow = size.width();
- if (imageColorSpace != GrayScale) {
- // Protect against overflow
- if (bytesPerRow > 0x3FFFFFFF)
- return;
- bytesPerRow *= 4;
- }
+
+ // Protect against overflow
+ if (bytesPerRow > 0x3FFFFFFF)
+ return;
+ bytesPerRow *= 4;
m_data.m_bytesPerRow = bytesPerRow;
size_t dataSize = size.height() * bytesPerRow;
@@ -80,27 +79,20 @@ ImageBuffer::ImageBuffer(const IntSize& size, ImageColorSpace imageColorSpace, b
ASSERT((reinterpret_cast<size_t>(m_data.m_data) & 2) == 0);
switch(imageColorSpace) {
- case DeviceRGB:
- m_data.m_colorSpace.adoptCF(CGColorSpaceCreateDeviceRGB());
- break;
- case GrayScale:
- m_data.m_colorSpace.adoptCF(CGColorSpaceCreateDeviceGray());
- break;
-#if ((PLATFORM(MAC) || PLATFORM(CHROMIUM)) && !defined(BUILDING_ON_TIGER))
- case LinearRGB:
- m_data.m_colorSpace.adoptCF(CGColorSpaceCreateWithName(kCGColorSpaceGenericRGBLinear));
- break;
-
-#endif
- default:
- m_data.m_colorSpace.adoptCF(CGColorSpaceCreateDeviceRGB());
- break;
+ case ColorSpaceDeviceRGB:
+ m_data.m_colorSpace = deviceRGBColorSpaceRef();
+ break;
+ case ColorSpaceSRGB:
+ m_data.m_colorSpace = sRGBColorSpaceRef();
+ break;
+ case ColorSpaceLinearRGB:
+ m_data.m_colorSpace = linearRGBColorSpaceRef();
+ break;
}
- m_data.m_grayScale = imageColorSpace == GrayScale;
- m_data.m_bitmapInfo = m_data.m_grayScale ? kCGImageAlphaNone : kCGImageAlphaPremultipliedLast;
+ m_data.m_bitmapInfo = kCGImageAlphaPremultipliedLast;
RetainPtr<CGContextRef> cgContext(AdoptCF, CGBitmapContextCreate(m_data.m_data, size.width(), size.height(), 8, bytesPerRow,
- m_data.m_colorSpace.get(), m_data.m_bitmapInfo));
+ m_data.m_colorSpace, m_data.m_bitmapInfo));
if (!cgContext)
return;
@@ -135,8 +127,8 @@ PassRefPtr<Image> ImageBuffer::copyImage() const
static CGImageRef cgImage(const IntSize& size, const ImageBufferData& data)
{
- return CGImageCreate(size.width(), size.height(), 8, data.m_grayScale ? 8 : 32, data.m_bytesPerRow,
- data.m_colorSpace.get(), data.m_bitmapInfo, data.m_dataProvider.get(), 0, true, kCGRenderingIntentDefault);
+ return CGImageCreate(size.width(), size.height(), 8, 32, data.m_bytesPerRow,
+ data.m_colorSpace, data.m_bitmapInfo, data.m_dataProvider.get(), 0, true, kCGRenderingIntentDefault);
}
void ImageBuffer::draw(GraphicsContext* destContext, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect,
@@ -145,7 +137,7 @@ void ImageBuffer::draw(GraphicsContext* destContext, ColorSpace styleColorSpace,
if (destContext == context()) {
// We're drawing into our own buffer. In order for this to work, we need to copy the source buffer first.
RefPtr<Image> copy = copyImage();
- destContext->drawImage(copy.get(), DeviceColorSpace, destRect, srcRect, op, useLowQualityScale);
+ destContext->drawImage(copy.get(), ColorSpaceDeviceRGB, destRect, srcRect, op, useLowQualityScale);
} else {
RefPtr<Image> imageForRendering = BitmapImage::create(cgImage(m_size, m_data));
destContext->drawImage(imageForRendering.get(), styleColorSpace, destRect, srcRect, op, useLowQualityScale);
@@ -371,7 +363,7 @@ String ImageBuffer::toDataURL(const String& mimeType, const double* quality) con
base64Encode(reinterpret_cast<const char*>(CFDataGetBytePtr(data.get())), CFDataGetLength(data.get()), out);
out.append('\0');
- return String::format("data:%s;base64,%s", mimeType.utf8().data(), out.data());
+ return makeString("data:", mimeType, ";base64,", out.data());
}
} // namespace WebCore
diff --git a/WebCore/platform/graphics/cg/ImageBufferData.h b/WebCore/platform/graphics/cg/ImageBufferData.h
index 2f9d854..456c934 100644
--- a/WebCore/platform/graphics/cg/ImageBufferData.h
+++ b/WebCore/platform/graphics/cg/ImageBufferData.h
@@ -46,9 +46,8 @@ public:
RetainPtr<CGDataProviderRef> m_dataProvider;
CGBitmapInfo m_bitmapInfo;
- bool m_grayScale;
unsigned m_bytesPerRow;
- RetainPtr<CGColorSpaceRef> m_colorSpace;
+ CGColorSpaceRef m_colorSpace;
};
} // namespace WebCore
diff --git a/WebCore/platform/graphics/cg/ImageCG.cpp b/WebCore/platform/graphics/cg/ImageCG.cpp
index 70a80a0..c7ed0c8 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,12 +31,12 @@
#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"
#include <ApplicationServices/ApplicationServices.h>
+#include <wtf/RetainPtr.h>
#if PLATFORM(MAC) || PLATFORM(CHROMIUM)
#include "WebCoreSystemInterface.h"
@@ -138,11 +138,12 @@ static RetainPtr<CGImageRef> imageWithColorSpace(CGImageRef originalImage, Color
return originalImage;
switch (colorSpace) {
- case DeviceColorSpace:
+ case ColorSpaceDeviceRGB:
return originalImage;
- case sRGBColorSpace:
- return RetainPtr<CGImageRef>(AdoptCF, CGImageCreateCopyWithColorSpace(originalImage,
- sRGBColorSpaceRef()));
+ case ColorSpaceSRGB:
+ return RetainPtr<CGImageRef>(AdoptCF, CGImageCreateCopyWithColorSpace(originalImage, sRGBColorSpaceRef()));
+ case ColorSpaceLinearRGB:
+ return RetainPtr<CGImageRef>(AdoptCF, CGImageCreateCopyWithColorSpace(originalImage, linearRGBColorSpaceRef()));
}
ASSERT_NOT_REACHED();
@@ -186,7 +187,7 @@ void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& destRect, const F
// containing only the portion we want to display. We need to do this because high-quality
// interpolation smoothes sharp edges, causing pixels from outside the source rect to bleed
// into the destination rect. See <rdar://problem/6112909>.
- shouldUseSubimage = (interpolationQuality == kCGInterpolationHigh || interpolationQuality == kCGInterpolationDefault) && srcRect.size() != destRect.size();
+ shouldUseSubimage = (interpolationQuality == kCGInterpolationHigh || interpolationQuality == kCGInterpolationDefault) && (srcRect.size() != destRect.size() || !ctxt->getCTM().isIdentityOrTranslationOrFlipped());
float xScale = srcRect.width() / destRect.width();
float yScale = srcRect.height() / destRect.height();
if (shouldUseSubimage) {
diff --git a/WebCore/platform/graphics/cg/PathCG.cpp b/WebCore/platform/graphics/cg/PathCG.cpp
index 90d4b8a..b47ed02 100644
--- a/WebCore/platform/graphics/cg/PathCG.cpp
+++ b/WebCore/platform/graphics/cg/PathCG.cpp
@@ -254,61 +254,9 @@ FloatPoint Path::currentPoint() const
return CGPathGetCurrentPoint(m_path);
}
-static void CGPathToCFStringApplierFunction(void* info, const CGPathElement *element)
-{
- CFMutableStringRef string = static_cast<CFMutableStringRef>(info);
-
- CGPoint* points = element->points;
- switch (element->type) {
- case kCGPathElementMoveToPoint:
- CFStringAppendFormat(string, 0, CFSTR("M%.2f,%.2f "), points[0].x, points[0].y);
- break;
- case kCGPathElementAddLineToPoint:
- CFStringAppendFormat(string, 0, CFSTR("L%.2f,%.2f "), points[0].x, points[0].y);
- break;
- case kCGPathElementAddQuadCurveToPoint:
- CFStringAppendFormat(string, 0, CFSTR("Q%.2f,%.2f,%.2f,%.2f "),
- points[0].x, points[0].y, points[1].x, points[1].y);
- break;
- case kCGPathElementAddCurveToPoint:
- CFStringAppendFormat(string, 0, CFSTR("C%.2f,%.2f,%.2f,%.2f,%.2f,%.2f "),
- points[0].x, points[0].y, points[1].x, points[1].y,
- points[2].x, points[2].y);
- break;
- case kCGPathElementCloseSubpath:
- CFStringAppendFormat(string, 0, CFSTR("Z "));
- break;
- }
-}
-
-static CFStringRef CFStringFromCGPath(CGPathRef path)
-{
- if (!path)
- return 0;
-
- CFMutableStringRef string = CFStringCreateMutable(NULL, 0);
- CGPathApply(path, string, CGPathToCFStringApplierFunction);
- CFStringTrimWhitespace(string);
-
-
- return string;
-}
-
-
#pragma mark -
#pragma mark Path Management
-String Path::debugString() const
-{
- String result;
- if (!isEmpty()) {
- CFStringRef pathString = CFStringFromCGPath(m_path);
- result = String(pathString);
- CFRelease(pathString);
- }
- return result;
-}
-
struct PathApplierInfo {
void* info;
PathApplierFunction function;