[canvaskit] Expose nima animation as POC
Still to come, actually exposing drawVertices, and the
other APIs needed.
Had to re-make all the jsfiddles because of an API change
in a previous CL.
Docs-Preview: https://skia.org/?cl=166444
Bug: skia:
Change-Id: I4d4825f6e7b073d6792ab8d99d5117df860d4815
Reviewed-on: https://skia-review.googlesource.com/c/166444
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
diff --git a/experimental/canvaskit/canvaskit_bindings.cpp b/experimental/canvaskit/canvaskit_bindings.cpp
index 1d91667..129ee50 100644
--- a/experimental/canvaskit/canvaskit_bindings.cpp
+++ b/experimental/canvaskit/canvaskit_bindings.cpp
@@ -28,6 +28,9 @@
#if SK_INCLUDE_SKOTTIE
#include "Skottie.h"
#endif
+#if SK_INCLUDE_NIMA
+#include "nima/NimaActor.h"
+#endif
#include <iostream>
#include <string>
@@ -41,9 +44,10 @@
using namespace emscripten;
+// Self-documenting types
+using JSArray = emscripten::val;
using JSColor = int32_t;
-
void EMSCRIPTEN_KEEPALIVE initFonts() {
gSkFontMgr_DefaultFactory = &sk_tool_utils::MakePortableFontMgr;
}
@@ -376,4 +380,35 @@
function("MakeAnimation", &MakeAnimation);
constant("skottie", true);
#endif
+
+#if SK_INCLUDE_NIMA
+ class_<NimaActor>("NimaActor")
+ .function("duration", &NimaActor::duration)
+ .function("getAnimationNames", optional_override([](NimaActor& self)->JSArray {
+ JSArray names = emscripten::val::array();
+ auto vNames = self.getAnimationNames();
+ for (size_t i = 0; i < vNames.size(); i++) {
+ names.call<void>("push", vNames[i]);
+ }
+ return names;
+ }), allow_raw_pointers())
+ .function("render", optional_override([](NimaActor& self, SkCanvas* canvas)->void {
+ self.render(canvas, 0);
+ }), allow_raw_pointers())
+ .function("seek", &NimaActor::seek)
+ .function("setAnimationByIndex", select_overload<void(uint8_t )>(&NimaActor::setAnimation))
+ .function("setAnimationByName" , select_overload<void(std::string)>(&NimaActor::setAnimation));
+
+ function("_MakeNimaActor", optional_override([](uintptr_t /* uint8_t* */ nptr, int nlen,
+ uintptr_t /* uint8_t* */ tptr, int tlen)->NimaActor* {
+ // See comment above for uintptr_t explanation
+ const uint8_t* nimaBytes = reinterpret_cast<const uint8_t*>(nptr);
+ const uint8_t* textureBytes = reinterpret_cast<const uint8_t*>(tptr);
+
+ auto nima = SkData::MakeWithoutCopy(nimaBytes, nlen);
+ auto texture = SkData::MakeWithoutCopy(textureBytes, tlen);
+ return new NimaActor(nima, texture);
+ }), allow_raw_pointers());
+ constant("nima", true);
+#endif
}