tags:

views:

141

answers:

1

I use System.Windows.Media.RenderCapability.Tier to show the current render mode within a diagnostics panel of my app. If I force the app (3.5sp1) to change the render-mode through the following code

HwndSource hwndSource = PresentationSource.FromVisual(visual) as System.Windows.Interop.HwndSource;
HwndTarget hwndTarget = hwndSource.CompositionTarget;
hwndTarget.RenderMode = renderMode;

neither System.Windows.Media.RenderCapability.TierChanged fires, nor has the System.Windows.Media.RenderCapability.Tier property changed. However the changes are applied to the app. If I look with Perforator, the render mode has been changed to the desired mode.

Although I’ve found at many locations that System.Windows.Media.RenderCapability.Tier can be used to detect the current render state (also msdn, see this), it seems, System.Windows.Media.RenderCapability only gives information about the capabilities and not about the current mode. That makes also sense if I look at the name of the class.

Is there another source to know how an actual wpf-content is rendered or am I doing something wrong?

+2  A: 

Just combine RenderCapability.Tier and HwndTarget.RenderMode together and you'll get what you're looking for:

  • RenderCapability.Tier tells you what the current graphic card supports
  • HwndTarget.RenderMode tells you whether WPF will actually use the GPU or not

RenderCapability.Tier changes and fires TierChanged any time the Direct3D surface switches to a new video card (such as a window being dragged between monitors or switching the display to a new monitor).

HwndTarget.RenderMode is only changed by user code but has no notification mechanism for when it changes. If you only set it in one place you can simply notify from there, otherwise you might need to use a timer to check it periodically.

Basically if HwndTarget.RenderMode==RenderMode.Default and RenderCapability.Tier is high enough you have hardware acceleration.

Ray Burns