-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86965b7
commit 57f2998
Showing
13 changed files
with
162 additions
and
4 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
binding/SkiaSharp.Resources/Properties/SkiaSharpResourcesAssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace SkiaSharp.Resources | ||
{ | ||
public unsafe class ResourceProvider : SKObject, ISKSkipObjectRegistration | ||
{ | ||
internal ResourceProvider (IntPtr handle, bool owns) | ||
: base (handle, owns) | ||
{ | ||
} | ||
|
||
protected override void DisposeNative () | ||
=> ResourcesApi.skresources_resource_provider_delete (Handle); | ||
|
||
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 static ResourceProvider CreateCaching (ResourceProvider resourceProvider) | ||
{ | ||
_ = resourceProvider ?? throw new ArgumentNullException (nameof (resourceProvider)); | ||
return GetObject (ResourcesApi.skresources_caching_resource_provider_proxy_make (resourceProvider.Handle))!; | ||
} | ||
|
||
public static ResourceProvider CreateDataUri (ResourceProvider fallbackProvider, bool preDecode = false) | ||
{ | ||
_ = fallbackProvider ?? throw new ArgumentNullException (nameof (fallbackProvider)); | ||
return GetObject (ResourcesApi.skresources_data_uri_resource_provider_proxy_make (fallbackProvider.Handle, preDecode))!; | ||
} | ||
|
||
public static ResourceProvider CreateFile (string baseDirectory, bool preDecode = false) | ||
{ | ||
using var baseDir = new SKString(baseDirectory ?? throw new ArgumentNullException (nameof (baseDirectory))); | ||
return GetObject (ResourcesApi.skresources_file_resource_provider_make (baseDir.Handle, preDecode))!; | ||
} | ||
|
||
internal static ResourceProvider? GetObject (IntPtr handle) => | ||
handle == IntPtr.Zero ? null : new ResourceProvider (handle, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.IO; | ||
using SkiaSharp.Resources; | ||
using Xunit; | ||
|
||
namespace SkiaSharp.Tests | ||
{ | ||
public class ResourceProviderTest : SKTest | ||
{ | ||
[SkippableFact] | ||
public void FileResourceProviderCanReadFiles() | ||
{ | ||
var fullPath = Path.Combine(PathToImages, "baboon.png"); | ||
var expectedData = SKData.Create(fullPath); | ||
|
||
using var rp = ResourceProvider.CreateFile(PathToImages); | ||
|
||
using var data = rp.Load("baboon.png"); | ||
|
||
Assert.Equal(expectedData.ToArray(), data.ToArray()); | ||
} | ||
|
||
[SkippableFact] | ||
public void ProxyProviderCanReadFiles() | ||
{ | ||
var fullPath = Path.Combine(PathToImages, "baboon.png"); | ||
var expectedData = SKData.Create(fullPath); | ||
|
||
using var files = ResourceProvider.CreateFile(PathToImages); | ||
using var datauri = ResourceProvider.CreateDataUri(files); | ||
using var caching = ResourceProvider.CreateCaching(datauri); | ||
|
||
using var data = caching.Load("baboon.png"); | ||
|
||
Assert.Equal(expectedData.ToArray(), data.ToArray()); | ||
} | ||
} | ||
} |