Skip to content

Commit

Permalink
fix: Fix SkiaCompat crashing with SkiaSharp 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed May 2, 2024
1 parent 2ea1c54 commit f0262dc
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 34 deletions.
31 changes: 18 additions & 13 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
<WriteLinesToFile File="$(_AndroidResourceDesignerFile)" Lines="// Empty Content from uno.ui Directory.Build.targets." />
</Target>

<PropertyGroup>
<SkiaSharpVersion>2.88.7</SkiaSharpVersion>
<SkiaSharpVersion Condition="'$(IsTestProject)' == 'true' or '$(IsSampleProject)' == 'true'">3.0.0-preview.3.1</SkiaSharpVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Update="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.1.9" />
<!-- Keep aligned with MSBuild extras' default ExtrasUwpMetaPackageVersion -->
Expand Down Expand Up @@ -90,22 +95,22 @@
<PackageReference Update="Xamarin.TestCloud.Agent" Version="0.23.2" />
<PackageReference Update="System.Numerics.Vectors" Version="4.5.0" />

<PackageReference Update="SkiaSharp.Views" Version="2.88.7" />
<PackageReference Update="SkiaSharp.Views.Uno" Version="2.88.7" />
<PackageReference Update="SkiaSharp.Views.Uno.WinUI" Version="2.88.7" />
<PackageReference Update="SkiaSharp.Views.WPF" Version="2.88.7" />
<PackageReference Update="SkiaSharp" Version="2.88.7" />
<PackageReference Update="SkiaSharp.NativeAssets.Linux" Version="2.88.7" />
<PackageReference Update="SkiaSharp.Harfbuzz" Version="2.88.7" />
<PackageReference Update="SkiaSharp.Skottie" Version="2.88.7" />
<PackageReference Update="SkiaSharp.NativeAssets.Android" Version="2.88.7" />
<PackageReference Update="SkiaSharp.NativeAssets.iOS" Version="2.88.7" />
<PackageReference Update="SkiaSharp.NativeAssets.MacCatalyst" Version="2.88.7" />
<PackageReference Update="SkiaSharp.NativeAssets.macos" Version="2.88.7" />
<PackageReference Update="SkiaSharp.Views" Version="$(SkiaSharpVersion)" />
<PackageReference Update="SkiaSharp.Views.Uno" Version="$(SkiaSharpVersion)" />
<PackageReference Update="SkiaSharp.Views.Uno.WinUI" Version="$(SkiaSharpVersion)" />
<PackageReference Update="SkiaSharp.Views.WPF" Version="$(SkiaSharpVersion)" />
<PackageReference Update="SkiaSharp" Version="$(SkiaSharpVersion)" />
<PackageReference Update="SkiaSharp.NativeAssets.Linux" Version="$(SkiaSharpVersion)" />
<PackageReference Update="SkiaSharp.Harfbuzz" Version="$(SkiaSharpVersion)" />
<PackageReference Update="SkiaSharp.Skottie" Version="$(SkiaSharpVersion)" />
<PackageReference Update="SkiaSharp.NativeAssets.Android" Version="$(SkiaSharpVersion)" />
<PackageReference Update="SkiaSharp.NativeAssets.iOS" Version="$(SkiaSharpVersion)" />
<PackageReference Update="SkiaSharp.NativeAssets.MacCatalyst" Version="$(SkiaSharpVersion)" />
<PackageReference Update="SkiaSharp.NativeAssets.macos" Version="$(SkiaSharpVersion)" />

<PackageReference Update="HarfBuzzSharp.NativeAssets.macOS" Version="7.3.0.1" />
<PackageReference Update="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0.1" />
<PackageReference Update="SkiaSharp.HarfBuzz" Version="2.88.7" />
<PackageReference Update="SkiaSharp.HarfBuzz" Version="$(SkiaSharpVersion)" />

<PackageReference Update="Svg.Skia" Version="1.0.0.1" />
<PackageReference Update="GtkSharp" Version="3.24.24.38" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<ItemGroup>
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Include="SkiaSharp.Views.WPF" Version="2.88.7" />
<PackageReference Include="SkiaSharp.Views.WPF" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net8.0-windows'">
Expand Down
80 changes: 60 additions & 20 deletions src/Uno.UI.Composition/SkiaCompat.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ internal static SKImageFilter SKImageFilter_CreateBlur(float sigmaX, float sigma
{
if (!_isSkiaSharp3OrLater)
{
return SKImageFilter.CreateBlur(sigmaX, sigmaY, input, new SKImageFilter.CropRect(cropRect));
[MethodImpl(MethodImplOptions.NoInlining)]
SKImageFilter Legacy() => SKImageFilter.CreateBlur(sigmaX, sigmaY, input, new SKImageFilter.CropRect(cropRect));
return Legacy();
}

#if NET8_0_OR_GREATER
Expand All @@ -37,7 +39,9 @@ internal static SKImageFilter SKImageFilter_CreateColorFilter(SKColorFilter cf,
{
if (!_isSkiaSharp3OrLater)
{
return SKImageFilter.CreateColorFilter(cf, input, new SKImageFilter.CropRect(cropRect));
[MethodImpl(MethodImplOptions.NoInlining)]
SKImageFilter Legacy() => SKImageFilter.CreateColorFilter(cf, input, new SKImageFilter.CropRect(cropRect));
return Legacy();
}

#if NET8_0_OR_GREATER
Expand All @@ -56,7 +60,9 @@ internal static SKImageFilter SKImageFilter_CreateColorFilter(SKColorFilter cf,
{
if (!_isSkiaSharp3OrLater)
{
return SKImageFilter.CreateColorFilter(cf, input);
[MethodImpl(MethodImplOptions.NoInlining)]
SKImageFilter Legacy() => SKImageFilter.CreateColorFilter(cf, input);
return Legacy();
}

#if NET8_0_OR_GREATER
Expand All @@ -75,7 +81,9 @@ internal static SKImageFilter SKImageFilter_CreateOffset(float dx, float dy, SKI
{
if (!_isSkiaSharp3OrLater)
{
return SKImageFilter.CreateOffset(dx, dy, input, new SKImageFilter.CropRect(cropRect));
[MethodImpl(MethodImplOptions.NoInlining)]
SKImageFilter Legacy() => SKImageFilter.CreateOffset(dx, dy, input, new SKImageFilter.CropRect(cropRect));
return Legacy();
}

#if NET8_0_OR_GREATER
Expand All @@ -94,7 +102,9 @@ internal static SKRuntimeEffect SKRuntimeEffect_CreateShader(string sksl, out st
{
if (!_isSkiaSharp3OrLater)
{
return SKRuntimeEffect.Create(sksl, out errors);
[MethodImpl(MethodImplOptions.NoInlining)]
SKRuntimeEffect Legacy(out string errors) => SKRuntimeEffect.Create(sksl, out errors);
return Legacy(out errors);
}

#if NET8_0_OR_GREATER
Expand All @@ -113,7 +123,9 @@ internal static void SKRuntimeEffectChildren_Add_WithNull(SKRuntimeEffectChildre
{
if (!_isSkiaSharp3OrLater)
{
@this.Add(name, null);
[MethodImpl(MethodImplOptions.NoInlining)]
void Legacy() => @this.Add(name, null);
Legacy();
return;
}

Expand All @@ -129,7 +141,9 @@ internal static SKImageFilter SKImageFilter_CreateBlendMode(SKBlendMode mode, SK
{
if (!_isSkiaSharp3OrLater)
{
return SKImageFilter.CreateBlendMode(mode, background, foreground, new SKImageFilter.CropRect(cropRect));
[MethodImpl(MethodImplOptions.NoInlining)]
SKImageFilter Legacy() => SKImageFilter.CreateBlendMode(mode, background, foreground, new SKImageFilter.CropRect(cropRect));
return Legacy();
}

#if NET8_0_OR_GREATER
Expand All @@ -148,7 +162,9 @@ internal static SKImageFilter SKImageFilter_CreatePaint(SKPaint paint, SKRect cr
{
if (!_isSkiaSharp3OrLater)
{
return SKImageFilter.CreatePaint(paint, new SKImageFilter.CropRect(cropRect));
[MethodImpl(MethodImplOptions.NoInlining)]
SKImageFilter Legacy() => SKImageFilter.CreatePaint(paint, new SKImageFilter.CropRect(cropRect));
return Legacy();
}

#if NET8_0_OR_GREATER
Expand All @@ -167,7 +183,9 @@ internal static SKImageFilter SKImageFilter_CreateDropShadow(float dx, float dy,
{
if (!_isSkiaSharp3OrLater)
{
return SKImageFilter.CreateDropShadow(dx, dy, sigmaX, sigmaY, color);
[MethodImpl(MethodImplOptions.NoInlining)]
SKImageFilter Legacy() => SKImageFilter.CreateDropShadow(dx, dy, sigmaX, sigmaY, color);
return Legacy();
}

#if NET8_0_OR_GREATER
Expand All @@ -186,7 +204,9 @@ internal static SKImageFilter SKImageFilter_CreateArithmetic(float k1, float k2,
{
if (!_isSkiaSharp3OrLater)
{
return SKImageFilter.CreateArithmetic(k1, k2, k3, k4, enforcePMColor, background, foreground, new SKImageFilter.CropRect(cropRect));
[MethodImpl(MethodImplOptions.NoInlining)]
SKImageFilter Legacy() => SKImageFilter.CreateArithmetic(k1, k2, k3, k4, enforcePMColor, background, foreground, new SKImageFilter.CropRect(cropRect));
return Legacy();
}

#if NET8_0_OR_GREATER
Expand All @@ -205,7 +225,9 @@ internal static SKImageFilter SKImageFilter_CreateMerge(ReadOnlySpan<SKImageFilt
{
if (!_isSkiaSharp3OrLater)
{
return SKImageFilter.CreateMerge(filters.ToArray(), new SKImageFilter.CropRect(cropRect));
[MethodImpl(MethodImplOptions.NoInlining)]
SKImageFilter Legacy(ReadOnlySpan<SKImageFilter> filters) => SKImageFilter.CreateMerge(filters.ToArray(), new SKImageFilter.CropRect(cropRect));
return Legacy(filters);
}

#if NET8_0_OR_GREATER
Expand All @@ -224,7 +246,9 @@ internal static SKImageFilter SKImageFilter_CreateMatrixConvolution(SKSizeI kern
{
if (!_isSkiaSharp3OrLater)
{
return SKImageFilter.CreateMatrixConvolution(kernelSize, kernel.ToArray(), gain, bias, kernelOffset, tileMode, convolveAlpha, input, new SKImageFilter.CropRect(cropRect));
[MethodImpl(MethodImplOptions.NoInlining)]
SKImageFilter Legacy(ReadOnlySpan<float> kernel) => SKImageFilter.CreateMatrixConvolution(kernelSize, kernel.ToArray(), gain, bias, kernelOffset, tileMode, convolveAlpha, input, new SKImageFilter.CropRect(cropRect));
return Legacy(kernel);
}

#if NET8_0_OR_GREATER
Expand All @@ -243,7 +267,9 @@ internal static SKImageFilter SKImageFilter_CreateDistantLitDiffuse(SKPoint3 dir
{
if (!_isSkiaSharp3OrLater)
{
return SKImageFilter.CreateDistantLitDiffuse(direction, lightColor, surfaceScale, kd, input, new SKImageFilter.CropRect(cropRect));
[MethodImpl(MethodImplOptions.NoInlining)]
SKImageFilter Legacy() => SKImageFilter.CreateDistantLitDiffuse(direction, lightColor, surfaceScale, kd, input, new SKImageFilter.CropRect(cropRect));
return Legacy();
}

#if NET8_0_OR_GREATER
Expand All @@ -262,7 +288,9 @@ internal static SKImageFilter SKImageFilter_CreateDistantLitSpecular(SKPoint3 di
{
if (!_isSkiaSharp3OrLater)
{
return SKImageFilter.CreateDistantLitSpecular(direction, lightColor, surfaceScale, ks, shininess, input, new SKImageFilter.CropRect(cropRect));
[MethodImpl(MethodImplOptions.NoInlining)]
SKImageFilter Legacy() => SKImageFilter.CreateDistantLitSpecular(direction, lightColor, surfaceScale, ks, shininess, input, new SKImageFilter.CropRect(cropRect));
return Legacy();
}

#if NET8_0_OR_GREATER
Expand All @@ -281,7 +309,9 @@ internal static SKImageFilter SKImageFilter_CreateSpotLitDiffuse(SKPoint3 locati
{
if (!_isSkiaSharp3OrLater)
{
return SKImageFilter.CreateSpotLitDiffuse(location, target, specularExponent, cutoffAngle, lightColor, surfaceScale, kd, input, new SKImageFilter.CropRect(cropRect));
[MethodImpl(MethodImplOptions.NoInlining)]
SKImageFilter Legacy() => SKImageFilter.CreateSpotLitDiffuse(location, target, specularExponent, cutoffAngle, lightColor, surfaceScale, kd, input, new SKImageFilter.CropRect(cropRect));
return Legacy();
}

#if NET8_0_OR_GREATER
Expand All @@ -300,7 +330,9 @@ internal static SKImageFilter SKImageFilter_CreateSpotLitSpecular(SKPoint3 locat
{
if (!_isSkiaSharp3OrLater)
{
return SKImageFilter.CreateSpotLitSpecular(location, target, specularExponent, cutoffAngle, lightColor, surfaceScale, ks, shininess, input, new SKImageFilter.CropRect(cropRect));
[MethodImpl(MethodImplOptions.NoInlining)]
SKImageFilter Legacy() => SKImageFilter.CreateSpotLitSpecular(location, target, specularExponent, cutoffAngle, lightColor, surfaceScale, ks, shininess, input, new SKImageFilter.CropRect(cropRect));
return Legacy();
}

#if NET8_0_OR_GREATER
Expand All @@ -319,7 +351,9 @@ internal static SKImageFilter SKImageFilter_CreatePointLitDiffuse(SKPoint3 locat
{
if (!_isSkiaSharp3OrLater)
{
return SKImageFilter.CreatePointLitDiffuse(location, lightColor, surfaceScale, kd, input, new SKImageFilter.CropRect(cropRect));
[MethodImpl(MethodImplOptions.NoInlining)]
SKImageFilter Legacy() => SKImageFilter.CreatePointLitDiffuse(location, lightColor, surfaceScale, kd, input, new SKImageFilter.CropRect(cropRect));
return Legacy();
}

#if NET8_0_OR_GREATER
Expand All @@ -338,7 +372,9 @@ internal static SKImageFilter SKImageFilter_CreatePointLitSpecular(SKPoint3 loca
{
if (!_isSkiaSharp3OrLater)
{
return SKImageFilter.CreatePointLitSpecular(location, lightColor, surfaceScale, ks, shininess, input, new SKImageFilter.CropRect(cropRect));
[MethodImpl(MethodImplOptions.NoInlining)]
SKImageFilter Legacy() => SKImageFilter.CreatePointLitSpecular(location, lightColor, surfaceScale, ks, shininess, input, new SKImageFilter.CropRect(cropRect));
return Legacy();
}

#if NET8_0_OR_GREATER
Expand All @@ -357,7 +393,9 @@ internal static SKShader SKRuntimeEffect_ToShader(SKRuntimeEffect @this, bool is
{
if (!_isSkiaSharp3OrLater)
{
return @this.ToShader(isOpaque, uniforms);
[MethodImpl(MethodImplOptions.NoInlining)]
SKShader Legacy() => @this.ToShader(isOpaque, uniforms);
return Legacy();
}

#if NET8_0_OR_GREATER
Expand All @@ -377,7 +415,9 @@ internal static ReadOnlySpan<byte> SKBitmap_GetPixelSpan(SKBitmap @this)
{
if (!_isSkiaSharp3OrLater)
{
return @this.GetPixelSpan();
[MethodImpl(MethodImplOptions.NoInlining)]
ReadOnlySpan<byte> Legacy() => @this.GetPixelSpan();
return Legacy();
}

#if NET8_0_OR_GREATER
Expand Down

0 comments on commit f0262dc

Please sign in to comment.