diff options
Diffstat (limited to 'WebCore/platform/graphics/cairo/ImageCairo.cpp')
-rw-r--r-- | WebCore/platform/graphics/cairo/ImageCairo.cpp | 70 |
1 files changed, 15 insertions, 55 deletions
diff --git a/WebCore/platform/graphics/cairo/ImageCairo.cpp b/WebCore/platform/graphics/cairo/ImageCairo.cpp index 904e819..8f7a194 100644 --- a/WebCore/platform/graphics/cairo/ImageCairo.cpp +++ b/WebCore/platform/graphics/cairo/ImageCairo.cpp @@ -31,7 +31,9 @@ #if PLATFORM(CAIRO) #include "AffineTransform.h" +#include "CairoUtilities.h" #include "Color.h" +#include "ContextShadow.h" #include "FloatRect.h" #include "PlatformRefPtrCairo.h" #include "GraphicsContext.h" @@ -133,29 +135,18 @@ void BitmapImage::draw(GraphicsContext* context, const FloatRect& dst, const Flo cairo_matrix_t matrix = { scaleX, 0, 0, scaleY, srcRect.x(), srcRect.y() }; cairo_pattern_set_matrix(pattern, &matrix); - // Draw the shadow -#if ENABLE(FILTERS) - FloatSize shadowOffset; - float shadowBlur; - Color shadowColor; - if (context->getShadow(shadowOffset, shadowBlur, shadowColor)) { - IntSize shadowBufferSize; - FloatRect shadowRect; - float radius = 0; - context->calculateShadowBufferDimensions(shadowBufferSize, shadowRect, radius, dstRect, shadowOffset, shadowBlur); - shadowColor = colorWithOverrideAlpha(shadowColor.rgb(), (shadowColor.alpha() * context->getAlpha()) / 255.f); - - //draw shadow into a new ImageBuffer - OwnPtr<ImageBuffer> shadowBuffer = ImageBuffer::create(shadowBufferSize); - cairo_t* shadowContext = shadowBuffer->context()->platformContext(); - cairo_set_source(shadowContext, pattern); - cairo_translate(shadowContext, -dstRect.x(), -dstRect.y()); - cairo_rectangle(shadowContext, 0, 0, dstRect.width(), dstRect.height()); - cairo_fill(shadowContext); - - context->applyPlatformShadow(shadowBuffer.release(), shadowColor, shadowRect, radius); + ContextShadow* shadow = context->contextShadow(); + ASSERT(shadow); + if (shadow->m_type != ContextShadow::NoShadow) { + cairo_t* shadowContext = shadow->beginShadowLayer(cr, dstRect); + if (shadowContext) { + cairo_translate(shadowContext, dstRect.x(), dstRect.y()); + cairo_set_source(shadowContext, pattern); + cairo_rectangle(shadowContext, 0, 0, dstRect.width(), dstRect.height()); + cairo_fill(shadowContext); + shadow->endShadowLayer(cr); + } } -#endif // Draw the image. cairo_translate(cr, dstRect.x(), dstRect.y()); @@ -172,46 +163,15 @@ void BitmapImage::draw(GraphicsContext* context, const FloatRect& dst, const Flo } void Image::drawPattern(GraphicsContext* context, const FloatRect& tileRect, const AffineTransform& patternTransform, - const FloatPoint& phase, ColorSpace, CompositeOperator op, const FloatRect& destRect) + const FloatPoint& phase, ColorSpace colorSpace, CompositeOperator op, const FloatRect& destRect) { cairo_surface_t* image = nativeImageForCurrentFrame(); 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(); - - PlatformRefPtr<cairo_surface_t> clippedImageSurface = 0; - if (tileRect.size() != size()) { - IntRect imageSize = enclosingIntRect(tileRect); - clippedImageSurface = adoptPlatformRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, imageSize.width(), imageSize.height())); - PlatformRefPtr<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); - cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT); - cairo_matrix_t pattern_matrix = cairo_matrix_t(patternTransform); - 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); - cairo_pattern_set_matrix(pattern, &combined); - - context->setCompositeOperation(op); - cairo_set_source(cr, pattern); - cairo_pattern_destroy(pattern); - cairo_rectangle(cr, destRect.x(), destRect.y(), destRect.width(), destRect.height()); - cairo_fill(cr); - - context->restore(); + drawPatternToCairoContext(cr, image, size(), tileRect, patternTransform, phase, toCairoOperator(op), destRect); if (imageObserver()) imageObserver()->didDraw(this); |