Skip to content

Commit

Permalink
feat: Add basic Skottie support (#1987)
Browse files Browse the repository at this point in the history
* feat: Add basic Skottie support
* chore: Adjust skottie SKStream support
* ci: Adjust apple targets
* chore: Adjust apple targets
* chore: Adjust tizen targets
* chore: Adjust APIs, add tests, align with new memory management functions
* chore: Adjust for updated API name in sample
* chore: Adjust test values
* chore: Adjust AnimationRenderFlags generation
* chore: Fix linux skottie export map
* ci: Update skia submodule
  • Loading branch information
jeromelaban authored May 31, 2022
1 parent b651807 commit cda59a8
Show file tree
Hide file tree
Showing 27 changed files with 15,671 additions and 12 deletions.
54 changes: 54 additions & 0 deletions binding/Binding/SceneGraph/InvalidationController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.InteropServices;

namespace SkiaSharp.SceneGraph
{
public unsafe class InvalidationController : SKObject, ISKSkipObjectRegistration
{
public InvalidationController ()
: this (SkiaApi.sksg_invalidation_controller_new (), true)
{
}

internal InvalidationController (IntPtr handle, bool owns)
: base (handle, owns)
{
}

protected override void DisposeNative ()
{
SkiaApi.sksg_invalidation_controller_delete (Handle);
}

public unsafe void Invalidate(SKRect rect, SKMatrix matrix)
{
SkiaApi.sksg_invalidation_controller_inval (Handle, &rect, &matrix);
}

public unsafe SKRect Bounds
{
get {
SKRect rect;
SkiaApi.sksg_invalidation_controller_get_bounds (Handle, &rect);
return rect;
}
}

public unsafe void Begin ()
{
SkiaApi.sksg_invalidation_controller_begin (Handle);
}

public unsafe void End ()
{
SkiaApi.sksg_invalidation_controller_end (Handle);
}

public unsafe void Reset ()
{
SkiaApi.sksg_invalidation_controller_reset (Handle);
}
}
}
379 changes: 379 additions & 0 deletions binding/Binding/SkiaApi.generated.cs

Large diffs are not rendered by default.

98 changes: 98 additions & 0 deletions binding/Binding/Skottie/Animation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.InteropServices;
using SkiaSharp.SceneGraph;

namespace SkiaSharp.Skottie
{
public unsafe class Animation : SKObject, ISKNonVirtualReferenceCounted, ISKSkipObjectRegistration
{
internal Animation (IntPtr handle, bool owns)
: base (handle, owns)
{
}

void ISKNonVirtualReferenceCounted.ReferenceNative ()
=> SkiaApi.skottie_animation_ref (Handle);

void ISKNonVirtualReferenceCounted.UnreferenceNative ()
=> SkiaApi.skottie_animation_unref (Handle);

protected override void DisposeNative ()
=> SkiaApi.skottie_animation_delete (Handle);

public static bool TryParse (string data, out Animation animation)
{
animation = GetObject (SkiaApi.skottie_animation_make_from_string (data, data.Length));
return animation != null;
}

public static bool TryCreate (Stream stream, out Animation animation)
{
using (var managed = new SKManagedStream (stream)) {
return TryCreate (managed, out animation);
}
}

public static bool TryCreate (SKStream stream, out Animation animation)
{
animation = GetObject (SkiaApi.skottie_animation_make_from_stream (stream.Handle));
return animation != null;
}

public static bool TryCreate (string path, out Animation animation)
{
animation = GetObject (SkiaApi.skottie_animation_make_from_file (path));
return animation != null;
}

public unsafe void Render(SKCanvas canvas, SKRect dst)
=> SkiaApi.skottie_animation_render (Handle, canvas.Handle, &dst);

public void Render (SKCanvas canvas, SKRect dst, AnimationRenderFlags flags)
=> SkiaApi.skottie_animation_render_with_flags (Handle, canvas.Handle, &dst, flags);

public void Seek (double t, InvalidationController ic = null)
=> SkiaApi.skottie_animation_seek (Handle, (float)t, ic?.Handle ?? IntPtr.Zero);

public void SeekFrame(double t, InvalidationController ic = null)
=> SkiaApi.skottie_animation_seek_frame (Handle, (float)t, ic?.Handle ?? IntPtr.Zero);

public void SeekFrameTime(double t, InvalidationController ic = null)
=> SkiaApi.skottie_animation_seek_frame_time (Handle, (float)t, ic?.Handle ?? IntPtr.Zero);

public double Duration
=> SkiaApi.skottie_animation_get_duration (Handle);

public double Fps
=> SkiaApi.skottie_animation_get_fps (Handle);

public double InPoint
=> SkiaApi.skottie_animation_get_in_point (Handle);

public double OutPoint
=> SkiaApi.skottie_animation_get_out_point (Handle);

public string Version {
get {
using var str = new SKString ();

SkiaApi.skottie_animation_get_version (Handle, str.Handle);

return str.ToString();
}
}

public unsafe SKSize Size {
get {
SKSize size;
SkiaApi.skottie_animation_get_size (Handle, &size);
return size;
}
}

internal static Animation GetObject (IntPtr handle) =>
handle == IntPtr.Zero ? null : new Animation (handle, true);
}
}
28 changes: 26 additions & 2 deletions binding/libSkiaSharp.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,26 @@
},
"gr_": {
"prefix": "GR"
},
"sksg_": {
"cs": "SceneGraph",
"prefix": ""
},
"skottie_": {
"cs": "Skottie",
"prefix": ""
}
},
"className": "SkiaApi",
"includeDirs": [
"."
],
"headers": {
"include/c": [ "sk_*", "gr_*" ],
"include/c": [ "sk_*", "gr_*", "skottie*", "sksg_*" ],
"include/xamarin": [ "sk_*" ]
},
"source": {
"src/c": [ "sk_*", "gr_*" ],
"src/c": [ "sk_*", "gr_*", "skottie*", "sksg_*" ],
"src/xamarin": [ "sk_*" ]
},
"mappings": {
Expand Down Expand Up @@ -366,6 +374,10 @@
"sk_lattice_t": {
"cs": "SKLatticeInternal",
"internal": true
},
"skottie_animation_renderflags_t": {
"cs": "AnimationRenderFlags",
"flags": true
}
},
"functions": {
Expand Down Expand Up @@ -444,6 +456,18 @@
"parameters": {
"1": "[MarshalAs (UnmanagedType.LPStr)] String"
}
},
"skottie_animation_make_from_string": {
"parameters": {
"0": "[MarshalAs (UnmanagedType.LPStr)] String",
"1": "int"

}
},
"skottie_animation_make_from_file": {
"parameters": {
"0": "[MarshalAs (UnmanagedType.LPStr)] String"
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions native/android/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Task("libSkiaSharp")
$"skia_use_system_libwebp=false " +
$"skia_use_system_zlib=false " +
$"skia_use_vulkan={SUPPORT_VULKAN} ".ToLower () +
$"skia_enable_skottie=true " +
$"extra_cflags=[ '-DSKIA_C_DLL', '-DHAVE_SYSCALL_GETRANDOM', '-DXML_DEV_URANDOM' ] " +
$"ndk='{ANDROID_NDK_HOME}' " +
$"ndk_api={(skiaArch == "x64" || skiaArch == "arm64" ? 21 : 16)}");
Expand Down
3 changes: 2 additions & 1 deletion native/ios/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Task("libSkiaSharp")
{
if (Skip(arch)) return;
GnNinja($"{VARIANT}/{arch}", "skia",
GnNinja($"{VARIANT}/{arch}", "skia modules/skottie",
$"target_cpu='{skiaArch}' " +
$"target_os='{VARIANT}' " +
$"skia_use_icu=false " +
Expand All @@ -41,6 +41,7 @@ Task("libSkiaSharp")
$"skia_use_system_libpng=false " +
$"skia_use_system_libwebp=false " +
$"skia_use_system_zlib=false " +
$"skia_enable_skottie=true " +
$"extra_cflags=[ '-DSKIA_C_DLL', '-DHAVE_ARC4RANDOM_BUF' ] ");
RunXCodeBuild("libSkiaSharp/libSkiaSharp.xcodeproj", "libSkiaSharp", sdk, arch, platform: VARIANT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@
OTHER_LDFLAGS = (
"-all_load",
"-lskia",
"-lskottie",
"-lsksg",
"-lskshaper",
"-lskresources",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.microsoft.libSkiaSharp";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -444,6 +448,10 @@
OTHER_LDFLAGS = (
"-all_load",
"-lskia",
"-lskottie",
"-lsksg",
"-lskshaper",
"-lskresources",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.microsoft.libSkiaSharp";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
1 change: 1 addition & 0 deletions native/linux/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Task("libSkiaSharp")
$"skia_use_system_libpng=false " +
$"skia_use_system_libwebp=false " +
$"skia_use_system_zlib=false " +
$"skia_enable_skottie=true " +
$"skia_use_vulkan={SUPPORT_VULKAN} ".ToLower() +
$"extra_asmflags=[] " +
$"extra_cflags=[ '-DSKIA_C_DLL', '-DHAVE_SYSCALL_GETRANDOM', '-DXML_DEV_URANDOM' ] " +
Expand Down
2 changes: 2 additions & 0 deletions native/linux/libSkiaSharp/libSkiaSharp.map
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ libSkiaSharp {
global:
sk_*;
gr_*;
skottie_*;
sksg_*;
local:
*;
};
3 changes: 2 additions & 1 deletion native/macos/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Task("libSkiaSharp")
? "11.0"
: "10.8";
GnNinja($"macos/{arch}", "skia",
GnNinja($"macos/{arch}", "skia modules/skottie",
$"target_os='mac' " +
$"target_cpu='{skiaArch}' " +
$"min_macos_version='{minVersion}' " +
Expand All @@ -35,6 +35,7 @@ Task("libSkiaSharp")
$"skia_use_system_libpng=false " +
$"skia_use_system_libwebp=false " +
$"skia_use_system_zlib=false " +
$"skia_enable_skottie=true " +
$"extra_cflags=[ '-DSKIA_C_DLL', '-DHAVE_ARC4RANDOM_BUF', '-stdlib=libc++' ] " +
$"extra_ldflags=[ '-stdlib=libc++' ]");
Expand Down
16 changes: 14 additions & 2 deletions native/macos/libSkiaSharp/libSkiaSharp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,13 @@
INSTALL_PATH = "@rpath";
LIBRARY_SEARCH_PATHS = "../../../externals/skia/out/macos/$(ARCHS)";
MACOSX_DEPLOYMENT_TARGET = 10.8;
OTHER_LDFLAGS = "-lskia";
OTHER_LDFLAGS = (
"-lskia",
"-lskottie",
"-lsksg",
"-lskshaper",
"-lskresources",
);
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Expand All @@ -396,7 +402,13 @@
INSTALL_PATH = "@rpath";
LIBRARY_SEARCH_PATHS = "../../../externals/skia/out/macos/$(ARCHS)";
MACOSX_DEPLOYMENT_TARGET = 10.8;
OTHER_LDFLAGS = "-lskia";
OTHER_LDFLAGS = (
"-lskia",
"-lskottie",
"-lsksg",
"-lskshaper",
"-lskresources",
);
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand Down
3 changes: 2 additions & 1 deletion native/tizen/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Task("libSkiaSharp")
{
if (Skip(arch)) return;
GnNinja($"tizen/{arch}", "skia",
GnNinja($"tizen/{arch}", "skia modules/skottie",
$"target_os='tizen' " +
$"target_cpu='{skiaArch}' " +
$"skia_enable_gpu=true " +
Expand All @@ -34,6 +34,7 @@ Task("libSkiaSharp")
$"skia_use_system_libpng=false " +
$"skia_use_system_libwebp=false " +
$"skia_use_system_zlib=true " +
$"skia_enable_skottie=true " +
$"extra_cflags=[ '-DSKIA_C_DLL', '-DXML_DEV_URANDOM', '-DSK_NO_MAKE_SHARED_PTR' ] " +
$"ncli='{TIZEN_STUDIO_HOME}' " +
$"ncli_version='4.0'");
Expand Down
2 changes: 1 addition & 1 deletion native/tizen/libSkiaSharp/project_def.prop
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ skia_root = $(abspath ../../../externals/skia)

USER_LIB_DIRS = $(skia_root)/out/tizen/$(BUILD_ARCH)

USER_LIBS = skia
USER_LIBS = skia skresources skottie sksg skshaper

USER_LINK_OPTS = -Wl,--gc-sections

Expand Down
3 changes: 2 additions & 1 deletion native/tvos/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Task("libSkiaSharp")
{
if (Skip(arch)) return;
GnNinja($"tvos/{arch}", "skia",
GnNinja($"tvos/{arch}", "skia modules/skottie",
$"target_os='tvos' " +
$"target_cpu='{skiaArch}' " +
$"skia_use_icu=false " +
Expand All @@ -30,6 +30,7 @@ Task("libSkiaSharp")
$"skia_use_system_libpng=false " +
$"skia_use_system_libwebp=false " +
$"skia_use_system_zlib=false " +
$"skia_enable_skottie=true " +
$"extra_cflags=[ '-DSKIA_C_DLL', '-DHAVE_ARC4RANDOM_BUF' ] ");
RunXCodeBuild("libSkiaSharp/libSkiaSharp.xcodeproj", "libSkiaSharp", sdk, arch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@
OTHER_LDFLAGS = (
"-all_load",
"-lskia",
"-lskottie",
"-lsksg",
"-lskshaper",
"-lskresources",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.microsoft.libSkiaSharp";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -432,6 +436,10 @@
OTHER_LDFLAGS = (
"-all_load",
"-lskia",
"-lskottie",
"-lsksg",
"-lskshaper",
"-lskresources",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.microsoft.libSkiaSharp";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
1 change: 1 addition & 0 deletions native/uwp/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Task("libSkiaSharp")
$"skia_use_system_libpng=false " +
$"skia_use_system_libwebp=false " +
$"skia_use_system_zlib=false " +
$"skia_enable_skottie=true " +
win_vcvars_version +
$"extra_cflags=[ " +
$" '-DSKIA_C_DLL', '/MD{d}', '/EHsc', '/Z7', " +
Expand Down
Loading

0 comments on commit cda59a8

Please sign in to comment.