Show
Ignore:
Timestamp:
04/23/07 00:13:21 (21 months ago)
Author:
bdash
Message:

2007-04-23 Alp Toker <alp@atoker.com>

Reviewed by Hyatt.

  • platform/graphics/cairo/GraphicsContextCairo.cpp: (WebCore::GraphicsContext::drawEllipse): (WebCore::GraphicsContext::drawConvexPolygon): Fix stroking and filling of ellipses and polygons.
  • platform/graphics/cairo/ImageCairo.cpp: (WebCore::BitmapImage::draw): Make use of a new GraphicsContext function to simplify the code. (WebCore::Image::drawPattern): Now implemented. This makes content with tiled patterns (eg. CSS repeat) render correctly.
  • platform/graphics/gdk/ImageGdk.cpp: (WebCore::Image::drawPattern): Remove old stub.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/platform/graphics/cairo/ImageCairo.cpp

    r19481 r21022  
    11/* 
    22 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.  All rights reserved. 
     3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 
    34 * 
    45 * Redistribution and use in source and binary forms, with or without 
     
    2930#if PLATFORM(CAIRO) 
    3031 
     32#include "AffineTransform.h" 
    3133#include "FloatRect.h" 
    3234#include "GraphicsContext.h" 
     
    5254// Drawing Routines 
    5355 
    54 static void setCompositingOperation(cairo_t* context, CompositeOperator op, bool hasAlpha) 
    55 { 
    56     // FIXME: Add support for more operators. 
    57     // FIXME: This should really move to be a graphics context function once we have 
    58     // a C++ abstraction for GraphicsContext. 
    59     if (op == CompositeSourceOver && !hasAlpha) 
    60         op = CompositeCopy; 
    61  
    62     if (op == CompositeCopy) 
    63         cairo_set_operator(context, CAIRO_OPERATOR_SOURCE); 
    64     else 
    65         cairo_set_operator(context, CAIRO_OPERATOR_OVER); 
    66 } 
    67  
    6856void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst, const FloatRect& src, CompositeOperator op) 
    6957{ 
     
    8472 
    8573    // Set the compositing operation. 
    86     setCompositingOperation(context, op, frameHasAlphaAtIndex(m_currentFrame)); 
    87      
     74    if (op == CompositeSourceOver && !frameHasAlphaAtIndex(m_currentFrame)) 
     75        ctxt->setCompositeOperation(CompositeCopy); 
     76    else 
     77        ctxt->setCompositeOperation(op); 
     78 
    8879    // If we're drawing a sub portion of the image or scaling then create 
    8980    // a pattern transformation on the image and draw the transformed pattern. 
     
    10899} 
    109100 
     101void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const AffineTransform& patternTransform, 
     102                        const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect) 
     103{ 
     104    cairo_surface_t* image = nativeImageForCurrentFrame(); 
     105    if (!image) // If it's too early we won't have an image yet. 
     106        return; 
     107 
     108    cairo_t* context = ctxt->platformContext(); 
     109    ctxt->save(); 
     110 
     111    // TODO: Make use of tileRect. 
     112 
     113    cairo_pattern_t* pattern = cairo_pattern_create_for_surface(image); 
     114    cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT); 
     115 
     116    cairo_matrix_t pattern_matrix = cairo_matrix_t(patternTransform); 
     117    cairo_matrix_t phase_matrix = {1, 0, 0, 1, phase.x(), phase.y()}; 
     118    cairo_matrix_t combined; 
     119    cairo_matrix_multiply(&combined, &pattern_matrix, &phase_matrix); 
     120    cairo_matrix_invert(&combined); 
     121    cairo_pattern_set_matrix(pattern, &combined); 
     122 
     123    ctxt->setCompositeOperation(op); 
     124    cairo_set_source(context, pattern); 
     125    cairo_rectangle(context, destRect.x(), destRect.y(), destRect.width(), destRect.height()); 
     126    cairo_fill(context); 
     127 
     128    cairo_pattern_destroy(pattern); 
     129    ctxt->restore(); 
     130} 
     131 
    110132void BitmapImage::checkForSolidColor() 
    111133{