Bug 589648 part 2. Stop hardcoding the segment argument count in SVGPathData::ConstructPath. r=longsonr.
authorJonathan Watt <jwatt@jwatt.org>
Wed, 20 Apr 2011 10:16:02 +0100
changeset 68722 ccd5d505ab00c637ec429fe6f710834b4a4f185a
parent 68721 cbaa924ffecac763b1b7d6a1e9da2589367371f6
child 68723 5b78983c482249186af83a3895c8080af15fe077
push id11
push userffxbld
push dateThu, 11 Aug 2011 21:43:38 +0000
treeherdermozilla-release@cf0a29826586 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslongsonr
bugs589648
milestone6.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 589648 part 2. Stop hardcoding the segment argument count in SVGPathData::ConstructPath. r=longsonr.
content/svg/content/src/SVGPathData.cpp
--- a/content/svg/content/src/SVGPathData.cpp
+++ b/content/svg/content/src/SVGPathData.cpp
@@ -253,82 +253,75 @@ SVGPathData::ConstructPath(gfxContext *a
 
   // Regarding cp1 and cp2: If the previous segment was a cubic bezier curve,
   // then cp2 is its second control point. If the previous segment was a
   // quadratic curve, then cp1 is its (only) control point.
 
   PRUint32 i = 0;
   while (i < mData.Length()) {
     segType = SVGPathSegUtils::DecodeType(mData[i++]);
+    PRUint32 argCount = SVGPathSegUtils::ArgCountForType(segType);
 
     switch (segType)
     {
     case nsIDOMSVGPathSeg::PATHSEG_CLOSEPATH:
       segEnd = pathStart;
       aCtx->ClosePath();
       break;
 
     case nsIDOMSVGPathSeg::PATHSEG_MOVETO_ABS:
       pathStart = segEnd = gfxPoint(mData[i], mData[i+1]);
       aCtx->MoveTo(segEnd);
-      i += 2;
       break;
 
     case nsIDOMSVGPathSeg::PATHSEG_MOVETO_REL:
       pathStart = segEnd = segStart + gfxPoint(mData[i], mData[i+1]);
       aCtx->MoveTo(segEnd);
-      i += 2;
       break;
 
     case nsIDOMSVGPathSeg::PATHSEG_LINETO_ABS:
       segEnd = gfxPoint(mData[i], mData[i+1]);
       aCtx->LineTo(segEnd);
-      i += 2;
       break;
 
     case nsIDOMSVGPathSeg::PATHSEG_LINETO_REL:
       segEnd = segStart + gfxPoint(mData[i], mData[i+1]);
       aCtx->LineTo(segEnd);
-      i += 2;
       break;
 
     case nsIDOMSVGPathSeg::PATHSEG_CURVETO_CUBIC_ABS:
       cp1 = gfxPoint(mData[i], mData[i+1]);
       cp2 = gfxPoint(mData[i+2], mData[i+3]);
       segEnd = gfxPoint(mData[i+4], mData[i+5]);
       aCtx->CurveTo(cp1, cp2, segEnd);
-      i += 6;
       break;
 
     case nsIDOMSVGPathSeg::PATHSEG_CURVETO_CUBIC_REL:
       cp1 = segStart + gfxPoint(mData[i], mData[i+1]);
       cp2 = segStart + gfxPoint(mData[i+2], mData[i+3]);
       segEnd = segStart + gfxPoint(mData[i+4], mData[i+5]);
       aCtx->CurveTo(cp1, cp2, segEnd);
-      i += 6;
       break;
 
     case nsIDOMSVGPathSeg::PATHSEG_CURVETO_QUADRATIC_ABS:
       cp1 = gfxPoint(mData[i], mData[i+1]);
       // Convert quadratic curve to cubic curve:
       tcp1 = segStart + (cp1 - segStart) * 2 / 3;
       segEnd = gfxPoint(mData[i+2], mData[i+3]); // set before setting tcp2!
       tcp2 = cp1 + (segEnd - cp1) / 3;
       aCtx->CurveTo(tcp1, tcp2, segEnd);
-      i += 4;
       break;
 
     case nsIDOMSVGPathSeg::PATHSEG_CURVETO_QUADRATIC_REL:
       cp1 = segStart + gfxPoint(mData[i], mData[i+1]);
       // Convert quadratic curve to cubic curve:
       tcp1 = segStart + (cp1 - segStart) * 2 / 3;
       segEnd = segStart + gfxPoint(mData[i+2], mData[i+3]); // set before setting tcp2!
       tcp2 = cp1 + (segEnd - cp1) / 3;
       aCtx->CurveTo(tcp1, tcp2, segEnd);
-      i += 4;
       break;
 
     case nsIDOMSVGPathSeg::PATHSEG_ARC_ABS:
     case nsIDOMSVGPathSeg::PATHSEG_ARC_REL:
     {
       gfxPoint radii(mData[i], mData[i+1]);
       gfxPoint segEnd = gfxPoint(mData[i+5], mData[i+6]);
       if (segType == nsIDOMSVGPathSeg::PATHSEG_ARC_REL) {
@@ -340,80 +333,76 @@ SVGPathData::ConstructPath(gfxContext *a
         } else {
           nsSVGArcConverter converter(segStart, segEnd, radii, mData[i+2],
                                       mData[i+3] != 0, mData[i+4] != 0);
           while (converter.GetNextSegment(&cp1, &cp2, &segEnd)) {
             aCtx->CurveTo(cp1, cp2, segEnd);
           }
         }
       }
-      i += 7;
       break;
     }
 
     case nsIDOMSVGPathSeg::PATHSEG_LINETO_HORIZONTAL_ABS:
-      segEnd = gfxPoint(mData[i++], segStart.y);
+      segEnd = gfxPoint(mData[i], segStart.y);
       aCtx->LineTo(segEnd);
       break;
 
     case nsIDOMSVGPathSeg::PATHSEG_LINETO_HORIZONTAL_REL:
-      segEnd = segStart + gfxPoint(mData[i++], 0.0f);
+      segEnd = segStart + gfxPoint(mData[i], 0.0f);
       aCtx->LineTo(segEnd);
       break;
 
     case nsIDOMSVGPathSeg::PATHSEG_LINETO_VERTICAL_ABS:
-      segEnd = gfxPoint(segStart.x, mData[i++]);
+      segEnd = gfxPoint(segStart.x, mData[i]);
       aCtx->LineTo(segEnd);
       break;
 
     case nsIDOMSVGPathSeg::PATHSEG_LINETO_VERTICAL_REL:
-      segEnd = segStart + gfxPoint(0.0f, mData[i++]);
+      segEnd = segStart + gfxPoint(0.0f, mData[i]);
       aCtx->LineTo(segEnd);
       break;
 
     case nsIDOMSVGPathSeg::PATHSEG_CURVETO_CUBIC_SMOOTH_ABS:
       cp1 = SVGPathSegUtils::IsCubicType(prevSegType) ? segStart * 2 - cp2 : segStart;
       cp2 = gfxPoint(mData[i],   mData[i+1]);
       segEnd = gfxPoint(mData[i+2], mData[i+3]);
       aCtx->CurveTo(cp1, cp2, segEnd);
-      i += 4;
       break;
 
     case nsIDOMSVGPathSeg::PATHSEG_CURVETO_CUBIC_SMOOTH_REL:
       cp1 = SVGPathSegUtils::IsCubicType(prevSegType) ? segStart * 2 - cp2 : segStart;
       cp2 = segStart + gfxPoint(mData[i], mData[i+1]);
       segEnd = segStart + gfxPoint(mData[i+2], mData[i+3]);
       aCtx->CurveTo(cp1, cp2, segEnd);
-      i += 4;
       break;
 
     case nsIDOMSVGPathSeg::PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS:
       cp1 = SVGPathSegUtils::IsQuadraticType(prevSegType) ? segStart * 2 - cp1 : segStart;
       // Convert quadratic curve to cubic curve:
       tcp1 = segStart + (cp1 - segStart) * 2 / 3;
       segEnd = gfxPoint(mData[i], mData[i+1]); // set before setting tcp2!
       tcp2 = cp1 + (segEnd - cp1) / 3;
       aCtx->CurveTo(tcp1, tcp2, segEnd);
-      i += 2;
       break;
 
     case nsIDOMSVGPathSeg::PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL:
       cp1 = SVGPathSegUtils::IsQuadraticType(prevSegType) ? segStart * 2 - cp1 : segStart;
       // Convert quadratic curve to cubic curve:
       tcp1 = segStart + (cp1 - segStart) * 2 / 3;
       segEnd = segStart + gfxPoint(mData[i], mData[i+1]); // changed before setting tcp2!
       tcp2 = cp1 + (segEnd - cp1) / 3;
       aCtx->CurveTo(tcp1, tcp2, segEnd);
-      i += 2;
       break;
 
     default:
       NS_NOTREACHED("Bad path segment type");
       return; // according to spec we'd use everything up to the bad seg anyway
     }
+    i += argCount;
     prevSegType = segType;
     segStart = segEnd;
   }
   NS_ABORT_IF_FALSE(i == mData.Length(), "Very, very bad - mData corrupt");
 }
 
 already_AddRefed<gfxFlattenedPath>
 SVGPathData::ToFlattenedPath(const gfxMatrix& aMatrix) const