Saturday, August 1, 2009

New features in Silverlight 3: Browser Zoom Support & Hardware Acceleration

In this post, I’ll write about two new Silverlight features: Browser Zoom Support and Hardware Acceleration.

Browser Zoom Support

By default, Silverlight-based content resizes in response to changes in the browser zoom setting. You can disable this feature by setting Settings.EnableAutoZoom to false, or replace it by handling the Zoomed event. If you want to supplement the zooming feature instead of replacing it, handle the Zoomed event and set EnableAutoZoom to true. You can access the zoom setting for the current browser window through the ZoomFactor property.

zoom1zoom2

Hardware Acceleration

Caching visual elements as bitmaps allows you to take advantage of hardware acceleration.

ha

Hardware acceleration can benefit performance for the following scenarios:

  • Blending two static layers using opacity
  • Transforming objects (f.i stretching a VideoBrush, stretching and rotating objects)
  • Video

The GPU acceleration feature works only in managed code.

At the object level, you set cached composition information for graphics with the CacheMode property and BitmapCache values. But the GPU acceleration must be enabled at the Silverlight plug-in level, and by default the feature is disabled. Set EnableGPUAcceleration to true to enable GPU acceleration.

During profiling of application, you can set EnableCacheVisualization (Silverlight Plug-in Object) to true to produce an overlay visualization of the areas in your UI that are being hardware accelerated. Areas where optimisations are not being applied will be coloured (red) whereas areas where the optimisations are being applied will use their usual colours.

Caching objects can hurt performance if you misuse it. You only set CacheMode on objects that are either being transformed or having opacity changes applied because otherwise the object will not benefit from caching and performance could be worse than if you did not cache it.

EnableGPUAcceleration = false Without_GPU_CacheEnableGPUAcceleration = true, EnableCacheVisualization = true, CacheMode = null GPU_Without_CacheEnableGPUAcceleration = true, EnableCacheVisualization = true, CacheMode = BitmapCache With_GPU_and_Cache

No comments: