Commit 1b8cb43f authored by Dan Backes's avatar Dan Backes Committed by James Welle
Browse files

Performance Improvement

- Because querying the Bounds property of an ISvgBoundable or
  SvgVisualElement is expensive, we introduced an ImmutableBoundable that
  is used by the SvgRenderer. This class stores the bounds of the supplied
  ISvgBoundable so that multiple queries for the bounds do not hamper
  performance when rendering.

- Converted the Bounds property on ISvgBoundable and SvgVisualElement to a
  CalculateBounds method to indicate that it is an expensive operation
  that returns a new value each time it is called.

- Removed redundant ISvgBoundable Location and Size properties.

- Fixed a bug in SvgFragment.Path property by converting it to a method that
  indicates it returns a new GraphicsPath instance when called and by
  disposing of that instance in CalculateBounds. There are many more
  instances of GraphicsPath not being disposed in the code base but we did
  not address that here.
parent a653b4a4
...@@ -127,7 +127,7 @@ namespace Svg ...@@ -127,7 +127,7 @@ namespace Svg
using (var transform = EffectiveGradientTransform) using (var transform = EffectiveGradientTransform)
{ {
var bounds = renderer.GetBoundable().Bounds; var bounds = renderer.GetBoundable().CalculateBounds();
transform.Translate(bounds.X, bounds.Y, MatrixOrder.Prepend); transform.Translate(bounds.X, bounds.Y, MatrixOrder.Prepend);
if (this.GradientUnits == SvgCoordinateUnits.ObjectBoundingBox) if (this.GradientUnits == SvgCoordinateUnits.ObjectBoundingBox)
{ {
......
...@@ -114,10 +114,10 @@ namespace Svg ...@@ -114,10 +114,10 @@ namespace Svg
/// <summary> /// <summary>
/// Gets the bounds of the element. /// Gets the bounds of the element.
/// </summary> /// </summary>
/// <value>The bounds.</value> /// <returns>The bounds.</returns>
public override System.Drawing.RectangleF Bounds public override RectangleF CalculateBounds()
{ {
get { return this.Path(null).GetBounds(); } return this.Path(null).GetBounds();
} }
/// <summary> /// <summary>
......
...@@ -18,7 +18,7 @@ namespace Svg ...@@ -18,7 +18,7 @@ namespace Svg
public void SetBoundable(ISvgBoundable boundable) public void SetBoundable(ISvgBoundable boundable)
{ {
_boundables.Push(boundable); _boundables.Push(new ImmutableBoundable(boundable));
} }
public ISvgBoundable GetBoundable() public ISvgBoundable GetBoundable()
{ {
......
...@@ -109,6 +109,7 @@ ...@@ -109,6 +109,7 @@
<Compile Include="Document Structure\SvgSymbol.cs" /> <Compile Include="Document Structure\SvgSymbol.cs" />
<Compile Include="Filter Effects\ImageBuffer.cs" /> <Compile Include="Filter Effects\ImageBuffer.cs" />
<Compile Include="Painting\GenericBoundable.cs" /> <Compile Include="Painting\GenericBoundable.cs" />
<Compile Include="Painting\ImmutableBoundable.cs" />
<Compile Include="Painting\SvgFallbackPaintServer .cs" /> <Compile Include="Painting\SvgFallbackPaintServer .cs" />
<Compile Include="Paths\CoordinateParser.cs" /> <Compile Include="Paths\CoordinateParser.cs" />
<Compile Include="Rendering\IGraphicsProvider.cs" /> <Compile Include="Rendering\IGraphicsProvider.cs" />
......
...@@ -1162,4 +1162,4 @@ namespace Svg ...@@ -1162,4 +1162,4 @@ namespace Svg
void Render(ISvgRenderer renderer); void Render(ISvgRenderer renderer);
} }
} }
\ No newline at end of file
...@@ -91,10 +91,10 @@ namespace Svg ...@@ -91,10 +91,10 @@ namespace Svg
/// <summary> /// <summary>
/// Gets the bounds of the element. /// Gets the bounds of the element.
/// </summary> /// </summary>
/// <value>The bounds.</value> /// <returns>The bounds.</returns>
public override System.Drawing.RectangleF Bounds public override System.Drawing.RectangleF CalculateBounds()
{ {
get { return this.Path(null).GetBounds(); } return this.Path(null).GetBounds();
} }
/// <summary> /// <summary>
......
...@@ -227,18 +227,15 @@ namespace Svg ...@@ -227,18 +227,15 @@ namespace Svg
/// <summary> /// <summary>
/// Gets the bounds of the element. /// Gets the bounds of the element.
/// </summary> /// </summary>
/// <value>The bounds.</value> /// <returns>The bounds.</returns>
public override System.Drawing.RectangleF Bounds public override RectangleF CalculateBounds()
{ {
get var path = this.Path(null);
foreach (var elem in this.Children.OfType<SvgVisualElement>())
{ {
var path = this.Path(null); path.AddPath(elem.Path(null), false);
foreach (var elem in this.Children.OfType<SvgVisualElement>())
{
path.AddPath(elem.Path(null), false);
}
return path.GetBounds();
} }
return path.GetBounds();
} }
/// <summary> /// <summary>
...@@ -495,19 +492,9 @@ namespace Svg ...@@ -495,19 +492,9 @@ namespace Svg
_width = width; _width = width;
} }
public PointF Location public RectangleF CalculateBounds()
{
get { return PointF.Empty; }
}
public SizeF Size
{
get { return new SizeF(_width, _font.Size); }
}
public RectangleF Bounds
{ {
get { return new RectangleF(this.Location, this.Size); } return new RectangleF(PointF.Empty, new SizeF(_width, _font.Size));
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment