summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics/cairo
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/graphics/cairo')
-rw-r--r--WebCore/platform/graphics/cairo/GRefPtrCairo.cpp52
-rw-r--r--WebCore/platform/graphics/cairo/GRefPtrCairo.h38
-rw-r--r--WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp12
-rw-r--r--WebCore/platform/graphics/cairo/ImageBufferCairo.cpp47
-rw-r--r--WebCore/platform/graphics/cairo/ImageCairo.cpp18
5 files changed, 128 insertions, 39 deletions
diff --git a/WebCore/platform/graphics/cairo/GRefPtrCairo.cpp b/WebCore/platform/graphics/cairo/GRefPtrCairo.cpp
new file mode 100644
index 0000000..d244954
--- /dev/null
+++ b/WebCore/platform/graphics/cairo/GRefPtrCairo.cpp
@@ -0,0 +1,52 @@
+/*
+ * 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 "GRefPtrCairo.h"
+
+#include <cairo.h>
+
+namespace WTF {
+
+template <> cairo_t* refGPtr(cairo_t* ptr)
+{
+ if (ptr)
+ cairo_reference(ptr);
+ return ptr;
+}
+
+template <> void derefGPtr(cairo_t* ptr)
+{
+ if (ptr)
+ cairo_destroy(ptr);
+}
+
+template <> cairo_surface_t* refGPtr(cairo_surface_t* ptr)
+{
+ if (ptr)
+ cairo_surface_reference(ptr);
+ return ptr;
+}
+
+template <> void derefGPtr(cairo_surface_t* ptr)
+{
+ if (ptr)
+ cairo_surface_destroy(ptr);
+}
+
+}
diff --git a/WebCore/platform/graphics/cairo/GRefPtrCairo.h b/WebCore/platform/graphics/cairo/GRefPtrCairo.h
new file mode 100644
index 0000000..aef51fe
--- /dev/null
+++ b/WebCore/platform/graphics/cairo/GRefPtrCairo.h
@@ -0,0 +1,38 @@
+/*
+ * 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
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef GRefPtrCairo_h
+#define GRefPtrCairo_h
+
+#include "GRefPtr.h"
+
+typedef struct _cairo cairo_t;
+typedef struct _cairo_surface cairo_surface_t;
+
+namespace WTF {
+
+template <> cairo_t* refGPtr(cairo_t* ptr);
+template <> void derefGPtr(cairo_t* ptr);
+
+template <> cairo_surface_t* refGPtr(cairo_surface_t* ptr);
+template <> void derefGPtr(cairo_surface_t* ptr);
+
+}
+
+#endif
diff --git a/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp b/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
index f3fc943..9b3096e 100644
--- a/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
+++ b/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
@@ -908,14 +908,6 @@ void GraphicsContext::addInnerRoundedRectClip(const IntRect& rect, int thickness
cairo_set_fill_rule(cr, savedFillRule);
}
-void GraphicsContext::clipToImageBuffer(const FloatRect& rect, const ImageBuffer* imageBuffer)
-{
- if (paintingDisabled())
- return;
-
- notImplemented();
-}
-
void GraphicsContext::setPlatformShadow(FloatSize const& size, float, Color const&, ColorSpace)
{
// Cairo doesn't support shadows natively, they are drawn manually in the draw*
@@ -936,7 +928,7 @@ void GraphicsContext::createPlatformShadow(PassOwnPtr<ImageBuffer> buffer, const
// draw the shadow without blurring, if kernelSize is zero
if (!kernelSize) {
setColor(cr, shadowColor);
- cairo_mask_surface(cr, buffer->image()->nativeImageForCurrentFrame(), shadowRect.x(), shadowRect.y());
+ cairo_mask_surface(cr, buffer->m_data.m_surface, shadowRect.x(), shadowRect.y());
return;
}
@@ -956,7 +948,7 @@ void GraphicsContext::createPlatformShadow(PassOwnPtr<ImageBuffer> buffer, const
// Mask the filter with the shadow color and draw it to the context.
// Masking makes it possible to just blur the alpha channel.
setColor(cr, shadowColor);
- cairo_mask_surface(cr, blur->resultImage()->image()->nativeImageForCurrentFrame(), shadowRect.x(), shadowRect.y());
+ cairo_mask_surface(cr, blur->resultImage()->m_data.m_surface, shadowRect.x(), shadowRect.y());
#endif
}
diff --git a/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp b/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
index 1a43e54..db66276 100644
--- a/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
+++ b/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
@@ -35,6 +35,7 @@
#include "GraphicsContext.h"
#include "ImageData.h"
#include "MIMETypeRegistry.h"
+#include "NotImplemented.h"
#include "Pattern.h"
#include "PlatformString.h"
@@ -97,26 +98,34 @@ GraphicsContext* ImageBuffer::context() const
return m_context.get();
}
-Image* ImageBuffer::image() const
+bool ImageBuffer::drawsUsingCopy() const
{
- if (!m_image) {
- // 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(newsurface);
- }
- return m_image.get();
+ return true;
+}
+
+PassRefPtr<Image> ImageBuffer::copyImage() const
+{
+ // BitmapImage will release the passed in surface on destruction
+ return BitmapImage::create(copySurface(m_data.m_surface));
+}
+
+void ImageBuffer::clip(GraphicsContext*, const FloatRect&) const
+{
+ notImplemented();
+}
+
+void ImageBuffer::draw(GraphicsContext* context, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect,
+ CompositeOperator op , bool useLowQualityScale)
+{
+ RefPtr<Image> imageCopy = copyImage();
+ context->drawImage(imageCopy.get(), styleColorSpace, destRect, srcRect, op, useLowQualityScale);
+}
+
+void ImageBuffer::drawPattern(GraphicsContext* context, const FloatRect& srcRect, const AffineTransform& patternTransform,
+ const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect)
+{
+ RefPtr<Image> imageCopy = copyImage();
+ imageCopy->drawPattern(context, srcRect, patternTransform, phase, styleColorSpace, op, destRect);
}
void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable)
diff --git a/WebCore/platform/graphics/cairo/ImageCairo.cpp b/WebCore/platform/graphics/cairo/ImageCairo.cpp
index 64fbedf..1582671 100644
--- a/WebCore/platform/graphics/cairo/ImageCairo.cpp
+++ b/WebCore/platform/graphics/cairo/ImageCairo.cpp
@@ -33,6 +33,7 @@
#include "AffineTransform.h"
#include "Color.h"
#include "FloatRect.h"
+#include "GRefPtrCairo.h"
#include "GraphicsContext.h"
#include "ImageBuffer.h"
#include "ImageObserver.h"
@@ -184,17 +185,14 @@ void Image::drawPattern(GraphicsContext* context, const FloatRect& tileRect, con
cairo_t* cr = context->platformContext();
context->save();
- IntRect imageSize = enclosingIntRect(tileRect);
- OwnPtr<ImageBuffer> imageSurface = ImageBuffer::create(imageSize.size());
-
- if (!imageSurface)
- return;
-
+ GRefPtr<cairo_surface_t> clippedImageSurface = 0;
if (tileRect.size() != size()) {
- cairo_t* clippedImageContext = imageSurface->context()->platformContext();
- cairo_set_source_surface(clippedImageContext, image, -tileRect.x(), -tileRect.y());
- cairo_paint(clippedImageContext);
- image = imageSurface->image()->nativeImageForCurrentFrame();
+ IntRect imageSize = enclosingIntRect(tileRect);
+ clippedImageSurface = adoptGRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, imageSize.width(), imageSize.height()));
+ GRefPtr<cairo_t> clippedImageContext(cairo_create(clippedImageSurface.get()));
+ cairo_set_source_surface(clippedImageContext.get(), image, -tileRect.x(), -tileRect.y());
+ cairo_paint(clippedImageContext.get());
+ image = clippedImageSurface.get();
}
cairo_pattern_t* pattern = cairo_pattern_create_for_surface(image);