summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2010-08-04 11:41:34 +0100
committerSteve Block <steveblock@google.com>2010-08-09 12:04:44 +0100
commitdb14019a23d96bc8a444b6576a5da8bd1cfbc8b0 (patch)
tree9f793c5b0f5e1f2aca8247158920e2c4bf962bbf /WebCore/platform/graphics
parentbf916837aa84f1e4b00e6ed6268516c2acd27545 (diff)
downloadexternal_webkit-db14019a23d96bc8a444b6576a5da8bd1cfbc8b0.zip
external_webkit-db14019a23d96bc8a444b6576a5da8bd1cfbc8b0.tar.gz
external_webkit-db14019a23d96bc8a444b6576a5da8bd1cfbc8b0.tar.bz2
Merge WebKit at r64523 : Initial merge by git.
Change-Id: Ibb796c6802e757b1d9b40f58205cfbe4da95fcd4
Diffstat (limited to 'WebCore/platform/graphics')
-rw-r--r--WebCore/platform/graphics/FloatRect.cpp24
-rw-r--r--WebCore/platform/graphics/WOFFFileFormat.cpp258
-rw-r--r--WebCore/platform/graphics/WOFFFileFormat.h48
-rw-r--r--WebCore/platform/graphics/cairo/CairoPath.h35
-rw-r--r--WebCore/platform/graphics/cairo/FontCustomPlatformData.cpp7
-rw-r--r--WebCore/platform/graphics/cairo/FontCustomPlatformData.h3
-rw-r--r--WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp126
-rw-r--r--WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h1
-rw-r--r--WebCore/platform/graphics/cairo/ImageBufferCairo.cpp2
-rw-r--r--WebCore/platform/graphics/cairo/PathCairo.cpp50
-rw-r--r--WebCore/platform/graphics/chromium/FontCustomPlatformData.cpp9
-rw-r--r--WebCore/platform/graphics/chromium/FontCustomPlatformData.h3
-rw-r--r--WebCore/platform/graphics/chromium/GLES2Canvas.cpp4
-rw-r--r--WebCore/platform/graphics/chromium/GLES2Canvas.h1
-rw-r--r--WebCore/platform/graphics/gtk/CairoUtilities.cpp94
-rw-r--r--WebCore/platform/graphics/gtk/CairoUtilities.h33
-rw-r--r--WebCore/platform/graphics/gtk/FontCustomPlatformDataPango.cpp5
-rw-r--r--WebCore/platform/graphics/gtk/ImageBufferGtk.cpp73
-rw-r--r--WebCore/platform/graphics/gtk/ImageGtk.cpp61
-rw-r--r--WebCore/platform/graphics/haiku/FontCustomPlatformData.cpp5
-rw-r--r--WebCore/platform/graphics/haiku/FontCustomPlatformData.h3
-rw-r--r--WebCore/platform/graphics/mac/FontCustomPlatformData.cpp24
-rw-r--r--WebCore/platform/graphics/mac/FontCustomPlatformData.h3
-rw-r--r--WebCore/platform/graphics/qt/FontCustomPlatformData.h5
-rw-r--r--WebCore/platform/graphics/qt/FontCustomPlatformDataQt.cpp4
-rw-r--r--WebCore/platform/graphics/skia/ImageBufferSkia.cpp2
-rw-r--r--WebCore/platform/graphics/skia/ImageSkia.cpp44
-rw-r--r--WebCore/platform/graphics/win/FontCustomPlatformData.cpp18
-rw-r--r--WebCore/platform/graphics/win/FontCustomPlatformData.h3
-rw-r--r--WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp5
-rw-r--r--WebCore/platform/graphics/win/FontCustomPlatformDataCairo.h3
-rw-r--r--WebCore/platform/graphics/win/WKCACFLayer.cpp14
-rw-r--r--WebCore/platform/graphics/win/WKCACFLayer.h11
-rw-r--r--WebCore/platform/graphics/win/WKCACFLayerRenderer.cpp8
-rw-r--r--WebCore/platform/graphics/win/WKCACFLayerRenderer.h1
-rw-r--r--WebCore/platform/graphics/wince/FontCustomPlatformData.cpp5
-rw-r--r--WebCore/platform/graphics/wince/FontCustomPlatformData.h3
37 files changed, 818 insertions, 180 deletions
diff --git a/WebCore/platform/graphics/FloatRect.cpp b/WebCore/platform/graphics/FloatRect.cpp
index 7a54f21..6dfa808 100644
--- a/WebCore/platform/graphics/FloatRect.cpp
+++ b/WebCore/platform/graphics/FloatRect.cpp
@@ -30,6 +30,7 @@
#include "FloatConversion.h"
#include "IntRect.h"
#include <algorithm>
+#include <limits>
#include <math.h>
using std::max;
@@ -110,13 +111,26 @@ void FloatRect::scale(float sx, float sy)
m_size.setHeight(height() * sy);
}
+static inline int safeFloatToInt(float x)
+{
+ static const int s_intMax = std::numeric_limits<int>::max();
+ static const int s_intMin = std::numeric_limits<int>::min();
+
+ if (x >= static_cast<float>(s_intMax))
+ return s_intMax;
+ if (x < static_cast<float>(s_intMin))
+ return s_intMin;
+ return static_cast<int>(x);
+}
+
IntRect enclosingIntRect(const FloatRect& rect)
{
- int l = static_cast<int>(floorf(rect.x()));
- int t = static_cast<int>(floorf(rect.y()));
- int r = static_cast<int>(ceilf(rect.right()));
- int b = static_cast<int>(ceilf(rect.bottom()));
- return IntRect(l, t, r - l, b - t);
+ float left = floorf(rect.x());
+ float top = floorf(rect.y());
+ float width = ceilf(rect.right()) - left;
+ float height = ceilf(rect.bottom()) - top;
+ return IntRect(safeFloatToInt(left), safeFloatToInt(top),
+ safeFloatToInt(width), safeFloatToInt(height));
}
FloatRect mapRect(const FloatRect& r, const FloatRect& srcRect, const FloatRect& destRect)
diff --git a/WebCore/platform/graphics/WOFFFileFormat.cpp b/WebCore/platform/graphics/WOFFFileFormat.cpp
new file mode 100644
index 0000000..dc73603
--- /dev/null
+++ b/WebCore/platform/graphics/WOFFFileFormat.cpp
@@ -0,0 +1,258 @@
+/*
+ * Copyright (C) 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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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.
+ */
+
+#include "config.h"
+#include "WOFFFileFormat.h"
+
+#if !ENABLE(OPENTYPE_SANITIZER)
+
+#include "SharedBuffer.h"
+
+#if !PLATFORM(WIN)
+#include <zlib.h>
+#else
+#include "SoftLinking.h"
+
+typedef unsigned char Bytef;
+typedef unsigned long uLong;
+typedef unsigned long uLongf;
+#define Z_OK 0
+
+SOFT_LINK_LIBRARY(zlib1);
+SOFT_LINK(zlib1, uncompress, int, __cdecl, (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen), (dest, destLen, source, sourceLen));
+
+#if CPU(BIG_ENDIAN)
+#define ntohs(x) ((uint16_t)(x))
+#define htons(x) ((uint16_t)(x))
+#define ntohl(x) ((uint32_t)(x))
+#define htonl(x) ((uint32_t)(x))
+#elif CPU(MIDDLE_ENDIAN)
+#define ntohs(x) ((unit16_t)(x))
+#define htons(x) ((uint16_t)(x))
+#define ntohl(x) ((uint32_t)((((uint32_t)(x) & 0xffff0000) >> 16) | (((uint32_t)(x) & 0xffff) << 16))
+#define htonl(x) ntohl(x)
+#else
+#define ntohs(x) ((uint16_t)((((uint16_t)(x) & 0xff00) >> 8) | (((uint16_t)(x) & 0x00ff) << 8)))
+#define htons(x) ntohs(x)
+#define ntohl(x) ((uint32_t)((((uint32_t)(x) & 0xff000000) >> 24) | (((uint32_t)(x) & 0x00ff0000) >> 8) | \
+ (((uint32_t)(x) & 0x0000ff00) << 8) | (((uint32_t)(x) & 0x000000ff) << 24)))
+#define htonl(x) ntohl(x)
+#endif
+
+#endif // PLATFORM(WIN)
+
+namespace WebCore {
+
+static bool readUInt32(SharedBuffer* buffer, size_t& offset, uint32_t& value)
+{
+ ASSERT_ARG(offset, offset <= buffer->size());
+ if (buffer->size() - offset < sizeof(value))
+ return false;
+
+ value = ntohl(*reinterpret_cast<const uint32_t*>(buffer->data() + offset));
+ offset += sizeof(value);
+
+ return true;
+}
+
+static bool readUInt16(SharedBuffer* buffer, size_t& offset, uint16_t& value)
+{
+ ASSERT_ARG(offset, offset <= buffer->size());
+ if (buffer->size() - offset < sizeof(value))
+ return false;
+
+ value = ntohs(*reinterpret_cast<const uint16_t*>(buffer->data() + offset));
+ offset += sizeof(value);
+
+ return true;
+}
+
+static bool writeUInt32(Vector<char>& vector, uint32_t value)
+{
+ uint32_t bigEndianValue = htonl(value);
+ return vector.tryAppend(reinterpret_cast<char*>(&bigEndianValue), sizeof(bigEndianValue));
+}
+
+static bool writeUInt16(Vector<char>& vector, uint16_t value)
+{
+ uint16_t bigEndianValue = htons(value);
+ return vector.tryAppend(reinterpret_cast<char*>(&bigEndianValue), sizeof(bigEndianValue));
+}
+
+static const uint32_t woffSignature = 0x774f4646; /* 'wOFF' */
+
+bool isWOFF(SharedBuffer* buffer)
+{
+ size_t offset = 0;
+ uint32_t signature;
+
+ return readUInt32(buffer, offset, signature) && signature == woffSignature;
+}
+
+bool convertWOFFToSfnt(SharedBuffer* woff, Vector<char>& sfnt)
+{
+#if PLATFORM(WINDOWS)
+ if (!zlib1Library())
+ return false;
+#endif
+ ASSERT_ARG(sfnt, sfnt.isEmpty());
+
+ size_t offset = 0;
+
+ // Read the WOFF header.
+ uint32_t signature;
+ if (!readUInt32(woff, offset, signature) || signature != woffSignature) {
+ ASSERT_NOT_REACHED();
+ return false;
+ }
+
+ uint32_t flavor;
+ if (!readUInt32(woff, offset, flavor))
+ return false;
+
+ uint32_t length;
+ if (!readUInt32(woff, offset, length) || length != woff->size())
+ return false;
+
+ uint16_t numTables;
+ if (!readUInt16(woff, offset, numTables))
+ return false;
+
+ if (!numTables || numTables > 0x0fff)
+ return false;
+
+ uint16_t reserved;
+ if (!readUInt16(woff, offset, reserved) || reserved)
+ return false;
+
+ uint32_t totalSfntSize;
+ if (!readUInt32(woff, offset, totalSfntSize))
+ return false;
+
+ if (woff->size() - offset < sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t))
+ return false;
+
+ offset += sizeof(uint16_t); // majorVersion
+ offset += sizeof(uint16_t); // minorVersion
+ offset += sizeof(uint32_t); // metaOffset
+ offset += sizeof(uint32_t); // metaLength
+ offset += sizeof(uint32_t); // metaOrigLength
+ offset += sizeof(uint32_t); // privOffset
+ offset += sizeof(uint32_t); // privLength
+
+ // Check if the WOFF can supply as many tables as it claims it has.
+ if (woff->size() - offset < numTables * 5 * sizeof(uint32_t))
+ return false;
+
+ // Write the sfnt offset subtable.
+ uint16_t entrySelector = 0;
+ uint16_t searchRange = 1;
+ while (searchRange < numTables >> 1) {
+ entrySelector++;
+ searchRange <<= 1;
+ }
+ searchRange <<= 4;
+ uint16_t rangeShift = (numTables << 4) - searchRange;
+
+ if (!writeUInt32(sfnt, flavor)
+ || !writeUInt16(sfnt, numTables)
+ || !writeUInt16(sfnt, searchRange)
+ || !writeUInt16(sfnt, entrySelector)
+ || !writeUInt16(sfnt, rangeShift))
+ return false;
+
+ if (sfnt.size() > totalSfntSize)
+ return false;
+
+ if (totalSfntSize - sfnt.size() < numTables * 4 * sizeof(uint32_t))
+ return false;
+
+ size_t sfntTableDirectoryCursor = sfnt.size();
+ sfnt.grow(sfnt.size() + numTables * 4 * sizeof(uint32_t));
+
+ // Process tables.
+ for (uint16_t i = 0; i < numTables; ++i) {
+ // Read a WOFF table directory entry.
+ uint32_t tableTag;
+ if (!readUInt32(woff, offset, tableTag))
+ return false;
+
+ uint32_t tableOffset;
+ if (!readUInt32(woff, offset, tableOffset))
+ return false;
+
+ uint32_t tableCompLength;
+ if (!readUInt32(woff, offset, tableCompLength))
+ return false;
+
+ if (tableOffset > woff->size() || tableCompLength > woff->size() - tableOffset)
+ return false;
+
+ uint32_t tableOrigLength;
+ if (!readUInt32(woff, offset, tableOrigLength) || tableCompLength > tableOrigLength)
+ return false;
+
+ if (tableOrigLength > totalSfntSize || sfnt.size() > totalSfntSize - tableOrigLength)
+ return false;
+
+ uint32_t tableOrigChecksum;
+ if (!readUInt32(woff, offset, tableOrigChecksum))
+ return false;
+
+ // Write an sfnt table directory entry.
+ uint32_t* sfntTableDirectoryPtr = reinterpret_cast<uint32_t*>(sfnt.data() + sfntTableDirectoryCursor);
+ *sfntTableDirectoryPtr++ = htonl(tableTag);
+ *sfntTableDirectoryPtr++ = htonl(tableOrigChecksum);
+ *sfntTableDirectoryPtr++ = htonl(sfnt.size());
+ *sfntTableDirectoryPtr++ = htonl(tableOrigLength);
+ sfntTableDirectoryCursor += 4 * sizeof(uint32_t);
+
+ if (tableCompLength == tableOrigLength) {
+ // The table is not compressed.
+ if (!sfnt.tryAppend(woff->data() + tableOffset, tableCompLength))
+ return false;
+ } else {
+ uLongf destLen = tableOrigLength;
+ if (!sfnt.tryReserveCapacity(sfnt.size() + tableOrigLength))
+ return false;
+ Bytef* dest = reinterpret_cast<Bytef*>(sfnt.end());
+ sfnt.grow(sfnt.size() + tableOrigLength);
+ if (uncompress(dest, &destLen, reinterpret_cast<const Bytef*>(woff->data() + tableOffset), tableCompLength) != Z_OK)
+ return false;
+ if (destLen != tableOrigLength)
+ return false;
+ }
+
+ // Pad to a multiple of 4 bytes.
+ while (sfnt.size() % 4)
+ sfnt.append(0);
+ }
+
+ return sfnt.size() == totalSfntSize;
+}
+
+#endif // !ENABLE(OPENTYPE_SANITIZER)
+
+} // namespace WebCore
diff --git a/WebCore/platform/graphics/WOFFFileFormat.h b/WebCore/platform/graphics/WOFFFileFormat.h
new file mode 100644
index 0000000..9351d0e
--- /dev/null
+++ b/WebCore/platform/graphics/WOFFFileFormat.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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 WOFFFileFormat_h
+#define WOFFFileFormat_h
+
+#if !ENABLE(OPENTYPE_SANITIZER)
+
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class SharedBuffer;
+
+// Returns whether the buffer is a WOFF file.
+bool isWOFF(SharedBuffer* buffer);
+
+// Returns false if the WOFF file woff is invalid or could not be converted to sfnt (for example,
+// if conversion ran out of memory). Otherwise returns true and writes the sfnt payload into sfnt.
+bool convertWOFFToSfnt(SharedBuffer* woff, Vector<char>& sfnt);
+
+} // namespace WebCore
+
+#endif // !ENABLE(OPENTYPE_SANITIZER)
+
+#endif // WOFFFileFormat_h
diff --git a/WebCore/platform/graphics/cairo/CairoPath.h b/WebCore/platform/graphics/cairo/CairoPath.h
index b761ce6..da7affb 100644
--- a/WebCore/platform/graphics/cairo/CairoPath.h
+++ b/WebCore/platform/graphics/cairo/CairoPath.h
@@ -1,5 +1,6 @@
/*
Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk>
+ Copyright (C) 2010 Igalia S.L.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -24,21 +25,25 @@
namespace WebCore {
- // This is necessary since cairo_path_fixed_t isn't exposed in Cairo's public API.
- struct CairoPath {
- cairo_t* m_cr;
-
- CairoPath()
- {
- static cairo_surface_t* pathSurface = cairo_image_surface_create(CAIRO_FORMAT_A8, 1, 1);
- m_cr = cairo_create(pathSurface);
- }
-
- ~CairoPath()
- {
- cairo_destroy(m_cr);
- }
- };
+// This is necessary since cairo_path_fixed_t isn't exposed in Cairo's public API.
+class CairoPath {
+public:
+ CairoPath()
+ {
+ static cairo_surface_t* pathSurface = cairo_image_surface_create(CAIRO_FORMAT_A8, 1, 1);
+ m_cr = cairo_create(pathSurface);
+ }
+
+ ~CairoPath()
+ {
+ cairo_destroy(m_cr);
+ }
+
+ cairo_t* context() { return m_cr; }
+
+private:
+ cairo_t* m_cr;
+};
} // namespace WebCore
diff --git a/WebCore/platform/graphics/cairo/FontCustomPlatformData.cpp b/WebCore/platform/graphics/cairo/FontCustomPlatformData.cpp
index bb2e064..6b76c2a 100644
--- a/WebCore/platform/graphics/cairo/FontCustomPlatformData.cpp
+++ b/WebCore/platform/graphics/cairo/FontCustomPlatformData.cpp
@@ -21,8 +21,8 @@
#include "config.h"
#include "FontCustomPlatformData.h"
-#include "SharedBuffer.h"
#include "FontPlatformData.h"
+#include "SharedBuffer.h"
namespace WebCore {
@@ -70,4 +70,9 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
return new FontCustomPlatformData(fontFace);
}
+bool FontCustomPlatformData::supportsFormat(const String& format)
+{
+ return equalIgnoringCase(format, "truetype") || equalIgnoringCase(format, "opentype");
+}
+
}
diff --git a/WebCore/platform/graphics/cairo/FontCustomPlatformData.h b/WebCore/platform/graphics/cairo/FontCustomPlatformData.h
index b36cc79..2816427 100644
--- a/WebCore/platform/graphics/cairo/FontCustomPlatformData.h
+++ b/WebCore/platform/graphics/cairo/FontCustomPlatformData.h
@@ -30,6 +30,7 @@ namespace WebCore {
class FontPlatformData;
class SharedBuffer;
+class String;
struct FontCustomPlatformData : Noncopyable {
FontCustomPlatformData(cairo_font_face_t* fontFace)
@@ -40,6 +41,8 @@ struct FontCustomPlatformData : Noncopyable {
FontPlatformData fontPlatformData(int size, bool bold, bool italic, FontRenderingMode = NormalRenderingMode);
+ static bool supportsFormat(const String&);
+
cairo_font_face_t* m_fontFace;
};
diff --git a/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp b/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
index 96cd4ee..f3fc943 100644
--- a/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
+++ b/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
@@ -4,6 +4,7 @@
* Copyright (C) 2008, 2009 Dirk Schulze <krit@webkit.org>
* Copyright (C) 2008 Nuanti Ltd.
* Copyright (C) 2009 Brent Fulgham <bfulgham@webkit.org>
+ * Copyright (C) 2010 Igalia S.L.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -143,6 +144,35 @@ static inline void copyContextProperties(cairo_t* srcCr, cairo_t* dstCr)
cairo_set_fill_rule(dstCr, cairo_get_fill_rule(srcCr));
}
+static void appendPathToCairoContext(cairo_t* to, cairo_t* from)
+{
+ cairo_path_t* cairoPath = cairo_copy_path(from);
+ cairo_append_path(to, cairoPath);
+ cairo_path_destroy(cairoPath);
+}
+
+// We apply the pending path built via addPath to the Cairo context
+// lazily. This prevents interaction between the path and other routines
+// such as fillRect.
+static void setPathOnCairoContext(cairo_t* to, cairo_t* from)
+{
+ cairo_new_path(to);
+ appendPathToCairoContext(to, from);
+}
+
+static void appendWebCorePathToCairoContext(cairo_t* context, const Path& path)
+{
+ appendPathToCairoContext(context, path.platformPath()->context());
+}
+
+static void addConvexPolygonToContext(cairo_t* context, size_t numPoints, const FloatPoint* points)
+{
+ cairo_move_to(context, points[0].x(), points[0].y());
+ for (size_t i = 1; i < numPoints; i++)
+ cairo_line_to(context, points[i].x(), points[i].y());
+ cairo_close_path(context);
+}
+
void GraphicsContext::calculateShadowBufferDimensions(IntSize& shadowBufferSize, FloatRect& shadowRect, float& kernelSize, const FloatRect& sourceRect, const FloatSize& shadowSize, float shadowBlur)
{
#if ENABLE(FILTERS)
@@ -201,6 +231,22 @@ static inline void drawPathShadow(GraphicsContext* context, GraphicsContextPriva
#endif
}
+static void fillCurrentCairoPath(GraphicsContext* context, GraphicsContextPrivate* gcp, cairo_t* cairoContext)
+{
+ cairo_set_fill_rule(cairoContext, context->fillRule() == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
+ drawPathShadow(context, gcp, true, false);
+
+ setPlatformFill(context, cairoContext, gcp);
+ cairo_new_path(cairoContext);
+}
+
+static void strokeCurrentCairoPath(GraphicsContext* context, GraphicsContextPrivate* gcp, cairo_t* cairoContext)
+{
+ drawPathShadow(context, gcp, false, true);
+ setPlatformStroke(context, cairoContext, gcp);
+ cairo_new_path(cairoContext);
+}
+
GraphicsContext::GraphicsContext(PlatformGraphicsContext* cr)
: m_common(createGraphicsContextPrivate())
, m_data(new GraphicsContextPlatformPrivate)
@@ -380,9 +426,8 @@ void GraphicsContext::drawEllipse(const IntRect& rect)
setColor(cr, strokeColor());
cairo_set_line_width(cr, strokeThickness());
cairo_stroke(cr);
- }
-
- cairo_new_path(cr);
+ } else
+ cairo_new_path(cr);
}
void GraphicsContext::strokeArc(const IntRect& rect, int startAngle, int angleSpan)
@@ -483,10 +528,7 @@ void GraphicsContext::drawConvexPolygon(size_t npoints, const FloatPoint* points
cairo_save(cr);
cairo_set_antialias(cr, shouldAntialias ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE);
- cairo_move_to(cr, points[0].x(), points[0].y());
- for (size_t i = 1; i < npoints; i++)
- cairo_line_to(cr, points[i].x(), points[i].y());
- cairo_close_path(cr);
+ addConvexPolygonToContext(cr, npoints, points);
if (fillColor().alpha()) {
setColor(cr, fillColor());
@@ -498,9 +540,9 @@ void GraphicsContext::drawConvexPolygon(size_t npoints, const FloatPoint* points
setColor(cr, strokeColor());
cairo_set_line_width(cr, strokeThickness());
cairo_stroke(cr);
- }
+ } else
+ cairo_new_path(cr);
- cairo_new_path(cr);
cairo_restore(cr);
}
@@ -511,8 +553,20 @@ void GraphicsContext::clipConvexPolygon(size_t numPoints, const FloatPoint* poin
if (numPoints <= 1)
return;
-
- // FIXME: IMPLEMENT!
+
+ cairo_t* cr = m_data->cr;
+
+ cairo_new_path(cr);
+ cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
+ cairo_antialias_t savedAntialiasRule = cairo_get_antialias(cr);
+
+ cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT);
+ cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING);
+ addConvexPolygonToContext(cr, numPoints, points);
+ cairo_clip(cr);
+
+ cairo_set_antialias(cr, savedAntialiasRule);
+ cairo_set_fill_rule(cr, savedFillRule);
}
void GraphicsContext::fillPath()
@@ -522,11 +576,8 @@ void GraphicsContext::fillPath()
cairo_t* cr = m_data->cr;
- cairo_set_fill_rule(cr, fillRule() == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
- drawPathShadow(this, m_common, true, false);
-
- setPlatformFill(this, cr, m_common);
- cairo_new_path(cr);
+ setPathOnCairoContext(cr, m_data->m_pendingPath.context());
+ fillCurrentCairoPath(this, m_common, cr);
}
void GraphicsContext::strokePath()
@@ -535,11 +586,8 @@ void GraphicsContext::strokePath()
return;
cairo_t* cr = m_data->cr;
- drawPathShadow(this, m_common, false, true);
-
- setPlatformStroke(this, cr, m_common);
- cairo_new_path(cr);
-
+ setPathOnCairoContext(cr, m_data->m_pendingPath.context());
+ strokeCurrentCairoPath(this, m_common, cr);
}
void GraphicsContext::drawPath()
@@ -549,6 +597,8 @@ void GraphicsContext::drawPath()
cairo_t* cr = m_data->cr;
+ setPathOnCairoContext(cr, m_data->m_pendingPath.context());
+
cairo_set_fill_rule(cr, fillRule() == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
drawPathShadow(this, m_common, true, true);
@@ -565,7 +615,7 @@ void GraphicsContext::fillRect(const FloatRect& rect)
cairo_t* cr = m_data->cr;
cairo_save(cr);
cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height());
- fillPath();
+ fillCurrentCairoPath(this, m_common, cr);
cairo_restore(cr);
}
@@ -673,7 +723,7 @@ void GraphicsContext::drawFocusRing(const Vector<IntRect>& rects, int width, int
#else
int radius = (width - 1) / 2;
for (unsigned i = 0; i < rectCount; i++)
- addPath(Path::createRoundedRectangle(rects[i], FloatSize(radius, radius)));
+ appendWebCorePathToCairoContext(cr, Path::createRoundedRectangle(rects[i], FloatSize(radius, radius)));
// Force the alpha to 50%. This matches what the Mac does with outline rings.
Color ringColor(color.red(), color.green(), color.blue(), 127);
@@ -700,14 +750,8 @@ void GraphicsContext::drawLineForText(const IntPoint& origin, int width, bool pr
if (paintingDisabled())
return;
- // This is a workaround for http://bugs.webkit.org/show_bug.cgi?id=15659
- StrokeStyle savedStrokeStyle = strokeStyle();
- setStrokeStyle(SolidStroke);
-
IntPoint endPoint = origin + IntSize(width, 0);
drawLine(origin, endPoint);
-
- setStrokeStyle(savedStrokeStyle);
}
#if !PLATFORM(GTK)
@@ -846,6 +890,7 @@ void GraphicsContext::addInnerRoundedRectClip(const IntRect& rect, int thickness
if (paintingDisabled())
return;
+ cairo_t* cr = m_data->cr;
clip(rect);
Path p;
@@ -855,9 +900,8 @@ void GraphicsContext::addInnerRoundedRectClip(const IntRect& rect, int thickness
// Add inner ellipse
r.inflate(-thickness);
p.addEllipse(r);
- addPath(p);
+ appendWebCorePathToCairoContext(cr, p);
- cairo_t* cr = m_data->cr;
cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
cairo_clip(cr);
@@ -968,7 +1012,7 @@ void GraphicsContext::strokeRect(const FloatRect& rect, float width)
cairo_save(cr);
cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height());
cairo_set_line_width(cr, width);
- strokePath();
+ strokeCurrentCairoPath(this, m_common, cr);
cairo_restore(cr);
}
@@ -1085,8 +1129,7 @@ void GraphicsContext::beginPath()
if (paintingDisabled())
return;
- cairo_t* cr = m_data->cr;
- cairo_new_path(cr);
+ cairo_new_path(m_data->m_pendingPath.context());
}
void GraphicsContext::addPath(const Path& path)
@@ -1094,10 +1137,10 @@ void GraphicsContext::addPath(const Path& path)
if (paintingDisabled())
return;
- cairo_t* cr = m_data->cr;
- cairo_path_t* p = cairo_copy_path(path.platformPath()->m_cr);
- cairo_append_path(cr, p);
- cairo_path_destroy(p);
+ cairo_matrix_t currentMatrix;
+ cairo_get_matrix(m_data->cr, &currentMatrix);
+ cairo_set_matrix(m_data->m_pendingPath.context(), &currentMatrix);
+ appendWebCorePathToCairoContext(m_data->m_pendingPath.context(), path);
}
void GraphicsContext::clip(const Path& path)
@@ -1106,7 +1149,7 @@ void GraphicsContext::clip(const Path& path)
return;
cairo_t* cr = m_data->cr;
- cairo_path_t* p = cairo_copy_path(path.platformPath()->m_cr);
+ cairo_path_t* p = cairo_copy_path(path.platformPath()->context());
cairo_append_path(cr, p);
cairo_path_destroy(p);
cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
@@ -1130,7 +1173,7 @@ void GraphicsContext::clipOut(const Path& path)
double x1, y1, x2, y2;
cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
cairo_rectangle(cr, x1, y1, x2 - x1, y2 - y1);
- addPath(path);
+ appendWebCorePathToCairoContext(cr, path);
cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
@@ -1189,8 +1232,7 @@ void GraphicsContext::fillRoundedRect(const IntRect& r, const IntSize& topLeft,
cairo_t* cr = m_data->cr;
cairo_save(cr);
- beginPath();
- addPath(Path::createRoundedRectangle(r, topLeft, topRight, bottomLeft, bottomRight));
+ appendWebCorePathToCairoContext(cr, Path::createRoundedRectangle(r, topLeft, topRight, bottomLeft, bottomRight));
setColor(cr, color);
drawPathShadow(this, m_common, true, false);
cairo_fill(cr);
diff --git a/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h b/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h
index 5e38832..97e7e07 100644
--- a/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h
+++ b/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h
@@ -95,6 +95,7 @@ public:
cairo_t* cr;
Vector<float> layers;
+ CairoPath m_pendingPath;
#if PLATFORM(GTK)
GdkEventExpose* expose;
diff --git a/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp b/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
index c298e18..1a43e54 100644
--- a/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
+++ b/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
@@ -277,6 +277,7 @@ void ImageBuffer::putPremultipliedImageData(ImageData* source, const IntRect& so
putImageData<Premultiplied>(source, sourceRect, destPoint, m_data, m_size);
}
+#if !PLATFORM(GTK)
static cairo_status_t writeFunction(void* closure, const unsigned char* data, unsigned int length)
{
Vector<char>* in = reinterpret_cast<Vector<char>*>(closure);
@@ -303,5 +304,6 @@ String ImageBuffer::toDataURL(const String& mimeType, const double*) const
return "data:" + actualMimeType + ";base64," + String(out.data(), out.size());
}
+#endif
} // namespace WebCore
diff --git a/WebCore/platform/graphics/cairo/PathCairo.cpp b/WebCore/platform/graphics/cairo/PathCairo.cpp
index d880626..05c6952 100644
--- a/WebCore/platform/graphics/cairo/PathCairo.cpp
+++ b/WebCore/platform/graphics/cairo/PathCairo.cpp
@@ -51,8 +51,8 @@ Path::~Path()
Path::Path(const Path& other)
: m_path(new CairoPath())
{
- cairo_t* cr = platformPath()->m_cr;
- cairo_path_t* p = cairo_copy_path(other.platformPath()->m_cr);
+ cairo_t* cr = platformPath()->context();
+ cairo_path_t* p = cairo_copy_path(other.platformPath()->context());
cairo_append_path(cr, p);
cairo_path_destroy(p);
}
@@ -63,8 +63,8 @@ Path& Path::operator=(const Path& other)
return *this;
clear();
- cairo_t* cr = platformPath()->m_cr;
- cairo_path_t* p = cairo_copy_path(other.platformPath()->m_cr);
+ cairo_t* cr = platformPath()->context();
+ cairo_path_t* p = cairo_copy_path(other.platformPath()->context());
cairo_append_path(cr, p);
cairo_path_destroy(p);
return *this;
@@ -72,13 +72,13 @@ Path& Path::operator=(const Path& other)
void Path::clear()
{
- cairo_t* cr = platformPath()->m_cr;
+ cairo_t* cr = platformPath()->context();
cairo_new_path(cr);
}
bool Path::isEmpty() const
{
- return !cairo_has_current_point(platformPath()->m_cr);
+ return !cairo_has_current_point(platformPath()->context());
}
bool Path::hasCurrentPoint() const
@@ -91,31 +91,31 @@ FloatPoint Path::currentPoint() const
// FIXME: Is this the correct way?
double x;
double y;
- cairo_get_current_point(platformPath()->m_cr, &x, &y);
+ cairo_get_current_point(platformPath()->context(), &x, &y);
return FloatPoint(x, y);
}
void Path::translate(const FloatSize& p)
{
- cairo_t* cr = platformPath()->m_cr;
+ cairo_t* cr = platformPath()->context();
cairo_translate(cr, -p.width(), -p.height());
}
void Path::moveTo(const FloatPoint& p)
{
- cairo_t* cr = platformPath()->m_cr;
+ cairo_t* cr = platformPath()->context();
cairo_move_to(cr, p.x(), p.y());
}
void Path::addLineTo(const FloatPoint& p)
{
- cairo_t* cr = platformPath()->m_cr;
+ cairo_t* cr = platformPath()->context();
cairo_line_to(cr, p.x(), p.y());
}
void Path::addRect(const FloatRect& rect)
{
- cairo_t* cr = platformPath()->m_cr;
+ cairo_t* cr = platformPath()->context();
cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height());
}
@@ -124,7 +124,7 @@ void Path::addRect(const FloatRect& rect)
*/
void Path::addQuadCurveTo(const FloatPoint& controlPoint, const FloatPoint& point)
{
- cairo_t* cr = platformPath()->m_cr;
+ cairo_t* cr = platformPath()->context();
double x, y;
double x1 = controlPoint.x();
double y1 = controlPoint.y();
@@ -139,7 +139,7 @@ void Path::addQuadCurveTo(const FloatPoint& controlPoint, const FloatPoint& poin
void Path::addBezierCurveTo(const FloatPoint& controlPoint1, const FloatPoint& controlPoint2, const FloatPoint& controlPoint3)
{
- cairo_t* cr = platformPath()->m_cr;
+ cairo_t* cr = platformPath()->context();
cairo_curve_to(cr, controlPoint1.x(), controlPoint1.y(),
controlPoint2.x(), controlPoint2.y(),
controlPoint3.x(), controlPoint3.y());
@@ -152,7 +152,7 @@ void Path::addArc(const FloatPoint& p, float r, float sa, float ea, bool anticlo
if (!isfinite(r) || !isfinite(sa) || !isfinite(ea))
return;
- cairo_t* cr = platformPath()->m_cr;
+ cairo_t* cr = platformPath()->context();
if (anticlockwise)
cairo_arc_negative(cr, p.x(), p.y(), r, sa, ea);
else
@@ -164,7 +164,7 @@ void Path::addArcTo(const FloatPoint& p1, const FloatPoint& p2, float radius)
if (isEmpty())
return;
- cairo_t* cr = platformPath()->m_cr;
+ cairo_t* cr = platformPath()->context();
double x0, y0;
cairo_get_current_point(cr, &x0, &y0);
@@ -237,7 +237,7 @@ void Path::addArcTo(const FloatPoint& p1, const FloatPoint& p2, float radius)
void Path::addEllipse(const FloatRect& rect)
{
- cairo_t* cr = platformPath()->m_cr;
+ cairo_t* cr = platformPath()->context();
cairo_save(cr);
float yRadius = .5 * rect.height();
float xRadius = .5 * rect.width();
@@ -249,13 +249,13 @@ void Path::addEllipse(const FloatRect& rect)
void Path::closeSubpath()
{
- cairo_t* cr = platformPath()->m_cr;
+ cairo_t* cr = platformPath()->context();
cairo_close_path(cr);
}
FloatRect Path::boundingRect() const
{
- cairo_t* cr = platformPath()->m_cr;
+ cairo_t* cr = platformPath()->context();
double x0, x1, y0, y1;
cairo_path_extents(cr, &x0, &y0, &x1, &y1);
return FloatRect(x0, y0, x1 - x0, y1 - y0);
@@ -263,7 +263,7 @@ FloatRect Path::boundingRect() const
FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier)
{
- cairo_t* cr = platformPath()->m_cr;
+ cairo_t* cr = platformPath()->context();
if (applier) {
GraphicsContext gc(cr);
applier->strokeStyle(&gc);
@@ -276,7 +276,7 @@ FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier)
bool Path::contains(const FloatPoint& point, WindRule rule) const
{
- cairo_t* cr = platformPath()->m_cr;
+ cairo_t* cr = platformPath()->context();
cairo_fill_rule_t cur = cairo_get_fill_rule(cr);
cairo_set_fill_rule(cr, rule == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
bool contains = cairo_in_fill(cr, point.x(), point.y());
@@ -287,7 +287,7 @@ bool Path::contains(const FloatPoint& point, WindRule rule) const
bool Path::strokeContains(StrokeStyleApplier* applier, const FloatPoint& point) const
{
ASSERT(applier);
- cairo_t* cr = platformPath()->m_cr;
+ cairo_t* cr = platformPath()->context();
GraphicsContext gc(cr);
applier->strokeStyle(&gc);
@@ -296,7 +296,7 @@ bool Path::strokeContains(StrokeStyleApplier* applier, const FloatPoint& point)
void Path::apply(void* info, PathApplierFunction function) const
{
- cairo_t* cr = platformPath()->m_cr;
+ cairo_t* cr = platformPath()->context();
cairo_path_t* path = cairo_copy_path(cr);
cairo_path_data_t* data;
PathElement pelement;
@@ -334,10 +334,10 @@ void Path::apply(void* info, PathApplierFunction function) const
void Path::transform(const AffineTransform& trans)
{
- cairo_t* m_cr = platformPath()->m_cr;
+ cairo_t* cr = platformPath()->context();
cairo_matrix_t c_matrix = cairo_matrix_t(trans);
cairo_matrix_invert(&c_matrix);
- cairo_transform(m_cr, &c_matrix);
+ cairo_transform(cr, &c_matrix);
}
String Path::debugString() const
@@ -346,7 +346,7 @@ String Path::debugString() const
return String();
String pathString;
- cairo_path_t* path = cairo_copy_path(platformPath()->m_cr);
+ cairo_path_t* path = cairo_copy_path(platformPath()->context());
cairo_path_data_t* data;
for (int i = 0; i < path->num_data; i += path->data[i].header.length) {
diff --git a/WebCore/platform/graphics/chromium/FontCustomPlatformData.cpp b/WebCore/platform/graphics/chromium/FontCustomPlatformData.cpp
index 74f1e26..b6d6e65 100644
--- a/WebCore/platform/graphics/chromium/FontCustomPlatformData.cpp
+++ b/WebCore/platform/graphics/chromium/FontCustomPlatformData.cpp
@@ -201,4 +201,13 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
#endif
}
+bool FontCustomPlatformData::supportsFormat(const String& format)
+{
+ return equalIgnoringCase(format, "truetype") || equalIgnoringCase(format, "opentype")
+#if ENABLE(OPENTYPE_SANITIZER)
+ || equalIgnoringCase(format, "woff")
+#endif
+ ;
+}
+
}
diff --git a/WebCore/platform/graphics/chromium/FontCustomPlatformData.h b/WebCore/platform/graphics/chromium/FontCustomPlatformData.h
index e1fbd48..03e1b8c 100644
--- a/WebCore/platform/graphics/chromium/FontCustomPlatformData.h
+++ b/WebCore/platform/graphics/chromium/FontCustomPlatformData.h
@@ -46,6 +46,7 @@ namespace WebCore {
class FontPlatformData;
class SharedBuffer;
+class String;
struct FontCustomPlatformData : Noncopyable {
#if OS(WINDOWS)
@@ -64,6 +65,8 @@ struct FontCustomPlatformData : Noncopyable {
FontPlatformData fontPlatformData(int size, bool bold, bool italic,
FontRenderingMode = NormalRenderingMode);
+ static bool supportsFormat(const String&);
+
#if OS(WINDOWS)
HANDLE m_fontReference;
String m_name;
diff --git a/WebCore/platform/graphics/chromium/GLES2Canvas.cpp b/WebCore/platform/graphics/chromium/GLES2Canvas.cpp
index ec188c8..9fc8917 100644
--- a/WebCore/platform/graphics/chromium/GLES2Canvas.cpp
+++ b/WebCore/platform/graphics/chromium/GLES2Canvas.cpp
@@ -99,6 +99,10 @@ GLES2Canvas::GLES2Canvas(GLES2Context* context, const IntSize& size)
m_stateStack.append(State());
m_state = &m_stateStack.last();
+
+ // Force the source over composite mode to be applied.
+ m_lastCompositeOp = CompositeClear;
+ applyCompositeOperator(CompositeSourceOver);
}
GLES2Canvas::~GLES2Canvas()
diff --git a/WebCore/platform/graphics/chromium/GLES2Canvas.h b/WebCore/platform/graphics/chromium/GLES2Canvas.h
index e3a7a3b..4e500be 100644
--- a/WebCore/platform/graphics/chromium/GLES2Canvas.h
+++ b/WebCore/platform/graphics/chromium/GLES2Canvas.h
@@ -42,6 +42,7 @@
#include <wtf/HashMap.h>
#include <wtf/Noncopyable.h>
+#include <wtf/Vector.h>
namespace WebCore {
diff --git a/WebCore/platform/graphics/gtk/CairoUtilities.cpp b/WebCore/platform/graphics/gtk/CairoUtilities.cpp
new file mode 100644
index 0000000..81e00f0
--- /dev/null
+++ b/WebCore/platform/graphics/gtk/CairoUtilities.cpp
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2010 Igalia S.L.
+ *
+ * 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.
+ */
+
+#include "config.h"
+#include "CairoUtilities.h"
+
+#include <cairo.h>
+#include <gtk/gtk.h>
+
+static inline unsigned char* getCairoSurfacePixel(unsigned char* data, unsigned x, unsigned y, unsigned rowStride)
+{
+ return data + (y * rowStride) + x * 4;
+}
+
+static inline guchar* getGdkPixbufPixel(guchar* data, unsigned x, unsigned y, unsigned rowStride)
+{
+ return data + (y * rowStride) + x * 4;
+}
+
+GdkPixbuf* cairoImageSurfaceToGdkPixbuf(cairo_surface_t* surface)
+{
+ int width = cairo_image_surface_get_width(surface);
+ int height = cairo_image_surface_get_height(surface);
+ unsigned char* surfaceData = cairo_image_surface_get_data(surface);
+ int surfaceRowStride = cairo_image_surface_get_stride(surface);
+
+ GdkPixbuf* dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
+ if (!dest)
+ return 0;
+
+ guchar* pixbufData = gdk_pixbuf_get_pixels(dest);
+ int pixbufRowStride = gdk_pixbuf_get_rowstride(dest);
+
+ /* From: http://cairographics.org/manual/cairo-image-surface.html#cairo-format-t
+ * "CAIRO_FORMAT_ARGB32: each pixel is a 32-bit quantity, with alpha in
+ * the upper 8 bits, then red, then green, then blue. The 32-bit
+ * quantities are stored native-endian. Pre-multiplied alpha is used.
+ * (That is, 50% transparent red is 0x80800000, not 0x80ff0000.)"
+ *
+ * See http://developer.gimp.org/api/2.0/gdk-pixbuf/gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf
+ * for information on the structure of GdkPixbufs stored with GDK_COLORSPACE_RGB.
+ *
+ * RGB color channels in CAIRO_FORMAT_ARGB32 are stored based on the
+ * endianness of the machine and are also multiplied by the alpha channel.
+ * To properly transfer the data from the Cairo surface we must divide each
+ * of the RGB channels by the alpha channel and then reorder all channels
+ * if this machine is little-endian.
+ */
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ unsigned char* source = getCairoSurfacePixel(surfaceData, x, y, surfaceRowStride);
+ guchar* dest = getGdkPixbufPixel(pixbufData, x, y, pixbufRowStride);
+
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+ guchar alpha = source[3];
+ dest[0] = alpha ? ((source[2] * 255) / alpha) : 0;
+ dest[1] = alpha ? ((source[1] * 255) / alpha) : 0;
+ dest[2] = alpha ? ((source[0] * 255) / alpha) : 0;
+ dest[3] = alpha;
+#else
+ guchar alpha = source[0];
+ dest[0] = alpha ? ((source[1] * 255) / alpha) : 0;
+ dest[1] = alpha ? ((source[2] * 255) / alpha) : 0;
+ dest[2] = alpha ? ((source[3] * 255) / alpha) : 0;
+ dest[3] = alpha;
+#endif
+ }
+ }
+
+ return dest;
+}
+
diff --git a/WebCore/platform/graphics/gtk/CairoUtilities.h b/WebCore/platform/graphics/gtk/CairoUtilities.h
new file mode 100644
index 0000000..89eb458
--- /dev/null
+++ b/WebCore/platform/graphics/gtk/CairoUtilities.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2010 Igalia S.L.
+ *
+ * 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 CairoUtilities_h
+#define CairoUtilities_h
+
+typedef struct _cairo_surface cairo_surface_t;
+typedef struct _GdkPixbuf GdkPixbuf;
+GdkPixbuf* cairoImageSurfaceToGdkPixbuf(cairo_surface_t* surface);
+
+#endif // CairoUtilities_h
diff --git a/WebCore/platform/graphics/gtk/FontCustomPlatformDataPango.cpp b/WebCore/platform/graphics/gtk/FontCustomPlatformDataPango.cpp
index 4f2f2bb..d5f3173 100644
--- a/WebCore/platform/graphics/gtk/FontCustomPlatformDataPango.cpp
+++ b/WebCore/platform/graphics/gtk/FontCustomPlatformDataPango.cpp
@@ -46,4 +46,9 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
return 0;
}
+bool FontCustomPlatformData::supportsFormat(const String& /* format */)
+{
+ return false;
+}
+
}
diff --git a/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp b/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp
new file mode 100644
index 0000000..d0b0274
--- /dev/null
+++ b/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2010 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+#include "config.h"
+#include "ImageBuffer.h"
+
+#include "Base64.h"
+#include "CairoUtilities.h"
+#include "GOwnPtr.h"
+#include "GRefPtrGtk.h"
+#include "MIMETypeRegistry.h"
+#include <cairo.h>
+#include <gtk/gtk.h>
+#include <wtf/text/CString.h>
+
+namespace WebCore {
+
+String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const
+{
+ ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
+
+ if (!mimeType.startsWith("image/"))
+ return "data:,";
+
+ // List of supported image types comes from the GdkPixbuf documentation.
+ // http://library.gnome.org/devel/gdk-pixbuf/stable/gdk-pixbuf-file-saving.html#gdk-pixbuf-save-to-bufferv
+ String type = mimeType.substring(sizeof "image");
+ if (type != "jpeg" && type != "png" && type != "tiff" && type != "ico" && type != "bmp")
+ return "data:,";
+
+ GRefPtr<GdkPixbuf> pixbuf = cairoImageSurfaceToGdkPixbuf(m_data.m_surface);
+ if (!pixbuf)
+ return "data:,";
+
+ GOwnPtr<gchar> buffer(0);
+ gsize bufferSize;
+ GError* error = 0;
+ gboolean success = FALSE;
+ if (type == "jpeg" && quality && *quality >= 0.0 && *quality <= 1.0) {
+ String qualityString = String::format("%f", *quality);
+ success = gdk_pixbuf_save_to_buffer(pixbuf.get(), &buffer.outPtr(), &bufferSize,
+ type.utf8().data(), &error, "quality", qualityString.utf8().data(), NULL);
+ } else {
+ success = gdk_pixbuf_save_to_buffer(pixbuf.get(), &buffer.outPtr(), &bufferSize, type.utf8().data(), &error, NULL);
+ }
+
+ if (!success)
+ return "data:,";
+
+ Vector<char> out;
+ base64Encode(reinterpret_cast<const char*>(buffer.get()), bufferSize, out);
+ out.append('\0');
+
+ return String::format("data:%s;base64,%s", mimeType.utf8().data(), out.data());
+}
+
+}
diff --git a/WebCore/platform/graphics/gtk/ImageGtk.cpp b/WebCore/platform/graphics/gtk/ImageGtk.cpp
index 3de8495..30db6d7 100644
--- a/WebCore/platform/graphics/gtk/ImageGtk.cpp
+++ b/WebCore/platform/graphics/gtk/ImageGtk.cpp
@@ -26,6 +26,7 @@
#include "config.h"
#include "BitmapImage.h"
+#include "CairoUtilities.h"
#include "GOwnPtr.h"
#include "SharedBuffer.h"
#include <wtf/text/CString.h>
@@ -172,67 +173,9 @@ PassRefPtr<Image> Image::loadPlatformThemeIcon(const char* name, int size)
return loadImageFromFile(getThemeIconFileName(name, size));
}
-static inline unsigned char* getCairoSurfacePixel(unsigned char* data, unsigned x, unsigned y, unsigned rowStride)
-{
- return data + (y * rowStride) + x * 4;
-}
-
-static inline guchar* getGdkPixbufPixel(guchar* data, unsigned x, unsigned y, unsigned rowStride)
-{
- return data + (y * rowStride) + x * 4;
-}
-
GdkPixbuf* BitmapImage::getGdkPixbuf()
{
- int width = cairo_image_surface_get_width(frameAtIndex(currentFrame()));
- int height = cairo_image_surface_get_height(frameAtIndex(currentFrame()));
- unsigned char* surfaceData = cairo_image_surface_get_data(frameAtIndex(currentFrame()));
- int surfaceRowStride = cairo_image_surface_get_stride(frameAtIndex(currentFrame()));
-
- GdkPixbuf* dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
- if (!dest)
- return 0;
-
- guchar* pixbufData = gdk_pixbuf_get_pixels(dest);
- int pixbufRowStride = gdk_pixbuf_get_rowstride(dest);
-
- /* From: http://cairographics.org/manual/cairo-image-surface.html#cairo-format-t
- * "CAIRO_FORMAT_ARGB32: each pixel is a 32-bit quantity, with alpha in
- * the upper 8 bits, then red, then green, then blue. The 32-bit
- * quantities are stored native-endian. Pre-multiplied alpha is used.
- * (That is, 50% transparent red is 0x80800000, not 0x80ff0000.)"
- *
- * See http://developer.gimp.org/api/2.0/gdk-pixbuf/gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf
- * for information on the structure of GdkPixbufs stored with GDK_COLORSPACE_RGB.
- *
- * RGB color channels in CAIRO_FORMAT_ARGB32 are stored based on the
- * endianness of the machine and are also multiplied by the alpha channel.
- * To properly transfer the data from the Cairo surface we must divide each
- * of the RGB channels by the alpha channel and then reorder all channels
- * if this machine is little-endian.
- */
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- unsigned char* source = getCairoSurfacePixel(surfaceData, x, y, surfaceRowStride);
- guchar* dest = getGdkPixbufPixel(pixbufData, x, y, pixbufRowStride);
-
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
- guchar alpha = source[3];
- dest[0] = alpha ? ((source[2] * 255) / alpha) : 0;
- dest[1] = alpha ? ((source[1] * 255) / alpha) : 0;
- dest[2] = alpha ? ((source[0] * 255) / alpha) : 0;
- dest[3] = alpha;
-#else
- guchar alpha = source[0];
- dest[0] = alpha ? ((source[1] * 255) / alpha) : 0;
- dest[1] = alpha ? ((source[2] * 255) / alpha) : 0;
- dest[2] = alpha ? ((source[3] * 255) / alpha) : 0;
- dest[3] = alpha;
-#endif
- }
- }
-
- return dest;
+ return cairoImageSurfaceToGdkPixbuf(frameAtIndex(currentFrame()));
}
}
diff --git a/WebCore/platform/graphics/haiku/FontCustomPlatformData.cpp b/WebCore/platform/graphics/haiku/FontCustomPlatformData.cpp
index 6008bb1..4b39fdd 100644
--- a/WebCore/platform/graphics/haiku/FontCustomPlatformData.cpp
+++ b/WebCore/platform/graphics/haiku/FontCustomPlatformData.cpp
@@ -42,4 +42,9 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
return 0;
}
+bool FontCustomPlatformData::supportsFormat(const String& /* format */)
+{
+ return false;
+}
+
}
diff --git a/WebCore/platform/graphics/haiku/FontCustomPlatformData.h b/WebCore/platform/graphics/haiku/FontCustomPlatformData.h
index c5a814e..9db6cc6 100644
--- a/WebCore/platform/graphics/haiku/FontCustomPlatformData.h
+++ b/WebCore/platform/graphics/haiku/FontCustomPlatformData.h
@@ -28,12 +28,15 @@ namespace WebCore {
class FontPlatformData;
class SharedBuffer;
+ class String;
struct FontCustomPlatformData : Noncopyable {
public:
FontCustomPlatformData() { }
~FontCustomPlatformData();
+ static bool supportsFormat(const String&);
+
FontPlatformData fontPlatformData(int size, bool bold, bool italic, FontRenderingMode = NormalRenderingMode);
};
diff --git a/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp b/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp
index 256b5a4..c591ddc 100644
--- a/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp
+++ b/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 Apple Computer, Inc.
+ * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -21,10 +21,11 @@
#include "config.h"
#include "FontCustomPlatformData.h"
-#include <ApplicationServices/ApplicationServices.h>
-#include "SharedBuffer.h"
#include "FontPlatformData.h"
#include "OpenTypeSanitizer.h"
+#include "SharedBuffer.h"
+#include "WOFFFileFormat.h"
+#include <ApplicationServices/ApplicationServices.h>
namespace WebCore {
@@ -50,6 +51,16 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
if (!transcodeBuffer)
return 0; // validation failed.
buffer = transcodeBuffer.get();
+#else
+ RefPtr<SharedBuffer> sfntBuffer;
+ if (isWOFF(buffer)) {
+ Vector<char> sfnt;
+ if (!convertWOFFToSfnt(buffer, sfnt))
+ return 0;
+
+ sfntBuffer = SharedBuffer::adoptVector(sfnt);
+ buffer = sfntBuffer.get();
+ }
#endif
ATSFontContainerRef containerRef = 0;
@@ -60,7 +71,7 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
RetainPtr<CFDataRef> bufferData(AdoptCF, buffer->createCFData());
RetainPtr<CGDataProviderRef> dataProvider(AdoptCF, CGDataProviderCreateWithCFData(bufferData.get()));
-
+
cgFontRef.adoptCF(CGFontCreateWithDataProvider(dataProvider.get()));
if (!cgFontRef)
return 0;
@@ -101,4 +112,9 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
return new FontCustomPlatformData(containerRef, fontRef, cgFontRef.releaseRef());
}
+bool FontCustomPlatformData::supportsFormat(const String& format)
+{
+ return equalIgnoringCase(format, "truetype") || equalIgnoringCase(format, "opentype") || equalIgnoringCase(format, "woff");
+}
+
}
diff --git a/WebCore/platform/graphics/mac/FontCustomPlatformData.h b/WebCore/platform/graphics/mac/FontCustomPlatformData.h
index 2c1222f..f2cd2cc 100644
--- a/WebCore/platform/graphics/mac/FontCustomPlatformData.h
+++ b/WebCore/platform/graphics/mac/FontCustomPlatformData.h
@@ -33,6 +33,7 @@ namespace WebCore {
class FontPlatformData;
class SharedBuffer;
+class String;
struct FontCustomPlatformData : Noncopyable {
FontCustomPlatformData(ATSFontContainerRef container, ATSFontRef atsFont, CGFontRef cgFont)
@@ -42,6 +43,8 @@ struct FontCustomPlatformData : Noncopyable {
FontPlatformData fontPlatformData(int size, bool bold, bool italic, FontRenderingMode = NormalRenderingMode);
+ static bool supportsFormat(const String&);
+
ATSFontContainerRef m_atsContainer;
ATSFontRef m_atsFont;
CGFontRef m_cgFont;
diff --git a/WebCore/platform/graphics/qt/FontCustomPlatformData.h b/WebCore/platform/graphics/qt/FontCustomPlatformData.h
index 0f2a6ce..6837059 100644
--- a/WebCore/platform/graphics/qt/FontCustomPlatformData.h
+++ b/WebCore/platform/graphics/qt/FontCustomPlatformData.h
@@ -27,8 +27,9 @@
namespace WebCore {
-class SharedBuffer;
class FontPlatformData;
+class SharedBuffer;
+class String;
struct FontCustomPlatformData : Noncopyable {
~FontCustomPlatformData();
@@ -37,6 +38,8 @@ struct FontCustomPlatformData : Noncopyable {
int m_handle;
FontPlatformData fontPlatformData(int size, bool bold, bool italic, FontRenderingMode = NormalRenderingMode);
+
+ static bool supportsFormat(const String&);
};
FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer);
diff --git a/WebCore/platform/graphics/qt/FontCustomPlatformDataQt.cpp b/WebCore/platform/graphics/qt/FontCustomPlatformDataQt.cpp
index 6e9d053..dbf0b16 100644
--- a/WebCore/platform/graphics/qt/FontCustomPlatformDataQt.cpp
+++ b/WebCore/platform/graphics/qt/FontCustomPlatformDataQt.cpp
@@ -61,5 +61,9 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
return data;
}
+bool FontCustomPlatformData::supportsFormat(const String& format)
+{
+ return equalIgnoringCase(format, "truetype") || equalIgnoringCase(format, "opentype");
}
+}
diff --git a/WebCore/platform/graphics/skia/ImageBufferSkia.cpp b/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
index 26c44f2..3eb033d 100644
--- a/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
+++ b/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
@@ -198,11 +198,13 @@ PassRefPtr<ImageData> getImageData(const IntRect& rect, const SkBitmap& bitmap,
PassRefPtr<ImageData> ImageBuffer::getUnmultipliedImageData(const IntRect& rect) const
{
+ context()->platformContext()->syncSoftwareCanvas();
return getImageData<Unmultiplied>(rect, *context()->platformContext()->bitmap(), m_size);
}
PassRefPtr<ImageData> ImageBuffer::getPremultipliedImageData(const IntRect& rect) const
{
+ context()->platformContext()->syncSoftwareCanvas();
return getImageData<Premultiplied>(rect, *context()->platformContext()->bitmap(), m_size);
}
diff --git a/WebCore/platform/graphics/skia/ImageSkia.cpp b/WebCore/platform/graphics/skia/ImageSkia.cpp
index d1d1692..a2485e6 100644
--- a/WebCore/platform/graphics/skia/ImageSkia.cpp
+++ b/WebCore/platform/graphics/skia/ImageSkia.cpp
@@ -47,6 +47,11 @@
#include "skia/ext/image_operations.h"
#include "skia/ext/platform_canvas.h"
+#if USE(GLES2_RENDERING)
+#include "GLES2Canvas.h"
+#include "GLES2Context.h"
+#include "SkPixelRef.h"
+#endif
namespace WebCore {
@@ -404,6 +409,24 @@ void Image::drawPattern(GraphicsContext* context,
context->platformContext()->paintSkPaint(destRect, paint);
}
+#if USE(GLES2_RENDERING)
+static void drawBitmapGLES2(GraphicsContext* ctxt, NativeImageSkia* bitmap, const FloatRect& srcRect, const FloatRect& dstRect, ColorSpace styleColorSpace, CompositeOperator compositeOp)
+{
+ ctxt->platformContext()->prepareForHardwareDraw();
+ GLES2Canvas* gpuCanvas = ctxt->platformContext()->gpuCanvas();
+ gpuCanvas->gles2Context()->makeCurrent();
+ GLES2Texture* texture = gpuCanvas->getTexture(bitmap);
+ if (!texture) {
+ ASSERT(bitmap->config() == SkBitmap::kARGB_8888_Config);
+ ASSERT(bitmap->rowBytes() == bitmap->width() * 4);
+ texture = gpuCanvas->createTexture(bitmap, GLES2Texture::BGRA8, bitmap->width(), bitmap->height());
+ ASSERT(bitmap->pixelRef());
+ texture->load(bitmap->pixelRef()->pixels());
+ }
+ gpuCanvas->drawTexturedRect(texture, srcRect, dstRect, styleColorSpace, compositeOp);
+}
+#endif
+
// ================================================
// BitmapImage Class
// ================================================
@@ -429,7 +452,7 @@ void BitmapImage::checkForSolidColor()
}
void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect,
- const FloatRect& srcRect, ColorSpace, CompositeOperator compositeOp)
+ const FloatRect& srcRect, ColorSpace colorSpace, CompositeOperator compositeOp)
{
if (!m_source.initialized())
return;
@@ -439,16 +462,24 @@ void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect,
// causing flicker and wasting CPU.
startAnimation();
- const NativeImageSkia* bm = nativeImageForCurrentFrame();
+ NativeImageSkia* bm = nativeImageForCurrentFrame();
if (!bm)
return; // It's too early and we don't have an image yet.
+#if USE(GLES2_RENDERING)
+ if (ctxt->platformContext()->useGPU()) {
+ drawBitmapGLES2(ctxt, bm, srcRect, dstRect, colorSpace, compositeOp);
+ return;
+ }
+#endif
FloatRect normDstRect = normalizeRect(dstRect);
FloatRect normSrcRect = normalizeRect(srcRect);
if (normSrcRect.isEmpty() || normDstRect.isEmpty())
return; // Nothing to draw.
+ ctxt->platformContext()->prepareForSoftwareDraw();
+
paintSkBitmap(ctxt->platformContext(),
*bm,
enclosingIntRect(normSrcRect),
@@ -470,6 +501,15 @@ void BitmapImageSingleFrameSkia::draw(GraphicsContext* ctxt,
if (normSrcRect.isEmpty() || normDstRect.isEmpty())
return; // Nothing to draw.
+#if USE(GLES2_RENDERING)
+ if (ctxt->platformContext()->useGPU()) {
+ drawBitmapGLES2(ctxt, &m_nativeImage, srcRect, dstRect, styleColorSpace, compositeOp);
+ return;
+ }
+#endif
+
+ ctxt->platformContext()->prepareForSoftwareDraw();
+
paintSkBitmap(ctxt->platformContext(),
m_nativeImage,
enclosingIntRect(normSrcRect),
diff --git a/WebCore/platform/graphics/win/FontCustomPlatformData.cpp b/WebCore/platform/graphics/win/FontCustomPlatformData.cpp
index e9f83ab..6e59ad7 100644
--- a/WebCore/platform/graphics/win/FontCustomPlatformData.cpp
+++ b/WebCore/platform/graphics/win/FontCustomPlatformData.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -26,6 +26,7 @@
#include "OpenTypeUtilities.h"
#include "SharedBuffer.h"
#include "SoftLinking.h"
+#include "WOFFFileFormat.h"
#include <ApplicationServices/ApplicationServices.h>
#include <WebKitSystemInterface/WebKitSystemInterface.h>
#include <wtf/RetainPtr.h>
@@ -167,6 +168,16 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
ASSERT_ARG(buffer, buffer);
ASSERT(T2embedLibrary());
+ RefPtr<SharedBuffer> sfntBuffer;
+ if (isWOFF(buffer)) {
+ Vector<char> sfnt;
+ if (!convertWOFFToSfnt(buffer, sfnt))
+ return 0;
+
+ sfntBuffer = SharedBuffer::adoptVector(sfnt);
+ buffer = sfntBuffer.get();
+ }
+
// Introduce the font to GDI. AddFontMemResourceEx cannot be used, because it will pollute the process's
// font namespace (Windows has no API for creating an HFONT from data without exposing the font to the
// entire process first). TTLoadEmbeddedFont lets us override the font family name, so using a unique name
@@ -200,4 +211,9 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
return new FontCustomPlatformData(fontReference, fontName);
}
+bool FontCustomPlatformData::supportsFormat(const String& format)
+{
+ return equalIgnoringCase(format, "truetype") || equalIgnoringCase(format, "opentype") || equalIgnoringCase(format, "woff");
+}
+
}
diff --git a/WebCore/platform/graphics/win/FontCustomPlatformData.h b/WebCore/platform/graphics/win/FontCustomPlatformData.h
index f75f12a..46ddbb5 100644
--- a/WebCore/platform/graphics/win/FontCustomPlatformData.h
+++ b/WebCore/platform/graphics/win/FontCustomPlatformData.h
@@ -31,6 +31,7 @@ namespace WebCore {
class FontPlatformData;
class SharedBuffer;
+class String;
struct FontCustomPlatformData : Noncopyable {
FontCustomPlatformData(HANDLE fontReference, const String& name)
@@ -43,6 +44,8 @@ struct FontCustomPlatformData : Noncopyable {
FontPlatformData fontPlatformData(int size, bool bold, bool italic, FontRenderingMode = NormalRenderingMode);
+ static bool supportsFormat(const String&);
+
HANDLE m_fontReference;
String m_name;
};
diff --git a/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp b/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp
index e54d85a..35839f5 100644
--- a/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp
+++ b/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp
@@ -58,4 +58,9 @@ FontCustomPlatformDataCairo* createFontCustomPlatformData(SharedBuffer* buffer)
return new FontCustomPlatformDataCairo(fontFace);
}
+bool FontCustomPlatformData::supportsFormat(const String& format)
+{
+ return equalIgnoringCase(format, "truetype") || equalIgnoringCase(format, "opentype");
+}
+
}
diff --git a/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.h b/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.h
index 87794b5..75fe3d1 100644
--- a/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.h
+++ b/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.h
@@ -29,6 +29,7 @@ namespace WebCore {
class FontPlatformData;
class SharedBuffer;
+class String;
struct FontCustomPlatformDataCairo : Noncopyable {
FontCustomPlatformDataCairo(cairo_font_face_t* fontFace)
@@ -39,6 +40,8 @@ struct FontCustomPlatformDataCairo : Noncopyable {
FontPlatformData fontPlatformData(int size, bool bold, bool italic);
+ static bool supportsFormat(const String&);
+
cairo_font_face_t* m_fontFace;
};
diff --git a/WebCore/platform/graphics/win/WKCACFLayer.cpp b/WebCore/platform/graphics/win/WKCACFLayer.cpp
index d3928f1..b5f3427 100644
--- a/WebCore/platform/graphics/win/WKCACFLayer.cpp
+++ b/WebCore/platform/graphics/win/WKCACFLayer.cpp
@@ -29,7 +29,6 @@
#include "WKCACFLayer.h"
-#include "WKCACFContextFlusher.h"
#include "WKCACFLayerRenderer.h"
#include <wtf/text/CString.h>
@@ -123,7 +122,6 @@ static CFStringRef toCACFFilterType(WKCACFLayer::FilterType type)
case WKCACFLayer::Linear: return kCACFFilterLinear;
case WKCACFLayer::Nearest: return kCACFFilterNearest;
case WKCACFLayer::Trilinear: return kCACFFilterTrilinear;
- case WKCACFLayer::Lanczos: return kCACFFilterLanczos;
default: return 0;
}
}
@@ -136,9 +134,6 @@ static WKCACFLayer::FilterType fromCACFFilterType(CFStringRef string)
if (CFEqual(string, kCACFFilterTrilinear))
return WKCACFLayer::Trilinear;
- if (CFEqual(string, kCACFFilterLanczos))
- return WKCACFLayer::Lanczos;
-
return WKCACFLayer::Linear;
}
@@ -180,15 +175,6 @@ void WKCACFLayer::setNeedsCommit()
{
WKCACFLayer* root = rootLayer();
- CACFContextRef context = CACFLayerGetContext(root->layer());
-
- // The context might now be set yet. This happens if a property gets set
- // before placing the layer in the tree. In this case we don't need to
- // worry about remembering the context because we will when the layer is
- // added to the tree.
- if (context)
- WKCACFContextFlusher::shared().addContext(context);
-
// Call setNeedsRender on the root layer, which will cause a render to
// happen in WKCACFLayerRenderer
root->setNeedsRender();
diff --git a/WebCore/platform/graphics/win/WKCACFLayer.h b/WebCore/platform/graphics/win/WKCACFLayer.h
index 5e8eb05..ed39297 100644
--- a/WebCore/platform/graphics/win/WKCACFLayer.h
+++ b/WebCore/platform/graphics/win/WKCACFLayer.h
@@ -56,7 +56,7 @@ protected:
class WKCACFLayer : public RefCounted<WKCACFLayer> {
public:
enum LayerType { Layer, TransformLayer };
- enum FilterType { Linear, Nearest, Trilinear, Lanczos };
+ enum FilterType { Linear, Nearest, Trilinear };
enum ContentsGravityType { Center, Top, Bottom, Left, Right, TopLeft, TopRight,
BottomLeft, BottomRight, Resize, ResizeAspect, ResizeAspectFill };
@@ -162,9 +162,6 @@ public:
virtual void setBounds(const CGRect&);
CGRect bounds() const { return CACFLayerGetBounds(layer()); }
- void setClearsContext(bool clears) { CACFLayerSetClearsContext(layer(), clears); setNeedsCommit(); }
- bool clearsContext() const { return CACFLayerGetClearsContext(layer()); }
-
void setContents(CFTypeRef contents) { CACFLayerSetContents(layer(), contents); setNeedsCommit(); }
CFTypeRef contents() const { return CACFLayerGetContents(layer()); }
@@ -180,9 +177,6 @@ public:
void setEdgeAntialiasingMask(uint32_t mask) { CACFLayerSetEdgeAntialiasingMask(layer(), mask); setNeedsCommit(); }
uint32_t edgeAntialiasingMask() const { return CACFLayerGetEdgeAntialiasingMask(layer()); }
- void setFilters(CFArrayRef filters) { CACFLayerSetFilters(layer(), filters); setNeedsCommit(); }
- CFArrayRef filters() const { return CACFLayerGetFilters(layer()); }
-
virtual void setFrame(const CGRect&);
CGRect frame() const { return CACFLayerGetFrame(layer()); }
@@ -226,9 +220,6 @@ public:
WKCACFLayer* rootLayer() const;
- void setSortsSublayers(bool sorts) { CACFLayerSetSortsSublayers(layer(), sorts); setNeedsCommit(); }
- bool sortsSublayers() const { return CACFLayerGetSortsSublayers(layer()); }
-
void setSublayerTransform(const CATransform3D& transform) { CACFLayerSetSublayerTransform(layer(), transform); setNeedsCommit(); }
CATransform3D sublayerTransform() const { return CACFLayerGetSublayerTransform(layer()); }
diff --git a/WebCore/platform/graphics/win/WKCACFLayerRenderer.cpp b/WebCore/platform/graphics/win/WKCACFLayerRenderer.cpp
index 0ee61f3..2a355c2 100644
--- a/WebCore/platform/graphics/win/WKCACFLayerRenderer.cpp
+++ b/WebCore/platform/graphics/win/WKCACFLayerRenderer.cpp
@@ -98,7 +98,7 @@ public:
return adoptRef(new WKCACFRootLayer(renderer));
}
- virtual void setNeedsRender() { m_renderer->renderSoon(); }
+ virtual void setNeedsRender() { m_renderer->layerTreeDidChange(); }
// Overload this to avoid calling setNeedsDisplay on the layer, which would override the contents
// we have placed on the root layer.
@@ -333,6 +333,12 @@ void WKCACFLayerRenderer::setRootChildLayer(WKCACFLayer* layer)
}
}
+void WKCACFLayerRenderer::layerTreeDidChange()
+{
+ WKCACFContextFlusher::shared().addContext(m_context.get());
+ renderSoon();
+}
+
void WKCACFLayerRenderer::setNeedsDisplay()
{
ASSERT(m_rootLayer);
diff --git a/WebCore/platform/graphics/win/WKCACFLayerRenderer.h b/WebCore/platform/graphics/win/WKCACFLayerRenderer.h
index 1ff955a..2647c5f 100644
--- a/WebCore/platform/graphics/win/WKCACFLayerRenderer.h
+++ b/WebCore/platform/graphics/win/WKCACFLayerRenderer.h
@@ -70,6 +70,7 @@ public:
void setRootContents(CGImageRef);
void setRootContentsAndDisplay(CGImageRef);
void setRootChildLayer(WKCACFLayer* layer);
+ void layerTreeDidChange();
void setNeedsDisplay();
void setHostWindow(HWND window) { m_hostWindow = window; }
void setBackingStoreDirty(bool dirty) { m_backingStoreDirty = dirty; }
diff --git a/WebCore/platform/graphics/wince/FontCustomPlatformData.cpp b/WebCore/platform/graphics/wince/FontCustomPlatformData.cpp
index f8a1e26..3605c72 100644
--- a/WebCore/platform/graphics/wince/FontCustomPlatformData.cpp
+++ b/WebCore/platform/graphics/wince/FontCustomPlatformData.cpp
@@ -83,4 +83,9 @@ FontCustomPlatformData* createFontCustomPlatformData(const SharedBuffer* buffer)
return 0;
}
+bool FontCustomPlatformData::supportsFormat(const String& format)
+{
+ return equalIgnoringCase(format, "truetype") || equalIgnoringCase(format, "opentype");
+}
+
}
diff --git a/WebCore/platform/graphics/wince/FontCustomPlatformData.h b/WebCore/platform/graphics/wince/FontCustomPlatformData.h
index 89d1fdd..5ce0ea6 100644
--- a/WebCore/platform/graphics/wince/FontCustomPlatformData.h
+++ b/WebCore/platform/graphics/wince/FontCustomPlatformData.h
@@ -45,6 +45,9 @@ namespace WebCore {
~FontCustomPlatformData();
FontPlatformData fontPlatformData(int size, bool bold, bool italic, FontRenderingMode = NormalRenderingMode);
+
+ static bool supportsFormat(const String&);
+
String m_name;
};