[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

eric at webkit.org eric at webkit.org
Thu Apr 8 01:01:55 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit 786561be1f0a8f0c09ccb430b103cbe2c674956b
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Jan 12 11:28:18 2010 +0000

    2010-01-12  Simon Hausmann  <simon.hausmann at nokia.com>
    
            Reviewed by Holger Freyther.
    
            [Qt] WebCore::Path allocates QPainterPath unnecessarily on the heap
            https://bugs.webkit.org/show_bug.cgi?id=33466
    
            WebCore::Path is a pointer to a PlatformPath. In case of Qt that's a
            QPainterPath, which itself is a pointer to the elements (QVector).
            That creates unecessary allocations in PathQt.cpp.
    
            Replaced the "PlatformPath* m_path;" with a PlatformPathPtr, which
            is a plain QPainterPath.
    
            * platform/graphics/Path.h:
            (WebCore::Path::platformPath):
            * platform/graphics/qt/GraphicsContextQt.cpp:
            (WebCore::drawFilledShadowPath):
            (WebCore::GraphicsContext::fillPath):
            (WebCore::GraphicsContext::fillRoundedRect):
            (WebCore::GraphicsContext::addPath):
            (WebCore::GraphicsContext::clip):
            (WebCore::GraphicsContext::clipOut):
            * platform/graphics/qt/PathQt.cpp:
            (WebCore::Path::~Path):
            (WebCore::Path::operator=):
            (WebCore::Path::contains):
            (WebCore::Path::strokeContains):
            (WebCore::Path::translate):
            (WebCore::Path::boundingRect):
            (WebCore::Path::strokeBoundingRect):
            (WebCore::Path::moveTo):
            (WebCore::Path::addLineTo):
            (WebCore::Path::addQuadCurveTo):
            (WebCore::Path::addBezierCurveTo):
            (WebCore::Path::addArcTo):
            (WebCore::Path::closeSubpath):
            (WebCore::Path::addArc):
            (WebCore::Path::addRect):
            (WebCore::Path::addEllipse):
            (WebCore::Path::clear):
            (WebCore::Path::isEmpty):
            (WebCore::Path::debugString):
            (WebCore::Path::apply):
            (WebCore::Path::transform):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@53131 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 67f2275..7b0ee33 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,49 @@
+2010-01-12  Simon Hausmann  <simon.hausmann at nokia.com>
+
+        Reviewed by Holger Freyther.
+
+        [Qt] WebCore::Path allocates QPainterPath unnecessarily on the heap
+        https://bugs.webkit.org/show_bug.cgi?id=33466
+
+        WebCore::Path is a pointer to a PlatformPath. In case of Qt that's a
+        QPainterPath, which itself is a pointer to the elements (QVector).
+        That creates unecessary allocations in PathQt.cpp.
+
+        Replaced the "PlatformPath* m_path;" with a PlatformPathPtr, which
+        is a plain QPainterPath.
+
+        * platform/graphics/Path.h:
+        (WebCore::Path::platformPath):
+        * platform/graphics/qt/GraphicsContextQt.cpp:
+        (WebCore::drawFilledShadowPath):
+        (WebCore::GraphicsContext::fillPath):
+        (WebCore::GraphicsContext::fillRoundedRect):
+        (WebCore::GraphicsContext::addPath):
+        (WebCore::GraphicsContext::clip):
+        (WebCore::GraphicsContext::clipOut):
+        * platform/graphics/qt/PathQt.cpp:
+        (WebCore::Path::~Path):
+        (WebCore::Path::operator=):
+        (WebCore::Path::contains):
+        (WebCore::Path::strokeContains):
+        (WebCore::Path::translate):
+        (WebCore::Path::boundingRect):
+        (WebCore::Path::strokeBoundingRect):
+        (WebCore::Path::moveTo):
+        (WebCore::Path::addLineTo):
+        (WebCore::Path::addQuadCurveTo):
+        (WebCore::Path::addBezierCurveTo):
+        (WebCore::Path::addArcTo):
+        (WebCore::Path::closeSubpath):
+        (WebCore::Path::addArc):
+        (WebCore::Path::addRect):
+        (WebCore::Path::addEllipse):
+        (WebCore::Path::clear):
+        (WebCore::Path::isEmpty):
+        (WebCore::Path::debugString):
+        (WebCore::Path::apply):
+        (WebCore::Path::transform):
+
 2010-01-12  Jakub Wieczorek  <faw217 at gmail.com>
 
         Reviewed by Adam Barth.
diff --git a/WebCore/platform/graphics/Path.h b/WebCore/platform/graphics/Path.h
index bf4cd9d..79d6cc4 100644
--- a/WebCore/platform/graphics/Path.h
+++ b/WebCore/platform/graphics/Path.h
@@ -34,10 +34,7 @@
 #if PLATFORM(CG)
 typedef struct CGPath PlatformPath;
 #elif PLATFORM(QT)
-#include <qglobal.h>
-QT_BEGIN_NAMESPACE
-class QPainterPath;
-QT_END_NAMESPACE
+#include <qpainterpath.h>
 typedef QPainterPath PlatformPath;
 #elif PLATFORM(WX) && USE(WXGC)
 class wxGraphicsPath;
@@ -61,6 +58,13 @@ namespace WebCore {
 typedef void PlatformPath;
 #endif
 
+#if PLATFORM(QT)
+/* QPainterPath is valued based */
+typedef PlatformPath PlatformPathPtr;
+#else
+typedef PlatformPath* PlatformPathPtr;
+#endif
+
 namespace WebCore {
 
     class FloatPoint;
@@ -131,7 +135,7 @@ namespace WebCore {
 
         String debugString() const;
 
-        PlatformPath* platformPath() const { return m_path; }
+        PlatformPathPtr platformPath() const { return m_path; }
 
         static Path createRoundedRectangle(const FloatRect&, const FloatSize& roundingRadii);
         static Path createRoundedRectangle(const FloatRect&, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius);
@@ -144,7 +148,7 @@ namespace WebCore {
         void transform(const TransformationMatrix&);
 
     private:
-        PlatformPath* m_path;
+        PlatformPathPtr m_path;
     };
 
 }
diff --git a/WebCore/platform/graphics/qt/GraphicsContextQt.cpp b/WebCore/platform/graphics/qt/GraphicsContextQt.cpp
index ae31d4c..9f1b772 100644
--- a/WebCore/platform/graphics/qt/GraphicsContextQt.cpp
+++ b/WebCore/platform/graphics/qt/GraphicsContextQt.cpp
@@ -618,14 +618,14 @@ QPen GraphicsContext::pen()
     return p->pen();
 }
 
-static void inline drawFilledShadowPath(GraphicsContext* context, QPainter* p, const QPainterPath *path)
+static void inline drawFilledShadowPath(GraphicsContext* context, QPainter* p, const QPainterPath& path)
 {
     IntSize shadowSize;
     int shadowBlur;
     Color shadowColor;
     if (context->getShadow(shadowSize, shadowBlur, shadowColor)) {
         p->translate(shadowSize.width(), shadowSize.height());
-        p->fillPath(*path, QBrush(shadowColor));
+        p->fillPath(path, QBrush(shadowColor));
         p->translate(-shadowSize.width(), -shadowSize.height());
     }
 }
@@ -640,7 +640,7 @@ void GraphicsContext::fillPath()
     path.setFillRule(toQtFillRule(fillRule()));
 
     if (m_common->state.fillPattern || m_common->state.fillGradient || fillColor().alpha()) {
-        drawFilledShadowPath(this, p, &path);
+        drawFilledShadowPath(this, p, path);
         if (m_common->state.fillPattern) {
             TransformationMatrix affine;
             p->fillPath(path, QBrush(m_common->state.fillPattern->createPlatformPattern(affine)));
@@ -751,7 +751,7 @@ void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLef
     Path path = Path::createRoundedRectangle(rect, topLeft, topRight, bottomLeft, bottomRight);
     QPainter* p = m_data->p();
     drawFilledShadowPath(this, p, path.platformPath());
-    p->fillPath(*path.platformPath(), QColor(color));
+    p->fillPath(path.platformPath(), QColor(color));
 }
 
 void GraphicsContext::beginPath()
@@ -762,7 +762,7 @@ void GraphicsContext::beginPath()
 void GraphicsContext::addPath(const Path& path)
 {
     QPainterPath newPath = m_data->currentPath;
-    newPath.addPath(*(path.platformPath()));
+    newPath.addPath(path.platformPath());
     m_data->currentPath = newPath;
 }
 
@@ -1030,7 +1030,7 @@ void GraphicsContext::clip(const Path& path)
     if (paintingDisabled())
         return;
 
-    m_data->p()->setClipPath(*path.platformPath(), Qt::IntersectClip);
+    m_data->p()->setClipPath(path.platformPath(), Qt::IntersectClip);
 }
 
 void GraphicsContext::canvasClip(const Path& path)
@@ -1044,7 +1044,7 @@ void GraphicsContext::clipOut(const Path& path)
         return;
 
     QPainter* p = m_data->p();
-    QPainterPath clippedOut = *path.platformPath();
+    QPainterPath clippedOut = path.platformPath();
     QPainterPath newClip;
     newClip.setFillRule(Qt::OddEvenFill);
     if (p->hasClipping()) {
diff --git a/WebCore/platform/graphics/qt/PathQt.cpp b/WebCore/platform/graphics/qt/PathQt.cpp
index e5cecc8..4716d32 100644
--- a/WebCore/platform/graphics/qt/PathQt.cpp
+++ b/WebCore/platform/graphics/qt/PathQt.cpp
@@ -51,38 +51,32 @@
 namespace WebCore {
 
 Path::Path()
-    : m_path(new QPainterPath())
 {
 }
 
 Path::~Path()
 {
-    delete m_path;
 }
 
 Path::Path(const Path& other)
-    : m_path(new QPainterPath(*other.platformPath()))
+    : m_path(other.m_path)
 {
 }
 
 Path& Path::operator=(const Path& other)
 {
-    if (&other != this) {
-        delete m_path;
-        m_path = new QPainterPath(*other.platformPath());
-    }
-
+    m_path = other.m_path;
     return *this;
 }
 
 bool Path::contains(const FloatPoint& point, WindRule rule) const
 {
-    Qt::FillRule savedRule = m_path->fillRule();
-    m_path->setFillRule(rule == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);
+    Qt::FillRule savedRule = m_path.fillRule();
+    const_cast<QPainterPath*>(&m_path)->setFillRule(rule == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);
 
-    bool contains = m_path->contains(point);
+    bool contains = m_path.contains(point);
 
-    m_path->setFillRule(savedRule);
+    const_cast<QPainterPath*>(&m_path)->setFillRule(savedRule);
     return contains;
 }
 
@@ -105,19 +99,19 @@ bool Path::strokeContains(StrokeStyleApplier* applier, const FloatPoint& point)
     stroke.setDashPattern(pen.dashPattern());
     stroke.setDashOffset(pen.dashOffset());
 
-    return (stroke.createStroke(*platformPath())).contains(point);
+    return stroke.createStroke(m_path).contains(point);
 }
 
 void Path::translate(const FloatSize& size)
 {
     QTransform matrix;
     matrix.translate(size.width(), size.height());
-    *m_path = (*m_path) * matrix;
+    m_path = m_path * matrix;
 }
 
 FloatRect Path::boundingRect() const
 {
-    return m_path->boundingRect();
+    return m_path.boundingRect();
 }
 
 FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier)
@@ -138,35 +132,35 @@ FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier)
         stroke.setDashPattern(pen.dashPattern());
         stroke.setDashOffset(pen.dashOffset());
     }
-    return (stroke.createStroke(*platformPath())).boundingRect();
+    return stroke.createStroke(m_path).boundingRect();
 }
 
 void Path::moveTo(const FloatPoint& point)
 {
-    m_path->moveTo(point);
+    m_path.moveTo(point);
 }
 
 void Path::addLineTo(const FloatPoint& p)
 {
-    m_path->lineTo(p);
+    m_path.lineTo(p);
 }
 
 void Path::addQuadCurveTo(const FloatPoint& cp, const FloatPoint& p)
 {
-    m_path->quadTo(cp, p);
+    m_path.quadTo(cp, p);
 }
 
 void Path::addBezierCurveTo(const FloatPoint& cp1, const FloatPoint& cp2, const FloatPoint& p)
 {
-    m_path->cubicTo(cp1, cp2, p);
+    m_path.cubicTo(cp1, cp2, p);
 }
 
 void Path::addArcTo(const FloatPoint& p1, const FloatPoint& p2, float radius)
 {
-    FloatPoint p0(m_path->currentPosition());
+    FloatPoint p0(m_path.currentPosition());
 
     if ((p1.x() == p0.x() && p1.y() == p0.y()) || (p1.x() == p2.x() && p1.y() == p2.y()) || radius == 0.f) {
-        m_path->lineTo(p1);
+        m_path.lineTo(p1);
         return;
     }
 
@@ -178,7 +172,7 @@ void Path::addArcTo(const FloatPoint& p1, const FloatPoint& p2, float radius)
     double cos_phi = (p1p0.x() * p1p2.x() + p1p0.y() * p1p2.y()) / (p1p0_length * p1p2_length);
     // all points on a line logic
     if (cos_phi == -1) {
-        m_path->lineTo(p1);
+        m_path.lineTo(p1);
         return;
     }
     if (cos_phi == 1) {
@@ -186,7 +180,7 @@ void Path::addArcTo(const FloatPoint& p1, const FloatPoint& p2, float radius)
         unsigned int max_length = 65535;
         double factor_max = max_length / p1p0_length;
         FloatPoint ep((p0.x() + factor_max * p1p0.x()), (p0.y() + factor_max * p1p0.y()));
-        m_path->lineTo(ep);
+        m_path.lineTo(ep);
         return;
     }
 
@@ -226,14 +220,14 @@ void Path::addArcTo(const FloatPoint& p1, const FloatPoint& p2, float radius)
     if ((sa < ea) && ((ea - sa) > piDouble))
         anticlockwise = true;
 
-    m_path->lineTo(t_p1p0);
+    m_path.lineTo(t_p1p0);
 
     addArc(p, radius, sa, ea, anticlockwise);
 }
 
 void Path::closeSubpath()
 {
-    m_path->closeSubpath();
+    m_path.closeSubpath();
 }
 
 #define DEGREES(t) ((t) * 180.0 / M_PI)
@@ -275,32 +269,32 @@ void Path::addArc(const FloatPoint& p, float r, float sar, float ear, bool antic
         span += ea - sa;
     }
 
-    m_path->moveTo(QPointF(xc + radius  * cos(sar),
+    m_path.moveTo(QPointF(xc + radius  * cos(sar),
                           yc - radius  * sin(sar)));
 
-    m_path->arcTo(xs, ys, width, height, sa, span);
+    m_path.arcTo(xs, ys, width, height, sa, span);
 }
 
 void Path::addRect(const FloatRect& r)
 {
-    m_path->addRect(r.x(), r.y(), r.width(), r.height());
+    m_path.addRect(r.x(), r.y(), r.width(), r.height());
 }
 
 void Path::addEllipse(const FloatRect& r)
 {
-    m_path->addEllipse(r.x(), r.y(), r.width(), r.height());
+    m_path.addEllipse(r.x(), r.y(), r.width(), r.height());
 }
 
 void Path::clear()
 {
-    *m_path = QPainterPath();
+    m_path = QPainterPath();
 }
 
 bool Path::isEmpty() const
 {
     // Don't use QPainterPath::isEmpty(), as that also returns true if there's only
     // one initial MoveTo element in the path.
-    return !m_path->elementCount();
+    return !m_path.elementCount();
 }
 
 bool Path::hasCurrentPoint() const
@@ -311,8 +305,8 @@ bool Path::hasCurrentPoint() const
 String Path::debugString() const
 {
     QString ret;
-    for (int i = 0; i < m_path->elementCount(); ++i) {
-        const QPainterPath::Element &cur = m_path->elementAt(i);
+    for (int i = 0; i < m_path.elementCount(); ++i) {
+        const QPainterPath::Element &cur = m_path.elementAt(i);
 
         switch (cur.type) {
             case QPainterPath::MoveToElement:
@@ -323,8 +317,8 @@ String Path::debugString() const
                 break;
             case QPainterPath::CurveToElement:
             {
-                const QPainterPath::Element &c1 = m_path->elementAt(i + 1);
-                const QPainterPath::Element &c2 = m_path->elementAt(i + 2);
+                const QPainterPath::Element &c1 = m_path.elementAt(i + 1);
+                const QPainterPath::Element &c2 = m_path.elementAt(i + 2);
 
                 Q_ASSERT(c1.type == QPainterPath::CurveToDataElement);
                 Q_ASSERT(c2.type == QPainterPath::CurveToDataElement);
@@ -348,8 +342,8 @@ void Path::apply(void* info, PathApplierFunction function) const
     PathElement pelement;
     FloatPoint points[3];
     pelement.points = points;
-    for (int i = 0; i < m_path->elementCount(); ++i) {
-        const QPainterPath::Element& cur = m_path->elementAt(i);
+    for (int i = 0; i < m_path.elementCount(); ++i) {
+        const QPainterPath::Element& cur = m_path.elementAt(i);
 
         switch (cur.type) {
             case QPainterPath::MoveToElement:
@@ -364,8 +358,8 @@ void Path::apply(void* info, PathApplierFunction function) const
                 break;
             case QPainterPath::CurveToElement:
             {
-                const QPainterPath::Element& c1 = m_path->elementAt(i + 1);
-                const QPainterPath::Element& c2 = m_path->elementAt(i + 2);
+                const QPainterPath::Element& c1 = m_path.elementAt(i + 1);
+                const QPainterPath::Element& c2 = m_path.elementAt(i + 2);
 
                 Q_ASSERT(c1.type == QPainterPath::CurveToDataElement);
                 Q_ASSERT(c2.type == QPainterPath::CurveToDataElement);
@@ -387,12 +381,7 @@ void Path::apply(void* info, PathApplierFunction function) const
 
 void Path::transform(const TransformationMatrix& transform)
 {
-    if (m_path) {
-        QTransform mat = transform;
-        QPainterPath temp = mat.map(*m_path);
-        delete m_path;
-        m_path = new QPainterPath(temp);
-    }
+    m_path = QTransform(transform).map(m_path);
 }
 
 }

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list