Changeset 53131 in webkit
- Timestamp:
- Jan 12, 2010 3:28:18 AM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r53127 r53131 1 2010-01-12 Simon Hausmann <simon.hausmann@nokia.com> 2 3 Reviewed by Holger Freyther. 4 5 [Qt] WebCore::Path allocates QPainterPath unnecessarily on the heap 6 https://bugs.webkit.org/show_bug.cgi?id=33466 7 8 WebCore::Path is a pointer to a PlatformPath. In case of Qt that's a 9 QPainterPath, which itself is a pointer to the elements (QVector). 10 That creates unecessary allocations in PathQt.cpp. 11 12 Replaced the "PlatformPath* m_path;" with a PlatformPathPtr, which 13 is a plain QPainterPath. 14 15 * platform/graphics/Path.h: 16 (WebCore::Path::platformPath): 17 * platform/graphics/qt/GraphicsContextQt.cpp: 18 (WebCore::drawFilledShadowPath): 19 (WebCore::GraphicsContext::fillPath): 20 (WebCore::GraphicsContext::fillRoundedRect): 21 (WebCore::GraphicsContext::addPath): 22 (WebCore::GraphicsContext::clip): 23 (WebCore::GraphicsContext::clipOut): 24 * platform/graphics/qt/PathQt.cpp: 25 (WebCore::Path::~Path): 26 (WebCore::Path::operator=): 27 (WebCore::Path::contains): 28 (WebCore::Path::strokeContains): 29 (WebCore::Path::translate): 30 (WebCore::Path::boundingRect): 31 (WebCore::Path::strokeBoundingRect): 32 (WebCore::Path::moveTo): 33 (WebCore::Path::addLineTo): 34 (WebCore::Path::addQuadCurveTo): 35 (WebCore::Path::addBezierCurveTo): 36 (WebCore::Path::addArcTo): 37 (WebCore::Path::closeSubpath): 38 (WebCore::Path::addArc): 39 (WebCore::Path::addRect): 40 (WebCore::Path::addEllipse): 41 (WebCore::Path::clear): 42 (WebCore::Path::isEmpty): 43 (WebCore::Path::debugString): 44 (WebCore::Path::apply): 45 (WebCore::Path::transform): 46 1 47 2010-01-12 Jakub Wieczorek <faw217@gmail.com> 2 48 -
trunk/WebCore/platform/graphics/Path.h
r52791 r53131 35 35 typedef struct CGPath PlatformPath; 36 36 #elif PLATFORM(QT) 37 #include <qglobal.h> 38 QT_BEGIN_NAMESPACE 39 class QPainterPath; 40 QT_END_NAMESPACE 37 #include <qpainterpath.h> 41 38 typedef QPainterPath PlatformPath; 42 39 #elif PLATFORM(WX) && USE(WXGC) … … 60 57 #else 61 58 typedef void PlatformPath; 59 #endif 60 61 #if PLATFORM(QT) 62 /* QPainterPath is valued based */ 63 typedef PlatformPath PlatformPathPtr; 64 #else 65 typedef PlatformPath* PlatformPathPtr; 62 66 #endif 63 67 … … 132 136 String debugString() const; 133 137 134 PlatformPath *platformPath() const { return m_path; }138 PlatformPathPtr platformPath() const { return m_path; } 135 139 136 140 static Path createRoundedRectangle(const FloatRect&, const FloatSize& roundingRadii); … … 145 149 146 150 private: 147 PlatformPath *m_path;151 PlatformPathPtr m_path; 148 152 }; 149 153 -
trunk/WebCore/platform/graphics/qt/GraphicsContextQt.cpp
r52791 r53131 619 619 } 620 620 621 static void inline drawFilledShadowPath(GraphicsContext* context, QPainter* p, const QPainterPath *path)621 static void inline drawFilledShadowPath(GraphicsContext* context, QPainter* p, const QPainterPath& path) 622 622 { 623 623 IntSize shadowSize; … … 626 626 if (context->getShadow(shadowSize, shadowBlur, shadowColor)) { 627 627 p->translate(shadowSize.width(), shadowSize.height()); 628 p->fillPath( *path, QBrush(shadowColor));628 p->fillPath(path, QBrush(shadowColor)); 629 629 p->translate(-shadowSize.width(), -shadowSize.height()); 630 630 } … … 641 641 642 642 if (m_common->state.fillPattern || m_common->state.fillGradient || fillColor().alpha()) { 643 drawFilledShadowPath(this, p, &path);643 drawFilledShadowPath(this, p, path); 644 644 if (m_common->state.fillPattern) { 645 645 TransformationMatrix affine; … … 752 752 QPainter* p = m_data->p(); 753 753 drawFilledShadowPath(this, p, path.platformPath()); 754 p->fillPath( *path.platformPath(), QColor(color));754 p->fillPath(path.platformPath(), QColor(color)); 755 755 } 756 756 … … 763 763 { 764 764 QPainterPath newPath = m_data->currentPath; 765 newPath.addPath( *(path.platformPath()));765 newPath.addPath(path.platformPath()); 766 766 m_data->currentPath = newPath; 767 767 } … … 1031 1031 return; 1032 1032 1033 m_data->p()->setClipPath( *path.platformPath(), Qt::IntersectClip);1033 m_data->p()->setClipPath(path.platformPath(), Qt::IntersectClip); 1034 1034 } 1035 1035 … … 1045 1045 1046 1046 QPainter* p = m_data->p(); 1047 QPainterPath clippedOut = *path.platformPath();1047 QPainterPath clippedOut = path.platformPath(); 1048 1048 QPainterPath newClip; 1049 1049 newClip.setFillRule(Qt::OddEvenFill); -
trunk/WebCore/platform/graphics/qt/PathQt.cpp
r46956 r53131 52 52 53 53 Path::Path() 54 : m_path(new QPainterPath())55 54 { 56 55 } … … 58 57 Path::~Path() 59 58 { 60 delete m_path;61 59 } 62 60 63 61 Path::Path(const Path& other) 64 : m_path( new QPainterPath(*other.platformPath()))62 : m_path(other.m_path) 65 63 { 66 64 } … … 68 66 Path& Path::operator=(const Path& other) 69 67 { 70 if (&other != this) { 71 delete m_path; 72 m_path = new QPainterPath(*other.platformPath()); 73 } 74 68 m_path = other.m_path; 75 69 return *this; 76 70 } … … 78 72 bool Path::contains(const FloatPoint& point, WindRule rule) const 79 73 { 80 Qt::FillRule savedRule = m_path ->fillRule();81 m_path->setFillRule(rule == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);82 83 bool contains = m_path ->contains(point);84 85 m_path->setFillRule(savedRule);74 Qt::FillRule savedRule = m_path.fillRule(); 75 const_cast<QPainterPath*>(&m_path)->setFillRule(rule == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill); 76 77 bool contains = m_path.contains(point); 78 79 const_cast<QPainterPath*>(&m_path)->setFillRule(savedRule); 86 80 return contains; 87 81 } … … 106 100 stroke.setDashOffset(pen.dashOffset()); 107 101 108 return (stroke.createStroke(*platformPath())).contains(point);102 return stroke.createStroke(m_path).contains(point); 109 103 } 110 104 … … 113 107 QTransform matrix; 114 108 matrix.translate(size.width(), size.height()); 115 *m_path = (*m_path)* matrix;109 m_path = m_path * matrix; 116 110 } 117 111 118 112 FloatRect Path::boundingRect() const 119 113 { 120 return m_path ->boundingRect();114 return m_path.boundingRect(); 121 115 } 122 116 … … 139 133 stroke.setDashOffset(pen.dashOffset()); 140 134 } 141 return (stroke.createStroke(*platformPath())).boundingRect();135 return stroke.createStroke(m_path).boundingRect(); 142 136 } 143 137 144 138 void Path::moveTo(const FloatPoint& point) 145 139 { 146 m_path ->moveTo(point);140 m_path.moveTo(point); 147 141 } 148 142 149 143 void Path::addLineTo(const FloatPoint& p) 150 144 { 151 m_path ->lineTo(p);145 m_path.lineTo(p); 152 146 } 153 147 154 148 void Path::addQuadCurveTo(const FloatPoint& cp, const FloatPoint& p) 155 149 { 156 m_path ->quadTo(cp, p);150 m_path.quadTo(cp, p); 157 151 } 158 152 159 153 void Path::addBezierCurveTo(const FloatPoint& cp1, const FloatPoint& cp2, const FloatPoint& p) 160 154 { 161 m_path ->cubicTo(cp1, cp2, p);155 m_path.cubicTo(cp1, cp2, p); 162 156 } 163 157 164 158 void Path::addArcTo(const FloatPoint& p1, const FloatPoint& p2, float radius) 165 159 { 166 FloatPoint p0(m_path ->currentPosition());160 FloatPoint p0(m_path.currentPosition()); 167 161 168 162 if ((p1.x() == p0.x() && p1.y() == p0.y()) || (p1.x() == p2.x() && p1.y() == p2.y()) || radius == 0.f) { 169 m_path ->lineTo(p1);163 m_path.lineTo(p1); 170 164 return; 171 165 } … … 179 173 // all points on a line logic 180 174 if (cos_phi == -1) { 181 m_path ->lineTo(p1);175 m_path.lineTo(p1); 182 176 return; 183 177 } … … 187 181 double factor_max = max_length / p1p0_length; 188 182 FloatPoint ep((p0.x() + factor_max * p1p0.x()), (p0.y() + factor_max * p1p0.y())); 189 m_path ->lineTo(ep);183 m_path.lineTo(ep); 190 184 return; 191 185 } … … 227 221 anticlockwise = true; 228 222 229 m_path ->lineTo(t_p1p0);223 m_path.lineTo(t_p1p0); 230 224 231 225 addArc(p, radius, sa, ea, anticlockwise); … … 234 228 void Path::closeSubpath() 235 229 { 236 m_path ->closeSubpath();230 m_path.closeSubpath(); 237 231 } 238 232 … … 276 270 } 277 271 278 m_path ->moveTo(QPointF(xc + radius * cos(sar),272 m_path.moveTo(QPointF(xc + radius * cos(sar), 279 273 yc - radius * sin(sar))); 280 274 281 m_path ->arcTo(xs, ys, width, height, sa, span);275 m_path.arcTo(xs, ys, width, height, sa, span); 282 276 } 283 277 284 278 void Path::addRect(const FloatRect& r) 285 279 { 286 m_path ->addRect(r.x(), r.y(), r.width(), r.height());280 m_path.addRect(r.x(), r.y(), r.width(), r.height()); 287 281 } 288 282 289 283 void Path::addEllipse(const FloatRect& r) 290 284 { 291 m_path ->addEllipse(r.x(), r.y(), r.width(), r.height());285 m_path.addEllipse(r.x(), r.y(), r.width(), r.height()); 292 286 } 293 287 294 288 void Path::clear() 295 289 { 296 *m_path = QPainterPath();290 m_path = QPainterPath(); 297 291 } 298 292 … … 301 295 // Don't use QPainterPath::isEmpty(), as that also returns true if there's only 302 296 // one initial MoveTo element in the path. 303 return !m_path ->elementCount();297 return !m_path.elementCount(); 304 298 } 305 299 … … 312 306 { 313 307 QString ret; 314 for (int i = 0; i < m_path ->elementCount(); ++i) {315 const QPainterPath::Element &cur = m_path ->elementAt(i);308 for (int i = 0; i < m_path.elementCount(); ++i) { 309 const QPainterPath::Element &cur = m_path.elementAt(i); 316 310 317 311 switch (cur.type) { … … 324 318 case QPainterPath::CurveToElement: 325 319 { 326 const QPainterPath::Element &c1 = m_path ->elementAt(i + 1);327 const QPainterPath::Element &c2 = m_path ->elementAt(i + 2);320 const QPainterPath::Element &c1 = m_path.elementAt(i + 1); 321 const QPainterPath::Element &c2 = m_path.elementAt(i + 2); 328 322 329 323 Q_ASSERT(c1.type == QPainterPath::CurveToDataElement); … … 349 343 FloatPoint points[3]; 350 344 pelement.points = points; 351 for (int i = 0; i < m_path ->elementCount(); ++i) {352 const QPainterPath::Element& cur = m_path ->elementAt(i);345 for (int i = 0; i < m_path.elementCount(); ++i) { 346 const QPainterPath::Element& cur = m_path.elementAt(i); 353 347 354 348 switch (cur.type) { … … 365 359 case QPainterPath::CurveToElement: 366 360 { 367 const QPainterPath::Element& c1 = m_path ->elementAt(i + 1);368 const QPainterPath::Element& c2 = m_path ->elementAt(i + 2);361 const QPainterPath::Element& c1 = m_path.elementAt(i + 1); 362 const QPainterPath::Element& c2 = m_path.elementAt(i + 2); 369 363 370 364 Q_ASSERT(c1.type == QPainterPath::CurveToDataElement); … … 388 382 void Path::transform(const TransformationMatrix& transform) 389 383 { 390 if (m_path) { 391 QTransform mat = transform; 392 QPainterPath temp = mat.map(*m_path); 393 delete m_path; 394 m_path = new QPainterPath(temp); 395 } 384 m_path = QTransform(transform).map(m_path); 396 385 } 397 386
Note: See TracChangeset
for help on using the changeset viewer.