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
using (var transform = EffectiveGradientTransform)
{
var bounds = renderer.GetBoundable().Bounds;
var bounds = renderer.GetBoundable().CalculateBounds();
transform.Translate(bounds.X, bounds.Y, MatrixOrder.Prepend);
if (this.GradientUnits == SvgCoordinateUnits.ObjectBoundingBox)
{
......
......@@ -114,10 +114,10 @@ namespace Svg
/// <summary>
/// Gets the bounds of the element.
/// </summary>
/// <value>The bounds.</value>
public override System.Drawing.RectangleF Bounds
/// <returns>The bounds.</returns>
public override RectangleF CalculateBounds()
{
get { return this.Path(null).GetBounds(); }
return this.Path(null).GetBounds();
}
/// <summary>
......
......@@ -18,7 +18,7 @@ namespace Svg
public void SetBoundable(ISvgBoundable boundable)
{
_boundables.Push(boundable);
_boundables.Push(new ImmutableBoundable(boundable));
}
public ISvgBoundable GetBoundable()
{
......
......@@ -109,6 +109,7 @@
<Compile Include="Document Structure\SvgSymbol.cs" />
<Compile Include="Filter Effects\ImageBuffer.cs" />
<Compile Include="Painting\GenericBoundable.cs" />
<Compile Include="Painting\ImmutableBoundable.cs" />
<Compile Include="Painting\SvgFallbackPaintServer .cs" />
<Compile Include="Paths\CoordinateParser.cs" />
<Compile Include="Rendering\IGraphicsProvider.cs" />
......
......@@ -1162,4 +1162,4 @@ namespace Svg
void Render(ISvgRenderer renderer);
}
}
\ No newline at end of file
}
......@@ -91,10 +91,10 @@ namespace Svg
/// <summary>
/// Gets the bounds of the element.
/// </summary>
/// <value>The bounds.</value>
public override System.Drawing.RectangleF Bounds
/// <returns>The bounds.</returns>
public override System.Drawing.RectangleF CalculateBounds()
{
get { return this.Path(null).GetBounds(); }
return this.Path(null).GetBounds();
}
/// <summary>
......
......@@ -227,18 +227,15 @@ namespace Svg
/// <summary>
/// Gets the bounds of the element.
/// </summary>
/// <value>The bounds.</value>
public override System.Drawing.RectangleF Bounds
/// <returns>The bounds.</returns>
public override RectangleF CalculateBounds()
{
get
var path = this.Path(null);
foreach (var elem in this.Children.OfType<SvgVisualElement>())
{
var path = this.Path(null);
foreach (var elem in this.Children.OfType<SvgVisualElement>())
{
path.AddPath(elem.Path(null), false);
}
return path.GetBounds();
path.AddPath(elem.Path(null), false);
}
return path.GetBounds();
}
/// <summary>
......@@ -495,19 +492,9 @@ namespace Svg
_width = width;
}
public PointF Location
{
get { return PointF.Empty; }
}
public SizeF Size
{
get { return new SizeF(_width, _font.Size); }
}
public RectangleF Bounds
public RectangleF CalculateBounds()
{
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