Changeset 28971 in webkit


Ignore:
Timestamp:
Dec 23, 2007 7:04:19 PM (16 years ago)
Author:
alp@webkit.org
Message:

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

Reviewed by Holger Freyther.

http://bugs.webkit.org/show_bug.cgi?id=15382
[CAIRO] Canvas pattern support

http://bugs.webkit.org/show_bug.cgi?id=16577
Merge Cairo enhancements from Apollo project

Add support for canvas patterns.

Make Image::nativeImageForCurrentFrame() public.

Fix some typos along the way.

The globalAlpha canvas fixes are not included in this patch as
they're slightly more intrusive and may conflict conceptually with
GraphicsContext::setAlpha().

  • html/CanvasPattern.cpp: (WebCore::CanvasPattern::CanvasPattern): (WebCore::CanvasPattern::~CanvasPattern): (WebCore::CanvasPattern::createPattern):
  • html/CanvasPattern.h: (WebCore::CanvasPattern::platformImage):
  • html/CanvasRenderingContext2D.cpp: (WebCore::CanvasRenderingContext2D::setShadow): (WebCore::CanvasRenderingContext2D::applyShadow): (WebCore::CanvasRenderingContext2D::drawImage): (WebCore::CanvasRenderingContext2D::createPattern): (WebCore::CanvasRenderingContext2D::applyStrokePattern): (WebCore::CanvasRenderingContext2D::applyFillPattern):
  • platform/graphics/Image.h: (WebCore::Image::nativeImageForCurrentFrame):
Location:
trunk/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r28970 r28971  
     12007-12-23  Alp Toker  <alp@atoker.com>
     2
     3        Reviewed by Holger Freyther.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=15382
     6        [CAIRO] Canvas pattern support
     7
     8        http://bugs.webkit.org/show_bug.cgi?id=16577
     9        Merge Cairo enhancements from Apollo project
     10
     11        Add support for canvas patterns.
     12
     13        Make Image::nativeImageForCurrentFrame() public.
     14
     15        Fix some typos along the way.
     16
     17        The globalAlpha canvas fixes are not included in this patch as
     18        they're slightly more intrusive and may conflict conceptually with
     19        GraphicsContext::setAlpha().
     20
     21        * html/CanvasPattern.cpp:
     22        (WebCore::CanvasPattern::CanvasPattern):
     23        (WebCore::CanvasPattern::~CanvasPattern):
     24        (WebCore::CanvasPattern::createPattern):
     25        * html/CanvasPattern.h:
     26        (WebCore::CanvasPattern::platformImage):
     27        * html/CanvasRenderingContext2D.cpp:
     28        (WebCore::CanvasRenderingContext2D::setShadow):
     29        (WebCore::CanvasRenderingContext2D::applyShadow):
     30        (WebCore::CanvasRenderingContext2D::drawImage):
     31        (WebCore::CanvasRenderingContext2D::createPattern):
     32        (WebCore::CanvasRenderingContext2D::applyStrokePattern):
     33        (WebCore::CanvasRenderingContext2D::applyFillPattern):
     34        * platform/graphics/Image.h:
     35        (WebCore::Image::nativeImageForCurrentFrame):
     36
    1372007-12-23  Kevin Ollivier  <kevino@theolliviers.com>
    238
  • trunk/WebCore/html/CanvasPattern.cpp

    r25124 r28971  
    7474}
    7575
     76#elif PLATFORM(CAIRO)
     77
     78CanvasPattern::CanvasPattern(cairo_surface_t* surface, bool repeatX, bool repeatY)
     79    : m_platformImage(surface)
     80    , m_cachedImage(0)
     81    , m_repeatX(repeatX)
     82    , m_repeatY(repeatY)
     83{
     84}
     85
    7686#endif
    7787
    7888CanvasPattern::CanvasPattern(CachedImage* cachedImage, bool repeatX, bool repeatY)
    7989    :
    80 #if PLATFORM(CG)
     90#if PLATFORM(CG) || PLATFORM(CAIRO)
    8191      m_platformImage(0)
    8292    ,
     
    92102CanvasPattern::~CanvasPattern()
    93103{
     104#if PLATFORM(CAIRO)
     105    if (m_platformImage)
     106        cairo_surface_destroy(m_platformImage);
     107#endif
    94108    if (m_cachedImage)
    95109        m_cachedImage->deref(this);
     
    169183}
    170184
    171 #endif
    172 
    173 }
     185#elif PLATFORM(CAIRO)
     186
     187cairo_pattern_t* CanvasPattern::createPattern(const cairo_matrix_t& m)
     188{
     189    cairo_surface_t* surface = 0;
     190    if (m_platformImage) {
     191        surface = m_platformImage;
     192    } else {
     193        if (!m_cachedImage)
     194            return 0;
     195        Image* image = m_cachedImage->image();
     196        if (!image)
     197            return 0;
     198        surface = image->nativeImageForCurrentFrame();
     199    }
     200
     201    if (!surface)
     202        return 0;
     203
     204    cairo_pattern_t* pattern = cairo_pattern_create_for_surface(surface);
     205    cairo_pattern_set_matrix(pattern, &m);
     206    if (m_repeatX || m_repeatY)
     207        cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
     208    return pattern;
     209}
     210
     211#endif
     212
     213}
  • trunk/WebCore/html/CanvasPattern.h

    r27776 r28971  
    3333#include <wtf/RetainPtr.h>
    3434#include <ApplicationServices/ApplicationServices.h>
     35#elif PLATFORM(CAIRO)
     36#include <cairo.h>
    3537#endif
    3638
     
    4850#if PLATFORM(CG)
    4951        CanvasPattern(CGImageRef, bool repeatX, bool repeatY);
     52#elif PLATFORM(CAIRO)
     53        CanvasPattern(cairo_surface_t*, bool repeatX, bool repeatY);
    5054#endif
    5155        CanvasPattern(CachedImage*, bool repeatX, bool repeatY);
     
    5458#if PLATFORM(CG)
    5559        CGImageRef platformImage() const { return m_platformImage.get(); }
     60#elif PLATFORM(CAIRO)
     61        cairo_surface_t* platformImage() const { return m_platformImage; }
    5662#endif
    5763        CachedImage* cachedImage() const { return m_cachedImage; }
     
    5965#if PLATFORM(CG)
    6066        CGPatternRef createPattern(const CGAffineTransform&);
     67#elif PLATFORM(CAIRO)
     68        cairo_pattern_t* createPattern(const cairo_matrix_t&);
    6169#endif
    6270
     
    6472#if PLATFORM(CG)
    6573        const RetainPtr<CGImageRef> m_platformImage;
     74#elif PLATFORM(CAIRO)
     75        cairo_surface_t* const m_platformImage;
    6676#endif
    6777        CachedImage* const m_cachedImage;
  • trunk/WebCore/html/CanvasRenderingContext2D.cpp

    r28944 r28971  
    726726    // FIXME: Do this through platform-independent GraphicsContext API.
    727727#if PLATFORM(CG)
    728     RGBA32 rgba = 0; // default is transparant black
     728    RGBA32 rgba = 0; // default is transparent black
    729729    CSSParser::parseColor(rgba, color);
    730730    const CGFloat components[4] = {
     
    817817    // FIXME: Do this through platform-independent GraphicsContext API.
    818818#if PLATFORM(CG)
    819     RGBA32 rgba = 0; // default is transparant black
     819    RGBA32 rgba = 0; // default is transparent black
    820820    if (!state().m_shadowColor.isEmpty())
    821821        CSSParser::parseColor(rgba, state().m_shadowColor);
     
    978978        return;
    979979    willDraw(dstRect);
    980 
    981     float iw = cairo_image_surface_get_width(image);
    982     float ih = cairo_image_surface_get_height(image);
    983 
    984     if (sourceRect.x() == 0 && sourceRect.y() == 0 && iw == sourceRect.width() && ih == sourceRect.height()) {
    985         cairo_t* cr = c->platformContext();
    986         cairo_save(cr);
    987         cairo_set_source_surface(cr, image, srcRect.x(), srcRect.y());
    988         cairo_surface_destroy(image);
    989         cairo_rectangle(cr, dstRect.x(), dstRect.y(), dstRect.width(), dstRect.height());
    990         cairo_fill(cr);
    991         cairo_restore(cr);
    992     } else
    993         notImplemented();
    994 
     980    cairo_t* cr = c->platformContext();
     981    cairo_save(cr);
     982    cairo_set_source_surface(cr, image, srcRect.x(), srcRect.y());
     983    cairo_surface_destroy(image);
     984    cairo_rectangle(cr, dstRect.x(), dstRect.y(), dstRect.width(), dstRect.height());
     985    cairo_fill(cr);
     986    cairo_restore(cr);
    995987#endif
    996988}
     
    10691061    CGImageRelease(image);
    10701062    return pattern;
     1063#elif PLATFORM(CAIRO)
     1064    cairo_surface_t* surface = canvas->createPlatformImage();
     1065    if (!surface)
     1066        return 0;
     1067    PassRefPtr<CanvasPattern> pattern = new CanvasPattern(surface, repeatX, repeatY);
     1068    cairo_surface_destroy(surface);
     1069    return pattern;
    10711070#else
    10721071    notImplemented();
     
    11221121    fprintf(stderr, "FIXME: CanvasRenderingContext2D::applyStrokePattern\n");
    11231122#elif PLATFORM(CAIRO)
    1124     notImplemented();
     1123    CanvasPattern* pattern = state().m_strokeStyle->pattern();
     1124    if (!pattern)
     1125        return;
     1126
     1127    cairo_t* cr = c->platformContext();
     1128    cairo_matrix_t m;
     1129    cairo_get_matrix(cr, &m);
     1130
     1131    cairo_pattern_t* platformPattern = pattern->createPattern(m);
     1132    if (!platformPattern)
     1133        return;
     1134
     1135    cairo_set_source(cr, platformPattern);
     1136    cairo_pattern_destroy(platformPattern);
    11251137#endif
    11261138    state().m_appliedStrokePattern = true;
     
    11591171#elif PLATFORM(QT)
    11601172    fprintf(stderr, "FIXME: CanvasRenderingContext2D::applyFillPattern\n");
     1173#elif PLATFORM(CAIRO)
     1174    CanvasPattern* pattern = state().m_fillStyle->pattern();
     1175    if (!pattern)
     1176        return;
     1177
     1178    cairo_t* cr = c->platformContext();
     1179    cairo_matrix_t m;
     1180    cairo_get_matrix(cr, &m);
     1181
     1182    cairo_pattern_t* platformPattern = pattern->createPattern(m);
     1183    if (!platformPattern)
     1184        return;
     1185
     1186    cairo_set_source(cr, platformPattern);
     1187    cairo_pattern_destroy(platformPattern);
    11611188#endif
    11621189    state().m_appliedFillPattern = true;
  • trunk/WebCore/platform/graphics/Image.h

    r28871 r28971  
    112112
    113113    enum TileRule { StretchTile, RoundTile, RepeatTile };
     114
     115    virtual NativeImagePtr nativeImageForCurrentFrame() { return 0; }
    114116   
    115117#if PLATFORM(MAC)
     
    147149    virtual Color solidColor() const { return Color(); }
    148150   
    149     virtual NativeImagePtr nativeImageForCurrentFrame() { return 0; }
    150    
    151151    virtual void startAnimation() { }
    152152   
Note: See TracChangeset for help on using the changeset viewer.