diff options
author | Ben Murdoch <benm@google.com> | 2009-08-11 17:01:47 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2009-08-11 18:21:02 +0100 |
commit | 0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5 (patch) | |
tree | 2943df35f62d885c89d01063cc528dd73b480fea /WebCore/platform/graphics/cairo | |
parent | 7e7a70bfa49a1122b2597a1e6367d89eb4035eca (diff) | |
download | external_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.zip external_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.tar.gz external_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.tar.bz2 |
Merge in WebKit r47029.
Diffstat (limited to 'WebCore/platform/graphics/cairo')
6 files changed, 71 insertions, 25 deletions
diff --git a/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp b/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp index 23f30f3..5765546 100644 --- a/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp +++ b/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp @@ -62,15 +62,6 @@ namespace WebCore { -static const unsigned aquaFocusRingColor = 0xFF7DADD9; - -Color focusRingColor() -{ - static Color focusRingColor = aquaFocusRingColor; - - return focusRingColor; -} - static inline void setColor(cairo_t* cr, const Color& col) { float red, green, blue, alpha; diff --git a/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h b/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h index 531ebf4..54e1217 100644 --- a/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h +++ b/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h @@ -65,6 +65,7 @@ public: // On Windows, we need to update the HDC for form controls to draw in the right place. void save(); void restore(); + void flush(); void clip(const FloatRect&); void clip(const Path&); void scale(const FloatSize&); @@ -78,6 +79,7 @@ public: // On everything else, we do nothing. void save() {} void restore() {} + void flush() {} void clip(const FloatRect&) {} void clip(const Path&) {} void scale(const FloatSize&) {} diff --git a/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp b/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp index d2652d6..c905ee8 100644 --- a/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp +++ b/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp @@ -39,9 +39,29 @@ #include <cairo.h> #include <wtf/Vector.h> +#include <math.h> using namespace std; +// Cairo doesn't provide a way to copy a cairo_surface_t. +// See http://lists.cairographics.org/archives/cairo/2007-June/010877.html +// Once cairo provides the way, use the function instead of this. +static inline cairo_surface_t* copySurface(cairo_surface_t* surface) +{ + cairo_format_t format = cairo_image_surface_get_format(surface); + int width = cairo_image_surface_get_width(surface); + int height = cairo_image_surface_get_height(surface); + cairo_surface_t* newsurface = cairo_image_surface_create(format, width, height); + + cairo_t* cr = cairo_create(newsurface); + cairo_set_source_surface(cr, surface, 0, 0); + cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); + cairo_paint(cr); + cairo_destroy(cr); + + return newsurface; +} + namespace WebCore { ImageBufferData::ImageBufferData(const IntSize& size) @@ -49,7 +69,7 @@ ImageBufferData::ImageBufferData(const IntSize& size) { } -ImageBuffer::ImageBuffer(const IntSize& size, bool grayScale, bool& success) +ImageBuffer::ImageBuffer(const IntSize& size, ImageColorSpace imageColorSpace, bool& success) : m_data(size) , m_size(size) { @@ -82,12 +102,42 @@ Image* ImageBuffer::image() const // It's assumed that if image() is called, the actual rendering to the // GraphicsContext must be done. ASSERT(context()); + + // This creates a COPY of the image and will cache that copy. This means + // that if subsequent operations take place on the context, neither the + // currently-returned image, nor the results of future image() calls, + // will contain that operation. + // + // This seems silly, but is the way the CG port works: image() is + // intended to be used only when rendering is "complete." + cairo_surface_t* newsurface = copySurface(m_data.m_surface); + // BitmapImage will release the passed in surface on destruction - m_image = BitmapImage::create(cairo_surface_reference(m_data.m_surface)); + m_image = BitmapImage::create(newsurface); } return m_image.get(); } +void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable) +{ + ASSERT(cairo_surface_get_type(m_data.m_surface) == CAIRO_SURFACE_TYPE_IMAGE); + + unsigned char* dataSrc = cairo_image_surface_get_data(m_data.m_surface); + int stride = cairo_image_surface_get_stride(m_data.m_surface); + for (int y = 0; y < m_size.height(); ++y) { + unsigned* row = reinterpret_cast<unsigned*>(dataSrc + stride * y); + for (int x = 0; x < m_size.width(); x++) { + unsigned* pixel = row + x; + Color pixelColor = colorFromPremultipliedARGB(*pixel); + pixelColor = Color(lookUpTable[pixelColor.red()], + lookUpTable[pixelColor.green()], + lookUpTable[pixelColor.blue()], + lookUpTable[pixelColor.alpha()]); + *pixel = premultipliedARGBFromColor(pixelColor); + } + } +} + PassRefPtr<ImageData> ImageBuffer::getImageData(const IntRect& rect) const { ASSERT(cairo_surface_get_type(m_data.m_surface) == CAIRO_SURFACE_TYPE_IMAGE); diff --git a/WebCore/platform/graphics/cairo/ImageCairo.cpp b/WebCore/platform/graphics/cairo/ImageCairo.cpp index 7c34e6f..c8c992e 100644 --- a/WebCore/platform/graphics/cairo/ImageCairo.cpp +++ b/WebCore/platform/graphics/cairo/ImageCairo.cpp @@ -157,11 +157,15 @@ void Image::drawPattern(GraphicsContext* context, const FloatRect& tileRect, con if (!image) // If it's too early we won't have an image yet. return; + // Avoid NaN + if (!isfinite(phase.x()) || !isfinite(phase.y())) + return; + cairo_t* cr = context->platformContext(); context->save(); IntRect imageSize = enclosingIntRect(tileRect); - OwnPtr<ImageBuffer> imageSurface = ImageBuffer::create(imageSize.size(), false); + OwnPtr<ImageBuffer> imageSurface = ImageBuffer::create(imageSize.size()); if (!imageSurface) return; diff --git a/WebCore/platform/graphics/cairo/ImageSourceCairo.cpp b/WebCore/platform/graphics/cairo/ImageSourceCairo.cpp index b51caf6..df62618 100644 --- a/WebCore/platform/graphics/cairo/ImageSourceCairo.cpp +++ b/WebCore/platform/graphics/cairo/ImageSourceCairo.cpp @@ -34,13 +34,10 @@ #include "ICOImageDecoder.h" #include "JPEGImageDecoder.h" #include "PNGImageDecoder.h" +#include "XBMImageDecoder.h" #include "SharedBuffer.h" #include <cairo.h> -#if !PLATFORM(WIN) -#include "XBMImageDecoder.h" -#endif - namespace WebCore { ImageDecoder* createDecoder(const Vector<char>& data) @@ -80,11 +77,9 @@ ImageDecoder* createDecoder(const Vector<char>& data) !memcmp(contents, "\000\000\002\000", 4)) return new ICOImageDecoder(); -#if !PLATFORM(WIN) // XBMs require 8 bytes of info. if (length >= 8 && strncmp(contents, "#define ", 8) == 0) return new XBMImageDecoder(); -#endif // Give up. We don't know what the heck this is. return 0; @@ -158,9 +153,12 @@ IntSize ImageSource::size() const return m_decoder->size(); } -IntSize ImageSource::frameSizeAtIndex(size_t) const +IntSize ImageSource::frameSizeAtIndex(size_t index) const { - return size(); + if (!m_decoder) + return IntSize(); + + return m_decoder->frameSizeAtIndex(index); } int ImageSource::repetitionCount() @@ -193,11 +191,7 @@ NativeImagePtr ImageSource::createFrameAtIndex(size_t index) if (!size().height()) return 0; - return cairo_image_surface_create_for_data((unsigned char*)buffer->bytes().data(), - CAIRO_FORMAT_ARGB32, - size().width(), - size().height(), - size().width()*4); + return buffer->asNewNativeImage(); } bool ImageSource::frameIsCompleteAtIndex(size_t index) diff --git a/WebCore/platform/graphics/cairo/PathCairo.cpp b/WebCore/platform/graphics/cairo/PathCairo.cpp index 13ca1e2..75681bd 100644 --- a/WebCore/platform/graphics/cairo/PathCairo.cpp +++ b/WebCore/platform/graphics/cairo/PathCairo.cpp @@ -89,6 +89,11 @@ bool Path::isEmpty() const #endif } +bool Path::hasCurrentPoint() const +{ + return !isEmpty(); +} + void Path::translate(const FloatSize& p) { cairo_t* cr = platformPath()->m_cr; |