Skip to content

Commit

Permalink
Use Unsafe.As for better perf
Browse files Browse the repository at this point in the history
Fixes #2778
  • Loading branch information
mattleibow committed Mar 2, 2024
1 parent d98115c commit 9ec7f92
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
4 changes: 4 additions & 0 deletions binding/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>

<ItemGroup Condition=" ('$(TargetFramework)' == 'netstandard2.1') and (!$(MSBuildProjectName.Contains('.NativeAssets.'))) ">
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.3" />
</ItemGroup>

<PropertyGroup Condition="'$(PackagingGroup)' == 'SkiaSharp'">
<PackageDescription Condition="'$(PackageDescription)' == ''">SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library.
It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.</PackageDescription>
Expand Down
13 changes: 3 additions & 10 deletions binding/SkiaSharp/SKMatrix44.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Numerics;
using System.Runtime.CompilerServices;

namespace SkiaSharp
{
Expand Down Expand Up @@ -474,17 +475,9 @@ public static implicit operator SKMatrix44 (SKMatrix matrix) =>
matrix.Persp0, matrix.Persp1, 0, matrix.Persp2);

public static implicit operator Matrix4x4 (SKMatrix44 matrix) =>
new Matrix4x4 (
matrix.m00, matrix.m10, matrix.m20, matrix.m30,
matrix.m01, matrix.m11, matrix.m21, matrix.m31,
matrix.m02, matrix.m12, matrix.m22, matrix.m32,
matrix.m03, matrix.m13, matrix.m23, matrix.m33);
Unsafe.As<SKMatrix44, Matrix4x4> (ref matrix);

public static implicit operator SKMatrix44 (Matrix4x4 matrix) =>
new SKMatrix44 (
matrix.M11, matrix.M21, matrix.M31, matrix.M41,
matrix.M12, matrix.M22, matrix.M32, matrix.M42,
matrix.M13, matrix.M23, matrix.M33, matrix.M43,
matrix.M14, matrix.M24, matrix.M34, matrix.M44);
Unsafe.As<Matrix4x4, SKMatrix44> (ref matrix);
}
}

0 comments on commit 9ec7f92

Please sign in to comment.