WPF Rendering 3 (hardware acceleration and Software Acceleration): Performance profiling-Configurator

Source: Internet
Author: User

Day 3 (11/17/2010)

Step 3: Practice
1. find an Animation demo (requires a bit of attention, rich pixels, and faster Animation speed to improve the difficulty of the Screen Display), and add a timer in it, modify the RenderOptions of the current process at intervals. processRenderMode, the Code is as follows:

          
Timer timer = new Timer ();
Timer. Interval = 500; // change once in half a second
Timer. Enabled = true;
Timer. Elapsed + = new ElapsedEventHandler (changeRenderMode );
Timer. Start ();
// Execute the animation

// Function for changing the rendering Mode
Void changeRenderMode (object sender, ElapsedEventArgs e)
{
If (RenderOptions. ProcessRenderMode = RenderMode. Default)
{
RenderOptions. ProcessRenderMode = RenderMode. SoftwareOnly;
}
Else
{
RenderOptions. ProcessRenderMode = RenderMode. Default;
}
}

 

2. Run the above function and run the tool in the windows sdk: Performance profiling-configurator. Add the above process to the monitoring content and you can see the following effects:

 

From this we can see that software rendering and hardware rendering Alternate

3. From the experiment, when the program is running, modifying the registry value (see the previous two articles) does not affect the software and hardware presentation of the program. Maybe you need to restart the program or restart the machine or something? Verify it later!

 

Correction:

In the above experiment, I thought that modifying the registry value had no impact on rendering. Later I found this idea wrong. The reason why modifying the registry does not change the rendering mode at runtime (instead of changing the rendering mode as immediately as modifying RenderingOption) is that the application only reads the registry value once before the window appears, in other words, we can change the registry value before the window appears to affect the rendering mode, and then there is no chance to change the registry before the program restarts. For example, you can add the following code to App. cs:

  protected override void OnStartup(StartupEventArgs e)
{
//Enable hardware accelration
EnableHWAcceleration();
base.OnStartup(e);
}

//Change the RegistryKey value to enable hardware accelration
public void EnableHWAcceleration()
{
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Avalon.Graphics\", true);
if (registryKey != null && registryKey.GetValue("DisableHWAcceleration").ToString() == "1")
{
registryKey.SetValue("DisableHWAcceleration", 0);
}
}

This ensures that hardware acceleration is enabled on the computer,

If the statement is:

RegistryKey. SetValue ("DisableHWAcceleration", 1 );
In this way, hardware acceleration is disabled. In this case, even if:

RenderOptions. ProcessRenderMode = RenderMode. Default;

In this way, hardware acceleration cannot be enabled (refer to the previous article about priority)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.