-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Scherba
committed
Mar 17, 2014
0 parents
commit ffef890
Showing
25 changed files
with
937 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Application x:Class="WpfRenderPerformance.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
|
||
namespace WpfRenderPerformance | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
/// | ||
public partial class App : Application | ||
{ | ||
public OverlayWindow ow_; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Window x:Class="WpfRenderPerformance.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
Title="WPF Render Performance Control Panel" Height="147.649" Width="525" Loaded="OnLoaded" Closed="Window_Closed" Topmost="True"> | ||
<Grid> | ||
<CheckBox Name="TransparentChk" Content="Transparent" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" IsChecked="True" Click="CheckBox_Checked" Checked="CheckBox_Checked"/> | ||
<Slider Name="WindowSizeSlider" HorizontalAlignment="Left" Margin="105,80,0,0" VerticalAlignment="Top" Width="391" ValueChanged="WindowSizeSlider_ValueChanged" Value="10.0"/> | ||
<Label Content="Window Size" HorizontalAlignment="Left" Margin="10,76,0,0" VerticalAlignment="Top" Width="78"/> | ||
<CheckBox Name="RenderChk" Content="Update overlay (30fps)" HorizontalAlignment="Left" Margin="10,29,0,0" VerticalAlignment="Top" IsChecked="True"/> | ||
<CheckBox Name="SoftwareRenderChk" Content="Force Software Render" HorizontalAlignment="Left" Margin="10,49,0,0" VerticalAlignment="Top" Checked="SoftwareRenderChk_Checked" Unchecked="SoftwareRenderChk_Checked"/> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Interop; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
|
||
namespace WpfRenderPerformance | ||
{ | ||
/// <summary> | ||
/// Interaction logic for MainWindow.xaml | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
{ | ||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void OnLoaded(object sender, RoutedEventArgs e) | ||
{ | ||
App app = App.Current as App; | ||
|
||
if (app.ow_ == null) { | ||
app.ow_ = new OverlayWindow(); | ||
app.ow_.Width = (app.MainWindow as MainWindow).WindowSizeSlider.Value / 10.0 * System.Windows.SystemParameters.PrimaryScreenWidth; | ||
app.ow_.Height = app.ow_.Width * 480.0 / 640.0; | ||
app.ow_.Show(); | ||
} | ||
} | ||
|
||
private void CheckBox_Checked(object sender, RoutedEventArgs e) | ||
{ | ||
App app = App.Current as App; | ||
|
||
if (app.ow_ == null) return; | ||
|
||
app.ow_.Close(); | ||
|
||
app.ow_ = new OverlayWindow(); | ||
app.ow_.Width = (app.MainWindow as MainWindow).WindowSizeSlider.Value / 10.0 * System.Windows.SystemParameters.PrimaryScreenWidth; | ||
app.ow_.Height = app.ow_.Width * 480.0 / 640.0; | ||
|
||
if (TransparentChk.IsChecked.GetValueOrDefault(false)) { | ||
app.ow_.AllowsTransparency = true; | ||
} | ||
else { | ||
app.ow_.AllowsTransparency = false; | ||
} | ||
|
||
app.ow_.Show(); | ||
} | ||
|
||
private void Window_Closed(object sender, EventArgs e) | ||
{ | ||
App app = App.Current as App; | ||
app.ow_.Close(); | ||
} | ||
|
||
private void WindowSizeSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) | ||
{ | ||
App app = App.Current as App; | ||
if (app.ow_ != null) | ||
{ | ||
app.ow_.Width = e.NewValue / 10.0 * System.Windows.SystemParameters.PrimaryScreenWidth; | ||
app.ow_.Height = app.ow_.Width * 480.0 / 640.0; | ||
} | ||
} | ||
|
||
private void SoftwareRenderChk_Checked(object sender, RoutedEventArgs e) | ||
{ | ||
App app = App.Current as App; | ||
HwndSource hwndSource = PresentationSource.FromVisual(app.ow_) as HwndSource; | ||
HwndTarget hwndTarget = hwndSource.CompositionTarget; | ||
if (SoftwareRenderChk.IsChecked.GetValueOrDefault(false)) { | ||
hwndTarget.RenderMode = RenderMode.SoftwareOnly; | ||
} else { | ||
hwndTarget.RenderMode = RenderMode.Default; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
<Window x:Class="WpfRenderPerformance.OverlayWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
Title="OverlayWindow" Background="Transparent" AllowsTransparency="True" WindowStyle="None" Height="350" Width="525" Loaded="OnLoaded" Closed="Window_Closed" Left="20" Top="20"> | ||
<Grid> | ||
<Image Name="foo"/> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Interop; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Shapes; | ||
|
||
namespace WpfRenderPerformance | ||
{ | ||
/// <summary> | ||
/// Interaction logic for OverlayWindow.xaml | ||
/// </summary> | ||
public partial class OverlayWindow : Window | ||
{ | ||
public OverlayWindow() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
WriteableBitmap wb_source_out_; | ||
public void OnNewWriteableImage(Byte[] pixel) | ||
{ | ||
App app = App.Current as App; | ||
|
||
Dispatcher.BeginInvoke(new Action(delegate() { | ||
if (app.MainWindow != null && (app.MainWindow as MainWindow).RenderChk.IsChecked.GetValueOrDefault(false)) { | ||
if (wb_source_out_ == null) { | ||
wb_source_out_ = new WriteableBitmap(640, 480, 96, 96, PixelFormats.Bgra32, null); | ||
foo.Source = wb_source_out_; | ||
} | ||
else if (foo.Source != wb_source_out_) foo.Source = wb_source_out_; | ||
|
||
(wb_source_out_ as WriteableBitmap).WritePixels(new System.Windows.Int32Rect(0, 0, 640, 480), pixel, 640 * 4, 0); | ||
} | ||
})); | ||
} | ||
|
||
private Thread worker_thread_; | ||
public WpfRenderHelper.WpfRenderHelper helper_; | ||
private void OnLoaded(object sender, RoutedEventArgs e) | ||
{ | ||
helper_ = new WpfRenderHelper.WpfRenderHelper(); | ||
helper_.NewWriteableImage += OnNewWriteableImage; | ||
worker_thread_ = new Thread(new ThreadStart(helper_.Worker)); | ||
worker_thread_.Start(); | ||
} | ||
|
||
private void Window_Closed(object sender, EventArgs e) | ||
{ | ||
worker_thread_.Abort(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.Reflection; | ||
using System.Resources; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using System.Windows; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("WpfRenderPerformance")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("WpfRenderPerformance")] | ||
[assembly: AssemblyCopyright("Copyright © 2014")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
//In order to begin building localizable applications, set | ||
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file | ||
//inside a <PropertyGroup>. For example, if you are using US english | ||
//in your source files, set the <UICulture> to en-US. Then uncomment | ||
//the NeutralResourceLanguage attribute below. Update the "en-US" in | ||
//the line below to match the UICulture setting in the project file. | ||
|
||
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] | ||
|
||
|
||
[assembly: ThemeInfo( | ||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||
//(used if a resource is not found in the page, | ||
// or application resource dictionaries) | ||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||
//(used if a resource is not found in the page, | ||
// app, or any theme specific resource dictionaries) | ||
)] | ||
|
||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.