Changeset 28969 in webkit


Ignore:
Timestamp:
Dec 23, 2007 4:47:05 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=16577
Merge Cairo enhancements from Apollo project

This patch is based on initial merging work by Brent Fulgham. Adobe's
code has been modified in a few places to better suit the existing
coding style.

Implement more clipping and drawing functions.

Save and restore the fill rule manually when clipping.

Avoid image surface creation when the image buffer has height zero.

  • platform/graphics/cairo/GraphicsContextCairo.cpp: (WebCore::GraphicsContext::clip): (WebCore::GraphicsContext::addInnerRoundedRectClip): (WebCore::GraphicsContext::addPath): (WebCore::GraphicsContext::clipOut): (WebCore::GraphicsContext::clipOutEllipseInRect): (WebCore::GraphicsContext::fillRoundedRect):
  • platform/graphics/cairo/ImageSourceCairo.cpp: (WebCore::ImageSource::createFrameAtIndex):
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r28966 r28969  
     12007-12-23  Alp Toker  <alp@atoker.com>
     2
     3        Reviewed by Holger Freyther.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=16577
     6        Merge Cairo enhancements from Apollo project
     7
     8        This patch is based on initial merging work by Brent Fulgham. Adobe's
     9        code has been modified in a few places to better suit the existing
     10        coding style.
     11
     12        Implement more clipping and drawing functions.
     13
     14        Save and restore the fill rule manually when clipping.
     15
     16        Avoid image surface creation when the image buffer has height zero.
     17
     18        * platform/graphics/cairo/GraphicsContextCairo.cpp:
     19        (WebCore::GraphicsContext::clip):
     20        (WebCore::GraphicsContext::addInnerRoundedRectClip):
     21        (WebCore::GraphicsContext::addPath):
     22        (WebCore::GraphicsContext::clipOut):
     23        (WebCore::GraphicsContext::clipOutEllipseInRect):
     24        (WebCore::GraphicsContext::fillRoundedRect):
     25        * platform/graphics/cairo/ImageSourceCairo.cpp:
     26        (WebCore::ImageSource::createFrameAtIndex):
     27
    1282007-12-23  Nikolas Zimmermann  <zimmermann@kde.org>
    229
  • trunk/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp

    r28861 r28969  
    410410    cairo_t* cr = m_data->cr;
    411411    cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height());
     412    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
     413    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING);
    412414    cairo_clip(cr);
     415    cairo_set_fill_rule(cr, savedFillRule);
    413416}
    414417
     
    604607
    605608    clip(rect);
    606     Path path;
    607 
    608     path.addEllipse(rect);
    609 
    610     IntRect inner(rect);
    611     inner.inflate(-thickness);
    612     path.addEllipse(inner);
    613 
    614     cairo_t* cr = m_data->cr;
     609
     610    Path p;
     611    FloatRect r(rect);
     612    // Add outer ellipse
     613    p.addEllipse(r);
     614    // Add inner ellipse
     615    r.inflate(-thickness);
     616    p.addEllipse(r);
     617    addPath(p);
     618
     619    cairo_t* cr = m_data->cr;
     620    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
    615621    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
    616 
    617     clip(path);
    618 }
     622    cairo_clip(cr);
     623    cairo_set_fill_rule(cr, savedFillRule);
     624}
     625
    619626
    620627void GraphicsContext::setShadow(IntSize const&, int, Color const&)
     
    791798
    792799    cairo_t* cr = m_data->cr;
    793     cairo_path_t *p = cairo_copy_path(path.platformPath()->m_cr);
     800    cairo_path_t* p = cairo_copy_path(path.platformPath()->m_cr);
    794801    cairo_append_path(cr, p);
    795802    cairo_path_destroy(p);
     
    802809
    803810    cairo_t* cr = m_data->cr;
    804     cairo_path_t *p = cairo_copy_path(path.platformPath()->m_cr);
     811    cairo_path_t* p = cairo_copy_path(path.platformPath()->m_cr);
    805812    cairo_append_path(cr, p);
    806813    cairo_path_destroy(p);
     814    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
     815    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING);
    807816    cairo_clip(cr);
    808 }
    809 
    810 void GraphicsContext::clipOut(const Path&)
    811 {
    812     notImplemented();
     817    cairo_set_fill_rule(cr, savedFillRule);
     818}
     819
     820void GraphicsContext::clipOut(const Path& path)
     821{
     822    if (paintingDisabled())
     823        return;
     824
     825    cairo_t* cr = m_data->cr;
     826    double x1, y1, x2, y2;
     827    cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
     828    cairo_rectangle(cr, x1, y1, x2 - x1, y2 - y1);
     829    addPath(path);
     830
     831    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
     832    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
     833    cairo_clip(cr);
     834    cairo_set_fill_rule(cr, savedFillRule);
    813835}
    814836
     
    829851}
    830852
    831 void GraphicsContext::clipOut(const IntRect&)
    832 {
    833     notImplemented();
    834 }
    835 
    836 void GraphicsContext::clipOutEllipseInRect(const IntRect&)
    837 {
    838     notImplemented();
    839 }
    840 
    841 void GraphicsContext::fillRoundedRect(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color&)
    842 {
    843     notImplemented();
     853void GraphicsContext::clipOut(const IntRect& r)
     854{
     855    if (paintingDisabled())
     856        return;
     857
     858    cairo_t* cr = m_data->cr;
     859    double x1, y1, x2, y2;
     860    cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
     861    cairo_rectangle(cr, x1, x2, x2 - x1, y2 - y1);
     862    cairo_rectangle(cr, r.x(), r.y(), r.width(), r.height());
     863    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
     864    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
     865    cairo_clip(cr);
     866    cairo_set_fill_rule(cr, savedFillRule);
     867}
     868
     869void GraphicsContext::clipOutEllipseInRect(const IntRect& r)
     870{
     871    if (paintingDisabled())
     872        return;
     873
     874    Path p;
     875    p.addEllipse(r);
     876    clipOut(p);
     877}
     878
     879void GraphicsContext::fillRoundedRect(const IntRect& r, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color& color)
     880{
     881    if (paintingDisabled())
     882        return;
     883
     884    cairo_t* cr = m_data->cr;
     885    cairo_save(cr);
     886    beginPath();
     887    addPath(Path::createRoundedRectangle(r, topLeft, topRight, bottomLeft, bottomRight));
     888    setColor(cr, color);
     889    cairo_fill(cr);
     890    cairo_restore(cr);
    844891}
    845892
  • trunk/WebCore/platform/graphics/cairo/ImageSourceCairo.cpp

    r28345 r28969  
    160160        return 0;
    161161
     162    // Cairo does not like zero height images.
     163    // If we have a zero height image, just pretend we don't have enough data yet.
     164    if (!buffer->height())
     165        return 0;
     166
    162167    return cairo_image_surface_create_for_data((unsigned char*)buffer->bytes().data(),
    163168                                               CAIRO_FORMAT_ARGB32,
Note: See TracChangeset for help on using the changeset viewer.