diff options
Diffstat (limited to 'WebCore/platform/graphics/cairo/ImageCairo.cpp')
-rw-r--r-- | WebCore/platform/graphics/cairo/ImageCairo.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/WebCore/platform/graphics/cairo/ImageCairo.cpp b/WebCore/platform/graphics/cairo/ImageCairo.cpp index 224154e..7c34e6f 100644 --- a/WebCore/platform/graphics/cairo/ImageCairo.cpp +++ b/WebCore/platform/graphics/cairo/ImageCairo.cpp @@ -33,10 +33,12 @@ #include "Color.h" #include "FloatRect.h" #include "GraphicsContext.h" +#include "ImageBuffer.h" #include "ImageObserver.h" #include "TransformationMatrix.h" #include <cairo.h> #include <math.h> +#include <wtf/OwnPtr.h> namespace WebCore { @@ -89,15 +91,19 @@ BitmapImage::BitmapImage(cairo_surface_t* surface, ImageObserver* observer) void BitmapImage::draw(GraphicsContext* context, const FloatRect& dst, const FloatRect& src, CompositeOperator op) { + FloatRect srcRect(src); + FloatRect dstRect(dst); + + if (dstRect.width() == 0.0f || dstRect.height() == 0.0f || + srcRect.width() == 0.0f || srcRect.height() == 0.0f) + return; + startAnimation(); cairo_surface_t* image = frameAtIndex(m_currentFrame); if (!image) // If it's too early we won't have an image yet. return; - FloatRect srcRect(src); - FloatRect dstRect(dst); - if (mayFillWithSolidColor()) { fillWithSolidColor(context, dstRect, solidColor(), op); return; @@ -106,7 +112,7 @@ void BitmapImage::draw(GraphicsContext* context, const FloatRect& dst, const Flo IntSize selfSize = size(); cairo_t* cr = context->platformContext(); - cairo_save(cr); + context->save(); // Set the compositing operation. if (op == CompositeSourceOver && !frameHasAlphaAtIndex(m_currentFrame)) @@ -138,7 +144,7 @@ void BitmapImage::draw(GraphicsContext* context, const FloatRect& dst, const Flo cairo_clip(cr); cairo_paint_with_alpha(cr, context->getAlpha()); - cairo_restore(cr); + context->restore(); if (imageObserver()) imageObserver()->didDraw(this); @@ -154,7 +160,18 @@ void Image::drawPattern(GraphicsContext* context, const FloatRect& tileRect, con cairo_t* cr = context->platformContext(); context->save(); - // TODO: Make use of tileRect. + IntRect imageSize = enclosingIntRect(tileRect); + OwnPtr<ImageBuffer> imageSurface = ImageBuffer::create(imageSize.size(), false); + + if (!imageSurface) + return; + + 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(); + } cairo_pattern_t* pattern = cairo_pattern_create_for_surface(image); cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT); @@ -163,7 +180,7 @@ void Image::drawPattern(GraphicsContext* context, const FloatRect& tileRect, con cairo_pattern_set_filter(pattern, CAIRO_FILTER_NEAREST); cairo_matrix_t pattern_matrix = cairo_matrix_t(patternTransform); - cairo_matrix_t phase_matrix = {1, 0, 0, 1, phase.x(), phase.y()}; + cairo_matrix_t phase_matrix = {1, 0, 0, 1, phase.x() + tileRect.x() * patternTransform.a(), phase.y() + tileRect.y() * patternTransform.d()}; cairo_matrix_t combined; cairo_matrix_multiply(&combined, &pattern_matrix, &phase_matrix); cairo_matrix_invert(&combined); |