Skip to content

Commit

Permalink
initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
David Scherba committed Mar 17, 2014
0 parents commit ffef890
Show file tree
Hide file tree
Showing 25 changed files with 937 additions and 0 deletions.
6 changes: 6 additions & 0 deletions App.config
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>
8 changes: 8 additions & 0 deletions App.xaml
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>
19 changes: 19 additions & 0 deletions App.xaml.cs
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_;
}
}
12 changes: 12 additions & 0 deletions MainWindow.xaml
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>
92 changes: 92 additions & 0 deletions MainWindow.xaml.cs
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;
}
}
}
}
9 changes: 9 additions & 0 deletions OverlayWindow.xaml
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>
62 changes: 62 additions & 0 deletions OverlayWindow.xaml.cs
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();
}
}
}
55 changes: 55 additions & 0 deletions Properties/AssemblyInfo.cs
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")]
63 changes: 63 additions & 0 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ffef890

Please sign in to comment.