Silverlight 3 Quick Tip #4: Hardware Acceleration

March 29, 2009

Silverlight 3 Beta 1 bring us new and highly expected future – hardware acceleration. This short article will answer simple questions is how it could be enabled/used, where it is supported and when should be used.


Well, the first answer is relatively simple. To enable hardware acceleration one need to do following:


In plugin settings enable GPU Acceleration:

<param name=”EnableGPUAcceleration” value=”true” />
Next, set the “CacheMode” property of desired element to to “BitmapCache”:
<Canvas.CacheMode>
<
BitmapCache/>
</
Canvas.CacheMode>

or

<StackPanel CacheMode=”BitmapCache”/>

Now desired elements will be cached and will use hardware acceleration.


Now the support issue. The hardware acceleration is supported as following:



  • Windows: Browser & Fullscreen (on machines with DirectX 9.0c)

  • Mac: Fullscreen only

The last question left is when this feature should be used? The most impulsive answer I heard here is “everywhere”. But in real word the picture is slightly different.


Only 3 properties could be hardware accelerated (at least in current Beta stage): Transforms, Rectangular Clipping and Blending. This means, that if your application doesn’t use those properties you will not benefit from this feature. If so, why not set the CacheMode on topmost element? The answer is simple – this will introduce more overhead to the rendering system which will try to calculate what should be cached and what not. Also, rendering mechanism uses unmanaged intermediate surfaces while rendering hardware accelerated elements and they could be pretty expensive especially if not really used. The best practice from here is to set it only on the specific “leaf-most” element which will be hardware accelerated. Another point here – use it only if there is real user-detectable impact.


Source for simple application which uses this feature is here.


Enjoy,


Alex

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

2 comments

  1. JoannahApril 4, 2009 ב 14:54

    I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

    Joannah

    http://linuxmemory.net

    Reply
  2. Ink cartridgesJuly 29, 2009 ב 15:06

    Thanks for the info mate..look forward for your updates…

    Reply