Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one disable hardware acceleration in wpf?

What is the procedure for disabling hardware acceleration in WPF? What is it exactly? Is it a Windows setting, a Visual Studio setting, or something you alter in the code of your WPF project? Will it affect only the program you're running or will it be system-wide?

like image 814
Stefan Avatar asked Jan 30 '10 21:01

Stefan


People also ask

Does WPF use hardware acceleration?

A rendering tier value of 1 or 2 means that most of the graphics features of WPF will use hardware acceleration if the necessary system resources are available and have not been exhausted. This corresponds to a DirectX version that is greater than or equal to 9.0.

How do I disable my hardware acceleration?

In the Settings menu, expand the “Advanced” drop-down section found in the left sidebar and then select “System.” Find the “Use hardware acceleration when available” setting. Toggle the switch to the “Off” position and then click “Relaunch” to apply the changes. Warning: Make sure you save anything you're working on.

Should I enable or disable hardware acceleration?

Unless you're facing an issue that you know is because of hardware acceleration, you shouldn't turn off hardware acceleration. It'll generally do more good than harm, but when you see it is causing you more harm instead, that's when you should turn it off for that one specific app.


2 Answers

You can disable it on a Window level starting from .Net 3.5 SP1.

public partial class MyWindow : Window
{
    public MyWindow()
        : base()
    {
        InitializeComponent();
    }

    protected override void OnSourceInitialized(EventArgs e)
    {
        var hwndSource = PresentationSource.FromVisual(this) as HwndSource;

        if (hwndSource != null)
            hwndSource.CompositionTarget.RenderMode = RenderMode.SoftwareOnly;

        base.OnSourceInitialized(e);
    }
}

or you can subscribe to SourceInitialized event of the window and do the same.

Alternatively you can set it on Process level:

RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;

The precedence order for software rendering is:

  1. DisableHWAcceleration registry key
  2. ProcessRenderMode
  3. RenderMode (per-target)
like image 119
Konstantin Spirin Avatar answered Oct 19 '22 03:10

Konstantin Spirin


It is a machine-wide registry setting. See Graphics Rendering Registry Settings in the WPF docs for the registry key and other details relating to customizing WPF rendering.

The key listed is: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Avalon.Graphics\DisableHWAcceleration

The MSDN document is "not available" for .NET 4.5, so this may be a depricated option that only works in 4.0 or below.

like image 40
itowlson Avatar answered Oct 19 '22 03:10

itowlson