I have a question about bitmap caching in windows phone 7 silverlight applications.
When shall i use it? And on what controlls? Should i bitmap cache children of a controll thats bitmap cached? I'm not sure how its works and it would be nice to get some advice from you guys.
/Richard
I found this link explaining CacheMode
in Silverlight 3. From the link:
[This link is dead.]
- BitmapCache is the only cache-mode that is supported.
- The Caching is applied to the element and all of it’s child elements.
- BitmapCaching should be used in scenarios where you are blending, transforming (translating, stretching, rotating).
- Misuse of the CacheMode feature can hurt performance, so you need to really think through what you are doing. If your visual tree is interleaving cached and un-cached elements, you are effectively causing multiple rendering surfaces to get created behind the scenes. The un-cached surfaces are rendered in software and the cached surfaces are rendered in hardware. Your performance will be best if you can minimize the total number of rendering surfaces and get the hardware to do work where it can.
- You can determine which elements are being cached by adding the EnableCacheVisualization parameter to your Silverlight plugin declaration.
<param name="EnableCacheVisualization" value="true" />
- As far as I can tell, GPU acceleration does not occur on Macs when the Silverlight application is not in full-screen mode. This is apparently a limitation of the Safari plug-in model.
I wonder if the EnableCacheVisualization
can be enabled for WP7, I'm using BitmapCache
for a LongListPicker
and a ContentPresenter
(that I populate with dynamically created content) and it'd be interesting to know if the caching is working. But according to the 3rd bullet, you should be using it only if you're animating UIElement
s, which I'm not, so maybe I shouldn't be using it at all!
BitmapCache should, for the large majority of objects, be something you don't need to think about on Windows Phone 7. Silverlight for WP7 implements automatic bitmap caching of elements that are animating in ways that caching helps (translate, opacity, rotate - maybe more, I can't recall now).
Silverlight on a desktop PC (or Mac) isn't quite as smart currently, so you need to manually specify CacheMode=BitmapCache on objects using roughly the guidance pointed to by Praetorian in his answer.
There are probably edge cases where setting BitmapCache explicitly is useful even on Windows Phone, but I don't know about them offhand. You could try looking at the Windows Phone Performance Tips on MSDN.
From what i've seen/read, you want to use bitmap caching on objects that might be expensive to render (like lots of children or complicated layout) if you are going to use them in transitions or animations.
With bitmap caching, the hardware can do the transitions+animations faster/smoother.
I think you just need to put it on the top most item/parent item where you apply the transform or animation? Someone will be along shortly to correct me, i'm sure :)