Skip to content

Commit

Permalink
Bind Skottie's Animation Builder (#2630)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow authored Feb 18, 2024
1 parent c4fd517 commit 42fc018
Show file tree
Hide file tree
Showing 45 changed files with 1,219 additions and 26 deletions.
2 changes: 2 additions & 0 deletions benchmarks/SkiaSharp.Benchmarks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp.Benchmarks", "Ski
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp.SceneGraph", "..\binding\SkiaSharp.SceneGraph\SkiaSharp.SceneGraph.csproj", "{42B5D998-A676-4B50-B558-1D3ACA7D3FC4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp.Resources", "..\binding\SkiaSharp.Resources\SkiaSharp.Resources.csproj", "{AD2C6978-4F5E-E592-B565-26C357877B2C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp.Skottie", "..\binding\SkiaSharp.Skottie\SkiaSharp.Skottie.csproj", "{DD03EAA1-A85D-4588-8B84-8285EC1979C8}"
EndProject
Global
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;

[assembly: AssemblyTitle("SkiaSharp.Resources")]
[assembly: AssemblyDescription("This package adds lottie support to SkiaSharp via skottie.")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyProduct("SkiaSharp")]
[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")]
[assembly: NeutralResourcesLanguage("en")]

[assembly: InternalsVisibleTo("SkiaSharp.Tests, PublicKey=" +
"002400000480000094000000060200000024000052534131000400000100010079159977d2d03a" +
"8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c" +
"3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fd" +
"dafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef00" +
"65d016df")]

[assembly: InternalsVisibleTo("SkiaSharp.Benchmarks, PublicKey=" +
"002400000480000094000000060200000024000052534131000400000100010079159977d2d03a" +
"8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c" +
"3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fd" +
"dafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef00" +
"65d016df")]

[assembly: AssemblyMetadata("IsTrimmable", "True")]

#if __IOS__ || __TVOS__ || __MACOS__
// This attribute allows you to mark your assemblies as “safe to link”.
// When the attribute is present, the linker—if enabled—will process the assembly
// even if you’re using the “Link SDK assemblies only” option, which is the default for device builds.
#pragma warning disable CS0618 // Type or member is obsolete
[assembly: Foundation.LinkerSafe]
#pragma warning restore CS0618 // Type or member is obsolete
#endif
64 changes: 64 additions & 0 deletions binding/SkiaSharp.Resources/ResourceProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;

namespace SkiaSharp.Resources
{
public abstract unsafe class ResourceProvider : SKObject, ISKReferenceCounted, ISKSkipObjectRegistration
{
internal ResourceProvider (IntPtr handle, bool owns)
: base (handle, owns)
{
}

public SKData? Load (string resourceName) =>
Load ("", resourceName);

public SKData? Load (string resourcePath, string resourceName) =>
SKData.GetObject (ResourcesApi.skresources_resource_provider_load (Handle, resourcePath, resourceName));
}

public sealed class CachingResourceProvider : ResourceProvider
{
public CachingResourceProvider (ResourceProvider resourceProvider)
: base (Create (resourceProvider), true)
{
Referenced(this, resourceProvider);
}

private static IntPtr Create (ResourceProvider resourceProvider)
{
_ = resourceProvider ?? throw new ArgumentNullException (nameof (resourceProvider));
return ResourcesApi.skresources_caching_resource_provider_proxy_make (resourceProvider.Handle);
}
}

public sealed class DataUriResourceProvider : ResourceProvider
{
public DataUriResourceProvider (bool preDecode = false)
: this (null, preDecode)
{
}

public DataUriResourceProvider (ResourceProvider? fallbackProvider, bool preDecode = false)
: base (Create (fallbackProvider, preDecode), true)
{
Referenced (this, fallbackProvider);
}

private static IntPtr Create (ResourceProvider? fallbackProvider, bool preDecode = false) =>
ResourcesApi.skresources_data_uri_resource_provider_proxy_make (fallbackProvider?.Handle ?? IntPtr.Zero, preDecode);
}

public sealed class FileResourceProvider : ResourceProvider
{
public FileResourceProvider (string baseDirectory, bool preDecode = false)
: base (Create (baseDirectory, preDecode), true)
{
}

private static IntPtr Create (string baseDirectory, bool preDecode)
{
using var baseDir = new SKString(baseDirectory ?? throw new ArgumentNullException (nameof (baseDirectory)));
return ResourcesApi.skresources_file_resource_provider_make (baseDir.Handle, preDecode);
}
}
}
23 changes: 23 additions & 0 deletions binding/SkiaSharp.Resources/ResourcesApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#nullable disable

using System;

namespace SkiaSharp
{
internal partial class ResourcesApi
{
#if __IOS__ || __TVOS__
private const string SKIA = "@rpath/libSkiaSharp.framework/libSkiaSharp";
#else
private const string SKIA = "libSkiaSharp";
#endif

#if USE_DELEGATES
private static readonly Lazy<IntPtr> libSkiaSharpHandle =
new Lazy<IntPtr> (() => LibraryLoader.LoadLocalLibrary<SkiaApi> (SKIA));

private static T GetSymbol<T> (string name) where T : Delegate =>
LibraryLoader.GetSymbolDelegate<T> (libSkiaSharpHandle.Value, name);
#endif
}
}
Loading

0 comments on commit 42fc018

Please sign in to comment.