Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Wpf support (control and sample) #12

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions MarcusW.VncClient.sln
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32014.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2CB2F0BD-AABA-4047-AAEE-E3AA512EFE47}"
ProjectSection(SolutionItems) = preProject
src\Directory.Build.props = src\Directory.Build.props
EndProjectSection
ProjectSection(SolutionItems) = preProject
src\Directory.Build.props = src\Directory.Build.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MarcusW.VncClient", "src\MarcusW.VncClient\MarcusW.VncClient.csproj", "{90137400-5377-4EB1-AD8A-E200F9006B7D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MarcusW.VncClient", "src\MarcusW.VncClient\MarcusW.VncClient.csproj", "{90137400-5377-4EB1-AD8A-E200F9006B7D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{1FC9632E-AA75-4DDB-8CAD-332CA3EFA62D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MarcusW.VncClient.Tests", "tests\MarcusW.VncClient.Tests\MarcusW.VncClient.Tests.csproj", "{17267552-3363-4060-A52B-C5F1ACA558AB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MarcusW.VncClient.Tests", "tests\MarcusW.VncClient.Tests\MarcusW.VncClient.Tests.csproj", "{17267552-3363-4060-A52B-C5F1ACA558AB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{7E5D1011-F3AB-4B7E-A015-58B5A910EBA8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{F24C1D8F-7ADE-4900-BB9B-817D0AD10C50}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{678728BC-1F28-4C65-894B-545C62739E73}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MarcusW.VncClient.Avalonia", "src\MarcusW.VncClient.Avalonia\MarcusW.VncClient.Avalonia.csproj", "{7CE9299C-5017-47E4-919F-9DE04E8D9751}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MarcusW.VncClient.Avalonia", "src\MarcusW.VncClient.Avalonia\MarcusW.VncClient.Avalonia.csproj", "{7CE9299C-5017-47E4-919F-9DE04E8D9751}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaVncClient", "samples\AvaloniaVncClient\AvaloniaVncClient.csproj", "{DEF2D06D-D010-41B8-9011-693F6969AA1D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AvaloniaVncClient", "samples\AvaloniaVncClient\AvaloniaVncClient.csproj", "{DEF2D06D-D010-41B8-9011-693F6969AA1D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmarks", "benchmarks\Benchmarks\Benchmarks.csproj", "{73A59C77-A920-476C-B4E2-07437E2C971D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "benchmarks\Benchmarks\Benchmarks.csproj", "{73A59C77-A920-476C-B4E2-07437E2C971D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MarcusW.VncClient.Wpf", "src\MarcusW.VncClient.Wpf\MarcusW.VncClient.Wpf.csproj", "{A454F5D1-713D-49B1-B9A3-7B490A635826}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfVncClient", "samples\WpfVncClient\WpfVncClient.csproj", "{23277D61-F815-4339-AE74-03BE39E36D2B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MarcusW.VncClient.Skia", "src\MarcusW.VncClient.Skia\MarcusW.VncClient.Skia.csproj", "{A02D99B0-3C63-49C4-A4B7-147FDCD08102}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -49,12 +58,33 @@ Global
{73A59C77-A920-476C-B4E2-07437E2C971D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{73A59C77-A920-476C-B4E2-07437E2C971D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{73A59C77-A920-476C-B4E2-07437E2C971D}.Release|Any CPU.Build.0 = Release|Any CPU
{A454F5D1-713D-49B1-B9A3-7B490A635826}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A454F5D1-713D-49B1-B9A3-7B490A635826}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A454F5D1-713D-49B1-B9A3-7B490A635826}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A454F5D1-713D-49B1-B9A3-7B490A635826}.Release|Any CPU.Build.0 = Release|Any CPU
{23277D61-F815-4339-AE74-03BE39E36D2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23277D61-F815-4339-AE74-03BE39E36D2B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23277D61-F815-4339-AE74-03BE39E36D2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23277D61-F815-4339-AE74-03BE39E36D2B}.Release|Any CPU.Build.0 = Release|Any CPU
{A02D99B0-3C63-49C4-A4B7-147FDCD08102}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A02D99B0-3C63-49C4-A4B7-147FDCD08102}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A02D99B0-3C63-49C4-A4B7-147FDCD08102}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A02D99B0-3C63-49C4-A4B7-147FDCD08102}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{90137400-5377-4EB1-AD8A-E200F9006B7D} = {2CB2F0BD-AABA-4047-AAEE-E3AA512EFE47}
{17267552-3363-4060-A52B-C5F1ACA558AB} = {1FC9632E-AA75-4DDB-8CAD-332CA3EFA62D}
{7CE9299C-5017-47E4-919F-9DE04E8D9751} = {2CB2F0BD-AABA-4047-AAEE-E3AA512EFE47}
{DEF2D06D-D010-41B8-9011-693F6969AA1D} = {F24C1D8F-7ADE-4900-BB9B-817D0AD10C50}
{73A59C77-A920-476C-B4E2-07437E2C971D} = {678728BC-1F28-4C65-894B-545C62739E73}
{A454F5D1-713D-49B1-B9A3-7B490A635826} = {2CB2F0BD-AABA-4047-AAEE-E3AA512EFE47}
{23277D61-F815-4339-AE74-03BE39E36D2B} = {F24C1D8F-7ADE-4900-BB9B-817D0AD10C50}
{A02D99B0-3C63-49C4-A4B7-147FDCD08102} = {2CB2F0BD-AABA-4047-AAEE-E3AA512EFE47}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9F1B3E40-9675-426B-AC5A-B5636F738D28}
EndGlobalSection
EndGlobal
7 changes: 7 additions & 0 deletions MarcusW.VncClient.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=WpfVncClient_002EAnnotations/@EntryIndexedValue">True</s:Boolean>




</wpf:ResourceDictionary>
22 changes: 10 additions & 12 deletions benchmarks/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
</ItemGroup>

</Project>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
</ItemGroup>
</Project>
143 changes: 71 additions & 72 deletions benchmarks/Benchmarks/BufferWriting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,95 +2,94 @@
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;

namespace Benchmarks
namespace Benchmarks;

public class BufferWriting
{
public class BufferWriting
private readonly byte[] _buffer = new byte[1920 * 1080 * 4];

[Benchmark]
public void ArrayIndexer()
{
private readonly byte[] _buffer = new byte[1920 * 1080 * 4];
for (var i = 0; i < _buffer.Length; i += 4)
SetPixelArrayIndexer(_buffer, i, 0xffffffff);
}

[Benchmark]
public void ArrayIndexer()
[Benchmark]
public unsafe void Pointer()
{
fixed (byte* ptr = &_buffer[0])
{
for (int i = 0; i < _buffer.Length; i += 4)
SetPixelArrayIndexer(_buffer, i, 0xffffffff);
for (var i = 0; i < _buffer.Length; i += 4)
SetPixelPointer(ptr + i, 0xffffffff);
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetPixelArrayIndexer(byte[] buffer, int i, uint color)
[Benchmark]
public unsafe void PointerMemcpy()
{
fixed (byte* ptr = &_buffer[0])
{
buffer[i] = (byte)(color & 0xff);
buffer[i + 1] = (byte)((color >> 8) & 0xff);
buffer[i + 2] = (byte)((color >> 16) & 0xff);
buffer[i + 3] = (byte)((color >> 24) & 0xff);
for (var i = 0; i < _buffer.Length; i += 4)
SetPixelPointerMemcpy(ptr + i, 0xffffffff);
}
}

[Benchmark]
public void Span()
[Benchmark]
public unsafe void PointerReinterpretCast()
{
fixed (byte* ptr = &_buffer[0])
{
Span<byte> buffer = _buffer;

for (int i = 0; i < _buffer.Length; i += 4)
SetPixelSpan(buffer.Slice(i, 4), 0xffffffff);
for (var i = 0; i < _buffer.Length; i += 4)
SetPixelPointerReinterpretCast(ptr + i, 0xffffffff);
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetPixelSpan(in Span<byte> span, uint color)
{
span[0] = (byte)(color & 0xff);
span[1] = (byte)((color >> 8) & 0xff);
span[2] = (byte)((color >> 16) & 0xff);
span[3] = (byte)((color >> 24) & 0xff);
}
[Benchmark]
public void Span()
{
Span<byte> buffer = _buffer;

[Benchmark]
public unsafe void Pointer()
{
fixed (byte* ptr = &_buffer[0])
{
for (int i = 0; i < _buffer.Length; i += 4)
SetPixelPointer(ptr + i, 0xffffffff);
}
}
for (var i = 0; i < _buffer.Length; i += 4)
SetPixelSpan(buffer.Slice(i, 4), 0xffffffff);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private unsafe void SetPixelPointer(byte* ptr, uint color)
{
*ptr++ = (byte)(color & 0xff);
*ptr++ = (byte)((color >> 8) & 0xff);
*ptr++ = (byte)((color >> 16) & 0xff);
*ptr = (byte)((color >> 24) & 0xff);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetPixelArrayIndexer(byte[] buffer, int i, uint color)
{
buffer[i] = (byte)(color & 0xff);
buffer[i + 1] = (byte)((color >> 8) & 0xff);
buffer[i + 2] = (byte)((color >> 16) & 0xff);
buffer[i + 3] = (byte)((color >> 24) & 0xff);
}

[Benchmark]
public unsafe void PointerReinterpretCast()
{
fixed (byte* ptr = &_buffer[0])
{
for (int i = 0; i < _buffer.Length; i += 4)
SetPixelPointerReinterpretCast(ptr + i, 0xffffffff);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private unsafe void SetPixelPointer(byte* ptr, uint color)
{
*ptr++ = (byte)(color & 0xff);
*ptr++ = (byte)((color >> 8) & 0xff);
*ptr++ = (byte)((color >> 16) & 0xff);
*ptr = (byte)((color >> 24) & 0xff);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private unsafe void SetPixelPointerReinterpretCast(byte* ptr, uint color)
{
*(uint*)ptr = color;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private unsafe void SetPixelPointerMemcpy(byte* ptr, uint color)
{
Unsafe.CopyBlock(ptr, &color, sizeof(uint));
}

[Benchmark]
public unsafe void PointerMemcpy()
{
fixed (byte* ptr = &_buffer[0])
{
for (int i = 0; i < _buffer.Length; i += 4)
SetPixelPointerMemcpy(ptr + i, 0xffffffff);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private unsafe void SetPixelPointerReinterpretCast(byte* ptr, uint color)
{
*(uint*)ptr = color;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private unsafe void SetPixelPointerMemcpy(byte* ptr, uint color)
{
Unsafe.CopyBlock(ptr, &color, sizeof(uint));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetPixelSpan(in Span<byte> span, uint color)
{
span[0] = (byte)(color & 0xff);
span[1] = (byte)((color >> 8) & 0xff);
span[2] = (byte)((color >> 16) & 0xff);
span[3] = (byte)((color >> 24) & 0xff);
}
}
49 changes: 20 additions & 29 deletions benchmarks/Benchmarks/ImmutableDictionaryLookup.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,33 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using BenchmarkDotNet.Attributes;

namespace Benchmarks
namespace Benchmarks;

public class ImmutableDictionaryLookup
{
public class ImmutableDictionaryLookup
{
private const int Index = 500;
private readonly IImmutableDictionary<int, object> _dictionary= Enumerable.Range(0, 1000).ToImmutableDictionary(i => i, i => new object());
private const int Index = 500;

[Benchmark]
public object Indexer()
{
if (!_dictionary.ContainsKey(Index))
return null;
return _dictionary[Index];
}
private readonly IImmutableDictionary<int, object> _dictionary =
Enumerable.Range(0, 1000).ToImmutableDictionary(i => i, _ => new object());

[Benchmark]
public object TryGet()
[Benchmark]
public object? Indexer() => CollectionExtensions.GetValueOrDefault(_dictionary, Index);

[Benchmark]
public object? TryCatch()
{
try
{
if (!_dictionary.TryGetValue(Index, out object value))
return null;
return value;
return _dictionary[Index];
}

[Benchmark]
public object TryCatch()
catch
{
try
{
return _dictionary[Index];
}
catch
{
return null;
}
return null;
}
}

[Benchmark]
public object? TryGet() => CollectionExtensions.GetValueOrDefault(_dictionary, Index);
}
29 changes: 14 additions & 15 deletions benchmarks/Benchmarks/LockOverhead.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
using BenchmarkDotNet.Attributes;

namespace Benchmarks
namespace Benchmarks;

public class LockOverhead
{
public class LockOverhead
{
private int _value;
private object _lock = new object();
private readonly object _lock = new();
private int _value;

[Benchmark]
public void IncreaseWithoutLock()
{
[Benchmark]
public void IncreaseWithLock()
{
lock (_lock)
_value++;
}
}

[Benchmark]
public void IncreaseWithLock()
{
lock (_lock)
_value++;
}
[Benchmark]
public void IncreaseWithoutLock()
{
_value++;
}
}
Loading