Bug 932762, part 1 - Get rid of nsSVGPathGeometryElement::CreatePathBuilder and make BuildPath's aBuilder argument non-optional. r=longsonr

This commit is contained in:
Jonathan Watt 2014-10-04 12:13:30 +01:00
parent 4963137d17
commit a59360db7f
15 changed files with 30 additions and 85 deletions

View File

@ -91,11 +91,9 @@ SVGCircleElement::BuildPath(PathBuilder* aBuilder)
return nullptr;
}
RefPtr<PathBuilder> pathBuilder = aBuilder ? aBuilder : CreatePathBuilder();
aBuilder->Arc(Point(x, y), r, 0, Float(2*M_PI));
pathBuilder->Arc(Point(x, y), r, 0, Float(2*M_PI));
return pathBuilder->Finish();
return aBuilder->Finish();
}
} // namespace dom

View File

@ -30,7 +30,7 @@ public:
virtual bool HasValidDimensions() const MOZ_OVERRIDE;
// nsSVGPathGeometryElement methods:
virtual TemporaryRef<Path> BuildPath(PathBuilder* aBuilder = nullptr) MOZ_OVERRIDE;
virtual TemporaryRef<Path> BuildPath(PathBuilder* aBuilder) MOZ_OVERRIDE;
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;

View File

@ -102,11 +102,9 @@ SVGEllipseElement::BuildPath(PathBuilder* aBuilder)
return nullptr;
}
RefPtr<PathBuilder> pathBuilder = aBuilder ? aBuilder : CreatePathBuilder();
EllipseToBezier(aBuilder, Point(x, y), Size(rx, ry));
EllipseToBezier(pathBuilder.get(), Point(x, y), Size(rx, ry));
return pathBuilder->Finish();
return aBuilder->Finish();
}
} // namespace dom

View File

@ -30,7 +30,7 @@ public:
virtual bool HasValidDimensions() const MOZ_OVERRIDE;
// nsSVGPathGeometryElement methods:
virtual TemporaryRef<Path> BuildPath(PathBuilder* aBuilder = nullptr) MOZ_OVERRIDE;
virtual TemporaryRef<Path> BuildPath(PathBuilder* aBuilder) MOZ_OVERRIDE;
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;

View File

@ -239,16 +239,14 @@ SVGImageElement::BuildPath(PathBuilder* aBuilder)
return nullptr;
}
RefPtr<PathBuilder> pathBuilder = aBuilder ? aBuilder : CreatePathBuilder();
Rect r(x, y, width, height);
pathBuilder->MoveTo(r.TopLeft());
pathBuilder->LineTo(r.TopRight());
pathBuilder->LineTo(r.BottomRight());
pathBuilder->LineTo(r.BottomLeft());
pathBuilder->Close();
aBuilder->MoveTo(r.TopLeft());
aBuilder->LineTo(r.TopRight());
aBuilder->LineTo(r.BottomRight());
aBuilder->LineTo(r.BottomLeft());
aBuilder->Close();
return pathBuilder->Finish();
return aBuilder->Finish();
}
//----------------------------------------------------------------------

View File

@ -53,7 +53,7 @@ public:
NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* name) const MOZ_OVERRIDE;
// nsSVGPathGeometryElement methods:
virtual TemporaryRef<Path> BuildPath(PathBuilder* aBuilder = nullptr) MOZ_OVERRIDE;
virtual TemporaryRef<Path> BuildPath(PathBuilder* aBuilder) MOZ_OVERRIDE;
// nsSVGSVGElement methods:
virtual bool HasValidDimensions() const MOZ_OVERRIDE;

View File

@ -109,15 +109,13 @@ SVGLineElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks) {
TemporaryRef<Path>
SVGLineElement::BuildPath(PathBuilder* aBuilder)
{
RefPtr<PathBuilder> pathBuilder = aBuilder ? aBuilder : CreatePathBuilder();
float x1, y1, x2, y2;
GetAnimatedLengthValues(&x1, &y1, &x2, &y2, nullptr);
pathBuilder->MoveTo(Point(x1, y1));
pathBuilder->LineTo(Point(x2, y2));
aBuilder->MoveTo(Point(x1, y1));
aBuilder->LineTo(Point(x2, y2));
return pathBuilder->Finish();
return aBuilder->Finish();
}
} // namespace dom

View File

@ -32,7 +32,7 @@ public:
// nsSVGPathGeometryElement methods:
virtual bool IsMarkable() MOZ_OVERRIDE { return true; }
virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks) MOZ_OVERRIDE;
virtual TemporaryRef<Path> BuildPath(PathBuilder* aBuilder = nullptr) MOZ_OVERRIDE;
virtual TemporaryRef<Path> BuildPath(PathBuilder* aBuilder) MOZ_OVERRIDE;
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const;

View File

@ -390,24 +390,7 @@ SVGPathElement::BuildPath(PathBuilder* aBuilder)
}
}
RefPtr<PathBuilder> builder;
if (aBuilder) {
builder = aBuilder;
} else {
RefPtr<DrawTarget> drawTarget =
gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
// The fill rule that we pass must be the current computed value of our
// CSS 'fill-rule' property if the path that we return will be used for
// painting or hit-testing. For all other uses (bounds calculatons, length
// measurement, position-at-offset calculations) the fill rule that we pass
// doesn't matter. As a result we can just pass the current computed value
// regardless of who's calling us, or what they're going to do with the
// path that we return.
RefPtr<PathBuilder> builder =
drawTarget->CreatePathBuilder(GetFillRule());
}
return mD.GetAnimValue().BuildPath(builder, strokeLineCap, strokeWidth);
return mD.GetAnimValue().BuildPath(aBuilder, strokeLineCap, strokeWidth);
}
} // namespace dom

View File

@ -50,7 +50,7 @@ public:
virtual bool AttributeDefinesGeometry(const nsIAtom *aName) MOZ_OVERRIDE;
virtual bool IsMarkable() MOZ_OVERRIDE;
virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks) MOZ_OVERRIDE;
virtual TemporaryRef<Path> BuildPath(PathBuilder* aBuilder = nullptr) MOZ_OVERRIDE;
virtual TemporaryRef<Path> BuildPath(PathBuilder* aBuilder) MOZ_OVERRIDE;
/**
* This returns a path without the extra little line segments that

View File

@ -118,19 +118,17 @@ SVGRectElement::BuildPath(PathBuilder* aBuilder)
return nullptr;
}
RefPtr<PathBuilder> pathBuilder = aBuilder ? aBuilder : CreatePathBuilder();
rx = std::max(rx, 0.0f);
ry = std::max(ry, 0.0f);
if (rx == 0 && ry == 0) {
// Optimization for the no rounded corners case.
Rect r(x, y, width, height);
pathBuilder->MoveTo(r.TopLeft());
pathBuilder->LineTo(r.TopRight());
pathBuilder->LineTo(r.BottomRight());
pathBuilder->LineTo(r.BottomLeft());
pathBuilder->Close();
aBuilder->MoveTo(r.TopLeft());
aBuilder->LineTo(r.TopRight());
aBuilder->LineTo(r.BottomRight());
aBuilder->LineTo(r.BottomLeft());
aBuilder->Close();
} else {
// If either the 'rx' or the 'ry' attribute isn't set, then we have to
// set it to the value of the other:
@ -150,10 +148,10 @@ SVGRectElement::BuildPath(PathBuilder* aBuilder)
Size cornerRadii(rx, ry);
Size radii[] = { cornerRadii, cornerRadii, cornerRadii, cornerRadii };
AppendRoundedRectToPath(pathBuilder, Rect(x, y, width, height), radii);
AppendRoundedRectToPath(aBuilder, Rect(x, y, width, height), radii);
}
return pathBuilder->Finish();
return aBuilder->Finish();
}
} // namespace dom

View File

@ -66,26 +66,6 @@ nsSVGPathGeometryElement::GetPathForLengthOrPositionMeasuring()
return nullptr;
}
TemporaryRef<PathBuilder>
nsSVGPathGeometryElement::CreatePathBuilder()
{
RefPtr<DrawTarget> drawTarget =
gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
NS_ASSERTION(gfxPlatform::GetPlatform()->
SupportsAzureContentForDrawTarget(drawTarget),
"Should support Moz2D content drawing");
// The fill rule that we pass to CreatePathBuilder must be the current
// computed value of our CSS 'fill-rule' property if the path that we return
// will be used for painting or hit-testing. For all other uses (bounds
// calculatons, length measurement, position-at-offset calculations) the fill
// rule that we pass doesn't matter. As a result we can just pass the current
// computed value regardless of who's calling us, or what they're going to do
// with the path that we return.
return drawTarget->CreatePathBuilder(GetFillRule());
}
FillRule
nsSVGPathGeometryElement::GetFillRule()
{

View File

@ -63,12 +63,6 @@ public:
virtual mozilla::TemporaryRef<Path> GetPathForLengthOrPositionMeasuring();
/**
* Returns a PathBuilder object created using the current computed value of
* the CSS property 'fill-rule' for this element.
*/
mozilla::TemporaryRef<PathBuilder> CreatePathBuilder();
/**
* Returns the current computed value of the CSS property 'fill-rule' for
* this element.

View File

@ -129,12 +129,10 @@ nsSVGPolyElement::BuildPath(PathBuilder* aBuilder)
return nullptr;
}
RefPtr<PathBuilder> pathBuilder = aBuilder ? aBuilder : CreatePathBuilder();
pathBuilder->MoveTo(points[0]);
aBuilder->MoveTo(points[0]);
for (uint32_t i = 1; i < points.Length(); ++i) {
pathBuilder->LineTo(points[i]);
aBuilder->LineTo(points[i]);
}
return pathBuilder->Finish();
return aBuilder->Finish();
}

View File

@ -45,7 +45,7 @@ public:
virtual bool AttributeDefinesGeometry(const nsIAtom *aName) MOZ_OVERRIDE;
virtual bool IsMarkable() MOZ_OVERRIDE { return true; }
virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks) MOZ_OVERRIDE;
virtual mozilla::TemporaryRef<Path> BuildPath(PathBuilder* aBuilder = nullptr) MOZ_OVERRIDE;
virtual mozilla::TemporaryRef<Path> BuildPath(PathBuilder* aBuilder) MOZ_OVERRIDE;
// WebIDL
already_AddRefed<mozilla::DOMSVGPointList> Points();