WPF PathGeometry/RotateTransform optimization

Posted by devinb on Stack Overflow See other posts from Stack Overflow or by devinb
Published on 2009-05-05T13:05:59Z Indexed on 2010/05/02 11:07 UTC
Read the original article Hit count: 183

Filed under:
|
|

I am having performance issues when rendering/rotating WPF triangles

If I had a WPF triangle being displayed and it will be rotated to some degree around a centrepoint, I can do it one of two ways:

  1. Programatically determine the points and their offset in the backend, use XAML to simply place them on the canvas where they belong, it would look like this:

    <Path Stroke="Black">
       <Path.Data>
          <PathGeometry>
             <PathFigure StartPoint ="{Binding CalculatedPointA, Mode=OneWay}">
                <LineSegment Point="{Binding CalculatedPointB, Mode=OneWay}" />
                <LineSegment Point="{Binding CalculatedPointC, Mode=OneWay}" />
                <LineSegment Point="{Binding CalculatedPointA, Mode=OneWay}" />
             </PathFigure>
          </PathGeometry>
       </Path.Data>
    </Path>
    
  2. Generate the 'same' triangle every time, and then use a RenderTransform (Rotate) to put it where it belongs. In this case, the rotation calculations are being obfuscated, because I don't have any access to how they are being done.

    <Path Stroke="Black">
       <Path.Data>
          <PathGeometry>
             <PathFigure StartPoint ="{Binding TriPointA, Mode=OneWay}">
                <LineSegment Point="{Binding TriPointB, Mode=OneWay}" />
                <LineSegment Point="{Binding TriPointC, Mode=OneWay}" />
                <LineSegment Point="{Binding TriPointA, Mode=OneWay}" />
             </PathFigure>
          </PathGeometry>
       </Path.Data>
       <Path.RenderTransform>
          <RotateTransform CenterX="{Binding Centre.X, Mode=OneWay}" 
                           CenterY="{Binding Centre.Y, Mode=OneWay}"
                           Angle="{Binding Orientation, Mode=OneWay}" />
       </Path.RenderTransform>
    </Path>
    

My question is which one is faster?

I know I should test it myself but how do I measure the render time of objects with such granularity. I would need to be able to time how long the actual rendering time is for the form, but since I'm not the one that's kicking off the redraw, I don't know how to capture the start time.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about optimization