Bug 876157 - Avoid expensive nsSVGGradientFrame::GetGradientTransform calls when gradients paint only a single color. r=roc

This commit is contained in:
Jonathan Watt 2013-05-27 08:31:39 +01:00
Родитель 7ab546eefe
Коммит fc4e140ee3
1 изменённых файлов: 22 добавлений и 17 удалений

Просмотреть файл

@ -174,18 +174,9 @@ nsSVGGradientFrame::GetGradientTransform(nsIFrame *aSource,
gfxMatrix bboxMatrix;
uint16_t gradientUnits = GetGradientUnits();
if (gradientUnits == SVG_UNIT_TYPE_USERSPACEONUSE) {
// If this gradient is applied to text, our caller
// will be the glyph, which is not a container, so we
// need to get the parent
if (aSource->GetContent()->IsNodeOfType(nsINode::eTEXT))
mSource = aSource->GetParent();
else
mSource = aSource;
} else {
NS_ASSERTION(
gradientUnits == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX,
"Unknown gradientUnits type");
if (gradientUnits != SVG_UNIT_TYPE_USERSPACEONUSE) {
NS_ASSERTION(gradientUnits == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX,
"Unknown gradientUnits type");
// objectBoundingBox is the default anyway
gfxRect bbox =
@ -242,11 +233,16 @@ nsSVGGradientFrame::GetPaintServerPattern(nsIFrame *aSource,
float aGraphicOpacity,
const gfxRect *aOverrideBounds)
{
// Get the transform list (if there is one)
gfxMatrix patternMatrix = GetGradientTransform(aSource, aOverrideBounds);
if (patternMatrix.IsSingular())
return nullptr;
uint16_t gradientUnits = GetGradientUnits();
MOZ_ASSERT(gradientUnits == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX ||
gradientUnits == SVG_UNIT_TYPE_USERSPACEONUSE);
if (gradientUnits == SVG_UNIT_TYPE_USERSPACEONUSE) {
// Set mSource for this consumer.
// If this gradient is applied to text, our caller will be the glyph, which
// is not an element, so we need to get the parent
mSource = aSource->GetContent()->IsNodeOfType(nsINode::eTEXT) ?
aSource->GetParent() : aSource;
}
uint32_t nStops = GetStopCount();
@ -272,6 +268,15 @@ nsSVGGradientFrame::GetPaintServerPattern(nsIFrame *aSource,
return pattern.forget();
}
// Get the transform list (if there is one). We do this after the returns
// above since this call can be expensive when "gradientUnits" is set to
// "objectBoundingBox" (since that requiring a GetBBox() call).
gfxMatrix patternMatrix = GetGradientTransform(aSource, aOverrideBounds);
if (patternMatrix.IsSingular()) {
return nullptr;
}
// revert the vector effect transform so that the gradient appears unchanged
if (aFillOrStroke == &nsStyleSVG::mStroke) {
patternMatrix.Multiply(nsSVGUtils::GetStrokeTransform(aSource).Invert());