Changeset 69517 in webkit


Ignore:
Timestamp:
Oct 11, 2010 12:19:05 PM (14 years ago)
Author:
andreas.kling@nokia.com
Message:

2010-10-11 Andreas Kling <kling@webkit.org>

Reviewed by Dirk Schulze.

SVG: Remove "create" methods and use port-specific "add" counterparts
https://bugs.webkit.org/show_bug.cgi?id=46052

Circles and ellipses will be significantly faster on platforms that
implement Path::addEllipse() in a sane fashion.

Also, a lot of Path copying has been factored out by changing functions
that would return Paths to take Path& arguments instead (toPathData, toClipPath)

  • mathml/RenderMathMLRoot.cpp: (WebCore::RenderMathMLRoot::paint):
  • mathml/RenderMathMLSquareRoot.cpp: (WebCore::RenderMathMLSquareRoot::paint):
  • platform/graphics/GraphicsContext.cpp: (WebCore::GraphicsContext::addRoundedRectClip): (WebCore::GraphicsContext::clipOutRoundedRect):
  • platform/graphics/Path.cpp: (WebCore::pathLengthApplierFunction): (WebCore::Path::addRoundedRect):
  • platform/graphics/Path.h:
  • platform/graphics/cairo/ContextShadowCairo.cpp: (WebCore::ContextShadow::drawRectShadowWithoutTiling): (WebCore::ContextShadow::drawRectShadow):
  • platform/graphics/cairo/GraphicsContextCairo.cpp: (WebCore::GraphicsContext::drawFocusRing): (WebCore::GraphicsContext::drawTiledShadow): (WebCore::GraphicsContext::fillRoundedRect):
  • platform/graphics/cg/GraphicsContextCG.cpp: (WebCore::GraphicsContext::fillRoundedRect):
  • platform/graphics/qt/GraphicsContextQt.cpp: (WebCore::GraphicsContext::fillRoundedRect):
  • rendering/RenderBoxModelObject.cpp: (WebCore::RenderBoxModelObject::paintBorder): (WebCore::RenderBoxModelObject::paintBoxShadow):
  • rendering/RenderEmbeddedObject.cpp: (WebCore::RenderEmbeddedObject::getReplacementTextGeometry):
  • rendering/RenderSVGResourceClipper.cpp: (WebCore::RenderSVGResourceClipper::pathOnlyClipping):
  • rendering/svg/RenderSVGPath.cpp: (WebCore::RenderSVGPath::layout):
  • rendering/svg/RenderSVGTextPath.cpp: (WebCore::RenderSVGTextPath::layoutPath):
  • rendering/svg/SVGInlineTextBox.cpp: (WebCore::SVGInlineTextBox::paintDecorationWithStyle):
  • svg/SVGAnimateMotionElement.cpp: (WebCore::SVGAnimateMotionElement::animationPath):
  • svg/SVGCircleElement.cpp: (WebCore::SVGCircleElement::toPathData):
  • svg/SVGCircleElement.h:
  • svg/SVGEllipseElement.cpp: (WebCore::SVGEllipseElement::toPathData):
  • svg/SVGEllipseElement.h:
  • svg/SVGLineElement.cpp: (WebCore::SVGLineElement::toPathData):
  • svg/SVGLineElement.h:
  • svg/SVGPathElement.cpp: (WebCore::SVGPathElement::getTotalLength): (WebCore::SVGPathElement::getPointAtLength): (WebCore::SVGPathElement::toPathData):
  • svg/SVGPathElement.h:
  • svg/SVGPolygonElement.cpp: (WebCore::SVGPolygonElement::toPathData):
  • svg/SVGPolygonElement.h:
  • svg/SVGPolylineElement.cpp: (WebCore::SVGPolylineElement::toPathData):
  • svg/SVGPolylineElement.h:
  • svg/SVGRectElement.cpp: (WebCore::SVGRectElement::toPathData):
  • svg/SVGRectElement.h:
  • svg/SVGStyledTransformableElement.cpp: (WebCore::SVGStyledTransformableElement::toClipPath):
  • svg/SVGStyledTransformableElement.h: (WebCore::SVGStyledTransformableElement::toPathData):
  • svg/SVGUseElement.cpp: (WebCore::SVGUseElement::toClipPath):
  • svg/SVGUseElement.h:
Location:
trunk/WebCore
Files:
35 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r69516 r69517  
     12010-10-11  Andreas Kling  <kling@webkit.org>
     2
     3        Reviewed by Dirk Schulze.
     4
     5        SVG: Remove "create" methods and use port-specific "add" counterparts
     6        https://bugs.webkit.org/show_bug.cgi?id=46052
     7
     8        Circles and ellipses will be significantly faster on platforms that
     9        implement Path::addEllipse() in a sane fashion.
     10
     11        Also, a lot of Path copying has been factored out by changing functions
     12        that would return Paths to take Path& arguments instead (toPathData, toClipPath)
     13
     14        * mathml/RenderMathMLRoot.cpp:
     15        (WebCore::RenderMathMLRoot::paint):
     16        * mathml/RenderMathMLSquareRoot.cpp:
     17        (WebCore::RenderMathMLSquareRoot::paint):
     18        * platform/graphics/GraphicsContext.cpp:
     19        (WebCore::GraphicsContext::addRoundedRectClip):
     20        (WebCore::GraphicsContext::clipOutRoundedRect):
     21        * platform/graphics/Path.cpp:
     22        (WebCore::pathLengthApplierFunction):
     23        (WebCore::Path::addRoundedRect):
     24        * platform/graphics/Path.h:
     25        * platform/graphics/cairo/ContextShadowCairo.cpp:
     26        (WebCore::ContextShadow::drawRectShadowWithoutTiling):
     27        (WebCore::ContextShadow::drawRectShadow):
     28        * platform/graphics/cairo/GraphicsContextCairo.cpp:
     29        (WebCore::GraphicsContext::drawFocusRing):
     30        (WebCore::GraphicsContext::drawTiledShadow):
     31        (WebCore::GraphicsContext::fillRoundedRect):
     32        * platform/graphics/cg/GraphicsContextCG.cpp:
     33        (WebCore::GraphicsContext::fillRoundedRect):
     34        * platform/graphics/qt/GraphicsContextQt.cpp:
     35        (WebCore::GraphicsContext::fillRoundedRect):
     36        * rendering/RenderBoxModelObject.cpp:
     37        (WebCore::RenderBoxModelObject::paintBorder):
     38        (WebCore::RenderBoxModelObject::paintBoxShadow):
     39        * rendering/RenderEmbeddedObject.cpp:
     40        (WebCore::RenderEmbeddedObject::getReplacementTextGeometry):
     41        * rendering/RenderSVGResourceClipper.cpp:
     42        (WebCore::RenderSVGResourceClipper::pathOnlyClipping):
     43        * rendering/svg/RenderSVGPath.cpp:
     44        (WebCore::RenderSVGPath::layout):
     45        * rendering/svg/RenderSVGTextPath.cpp:
     46        (WebCore::RenderSVGTextPath::layoutPath):
     47        * rendering/svg/SVGInlineTextBox.cpp:
     48        (WebCore::SVGInlineTextBox::paintDecorationWithStyle):
     49        * svg/SVGAnimateMotionElement.cpp:
     50        (WebCore::SVGAnimateMotionElement::animationPath):
     51        * svg/SVGCircleElement.cpp:
     52        (WebCore::SVGCircleElement::toPathData):
     53        * svg/SVGCircleElement.h:
     54        * svg/SVGEllipseElement.cpp:
     55        (WebCore::SVGEllipseElement::toPathData):
     56        * svg/SVGEllipseElement.h:
     57        * svg/SVGLineElement.cpp:
     58        (WebCore::SVGLineElement::toPathData):
     59        * svg/SVGLineElement.h:
     60        * svg/SVGPathElement.cpp:
     61        (WebCore::SVGPathElement::getTotalLength):
     62        (WebCore::SVGPathElement::getPointAtLength):
     63        (WebCore::SVGPathElement::toPathData):
     64        * svg/SVGPathElement.h:
     65        * svg/SVGPolygonElement.cpp:
     66        (WebCore::SVGPolygonElement::toPathData):
     67        * svg/SVGPolygonElement.h:
     68        * svg/SVGPolylineElement.cpp:
     69        (WebCore::SVGPolylineElement::toPathData):
     70        * svg/SVGPolylineElement.h:
     71        * svg/SVGRectElement.cpp:
     72        (WebCore::SVGRectElement::toPathData):
     73        * svg/SVGRectElement.h:
     74        * svg/SVGStyledTransformableElement.cpp:
     75        (WebCore::SVGStyledTransformableElement::toClipPath):
     76        * svg/SVGStyledTransformableElement.h:
     77        (WebCore::SVGStyledTransformableElement::toPathData):
     78        * svg/SVGUseElement.cpp:
     79        (WebCore::SVGUseElement::toClipPath):
     80        * svg/SVGUseElement.h:
     81
    1822010-10-01  Oliver Hunt  <oliver@apple.com>
    283
  • trunk/WebCore/mathml/RenderMathMLRoot.cpp

    r66403 r69517  
    191191   
    192192    Path line;
    193    
    194     line = line.createLine(bottomLeft, topLeft);
    195    
     193    line.moveTo(bottomLeft);
     194    line.addLineTo(topLeft);
     195
    196196    info.context->beginPath();
    197197    info.context->addPath(line);
  • trunk/WebCore/mathml/RenderMathMLSquareRoot.cpp

    r64596 r69517  
    157157   
    158158    Path line;
    159    
    160     line = line.createLine(bottomLeft, topLeft);
     159    line.moveTo(bottomLeft);
     160    line.addLineTo(topLeft);
    161161   
    162162    info.context->beginPath();
  • trunk/WebCore/platform/graphics/GraphicsContext.cpp

    r67799 r69517  
    501501        return;
    502502
    503     clip(Path::createRoundedRectangle(rect, topLeft, topRight, bottomLeft, bottomRight));
     503    Path path;
     504    path.addRoundedRect(rect, topLeft, topRight, bottomLeft, bottomRight);
     505    clip(path);
    504506}
    505507
     
    510512        return;
    511513
    512     clipOut(Path::createRoundedRectangle(rect, topLeft, topRight, bottomLeft, bottomRight));
     514    Path path;
     515    path.addRoundedRect(rect, topLeft, topRight, bottomLeft, bottomRight);
     516    clipOut(path);
    513517}
    514518
  • trunk/WebCore/platform/graphics/Path.cpp

    r66979 r69517  
    3636#include <wtf/MathExtras.h>
    3737
    38 static const float QUARTER = 0.552f; // approximation of control point positions on a bezier
    39                               // to simulate a quarter of a circle.
     38// Approximation of control point positions on a bezier to simulate a quarter of a circle.
     39static const float gCircleControlPoint = 1 - 0.552;
     40
    4041namespace WebCore {
    4142
     
    4849    traversalState.m_previous = traversalState.m_current;
    4950    FloatPoint* points = element->points;
    50     float segmentLength = 0.0f;
     51    float segmentLength = 0;
    5152    switch (element->type) {
    5253        case PathElementMoveToPoint:
     
    7677            float offset = traversalState.m_desiredLength - traversalState.m_totalLength;
    7778            traversalState.m_current.move(offset * cosf(slope), offset * sinf(slope));
    78         } else {
    79             static const float rad2deg = 180.0f / piFloat;
    80             traversalState.m_normalAngle = slope * rad2deg;
    81         }
     79        } else
     80            traversalState.m_normalAngle = rad2deg(slope);
    8281
    8382        traversalState.m_success = true;
     
    111110#endif
    112111
    113 Path Path::createRoundedRectangle(const FloatRect& rectangle, const FloatSize& roundingRadii)
     112void Path::addRoundedRect(const FloatRect& rect, const FloatSize& roundingRadii)
    114113{
    115     Path path;
    116     float x = rectangle.x();
    117     float y = rectangle.y();
    118     float width = rectangle.width();
    119     float height = rectangle.height();
    120     float rx = roundingRadii.width();
    121     float ry = roundingRadii.height();
    122     if (width <= 0.0f || height <= 0.0f)
    123         return path;
     114    if (rect.isEmpty())
     115        return;
    124116
    125     float dx = rx, dy = ry;
     117    FloatSize radius(roundingRadii);
     118    FloatSize halfSize(rect.width() / 2, rect.height() / 2);
     119
    126120    // If rx is greater than half of the width of the rectangle
    127121    // then set rx to half of the width (required in SVG spec)
    128     if (dx > width * 0.5f)
    129         dx = width * 0.5f;
     122    if (radius.width() > halfSize.width())
     123        radius.setWidth(halfSize.width());
    130124
    131125    // If ry is greater than half of the height of the rectangle
    132126    // then set ry to half of the height (required in SVG spec)
    133     if (dy > height * 0.5f)
    134         dy = height * 0.5f;
     127    if (radius.height() > halfSize.height())
     128        radius.setHeight(halfSize.height());
    135129
    136     path.moveTo(FloatPoint(x + dx, y));
     130    moveTo(FloatPoint(rect.x() + radius.width(), rect.y()));
    137131
    138     if (dx < width * 0.5f)
    139         path.addLineTo(FloatPoint(x + width - rx, y));
     132    if (radius.width() < halfSize.width())
     133        addLineTo(FloatPoint(rect.x() + rect.width() - roundingRadii.width(), rect.y()));
    140134
    141     path.addBezierCurveTo(FloatPoint(x + width - dx * (1 - QUARTER), y), FloatPoint(x + width, y + dy * (1 - QUARTER)), FloatPoint(x + width, y + dy));
     135    addBezierCurveTo(FloatPoint(rect.x() + rect.width() - radius.width() * gCircleControlPoint, rect.y()), FloatPoint(rect.x() + rect.width(), rect.y() + radius.height() * gCircleControlPoint), FloatPoint(rect.x() + rect.width(), rect.y() + radius.height()));
    142136
    143     if (dy < height * 0.5)
    144         path.addLineTo(FloatPoint(x + width, y + height - dy));
     137    if (radius.height() < halfSize.height())
     138        addLineTo(FloatPoint(rect.x() + rect.width(), rect.y() + rect.height() - radius.height()));
    145139
    146     path.addBezierCurveTo(FloatPoint(x + width, y + height - dy * (1 - QUARTER)), FloatPoint(x + width - dx * (1 - QUARTER), y + height), FloatPoint(x + width - dx, y + height));
     140    addBezierCurveTo(FloatPoint(rect.x() + rect.width(), rect.y() + rect.height() - radius.height() * gCircleControlPoint), FloatPoint(rect.x() + rect.width() - radius.width() * gCircleControlPoint, rect.y() + rect.height()), FloatPoint(rect.x() + rect.width() - radius.width(), rect.y() + rect.height()));
    147141
    148     if (dx < width * 0.5)
    149         path.addLineTo(FloatPoint(x + dx, y + height));
     142    if (radius.width() < halfSize.width())
     143        addLineTo(FloatPoint(rect.x() + radius.width(), rect.y() + rect.height()));
    150144
    151     path.addBezierCurveTo(FloatPoint(x + dx * (1 - QUARTER), y + height), FloatPoint(x, y + height - dy * (1 - QUARTER)), FloatPoint(x, y + height - dy));
     145    addBezierCurveTo(FloatPoint(rect.x() + radius.width() * gCircleControlPoint, rect.y() + rect.height()), FloatPoint(rect.x(), rect.y() + rect.height() - radius.height() * gCircleControlPoint), FloatPoint(rect.x(), rect.y() + rect.height() - radius.height()));
    152146
    153     if (dy < height * 0.5)
    154         path.addLineTo(FloatPoint(x, y + dy));
     147    if (radius.height() < halfSize.height())
     148        addLineTo(FloatPoint(rect.x(), rect.y() + radius.height()));
    155149
    156     path.addBezierCurveTo(FloatPoint(x, y + dy * (1 - QUARTER)), FloatPoint(x + dx * (1 - QUARTER), y), FloatPoint(x + dx, y));
     150    addBezierCurveTo(FloatPoint(rect.x(), rect.y() + radius.height() * gCircleControlPoint), FloatPoint(rect.x() + radius.width() * gCircleControlPoint, rect.y()), FloatPoint(rect.x() + radius.width(), rect.y()));
    157151
    158     path.closeSubpath();
    159 
    160     return path;
     152    closeSubpath();
    161153}
    162154
    163 Path Path::createRoundedRectangle(const FloatRect& rectangle, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius)
     155void Path::addRoundedRect(const FloatRect& rect, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius)
    164156{
    165     Path path;
     157    if (rect.isEmpty())
     158        return;
    166159
    167     float width = rectangle.width();
    168     float height = rectangle.height();
    169     if (width <= 0.0 || height <= 0.0)
    170         return path;
    171 
    172     if (width < topLeftRadius.width() + topRightRadius.width()
    173             || width < bottomLeftRadius.width() + bottomRightRadius.width()
    174             || height < topLeftRadius.height() + bottomLeftRadius.height()
    175             || height < topRightRadius.height() + bottomRightRadius.height())
     160    if (rect.width() < topLeftRadius.width() + topRightRadius.width()
     161            || rect.width() < bottomLeftRadius.width() + bottomRightRadius.width()
     162            || rect.height() < topLeftRadius.height() + bottomLeftRadius.height()
     163            || rect.height() < topRightRadius.height() + bottomRightRadius.height()) {
    176164        // If all the radii cannot be accommodated, return a rect.
    177         return createRectangle(rectangle);
    178 
    179     float x = rectangle.x();
    180     float y = rectangle.y();
    181 
    182     path.moveTo(FloatPoint(x + topLeftRadius.width(), y));
    183 
    184     path.addLineTo(FloatPoint(x + width - topRightRadius.width(), y));
    185 
    186     path.addBezierCurveTo(FloatPoint(x + width - topRightRadius.width() * (1 - QUARTER), y), FloatPoint(x + width, y + topRightRadius.height() * (1 - QUARTER)), FloatPoint(x + width, y + topRightRadius.height()));
    187 
    188     path.addLineTo(FloatPoint(x + width, y + height - bottomRightRadius.height()));
    189 
    190     path.addBezierCurveTo(FloatPoint(x + width, y + height - bottomRightRadius.height() * (1 - QUARTER)), FloatPoint(x + width - bottomRightRadius.width() * (1 - QUARTER), y + height), FloatPoint(x + width - bottomRightRadius.width(), y + height));
    191 
    192     path.addLineTo(FloatPoint(x + bottomLeftRadius.width(), y + height));
    193 
    194     path.addBezierCurveTo(FloatPoint(x + bottomLeftRadius.width() * (1 - QUARTER), y + height), FloatPoint(x, y + height - bottomLeftRadius.height() * (1 - QUARTER)), FloatPoint(x, y + height - bottomLeftRadius.height()));
    195 
    196     path.addLineTo(FloatPoint(x, y + topLeftRadius.height()));
    197 
    198     path.addBezierCurveTo(FloatPoint(x, y + topLeftRadius.height() * (1 - QUARTER)), FloatPoint(x + topLeftRadius.width() * (1 - QUARTER), y), FloatPoint(x + topLeftRadius.width(), y));
    199 
    200     path.closeSubpath();
    201 
    202     return path;
    203 }
    204 
    205 Path Path::createRectangle(const FloatRect& rectangle)
    206 {
    207     Path path;
    208     float x = rectangle.x();
    209     float y = rectangle.y();
    210     float width = rectangle.width();
    211     float height = rectangle.height();
    212     if (width <= 0.0f || height <= 0.0f)
    213         return path;
    214    
    215     path.moveTo(FloatPoint(x, y));
    216     path.addLineTo(FloatPoint(x + width, y));
    217     path.addLineTo(FloatPoint(x + width, y + height));
    218     path.addLineTo(FloatPoint(x, y + height));
    219     path.closeSubpath();
    220 
    221     return path;
    222 }
    223 
    224 Path Path::createEllipse(const FloatPoint& center, float rx, float ry)
    225 {
    226     float cx = center.x();
    227     float cy = center.y();
    228     Path path;
    229     if (rx <= 0.0f || ry <= 0.0f)
    230         return path;
    231 
    232     float x = cx;
    233     float y = cy;
    234 
    235     unsigned step = 0, num = 100;
    236     bool running = true;
    237     while (running)
    238     {
    239         if (step == num)
    240         {
    241             running = false;
    242             break;
    243         }
    244 
    245         float angle = static_cast<float>(step) / static_cast<float>(num) * 2.0f * piFloat;
    246         x = cx + cosf(angle) * rx;
    247         y = cy + sinf(angle) * ry;
    248 
    249         step++;
    250         if (step == 1)
    251             path.moveTo(FloatPoint(x, y));
    252         else
    253             path.addLineTo(FloatPoint(x, y));
     165        addRect(rect);
     166        return;
    254167    }
    255168
    256     path.closeSubpath();
     169    moveTo(FloatPoint(rect.x() + topLeftRadius.width(), rect.y()));
    257170
    258     return path;
    259 }
     171    addLineTo(FloatPoint(rect.x() + rect.width() - topRightRadius.width(), rect.y()));
     172    addBezierCurveTo(FloatPoint(rect.x() + rect.width() - topRightRadius.width() * gCircleControlPoint, rect.y()),
     173                     FloatPoint(rect.x() + rect.width(), rect.y() + topRightRadius.height() * gCircleControlPoint),
     174                     FloatPoint(rect.x() + rect.width(), rect.y() + topRightRadius.height()));
     175    addLineTo(FloatPoint(rect.x() + rect.width(), rect.y() + rect.height() - bottomRightRadius.height()));
     176    addBezierCurveTo(FloatPoint(rect.x() + rect.width(), rect.y() + rect.height() - bottomRightRadius.height() * gCircleControlPoint),
     177                     FloatPoint(rect.x() + rect.width() - bottomRightRadius.width() * gCircleControlPoint, rect.y() + rect.height()),
     178                     FloatPoint(rect.x() + rect.width() - bottomRightRadius.width(), rect.y() + rect.height()));
     179    addLineTo(FloatPoint(rect.x() + bottomLeftRadius.width(), rect.y() + rect.height()));
     180    addBezierCurveTo(FloatPoint(rect.x() + bottomLeftRadius.width() * gCircleControlPoint, rect.y() + rect.height()),
     181                     FloatPoint(rect.x(), rect.y() + rect.height() - bottomLeftRadius.height() * gCircleControlPoint),
     182                     FloatPoint(rect.x(), rect.y() + rect.height() - bottomLeftRadius.height()));
     183    addLineTo(FloatPoint(rect.x(), rect.y() + topLeftRadius.height()));
     184    addBezierCurveTo(FloatPoint(rect.x(), rect.y() + topLeftRadius.height() * gCircleControlPoint),
     185                     FloatPoint(rect.x() + topLeftRadius.width() * gCircleControlPoint, rect.y()),
     186                     FloatPoint(rect.x() + topLeftRadius.width(), rect.y()));
    260187
    261 Path Path::createCircle(const FloatPoint& center, float r)
    262 {
    263     return createEllipse(center, r, r);
    264 }
    265 
    266 Path Path::createLine(const FloatPoint& start, const FloatPoint& end)
    267 {
    268     Path path;
    269 
    270     path.moveTo(start);
    271     path.addLineTo(end);
    272 
    273     return path;
     188    closeSubpath();
    274189}
    275190
  • trunk/WebCore/platform/graphics/Path.h

    r69505 r69517  
    138138        void addRect(const FloatRect&);
    139139        void addEllipse(const FloatRect&);
     140        void addRoundedRect(const FloatRect&, const FloatSize& roundingRadii);
     141        void addRoundedRect(const FloatRect&, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius);
    140142
    141143        void translate(const FloatSize&);
    142144
    143145        PlatformPathPtr platformPath() const { return m_path; }
    144 
    145         static Path createRoundedRectangle(const FloatRect&, const FloatSize& roundingRadii);
    146         static Path createRoundedRectangle(const FloatRect&, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius);
    147         static Path createRectangle(const FloatRect&);
    148         static Path createEllipse(const FloatPoint& center, float rx, float ry);
    149         static Path createCircle(const FloatPoint& center, float r);
    150         static Path createLine(const FloatPoint&, const FloatPoint&);
    151146
    152147        void apply(void* info, PathApplierFunction) const;
  • trunk/WebCore/platform/graphics/cairo/ContextShadowCairo.cpp

    r69223 r69517  
    135135        return;
    136136
    137     appendWebCorePathToCairoContext(m_layerContext, Path::createRoundedRectangle(shadowRect, topLeftRadius, topRightRadius,
    138                                                                                  bottomLeftRadius, bottomRightRadius));
     137    Path path;
     138    path.addRoundedRect(shadowRect, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);
     139
     140    appendWebCorePathToCairoContext(m_layerContext, path);
    139141    cairo_set_source_rgba(m_layerContext, 0, 0, 0, alpha);
    140142    cairo_fill(m_layerContext);
     
    241243    // Draw the rectangle.
    242244    IntRect templateRect = IntRect(m_blurDistance, m_blurDistance, shadowTemplateSize.width() - radiusTwice, shadowTemplateSize.height() - radiusTwice);
    243     appendWebCorePathToCairoContext(m_layerContext, Path::createRoundedRectangle(templateRect, topLeftRadius, topRightRadius,
    244                                                                                  bottomLeftRadius, bottomRightRadius));
     245    Path path;
     246    path.addRoundedRect(templateRect, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);
     247    appendWebCorePathToCairoContext(m_layerContext, path);
    245248
    246249    cairo_set_source_rgba(m_layerContext, 0, 0, 0, context->getAlpha());
     
    264267    if (!shadowRect.isEmpty()) {
    265268        cairo_save(cr);
    266         appendWebCorePathToCairoContext(cr, Path::createRoundedRectangle(shadowRect, topLeftRadius,
    267                                                                               topRightRadius, bottomLeftRadius, bottomRightRadius));
     269        path.clear();
     270        path.addRoundedRect(shadowRect, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);
     271        appendWebCorePathToCairoContext(cr, path);
    268272        setSourceRGBAFromColor(cr, m_color);
    269273        cairo_fill(cr);
  • trunk/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp

    r69187 r69517  
    704704#else
    705705    int radius = (width - 1) / 2;
    706     for (unsigned i = 0; i < rectCount; i++)
    707         appendWebCorePathToCairoContext(cr, Path::createRoundedRectangle(rects[i], FloatSize(radius, radius)));
     706    Path path;
     707    for (unsigned i = 0; i < rectCount; ++i) {
     708        if (i > 0)
     709            path.clear();
     710        path.addRoundedRect(rects[i], FloatSize(radius, radius));
     711        appendWebCorePathToCairoContext(cr, path);
     712    }
    708713
    709714    // Force the alpha to 50%.  This matches what the Mac does with outline rings.
     
    12761281    cairo_t* smallBufferContext = smallBuffer->context()->platformContext();
    12771282    copyContextProperties(cr, smallBufferContext);
    1278     appendWebCorePathToCairoContext(smallBuffer->context()->platformContext(), Path::createRoundedRectangle(smallRect, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius));
     1283
     1284    Path path;
     1285    path.addRoundedRect(smallRect, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);
     1286    appendWebCorePathToCairoContext(smallBuffer->context()->platformContext(), path);
    12791287    setPlatformFill(this, smallBufferContext, m_common);
    12801288
     
    12951303    if (!shadowRect.isEmpty()) {
    12961304        cairo_save(cr);
    1297         appendWebCorePathToCairoContext(cr, Path::createRoundedRectangle(shadowRect, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius));
     1305        path.clear();
     1306        path.addRoundedRect(shadowRect, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);
     1307        appendWebCorePathToCairoContext(cr, path);
    12981308        setColor(cr, shadowColor);
    12991309        cairo_fill(cr);
     
    13741384    cairo_t* cr = m_data->cr;
    13751385    cairo_save(cr);
    1376     appendWebCorePathToCairoContext(cr, Path::createRoundedRectangle(r, topLeft, topRight, bottomLeft, bottomRight));
     1386    Path path;
     1387    path.addRoundedRect(r, topLeft, topRight, bottomLeft, bottomRight);
     1388    appendWebCorePathToCairoContext(cr, path);
    13771389    setColor(cr, color);
    13781390    drawPathShadow(this, m_common, true, false);
  • trunk/WebCore/platform/graphics/cg/GraphicsContextCG.cpp

    r69259 r69517  
    668668        setCGFillColor(context, color, colorSpace);
    669669
    670     addPath(Path::createRoundedRectangle(rect, topLeft, topRight, bottomLeft, bottomRight));
     670    Path path;
     671    path.addRoundedRect(rect, topLeft, topRight, bottomLeft, bottomRight);
     672    addPath(path);
    671673    fillPath();
    672674
  • trunk/WebCore/platform/graphics/qt/GraphicsContextQt.cpp

    r69493 r69517  
    730730        return;
    731731
    732     Path path = Path::createRoundedRectangle(rect, topLeft, topRight, bottomLeft, bottomRight);
     732    Path path;
     733    path.addRoundedRect(rect, topLeft, topRight, bottomLeft, bottomRight);
    733734    QPainter* p = m_data->p();
    734735    if (m_data->hasShadow()) {
  • trunk/WebCore/rendering/RenderBoxModelObject.cpp

    r68817 r69517  
    10621062        graphicsContext->clipOutRoundedRect(innerBorderRect, innerTopLeftRadius, innerTopRightRadius, innerBottomLeftRadius, innerBottomRightRadius);
    10631063
    1064         roundedPath = Path::createRoundedRectangle(borderRect, topLeft, topRight, bottomLeft, bottomRight);
     1064        roundedPath.addRoundedRect(borderRect, topLeft, topRight, bottomLeft, bottomRight);
    10651065        graphicsContext->addPath(roundedPath);
    10661066    }
     
    17531753            context->save();
    17541754
    1755             if (hasBorderRadius)
    1756                 context->clip(Path::createRoundedRectangle(rect, topLeft, topRight, bottomLeft, bottomRight));
    1757             else
     1755            Path path;
     1756            if (hasBorderRadius) {
     1757                path.addRoundedRect(rect, topLeft, topRight, bottomLeft, bottomRight);
     1758                context->clip(path);
     1759                path.clear();
     1760            } else
    17581761                context->clip(rect);
    17591762
     
    17621765            shadowOffset -= extraOffset;
    17631766
    1764             context->beginPath();
    1765             context->addPath(Path::createRectangle(outerRect));
     1767            path.addRect(outerRect);
    17661768
    17671769            if (hasBorderRadius) {
    17681770                if (shadowSpread > 0)
    17691771                    uniformlyExpandBorderRadii(-shadowSpread, topLeft, topRight, bottomLeft, bottomRight);
    1770                 context->addPath(Path::createRoundedRectangle(holeRect, topLeft, topRight, bottomLeft, bottomRight));
     1772                path.addRoundedRect(holeRect, topLeft, topRight, bottomLeft, bottomRight);
    17711773            } else
    1772                 context->addPath(Path::createRectangle(holeRect));
     1774                path.addRect(holeRect);
     1775
     1776            context->beginPath();
     1777            context->addPath(path);
    17731778
    17741779            context->setFillRule(RULE_EVENODD);
  • trunk/WebCore/rendering/RenderEmbeddedObject.cpp

    r68238 r69517  
    207207    replacementTextRect.setLocation(FloatPoint(x, y));
    208208   
    209     path = Path::createRoundedRectangle(replacementTextRect, FloatSize(replacementTextRoundedRectRadius, replacementTextRoundedRectRadius));
     209    path.addRoundedRect(replacementTextRect, FloatSize(replacementTextRoundedRectRadius, replacementTextRoundedRectRadius));
    210210
    211211    return true;
  • trunk/WebCore/rendering/RenderSVGResourceClipper.cpp

    r69279 r69517  
    137137        // Fallback to masking, if there is more than one clipping path.
    138138        if (clipPath.isEmpty()) {
    139             clipPath = styled->toClipPath();
     139            styled->toClipPath(clipPath);
    140140            clipRule = svgStyle->clipRule();
    141141        } else
  • trunk/WebCore/rendering/svg/RenderSVGPath.cpp

    r69437 r69517  
    113113    bool needsPathUpdate = m_needsPathUpdate;
    114114    if (needsPathUpdate) {
    115         m_path = element->toPathData();
     115        m_path.clear();
     116        element->toPathData(m_path);
    116117        m_needsPathUpdate = false;
    117118        updateCachedBoundariesInParents = true;
  • trunk/WebCore/rendering/svg/RenderSVGTextPath.cpp

    r68874 r69517  
    5454    SVGPathElement* pathElement = static_cast<SVGPathElement*>(targetElement);
    5555   
    56     Path pathData = pathElement->toPathData();
     56    Path pathData;
     57    pathElement->toPathData(pathData);
    5758    // Spec:  The transform attribute on the referenced 'path' element represents a
    5859    // supplemental transformation relative to the current user coordinate system for
  • trunk/WebCore/rendering/svg/SVGInlineTextBox.cpp

    r69413 r69517  
    491491    // The initial y value refers to overline position.
    492492    float thickness = thicknessForDecoration(decoration, font);
     493
     494    if (fragment.width <= 0 && thickness <= 0)
     495        return;
     496
    493497    float y = fragment.y - font.ascent() + positionOffsetForDecoration(decoration, font, thickness);
     498
     499    Path path;
     500    path.addRect(FloatRect(fragment.x, y, fragment.width, thickness));
    494501
    495502    context->save();
    496503    context->beginPath();
    497     context->addPath(Path::createRectangle(FloatRect(fragment.x, y, fragment.width, thickness)));
     504    context->addPath(path);
    498505
    499506    if (acquirePaintingResource(context, decorationRenderer, decorationStyle))
  • trunk/WebCore/svg/SVGAnimateMotionElement.cpp

    r66836 r69517  
    113113            SVGMPathElement* mPath = static_cast<SVGMPathElement*>(child);
    114114            SVGPathElement* pathElement = mPath->pathElement();
     115            Path path;
    115116            if (pathElement)
    116                 return pathElement->toPathData();
    117             return Path();
     117                pathElement->toPathData(path);
     118            return path;
    118119        }
    119120    }
  • trunk/WebCore/svg/SVGCircleElement.cpp

    r69279 r69517  
    122122}
    123123
    124 Path SVGCircleElement::toPathData() const
     124void SVGCircleElement::toPathData(Path& path) const
    125125{
    126     return Path::createCircle(FloatPoint(cx().value(this), cy().value(this)), r().value(this));
     126    ASSERT(path.isEmpty());
     127
     128    float radius = r().value(this);
     129
     130    if (radius <= 0)
     131        return;
     132
     133    path.addEllipse(FloatRect(cx().value(this) - radius, cy().value(this) - radius, radius * 2, radius * 2));
    127134}
    128135
  • trunk/WebCore/svg/SVGCircleElement.h

    r66397 r69517  
    4646        virtual void synchronizeProperty(const QualifiedName&);
    4747
    48         virtual Path toPathData() const;
     48        virtual void toPathData(Path&) const;
    4949
    5050        virtual bool selfHasRelativeLengths() const;
  • trunk/WebCore/svg/SVGEllipseElement.cpp

    r69279 r69517  
    131131}
    132132
    133 Path SVGEllipseElement::toPathData() const
     133void SVGEllipseElement::toPathData(Path& path) const
    134134{
    135     return Path::createEllipse(FloatPoint(cx().value(this), cy().value(this)),
    136                                           rx().value(this), ry().value(this));
     135    ASSERT(path.isEmpty());
     136
     137    float radiusX = rx().value(this);
     138    if (radiusX <= 0)
     139        return;
     140
     141    float radiusY = ry().value(this);
     142    if (radiusY <= 0)
     143        return;
     144
     145    path.addEllipse(FloatRect(cx().value(this) - radiusX, cy().value(this) - radiusY, radiusX * 2, radiusY * 2));
    137146}
    138147 
  • trunk/WebCore/svg/SVGEllipseElement.h

    r66397 r69517  
    4646        virtual void synchronizeProperty(const QualifiedName&);
    4747
    48         virtual Path toPathData() const;
     48        virtual void toPathData(Path&) const;
    4949
    5050        virtual bool selfHasRelativeLengths() const;
  • trunk/WebCore/svg/SVGLineElement.cpp

    r69279 r69517  
    127127}
    128128
    129 Path SVGLineElement::toPathData() const
     129void SVGLineElement::toPathData(Path& path) const
    130130{
    131     return Path::createLine(FloatPoint(x1().value(this), y1().value(this)),
    132                             FloatPoint(x2().value(this), y2().value(this)));
     131    ASSERT(path.isEmpty());
     132
     133    path.moveTo(FloatPoint(x1().value(this), y1().value(this)));
     134    path.addLineTo(FloatPoint(x2().value(this), y2().value(this)));
    133135}
    134136
  • trunk/WebCore/svg/SVGLineElement.h

    r66397 r69517  
    4848        virtual void synchronizeProperty(const QualifiedName&);
    4949
    50         virtual Path toPathData() const;
     50        virtual void toPathData(Path&) const;
    5151
    5252        virtual bool supportsMarkers() const { return true; }
  • trunk/WebCore/svg/SVGPathElement.cpp

    r69279 r69517  
    5858{
    5959    // FIXME: this may wish to use the pathSegList instead of the pathdata if that's cheaper to build (or cached)
    60     return toPathData().length();
     60    Path path;
     61    toPathData(path);
     62    return path.length();
    6163}
    6264
     
    6567    // FIXME: this may wish to use the pathSegList instead of the pathdata if that's cheaper to build (or cached)
    6668    bool ok = false;
    67     return toPathData().pointAtLength(length, ok);
     69    Path path;
     70    toPathData(path);
     71    return path.pointAtLength(length, ok);
    6872}
    6973
     
    263267}
    264268
    265 Path SVGPathElement::toPathData() const
    266 {
    267     Path result;
     269void SVGPathElement::toPathData(Path& path) const
     270{
     271    ASSERT(path.isEmpty());
     272
    268273    SVGPathParserFactory* factory = SVGPathParserFactory::self();
    269     factory->buildPathFromSVGPathSegList(pathSegList(), result);
    270     return result;
     274    factory->buildPathFromSVGPathSegList(pathSegList(), path);
    271275}
    272276
  • trunk/WebCore/svg/SVGPathElement.h

    r66397 r69517  
    9090        virtual SVGPathSegList* animatedNormalizedPathSegList() const;
    9191
    92         virtual Path toPathData() const;
     92        virtual void toPathData(Path&) const;
    9393
    9494    private:
  • trunk/WebCore/svg/SVGPolygonElement.cpp

    r66498 r69517  
    3838}
    3939
    40 Path SVGPolygonElement::toPathData() const
     40void SVGPolygonElement::toPathData(Path& path) const
    4141{
    42     Path polyData;
     42    ASSERT(path.isEmpty());
    4343
    4444    int len = points()->numberOfItems();
    4545    if (len < 1)
    46         return polyData;
     46        return;
    4747   
    4848    ExceptionCode ec = 0;
    49     polyData.moveTo(points()->getItem(0, ec));
     49    path.moveTo(points()->getItem(0, ec));
    5050
    5151    for (int i = 1; i < len; ++i)
    52         polyData.addLineTo(points()->getItem(i, ec));
     52        path.addLineTo(points()->getItem(i, ec));
    5353
    54     polyData.closeSubpath();
    55     return polyData;
     54    path.closeSubpath();
    5655}
    5756
  • trunk/WebCore/svg/SVGPolygonElement.h

    r66397 r69517  
    3434        SVGPolygonElement(const QualifiedName&, Document*);
    3535
    36         virtual Path toPathData() const;
     36        virtual void toPathData(Path&) const;
    3737    };
    3838
  • trunk/WebCore/svg/SVGPolylineElement.cpp

    r66498 r69517  
    3838}
    3939
    40 Path SVGPolylineElement::toPathData() const
     40void SVGPolylineElement::toPathData(Path& path) const
    4141{
    42     Path polyData;
     42    ASSERT(path.isEmpty());
    4343
    4444    int len = points()->numberOfItems();
    4545    if (len < 1)
    46         return polyData;
     46        return;
    4747
    4848    ExceptionCode ec = 0;
    49     polyData.moveTo(points()->getItem(0, ec));
     49    path.moveTo(points()->getItem(0, ec));
    5050
    5151    for (int i = 1; i < len; ++i)
    52         polyData.addLineTo(points()->getItem(i, ec));
    53    
    54     return polyData;
     52        path.addLineTo(points()->getItem(i, ec));
    5553}
    5654
  • trunk/WebCore/svg/SVGPolylineElement.h

    r66397 r69517  
    3434        SVGPolylineElement(const QualifiedName&, Document*);
    3535
    36         virtual Path toPathData() const;
     36        virtual void toPathData(Path&) const;
    3737    };
    3838
  • trunk/WebCore/svg/SVGRectElement.cpp

    r69279 r69517  
    148148}
    149149
    150 Path SVGRectElement::toPathData() const
     150void SVGRectElement::toPathData(Path& path) const
    151151{
    152     FloatRect rect(x().value(this), y().value(this), width().value(this), height().value(this));
     152    ASSERT(path.isEmpty());
     153
     154    float widthValue = width().value(this);
     155    if (widthValue <= 0)
     156        return;
     157
     158    float heightValue = height().value(this);
     159    if (heightValue <= 0)
     160        return;
     161
     162    float xValue = x().value(this);
     163    float yValue = y().value(this);
     164
     165    FloatRect rect(xValue, yValue, widthValue, heightValue);
    153166
    154167    bool hasRx = hasAttribute(SVGNames::rxAttr);
    155168    bool hasRy = hasAttribute(SVGNames::ryAttr);
    156169    if (hasRx || hasRy) {
    157         float _rx = hasRx ? rx().value(this) : ry().value(this);
    158         float _ry = hasRy ? ry().value(this) : rx().value(this);
    159         return Path::createRoundedRectangle(rect, FloatSize(_rx, _ry));
     170        float rxValue = rx().value(this);
     171        float ryValue = ry().value(this);
     172        if (!hasRx)
     173            rxValue = ryValue;
     174        else if (!hasRy)
     175            ryValue = rxValue;
     176        path.addRoundedRect(rect, FloatSize(rxValue, ryValue));
     177        return;
    160178    }
    161179
    162     return Path::createRectangle(rect);
     180    path.addRect(rect);
    163181}
    164182
  • trunk/WebCore/svg/SVGRectElement.h

    r66397 r69517  
    4646        virtual void synchronizeProperty(const QualifiedName&);
    4747
    48         virtual Path toPathData() const;
     48        virtual void toPathData(Path&) const;
    4949
    5050        virtual bool selfHasRelativeLengths() const;
  • trunk/WebCore/svg/SVGStyledTransformableElement.cpp

    r69437 r69517  
    112112}
    113113
    114 Path SVGStyledTransformableElement::toClipPath() const
     114void SVGStyledTransformableElement::toClipPath(Path& path) const
    115115{
    116     Path pathData = toPathData();
     116    toPathData(path);
    117117    // FIXME: How do we know the element has done a layout?
    118     pathData.transform(animatedLocalTransform());
    119     return pathData;
     118    path.transform(animatedLocalTransform());
    120119}
    121120
  • trunk/WebCore/svg/SVGStyledTransformableElement.h

    r69437 r69517  
    5050
    5151    // "base class" methods for all the elements which render as paths
    52     virtual Path toPathData() const { return Path(); }
    53     virtual Path toClipPath() const;
     52    virtual void toPathData(Path&) const { }
     53    virtual void toClipPath(Path&) const;
    5454    virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
    5555
  • trunk/WebCore/svg/SVGUseElement.cpp

    r66973 r69517  
    625625}
    626626
    627 Path SVGUseElement::toClipPath() const
    628 {
     627void SVGUseElement::toClipPath(Path& path) const
     628{
     629    ASSERT(path.isEmpty());
     630
    629631    Node* n = m_targetElementInstance ? m_targetElementInstance->shadowTreeElement() : 0;
    630632    if (!n)
    631         return Path();
     633        return;
    632634
    633635    if (n->isSVGElement() && static_cast<SVGElement*>(n)->isStyledTransformable()) {
     
    636638            document()->accessSVGExtensions()->reportError("Not allowed to use indirect reference in <clip-path>");
    637639        else {
    638             Path clipPath = static_cast<SVGStyledTransformableElement*>(n)->toClipPath();
    639             clipPath.translate(FloatSize(x().value(this), y().value(this)));
    640             clipPath.transform(animatedLocalTransform());
    641             return clipPath;
     640            static_cast<SVGStyledTransformableElement*>(n)->toClipPath(path);
     641            path.translate(FloatSize(x().value(this), y().value(this)));
     642            path.transform(animatedLocalTransform());
    642643        }
    643644    }
    644 
    645     return Path();
    646645}
    647646
  • trunk/WebCore/svg/SVGUseElement.h

    r66397 r69517  
    6868        virtual void detach();
    6969
    70         virtual Path toClipPath() const;
     70        virtual void toClipPath(Path&) const;
    7171
    7272        static void removeDisallowedElementsFromSubtree(Node* element);
Note: See TracChangeset for help on using the changeset viewer.