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)