Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind Skottie's Animation Builder #2630

Merged
merged 24 commits into from
Feb 18, 2024
Merged

Conversation

mattleibow
Copy link
Contributor

@mattleibow mattleibow commented Sep 22, 2023

Description of Change

This PR adds a few of the essential APIs to enable loading embedded files in the Lottie animation. Currently, there is just the support for file-based and data URI-based assets.

Bugs Fixed

API Changes

class Animation {
  public static AnimationBuilder CreateBuilder (AnimationBuilderFlags flags = AnimationBuilderFlags.None);
}

public sealed unsafe class AnimationBuilder : SKObject, ISKSkipObjectRegistration {
  public AnimationBuilder SetFontManager (SKFontManager fontManager);
  public AnimationBuilder SetResourceProvider (ResourceProvider resourceProvider);
  public AnimationBuilderStats Stats { get; }
  public Animation? Build (Stream stream);
  public Animation? Build (SKStream stream);
  public Animation? Build (SKData data);
  public Animation? Build (string path);
}

public struct AnimationBuilderStats {
  public readonly TimeSpan TotalLoadTime { get; }
  public readonly TimeSpan JsonParseTime { get; }
  public readonly TimeSpan SceneParseTime { get; }
  public readonly int JsonSize  { get; }
  public readonly int AnimatorCount  { get; }
}

public abstract unsafe class ResourceProvider : SKObject, ISKReferenceCounted, ISKSkipObjectRegistration {
  public SKData? Load (string resourceName);
  public SKData? Load (string resourcePath, string resourceName);
}

public class CachingResourceProvider : ResourceProvider {
  public CachingResourceProvider (ResourceProvider resourceProvider);
}

public class DataUriResourceProvider : ResourceProvider {
  public DataUriResourceProvider (bool preDecode = false);
  public DataUriResourceProvider (ResourceProvider? fallbackProvider, bool preDecode = false);
}

public class FileResourceProvider : ResourceProvider {
  public FileResourceProvider (string baseDirectory, bool preDecode = false);
}

Behavioral Changes

None.

Required skia PR

mono/skia#114

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Merged related skia PRs
  • Changes adhere to coding standard
  • Updated documentation

@thisisthekap
Copy link

@mattleibow When is this going to released?

@imms20
Copy link

imms20 commented Jan 27, 2024

Hi @mattleibow any idea when will it be released? i have done migration of an app and i am only blocked by lottie animations which uses files. if there is not plan for release, then will it be fine if i just checkout this branch and create build and use the dlls? i only need it for ios and android

Comment on lines +25 to +27
[Trait(Traits.FailingOn.Key, Traits.FailingOn.Values.macOS)] // Something with sk_sp<SkPicture> SkDrawable::onMakePictureSnapshot() is causing issues
[Trait(Traits.FailingOn.Key, Traits.FailingOn.Values.iOS)] // Something with sk_sp<SkPicture> SkDrawable::onMakePictureSnapshot() is causing issues
[Trait(Traits.FailingOn.Key, Traits.FailingOn.Values.MacCatalyst)] // Something with sk_sp<SkPicture> SkDrawable::onMakePictureSnapshot() is causing issues
Copy link
Contributor Author

@mattleibow mattleibow Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that the fact I override the

sk_sp<SkPicture> SkDrawable::onMakePictureSnapshot()

function in C++ for the managed drawable is causing a crash. If i change it to

SkPicture* SkDrawable::onMakePictureSnapshot()

stops the crash. I noticed this locally on macOS. Not sure why it passes on CI.

Issue: #2760


namespace SkiaSharp.Resources
{
public abstract unsafe class ResourceProvider : SKObject, ISKReferenceCounted, ISKSkipObjectRegistration
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to future self. Don't forget to correctly apply the ISKReferenceCounted interface and NOT explicitly delete the reference counted types. This causes a hard-to-debug crash because the type is deleted while in use. Ot sometimes crashes in a debug build with a better log message, but not often.

@mattleibow mattleibow merged commit 42fc018 into main Feb 18, 2024
2 checks passed
@mattleibow mattleibow deleted the dev/skottie-animation-builder branch February 18, 2024 15:33
@mattleibow mattleibow added the backport/release/2.x Backport this PR to release/2.x label Apr 13, 2024
Copy link

The backport to release/2.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-release/2.x release/2.x
# Navigate to the new working tree
cd .worktrees/backport-release/2.x
# Create a new branch
git switch --create backport/pr-2630-to-release/2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 42fc0181e0f9d2cda2d7f4f9359de2dd5252fcc1
# Push it to GitHub
git push --set-upstream origin backport/pr-2630-to-release/2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-release/2.x

Then, create a pull request where the base branch is release/2.x and the compare/head branch is backport/pr-2630-to-release/2.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/release/2.x Backport this PR to release/2.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Skottie cannot draw animations that have embedded images
3 participants