views:

416

answers:

2

Steps to reproduce:

  1. Create a new solution/add new WPF Application project.
  2. place just a canvas in the main window.
  3. create a RotateTransform + PageUp/Down events for incrementing the angle with +-10.
  4. place 50 polygons on the canvas
  5. Press PageUp/Down (and keep pressed)

On my PC the CPU usage is 80%.

  1. Now try placing 1000 polygons and press PageUp/Down - CPU can reach 100% at 1-2 frames/s.

I checked RenderCapability.Tier and it's 2 - meaning that it should render everything by hardware.

But it's not working, why?

+1  A: 

WPF will still be doing the calculations for where things need to be drawn on the screen. You have not specified if this is a layout or render transform as this makes a performance difference. You need to be carefull how you use your transform as msdn points out

LayoutTransform can lead to poor application performance if you invoke it in a scenario that does not require a full pass by the layout system. When you apply a LayoutTransform to the Children collection of the Panel, it triggers a new pass by the layout system and forces all on-screen objects to be remeasured and rearranged. If you are updating the complete application user interface (UI), this functionality might be exactly what you need. However, if you do not need a full layout pass, use the RenderTransform property, which does not invoke the layout system, and therefore, is typically a better choice for this scenario.

pjbelf
I admit I'm a bit confused.This is what I did:RotateTransform rotation = new RotateTransform();TransformGroup tg = new TransformGroup();polygon.RenderTransform = tg;canvas.Children.Add(polygon);I guess that the answer for you is RenderTransform.
(sry, i forgot tg.Children.Add(rotation);)
Thanks for answering!
+1  A: 

A bit more info would be useful such as the types of polygon your using, your graphics card and what version of WPF you're using.

I tried your example and didn't have any problem with 500 simple polygons. (Core 2 Duo, 8800 GTS). Your example and other times when you have fairly complex content that doesn't change very often but you are transforming it can greatly benefit from a BitmapCache.

<Canvas.CacheMode>
    <BitmapCache />
</Canvas.CacheMode>

With a BitmapCache you should be able to transform as many elements as you would want, although you will still have a performance hit whenever they need to be re-rendered. If you're using complex paths you could also try freezing them.

Kris